pygui: updates to properly save and load canvas size for each canvas separately
This commit is contained in:
parent
2b89503432
commit
1ce6e51318
4 changed files with 13 additions and 17 deletions
|
@ -24,7 +24,7 @@ class SizeAndScaleDialog(Dialog):
|
||||||
super().__init__(app, "Canvas Size and Scale")
|
super().__init__(app, "Canvas Size and Scale")
|
||||||
self.manager: CanvasManager = self.app.manager
|
self.manager: CanvasManager = self.app.manager
|
||||||
self.section_font: font.Font = font.Font(weight=font.BOLD)
|
self.section_font: font.Font = font.Font(weight=font.BOLD)
|
||||||
width, height = self.manager.current_dimensions
|
width, height = self.manager.current().current_dimensions
|
||||||
self.pixel_width: tk.IntVar = tk.IntVar(value=width)
|
self.pixel_width: tk.IntVar = tk.IntVar(value=width)
|
||||||
self.pixel_height: tk.IntVar = tk.IntVar(value=height)
|
self.pixel_height: tk.IntVar = tk.IntVar(value=height)
|
||||||
location = self.app.core.session.location
|
location = self.app.core.session.location
|
||||||
|
@ -189,7 +189,7 @@ class SizeAndScaleDialog(Dialog):
|
||||||
|
|
||||||
def click_apply(self) -> None:
|
def click_apply(self) -> None:
|
||||||
width, height = self.pixel_width.get(), self.pixel_height.get()
|
width, height = self.pixel_width.get(), self.pixel_height.get()
|
||||||
self.manager.redraw_canvases((width, height))
|
self.manager.redraw_canvas((width, height))
|
||||||
location = self.app.core.session.location
|
location = self.app.core.session.location
|
||||||
location.x = self.x.get()
|
location.x = self.x.get()
|
||||||
location.y = self.y.get()
|
location.y = self.y.get()
|
||||||
|
|
|
@ -827,6 +827,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
wallpaper=wallpaper_path,
|
wallpaper=wallpaper_path,
|
||||||
wallpaper_style=self.scale_option.get(),
|
wallpaper_style=self.scale_option.get(),
|
||||||
fit_image=self.adjust_to_dim.get(),
|
fit_image=self.adjust_to_dim.get(),
|
||||||
|
dimensions=self.current_dimensions,
|
||||||
)
|
)
|
||||||
|
|
||||||
def parse_metadata(self, config: Dict[str, Any]) -> None:
|
def parse_metadata(self, config: Dict[str, Any]) -> None:
|
||||||
|
@ -834,6 +835,9 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.adjust_to_dim.set(fit_image)
|
self.adjust_to_dim.set(fit_image)
|
||||||
wallpaper_style = config.get("wallpaper_style", 1)
|
wallpaper_style = config.get("wallpaper_style", 1)
|
||||||
self.scale_option.set(wallpaper_style)
|
self.scale_option.set(wallpaper_style)
|
||||||
|
dimensions = config.get("dimensions")
|
||||||
|
if dimensions:
|
||||||
|
self.redraw_canvas(dimensions)
|
||||||
wallpaper = config.get("wallpaper")
|
wallpaper = config.get("wallpaper")
|
||||||
if wallpaper:
|
if wallpaper:
|
||||||
wallpaper = Path(wallpaper)
|
wallpaper = Path(wallpaper)
|
||||||
|
|
|
@ -89,7 +89,6 @@ class CanvasManager:
|
||||||
self.app.guiconfig.preferences.width,
|
self.app.guiconfig.preferences.width,
|
||||||
self.app.guiconfig.preferences.height,
|
self.app.guiconfig.preferences.height,
|
||||||
)
|
)
|
||||||
self.current_dimensions: Tuple[int, int] = self.default_dimensions
|
|
||||||
self.show_node_labels: ShowVar = ShowNodeLabels(
|
self.show_node_labels: ShowVar = ShowNodeLabels(
|
||||||
self, tags.NODE_LABEL, value=True
|
self, tags.NODE_LABEL, value=True
|
||||||
)
|
)
|
||||||
|
@ -274,19 +273,15 @@ class CanvasManager:
|
||||||
if not self.canvases:
|
if not self.canvases:
|
||||||
self.add_canvas()
|
self.add_canvas()
|
||||||
|
|
||||||
def redraw_canvases(self, dimensions: Tuple[int, int]) -> None:
|
def redraw_canvas(self, dimensions: Tuple[int, int]) -> None:
|
||||||
for canvas in self.canvases.values():
|
canvas = self.current()
|
||||||
canvas.redraw_canvas(dimensions)
|
canvas.redraw_canvas(dimensions)
|
||||||
if canvas.wallpaper:
|
if canvas.wallpaper:
|
||||||
canvas.redraw_wallpaper()
|
canvas.redraw_wallpaper()
|
||||||
|
|
||||||
def get_metadata(self) -> Dict[str, Any]:
|
def get_metadata(self) -> Dict[str, Any]:
|
||||||
canvases = [x.get_metadata() for x in self.all()]
|
canvases = [x.get_metadata() for x in self.all()]
|
||||||
return dict(
|
return dict(gridlines=self.show_grid.get(), canvases=canvases)
|
||||||
gridlines=self.app.manager.show_grid.get(),
|
|
||||||
dimensions=self.app.manager.current_dimensions,
|
|
||||||
canvases=canvases,
|
|
||||||
)
|
|
||||||
|
|
||||||
def parse_metadata_canvas(self, metadata: Dict[str, Any]) -> None:
|
def parse_metadata_canvas(self, metadata: Dict[str, Any]) -> None:
|
||||||
# canvas setting
|
# canvas setting
|
||||||
|
@ -296,11 +291,8 @@ class CanvasManager:
|
||||||
return
|
return
|
||||||
canvas_config = json.loads(canvas_config)
|
canvas_config = json.loads(canvas_config)
|
||||||
# get configured dimensions and gridlines option
|
# get configured dimensions and gridlines option
|
||||||
dimensions = self.default_dimensions
|
|
||||||
dimensions = canvas_config.get("dimensions", dimensions)
|
|
||||||
gridlines = canvas_config.get("gridlines", True)
|
gridlines = canvas_config.get("gridlines", True)
|
||||||
self.show_grid.set(gridlines)
|
self.show_grid.set(gridlines)
|
||||||
self.redraw_canvases(dimensions)
|
|
||||||
|
|
||||||
# get background configurations
|
# get background configurations
|
||||||
for canvas_config in canvas_config.get("canvases", []):
|
for canvas_config in canvas_config.get("canvases", []):
|
||||||
|
|
|
@ -453,7 +453,7 @@ class Menubar(tk.Menu):
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
||||||
def click_autogrid(self) -> None:
|
def click_autogrid(self) -> None:
|
||||||
width, height = self.manager.current_dimensions
|
width, height = self.manager.current().current_dimensions
|
||||||
padding = (images.NODE_SIZE / 2) + 10
|
padding = (images.NODE_SIZE / 2) + 10
|
||||||
layout_size = padding + images.NODE_SIZE
|
layout_size = padding + images.NODE_SIZE
|
||||||
col_count = width // layout_size
|
col_count = width // layout_size
|
||||||
|
|
Loading…
Reference in a new issue