def createKeySignatureWidget(self): self.keySignatureLabel = QLabel() self.keyNote = QComboBox() self.keyNote.setModel(listmodel.ListModel(keyNames['nederlands'], self.keyNote)) self.keyMode = QComboBox() self.keyMode.setModel(listmodel.ListModel(modes, self.keyMode, display=listmodel.translate_index(1))) self.keySignatureLabel.setBuddy(self.keyNote)
def createMetronomeWidget(self): self.metronomeLabel = QLabel() self.metronomeNote = QComboBox() self.metronomeNote.setModel( listmodel.ListModel( durations, display=None, icon=lambda item: symbols.icon('note_{0}'.format( item.replace('.', 'd'))))) self.metronomeNote.setCurrentIndex(durations.index('4')) self.metronomeNote.view().setIconSize(QSize(22, 22)) self.metronomeEqualSign = QLabel('=') self.metronomeEqualSign.setFixedWidth( self.metronomeEqualSign.minimumSizeHint().width()) self.metronomeValue = QComboBox(editable=True) self.metronomeValue.setModel( listmodel.ListModel(metronomeValues, self.metronomeValue, display=format)) self.metronomeValue.setCompleter(None) self.metronomeValue.setValidator( QIntValidator(0, 999, self.metronomeValue)) self.metronomeValue.setCurrentIndex(metronomeValues.index(100)) self.metronomeTempo = widgets.tempobutton.TempoButton() self.metronomeTempo.tempo.connect(self.setMetronomeValue) self.metronomeLabel.setBuddy(self.metronomeNote) self.metronomeRound = QCheckBox()
def __init__(self, parent): super(InstrumentNames, self).__init__(parent, checkable=True, checked=True) grid = QGridLayout() self.setLayout(grid) self.firstSystemLabel = QLabel() self.firstSystem = QComboBox() self.firstSystemLabel.setBuddy(self.firstSystem) self.otherSystemsLabel = QLabel() self.otherSystems = QComboBox() self.otherSystemsLabel.setBuddy(self.otherSystems) self.languageLabel = QLabel() self.language = QComboBox() self.languageLabel.setBuddy(self.language) self.firstSystem.setModel( listmodel.ListModel((lambda: _("Long"), lambda: _("Short")), self.firstSystem, display=listmodel.translate)) self.otherSystems.setModel( listmodel.ListModel( (lambda: _("Long"), lambda: _("Short"), lambda: _("None")), self.otherSystems, display=listmodel.translate)) self._langs = l = ['', 'C'] l.extend(sorted(po.available())) def display(lang): if lang == 'C': return _("English (untranslated)") elif not lang: return _("Default") return language_names.languageName(lang, po.setup.current()) self.language.setModel( listmodel.ListModel(l, self.language, display=display)) grid.addWidget(self.firstSystemLabel, 0, 0) grid.addWidget(self.firstSystem, 0, 1) grid.addWidget(self.otherSystemsLabel, 1, 0) grid.addWidget(self.otherSystems, 1, 1) grid.addWidget(self.languageLabel, 2, 0) grid.addWidget(self.language, 2, 1) app.translateUI(self) self.loadSettings() self.window().finished.connect(self.saveSettings)
def createWidgets(self, layout): self.systemStartLabel = QLabel() self.systemStart = QComboBox() self.systemStartLabel.setBuddy(self.systemStart) self.systemStart.setModel( listmodel.ListModel( ( # L10N: Brace like a piano staff (lambda: _("Brace"), 'system_start_brace'), # L10N: Bracket like a choir staff (lambda: _("Bracket"), 'system_start_bracket'), # L10N: Square bracket like a sub-group (lambda: _("Square"), 'system_start_square'), ), self.systemStart, display=listmodel.translate_index(0), icon=lambda item: symbols.icon(item[1]))) self.systemStart.setIconSize(QSize(64, 64)) self.connectBarLines = QCheckBox(checked=True) box = QHBoxLayout() box.addWidget(self.systemStartLabel) box.addWidget(self.systemStart) layout.addLayout(box) layout.addWidget(self.connectBarLines)
def _load(self): _librarys = zfused_api.library.entity_cache([self._library_id]) if not _librarys: _librarys = [] self.entity_model = listmodel.ListModel(_librarys, self.entity_listview) self.entity_proxy_model.setSourceModel(self.entity_model)
def lyriccommands(self, cursor): return listmodel.ListModel(sorted( set( itertools.chain(('set stanza = ', 'set', 'override', 'markup', 'notemode', 'repeat'), harvest.include_identifiers(cursor), harvest.names(cursor)))), display=util.command)
def bookcommands(self, cursor): """Stuff inside \\book { }. """ return listmodel.ListModel(sorted( set( itertools.chain(completiondata.book, harvest.include_identifiers(cursor), harvest.names(cursor)))), display=util.command)
def slotDocumentClosed(self, document): if document == self._document: self._document = None self._fileSelector.setModel(listmodel.ListModel([])) self._player.stop() self._player.clear() self.updateTimeSlider() self._display.reset()
def model(self): """Returns a model for a combobox.""" if self._files is None: self.update() m = listmodel.ListModel(self._files, display = os.path.basename, icon = icons.file_type) m.setRoleFunction(Qt.UserRole, lambda f: f) return m
def markup(self, cursor): """Completes markup commands and normal text from the document.""" return listmodel.ListModel( ['\\' + w for w in sorted(ly.words.markupcommands)] + [ '\\' + w for w in sorted(set(itertools.chain( harvest.markup_commands(cursor), harvest.include_markup_commands(cursor))))] + sorted(set(harvest.words(self.document()))))
def schemewords(self): """Scheme names, including those harvested from document.""" schemewords = set( itertools.chain( ly.data.all_scheme_words(), (str(t) for t in harvest.schemewords(self.document()) if len(t) > 2), )) return listmodel.ListModel(sorted(schemewords))
def createPickupWidget(self): self.pickupLabel = QLabel() self.pickup = QComboBox() pickups = [''] pickups.extend(durations) self.pickup.setModel(listmodel.ListModel(pickups, self.pickup, display = lambda item: item or _("None"), icon = lambda item: symbols.icon('note_{0}'.format(item.replace('.', 'd'))) if item else None)) self.pickup.view().setIconSize(QSize(22, 22)) self.pickupLabel.setBuddy(self.pickup)
def musiccommands(self, cursor): return listmodel.ListModel(sorted( set( itertools.chain(ly.words.lilypond_keywords, ly.words.lilypond_music_commands, ly.words.articulations, ly.words.ornaments, ly.words.fermatas, ly.words.instrument_scripts, ly.words.repeat_scripts, harvest.include_identifiers(cursor), harvest.names(cursor)))), display=util.command)
def createTimeSignatureWidget(self): self.timeSignatureLabel = QLabel() self.timeSignature = QComboBox(editable=True) icons = { '(4/4)': symbols.icon('time_c44'), '(2/2)': symbols.icon('time_c22'), } self.timeSignature.setModel(listmodel.ListModel(timeSignaturePresets, self.timeSignature, icon=icons.get)) self.timeSignature.setCompleter(None) self.timeSignatureLabel.setBuddy(self.timeSignature)
def createWidgets(self, layout): self.chordStyleLabel = QLabel() self.chordStyle = QComboBox() self.chordStyleLabel.setBuddy(self.chordStyle) self.chordStyle.setModel(listmodel.ListModel(chordNameStyles, self.chordStyle, display=listmodel.translate)) self.guitarFrets = QCheckBox() box = QHBoxLayout() box.addWidget(self.chordStyleLabel) box.addWidget(self.chordStyle) layout.addLayout(box) layout.addWidget(self.guitarFrets)
def createWidgets(self, layout): self.label = QLabel(wordWrap=True) self.voicingLabel = QLabel() self.voicing = QComboBox(editable=True) self.voicingLabel.setBuddy(self.voicing) self.voicing.setCompleter(None) self.voicing.setValidator( QRegExpValidator(QRegExp("[SATB]+(-[SATB]+)*", Qt.CaseInsensitive), self.voicing)) self.voicing.addItems(( 'SA-TB', 'S-A-T-B', 'SA', 'S-A', 'SS-A', 'S-S-A', 'TB', 'T-B', 'TT-B', 'T-T-B', 'SS-A-T-B', 'S-A-TT-B', 'SS-A-TT-B', 'S-S-A-T-T-B', 'S-S-A-A-T-T-B-B', )) self.lyricsLabel = QLabel() self.lyrics = QComboBox() self.lyricsLabel.setBuddy(self.lyrics) self.lyrics.setModel( listmodel.ListModel(lyricStyles, self.lyrics, display=listmodel.translate_index(0), tooltip=listmodel.translate_index(1))) self.lyrics.setCurrentIndex(0) self.pianoReduction = QCheckBox() self.rehearsalMidi = QCheckBox() layout.addWidget(self.label) box = QHBoxLayout() layout.addLayout(box) box.addWidget(self.voicingLabel) box.addWidget(self.voicing) self.createStanzaWidget(layout) box = QHBoxLayout() layout.addLayout(box) box.addWidget(self.lyricsLabel) box.addWidget(self.lyrics) self.createAmbitusWidget(layout) layout.addWidget(self.pianoReduction) layout.addWidget(self.rehearsalMidi)
def includenames(self, cursor, directory=None): """Finds files relative to the directory of the cursor's document. If the document has a local filename, looks in that directory, also in a subdirectory of it, if the directory argument is given. Then looks recursively in the user-set include paths, and finally in LilyPond's own ly/ folder. """ names = [] # names in current dir path = self.document().url().toLocalFile() if path: basedir = os.path.dirname(path) if directory: basedir = os.path.join(basedir, directory) names.extend( sorted( os.path.join(directory, f) for f in get_filenames(basedir, True))) else: names.extend(sorted(get_filenames(basedir, True))) # names in specified include paths import documentinfo for basedir in documentinfo.info(self.document()).includepath(): # store dir relative to specified include path root reldir = directory if directory else "" # look for files in the current relative directory for f in sorted(get_filenames(os.path.join(basedir, reldir), True)): names.append(os.path.join(reldir, f)) # names from LilyPond itself import engrave.command datadir = engrave.command.info(self.document()).datadir() if datadir: basedir = os.path.join(datadir, 'ly') # get the filenames but avoid the -init files here names.extend( sorted(f for f in get_filenames(basedir) if not f.endswith('init.ly') and f.islower())) # forward slashes on Windows (issue #804) if os.name == "nt": names = [name.replace('\\', '/') for name in names] return listmodel.ListModel(names)
def createWidgets(self, layout): self.staffTypeLabel = QLabel() self.staffType = QComboBox() self.staffTypeLabel.setBuddy(self.staffType) self.staffType.setModel( listmodel.ListModel(tablatureStaffTypes, self.staffType, display=listmodel.translate)) box = QHBoxLayout() layout.addLayout(box) box.addWidget(self.staffTypeLabel) box.addWidget(self.staffType) if self.tunings: self.createTuningWidgets(layout) self.staffType.activated.connect(self.slotTabEnable) self.slotTabEnable(0)
def createWidgets(self, layout): self.voicesLabel = QLabel() self.voices = QSpinBox(minimum=1, maximum=4, value=1) self.drumStyleLabel = QLabel() self.drumStyle = QComboBox() self.drumStyle.setModel(listmodel.ListModel(drumStyles, self.drumStyle, display=listmodel.translate)) self.drumStems = QCheckBox() box = QHBoxLayout() box.addWidget(self.voicesLabel) box.addWidget(self.voices) layout.addLayout(box) box = QHBoxLayout() box.addWidget(self.drumStyleLabel) box.addWidget(self.drumStyle) layout.addLayout(box) layout.addWidget(self.drumStems)
def updateDocument(self): """(Re)read the output documents of the current document and show them.""" docs = self._documents = documents.group(self._document).documents() self.setVisible(bool(docs)) self.setEnabled(bool(docs)) # make model for the docs m = self._model = listmodel.ListModel([d.filename() for d in docs], display = os.path.basename, icon = icons.file_type) m.setRoleFunction(Qt.UserRole, lambda f: f) for w in self.createdWidgets(): w.setModel(m) index = self._indices.get(self._document, 0) if index < 0 or index >= len(docs): index = 0 self.documentsChanged.emit() self.setCurrentIndex(index)
def completionCursor(self): cursor = self.textCursor() if self.popup().isVisible() and self._pos < cursor.position(): cursor.setPosition(self._pos, cursor.KeepAnchor) return cursor # alter the model pos = cursor.position() text = cursor.document().toPlainText() # skip '-*- ' lines declaring variables, and check if it is python python = False block = cursor.document().firstBlock() start = 0 while block.text().startswith('-*- '): if not python: python = any(True for m in snippets._variables_re.finditer(block.text()) if m.group(1) == 'python') block = block.next() if not block.isValid(): break start = block.position() # determine the word set to complete on if python: pattern = r'\w+' else: pattern = r'\\?[\w-]+' rx = re.compile(pattern) words = set(m.group() for m in rx.finditer(text, start) if len(m.group()) > 4 and m.end() != pos) if python: words.update(keyword.kwlist) words.update(('cursor', 'state', 'text')) if words: self.setModel(listmodel.ListModel(sorted(words))) cursor.movePosition(cursor.StartOfWord, cursor.KeepAnchor) self._pos = cursor.position() return cursor
def __init__(self, tool): super(Widget, self).__init__(tool) layout = QVBoxLayout() self.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) self.blockCombo = QComboBox() self.charmap = CharMapWidget() layout.addWidget(self.blockCombo) layout.addWidget(self.charmap) # size policy of combo p = self.blockCombo.sizePolicy() p.setHorizontalPolicy(QSizePolicy.Ignored) self.blockCombo.setSizePolicy(p) # size policy of combo popup p = self.blockCombo.view().sizePolicy() p.setHorizontalPolicy(QSizePolicy.MinimumExpanding) self.blockCombo.view().setSizePolicy(p) model = listmodel.ListModel(_blocks, display = lambda b: b.name) self.blockCombo.setModel(model) # load block setting name = QSettings().value("charmaptool/last_block", "", type("")) if name: for i, b in enumerate(_blocks): if b.name == name: self.blockCombo.setCurrentIndex(i) break self.blockCombo.activated[int].connect(self.updateBlock) self.updateBlock() self.loadSettings() app.settingsChanged.connect(self.loadSettings)
def createTuningWidgets(self, layout): self.tuningLabel = QLabel() self.tuning = QComboBox() self.tuningLabel.setBuddy(self.tuning) tunings = [('', lambda: _("Default"))] tunings.extend(self.tunings) tunings.append(('', lambda: _("Custom tuning"))) self.tuning.setModel( listmodel.ListModel(tunings, self.tuning, display=listmodel.translate_index(1))) self.tuning.setCurrentIndex(1) self.customTuning = QLineEdit(enabled=False) completionmodel.complete( self.customTuning, "scorewiz/completion/plucked_strings/custom_tuning") self.tuning.currentIndexChanged.connect(self.slotCustomTuningEnable) box = QHBoxLayout() layout.addLayout(box) box.addWidget(self.tuningLabel) box.addWidget(self.tuning) layout.addWidget(self.customTuning)
def __init__(self, mainwindow): super(Dialog, self).__init__(mainwindow) self._document = None layout = QGridLayout() self.setLayout(layout) self.versionLabel = QLabel() self.lilyChooser = lilychooser.LilyChooser() self.outputLabel = QLabel() self.outputCombo = QComboBox() self.resolutionLabel = QLabel() self.resolutionCombo = QComboBox(editable=True) self.antialiasLabel = QLabel() self.antialiasSpin = QSpinBox(minimum=1, maximum=128, value=1) self.modeLabel = QLabel() self.modeCombo = QComboBox() self.deleteCheck = QCheckBox() self.embedSourceCodeCheck = QCheckBox() self.englishCheck = QCheckBox() self.commandLineLabel = QLabel() self.commandLine = QTextEdit(acceptRichText=False) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttons.button(QDialogButtonBox.Ok).setIcon( icons.get("lilypond-run")) userguide.addButton(self.buttons, "engrave_custom") self.resolutionCombo.addItems(['100', '200', '300', '600', '1200']) self.resolutionCombo.setCurrentIndex(2) self.modeCombo.addItems(['preview', 'publish', 'debug']) layout.addWidget(self.versionLabel, 0, 0) layout.addWidget(self.lilyChooser, 0, 1, 1, 3) layout.addWidget(self.outputLabel, 1, 0) layout.addWidget(self.outputCombo, 1, 1, 1, 3) layout.addWidget(self.resolutionLabel, 2, 0) layout.addWidget(self.resolutionCombo, 2, 1) layout.addWidget(self.antialiasLabel, 2, 2, Qt.AlignRight) layout.addWidget(self.antialiasSpin, 2, 3) layout.addWidget(self.modeLabel, 3, 0) layout.addWidget(self.modeCombo, 3, 1, 1, 3) layout.addWidget(self.deleteCheck, 4, 0, 1, 4) layout.addWidget(self.embedSourceCodeCheck, 5, 0, 1, 4) layout.addWidget(self.englishCheck, 6, 0, 1, 4) layout.addWidget(self.commandLineLabel, 7, 0, 1, 4) layout.addWidget(self.commandLine, 8, 0, 1, 4) layout.addWidget(widgets.Separator(), 9, 0, 1, 4) layout.addWidget(self.buttons, 10, 0, 1, 4) app.translateUI(self) qutil.saveDialogSize(self, "engrave/custom/dialog/size", QSize(480, 260)) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) model = listmodel.ListModel(formats, display=lambda f: f.title(), icon=lambda f: icons.file_type(f.type)) self.outputCombo.setModel(model) s = QSettings() s.beginGroup("lilypond_settings") self.englishCheck.setChecked(s.value("no_translation", False, bool)) self.deleteCheck.setChecked( s.value("delete_intermediate_files", True, bool)) if s.value("default_output_target", "pdf", str) == "svg": self.outputCombo.setCurrentIndex(3) app.jobFinished.connect(self.slotJobFinished) self.outputCombo.currentIndexChanged.connect(self.makeCommandLine) self.modeCombo.currentIndexChanged.connect(self.makeCommandLine) self.deleteCheck.toggled.connect(self.makeCommandLine) self.embedSourceCodeCheck.toggled.connect(self.makeCommandLine) self.resolutionCombo.editTextChanged.connect(self.makeCommandLine) self.antialiasSpin.valueChanged.connect(self.makeCommandLine) self.makeCommandLine() panelmanager.manager( mainwindow).layoutcontrol.widget().optionsChanged.connect( self.makeCommandLine)
def font_names(): model = listmodel.ListModel(sorted(QFontDatabase().families())) model.setRoleFunction(Qt.FontRole, QFont) return model
def lilypond_grob_properties(grob, hash_quote=True): display = (lambda item: "#'" + item) if hash_quote else (lambda item: item) return listmodel.ListModel(ly.data.grob_properties(grob), display=display)
# stuff inside \score {} score = sorted(everywhere + inputmodes + start_music + blocks[1:] + ('midi {', )) # stuff inside \bookpart {} bookpart = sorted(everywhere + inputmodes + markup + start_music + modes[2:] + blocks) # stuff inside \book {} book = sorted(everywhere + inputmodes + markup + start_music + modes[1:] + blocks + ( 'bookOutputName', 'bookOutputSuffix', )) lilypond_markup = listmodel.ListModel(['\\markup']) lilypond_markup_commands = listmodel.ListModel(sorted(ly.words.markupcommands), display=util.command) lilypond_header_variables = listmodel.ListModel(sorted( ly.words.headervariables, key=lambda i: i[:3]), edit=util.variable) lilypond_paper_variables = listmodel.ListModel(sorted(ly.words.papervariables), edit=util.variable) lilypond_layout_variables = listmodel.ListModel([ '\\context {', '\\override', '\\set',
def loadMidiPorts(self): output_ports = midihub.output_ports() self._playerPort.setModel(listmodel.ListModel(output_ports)) input_ports = midihub.input_ports() self._inputPort.setModel(listmodel.ListModel(input_ports)) self._portsMessage.setVisible((not output_ports) and (not input_ports))
def words(self): """Returns the list of words in comments, markup etc.""" return listmodel.ListModel(sorted(set(harvest.words(self.document()))))