def _aboutToShowSessionsMenu(self): menu = self.sender() assert(isinstance(menu, QMenu)) menu.clear() # QActionGroup group = QActionGroup(menu) sessions = self._sessionMetaData(False) # withBackups # SessionManager::SessionMetaData for metaData in sessions: action = menu.addAction(metaData.name) action.setCheckable(True) action.setChecked(metaData.isActive) group.addAction(action) def func(): self._switchToSession(metaData.filePath) action.triggered.connect(func)
def __init__(self, *args): QWidget.__init__(self, *args) self.mainwin = None # init layout self._lo = QVBoxLayout(self) self._lo.setContentsMargins(0, 0, 0, 0) self._lo.setSpacing(0) # init internal state self._currier = PersistentCurrier() self._z0 = 0 # z-depth of first image, the rest count down from it self._updating_imap = False self._locked_display_range = False self._imagecons = [] self._imagecon_loadorder = [] self._center_image = None self._plot = None self._border_pen = None self._drawing_key = None self._load_image_dialog = None self._label_color = None self._label_bg_brush = None self._model_imagecons = set() # init menu and standard actions self._menu = QMenu("&Image", self) qag = QActionGroup(self) # exclusive controls for plotting topmost or all images self._qa_plot_top = qag.addAction("Display topmost image only") self._qa_plot_all = qag.addAction("Display all images") self._qa_plot_top.setCheckable(True) self._qa_plot_all.setCheckable(True) self._qa_plot_top.setChecked(True) self._qa_plot_all.toggled[bool].connect(self._displayAllImages) self._closing = False self._qa_load_clipboard = None self._clipboard_mode = QClipboard.Clipboard QApplication.clipboard().changed[QClipboard.Mode].connect( self._checkClipboardPath) # populate the menu self._repopulateMenu() self.signalShowMessage = None self.signalShowErrorMessage = None
def createMenu(self, menu): ''' @param: menu QMenu ''' self._window.removeActions(menu.actions()) menu.clear() group = QActionGroup(menu) act = menu.addAction(_('Bookmarks'), self._slotShowSideBar) act.setCheckable(True) act.setShortcut(QKeySequence('Ctrl+Shift+B')) act.setData('Bookmarks') act.setChecked(self._activeBar == 'Bookmarks') group.addAction(act) act = menu.addAction(_('History'), self._slotShowSideBar) act.setCheckable(True) act.setShortcut(QKeySequence('Ctrl+H')) act.setData('History') act.setChecked(self._activeBar == 'History') group.addAction(act) for key, sidebar in self._s_sidebars.items(): if not sidebar: continue # QAction act = sidebar.createMenuAction() act.setData(key) act.setChecked(self._activeBar == key) act.triggered.connect(self._slotShowSideBar) menu.addAction(act) group.addAction(act) self._window.addActions(menu.actions())
def _createEncodingSubMenu(self, name, codecNames, menu): ''' @param: name QString @param: codecName QStringList @param: menu QMenu ''' if not codecNames: return codecNames.sort() subMenu = QMenu(name, menu) activeCodecName = gVar.app.webSettings().defaultTextEncoding() group = QActionGroup(subMenu) for codecName in codecNames: act = self._createEncodingAction(codecName, activeCodecName, subMenu) group.addAction(act) subMenu.addAction(act) menu.addMenu(subMenu)
class ThemeMenu(QMenu): # {{{ def __init__(self, parent): QMenu.__init__(self, _('Choose theme (needs restart)')) parent.addMenu(self) self.group = QActionGroup(self) current = prefs['theme'] alls = list(sorted(get_all_styles())) if current not in alls: current = prefs['theme'] = 'default' self.actions = [] for style in alls: ac = self.group.addAction(style) ac.setCheckable(True) if current == style: ac.setChecked(True) self.actions.append(ac) ac.triggered.connect(partial(self.set_theme, style)) self.addAction(ac) def set_theme(self, style, *args): prefs['theme'] = style
class ThemeMenu(QMenu): # {{{ def __init__(self, parent): QMenu.__init__(self, _("Choose theme (needs restart)")) parent.addMenu(self) self.group = QActionGroup(self) current = prefs["theme"] alls = list(sorted(get_all_styles())) if current not in alls: current = prefs["theme"] = "default" self.actions = [] for style in alls: ac = self.group.addAction(style) ac.setCheckable(True) if current == style: ac.setChecked(True) self.actions.append(ac) ac.triggered.connect(partial(self.set_theme, style)) self.addAction(ac) def set_theme(self, style, *args): prefs["theme"] = style
class LocationManager(QObject): # {{{ locations_changed = pyqtSignal() unmount_device = pyqtSignal() location_selected = pyqtSignal(object) configure_device = pyqtSignal() update_device_metadata = pyqtSignal() def __init__(self, parent=None): QObject.__init__(self, parent) self.free = [-1, -1, -1] self.count = 0 self.location_actions = QActionGroup(self) self.location_actions.setExclusive(True) self.current_location = 'library' self._mem = [] self.tooltips = {} self.all_actions = [] def ac(name, text, icon, tooltip): icon = QIcon(I(icon)) ac = self.location_actions.addAction(icon, text) setattr(self, 'location_' + name, ac) ac.setAutoRepeat(False) ac.setCheckable(True) receiver = partial(self._location_selected, name) ac.triggered.connect(receiver) self.tooltips[name] = tooltip m = QMenu(parent) self._mem.append(m) a = m.addAction(icon, tooltip) a.triggered.connect(receiver) if name != 'library': self._mem.append(a) a = m.addAction(QIcon(I('eject.png')), _('Eject this device')) a.triggered.connect(self._eject_requested) self._mem.append(a) a = m.addAction(QIcon(I('config.png')), _('Configure this device')) a.triggered.connect(self._configure_requested) self._mem.append(a) a = m.addAction(QIcon(I('sync.png')), _('Update cached metadata on device')) a.triggered.connect( lambda x: self.update_device_metadata.emit()) self._mem.append(a) else: ac.setToolTip(tooltip) ac.setMenu(m) ac.calibre_name = name self.all_actions.append(ac) return ac self.library_action = ac('library', _('Library'), 'lt.png', _('Show books in calibre library')) ac('main', _('Device'), 'reader.png', _('Show books in the main memory of the device')) ac('carda', _('Card A'), 'sd.png', _('Show books in storage card A')) ac('cardb', _('Card B'), 'sd.png', _('Show books in storage card B')) def set_switch_actions(self, quick_actions, rename_actions, delete_actions, switch_actions, choose_action): self.switch_menu = self.library_action.menu() if self.switch_menu: self.switch_menu.addSeparator() else: self.switch_menu = QMenu() self.switch_menu.addAction(choose_action) self.cs_menus = [] for t, acs in [(_('Quick switch'), quick_actions), (_('Rename library'), rename_actions), (_('Delete library'), delete_actions)]: if acs: self.cs_menus.append(QMenu(t)) for ac in acs: self.cs_menus[-1].addAction(ac) self.switch_menu.addMenu(self.cs_menus[-1]) self.switch_menu.addSeparator() for ac in switch_actions: self.switch_menu.addAction(ac) if self.switch_menu != self.library_action.menu(): self.library_action.setMenu(self.switch_menu) def _location_selected(self, location, *args): if location != self.current_location and hasattr( self, 'location_' + location): self.current_location = location self.location_selected.emit(location) getattr(self, 'location_' + location).setChecked(True) def _eject_requested(self, *args): self.unmount_device.emit() def _configure_requested(self): self.configure_device.emit() def update_devices(self, cp=(None, None), fs=[-1, -1, -1], icon=None): if icon is None: icon = I('reader.png') self.location_main.setIcon(QIcon(icon)) had_device = self.has_device if cp is None: cp = (None, None) if isinstance(cp, (str, unicode)): cp = (cp, None) if len(fs) < 3: fs = list(fs) + [0] self.free[0] = fs[0] self.free[1] = fs[1] self.free[2] = fs[2] cpa, cpb = cp self.free[1] = fs[1] if fs[1] is not None and cpa is not None else -1 self.free[2] = fs[2] if fs[2] is not None and cpb is not None else -1 self.update_tooltips() if self.has_device != had_device: self.location_library.setChecked(True) self.locations_changed.emit() if not self.has_device: self.location_library.trigger() def update_tooltips(self): for i, loc in enumerate(('main', 'carda', 'cardb')): t = self.tooltips[loc] if self.free[i] > -1: t += u'\n\n%s ' % human_readable(self.free[i]) + _('available') ac = getattr(self, 'location_' + loc) ac.setToolTip(t) ac.setWhatsThis(t) ac.setStatusTip(t) @property def has_device(self): return max(self.free) > -1 @property def available_actions(self): ans = [self.location_library] for i, loc in enumerate(('main', 'carda', 'cardb')): if self.free[i] > -1: ans.append(getattr(self, 'location_' + loc)) return ans
def __init__(self): QMainWindow.__init__(self) f = factory() self.setMinimumWidth(400) self.setWindowTitle( 'Demo of DBUS menu exporter and systray integration') self.statusBar().showMessage(self.windowTitle()) w = QWidget(self) self.setCentralWidget(w) self.l = l = QVBoxLayout(w) mb = self.menu_bar = f.create_window_menubar(self) m = self.menu_one = mb.addMenu('&One') m.aboutToShow.connect(self.about_to_show_one) s = self.style() self.q = q = QAction('&Quit', self) q.setShortcut(QKeySequence.Quit), q.setIcon( s.standardIcon(s.SP_DialogCancelButton)) q.triggered.connect(QApplication.quit) self.addAction(q) QApplication.instance().setWindowIcon(s.standardIcon( s.SP_ComputerIcon)) for i, icon in zip( xrange(3), map(s.standardIcon, (s.SP_DialogOkButton, s.SP_DialogHelpButton, s.SP_ArrowUp))): ac = m.addAction('One - &%d' % (i + 1)) ac.setShortcut( QKeySequence(Qt.CTRL | (Qt.Key_1 + i), Qt.SHIFT | (Qt.Key_1 + i))) ac.setIcon(icon) m.addSeparator() self.menu_two = m2 = m.addMenu('A &submenu') for i, icon in zip( xrange(3), map(s.standardIcon, (s.SP_DialogOkButton, s.SP_DialogCancelButton, s.SP_ArrowUp))): ac = m2.addAction('Two - &%d' % (i + 1)) ac.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_A + i))) ac.setIcon(icon) m2.aboutToShow.connect(self.about_to_show_two) m2.addSeparator(), m.addSeparator() m.addAction('&Disabled action').setEnabled(False) ac = m.addAction('A checkable action') make_checkable(ac) g = QActionGroup(self) make_checkable(g.addAction(m.addAction('Exclusive 1'))) make_checkable(g.addAction(m.addAction('Exclusive 2')), False) m.addSeparator() self.about_to_show_sentinel = m.addAction( 'This action\'s text should change before menu is shown') self.as_count = 0 for ac in mb.findChildren(QAction): ac.triggered.connect(self.action_triggered) for m in mb.findChildren(QMenu): m.aboutToShow.connect(self.about_to_show) self.systray = f.create_system_tray_icon(parent=self, title=self.windowTitle()) if self.systray is not None: self.systray.activated.connect(self.tray_activated) self.sm = m = QMenu() m.addAction('Show/hide main window').triggered.connect( self.tray_activated) m.addAction(q) self.systray.setContextMenu(m) self.update_tray_toggle_action() self.cib = b = QPushButton('Change system tray icon') l.addWidget(b), b.clicked.connect(self.change_icon) self.hib = b = QPushButton('Show/Hide system tray icon') l.addWidget(b), b.clicked.connect(self.systray.toggle) self.update_tooltip_timer = t = QTimer(self) t.setInterval(1000), t.timeout.connect( self.update_tooltip), t.start() self.ab = b = QPushButton('Add a new menu') b.clicked.connect(self.add_menu), l.addWidget(b) self.rb = b = QPushButton('Remove a created menu') b.clicked.connect(self.remove_menu), l.addWidget(b) self.sd = b = QPushButton('Show modal dialog') b.clicked.connect(self.show_dialog), l.addWidget(b) print('DBUS connection unique name:', f.bus.get_unique_name())
class RouteTableApp(QWidget): """ Main view class This class composes the widgets for the user to choose the logs files to compare and the options for the output """ def __init__(self, parent=None, controller=None, *args, **kwargs): super(RouteTableApp, self).__init__(parent, *args, **kwargs) self._parent = parent self._controller = controller self._options = self.__Options() self.initUI() logging.debug("Main RouteTableApp created {}".format(self)) def initUI(self): self.setWindowTitle("Routa Table comparison") logo = QIcon('img/icon/logo.png') self.setWindowIcon(logo) self.qw_router1 = LogFileWidget(parent=self) self.qw_router1.setTitle("Previous info") self.qw_router2 = LogFileWidget(parent=self) self.qw_router2.setTitle("New info") self.btn_process = QPushButton("Process") self.btn_process.setMaximumWidth(70) # self.btn_process.setEnabled(False) self.btn_process.clicked.connect(self._process) self.chk_protocol = QCheckBox("include protocol?") self.chk_protocol.setChecked(self._options.getattribute("includeProtocolFlag")) self.chk_next = QCheckBox("include nexthop?") self.chk_next.setChecked(self._options.getattribute("includeNexthopFlag")) icon = QIcon('img/icon/process.svg') self.btn_process.setIcon(icon) self.menubar = QMenuBar(self) preferenceMenu = self.menubar.addMenu('Preferences') self.routerIdComparisonAction = QAction('Same Router Id', self) self.routerIdComparisonAction.setCheckable(True) self.routerIdComparisonAction.setChecked(self._options.getattribute("routerIdComparison")) preferenceMenu.addAction(self.routerIdComparisonAction) separatorMenu = preferenceMenu.addMenu("Separator") parserMenu = preferenceMenu.addMenu("Log type") # Parsers options self.parserAction = QActionGroup(self) autoAction = QAction('auto', self) autoAction.setCheckable(True) autoAction.setChecked("auto" == self._options.getattribute("parser")) timosAction = QAction('sros', self) timosAction.setCheckable(True) timosAction.setChecked("sros" == self._options.getattribute("parser")) timosBgpAction = QAction('sros bgp', self) timosBgpAction.setCheckable(True) timosBgpAction.setChecked("sros bgp" == self._options.getattribute("parser")) hvrpAction = QAction('hvrp', self) hvrpAction.setCheckable(True) hvrpAction.setChecked("hvrp" == self._options.getattribute("parser")) autoAction.triggered.connect(self._selectParser) timosAction.triggered.connect(self._selectParser) timosBgpAction.triggered.connect(self._selectParser) hvrpAction.triggered.connect(self._selectParser) self.parserAction.addAction(autoAction) self.parserAction.addAction(timosAction) self.parserAction.addAction(timosBgpAction) self.parserAction.addAction(hvrpAction) self.parserAction.setExclusive(True) parserMenu.addAction(autoAction) parserMenu.addAction(timosAction) parserMenu.addAction(timosBgpAction) parserMenu.addAction(hvrpAction) # set separators menu, mutually exclusive, and get persistent value self.separatorAction = QActionGroup(self) commaAction = QAction('comma (,)', self) commaAction.setCheckable(True) commaAction.setChecked("," in self._options.getattribute("separator")) semicolonAction = QAction('semicolon (;)', self) semicolonAction.setCheckable(True) semicolonAction.setChecked(";" in self._options.getattribute("separator")) spaceAction = QAction('space ( )', self) spaceAction.setCheckable(True) spaceAction.setChecked(" " in self._options.getattribute("separator")) self.separatorAction.addAction(commaAction) self.separatorAction.addAction(spaceAction) self.separatorAction.addAction(semicolonAction) self.separatorAction.setExclusive(True) commaAction.triggered.connect(self._selectSeparator) semicolonAction.triggered.connect(self._selectSeparator) spaceAction.triggered.connect(self._selectSeparator) separatorMenu.addAction(spaceAction) separatorMenu.addAction(commaAction) separatorMenu.addAction(semicolonAction) self.layout = QVBoxLayout() self.hlayout = QHBoxLayout() self.hlayout.addWidget(self.btn_process) self.hlayout.addWidget(self.chk_protocol) self.hlayout.addWidget(self.chk_next) self.layout.addWidget(self.menubar) self.layout.addWidget(self.qw_router1) self.layout.addWidget(self.qw_router2) self.layout.addLayout(self.hlayout) self.setLayout(self.layout) self.show() def _process(self): logging.debug("Button clicked {}".format(self.btn_process)) self._controller.process() class __Options(object): """ Hold local widget options """ width = 200 height = 100 currentPath = "" compareByKey = True includeProtocolFlag = False includeNexthopFlag = False separator = " " parser = "auto" routerIdComparison = True def __init__(self): """ Load default values then get the values from serialized file if any """ import pickle try: with open('options.pickle', 'rb') as f: self.__dict__ = pickle.load(f) logging.debug("Load options widget. options {}".format(self.__dict__)) except FileNotFoundError: pass def getattribute(self, name): return getattr(self, name) def setattr(self, name, value): setattr(self, name, value) logging.debug("Set Attr <{}> value <{}> object {}".format(name, value, self)) def save(self): """ Memento save class __dict__ over a persistent file """ import pickle with open('options.pickle', 'wb') as f: pickle.dump(self.__dict__, f) def includeProtocol(self): return self.chk_protocol.isChecked() def includeNexthop(self): return self.chk_next.isChecked() def separatorChar(self): return self._options.separator def routerIdComparison(self): return self.routerIdComparisonAction.isChecked() def parserSelect(self): return self._options.parser def _selectSeparator(self): t = self.separatorAction.checkedAction().text() logging.debug("_selectSeparator separator <{}>".format(t)) if ',' in t: self._options.setattr("separator", ',') elif ';' in t: self._options.setattr("separator", ';') else: self._options.setattr("separator", ' ') def _selectParser(self): t = self.parserAction.checkedAction().text() logging.debug("_selectParser parser <{}>".format(t)) if 'auto' in t: self._options.setattr("parser", 'auto') elif 'sros' == t.strip(): self._options.setattr("parser", 'sros') elif 'sros bgp' == t.strip(): self._options.setattr("parser", 'sros bgp') elif 'hvrp' == t: self._options.setattr("parser", 'hvrp') else: self._options.setattr("parser", 'auto') def closeEvent(self, event): logging.debug("closing widget <{}> event <{}>".format(self, event)) self._options.setattr("includeProtocolFlag", self.chk_protocol.isChecked()) self._options.setattr("includeNexthopFlag", self.chk_next.isChecked()) self._options.setattr("width", self.width()) self._options.setattr("height", self.height()) self._selectSeparator() self._selectParser() self._options.setattr("routerIdComparison", self.routerIdComparisonAction.isChecked()) self._options.save() event.accept()
class LocationManager(QObject): # {{{ locations_changed = pyqtSignal() unmount_device = pyqtSignal() location_selected = pyqtSignal(object) configure_device = pyqtSignal() update_device_metadata = pyqtSignal() def __init__(self, parent=None): QObject.__init__(self, parent) self.free = [-1, -1, -1] self.count = 0 self.location_actions = QActionGroup(self) self.location_actions.setExclusive(True) self.current_location = 'library' self._mem = [] self.tooltips = {} self.all_actions = [] def ac(name, text, icon, tooltip): icon = QIcon(I(icon)) ac = self.location_actions.addAction(icon, text) setattr(self, 'location_'+name, ac) ac.setAutoRepeat(False) ac.setCheckable(True) receiver = partial(self._location_selected, name) ac.triggered.connect(receiver) self.tooltips[name] = tooltip m = QMenu(parent) self._mem.append(m) a = m.addAction(icon, tooltip) a.triggered.connect(receiver) if name != 'library': self._mem.append(a) a = m.addAction(QIcon(I('eject.png')), _('Eject this device')) a.triggered.connect(self._eject_requested) self._mem.append(a) a = m.addAction(QIcon(I('config.png')), _('Configure this device')) a.triggered.connect(self._configure_requested) self._mem.append(a) a = m.addAction(QIcon(I('sync.png')), _('Update cached metadata on device')) a.triggered.connect(lambda x : self.update_device_metadata.emit()) self._mem.append(a) else: ac.setToolTip(tooltip) ac.setMenu(m) ac.calibre_name = name self.all_actions.append(ac) return ac self.library_action = ac('library', _('Library'), 'lt.png', _('Show books in calibre library')) ac('main', _('Device'), 'reader.png', _('Show books in the main memory of the device')) ac('carda', _('Card A'), 'sd.png', _('Show books in storage card A')) ac('cardb', _('Card B'), 'sd.png', _('Show books in storage card B')) def set_switch_actions(self, quick_actions, rename_actions, delete_actions, switch_actions, choose_action): self.switch_menu = self.library_action.menu() if self.switch_menu: self.switch_menu.addSeparator() else: self.switch_menu = QMenu() self.switch_menu.addAction(choose_action) self.cs_menus = [] for t, acs in [(_('Quick switch'), quick_actions), (_('Rename library'), rename_actions), (_('Delete library'), delete_actions)]: if acs: self.cs_menus.append(QMenu(t)) for ac in acs: self.cs_menus[-1].addAction(ac) self.switch_menu.addMenu(self.cs_menus[-1]) self.switch_menu.addSeparator() for ac in switch_actions: self.switch_menu.addAction(ac) if self.switch_menu != self.library_action.menu(): self.library_action.setMenu(self.switch_menu) def _location_selected(self, location, *args): if location != self.current_location and hasattr(self, 'location_'+location): self.current_location = location self.location_selected.emit(location) getattr(self, 'location_'+location).setChecked(True) def _eject_requested(self, *args): self.unmount_device.emit() def _configure_requested(self): self.configure_device.emit() def update_devices(self, cp=(None, None), fs=[-1, -1, -1], icon=None): if icon is None: icon = I('reader.png') self.location_main.setIcon(QIcon(icon)) had_device = self.has_device if cp is None: cp = (None, None) if isinstance(cp, (str, unicode)): cp = (cp, None) if len(fs) < 3: fs = list(fs) + [0] self.free[0] = fs[0] self.free[1] = fs[1] self.free[2] = fs[2] cpa, cpb = cp self.free[1] = fs[1] if fs[1] is not None and cpa is not None else -1 self.free[2] = fs[2] if fs[2] is not None and cpb is not None else -1 self.update_tooltips() if self.has_device != had_device: self.location_library.setChecked(True) self.locations_changed.emit() if not self.has_device: self.location_library.trigger() def update_tooltips(self): for i, loc in enumerate(('main', 'carda', 'cardb')): t = self.tooltips[loc] if self.free[i] > -1: t += u'\n\n%s '%human_readable(self.free[i]) + _('available') ac = getattr(self, 'location_'+loc) ac.setToolTip(t) ac.setWhatsThis(t) ac.setStatusTip(t) @property def has_device(self): return max(self.free) > -1 @property def available_actions(self): ans = [self.location_library] for i, loc in enumerate(('main', 'carda', 'cardb')): if self.free[i] > -1: ans.append(getattr(self, 'location_'+loc)) return ans
def __init__(self): QMainWindow.__init__(self) f = factory() self.setMinimumWidth(400) self.setWindowTitle('Demo of DBUS menu exporter and systray integration') self.statusBar().showMessage(self.windowTitle()) w = QWidget(self) self.setCentralWidget(w) self.l = l = QVBoxLayout(w) mb = self.menu_bar = f.create_window_menubar(self) m = self.menu_one = mb.addMenu('&One') m.aboutToShow.connect(self.about_to_show_one) s = self.style() self.q = q = QAction('&Quit', self) q.setShortcut(QKeySequence.Quit), q.setIcon(s.standardIcon(s.SP_DialogCancelButton)) q.triggered.connect(QApplication.quit) self.addAction(q) QApplication.instance().setWindowIcon(s.standardIcon(s.SP_ComputerIcon)) for i, icon in zip(xrange(3), map(s.standardIcon, (s.SP_DialogOkButton, s.SP_DialogHelpButton, s.SP_ArrowUp))): ac = m.addAction('One - &%d' % (i + 1)) ac.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_1 + i), Qt.SHIFT | (Qt.Key_1 + i))) ac.setIcon(icon) m.addSeparator() self.menu_two = m2 = m.addMenu('A &submenu') for i, icon in zip(xrange(3), map(s.standardIcon, (s.SP_DialogOkButton, s.SP_DialogCancelButton, s.SP_ArrowUp))): ac = m2.addAction('Two - &%d' % (i + 1)) ac.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_A + i))) ac.setIcon(icon) m2.aboutToShow.connect(self.about_to_show_two) m2.addSeparator(), m.addSeparator() m.addAction('&Disabled action').setEnabled(False) ac = m.addAction('A checkable action') make_checkable(ac) g = QActionGroup(self) make_checkable(g.addAction(m.addAction('Exclusive 1'))) make_checkable(g.addAction(m.addAction('Exclusive 2')), False) m.addSeparator() self.about_to_show_sentinel = m.addAction('This action\'s text should change before menu is shown') self.as_count = 0 for ac in mb.findChildren(QAction): ac.triggered.connect(self.action_triggered) for m in mb.findChildren(QMenu): m.aboutToShow.connect(self.about_to_show) self.systray = f.create_system_tray_icon(parent=self, title=self.windowTitle()) if self.systray is not None: self.systray.activated.connect(self.tray_activated) self.sm = m = QMenu() m.addAction('Show/hide main window').triggered.connect(self.tray_activated) m.addAction(q) self.systray.setContextMenu(m) self.update_tray_toggle_action() self.cib = b = QPushButton('Change system tray icon') l.addWidget(b), b.clicked.connect(self.change_icon) self.hib = b = QPushButton('Show/Hide system tray icon') l.addWidget(b), b.clicked.connect(self.systray.toggle) self.update_tooltip_timer = t = QTimer(self) t.setInterval(1000), t.timeout.connect(self.update_tooltip), t.start() self.ab = b = QPushButton('Add a new menu') b.clicked.connect(self.add_menu), l.addWidget(b) self.rb = b = QPushButton('Remove a created menu') b.clicked.connect(self.remove_menu), l.addWidget(b) self.sd = b = QPushButton('Show modal dialog') b.clicked.connect(self.show_dialog), l.addWidget(b) print('DBUS connection unique name:', f.bus.get_unique_name())