def slotLinkClicked(self, ev, page, link): """Called when the use clicks a link. If the links is a textedit link, opens the document and puts the cursor there. Otherwise, call the helpers module to open the destination. """ if ev.button() == Qt.RightButton: return cursor = self._links.cursor(link, True) if cursor: if ev.modifiers() & Qt.ShiftModifier: import editinplace editinplace.edit(self, cursor, ev.globalPos()) else: import browseriface mainwindow = self.parent().mainwindow() self._clicking_link = True browseriface.get(mainwindow).setTextCursor(cursor, findOpenView=True) self._clicking_link = False import widgets.blink widgets.blink.Blinker.blink_cursor(mainwindow.currentView()) mainwindow.activateWindow() mainwindow.currentView().setFocus() elif (isinstance(link, popplerqt5.Poppler.LinkBrowse) and not link.url().startswith('textedit:')): helpers.openUrl(QUrl(link.url())) elif (isinstance(link, popplerqt5.Poppler.LinkGoto) and not link.isExternal()): self.view.gotoPageNumber(link.destination().pageNumber() - 1)
def createToolBars(self): ac = self.actionCollection self.toolbar_main = t = self.addToolBar('') t.setObjectName('toolbar_main') t.addAction(ac.file_new) t.addAction(ac.file_open) t.addAction(ac.file_save) t.addAction(ac.file_save_as) t.addAction(ac.file_close) t.addSeparator() t.addAction(browseriface.get(self).actionCollection.go_back) t.addAction(browseriface.get(self).actionCollection.go_forward) t.addSeparator() t.addAction(ac.edit_undo) t.addAction(ac.edit_redo) t.addSeparator() t.addAction( scorewiz.ScoreWizard.instance(self).actionCollection.scorewiz) t.addAction(engrave.engraver(self).actionCollection.engrave_runner) self.toolbar_music = t = self.addToolBar('') t.setObjectName('toolbar_music') ma = panelmanager.manager(self).musicview.actionCollection t.addAction(ma.music_document_select) t.addAction(ma.music_print) t.addSeparator() t.addAction(ma.music_zoom_in) t.addAction(ma.music_zoom_combo) t.addAction(ma.music_zoom_out) t.addSeparator() t.addAction(ma.music_prev_page) t.addAction(ma.music_pager) t.addAction(ma.music_next_page)
def createToolBars(self): ac = self.actionCollection self.toolbar_main = t = self.addToolBar('') t.setObjectName('toolbar_main') t.addAction(ac.file_new) t.addAction(ac.file_open) t.addAction(ac.file_save) t.addAction(ac.file_save_as) t.addAction(ac.file_close) t.addSeparator() t.addAction(browseriface.get(self).actionCollection.go_back) t.addAction(browseriface.get(self).actionCollection.go_forward) t.addSeparator() t.addAction(ac.edit_undo) t.addAction(ac.edit_redo) t.addSeparator() t.addAction(scorewiz.ScoreWizard.instance(self).actionCollection.scorewiz) t.addAction(engrave.engraver(self).actionCollection.engrave_runner) self.toolbar_music = t = self.addToolBar('') t.setObjectName('toolbar_music') ma = panelmanager.manager(self).musicview.actionCollection t.addAction(ma.music_document_select) t.addAction(ma.music_print) t.addSeparator() t.addAction(ma.music_zoom_in) t.addAction(ma.music_zoom_combo) t.addAction(ma.music_zoom_out) t.addSeparator() t.addAction(ma.music_prev_page) t.addAction(ma.music_pager) t.addAction(ma.music_next_page)
def goto_target(mainwindow, target): """Switch to the document and location where the node target is.""" filename = target.document.filename doc = app.openUrl(QUrl.fromLocalFile(filename)) cursor = QTextCursor(doc) cursor.setPosition(target.position) browseriface.get(mainwindow).setTextCursor(cursor) mainwindow.currentView().centerCursor()
def slotItemClicked(self, item): """Called when the user clicks an item.""" cursor = self.cursorForItem(item) cursor.movePosition(cursor.StartOfBlock) import browseriface browseriface.get(self.parent().mainwindow()).setTextCursor(cursor) view = self.parent().mainwindow().currentView() view.centerCursor() view.setFocus()
def open_targets(mainwindow, targets): """Open all given files, giving focus to the last one. Return True if there were one or more filenames that were opened. """ d = None for t in targets: d = mainwindow.openUrl(QUrl.fromLocalFile(t)) if d: browseriface.get(mainwindow).setCurrentDocument(d, True) return True
def open_file_at_cursor(mainwindow, cursor=None): """Open the filename(s) mentioned at the mainwindow's text cursor. Return True if there were one or more filenames that were opened. """ if cursor is None: cursor = mainwindow.textCursor() d = None for name in filenames_at_cursor(cursor): d = mainwindow.openUrl(QUrl.fromLocalFile(name)) if d: browseriface.get(mainwindow).setCurrentDocument(d, True) return True
def goto_target(mainwindow, target): """Switch to the document and location where the node target is.""" lydoc = target.document try: # this succeeds if this is a document that is currently open doc = lydoc.document except AttributeError: # it is an included file, just load it filename = target.document.filename doc = app.openUrl(QUrl.fromLocalFile(filename)) cursor = QTextCursor(doc) cursor.setPosition(target.position) browseriface.get(mainwindow).setTextCursor(cursor) mainwindow.currentView().centerCursor()
def menu_view(mainwindow): m = Menu(_("menu title", "&View"), mainwindow) ac = mainwindow.actionCollection m.addAction(ac.view_next_document) m.addAction(ac.view_previous_document) m.addSeparator() m.addAction(ac.view_wrap_lines) m.addAction(documentactions.get(mainwindow).actionCollection.view_highlighting) m.addAction(sidebar.SideBarManager.instance(mainwindow).actionCollection.view_linenumbers) m.addMenu(menu_view_folding(mainwindow)) m.addSeparator() m.addAction(documentactions.get(mainwindow).actionCollection.view_goto_file_or_definition) m.addAction(ac.view_goto_line) ac = browseriface.get(mainwindow).actionCollection m.addAction(ac.go_back) m.addAction(ac.go_forward) m.addSeparator() ac = matcher.Matcher.instance(mainwindow).actionCollection m.addAction(ac.view_matching_pair) m.addAction(ac.view_matching_pair_select) m.addSeparator() ac = bookmarkmanager.BookmarkManager.instance(mainwindow).actionCollection m.addAction(ac.view_bookmark) m.addAction(ac.view_next_mark) m.addAction(ac.view_previous_mark) m.addAction(ac.view_clear_error_marks) m.addAction(ac.view_clear_all_marks) m.addSeparator() ac = panelmanager.manager(mainwindow).logtool.actionCollection m.addAction(ac.log_next_error) m.addAction(ac.log_previous_error) return m
def menu_view(mainwindow): m = Menu(_("menu title", "&View"), mainwindow) ac = mainwindow.actionCollection m.addAction(ac.view_next_document) m.addAction(ac.view_previous_document) m.addSeparator() m.addAction(ac.view_wrap_lines) m.addAction(documentactions.get(mainwindow).actionCollection.view_highlighting) m.addAction(sidebar.SideBarManager.instance(mainwindow).actionCollection.view_linenumbers) m.addMenu(menu_view_folding(mainwindow)) m.addSeparator() m.addAction(documentactions.get(mainwindow).actionCollection.view_goto_file_or_definition) ac = browseriface.get(mainwindow).actionCollection m.addAction(ac.go_back) m.addAction(ac.go_forward) m.addSeparator() ac = matcher.Matcher.instance(mainwindow).actionCollection m.addAction(ac.view_matching_pair) m.addAction(ac.view_matching_pair_select) m.addSeparator() ac = bookmarkmanager.BookmarkManager.instance(mainwindow).actionCollection m.addAction(ac.view_bookmark) m.addAction(ac.view_next_mark) m.addAction(ac.view_previous_mark) m.addAction(ac.view_clear_error_marks) m.addAction(ac.view_clear_all_marks) m.addSeparator() ac = panelmanager.manager(mainwindow).logtool.actionCollection m.addAction(ac.log_next_error) m.addAction(ac.log_previous_error) return m
def open_doc(): d = mainwindow.openUrl(url) if d: browseriface.get(mainwindow).setCurrentDocument(d)