imagelist.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from lazpaint import command, dialog
  2. import glob
  3. if __name__ == "__main__":
  4. dialog.show_message("Library to act on the image list.")
  5. UNCHECK_OFF = 'UncheckOff'
  6. UNCHECK_ON_OPEN = 'UncheckOnOpen'
  7. UNCHECK_ON_SAVE = 'UncheckOnSave'
  8. def get_file_count() -> int:
  9. return command.send("ImageListGetFileCount?")
  10. def get_selected_index() -> int:
  11. return command.send("ImageListGetSelectedIndex?")
  12. def set_selected_index(index: int):
  13. command.send("ImageListSetSelectedIndex", Index=index)
  14. def add_files(file_names: list) -> int:
  15. if isinstance(file_names, str):
  16. file_names = glob.glob(file_names)
  17. return command.send("ImageListAddFiles?", FileNames=file_names)
  18. def index_of_file(file_name: str) -> int:
  19. return command.send("ImageListIndexOfFileName?", FileName=file_name)
  20. def get_file_name(index = None) -> str:
  21. return command.send("ImageListGetFileName?", Index=index)
  22. def remove_index(index: int):
  23. command.send("ImageListRemoveIndex", Index=index)
  24. def remove_unchecked():
  25. command.send("ImageListRemoveUnchecked")
  26. def remove_all():
  27. command.send("ImageListRemoveAll")
  28. def clear():
  29. remove_all()
  30. def uncheck_nonexistent():
  31. command.send("ImageListUncheckNonExistent")
  32. def open_first(skip_save) -> bool:
  33. return command.send("ImageListOpenFirst?", SkipSave=skip_save)
  34. def open_selected(skip_save):
  35. return command.send("ImageListOpenSelected", SkipSave=skip_save)
  36. def open_next(skip_save, silent = True, can_cycle = False) -> bool:
  37. return command.send("ImageListOpenNext?", SkipSave=skip_save, Silent=silent, CanCycle=can_cycle)
  38. def open_previous(skip_save, silent = True, can_cycle = False) -> bool:
  39. return command.send("ImageListOpenPrevious?", SkipSave=skip_save, Silent=silent, CanCycle=can_cycle)
  40. def iterate(skip_save):
  41. if open_first(skip_save):
  42. yield get_file_name()
  43. while open_next(skip_save):
  44. yield get_file_name()
  45. def get_file_checked(index = None) -> bool:
  46. return command.send("ImageListGetFileChecked?", Index=index)
  47. def set_file_checked(index = None, checked = True) -> bool:
  48. return command.send("ImageListSetFileChecked", Index=index, Checked=checked)
  49. def get_auto_uncheck_mode() -> str:
  50. return command.send("ImageListGetAutoUncheckMode?")
  51. def set_auto_uncheck_mode(mode: str):
  52. command.send("ImageListSetAutoUncheckMode", Mode=mode)
  53. def get_auto_zoom_fit() -> bool:
  54. return command.send("ImageListGetAutoZoomFit?")
  55. def set_auto_zoom_fit(enabled: bool):
  56. command.send("ImageListSetAutoZoomFit", Enabled=enabled)