From 841919160fd3c8b938fffbcb5c8539e5841e69e6 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 2 Jun 2018 22:35:43 +0300 Subject: [PATCH] - added the flexibility to add the menu entries (Actions) created by the instances of FlatCAMTool, in any position within the application menu's. install method of FlatCAMTool accept now the following kwargs: 'pos' = it is the menu where we want the Action installed. By default, if no 'pos' arg is provided, the tool will be install in the menutool menu (as before) 'before' = it is the position within the previously selected menu where, before it, we will install our new Action (menu entry) generated by the FlatCAMTool install method. By default, if no 'before' is provided, the action will be installed in the current last position in the menu. --- FlatCAMTool.py | 36 +++++++++++++++++++++++++++++++----- MeasurementTool.py | 4 ++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/FlatCAMTool.py b/FlatCAMTool.py index 45c6a0e8..98b3a13b 100644 --- a/FlatCAMTool.py +++ b/FlatCAMTool.py @@ -32,13 +32,39 @@ class FlatCAMTool(QtGui.QWidget): self.menuAction = None - def install(self, icon=None, separator=None): - if icon is None: - self.menuAction = self.app.ui.menutool.addAction(self.toolName) + def install(self, icon=None, separator=None, **kwargs): + before = None + + # 'pos' is the menu where the Action has to be installed + # if no 'pos' kwarg is provided then by default our Action will be installed in the menutool + # as it previously was + if 'pos' in kwargs: + pos = kwargs['pos'] else: - self.menuAction = self.app.ui.menutool.addAction(icon, self.toolName) + pos = self.app.ui.menutool + + # 'before' is the Action in the menu stated by 'pos' kwarg, before which we want our Action to be installed + # if 'before' kwarg is not provided, by default our Action will be added in the last place. + if 'before' in kwargs: + before = (kwargs['before']) + + # create the new Action + self.menuAction = QtGui.QAction(self) + # if provided, add an icon to this Action + if icon is not None: + self.menuAction.setIcon(icon) + # set the text name of the Action, which will be displayed in the menu + self.menuAction.setText(self.toolName) + # add a ToolTip to the new Action + # self.menuAction.setToolTip(self.toolTip) # currently not available + + # insert the action in the position specified by 'before' and 'pos' kwargs + pos.insertAction(before, self.menuAction) + + # if separator parameter is True add a Separator after the newly created Action if separator is True: - self.app.ui.menutool.addSeparator() + pos.addSeparator() + self.menuAction.triggered.connect(self.run) def run(self): diff --git a/MeasurementTool.py b/MeasurementTool.py index 3f70c6e6..2e2e76b1 100644 --- a/MeasurementTool.py +++ b/MeasurementTool.py @@ -29,8 +29,8 @@ class Measurement(FlatCAMTool): self.click_subscription = None self.move_subscription = None - def install(self, icon=None, separator=None): - FlatCAMTool.install(self, icon, separator) + def install(self, icon=None, separator=None, **kwargs): + FlatCAMTool.install(self, icon, separator, **kwargs) self.app.ui.right_layout.addWidget(self) self.app.plotcanvas.mpl_connect('key_press_event', self.on_key_press)