ソースを参照

script undo/redo

johann 5 年 前
コミット
e9afb428c6
2 ファイル変更18 行追加9 行削除
  1. 12 9
      scripts/layer_shadow.py
  2. 6 0
      scripts/lazpaint/image.py

+ 12 - 9
scripts/layer_shadow.py

@@ -1,16 +1,19 @@
 from lazpaint import colors, image, layer, filters, dialog, tools
 
 chosen_radius = 10
-source_id = layer.get_id()
+if layer.is_empty():
+    dialog.show_message("Layer is empty")
+    exit()
+
+layer.duplicate()
+shadow_index = image.get_layer_index()
+image.move_layer_index(shadow_index, shadow_index-1)
+colors.lightness(shift=-1)
+opacity = layer.get_opacity() 
+layer.set_opacity(opacity*2/3)
 
 while True:
-    layer.duplicate()
-    shadow_index = image.get_layer_index()
-    image.move_layer_index(shadow_index, shadow_index-1)
-    colors.lightness(shift=-1)
     filters.blur(radius=chosen_radius)
-    opacity = layer.get_opacity() 
-    layer.set_opacity(opacity*2/3)
     tools.choose(tools.MOVE_LAYER)
     tools.mouse([(0,0),(10,10)])
     new_radius = dialog.input_value("Radius:", chosen_radius)
@@ -18,6 +21,6 @@ while True:
         break
     else:
         chosen_radius = new_radius
-        layer.remove()
-        layer.select_id(source_id)
+        image.undo()
+        image.undo()
 

+ 6 - 0
scripts/lazpaint/image.py

@@ -115,3 +115,9 @@ def canvas_size(width, height, anchor=ANCHOR_MIDDLE):
 def repeat(width, height, anchor=ANCHOR_MIDDLE, flip=False):
   command.send("ImageRepeat", Width=width, Height=height, Anchor=anchor, Flip=flip)
 
+def undo():
+  command.send("EditUndo")
+
+def redo():
+  command.send("EditRedo")
+