def add_groups(): for k in sorted(groups.keys()): m = self.addMenu(k) self.groupMenus.append(m) for name in groups[k]: add_session(m, name, k) qutil.addAccelerators(m.actions())
def populateRecentFilesMenu(self): self.menu_recent_files.clear() for url in recentfiles.urls(): f = url.toLocalFile() dirname, basename = os.path.split(f) text = "{0} ({1})".format(basename, util.homify(dirname)) self.menu_recent_files.addAction(text).url = url qutil.addAccelerators(self.menu_recent_files.actions())
def translateUI(self): self.setPreviewTexts() for name, desc in headers(): self.labels[name].setText(desc + ":") # add accelerators to names, avoiding the tab names tabwidget = self.window().tabs used = filter(None, (qutil.getAccelerator(tabwidget.widget(i).title()) for i in range(tabwidget.count()))) qutil.addAccelerators([self.labels[name] for name, desc in headers()], used)
def menu_sessions(parent): m = QMenu(parent) m.setTitle(_('menu title', '&Session')) m.triggered.connect(slot_session_action) import sessions for name in sessions.sessionNames(): a = m.addAction(name.replace('&', '&&')) a.setObjectName(name) qutil.addAccelerators(m.actions()) return m
def populate(self): groups = {} tl_sessions = [] def add_session(menu, name, group=None): name = name.replace('&', '&&') fullname = group + '/' + name if group else name a = menu.addAction(name) a.setCheckable(True) if fullname == sessions.currentSession(): a.setChecked(True) if group: menu.setTitle('* ' + menu.title()) a.setObjectName(fullname) self._actionGroup.addAction(a) def add_sessions(): for name in tl_sessions: add_session(self, name) def add_groups(): for k in sorted(groups.keys()): m = self.addMenu(k) self.groupMenus.append(m) for name in groups[k]: add_session(m, name, k) qutil.addAccelerators(m.actions()) def reset_menu(): for m in self.groupMenus: m.deleteLater() self.groupMenus = [] ac = manager.get(self.parentWidget()).actionCollection ag = self._actionGroup for a in ag.actions(): if a is not ac.session_none: self.removeAction(a) ag.removeAction(a) ac.session_none.setChecked(not sessions.currentSession()) reset_menu() for name in sessions.sessionNames(): if '/' in name: group, name = name.split('/') if group in groups: groups[group].append(name) else: groups[group] = [name] else: tl_sessions.append(name) add_groups() if groups: self.addSeparator() add_sessions() qutil.addAccelerators(self.actions())
def menu_file_open_recent(parent): m = QMenu(parent) m.setTitle(_("Open &Recent")) m.triggered.connect(slot_file_open_recent_action) import recentfiles for url in recentfiles.urls(): f = url.toLocalFile() dirname, basename = os.path.split(f) text = "{0} ({1})".format(basename, util.homify(dirname)) m.addAction(text).url = url qutil.addAccelerators(m.actions()) return m
def translateUI(self): msg = _("Click to enter a value.") self.htmlView.setHtml(titles_html.format( copyrightmsg = _("bottom of first page"), taglinemsg = _("bottom of last page"), imgurl = QUrl.fromLocalFile(__path__[0]).toString(), **dict((name, "<a title='{0}' href='{1}'>{2}</a>".format(msg, name, desc)) for name, desc in headers()))) for name, desc in headers(): self.labels[name].setText(desc + ":") # add accelerators to names, avoiding the tab names tabwidget = self.window().tabs used = filter(None, (qutil.getAccelerator(tabwidget.widget(i).title()) for i in range(tabwidget.count()))) qutil.addAccelerators([self.labels[name] for name, desc in headers()], used)
def populate(self): ac = manager.get(self.parentWidget()).actionCollection ag = self._actionGroup for a in ag.actions(): if a is not ac.session_none: self.removeAction(a) ag.removeAction(a) ac.session_none.setChecked(not sessions.currentSession()) for name in sessions.sessionNames(): a = self.addAction(name.replace('&', '&&')) a.setCheckable(True) if name == sessions.currentSession(): a.setChecked(True) a.setObjectName(name) ag.addAction(a) qutil.addAccelerators(self.actions())
def translateUI(self): msg = _("Click to enter a value.") self.htmlView.setHtml( titles_html.format( copyrightmsg=_("bottom of first page"), taglinemsg=_("bottom of last page"), imgurl=QUrl.fromLocalFile(__path__[0]).toString(), **dict((name, "<a title='{0}' href='{1}'>{2}</a>".format( msg, name, desc)) for name, desc in headers()))) for name, desc in headers(): self.labels[name].setText(desc + ":") # add accelerators to names, avoiding the tab names tabwidget = self.window().tabs used = filter(None, (qutil.getAccelerator(tabwidget.widget(i).title()) for i in range(tabwidget.count()))) qutil.addAccelerators([self.labels[name] for name, desc in headers()], used)
def __init__(self, mainwindow): self.actionCollection = ac = Actions() actioncollectionmanager.manager(mainwindow).addActionCollection(ac) m = self.language_menu = QMenu() g = self.language_group = QActionGroup(None) for name in sorted(ly.pitch.pitchInfo.keys()): a = m.addAction(name.title()) a.setObjectName(name) a.setCheckable(True) g.addAction(a) qutil.addAccelerators(m.actions()) ac.pitch_language.setMenu(m) m.aboutToShow.connect(self.setLanguageMenu) g.triggered.connect(self.changeLanguage) ac.pitch_rel2abs.triggered.connect(self.rel2abs) ac.pitch_abs2rel.triggered.connect(self.abs2rel) ac.pitch_transpose.triggered.connect(self.transpose)
def populate(self): """Populates the menu with snippet actions.""" from . import model, snippets, actions last = self.insertBeforeAction() shortcuts = self.tool().snippetActions groups = {} for name in sorted(model.model().names()): variables = snippets.get(name).variables group = self.snippetGroup(variables) if group: action = actions.action(name, self.mainwindow(), shortcuts) self.visitAction(action, variables) groups.setdefault(group, []).append(action) for group in sorted(groups): for action in groups[group]: self.insertAction(last, action) self.insertSeparator(last) qutil.addAccelerators(self.actions())
def __init__(self, mainwindow): self.actionCollection = ac = Actions() actioncollectionmanager.manager(mainwindow).addActionCollection(ac) m = self.language_menu = QMenu() g = self.language_group = QActionGroup(None) for name in sorted(ly.pitch.pitchInfo.keys()): a = m.addAction(name.title()) a.setObjectName(name) a.setCheckable(True) g.addAction(a) qutil.addAccelerators(m.actions()) ac.pitch_language.setMenu(m) m.aboutToShow.connect(self.setLanguageMenu) g.triggered.connect(self.changeLanguage) ac.pitch_rel2abs.triggered.connect(self.rel2abs) ac.pitch_abs2rel.triggered.connect(self.abs2rel) ac.pitch_transpose.triggered.connect(self.transpose) ac.pitch_modal_transpose.triggered.connect(self.modalTranspose)
def populate(self): """Populates the menu with snippet actions.""" self.clearMenu() # on some systems aboutToHide does not fire... from . import model, snippets, actions last = self.insertBeforeAction() shortcuts = self.tool().snippetActions groups = {} for name in sorted(model.model().names()): variables = snippets.get(name).variables group = self.snippetGroup(variables) if group: action = actions.action(name, self.mainwindow(), shortcuts) self.visitAction(action, variables) groups.setdefault(group, []).append(action) for group in sorted(groups, key=lambda g: '' if g is True else g): for action in groups[group]: self.insertAction(last, action) self.insertSeparator(last) qutil.addAccelerators(self.actions())
def menu_file_new_from_template(parent): m = QMenu(parent) m.setTitle(_("New from &Template")) m.triggered.connect(slot_file_new_from_template_action) from snippet import model, actions, snippets groups = {} for name in sorted(model.model().names()): variables = snippets.get(name).variables group = variables.get('template') if group: action = actions.action(name, m) if action: groups.setdefault(group, []).append(action) for group in sorted(groups): for action in groups[group]: m.addAction(action) m.addSeparator() qutil.addAccelerators(m.actions()) return m
def populate(self): """Populates the menu with snippet actions.""" self.clearMenu() # on some systems aboutToHide does not fire... from . import model, snippets, actions last = self.insertBeforeAction() shortcuts = self.tool().snippetActions groups = {} for name in sorted(model.model().names()): variables = snippets.get(name).variables group = self.snippetGroup(variables) if group: action = actions.action(name, self.mainwindow(), shortcuts) self.visitAction(action, variables) groups.setdefault(group, []).append(action) for group in sorted(groups): for action in groups[group]: self.insertAction(last, action) self.insertSeparator(last) qutil.addAccelerators(self.actions())
def repopulate(self): """Clears the menu and populates it with snippet actions.""" # PyQt5's aboutToHide is buggy on macOS and prevents actions # from being triggered; instead of clearing the menu in aboutToHide # we do it just before repopulating it self.clearMenu() from . import model, snippets, actions last = self.insertBeforeAction() shortcuts = self.tool().snippetActions groups = {} for name in sorted(model.model().names()): variables = snippets.get(name).variables group = self.snippetGroup(variables) if group: action = actions.action(name, self.mainwindow(), shortcuts) self.visitAction(action, variables) groups.setdefault(group, []).append(action) for group in sorted(groups, key=lambda g: '' if g is True else g): for action in groups[group]: self.insertAction(last, action) self.insertSeparator(last) qutil.addAccelerators(self.actions())
def populate(self): self.clear() doc = self.parentWidget().currentDocument() if doc: import resultfiles files = resultfiles.results(doc).files() first = True for group in util.group_files(files, ('pdf', 'mid midi', 'svg svgz', 'png', '!ly ily lyi')): if group: if not first: self.addSeparator() first = False for f in group: name = os.path.split(f)[1] a = self.addAction(name) a.setIcon(icons.file_type(f)) a.filename = f if not self.actions(): a = self.addAction(_("No files available")) a.setEnabled(False) else: qutil.addAccelerators(self.actions())
def populate(self): self.clear() doc = self.parentWidget().currentDocument() if doc: import resultfiles files = resultfiles.results(doc).files() first = True for group in util.group_files( files, ('pdf', 'mid midi', 'svg svgz', 'png', '!ly ily lyi')): if group: if not first: self.addSeparator() first = False for f in group: name = os.path.split(f)[1] a = self.addAction(name) a.setIcon(icons.file_type(f)) a.filename = f if not self.actions(): a = self.addAction(_("No files available")) a.setEnabled(False) else: qutil.addAccelerators(self.actions())