This commit is contained in:
klemek
2021-08-26 15:43:55 +02:00
parent 8bab51aa3a
commit 5bf5f27128
+19 -17
View File
@@ -295,7 +295,7 @@ class ImageView(ttk.Frame):
self.bind("<MouseWheel>", self.zoom_canvas) self.bind("<MouseWheel>", self.zoom_canvas)
self.bind("<Button-4>", self.zoom_canvas_up) self.bind("<Button-4>", self.zoom_canvas_up)
self.bind("<Button-5>", self.zoom_canvas_down) self.bind("<Button-5>", self.zoom_canvas_down)
def update(self, image: Image) -> None: def update(self, image: Image) -> None:
if self.current_image != image: if self.current_image != image:
self.draw_scale = self.INITIAL_DRAW_SCALE self.draw_scale = self.INITIAL_DRAW_SCALE
@@ -368,7 +368,7 @@ class Explorer(ttk.Frame):
self.current_file = None self.current_file = None
self.update_callback = update_callback self.update_callback = update_callback
self.explorer = ttk.Treeview(self, columns=("size")) self.explorer = ttk.Treeview(self, columns=("size"))
self.explorer.heading("#0", text="name") self.explorer.heading("#0", text="name")
self.explorer.heading("size", text="size") self.explorer.heading("size", text="size")
@@ -377,15 +377,13 @@ class Explorer(ttk.Frame):
self.explorer.grid(row=0, column=0, sticky=(N, S, W)) self.explorer.grid(row=0, column=0, sticky=(N, S, W))
self.explorer.bind("<<TreeviewSelect>>", self.explorer_item_click) self.explorer.bind("<<TreeviewSelect>>", self.explorer_item_click)
yscrollbar = ttk.Scrollbar( yscrollbar = ttk.Scrollbar(self, orient="vertical", command=self.explorer.yview)
self, orient="vertical", command=self.explorer.yview
)
yscrollbar.grid(row=0, column=1, sticky=(N, S, W)) yscrollbar.grid(row=0, column=1, sticky=(N, S, W))
self.explorer.configure(yscrollcommand=yscrollbar.set) self.explorer.configure(yscrollcommand=yscrollbar.set)
self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1)
@property @property
def current_image(self) -> Optional[Image]: def current_image(self) -> Optional[Image]:
if self.current_file is None or self.explorer.focus() == "": if self.current_file is None or self.explorer.focus() == "":
@@ -417,7 +415,7 @@ class Explorer(ttk.Frame):
text=f"{image.name}{'*' if image.modified else ''}", text=f"{image.name}{'*' if image.modified else ''}",
values=[f"{image.width}x{image.height}"], values=[f"{image.width}x{image.height}"],
) )
def explorer_item_click(self, event) -> None: def explorer_item_click(self, event) -> None:
self.update_callback() self.update_callback()
@@ -437,7 +435,7 @@ class App(ttk.Frame):
self.image_view = ImageView(self) self.image_view = ImageView(self)
self.image_view.grid(column=1, row=0, sticky=(N, S, E, W)) self.image_view.grid(column=1, row=0, sticky=(N, S, E, W))
self.init_menus() self.init_menus()
self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)
@@ -587,28 +585,32 @@ class App(ttk.Frame):
) )
i += 1 i += 1
self.menu_bmp_need_image += [i] self.menu_bmp_need_image += [i]
def update_menus(self) -> None: def update_menus(self) -> None:
for index in self.menu_file_need_file: for index in self.menu_file_need_file:
self.menu_file.entryconfigure( self.menu_file.entryconfigure(
index, index,
state=("normal" if self.current_file is not None else "disabled"), state=("normal" if self.current_file is not None else "disabled"),
) )
self.menubar.entryconfigure("Image", state=("normal" if self.current_image is not None else "disabled")) self.menubar.entryconfigure(
self.menubar.entryconfigure("Bitmap", state=("normal" if self.current_file is not None else "disabled")) "Image", state=("normal" if self.current_image is not None else "disabled")
)
self.menubar.entryconfigure(
"Bitmap", state=("normal" if self.current_file is not None else "disabled")
)
for index in self.menu_bmp_need_image: for index in self.menu_bmp_need_image:
self.menu_bmp.entryconfigure( self.menu_bmp.entryconfigure(
index, index,
state=("normal" if self.current_image is not None else "disabled"), state=("normal" if self.current_image is not None else "disabled"),
) )
def open_file(self, path: Optional[str]) -> None: def open_file(self, path: Optional[str]) -> None:
if path is None: if path is None:
self.current_file = None self.current_file = None
else: else:
self.current_file = File(path if path != "" else None) self.current_file = File(path if path != "" else None)
self.update(force=True) self.update(force=True)
def save_file(self, path: Optional[str] = None) -> None: def save_file(self, path: Optional[str] = None) -> None:
if path == "": if path == "":
path = filedialog.asksaveasfilename() path = filedialog.asksaveasfilename()
@@ -620,7 +622,7 @@ class App(ttk.Frame):
def edit_image_name(self) -> None: def edit_image_name(self) -> None:
pass # TODO edit image name action pass # TODO edit image name action
def edit_image_size(self) -> None: def edit_image_size(self) -> None:
pass # TODO edit image size action pass # TODO edit image size action
@@ -629,7 +631,7 @@ class App(ttk.Frame):
def move_image_down(self) -> None: def move_image_down(self) -> None:
pass # TODO move image actions pass # TODO move image actions
def delete_image(self) -> None: def delete_image(self) -> None:
pass # TODO delete image action pass # TODO delete image action
@@ -669,4 +671,4 @@ if __name__ == "__main__":
# TODO remove debug # TODO remove debug
app.open_file("../watchfaces/tetris-2.0/tetris.h") app.open_file("../watchfaces/tetris-2.0/tetris.h")
app.mainloop() app.mainloop()