def _init_menu_buttons(self): """ Add the two menu buttons to the tool bar. Currently two are defined: View - for changing the view of the active window Data Processing - for applying a data processing step to the data. :return: """ self._option_buttons = [ self.ui.view_option_button, self.ui.cube_option_button ] # Create the View Menu view_menu = self._dict_to_menu( OrderedDict([ ('Hide Axes', ['checkable', self._toggle_viewer_axes]), ('Hide Toolbars', ['checkable', self._toggle_toolbars]), ('Hide Spaxel Value Tooltip', ['checkable', self._toggle_hover_value]), ('Hide Stats', ['checkable', self._toggle_stats_display]), ('Convert Flux Units', lambda: self._open_dialog('Convert Flux Units', None)), ('Wavelength Units/Redshift', lambda: self._open_dialog('Wavelength Units/Redshift', None)) ])) # Add toggle RA-DEC format: format_menu = view_menu.addMenu("RA-DEC Format") format_action_group = QActionGroup(format_menu) self.ra_dec_format_menu = format_menu # Make sure to change all instances of the the names # of the formats if modifications are made to them. for format_name in ["Sexagesimal", "Decimal Degrees"]: act = QAction(format_name, format_menu) act.triggered.connect(self._toggle_all_coords_in_degrees) act.setActionGroup(format_action_group) act.setCheckable(True) act.setChecked( True) if format == "Sexagesimal" else act.setChecked(False) format_menu.addAction(act) self.ui.view_option_button.setMenu(view_menu) # Create the Data Processing Menu cube_menu = self._dict_to_menu( OrderedDict([ ('Collapse Cube', lambda: self._open_dialog('Collapse Cube', None)), ('Spatial Smoothing', lambda: self._open_dialog('Spatial Smoothing', None)), ('Moment Maps', lambda: self._open_dialog('Moment Maps', None)), ('Arithmetic Operations', lambda: self._open_dialog('Arithmetic Operations', None)) ])) self.ui.cube_option_button.setMenu(cube_menu)
def _init_menu_buttons(self): """ Add the two menu buttons to the tool bar. Currently two are defined: View - for changing the view of the active window Data Processing - for applying a data processing step to the data. :return: """ self._option_buttons = [ self.ui.view_option_button, self.ui.cube_option_button ] # Create the View Menu view_menu = self._dict_to_menu(OrderedDict([ ('Hide Axes', ['checkable', self._toggle_viewer_axes]), ('Hide Toolbars', ['checkable', self._toggle_toolbars]), ('Hide Spaxel Value Tooltip', ['checkable', self._toggle_hover_value]), ('Hide Stats', ['checkable', self._toggle_stats_display]), ('Flux Units', OrderedDict([ ('Convert Displayed Units', lambda: self._open_dialog('Convert Displayed Units', None)), ('Convert Data Values', lambda: self._open_dialog('Convert Data Values', None)), ]) ), ('Wavelength Units/Redshift', lambda: self._open_dialog('Wavelength Units/Redshift', None)) ])) # Add toggle RA-DEC format: format_menu = view_menu.addMenu("RA-DEC Format") format_action_group = QActionGroup(format_menu) self.ra_dec_format_menu = format_menu # Make sure to change all instances of the the names # of the formats if modifications are made to them. for format_name in ["Sexagesimal", "Decimal Degrees"]: act = QAction(format_name, format_menu) act.triggered.connect(self._toggle_all_coords_in_degrees) act.setActionGroup(format_action_group) act.setCheckable(True) act.setChecked(True) if format == "Sexagesimal" else act.setChecked(False) format_menu.addAction(act) self.ui.view_option_button.setMenu(view_menu) # Create the Data Processing Menu cube_menu = self._dict_to_menu(OrderedDict([ ('Collapse Cube', lambda: self._open_dialog('Collapse Cube', None)), ('Spatial Smoothing', lambda: self._open_dialog('Spatial Smoothing', None)), ('Moment Maps', lambda: self._open_dialog('Moment Maps', None)), ('Arithmetic Operations', lambda: self._open_dialog('Arithmetic Operations', None)) ])) self.ui.cube_option_button.setMenu(cube_menu)
def menu_actions(self): """ List of QtWidgets.QActions to be attached to this tool as a context menu. """ self.options = [] component_action_group = QActionGroup(self.tool_bar) action = QAction("Off", self.tool_bar, checkable=True) action.setChecked(True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.remove_contour) self.options.append(action) action = QAction("Current Component", self.tool_bar, checkable=True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.default_contour) self.options.append(action) action = QAction("Custom Component", self.tool_bar, checkable=True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.custom_contour) self.options.append(action) action = QAction(" ", self.tool_bar) action.setSeparator(True) self.options.append(action) action = QAction("Contour Settings", self.tool_bar) action.triggered.connect(self.viewer.edit_contour_settings) self.options.append(action) return self.options
def menu_actions(self): """ List of QtWidgets.QActions to be attached to this tool as a context menu. """ self.options = [] # WARNING: QAction labels are used to identify them. # Changing them can cause problems unless # all references are updated in this package. component_action_group = QActionGroup(self.tool_bar) action = QAction("Off", self.tool_bar, checkable=True) action.setChecked(True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.remove_contour) self.options.append(action) action = QAction("Current Component", self.tool_bar, checkable=True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.default_contour) self.options.append(action) action = QAction("Other Component", self.tool_bar, checkable=True) action.setActionGroup(component_action_group) action.triggered.connect(self.viewer.custom_contour) self.options.append(action) action = QAction(" ", self.tool_bar) action.setSeparator(True) self.options.append(action) action = QAction("Contour Settings", self.tool_bar) action.triggered.connect(self.viewer.edit_contour_settings) self.options.append(action) return self.options
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 mkButtons(self, nodes): # Remove+delete previous children layout = self.layout() for i in reversed(range(layout.count())): layout.itemAt(i).widget().setParent(None) if not nodes: return parent = nodes[0].parent if parent is not None: action = QAction("↑", self) action.setFont(self.font) action.triggered.connect( partial(self.showNode, parent.parent, direction="up")) action.setProperty("isMode", True) self.addAction(action) # Make separator pipe label = QAction("|", self) label.setFont(self.font) label.setDisabled(True) self.addAction(label) # Loop over each "GUIPlugin" plugin for node in reversed(list(nodes)): action = QAction(node.name, self) action.triggered.connect( partial(self.showNode, node, direction="down")) action.setFont(self.font) action.setProperty("isMode", True) action.setCheckable(True) action.setActionGroup(self.GUIPluginActionGroup) self.addAction(action) # Make separator pipe label = QAction("|", self) label.setFont(self.font) label.setDisabled(True) self.addAction(label) # Remove last separator if self.layout().count(): self.layout().takeAt( self.layout().count() - 1).widget().deleteLater() # Delete the last pipe symbol if parent is not None: # Make separator pipe label = QAction(">", self) label.setFont(self.font) label.setDisabled(True) self.addAction(label) action = QAction(parent.name, self) action.setFont(self.font) action.setProperty("isMode", True) action.setDisabled(True) action.setActionGroup(self.GUIPluginActionGroup) self.addAction(action) self.fadeIn()