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 action(filename): url = QUrl.fromLocalFile(filename) a = QAction(menu) a.setText(_("Open \"{url}\"").format(url=util.homify(filename))) a.setIcon(icons.get('document-open')) @a.triggered.connect def open_doc(): d = mainwindow.openUrl(url) mainwindow.setCurrentDocument(d) return a
def display(self): text = util.homify(self._info.command) if self._info.version(): text += " ({0})".format(self._info.versionString()) self.setIcon(icons.get("lilypond-run")) else: self.setIcon(icons.get("dialog-error")) if self._info.command == self.listWidget().parentWidget().parentWidget()._defaultCommand: text += " [{0}]".format(_("default")) self.setText(text)
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 path(url): """Returns the path, as a string, of the url to group documents. Returns None if the document is nameless. """ if url.isEmpty(): return None elif url.toLocalFile(): return util.homify(os.path.dirname(url.toLocalFile())) else: return url.resolved(QUrl('.')).toString(QUrl.RemoveUserInfo)
def setDocumentStatus(self, doc): if doc in self.docs: index = self.docs.index(doc) self.setTabText(index, doc.documentName().replace('&', '&&')) if doc.url().toLocalFile(): tooltip = util.homify(doc.url().toLocalFile()) elif not doc.url().isEmpty(): tooltip = doc.url().toString(QUrl.RemoveUserInfo) else: tooltip = None self.setTabToolTip(index, tooltip) self.setTabIcon(index, documenticon.icon(doc, self.window()))
def prettyName(self): """Return a pretty-printable name for this LilyPond instance.""" command = self.abscommand() or "" # strip unneeded cruft from the command name outstrip='out/bin/lilypond' if command.endswith(outstrip): command=command[:-len(outstrip)] macstrip='/Contents/Resources/bin/lilypond' if sys.platform.startswith('darwin') and command.endswith('.app' + macstrip): command=command[:-len(macstrip)] return "{name} {version} ({command})".format( name = self.name, version = self.versionString(), command = util.homify(command))
def complete(): target = definition.target(node) if target: if target.document is node.document: a.setText(_("&Jump to definition (line {num})").format( num = node.document.index(node.document.block(target.position)) + 1)) else: a.setText(_("&Jump to definition (in {filename})").format( filename=util.homify(target.document.filename))) @a.triggered.connect def activate(): definition.goto_target(mainwindow, target) else: a.setText(_("&Jump to definition (unknown)")) a.setEnabled(False)
def updateWindowTitle(self): doc = self.currentDocument() name = [] if sessions.currentSession(): name.append(sessions.currentSession() + ":") if doc: if doc.url().isEmpty(): name.append(doc.documentName()) elif doc.url().toLocalFile(): name.append(util.homify(doc.url().toLocalFile())) else: name.append(doc.url().toString()) if doc.isModified(): # L10N: state of document in window titlebar name.append(_("[modified]")) self.setWindowTitle(app.caption(" ".join(name)))
def setDocumentStatus(self, doc): if doc in self.docs: index = self.docs.index(doc) self.setTabText(index, doc.documentName()) if doc.url().toLocalFile(): tooltip = util.homify(doc.url().toLocalFile()) elif not doc.url().isEmpty(): tooltip = doc.url().toString(QUrl.RemoveUserInfo) else: tooltip = None self.setTabToolTip(index, tooltip) # icon if jobmanager.isRunning(doc): icon = 'lilypond-run' elif doc.isModified(): icon = 'document-save' else: icon = 'text-plain' self.setTabIcon(index, icons.get(icon))
def setDocumentStatus(self, doc): if doc in self.docs: index = self.docs.index(doc) self.setTabText(index, doc.documentName().replace('&', '&&')) if doc.url().toLocalFile(): tooltip = util.homify(doc.url().toLocalFile()) elif not doc.url().isEmpty(): tooltip = doc.url().toString(QUrl.RemoveUserInfo) else: tooltip = None self.setTabToolTip(index, tooltip) # icon job = jobmanager.job(doc) if job and job.is_running() and not jobattributes.get(job).hidden: icon = 'lilypond-run' elif doc.isModified(): icon = 'document-save' else: icon = 'text-plain' self.setTabIcon(index, icons.get(icon))
def setDocuments(self, documents): """Display the specified documents in the list.""" # clear the treewidget for d in self.tree.invisibleRootItem().takeChildren(): for i in d.takeChildren(): i.doc = None # group the documents by directory dirs = {} for d in documents: path = d.url().toLocalFile() if path: dirname, filename = os.path.split(path) dirs.setdefault(dirname, []).append((filename, d)) for dirname in sorted(dirs, key=util.naturalsort): diritem = QTreeWidgetItem() diritem.setText(0, util.homify(dirname)) self.tree.addTopLevelItem(diritem) diritem.setExpanded(True) diritem.setFlags(Qt.ItemIsEnabled) diritem.setIcon(0, icons.get('folder-open')) for filename, document in sorted( dirs[dirname], key=lambda item: util.naturalsort(item[0])): fileitem = QTreeWidgetItem() diritem.addChild(fileitem) if documentwatcher.DocumentWatcher.instance( document).isdeleted(): itemtext = _("[deleted]") icon = "dialog-error" else: itemtext = _("[modified]") icon = "document-edit" fileitem.setIcon(0, icons.get(icon)) fileitem.setText(0, filename) fileitem.setText(1, itemtext) fileitem.doc = document # select the item if there is only one if len(dirs) == 1 and len(dirs.values()[0]) == 1: fileitem.setSelected(True) self.tree.resizeColumnToContents(0) self.tree.resizeColumnToContents(1) self.updateButtons()
def setDocuments(self, documents): """Display the specified documents in the list.""" # clear the treewidget for d in self.tree.invisibleRootItem().takeChildren(): for i in d.takeChildren(): i.doc = None # group the documents by directory dirs = {} for d in documents: path = d.url().toLocalFile() if path: dirname, filename = os.path.split(path) dirs.setdefault(dirname, []).append((filename, d)) for dirname in sorted(dirs, key=util.naturalsort): diritem = QTreeWidgetItem() diritem.setText(0, util.homify(dirname)) self.tree.addTopLevelItem(diritem) diritem.setExpanded(True) diritem.setFlags(Qt.ItemIsEnabled) diritem.setIcon(0, icons.get('folder-open')) for filename, document in sorted(dirs[dirname], key=lambda item: util.naturalsort(item[0])): fileitem = QTreeWidgetItem() diritem.addChild(fileitem) if documentwatcher.DocumentWatcher.instance(document).isdeleted(): itemtext = _("[deleted]") icon = "dialog-error" else: itemtext = _("[modified]") icon = "document-edit" fileitem.setIcon(0, icons.get(icon)) fileitem.setText(0, filename) fileitem.setText(1, itemtext) fileitem.doc = document # select the item if there is only one if len(dirs) == 1 and len(dirs.values()[0]) == 1: fileitem.setSelected(True) self.tree.resizeColumnToContents(0) self.tree.resizeColumnToContents(1) self.updateButtons()
def updateWindowTitle(self): doc = self.currentDocument() name = [] if sessions.currentSession(): name.append(sessions.currentSession() + ':') if doc: if doc.url().isEmpty(): name.append(doc.documentName()) elif doc.url().toLocalFile(): name.append(util.homify(doc.url().toLocalFile())) else: name.append(doc.url().toString()) if doc.isModified(): # L10N: state of document in window titlebar name.append(_("[modified]")) window_title = app.caption(" ".join(name)) if vcs.app_is_git_controlled(): window_title += " " + vcs.app_active_branch_window_title() self.setWindowTitle(window_title)
def displaycommand(self): """The path to the command in a format pretty to display. This removes the 'out/bin/lilypond' part of custom build LilyPond versions, and on Mac OS X it removes the '/Contents/Resources/bin/lilypond' part. Finally it replaces the users home directory with '~'. The empty string is returned if LilyPond is not installed on the users' system. """ command = self.abscommand() if command: outstrip='out/bin/lilypond' if command.endswith(outstrip): command=command[:-len(outstrip)] macstrip='/Contents/Resources/bin/lilypond' if sys.platform.startswith('darwin') and command.endswith('.app' + macstrip): command=command[:-len(macstrip)] return util.homify(command) else: return self.command