def updateDisplay(self): data = self.data[self.scheme.currentScheme()] with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(data.font) self.fontSize.setValue(data.font.pointSizeF()) with qutil.signalsBlocked(self): # update base colors for name in textformats.baseColors: self.baseColorsWidget.color[name].setColor( data.baseColors[name]) # update base colors for whole treewidget p = QApplication.palette() p.setColor(QPalette.Base, data.baseColors['background']) p.setColor(QPalette.Text, data.baseColors['text']) p.setColor(QPalette.Highlight, data.baseColors['selectionbackground']) p.setColor(QPalette.HighlightedText, data.baseColors['selectiontext']) self.tree.setPalette(p) def setItemTextFormat(item, f): font = QFont(data.font) if f.hasProperty(QTextFormat.ForegroundBrush): item.setForeground(0, f.foreground().color()) else: item.setForeground(0, data.baseColors['text']) if f.hasProperty(QTextFormat.BackgroundBrush): item.setBackground(0, f.background().color()) else: item.setBackground(0, QBrush()) font.setWeight(f.fontWeight()) font.setItalic(f.fontItalic()) font.setUnderline(f.fontUnderline()) item.setFont(0, font) # update looks of default styles for name in textformats.defaultStyles: setItemTextFormat(self.defaultStyles[name], data.defaultStyles[name]) # update looks of all the specific styles for group, styles in ly.colorize.default_mapping(): children = self.allStyles[group][1] for name, inherit, clss in styles: f = QTextCharFormat(data.defaultStyles[inherit] ) if inherit else QTextCharFormat() f.merge(data.allStyles[group][name]) setItemTextFormat(children[name], f)
def find(self): # hide replace stuff self.replaceLabel.hide() self.replaceEntry.hide() self.replaceButton.hide() self.replaceAllButton.hide() self._replace = False # we are not in replace mode visible = self.isVisible() if not visible: self.showWidget() else: self.adjustSize() cursor = self.currentView().textCursor() #if not visible and self.currentView(): if cursor.hasSelection() or not self.searchEntry.text(): if not cursor.hasSelection(): # pick current word wordboundary.handler.select(cursor, QTextCursor.WordUnderCursor) word = cursor.selection().toPlainText() if not re.search(r'\w', word): word = "" elif self.regexCheck.isChecked(): word = re.escape(word) with qutil.signalsBlocked(self.searchEntry): self.searchEntry.setText(word) self.slotSearchChanged() else: self.searchEntry.selectAll() self.highlightingOn() self.searchEntry.setFocus()
def find(self): """Called by the main menu Find... command.""" # hide replace stuff self.replaceLabel.hide() self.replaceEntry.hide() self.replaceButton.hide() self.replaceAllButton.hide() self._replace = False # we are not in replace mode visible = self.isVisible() if not visible: self.showWidget() else: self.adjustSize() cursor = self.currentView().textCursor() #if not visible and self.currentView(): if cursor.hasSelection(): word = cursor.selection().toPlainText() if not re.search(r'\w', word): word = "" elif self.regexCheck.isChecked(): word = re.escape(word) with qutil.signalsBlocked(self.searchEntry): self.searchEntry.setText(word) self.slotSearchChanged() else: self.searchEntry.selectAll() self.highlightingOn() self.searchEntry.setFocus()
def loadSettings(self): s = QSettings() s.beginGroup("helper_applications") self.printCommand.setPath(s.value("printcommand", "", str)) self.printDialogCheck.setChecked(s.value("printcommand/dialog", False, bool)) with qutil.signalsBlocked(self.resolution): self.resolution.setEditText(format(s.value("printcommand/dpi", 300, int)))
def find(self): # hide replace stuff self.replaceLabel.hide() self.replaceEntry.hide() self.replaceButton.hide() self.replaceAllButton.hide() self._replace = False # we are not in replace mode visible = self.isVisible() if not visible: with qutil.signalsBlocked(self.searchEntry): self.searchEntry.clear() self.showWidget() if not visible and self.currentView(): # pick current word cursor = self.currentView().textCursor() cursor.movePosition(QTextCursor.StartOfWord) cursor.movePosition(QTextCursor.EndOfWord, QTextCursor.KeepAnchor) word = cursor.selection().toPlainText() if not re.search(r'\w', word): word = "" self.searchEntry.setText(word) self.searchEntry.selectAll() else: self.slotSearchChanged() self.searchEntry.setFocus()
def loadSettings(self): s = QSettings() s.beginGroup("helper_applications") self.printCommand.setPath(s.value("printcommand", "", type(""))) self.printDialogCheck.setChecked(s.value("printcommand/dialog", False, bool)) with qutil.signalsBlocked(self.resolution): self.resolution.setEditText(format(s.value("printcommand/dpi", 300, int)))
def find(self): # hide replace stuff self.replaceLabel.hide() self.replaceEntry.hide() self.replaceButton.hide() self.replaceAllButton.hide() self._replace = False # we are not in replace mode visible = self.isVisible() if not visible: self.showWidget() else: self.adjustSize() cursor = self.currentView().textCursor() if not visible and self.currentView(): if cursor.hasSelection() or not self.searchEntry.text(): if not cursor.hasSelection(): # pick current word wordboundary.handler.select(cursor, QTextCursor.WordUnderCursor) word = cursor.selection().toPlainText() if not re.search(r'\w', word): word = "" elif self.regexCheck.isChecked(): word = re.escape(word) with qutil.signalsBlocked(self.searchEntry): self.searchEntry.setText(word) self.slotSearchChanged() else: self.highlightingOn() self.searchEntry.setFocus()
def updateDisplay(self): data = self.data[self.scheme.currentScheme()] with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(data.font) self.fontSize.setValue(data.font.pointSizeF()) with qutil.signalsBlocked(self): # update base colors for name in textformats.baseColors: self.baseColorsWidget.color[name].setColor(data.baseColors[name]) # update base colors for whole treewidget p = QApplication.palette() p.setColor(QPalette.Base, data.baseColors['background']) p.setColor(QPalette.Text, data.baseColors['text']) p.setColor(QPalette.Highlight, data.baseColors['selectionbackground']) p.setColor(QPalette.HighlightedText, data.baseColors['selectiontext']) self.tree.setPalette(p) def setItemTextFormat(item, f): font = QFont(data.font) if f.hasProperty(QTextFormat.ForegroundBrush): item.setForeground(0, f.foreground().color()) else: item.setForeground(0, data.baseColors['text']) if f.hasProperty(QTextFormat.BackgroundBrush): item.setBackground(0, f.background().color()) else: item.setBackground(0, QBrush()) font.setWeight(f.fontWeight()) font.setItalic(f.fontItalic()) font.setUnderline(f.fontUnderline()) item.setFont(0, font) # update looks of default styles for name in textformats.defaultStyles: setItemTextFormat(self.defaultStyles[name], data.defaultStyles[name]) # update looks of all the specific styles for group, styles in textformats.allStyles: children = self.allStyles[group][1] for name in styles: inherit = textformats.inherits[group].get(name) f = QTextCharFormat(data.defaultStyles[inherit]) if inherit else QTextCharFormat() f.merge(data.allStyles[group][name]) setItemTextFormat(children[name], f)
def currentSchemeChanged(self): scheme = self.scheme.currentScheme() if scheme not in self.data: self.data[scheme] = textformats.TextFormatData(scheme) self.updateDisplay() if self.tree.currentItem(): self.currentItemChanged(self.tree.currentItem(), None) with qutil.signalsBlocked(self.printScheme): self.printScheme.setChecked(scheme == self._printScheme)
def loadSettings(self): s = QSettings() s.beginGroup("log") font = QFont(s.value("fontfamily", "monospace")) font.setPointSizeF(float(s.value("fontsize", 9.0))) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(font.pointSizeF()) self.showlog.setChecked(s.value("show_on_start", True) not in (False, "false")) self.rawview.setChecked(s.value("rawview", True) not in (False, "false"))
def loadSettings(self): s = QSettings() s.beginGroup("log") font = QFont(s.value("fontfamily", "monospace", type(""))) font.setPointSizeF(s.value("fontsize", 9.0, float)) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(font.pointSizeF()) self.showlog.setChecked(s.value("show_on_start", True, bool)) self.rawview.setChecked(s.value("rawview", True, bool)) self.hideauto.setChecked(s.value("hide_auto_engrave", False, bool))
def initSvg(self, doc): """Opens first page of score after compilation""" if doc == self.mainwindow().currentDocument(): files = svgfiles.SvgFiles.instance(doc) model = files.model() # forces update if files: self._document = doc with qutil.signalsBlocked(self.pageCombo): self.pageCombo.setModel(model) self.pageCombo.setCurrentIndex(files.current) self.view.load(files.url(files.current))
def loadSettings(self): s = QSettings() s.beginGroup("charmaptool") font = self.font() family = s.value("fontfamily", "", type("")) if family: font.setFamily(family) font.setPointSizeF(s.value("fontsize", font.pointSizeF(), float)) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(font.pointSizeF())
def loadSettings(self): s = QSettings() s.beginGroup("charmaptool") font = self.font() family = s.value("fontfamily", "") if family: font.setFamily(family) font.setPointSizeF(float(s.value("fontsize", font.pointSizeF()))) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(font.pointSizeF())
def loadSettings(self): s = QSettings() useArthurPrint = s.value("printing/arthurbackend_print", True, bool) self.printArthurBackend.setChecked(useArthurPrint) # see comment in pagedview and warning messages in musicview/__init__ # and viewers/__init__ for the rationale for the default value self.useCups.setChecked(s.value("printing/directcups", False if sys.platform.startswith('darwin') else True, bool)) with qutil.signalsBlocked(self.resolution): self.resolution.setEditText(format(s.value("printing/dpi", 300, int)))
def loadSettings(self): s = QSettings() s.beginGroup("log") font = QFont(s.value("fontfamily", "monospace", str)) font.setPointSizeF(s.value("fontsize", 9.0, float)) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(font.pointSizeF()) self.showlog.setChecked(s.value("show_on_start", True, bool)) self.rawview.setChecked(s.value("rawview", True, bool)) self.hideauto.setChecked(s.value("hide_auto_engrave", False, bool))
def populate(self): self._group = QSettings().value("document_list/group_by_folder", False, bool) self.clear() self._paths = {} self._items = {} with qutil.signalsBlocked(self): # add all existing docs to the list for d in app.documents: self.addDocument(d) doc = self.parentWidget().mainwindow().currentDocument() if doc: self.selectDocument(doc)
def setPageCount(self, total): if total: self.setVisible(True) # L10N: page numbering: page {num} of {total} prefix, suffix = _("{num} of {total}").split('{num}') def adjust(w): w.setRange(1, total) w.setSuffix(suffix.format(total=total)) w.setPrefix(prefix.format(total=total)) else: self.setVisible(False) def adjust(w): w.setRange(0, 0) w.clear() for w in self.createdWidgets(): with qutil.signalsBlocked(w): adjust(w)
def loadSettings(self): s = QSettings() s.beginGroup("documentation") lang = s.value("language", "default", type("")) if lang in lilydoc.translations: i = lilydoc.translations.index(lang) + 2 elif lang == "C": i = 1 else: i = 0 self.languages.setCurrentIndex(i) font = self.font() family = s.value("fontfamily", "", type("")) if family: font.setFamily(family) size = s.value("fontsize", 16, int) with qutil.signalsBlocked(self.fontChooser, self.fontSize): self.fontChooser.setCurrentFont(font) self.fontSize.setValue(size)
def setCurrentPage(self, num): if num: for w in self.createdWidgets(): with qutil.signalsBlocked(w): w.setValue(num) w.lineEdit().deselect()
def loadSettings(self): s = QSettings() self.useCups.setChecked(s.value("printing/directcups", True, bool)) with qutil.signalsBlocked(self.resolution): self.resolution.setEditText( format(s.value("printing/dpi", 300, int)))
def updateTimeSlider(self): if not self._timeSlider.isSliderDown(): with qutil.signalsBlocked(self._timeSlider): self._timeSlider.setMaximum(self._player.total_time()) self._timeSlider.setValue(self._player.current_time())
def refreshMidiPorts(self): midihub.refresh_ports() with qutil.signalsBlocked(self): self.loadMidiPorts() self.loadSettings()
def updateView(self): """Recreate the items in the view.""" with qutil.signalsBlocked(self): self.clear() doc = self.parent().mainwindow().currentDocument() if not doc: return view_cursor_position = self.parent().mainwindow().textCursor( ).position() structure = documentstructure.DocumentStructure.instance(doc) last_item = None current_item = None last_block = None for i in structure.outline(): position = i.start() block = doc.findBlock(position) depth = tokeniter.state(block).depth() if block == last_block: parent = last_item elif last_block is None or depth == 1: # a toplevel item anyway parent = self else: while last_item and depth <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self else: # the item could belong to a parent item, but see if they # really are in the same (toplevel) state b = last_block.next() while b < block: depth2 = tokeniter.state(b).depth() if depth2 == 1: parent = self break while last_item and depth2 <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self break b = b.next() else: parent = last_item item = last_item = QTreeWidgetItem(parent) # set item text and display style bold if 'title' was used for name, text in i.groupdict().items(): if text: if name.startswith('title'): font = item.font(0) font.setWeight(QFont.Bold) item.setFont(0, font) break elif name.startswith('alert'): color = item.foreground(0).color() color = qutil.addcolor(color, 128, 0, 0) item.setForeground(0, QBrush(color)) font = item.font(0) font.setStyle(QFont.StyleItalic) item.setFont(0, font) elif name.startswith('text'): break else: text = i.group() item.setText(0, text) # remember whether is was collapsed by the user try: collapsed = block.userData().collapsed except AttributeError: collapsed = False item.setExpanded(not collapsed) item.depth = depth item.position = position last_block = block # scroll to the item at the view's cursor later if position <= view_cursor_position: current_item = item if current_item: self.scrollToItem(current_item)
def updateView(self): """Recreate the items in the view.""" with qutil.signalsBlocked(self): self.clear() doc = self.parent().mainwindow().currentDocument() if not doc: return view_cursor_position = self.parent().mainwindow().textCursor().position() structure = documentstructure.DocumentStructure.instance(doc) last_item = None current_item = None last_block = None for i in structure.outline(): position = i.start() block = doc.findBlock(position) depth = tokeniter.state(block).depth() if block == last_block: parent = last_item elif last_block is None or depth == 1: # a toplevel item anyway parent = self else: while last_item and depth <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self else: # the item could belong to a parent item, but see if they # really are in the same (toplevel) state b = last_block.next() while b < block: depth2 = tokeniter.state(b).depth() if depth2 == 1: parent = self break while last_item and depth2 <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self break b = b.next() else: parent = last_item item = last_item = QTreeWidgetItem(parent) # set item text and display style bold if 'title' was used for name, text in i.groupdict().items(): if text: if name.startswith('title'): font = item.font(0) font.setWeight(QFont.Bold) item.setFont(0, font) break elif name.startswith('alert'): color = item.foreground(0).color() color = qutil.addcolor(color, 128, 0, 0) item.setForeground(0, QBrush(color)) font = item.font(0) font.setStyle(QFont.StyleItalic) item.setFont(0, font) elif name.startswith('text'): break else: text = i.group() item.setText(0, text) # remember whether is was collapsed by the user try: collapsed = block.userData().collapsed except AttributeError: collapsed = False item.setExpanded(not collapsed) item.depth = depth item.position = position last_block = block # scroll to the item at the view's cursor later if position <= view_cursor_position: current_item = item if current_item: self.scrollToItem(current_item)