Przeglądaj źródła

script: add selection functions

circular17 5 lat temu
rodzic
commit
f8d7d59cde

+ 2 - 0
lazpaint/image/uimageaction.pas

@@ -136,6 +136,7 @@ begin
   Scripting.RegisterScriptFunction('EditPasteAsNewLayer',@GenericScriptFunction,ARegister);
   Scripting.RegisterScriptFunction('EditSelectAll',@GenericScriptFunction,ARegister);
   Scripting.RegisterScriptFunction('EditSelectionFit',@GenericScriptFunction,ARegister);
+  Scripting.RegisterScriptFunction('IsSelectionMaskEmpty',@GenericScriptFunction,ARegister);
   Scripting.RegisterScriptFunction('LayerHorizontalFlip',@GenericScriptFunction,ARegister);
   Scripting.RegisterScriptFunction('LayerVerticalFlip',@GenericScriptFunction,ARegister);
   Scripting.RegisterScriptFunction('LayerAddNew',@GenericScriptFunction,ARegister);
@@ -196,6 +197,7 @@ begin
   if f = 'EditPasteAsNewLayer' then PasteAsNewLayer else
   if f = 'EditSelectAll' then SelectAll else
   if f = 'EditSelectionFit' then SelectionFit else
+  if f = 'IsSelectionMaskEmpty' then AVars.Booleans['Result'] := Image.SelectionMaskEmpty else
   if f = 'LayerHorizontalFlip' then HorizontalFlip(foCurrentLayer) else
   if f = 'LayerVerticalFlip' then VerticalFlip(foCurrentLayer) else
   if f = 'LayerAddNew' then NewLayer else

+ 29 - 0
lazpaintscripts/lazpaint/selection.py

@@ -0,0 +1,29 @@
+from lazpaint import command
+
+if __name__ == "__main__":
+  command.show_message("Library to access selection.")
+
+def invert():
+  command.send("EditInvertSelection")
+
+def deselect():
+  command.send("EditDeselect")
+
+def copy():
+  command.send("EditCopy")
+
+def cut():
+  command.send("EditCut")
+
+def delete():
+  command.send("EditDeleteSelection")
+
+def select_all():
+  command.send("EditSelectAll")
+
+def fit():
+  command.send("EditSelectionFit")
+
+def is_mask_empty():
+  return command.send("IsSelectionMaskEmpty?")
+

+ 12 - 5
lazpaintscripts/test_file.py

@@ -1,11 +1,18 @@
-from lazpaint import image, io, colors, layer
+from lazpaint import image, io, colors, layer, selection, command
+
+if selection.is_mask_empty():
+  selection_name = ""
+else: 
+  selection_name = io.save_selection_as("script_test_selection.png")
+  command.show_message("Selection saved")
 
-selection_name = io.save_selection_as("script_test_selection.png")
 image.new(100, 100, colors.RED)
-io.load_selection(selection_name)
-io.show_message("Selection restored")
 
-file_name = file_save_as("script_test_file.png", skip_options=True)
+if selection_name != "":
+  io.load_selection(selection_name)
+  command.show_message("Selection restored")
+
+file_name = io.save_as("script_test_file.png", skip_options=True)
 image.new(100, 100, colors.LIME)
 io.save_as(file_name, validate=True, overwrite=True, skip_options=True)