diff --git a/pyflow/graphics/view.py b/pyflow/graphics/view.py index 677280bd..a004e0a0 100644 --- a/pyflow/graphics/view.py +++ b/pyflow/graphics/view.py @@ -27,6 +27,7 @@ BLOCKFILES_PATH = os.path.join(BLOCK_PATH, "blockfiles") EPS: float = 1e-10 # To check if blocks are of size 0 +ZOOM_INCREMENT = 1.2 LOGGER = get_logger(__name__) @@ -376,6 +377,16 @@ def setZoom(self, new_zoom: float): self.scale(zoom_factor, zoom_factor) self.zoom = new_zoom + def zoomIn(self): + """Zoom in.""" + + self.setZoom(self.zoom * ZOOM_INCREMENT) + + def zoomOut(self): + """Zoom out""" + + self.setZoom(self.zoom / ZOOM_INCREMENT) + def deleteSelected(self): """Delete selected items from the current scene.""" scene = self.scene() @@ -510,8 +521,10 @@ def drag_edge(self, event: QMouseEvent, action="press"): ): # Link a new CodeBlock under the selected block parent: CodeBlock = item_at_click.block - empty_code_block_path: str = os.path.join(BLOCKFILES_PATH, "empty.pfb") - new_block = self.scene().create_block_from_file(empty_code_block_path, 0, 0) + empty_code_block_path: str = os.path.join(BLOCKFILES_PATH, "empty.pfb") + new_block = self.scene().create_block_from_file( + empty_code_block_path, 0, 0 + ) parent.link_and_place(new_block) scene.history.checkpoint( "Created a new linked block", set_modified=True diff --git a/pyflow/graphics/window.py b/pyflow/graphics/window.py index b501a505..8f3db80c 100644 --- a/pyflow/graphics/window.py +++ b/pyflow/graphics/window.py @@ -181,6 +181,18 @@ def createActions(self): shortcut=" ", triggered=self.onMoveToItems, ) + self._actZoomIn = QAction( + "Zoom in", + statusTip="Zoom in", + shortcut=QKeySequence.ZoomIn, + triggered=self.onZoomIn, + ) + self._actZoomOut = QAction( + "Zoom out", + statusTip="Zoom out", + shortcut=QKeySequence.ZoomOut, + triggered=self.onZoomOut, + ) # Window self._actClose = QAction( @@ -252,6 +264,8 @@ def createMenus(self): self.thememenu = self.viewmenu.addMenu("Theme") self.thememenu.aboutToShow.connect(self.updateThemeMenu) self.viewmenu.addAction(self._actViewItems) + self.viewmenu.addAction(self._actZoomIn) + self.viewmenu.addAction(self._actZoomOut) self.windowMenu = self.menuBar().addMenu("&Window") self.updateWindowMenu() @@ -543,6 +557,18 @@ def onMoveToItems(self): if current_window is not None and isinstance(current_window, Widget): current_window.moveToItems() + def onZoomIn(self): + """Zoom in, in the current window..""" + current_window = self.activeMdiChild() + if current_window is not None and isinstance(current_window, Widget): + current_window.view.zoomIn() + + def onZoomOut(self): + """Zoom out, in the current window.""" + current_window = self.activeMdiChild() + if current_window is not None and isinstance(current_window, Widget): + current_window.view.zoomOut() + def setTheme(self, theme_index): """Set the theme of the application.""" theme_manager().selected_theme_index = theme_index