def __init__(self, exctype, excvalue, exctb): super(ExceptionDialog, self).__init__() self._tbshort = ''.join( traceback.format_exception_only(exctype, excvalue)) tbfull = traceback.format_exception(exctype, excvalue, exctb) self._tbfull = ''.join(tbfull) self._ext_maintainer = app.extensions().is_extension_exception(tbfull) layout = QVBoxLayout() self.setLayout(layout) self.errorLabel = QLabel() layout.addWidget(self.errorLabel) textview = QTextBrowser() layout.addWidget(textview) textview.setText(self._tbfull) textview.moveCursor(QTextCursor.End) layout.addWidget(widgets.Separator()) b = self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) b.button(QDialogButtonBox.Ok).setIcon(icons.get("tools-report-bug")) layout.addWidget(b) b.accepted.connect(self.accept) b.rejected.connect(self.reject) self.resize(600, 300) app.translateUI(self) self.exec_()
def __init__(self, exctype, excvalue, exctb): super(ExceptionDialog, self).__init__() self._tbshort = ''.join(traceback.format_exception_only(exctype, excvalue)) tbfull = traceback.format_exception(exctype, excvalue, exctb) self._tbfull = ''.join(tbfull) self._ext_maintainer = app.extensions().is_extension_exception(tbfull) layout = QVBoxLayout() self.setLayout(layout) self.errorLabel = QLabel() layout.addWidget(self.errorLabel) textview = QTextBrowser() layout.addWidget(textview) textview.setText(self._tbfull) textview.moveCursor(QTextCursor.End) layout.addWidget(widgets.Separator()) b = self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) b.button(QDialogButtonBox.Ok).setIcon(icons.get("tools-report-bug")) layout.addWidget(b) b.accepted.connect(self.accept) b.rejected.connect(self.reject) self.resize(600,300) app.translateUI(self) self.exec_()
def menu_tools(mainwindow): m = Menu(_('menu title', '&Tools'), mainwindow) ac = autocomplete.CompleterManager.instance(mainwindow).actionCollection m.addAction(ac.autocomplete) m.addAction(ac.popup_completions) m.addSeparator() m.addMenu(menu_tools_format(mainwindow)) m.addMenu(menu_tools_transform(mainwindow)) fac = fonts.fonts(mainwindow).actionCollection m.addAction(fac.fonts_document_fonts) dac = documentactions.get(mainwindow).actionCollection m.addAction(dac.tools_convert_ly) m.addSeparator() m.addMenu(menu_tools_directories(mainwindow)) m.addSeparator() panelmanager.manager(mainwindow).addActionsToMenu(m) extensions = app.extensions() # store a reference to the Tools menu extensions.set_tools_menu(m) ext_menu = extensions.menu('tools') if not ext_menu.isEmpty(): m.addSeparator() m.addMenu(ext_menu) return m
def contextmenu(view): cursor = view.textCursor() menu = view.createStandardContextMenu() mainwindow = view.window() # create the actions in the actions list actions = [] actions.extend(open_files(cursor, menu, mainwindow)) actions.extend(jump_to_definition(cursor, menu, mainwindow)) if cursor.hasSelection(): import panelmanager actions.append(mainwindow.actionCollection.edit_copy_colored_html) actions.append(panelmanager.manager(mainwindow).snippettool.actionCollection.copy_to_snippet) import documentactions ac = documentactions.get(mainwindow).actionCollection actions.append(ac.edit_cut_assign) actions.append(ac.edit_move_to_include_file) # now add the actions to the standard menu if actions: first_action = menu.actions()[0] if menu.actions() else None if first_action: first_action = menu.insertSeparator(first_action) menu.insertActions(first_action, actions) else: menu.addActions(actions) menu.addSeparator() extensions = app.extensions().menu('editor') if not extensions.isEmpty(): menu.addMenu(extensions) return menu
def extension(self): """Return the actual Extension object if possible.""" if self._extension_name: return app.extensions().get(self._extension_name) elif hasattr(self.parent(), 'extension'): # The parent has access to the extension (typically the Panel) return self.parent().extension() else: raise AttributeError( _("Class '{classname}' can't access Extension object. " "It should provide an _extension_name class variable."). format(classname=self.__class__.__name__))
def widget(self, extension): """Return a configuration widget if provided by the extension, or None otherwise.""" widget = self._widgets.get(extension, False) if widget == False: ext = app.extensions().get(extension) # skip non-loaded extensions if ext: widget = ext.config_widget(self) widget.load_settings() self._widgets[extension] = widget or None return widget
def extension(self): """Return the actual Extension object if possible.""" if self._extension_name: return app.extensions().get(self._extension_name) elif hasattr(self.parent(), 'extension'): # The parent has access to the extension (typically the Panel) return self.parent().extension() else: raise AttributeError(_( "Class '{classname}' can't access Extension object. " "It should provide an _extension_name class variable." ).format(classname=self.__class__.__name__))
def menu_tools(mainwindow): m = Menu(_('menu title', '&Tools'), mainwindow) ac = autocomplete.CompleterManager.instance(mainwindow).actionCollection m.addAction(ac.autocomplete) m.addAction(ac.popup_completions) m.addSeparator() m.addMenu(menu_tools_format(mainwindow)) m.addMenu(menu_tools_transform(mainwindow)) dac = documentactions.get(mainwindow).actionCollection m.addAction(dac.tools_convert_ly) m.addSeparator() m.addMenu(menu_tools_directories(mainwindow)) m.addSeparator() panelmanager.manager(mainwindow).addActionsToMenu(m) extensions = app.extensions() # store a reference to the Tools menu extensions.set_tools_menu(m) ext_menu = extensions.menu('tools') if not ext_menu.isEmpty(): m.addSeparator() m.addMenu(ext_menu) return m
def addExtensionMenu(self): """Add a submenu with all actions exposed by extensions""" self._menu.addMenu(app.extensions().menu(self.name))
def show(position, panel, link, cursor): """Shows a context menu. position: The global position to pop up panel: The music view panel, giving access to mainwindow and view widget link: a popplerqt5 LinkBrowse instance or None cursor: a QTextCursor instance or None """ m = QMenu(panel) # selection? -> Copy if panel.widget().view.surface().hasSelection(): if panel.widget().view.surface().selectedText(): m.addAction(panel.actionCollection.music_copy_text) m.addAction(panel.actionCollection.music_copy_image) if cursor: a = m.addAction(icons.get("document-edit"), _("Edit in Place")) @a.triggered.connect def edit(): import editinplace editinplace.edit(panel.widget(), cursor, position) elif link: a = m.addAction(icons.get("window-new"), _("Open Link in &New Window")) @a.triggered.connect def open_in_browser(): import helpers helpers.openUrl(QUrl(link.url())) a = m.addAction(icons.get("edit-copy"), _("Copy &Link")) @a.triggered.connect def copy_link(): QApplication.clipboard().setText(link.url()) # no actions yet? insert Fit Width/Height if not m.actions(): m.addAction(panel.actionCollection.music_fit_width) m.addAction(panel.actionCollection.music_fit_height) m.addAction(panel.actionCollection.music_zoom_original) m.addSeparator() m.addAction(panel.actionCollection.music_sync_cursor) # Context menus from extensions extensions = app.extensions().menu('musicview') if not extensions.isEmpty(): m.addSeparator() m.addMenu(extensions) # help m.addSeparator() a = m.addAction(icons.get("help-contents"), _("Help")) @a.triggered.connect def help(): import userguide userguide.show("musicview") # show it! if m.actions(): m.exec_(position) m.deleteLater()
def show(position, panel, link, cursor): """Shows a context menu. position: The global position to pop up panel: The music view panel, giving access to mainwindow and view widget link: a popplerqt5 LinkBrowse instance or None cursor: a QTextCursor instance or None """ m = QMenu(panel) # selection? -> Copy if panel.widget().view.rubberband().hasSelection(): if panel.widget().view.rubberband().selectedText(): m.addAction(panel.actionCollection.music_copy_text) m.addAction(panel.actionCollection.music_copy_image) if cursor: a = m.addAction(icons.get("document-edit"), _("Edit in Place")) @a.triggered.connect def edit(): import editinplace editinplace.edit(panel.widget(), cursor, position) elif link: a = m.addAction(icons.get("window-new"), _("Open Link in &New Window")) @a.triggered.connect def open_in_browser(): import helpers helpers.openUrl(QUrl(link.url())) a = m.addAction(icons.get("edit-copy"), _("Copy &Link")) @a.triggered.connect def copy_link(): QApplication.clipboard().setText(link.url()) # no actions yet? insert Fit Width/Height if not m.actions(): m.addAction(panel.actionCollection.music_fit_width) m.addAction(panel.actionCollection.music_fit_height) m.addAction(panel.actionCollection.music_zoom_original) m.addSeparator() m.addAction(panel.actionCollection.music_sync_cursor) # Context menus from extensions extensions = app.extensions().menu('musicview') if not extensions.isEmpty(): m.addSeparator() m.addMenu(extensions) # help m.addSeparator() a = m.addAction(icons.get("help-contents"), _("Help")) @a.triggered.connect def help(): import userguide userguide.show("musicview") # show it! if m.actions(): m.exec_(position) m.deleteLater()
def populate(self): """Populate the tree view with data from the installed extensions. """ # TODO/Question: # Would it make sense to move this to a dedicated model class # complementing the FailedModel? root = self.tree.model().invisibleRootItem() extensions = app.extensions() for ext in extensions.installed_extensions(): ext_infos = extensions.infos(ext) display_name = ext_infos.get(ext, ext) if ext_infos else ext.name() loaded_extension = extensions.get(ext) if loaded_extension: display_name += ' ({})'.format(loaded_extension.load_time()) name_item = QStandardItem(display_name) name_item.extension_name = ext name_item.setCheckable(True) self.name_items[ext] = name_item icon = extensions.icon(ext) if icon: name_item.setIcon(icon) root.appendRow([name_item]) for entry in [ 'extension-name', 'short-description', 'description', 'version', 'api-version', 'dependencies', 'maintainers', 'repository', 'website', 'license' ]: label_item = QStandardItem('{}:'.format( self.config_labels[entry])) label_item.setTextAlignment(Qt.AlignTop) bold = QFont() bold.setWeight(QFont.Bold) label_item.setFont(bold) details = ext_infos.get(entry, "") if ext_infos else "" if type(details) == list: details = '\n'.join(details) details_item = QStandardItem(details) details_item.setTextAlignment(Qt.AlignTop) if entry == 'api-version': # Check for correct(ly formatted) api-version entry # and highlight it in case of mismatch api_version = appinfo.extension_api if not details: details_item.setFont(bold) details_item.setText( _("Misformat: {api}").format(details)) elif not details == api_version: details_item.setFont(bold) details_item.setText('{} ({}: {})'.format( details, appinfo.appname, api_version)) name_item.appendRow([label_item, details_item])