pygui: simplified a couple of the other widget constructors
This commit is contained in:
parent
0dcfcbf4ea
commit
4eaecd6a7b
4 changed files with 23 additions and 30 deletions
|
@ -113,16 +113,15 @@ class Application(ttk.Frame):
|
|||
self.draw_canvas()
|
||||
self.draw_status()
|
||||
self.progress = Progressbar(self.right_frame, mode="indeterminate")
|
||||
self.menubar = Menubar(self.master, self)
|
||||
self.menubar = Menubar(self)
|
||||
self.master.config(menu=self.menubar)
|
||||
|
||||
def draw_canvas(self) -> None:
|
||||
width = self.guiconfig.preferences.width
|
||||
height = self.guiconfig.preferences.height
|
||||
canvas_frame = ttk.Frame(self.right_frame)
|
||||
canvas_frame.rowconfigure(0, weight=1)
|
||||
canvas_frame.columnconfigure(0, weight=1)
|
||||
canvas_frame.grid(sticky="nsew", pady=1)
|
||||
self.canvas = CanvasGraph(canvas_frame, self, self.core, width, height)
|
||||
self.canvas = CanvasGraph(canvas_frame, self, self.core)
|
||||
self.canvas.grid(sticky="nsew")
|
||||
scroll_y = ttk.Scrollbar(canvas_frame, command=self.canvas.yview)
|
||||
scroll_y.grid(row=0, column=1, sticky="ns")
|
||||
|
|
|
@ -41,19 +41,12 @@ class ShowVar(BooleanVar):
|
|||
def state(self) -> str:
|
||||
return tk.NORMAL if self.get() else tk.HIDDEN
|
||||
|
||||
def click_handler(self):
|
||||
def click_handler(self) -> None:
|
||||
self.canvas.itemconfigure(self.tag, state=self.state())
|
||||
|
||||
|
||||
class CanvasGraph(tk.Canvas):
|
||||
def __init__(
|
||||
self,
|
||||
master: tk.Widget,
|
||||
app: "Application",
|
||||
core: "CoreClient",
|
||||
width: int,
|
||||
height: int,
|
||||
):
|
||||
def __init__(self, master: tk.Widget, app: "Application", core: "CoreClient"):
|
||||
super().__init__(master, highlightthickness=0, background="#cccccc")
|
||||
self.app = app
|
||||
self.core = core
|
||||
|
@ -74,6 +67,8 @@ class CanvasGraph(tk.Canvas):
|
|||
self.drawing_edge = None
|
||||
self.rect = None
|
||||
self.shape_drawing = False
|
||||
width = self.app.guiconfig.preferences.width
|
||||
height = self.app.guiconfig.preferences.height
|
||||
self.default_dimensions = (width, height)
|
||||
self.current_dimensions = self.default_dimensions
|
||||
self.ratio = 1.0
|
||||
|
@ -571,10 +566,10 @@ class CanvasGraph(tk.Canvas):
|
|||
self.offset[0] * factor + event.x * (1 - factor),
|
||||
self.offset[1] * factor + event.y * (1 - factor),
|
||||
)
|
||||
logging.info("ratio: %s", self.ratio)
|
||||
logging.info("offset: %s", self.offset)
|
||||
self.app.statusbar.zoom.config(text="%s" % (int(self.ratio * 100)) + "%")
|
||||
|
||||
logging.debug("ratio: %s", self.ratio)
|
||||
logging.debug("offset: %s", self.offset)
|
||||
zoom_label = f"{self.ratio * 100:.0f}%"
|
||||
self.app.statusbar.zoom.config(text=zoom_label)
|
||||
if self.wallpaper:
|
||||
self.redraw_wallpaper()
|
||||
|
||||
|
@ -720,7 +715,7 @@ class CanvasGraph(tk.Canvas):
|
|||
if not self.app.core.is_runtime():
|
||||
self.delete_selected_objects()
|
||||
else:
|
||||
logging.info("node deletion is disabled during runtime state")
|
||||
logging.debug("node deletion is disabled during runtime state")
|
||||
|
||||
def double_click(self, event: tk.Event):
|
||||
selected = self.get_selected(event)
|
||||
|
@ -836,10 +831,10 @@ class CanvasGraph(tk.Canvas):
|
|||
self.draw_wallpaper(image)
|
||||
|
||||
def redraw_canvas(self, dimensions: Tuple[int, int] = None):
|
||||
logging.info("redrawing canvas to dimensions: %s", dimensions)
|
||||
logging.debug("redrawing canvas to dimensions: %s", dimensions)
|
||||
|
||||
# reset scale and move back to original position
|
||||
logging.info("resetting scaling: %s %s", self.ratio, self.offset)
|
||||
logging.debug("resetting scaling: %s %s", self.ratio, self.offset)
|
||||
factor = 1 / self.ratio
|
||||
self.scale(tk.ALL, self.offset[0], self.offset[1], factor, factor)
|
||||
self.move(tk.ALL, -self.offset[0], -self.offset[1])
|
||||
|
@ -858,11 +853,11 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def redraw_wallpaper(self):
|
||||
if self.adjust_to_dim.get():
|
||||
logging.info("drawing wallpaper to canvas dimensions")
|
||||
logging.debug("drawing wallpaper to canvas dimensions")
|
||||
self.resize_to_wallpaper()
|
||||
else:
|
||||
option = ScaleOption(self.scale_option.get())
|
||||
logging.info("drawing canvas using scaling option: %s", option)
|
||||
logging.debug("drawing canvas using scaling option: %s", option)
|
||||
if option == ScaleOption.UPPER_LEFT:
|
||||
self.wallpaper_upper_left()
|
||||
elif option == ScaleOption.CENTERED:
|
||||
|
@ -908,10 +903,10 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def copy(self):
|
||||
if self.core.is_runtime():
|
||||
logging.info("copy is disabled during runtime state")
|
||||
logging.debug("copy is disabled during runtime state")
|
||||
return
|
||||
if self.selection:
|
||||
logging.info("to copy nodes: %s", self.selection)
|
||||
logging.debug("to copy nodes: %s", self.selection)
|
||||
self.to_copy.clear()
|
||||
for node_id in self.selection.keys():
|
||||
canvas_node = self.nodes[node_id]
|
||||
|
@ -919,7 +914,7 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def paste(self):
|
||||
if self.core.is_runtime():
|
||||
logging.info("paste is disabled during runtime state")
|
||||
logging.debug("paste is disabled during runtime state")
|
||||
return
|
||||
# maps original node canvas id to copy node canvas id
|
||||
copy_map = {}
|
||||
|
|
|
@ -47,12 +47,11 @@ class Menubar(tk.Menu):
|
|||
Core menubar
|
||||
"""
|
||||
|
||||
def __init__(self, master: tk.Tk, app: "Application", **kwargs) -> None:
|
||||
def __init__(self, app: "Application") -> None:
|
||||
"""
|
||||
Create a CoreMenubar instance
|
||||
"""
|
||||
super().__init__(master, **kwargs)
|
||||
self.master.config(menu=self)
|
||||
super().__init__(app)
|
||||
self.app = app
|
||||
self.core = app.core
|
||||
self.canvas = app.canvas
|
||||
|
|
|
@ -13,8 +13,8 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class StatusBar(ttk.Frame):
|
||||
def __init__(self, master: tk.Widget, app: "Application", **kwargs):
|
||||
super().__init__(master, **kwargs)
|
||||
def __init__(self, master: tk.Widget, app: "Application"):
|
||||
super().__init__(master)
|
||||
self.app = app
|
||||
self.status = None
|
||||
self.statusvar = tk.StringVar()
|
||||
|
|
Loading…
Reference in a new issue