|
@@ -1,26 +1,124 @@
|
|
|
-from lazpaint import colors, image, layer, filters, dialog, tools
|
|
|
+from lazpaint import dialog
|
|
|
+
|
|
|
+try:
|
|
|
+ from tkinter import *
|
|
|
+except ImportError:
|
|
|
+ dialog.show_message("Please install tkinter.")
|
|
|
+ exit()
|
|
|
+
|
|
|
+from lazpaint import colors, image, layer, filters, tools
|
|
|
|
|
|
-chosen_radius = 10
|
|
|
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)
|
|
|
+############ image processing
|
|
|
|
|
|
-while True:
|
|
|
- filters.blur(radius=chosen_radius)
|
|
|
- tools.choose(tools.MOVE_LAYER)
|
|
|
- tools.mouse([(0,0),(10,10)])
|
|
|
- new_radius = dialog.input_value("Radius:", chosen_radius)
|
|
|
- if new_radius == chosen_radius:
|
|
|
- break
|
|
|
- else:
|
|
|
- chosen_radius = new_radius
|
|
|
+chosen_radius = 10
|
|
|
+chosen_offset = (10, 10)
|
|
|
+
|
|
|
+#create shadow layer
|
|
|
+shadow_layer_done = False
|
|
|
+def undo_shadow_layer():
|
|
|
+ global shadow_layer_done
|
|
|
+ if shadow_layer_done:
|
|
|
+ image.undo()
|
|
|
+ image.undo()
|
|
|
image.undo()
|
|
|
image.undo()
|
|
|
+ shadow_layer_done = False
|
|
|
+
|
|
|
+def create_shadow_layer():
|
|
|
+ global shadow_layer_done
|
|
|
+ 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)
|
|
|
+ shadow_layer_done = True
|
|
|
+
|
|
|
+blur_done = False
|
|
|
+def undo_blur():
|
|
|
+ global blur_done
|
|
|
+ if blur_done:
|
|
|
+ image.undo()
|
|
|
+ image.undo()
|
|
|
+ blur_done = False
|
|
|
+
|
|
|
+def apply_blur():
|
|
|
+ global blur_done
|
|
|
+ undo_blur()
|
|
|
+ filters.blur(radius=chosen_radius)
|
|
|
+ tools.choose(tools.MOVE_LAYER)
|
|
|
+ tools.mouse([(0,0), chosen_offset])
|
|
|
+ blur_done = True
|
|
|
+
|
|
|
+######## interface
|
|
|
+
|
|
|
+def button_ok_click():
|
|
|
+ exit()
|
|
|
+
|
|
|
+def button_cancel_click():
|
|
|
+ undo_blur()
|
|
|
+ undo_shadow_layer()
|
|
|
+ exit()
|
|
|
+
|
|
|
+scale_radius_update_job = None
|
|
|
+
|
|
|
+def scale_radius_update_do():
|
|
|
+ global scale_radius_update_job, chosen_radius, scale_radius
|
|
|
+ chosen_radius = scale_radius.get()
|
|
|
+ apply_blur()
|
|
|
+ scale_radius_update_job = None
|
|
|
+
|
|
|
+def scale_radius_update(event):
|
|
|
+ global window, scale_radius_update_job
|
|
|
+ if scale_radius_update_job:
|
|
|
+ window.after_cancel(scale_radius_update_job)
|
|
|
+ scale_radius_update_job = window.after(500, scale_radius_update_do)
|
|
|
+
|
|
|
+window = Tk()
|
|
|
+window.title("Layer shadow")
|
|
|
+window.resizable(False, False)
|
|
|
+
|
|
|
+frame = Frame(window)
|
|
|
+frame.pack()
|
|
|
+
|
|
|
+label_radius = Label(frame, text="Radius:")
|
|
|
+label_radius.grid(column=0, row=0)
|
|
|
+scale_radius = Scale(frame, from_=1, to=100, orient=HORIZONTAL, command=scale_radius_update)
|
|
|
+scale_radius.grid(column=1, row=0, columnspan=2, sticky=W+E, padx=10)
|
|
|
+scale_radius.set(chosen_radius)
|
|
|
+
|
|
|
+label_offset = Label(frame, text="Offset:")
|
|
|
+label_offset.grid(column=0, row=1)
|
|
|
+scale_offset_x = Scale(frame, from_=-100, to=100, orient=HORIZONTAL)
|
|
|
+scale_offset_x.grid(column=1, row=1, sticky=W+E, padx=10)
|
|
|
+scale_offset_x.set(chosen_offset[0])
|
|
|
+scale_offset_y = Scale(frame, from_=-100, to=100, orient=HORIZONTAL)
|
|
|
+scale_offset_y.grid(column=2, row=1, sticky=W+E, padx=10)
|
|
|
+scale_offset_y.set(chosen_offset[1])
|
|
|
+
|
|
|
+frame.columnconfigure(0, pad=20)
|
|
|
+frame.columnconfigure(1, weight=1)
|
|
|
+frame.columnconfigure(2, weight=1)
|
|
|
+frame.rowconfigure(0, pad=20)
|
|
|
+frame.rowconfigure(1, pad=20)
|
|
|
+
|
|
|
+button_ok = Button(window, text="Ok", command=button_ok_click)
|
|
|
+button_ok.pack(side=RIGHT, padx=10, pady=10)
|
|
|
+button_cancel = Button(window, text="Cancel", command=button_cancel_click)
|
|
|
+button_cancel.pack(side=RIGHT, pady=10)
|
|
|
+
|
|
|
+create_shadow_layer()
|
|
|
+apply_blur()
|
|
|
+
|
|
|
+window.update()
|
|
|
+window_width = window.winfo_width()
|
|
|
+screen_width = window.winfo_screenwidth()
|
|
|
+window.geometry('+%d+0' % (int((screen_width - window_width) / 2)))
|
|
|
+
|
|
|
+window.mainloop()
|
|
|
|
|
|
+button_cancel_click()
|