def getMenuAction(self, menu_action, title='notitle', action_name='noaction'): # ToDo: Clean this up, it is very hacky env = { 'app': QApplication.instance(), 'win': self, 'action': actions, } if action_name is not None: try: mod, action = action_name.split('.', 1) method = getattr(env.get(mod, self), action) menu_action.triggered.connect(method) return except: pass try: actions.bindWidget(menu_action, action_name) return except actions.InvalidAction: LOG.exception('Error binding menu action %s', action_name) msg = "The <b>{}</b> action specified for the " \ "<b>{}</b> menu item could not be triggered. " \ "Check the YAML config file for errors." \ .format(action_name or '', title.replace('&', '')) menu_action.triggered.connect( lambda: QMessageBox.critical(self, "Menu Action Error!", msg))
def actionName(self, action_name): """Sets the name of the action the dial should trigger. Args: action_name (str) : A fully qualified action name. """ self._action_name = action_name bindWidget(self, action_name)
def actionName(self, action_name): """Sets the name of the action the button should trigger and binds the widget to that action. Args: action_name (str) : A fully qualified action name. """ self._action_name = action_name bindWidget(self, action_name)
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("Brender VCP") # ========================================================================== # Add/Override methods and slots below to customize the main window # ========================================================================== actions.bindWidget(self.flood, action='coolant.flood.toggle') actions.bindWidget(self.floodCheckBox, action="coolant.flood.toggle")
def __init__(self, parent=None, axes=None): super(HomingMenu, self).__init__(parent) self.status = getPlugin('status') home_all = QAction(parent=self, text="Home &All") actions.bindWidget(home_all, 'machine.home.all') self.addAction(home_all) # add homing actions for each axis for aletter in axes or INFO.AXIS_LETTER_LIST: home_axis = QAction(parent=self, text="Home &{}".format(aletter.upper())) actions.bindWidget(home_axis, 'machine.home.axis:{}'.format(aletter.lower())) self.addAction(home_axis) home_axis.setVisible(True) self.setEnabled(self.status.stat.state == linuxcnc.STATE_ON) self.status.on.notify(lambda on: self.setEnabled(on))
def getMenuAction(self, menu, title='notitle', action_name='noaction', args=[], kwargs={}): # ToDo: Clean this up, it is very hacky env = {'app': QApplication.instance(), 'win': self, 'action': actions, } if action_name is not None: if action_name.startswith('settings.'): setting_id = action_name[len('settings.'):] setting = getSetting(setting_id) if setting: if setting.enum_options is not None: submenu = QMenu(parent=self, title=title) group = QActionGroup(self) group.setExclusive(True) group.triggered.connect(lambda a: setting.setValue(a.data())) def update(group, val): for act in group.actions(): if act.data() == val: act.setChecked(True) break for num, opt in enumerate(setting.enum_options): act = QAction(parent=self, text=opt) act.setCheckable(True) if setting.value == num: act.setChecked(True) act.setData(num) setting.notify(lambda v: update(group, v)) act.setActionGroup(group) submenu.addAction(act) menu.addMenu(submenu) elif setting.value_type == bool: # works for bool settings menu_action = QAction(parent=self, text=title) menu_action.setCheckable(True) menu_action.triggered.connect(setting.setValue) setting.notify(menu_action.setChecked) menu.addAction(menu_action) return try: menu_action = QAction(parent=self, text=title) mod, action = action_name.split('.', 1) method = getattr(env.get(mod, self), action) if menu_action.isCheckable(): menu_action.triggered.connect(method) else: menu_action.triggered.connect(lambda checked: method(*args, **kwargs)) menu.addAction(menu_action) return except: pass try: menu_action = QAction(parent=self, text=title) actions.bindWidget(menu_action, action_name) menu.addAction(menu_action) return except actions.InvalidAction: LOG.exception('Error binding menu action %s', action_name) menu_action = QAction(parent=self, text=title) msg = "The <b>{}</b> action specified for the " \ "<b>{}</b> menu item could not be triggered. " \ "Check the YAML config file for errors." \ .format(action_name or '', title.replace('&', '')) menu_action.triggered.connect(lambda: QMessageBox.critical(self, "Menu Action Error!", msg)) menu.addAction(menu_action)
def actionName(self, action_name): self._action_name = action_name bindWidget(self, action_name)
def actionName(self, action_name): self._action_name = action_name try: bindWidget(self, action_name) except InvalidAction: pass