class LilyPondPreferences(QGroupBox): def __init__(self, parent): super(LilyPondPreferences, self).__init__(parent) grid = QGridLayout() self.setLayout(grid) self.pitchLanguageLabel = QLabel() self.pitchLanguage = QComboBox() self.versionLabel = QLabel() self.version = QComboBox(editable=True) self.pitchLanguage.addItem('') self.pitchLanguage.addItems( [lang.title() for lang in sorted(scoreproperties.keyNames)]) self.version.addItem(lilypondinfo.preferred().versionString()) for v in ("2.18.0", "2.16.0", "2.14.0", "2.12.0"): if v != lilypondinfo.preferred().versionString(): self.version.addItem(v) grid.addWidget(self.pitchLanguageLabel, 0, 0) grid.addWidget(self.pitchLanguage, 0, 1) grid.addWidget(self.versionLabel, 1, 0) grid.addWidget(self.version, 1, 1) self.pitchLanguage.activated.connect(self.slotPitchLanguageChanged) app.translateUI(self) self.loadSettings() self.window().finished.connect(self.saveSettings) def translateUI(self): self.setTitle(_("LilyPond")) self.pitchLanguageLabel.setText(_("Pitch name language:")) self.pitchLanguage.setToolTip( _("The LilyPond language you want to use for the pitch names.")) self.pitchLanguage.setItemText(0, _("Default")) self.versionLabel.setText(_("Version:")) self.version.setToolTip( _("The LilyPond version you will be using for this document.")) def slotPitchLanguageChanged(self, index): if index == 0: language = '' else: language = self.pitchLanguage.currentText().lower() self.window().setPitchLanguage(language) def loadSettings(self): language = self.window().pitchLanguage() languages = list(sorted(scoreproperties.keyNames)) index = languages.index(language) + 1 if language in languages else 0 self.pitchLanguage.setCurrentIndex(index) def saveSettings(self): QSettings().setValue('scorewiz/lilypond/pitch_language', self.window().pitchLanguage())
class LilyPondPreferences(QGroupBox): def __init__(self, parent): super(LilyPondPreferences, self).__init__(parent) grid = QGridLayout() self.setLayout(grid) self.pitchLanguageLabel = QLabel() self.pitchLanguage = QComboBox() self.versionLabel = QLabel() self.version = QComboBox(editable=True) self.pitchLanguage.addItem('') self.pitchLanguage.addItems([lang.title() for lang in sorted(scoreproperties.keyNames)]) self.version.addItem(lilypondinfo.preferred().versionString()) for v in ("2.18.0", "2.16.0", "2.14.0", "2.12.0"): if v != lilypondinfo.preferred().versionString(): self.version.addItem(v) grid.addWidget(self.pitchLanguageLabel, 0, 0) grid.addWidget(self.pitchLanguage, 0, 1) grid.addWidget(self.versionLabel, 1, 0) grid.addWidget(self.version, 1, 1) self.pitchLanguage.activated.connect(self.slotPitchLanguageChanged) app.translateUI(self) self.loadSettings() self.window().finished.connect(self.saveSettings) def translateUI(self): self.setTitle(_("LilyPond")) self.pitchLanguageLabel.setText(_("Pitch name language:")) self.pitchLanguage.setToolTip(_( "The LilyPond language you want to use for the pitch names.")) self.pitchLanguage.setItemText(0, _("Default")) self.versionLabel.setText(_("Version:")) self.version.setToolTip(_( "The LilyPond version you will be using for this document.")) def slotPitchLanguageChanged(self, index): if index == 0: language = '' else: language = self.pitchLanguage.currentText().lower() self.window().setPitchLanguage(language) def loadSettings(self): language = self.window().pitchLanguage() languages = list(sorted(scoreproperties.keyNames)) index = languages.index(language) + 1 if language in languages else 0 self.pitchLanguage.setCurrentIndex(index) def saveSettings(self): QSettings().setValue('scorewiz/lilypond/pitch_language', self.window().pitchLanguage())
class GeneralPreferences(QGroupBox): def __init__(self, parent): super(GeneralPreferences, self).__init__(parent) layout = QVBoxLayout() self.setLayout(layout) self.typq = QCheckBox() self.tagl = QCheckBox() self.barnum = QCheckBox() self.neutdir = QCheckBox() self.midi = QCheckBox() self.metro = QCheckBox() self.paperSizeLabel = QLabel() self.paper = QComboBox() self.paper.addItems(paperSizes) self.paperLandscape = QCheckBox(enabled=False) self.paper.activated.connect(self.slotPaperChanged) layout.addWidget(self.typq) layout.addWidget(self.tagl) layout.addWidget(self.barnum) layout.addWidget(self.neutdir) layout.addWidget(self.midi) layout.addWidget(self.metro) box = QHBoxLayout(spacing=2) box.addWidget(self.paperSizeLabel) box.addWidget(self.paper) box.addWidget(self.paperLandscape) layout.addLayout(box) app.translateUI(self) self.loadSettings() self.window().finished.connect(self.saveSettings) def translateUI(self): self.setTitle(_("General preferences")) self.typq.setText(_("Use typographical quotes")) self.typq.setToolTip(_( "Replace normal quotes in titles with nice typographical quotes.")) self.tagl.setText(_("Remove default tagline")) self.tagl.setToolTip(_( "Suppress the default tagline output by LilyPond.")) self.barnum.setText(_("Remove bar numbers")) self.barnum.setToolTip(_( "Suppress the display of measure numbers at the beginning of " "every system.")) self.neutdir.setText(_("Smart neutral stem direction")) self.neutdir.setToolTip(_( "Use a logical direction (up or down) for stems on the middle " "line of a staff.")) self.midi.setText(_("Create MIDI output")) self.midi.setToolTip(_( "Create a MIDI file in addition to the PDF file.")) self.metro.setText(_("Show metronome mark")) self.metro.setToolTip(_( "If checked, show the metronome mark at the beginning of the " "score. The MIDI output also uses the metronome setting.")) # paper size: self.paperSizeLabel.setText(_("Paper size:")) self.paper.setItemText(0, _("Default")) self.paperLandscape.setText(_("Landscape")) def slotPaperChanged(self, index): self.paperLandscape.setEnabled(bool(index)) def getPaperSize(self): """Returns the configured papersize or the empty string for default.""" return paperSizes[self.paper.currentIndex()] def loadSettings(self): s = QSettings() s.beginGroup('scorewiz/preferences') self.typq.setChecked(s.value('typographical_quotes', True, bool)) self.tagl.setChecked(s.value('remove_tagline', False, bool)) self.barnum.setChecked(s.value('remove_barnumbers', False, bool)) self.neutdir.setChecked(s.value('smart_neutral_direction', False, bool)) self.midi.setChecked(s.value('midi', True, bool)) self.metro.setChecked(s.value('metronome_mark', False, bool)) psize = s.value('paper_size', '', type("")) enable = bool(psize and psize in paperSizes) self.paper.setCurrentIndex(paperSizes.index(psize) if enable else 0) self.paperLandscape.setChecked(s.value('paper_landscape', False, bool)) self.paperLandscape.setEnabled(enable) def saveSettings(self): s = QSettings() s.beginGroup('scorewiz/preferences') s.setValue('typographical_quotes', self.typq.isChecked()) s.setValue('remove_tagline', self.tagl.isChecked()) s.setValue('remove_barnumbers', self.barnum.isChecked()) s.setValue('smart_neutral_direction', self.neutdir.isChecked()) s.setValue('midi', self.midi.isChecked()) s.setValue('metronome_mark', self.metro.isChecked()) s.setValue('paper_size', paperSizes[self.paper.currentIndex()]) s.setValue('paper_landscape', self.paperLandscape.isChecked())
class experimentersDialog(QDialog): def __init__(self, parent): QDialog.__init__(self, parent) self.prm = self.parent().prm self.tmpPref = {} self.tmpPref['experimenter'] = {} self.tmpPref['experimenter'] = copy.deepcopy(self.parent().prm['experimenter']) self.currLocale = self.parent().prm['currentLocale'] self.currLocale.setNumberOptions(self.currLocale.OmitGroupSeparator | self.currLocale.RejectGroupSeparator) self.sizer = QGridLayout() self.h1Sizer = QHBoxLayout() self.v1Sizer = QVBoxLayout() self.v2Sizer = QVBoxLayout() n = 0 self.experimenterLabel = QLabel(self.tr("Experimenter ID:"), self) self.sizer.addWidget(self.experimenterLabel, n, 0) self.experimenterChooser = QComboBox() self.experimenterChooser.addItems(self.tmpPref['experimenter']['experimenter_id']) self.sizer.addWidget(self.experimenterChooser, n, 1) self.experimenterChooser.activated[str].connect(self.onExperimenterChange) self.currIdx = self.experimenterChooser.currentIndex() n = n+1 self.experimenterNameLabel = QLabel(self.tr("Name:"), self) self.sizer.addWidget(self.experimenterNameLabel, n, 0) self.experimenterNameTF = QLineEdit("") self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][0]) self.sizer.addWidget(self.experimenterNameTF, n, 1) n = n+1 self.experimenterSurnameLabel = QLabel(self.tr("Surname:"), self) self.sizer.addWidget(self.experimenterSurnameLabel, n, 0) self.experimenterSurnameTF = QLineEdit("") self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][0]) self.sizer.addWidget(self.experimenterSurnameTF, n, 1) n = n+1 self.experimenterEmailLabel = QLabel(self.tr("e-mail:"), self) self.sizer.addWidget(self.experimenterEmailLabel, n, 0) self.experimenterEmailTF = QLineEdit("") self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][0]) self.sizer.addWidget(self.experimenterEmailTF, n, 1) n = n+1 self.experimenterAddressLabel = QLabel(self.tr("Address (line 1):"), self) self.sizer.addWidget(self.experimenterAddressLabel, n, 0) self.experimenterAddressTF = QLineEdit("") self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][0]) self.sizer.addWidget(self.experimenterAddressTF, n, 1) n = n+1 self.experimenterAddressLabel2 = QLabel(self.tr("Address (line 2):"), self) self.sizer.addWidget(self.experimenterAddressLabel2, n, 0) self.experimenterAddressTF2 = QLineEdit("") self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][0]) self.sizer.addWidget(self.experimenterAddressTF2, n, 1) n = n+1 self.experimenterTelephoneLabel = QLabel(self.tr("Telephone:"), self) self.sizer.addWidget(self.experimenterTelephoneLabel, n, 0) self.experimenterTelephoneTF = QLineEdit("") self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][0]) self.sizer.addWidget(self.experimenterTelephoneTF, n, 1) n = n+1 self.experimenterMobileLabel = QLabel(self.tr("Mobile:"), self) self.sizer.addWidget(self.experimenterMobileLabel, n, 0) self.experimenterMobileTF = QLineEdit("") self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][0]) self.sizer.addWidget(self.experimenterMobileTF, n, 1) #ADD EXPERIMENTER BUTTON addExpButton = QPushButton(self.tr("Add Experimenter"), self) addExpButton.clicked.connect(self.onClickAddExpButton) self.v2Sizer.addWidget(addExpButton) #REMOVE EXPERIMENTER BUTTON removeExpButton = QPushButton(self.tr("Remove Experimenter"), self) removeExpButton.clicked.connect(self.onClickRemoveExpButton) self.v2Sizer.addWidget(removeExpButton) #CHANGE ID BUTTON changeIdButton = QPushButton(self.tr("Change Identifier"), self) changeIdButton.clicked.connect(self.onClickChangeIdButton) self.v2Sizer.addWidget(changeIdButton) #SET AS DEFAULT BUTTON setAsDefaultButton = QPushButton(self.tr("Set as default"), self) setAsDefaultButton.clicked.connect(self.onClickSetAsDefaultButton) self.v2Sizer.addWidget(setAsDefaultButton) self.v2Sizer.addStretch() buttonBox = QDialogButtonBox(QDialogButtonBox.Apply|QDialogButtonBox.Ok|QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.onClickApplyButton) self.h1Sizer.addLayout(self.v2Sizer) self.sizer.setAlignment(Qt.AlignTop) self.h1Sizer.addLayout(self.sizer) self.v1Sizer.addLayout(self.h1Sizer) self.v1Sizer.addWidget(buttonBox) self.setLayout(self.v1Sizer) def onClickApplyButton(self): self.tryApply(self.currIdx) self.permanentApply() def permanentApply(self): self.parent().prm['experimenter'] = copy.deepcopy(self.tmpPref['experimenter']) f = open(self.parent().prm['experimenterPrefFile'], 'wb') pickle.dump(self.parent().prm['experimenter'], f) f.close() for i in range(self.parent().experimenterChooser.count()): self.parent().experimenterChooser.removeItem(0) self.parent().experimenterChooser.addItems(self.parent().prm['experimenter']['experimenter_id']) def tryApply(self, idx): self.tmpPref['experimenter']['experimenter_id'][idx] = self.experimenterChooser.itemText(idx) self.tmpPref['experimenter']['experimenter_name'][idx] = self.experimenterNameTF.text() self.tmpPref['experimenter']['experimenter_surname'][idx] = self.experimenterSurnameTF.text() self.tmpPref['experimenter']['experimenter_email'][idx] = self.experimenterEmailTF.text() self.tmpPref['experimenter']['experimenter_address'][idx] = self.experimenterAddressTF.text() self.tmpPref['experimenter']['experimenter_address2'][idx] = self.experimenterAddressTF2.text() self.tmpPref['experimenter']['experimenter_telephone'][idx] = self.experimenterTelephoneTF.text() self.tmpPref['experimenter']['experimenter_mobile'][idx] = self.experimenterMobileTF.text() def revertChanges(self): if len(self.tmpPref['experimenter']['experimenter_id']) != len(self.parent().prm['experimenter']['experimenter_id']): #experimenter was added, reverting for i in range(self.experimenterChooser.count()): self.experimenterChooser.removeItem(0) self.experimenterChooser.addItems(self.parent().prm['experimenter']['experimenter_id']) self.tmpPref['experimenter'] = copy.deepcopy(self.parent().prm['experimenter']) def onExperimenterChange(self, experimenterSelected): self.prevIdx = self.currIdx self.currIdx = self.tmpPref['experimenter']['experimenter_id'].index(experimenterSelected) self.tryApply(self.prevIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() self.experimenterNameTF.setText(self.prm['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.prm['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.prm['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.prm['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.prm['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.prm['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.prm['experimenter']['experimenter_mobile'][self.currIdx]) def onClickAddExpButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() msg = self.tr("Experimenter's Identifier:") name, ok = QInputDialog.getText(self, self.tr('Input Dialog'), msg) if ok: self.tmpPref['experimenter']['defaultExperimenter'].append('') self.tmpPref['experimenter']['experimenter_id'].append(name) self.tmpPref['experimenter']['experimenter_name'].append('') self.tmpPref['experimenter']['experimenter_surname'].append('') self.tmpPref['experimenter']['experimenter_email'].append('') self.tmpPref['experimenter']['experimenter_address'].append('') self.tmpPref['experimenter']['experimenter_address2'].append('') self.tmpPref['experimenter']['experimenter_telephone'].append('') self.tmpPref['experimenter']['experimenter_mobile'].append('') self.permanentApply() self.currIdx = self.experimenterChooser.count() self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][self.currIdx]) self.experimenterChooser.addItem(name) self.experimenterChooser.setCurrentIndex(self.currIdx) def onClickRemoveExpButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() if self.experimenterChooser.count() > 1: reply = QMessageBox.warning(self, self.tr('Message'), "Remove experimenter? This action cannot be undone!", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.tmpPref['experimenter']['defaultExperimenter'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_id'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_name'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_surname'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_email'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_address'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_address2'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_telephone'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_mobile'].pop(self.currIdx) self.experimenterChooser.removeItem(self.currIdx) self.currIdx = self.experimenterChooser.currentIndex() self.permanentApply() self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][self.currIdx]) else: QMessageBox.warning(self, self.tr('Message'), self.tr("Only one experimenter left. Experimenter cannot be removed!"), QMessageBox.Ok) def onClickChangeIdButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() msg = self.tr("Experimenter's Identifier:") name, ok = QInputDialog.getText(self, self.tr('Input Dialog'), msg) if ok: self.tmpPref['experimenter']['experimenter_id'][self.currIdx] = name self.experimenterChooser.setItemText(self.currIdx, name) self.permanentApply() def onClickSetAsDefaultButton(self): idx = self.experimenterChooser.currentIndex() print(idx) self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() for i in range(len(self.parent().prm['experimenter']["defaultExperimenter"])): if i == idx: self.tmpPref['experimenter']["defaultExperimenter"][i] = "\u2713" else: self.tmpPref['experimenter']["defaultExperimenter"][i] = "\u2012" print(self.tmpPref) self.permanentApply()
class QuickInsert(QWidget): def __init__(self, dockwidget): super(QuickInsert, self).__init__(dockwidget) self._dockwidget = weakref.ref(dockwidget) # filled in by ButtonGroup subclasses self.actionDict = {} layout = QVBoxLayout() self.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) self.helpButton = QToolButton( icon=icons.get("help-contents"), autoRaise=True, clicked=lambda: userguide.show("quickinsert")) self.directionLabel = QLabel() self.direction = QComboBox() self.direction.addItems(['', '', '']) self.direction.setItemIcon(0, icons.get("go-up")) self.direction.setItemIcon(2, icons.get("go-down")) self.direction.setCurrentIndex(1) hor = QHBoxLayout() hor.setContentsMargins(0, 0, 0, 0) hor.addWidget(self.helpButton) hor.addWidget(self.directionLabel) hor.addWidget(self.direction) layout.addLayout(hor) self.toolbox = QToolBox(self) widgets.toolboxwheeler.ToolBoxWheeler(self.toolbox) layout.addWidget(self.toolbox) for cls in ( articulations.Articulations, dynamics.Dynamics, spanners.Spanners, barlines.BarLines, ): widget = cls(self) self.toolbox.addItem(widget, widget.icon(), '') app.translateUI(self) userguide.openWhatsThis(self) # restore remembered current page name = QSettings().value("quickinsert/current_tool", "", type("")) if name: for i in range(self.toolbox.count()): if name == self.toolbox.widget(i).__class__.__name__.lower(): self.toolbox.setCurrentIndex(i) break self.toolbox.currentChanged.connect(self.slotCurrentChanged) def slotCurrentChanged(self, index): name = self.toolbox.widget(index).__class__.__name__.lower() QSettings().setValue("quickinsert/current_tool", name) def translateUI(self): self.setWhatsThis( _("<p>With the Quick Insert Panel you can add various music " "elements to the current note or selected music.</p>\n" "<p>See {link} for more information.</p>").format( link=userguide.util.format_link("quickinsert"))) self.helpButton.setToolTip(_("Help")) self.directionLabel.setText(_("Direction:")) for item, text in enumerate((_("Up"), _("Neutral"), _("Down"))): self.direction.setItemText(item, text) for i in range(self.toolbox.count()): self.toolbox.setItemText(i, self.toolbox.widget(i).title()) self.toolbox.setItemToolTip(i, self.toolbox.widget(i).tooltip()) def actionForName(self, name): """This is called by the ShortcutCollection of our dockwidget, e.g. if the user presses a key.""" try: return self.actionDict[name] except KeyError: pass def dockwidget(self): return self._dockwidget()
class General(preferences.Group): def __init__(self, page): super(General, self).__init__(page) grid = QGridLayout() self.setLayout(grid) self.langLabel = QLabel() self.lang = QComboBox(currentIndexChanged=self.changed) grid.addWidget(self.langLabel, 0, 0) grid.addWidget(self.lang, 0, 1) self.styleLabel = QLabel() self.styleCombo = QComboBox(currentIndexChanged=self.changed) grid.addWidget(self.styleLabel, 1, 0) grid.addWidget(self.styleCombo, 1, 1) self.systemIcons = QCheckBox(toggled=self.changed) grid.addWidget(self.systemIcons, 2, 0, 1, 3) self.tabsClosable = QCheckBox(toggled=self.changed) grid.addWidget(self.tabsClosable, 3, 0, 1, 3) self.splashScreen = QCheckBox(toggled=self.changed) grid.addWidget(self.splashScreen, 4, 0, 1, 3) self.allowRemote = QCheckBox(toggled=self.changed) grid.addWidget(self.allowRemote, 5, 0, 1, 3) grid.setColumnStretch(2, 1) # fill in the language combo self._langs = ["C", ""] self.lang.addItems(('', '')) langnames = [(language_names.languageName(lang, lang), lang) for lang in po.available()] langnames.sort() for name, lang in langnames: self._langs.append(lang) self.lang.addItem(name) # fill in style combo self.styleCombo.addItem('') self.styleCombo.addItems(QStyleFactory.keys()) app.translateUI(self) def loadSettings(self): s = QSettings() lang = s.value("language", "", type("")) try: index = self._langs.index(lang) except ValueError: index = 1 self.lang.setCurrentIndex(index) style = s.value("guistyle", "", type("")).lower() styles = [name.lower() for name in QStyleFactory.keys()] try: index = styles.index(style) + 1 except ValueError: index = 0 self.styleCombo.setCurrentIndex(index) self.systemIcons.setChecked(s.value("system_icons", True, bool)) self.tabsClosable.setChecked(s.value("tabs_closable", True, bool)) self.splashScreen.setChecked(s.value("splash_screen", True, bool)) self.allowRemote.setChecked(remote.enabled()) def saveSettings(self): s = QSettings() s.setValue("language", self._langs[self.lang.currentIndex()]) s.setValue("system_icons", self.systemIcons.isChecked()) s.setValue("tabs_closable", self.tabsClosable.isChecked()) s.setValue("splash_screen", self.splashScreen.isChecked()) s.setValue("allow_remote", self.allowRemote.isChecked()) if self.styleCombo.currentIndex() == 0: s.remove("guistyle") else: s.setValue("guistyle", self.styleCombo.currentText()) def translateUI(self): self.setTitle(_("General Preferences")) self.langLabel.setText(_("Language:")) self.lang.setItemText(0, _("No Translation")) self.lang.setItemText(1, _("System Default Language (if available)")) self.styleLabel.setText(_("Style:")) self.styleCombo.setItemText(0, _("Default")) self.systemIcons.setText(_("Use System Icons")) self.systemIcons.setToolTip(_( "If checked, icons of the desktop icon theme " "will be used instead of the bundled icons.\n" "This setting takes effect on the next start of {appname}.").format(appname=appinfo.appname)) self.splashScreen.setText(_("Show Splash Screen on Startup")) self.tabsClosable.setText(_("Show Close Button on Document tabs")) self.allowRemote.setText(_("Open Files in Running Instance")) self.allowRemote.setToolTip(_( "If checked, files will be opened in a running Frescobaldi " "application if available, instead of starting a new instance."))
class Browser(preferences.Group): def __init__(self, page): super(Browser, self).__init__(page) layout = QGridLayout() self.setLayout(layout) self.languagesLabel = QLabel() self.languages = QComboBox(currentIndexChanged=self.changed) layout.addWidget(self.languagesLabel, 0, 0) layout.addWidget(self.languages, 0, 1) items = ['', ''] items.extend(language_names.languageName(l, l) for l in lilydoc.translations) self.languages.addItems(items) self.fontLabel = QLabel() self.fontChooser = QFontComboBox(currentFontChanged=self.changed) self.fontSize = QSpinBox(valueChanged=self.changed) self.fontSize.setRange(6, 32) self.fontSize.setSingleStep(1) layout.addWidget(self.fontLabel, 1, 0) layout.addWidget(self.fontChooser, 1, 1) layout.addWidget(self.fontSize, 1, 2) app.translateUI(self) def translateUI(self): self.setTitle(_("Documentation Browser")) self.languagesLabel.setText(_("Preferred Language:")) self.languages.setItemText(0, _("Default")) self.languages.setItemText(1, _("English (untranslated)")) self.fontLabel.setText(_("Font:")) 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 saveSettings(self): s = QSettings() s.beginGroup("documentation") langs = ['default', 'C'] + lilydoc.translations s.setValue("language", langs[self.languages.currentIndex()]) s.setValue("fontfamily", self.fontChooser.currentFont().family()) s.setValue("fontsize", self.fontSize.value())
class GeneralPreferences(QGroupBox): def __init__(self, parent): super(GeneralPreferences, self).__init__(parent) layout = QVBoxLayout() self.setLayout(layout) self.typq = QCheckBox() self.tagl = QCheckBox() self.barnum = QCheckBox() self.neutdir = QCheckBox() self.midi = QCheckBox() self.metro = QCheckBox() self.paperSizeLabel = QLabel() self.paper = QComboBox() self.paper.addItems(paperSizes) self.paperLandscape = QCheckBox(enabled=False) self.paper.activated.connect(self.slotPaperChanged) layout.addWidget(self.typq) layout.addWidget(self.tagl) layout.addWidget(self.barnum) layout.addWidget(self.neutdir) layout.addWidget(self.midi) layout.addWidget(self.metro) box = QHBoxLayout(spacing=2) box.addWidget(self.paperSizeLabel) box.addWidget(self.paper) box.addWidget(self.paperLandscape) layout.addLayout(box) app.translateUI(self) self.loadSettings() self.window().finished.connect(self.saveSettings) def translateUI(self): self.setTitle(_("General preferences")) self.typq.setText(_("Use typographical quotes")) self.typq.setToolTip( _("Replace normal quotes in titles with nice typographical quotes." )) self.tagl.setText(_("Remove default tagline")) self.tagl.setToolTip( _("Suppress the default tagline output by LilyPond.")) self.barnum.setText(_("Remove bar numbers")) self.barnum.setToolTip( _("Suppress the display of measure numbers at the beginning of " "every system.")) self.neutdir.setText(_("Smart neutral stem direction")) self.neutdir.setToolTip( _("Use a logical direction (up or down) for stems on the middle " "line of a staff.")) self.midi.setText(_("Create MIDI output")) self.midi.setToolTip( _("Create a MIDI file in addition to the PDF file.")) self.metro.setText(_("Show metronome mark")) self.metro.setToolTip( _("If checked, show the metronome mark at the beginning of the " "score. The MIDI output also uses the metronome setting.")) # paper size: self.paperSizeLabel.setText(_("Paper size:")) self.paper.setItemText(0, _("Default")) self.paperLandscape.setText(_("Landscape")) def slotPaperChanged(self, index): self.paperLandscape.setEnabled(bool(index)) def getPaperSize(self): """Returns the configured papersize or the empty string for default.""" return paperSizes[self.paper.currentIndex()] def loadSettings(self): s = QSettings() s.beginGroup('scorewiz/preferences') self.typq.setChecked(s.value('typographical_quotes', True, bool)) self.tagl.setChecked(s.value('remove_tagline', False, bool)) self.barnum.setChecked(s.value('remove_barnumbers', False, bool)) self.neutdir.setChecked(s.value('smart_neutral_direction', False, bool)) self.midi.setChecked(s.value('midi', True, bool)) self.metro.setChecked(s.value('metronome_mark', False, bool)) psize = s.value('paper_size', '', type("")) enable = bool(psize and psize in paperSizes) self.paper.setCurrentIndex(paperSizes.index(psize) if enable else 0) self.paperLandscape.setChecked(s.value('paper_landscape', False, bool)) self.paperLandscape.setEnabled(enable) def saveSettings(self): s = QSettings() s.beginGroup('scorewiz/preferences') s.setValue('typographical_quotes', self.typq.isChecked()) s.setValue('remove_tagline', self.tagl.isChecked()) s.setValue('remove_barnumbers', self.barnum.isChecked()) s.setValue('smart_neutral_direction', self.neutdir.isChecked()) s.setValue('midi', self.midi.isChecked()) s.setValue('metronome_mark', self.metro.isChecked()) s.setValue('paper_size', paperSizes[self.paper.currentIndex()]) s.setValue('paper_landscape', self.paperLandscape.isChecked())
class Dialog(QDialog): def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None self._path = None mainLayout = QGridLayout() self.setLayout(mainLayout) tabs = QTabWidget() import_tab = QWidget() post_tab = QWidget() itabLayout = QGridLayout(import_tab) ptabLayout = QGridLayout(post_tab) tabs.addTab(import_tab, "musicxml2ly") tabs.addTab(post_tab, "after import") self.noartCheck = QCheckBox() self.norestCheck = QCheckBox() self.nolayoutCheck = QCheckBox() self.nobeamCheck = QCheckBox() self.useAbsCheck = QCheckBox() self.langCombo = QComboBox() self.langLabel = QLabel() self.impChecks = [ self.noartCheck, self.norestCheck, self.nolayoutCheck, self.nobeamCheck, self.useAbsCheck ] self.formatCheck = QCheckBox() self.trimDurCheck = QCheckBox() self.removeScalesCheck = QCheckBox() self.runEngraverCheck = QCheckBox() self.postChecks = [ self.formatCheck, self.trimDurCheck, self.removeScalesCheck, self.runEngraverCheck ] self.commandLineLabel = QLabel() self.commandLine = QTextEdit(acceptRichText=False) self.setChecksObjectNames() self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) userguide.addButton(self.buttons, "musicxml_import") self.langCombo.addItem('') self.langCombo.addItems(_langlist) itabLayout.addWidget(self.noartCheck, 0, 0, 1, 2) itabLayout.addWidget(self.norestCheck, 1, 0, 1, 2) itabLayout.addWidget(self.nolayoutCheck, 2, 0, 1, 2) itabLayout.addWidget(self.nobeamCheck, 3, 0, 1, 2) itabLayout.addWidget(self.useAbsCheck, 4, 0, 1, 2) itabLayout.addWidget(self.langLabel, 5, 0, 1, 2) itabLayout.addWidget(self.langCombo, 6, 0, 1, 2) itabLayout.addWidget(widgets.Separator(), 7, 0, 1, 2) itabLayout.addWidget(self.commandLineLabel, 8, 0, 1, 2) itabLayout.addWidget(self.commandLine, 9, 0, 1, 2) ptabLayout.addWidget(self.formatCheck, 0, 0, 1, 2) ptabLayout.addWidget(self.trimDurCheck, 1, 0, 1, 2) ptabLayout.addWidget(self.removeScalesCheck, 2, 0, 1, 2) ptabLayout.addWidget(self.runEngraverCheck, 3, 0, 1, 2) ptabLayout.setRowStretch(4, 10) mainLayout.addWidget(tabs, 0, 0, 9, 2) mainLayout.addWidget(self.buttons, 10, 0, 1, 2) app.translateUI(self) qutil.saveDialogSize(self, "xml_import/dialog/size", QSize(480, 260)) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.noartCheck.toggled.connect(self.makeCommandLine) self.norestCheck.toggled.connect(self.makeCommandLine) self.nolayoutCheck.toggled.connect(self.makeCommandLine) self.nobeamCheck.toggled.connect(self.makeCommandLine) self.useAbsCheck.toggled.connect(self.makeCommandLine) self.langCombo.currentIndexChanged.connect(self.makeCommandLine) self.makeCommandLine() self.loadSettings() def setChecksObjectNames(self): self.noartCheck.setObjectName("articulation-directions") self.norestCheck.setObjectName("rest-positions") self.nolayoutCheck.setObjectName("page-layout") self.nobeamCheck.setObjectName("import-beaming") self.useAbsCheck.setObjectName("absolute-mode") self.formatCheck.setObjectName("reformat") self.trimDurCheck.setObjectName("trim-durations") self.removeScalesCheck.setObjectName("remove-scaling") self.runEngraverCheck.setObjectName("engrave-directly") def translateUI(self): self.setWindowTitle(app.caption(_("Import Music XML"))) self.noartCheck.setText(_("Import articulation directions")) self.norestCheck.setText(_("Import rest positions")) self.nolayoutCheck.setText(_("Import page layout")) self.nobeamCheck.setText(_("Import beaming")) self.useAbsCheck.setText(_("Pitches in absolute mode")) self.commandLineLabel.setText(_("Command line:")) self.langLabel.setText(_("Language for pitch names")) self.langCombo.setItemText(0, _("Default")) self.formatCheck.setText(_("Reformat source")) self.trimDurCheck.setText(_("Trim durations (Make implicit per line)")) self.removeScalesCheck.setText(_("Remove fraction duration scaling")) self.runEngraverCheck.setText(_("Engrave directly")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run musicxml2ly")) def setDocument(self, path): """Set the full path to the MusicXML document.""" self._document = path def makeCommandLine(self): """Reads the widgets and builds a command line.""" cmd = ["$musicxml2ly"] if self.useAbsCheck.isChecked(): cmd.append('-a') if not self.noartCheck.isChecked(): cmd.append('--nd') if not self.norestCheck.isChecked(): cmd.append('--nrp') if not self.nolayoutCheck.isChecked(): cmd.append('--npl') if not self.nobeamCheck.isChecked(): cmd.append('--no-beaming') index = self.langCombo.currentIndex() if index > 0: cmd.append('--language=' + _langlist[index - 1]) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def getCmd(self): """Returns the command line.""" cmd = [] for t in self.commandLine.toPlainText().split(): if t == '$musicxml2ly': cmd.extend(lilypondinfo.preferred().toolcommand('musicxml2ly')) elif t == '$filename': cmd.append(self._document) else: cmd.append(t) cmd.extend(['--output', '-']) return cmd def run_command(self): """ Run command line """ cmd = self.getCmd() directory = os.path.dirname(self._document) proc = subprocess.Popen(cmd, cwd=directory, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdouterr = proc.communicate() return stdouterr def getPostSettings(self): """ returns settings in the post import tab """ post = [] for p in self.postChecks: post.append(p.isChecked()) return post def loadSettings(self): """ get users previous settings """ imp_default = [False, False, False, False, False] post_default = [True, False, False, True] s = QSettings() s.beginGroup('xml_import') for i, d in zip(self.impChecks, imp_default): i.setChecked(s.value(i.objectName(), d, bool)) for p, f in zip(self.postChecks, post_default): p.setChecked(s.value(p.objectName(), f, bool)) lang = s.value("language", "default", type("")) try: index = _langlist.index(lang) except ValueError: index = -1 self.langCombo.setCurrentIndex(index + 1) def saveSettings(self): """ save users last settings """ s = QSettings() s.beginGroup('xml_import') for i in self.impChecks: s.setValue(i.objectName(), i.isChecked()) for p in self.postChecks: s.setValue(p.objectName(), p.isChecked()) index = self.langCombo.currentIndex() s.setValue('language', 'default' if index == 0 else _langlist[index - 1])
class ComboContainer(QWidget): def __init__(self, parent=None): super(ComboContainer, self).__init__() self._editor_widget = parent box = QHBoxLayout(self) box.setContentsMargins(0, 0, 0, 0) box.setSpacing(0) self._lines_symbols = [] # Basado en la GUI de Qt Creator # Combo archivos self.combo_file = QComboBox() self.combo_file.setIconSize(QSize(14, 14)) self.combo_file.setContextMenuPolicy(Qt.CustomContextMenu) box.addWidget(self.combo_file) # Botón cerrar btn_close_editor = QToolButton() btn_close_editor.setFixedSize(25, 22) btn_close_editor.setObjectName("combo-button") btn_close_editor.setToolTip(self.tr("Cerrar archivo")) btn_close_editor.setIcon(QIcon(":image/close")) btn_close_editor.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) box.addWidget(btn_close_editor) # Combo símbolos self.combo_symbols = QComboBox() self.combo_symbols.setIconSize(QSize(14, 14)) box.addWidget(self.combo_symbols) # Label número de línea y columna self.label_line_row = QToolButton() self.label_line_row.mousePressEvent = self._show_dialog_go_to_line self.label_line_row.setObjectName("combo-lines-button") self.line_row = "Lin: %s, Col: %s - %s" self.label_line_row.setText(self.line_row % (0, 0, 0)) self.label_line_row.setToolTip( self.tr("Click para ir a una línea y/o columna específica")) box.addWidget(self.label_line_row) output = Edis.get_component("output") # Conexiones self.connect(btn_close_editor, SIGNAL("clicked()"), self._close_current_file) self.connect(output.salida_, SIGNAL("updateSyntaxCheck(bool)"), self._show_icon_checker) self.connect(self.combo_symbols, SIGNAL("activated(int)"), self._go_to_symbol) self.connect(self.combo_file, SIGNAL("customContextMenuRequested(const QPoint)"), self._load_menu_combo_file) def update_cursor_position(self, line, row, lines): self.label_line_row.setText(self.line_row % (line, row, lines)) def _show_dialog_go_to_line(self, event): if event.button() == Qt.LeftButton: editor_container = Edis.get_component("principal") editor_container.show_go_to_line() def _load_menu_combo_file(self, point): """ Muestra el menú """ menu = QMenu() editor_container = Edis.get_component("principal") save_as_action = menu.addAction(QIcon(":image/save-as"), self.tr("Guardar como...")) reload_action = menu.addAction(QIcon(":image/reload"), self.tr("Recargar")) menu.addSeparator() compile_action = menu.addAction(QIcon(":image/build"), self.tr("Compilar")) execute_action = menu.addAction(QIcon(":image/run"), self.tr("Ejecutar")) menu.addSeparator() close_action = menu.addAction(QIcon(":image/close"), self.tr("Cerrar archivo")) # Conexiones self.connect(save_as_action, SIGNAL("triggered()"), editor_container.save_file_as) self.connect(reload_action, SIGNAL("triggered()"), editor_container.reload_file) self.connect(compile_action, SIGNAL("triggered()"), editor_container.build_source_code) self.connect(execute_action, SIGNAL("triggered()"), editor_container.run_binary) self.connect(close_action, SIGNAL("triggered()"), editor_container.close_file) menu.exec_(self.mapToGlobal(point)) def _go_to_symbol(self, index): editor_container = Edis.get_component("principal") line = self._lines_symbols[index] editor_container.go_to_line(line) def _show_icon_checker(self, value): index = self._editor_widget.current_index() icon = QIcon() if not value: icon = QIcon(":image/bug") self.combo_file.setItemIcon(index, icon) else: self.combo_file.setItemIcon(index, icon) def _close_current_file(self): current_editor = self._editor_widget.current_widget() current_index = self._editor_widget.current_index() self._editor_widget.remove_widget(current_editor, current_index) def set_modified(self, weditor, index, modified): if modified: text = " \u2022" # Bullet caracter current_text = self.combo_file.currentText() self.combo_file.setItemText(index, current_text + text) else: text = weditor.filename self.combo_file.setItemText(index, text) def add_symbols_combo(self, symbols): """ Agrega símbolos al combo """ self.combo_symbols.clear() self.combo_symbols.addItem(self.tr("<Selecciona un Símbolo>")) lines = [1] for symbol in symbols: lines.append(symbol[0]) to_combo = symbol[1][0] if symbol[1][1] == 'function': icon = QIcon(":image/function") elif symbol[1][1] == 'struct': icon = QIcon(":image/struct") self.combo_symbols.addItem(icon, to_combo) self._lines_symbols = lines def move_to_symbol(self, line): line += 1 index = bisect.bisect(self._lines_symbols, line) self.combo_symbols.setCurrentIndex(index - 1)
class Browser(preferences.Group): def __init__(self, page): super(Browser, self).__init__(page) layout = QGridLayout() self.setLayout(layout) self.languagesLabel = QLabel() self.languages = QComboBox(currentIndexChanged=self.changed) layout.addWidget(self.languagesLabel, 0, 0) layout.addWidget(self.languages, 0, 1) items = ['', ''] items.extend( language_names.languageName(l, l) for l in lilydoc.translations) self.languages.addItems(items) self.fontLabel = QLabel() self.fontChooser = QFontComboBox(currentFontChanged=self.changed) self.fontSize = QSpinBox(valueChanged=self.changed) self.fontSize.setRange(6, 32) self.fontSize.setSingleStep(1) layout.addWidget(self.fontLabel, 1, 0) layout.addWidget(self.fontChooser, 1, 1) layout.addWidget(self.fontSize, 1, 2) app.translateUI(self) def translateUI(self): self.setTitle(_("Documentation Browser")) self.languagesLabel.setText(_("Preferred Language:")) self.languages.setItemText(0, _("Default")) self.languages.setItemText(1, _("English (untranslated)")) self.fontLabel.setText(_("Font:")) 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 saveSettings(self): s = QSettings() s.beginGroup("documentation") langs = ['default', 'C'] + lilydoc.translations s.setValue("language", langs[self.languages.currentIndex()]) s.setValue("fontfamily", self.fontChooser.currentFont().family()) s.setValue("fontsize", self.fontSize.value())
class experimentersDialog(QDialog): def __init__(self, parent): QDialog.__init__(self, parent) self.prm = self.parent().prm self.tmpPref = {} self.tmpPref['experimenter'] = {} self.tmpPref['experimenter'] = copy.deepcopy(self.parent().prm['experimenter']) self.currLocale = self.parent().prm['currentLocale'] self.currLocale.setNumberOptions(self.currLocale.OmitGroupSeparator | self.currLocale.RejectGroupSeparator) self.sizer = QGridLayout() self.h1Sizer = QHBoxLayout() self.v1Sizer = QVBoxLayout() self.v2Sizer = QVBoxLayout() n = 0 self.experimenterLabel = QLabel(self.tr("Experimenter ID:"), self) self.sizer.addWidget(self.experimenterLabel, n, 0) self.experimenterChooser = QComboBox() self.experimenterChooser.addItems(self.tmpPref['experimenter']['experimenter_id']) self.sizer.addWidget(self.experimenterChooser, n, 1) self.experimenterChooser.activated[str].connect(self.onExperimenterChange) self.currIdx = self.experimenterChooser.currentIndex() n = n+1 self.experimenterNameLabel = QLabel(self.tr("Name:"), self) self.sizer.addWidget(self.experimenterNameLabel, n, 0) self.experimenterNameTF = QLineEdit("") self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][0]) self.sizer.addWidget(self.experimenterNameTF, n, 1) n = n+1 self.experimenterSurnameLabel = QLabel(self.tr("Surname:"), self) self.sizer.addWidget(self.experimenterSurnameLabel, n, 0) self.experimenterSurnameTF = QLineEdit("") self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][0]) self.sizer.addWidget(self.experimenterSurnameTF, n, 1) n = n+1 self.experimenterEmailLabel = QLabel(self.tr("e-mail:"), self) self.sizer.addWidget(self.experimenterEmailLabel, n, 0) self.experimenterEmailTF = QLineEdit("") self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][0]) self.sizer.addWidget(self.experimenterEmailTF, n, 1) n = n+1 self.experimenterAddressLabel = QLabel(self.tr("Address (line 1):"), self) self.sizer.addWidget(self.experimenterAddressLabel, n, 0) self.experimenterAddressTF = QLineEdit("") self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][0]) self.sizer.addWidget(self.experimenterAddressTF, n, 1) n = n+1 self.experimenterAddressLabel2 = QLabel(self.tr("Address (line 2):"), self) self.sizer.addWidget(self.experimenterAddressLabel2, n, 0) self.experimenterAddressTF2 = QLineEdit("") self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][0]) self.sizer.addWidget(self.experimenterAddressTF2, n, 1) n = n+1 self.experimenterTelephoneLabel = QLabel(self.tr("Telephone:"), self) self.sizer.addWidget(self.experimenterTelephoneLabel, n, 0) self.experimenterTelephoneTF = QLineEdit("") self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][0]) self.sizer.addWidget(self.experimenterTelephoneTF, n, 1) n = n+1 self.experimenterMobileLabel = QLabel(self.tr("Mobile:"), self) self.sizer.addWidget(self.experimenterMobileLabel, n, 0) self.experimenterMobileTF = QLineEdit("") self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][0]) self.sizer.addWidget(self.experimenterMobileTF, n, 1) #ADD EXPERIMENTER BUTTON addExpButton = QPushButton(self.tr("Add Experimenter"), self) addExpButton.clicked.connect(self.onClickAddExpButton) self.v2Sizer.addWidget(addExpButton) #REMOVE EXPERIMENTER BUTTON removeExpButton = QPushButton(self.tr("Remove Experimenter"), self) removeExpButton.clicked.connect(self.onClickRemoveExpButton) self.v2Sizer.addWidget(removeExpButton) #CHANGE ID BUTTON changeIdButton = QPushButton(self.tr("Change Identifier"), self) changeIdButton.clicked.connect(self.onClickChangeIdButton) self.v2Sizer.addWidget(changeIdButton) #SET AS DEFAULT BUTTON setAsDefaultButton = QPushButton(self.tr("Set as default"), self) setAsDefaultButton.clicked.connect(self.onClickSetAsDefaultButton) self.v2Sizer.addWidget(setAsDefaultButton) self.v2Sizer.addStretch() buttonBox = QDialogButtonBox(QDialogButtonBox.Apply|QDialogButtonBox.Ok|QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.onClickApplyButton) self.h1Sizer.addLayout(self.v2Sizer) self.sizer.setAlignment(Qt.AlignTop) self.h1Sizer.addLayout(self.sizer) self.v1Sizer.addLayout(self.h1Sizer) self.v1Sizer.addWidget(buttonBox) self.setLayout(self.v1Sizer) def onClickApplyButton(self): self.tryApply(self.currIdx) self.permanentApply() def permanentApply(self): self.parent().prm['experimenter'] = copy.deepcopy(self.tmpPref['experimenter']) f = open(self.parent().prm['experimenterPrefFile'], 'wb') pickle.dump(self.parent().prm['experimenter'], f) f.close() for i in range(self.parent().experimenterChooser.count()): self.parent().experimenterChooser.removeItem(0) self.parent().experimenterChooser.addItems(self.parent().prm['experimenter']['experimenter_id']) def tryApply(self, idx): self.tmpPref['experimenter']['experimenter_id'][idx] = self.experimenterChooser.itemText(idx) self.tmpPref['experimenter']['experimenter_name'][idx] = self.experimenterNameTF.text() self.tmpPref['experimenter']['experimenter_surname'][idx] = self.experimenterSurnameTF.text() self.tmpPref['experimenter']['experimenter_email'][idx] = self.experimenterEmailTF.text() self.tmpPref['experimenter']['experimenter_address'][idx] = self.experimenterAddressTF.text() self.tmpPref['experimenter']['experimenter_address2'][idx] = self.experimenterAddressTF2.text() self.tmpPref['experimenter']['experimenter_telephone'][idx] = self.experimenterTelephoneTF.text() self.tmpPref['experimenter']['experimenter_mobile'][idx] = self.experimenterMobileTF.text() def revertChanges(self): if len(self.tmpPref['experimenter']['experimenter_id']) != len(self.parent().prm['experimenter']['experimenter_id']): #experimenter was added, reverting for i in range(self.experimenterChooser.count()): self.experimenterChooser.removeItem(0) self.experimenterChooser.addItems(self.parent().prm['experimenter']['experimenter_id']) self.tmpPref['experimenter'] = copy.deepcopy(self.parent().prm['experimenter']) def onExperimenterChange(self, experimenterSelected): self.prevIdx = self.currIdx self.currIdx = self.tmpPref['experimenter']['experimenter_id'].index(experimenterSelected) self.tryApply(self.prevIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() self.experimenterNameTF.setText(self.prm['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.prm['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.prm['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.prm['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.prm['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.prm['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.prm['experimenter']['experimenter_mobile'][self.currIdx]) def onClickAddExpButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() msg = self.tr("Experimenter's Identifier:") name, ok = QInputDialog.getText(self, self.tr('Input Dialog'), msg) if ok: self.tmpPref['experimenter']['defaultExperimenter'].append('') self.tmpPref['experimenter']['experimenter_id'].append(name) self.tmpPref['experimenter']['experimenter_name'].append('') self.tmpPref['experimenter']['experimenter_surname'].append('') self.tmpPref['experimenter']['experimenter_email'].append('') self.tmpPref['experimenter']['experimenter_address'].append('') self.tmpPref['experimenter']['experimenter_address2'].append('') self.tmpPref['experimenter']['experimenter_telephone'].append('') self.tmpPref['experimenter']['experimenter_mobile'].append('') self.permanentApply() self.currIdx = self.experimenterChooser.count() self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][self.currIdx]) self.experimenterChooser.addItem(name) self.experimenterChooser.setCurrentIndex(self.currIdx) def onClickRemoveExpButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() if self.experimenterChooser.count() > 1: reply = QMessageBox.warning(self, self.tr('Message'), "Remove experimenter? This action cannot be undone!", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.tmpPref['experimenter']['defaultExperimenter'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_id'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_name'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_surname'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_email'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_address'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_address2'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_telephone'].pop(self.currIdx) self.tmpPref['experimenter']['experimenter_mobile'].pop(self.currIdx) self.experimenterChooser.removeItem(self.currIdx) self.currIdx = self.experimenterChooser.currentIndex() self.permanentApply() self.experimenterNameTF.setText(self.tmpPref['experimenter']['experimenter_name'][self.currIdx]) self.experimenterSurnameTF.setText(self.tmpPref['experimenter']['experimenter_surname'][self.currIdx]) self.experimenterEmailTF.setText(self.tmpPref['experimenter']['experimenter_email'][self.currIdx]) self.experimenterAddressTF.setText(self.tmpPref['experimenter']['experimenter_address'][self.currIdx]) self.experimenterAddressTF2.setText(self.tmpPref['experimenter']['experimenter_address2'][self.currIdx]) self.experimenterTelephoneTF.setText(self.tmpPref['experimenter']['experimenter_telephone'][self.currIdx]) self.experimenterMobileTF.setText(self.tmpPref['experimenter']['experimenter_mobile'][self.currIdx]) else: QMessageBox.warning(self, self.tr('Message'), self.tr("Only one experimenter left. Experimenter cannot be removed!"), QMessageBox.Ok) def onClickChangeIdButton(self): self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() msg = self.tr("Experimenter's Identifier:") name, ok = QInputDialog.getText(self, self.tr('Input Dialog'), msg) if ok: self.tmpPref['experimenter']['experimenter_id'][self.currIdx] = name self.experimenterChooser.setItemText(self.currIdx, name) self.permanentApply() def onClickSetAsDefaultButton(self): idx = self.experimenterChooser.currentIndex() print(idx) self.tryApply(self.currIdx) if self.tmpPref['experimenter'] != self.parent().prm['experimenter']: conf = applyChanges(self) if conf.exec_(): self.permanentApply() else: self.revertChanges() for i in range(len(self.parent().prm['experimenter']["defaultExperimenter"])): if i == idx: self.tmpPref['experimenter']["defaultExperimenter"][i] = "\u2713" else: self.tmpPref['experimenter']["defaultExperimenter"][i] = "\u2012" print(self.tmpPref) self.permanentApply()
class General(preferences.Group): def __init__(self, page): super(General, self).__init__(page) grid = QGridLayout() self.setLayout(grid) self.langLabel = QLabel() self.lang = QComboBox(currentIndexChanged=self.changed) grid.addWidget(self.langLabel, 0, 0) grid.addWidget(self.lang, 0, 1) self.styleLabel = QLabel() self.styleCombo = QComboBox(currentIndexChanged=self.changed) grid.addWidget(self.styleLabel, 1, 0) grid.addWidget(self.styleCombo, 1, 1) self.systemIcons = QCheckBox(toggled=self.changed) grid.addWidget(self.systemIcons, 2, 0, 1, 3) self.splashScreen = QCheckBox(toggled=self.changed) grid.addWidget(self.splashScreen, 3, 0, 1, 3) self.allowRemote = QCheckBox(toggled=self.changed) grid.addWidget(self.allowRemote, 4, 0, 1, 3) grid.setColumnStretch(2, 1) # fill in the language combo self._langs = ["C", ""] self.lang.addItems(('', '')) langnames = [(language_names.languageName(lang, lang), lang) for lang in po.available()] langnames.sort() for name, lang in langnames: self._langs.append(lang) self.lang.addItem(name) # fill in style combo self.styleCombo.addItem('') self.styleCombo.addItems(QStyleFactory.keys()) app.translateUI(self) def loadSettings(self): s = QSettings() lang = s.value("language", "", type("")) try: index = self._langs.index(lang) except ValueError: index = 1 self.lang.setCurrentIndex(index) style = s.value("guistyle", "", type("")).lower() styles = [name.lower() for name in QStyleFactory.keys()] try: index = styles.index(style) + 1 except ValueError: index = 0 self.styleCombo.setCurrentIndex(index) self.systemIcons.setChecked(s.value("system_icons", True, bool)) self.splashScreen.setChecked(s.value("splash_screen", True, bool)) self.allowRemote.setChecked(remote.enabled()) def saveSettings(self): s = QSettings() s.setValue("language", self._langs[self.lang.currentIndex()]) s.setValue("system_icons", self.systemIcons.isChecked()) s.setValue("splash_screen", self.splashScreen.isChecked()) s.setValue("allow_remote", self.allowRemote.isChecked()) if self.styleCombo.currentIndex() == 0: s.remove("guistyle") else: s.setValue("guistyle", self.styleCombo.currentText()) def translateUI(self): self.setTitle(_("General Preferences")) self.langLabel.setText(_("Language:")) self.lang.setItemText(0, _("No Translation")) self.lang.setItemText(1, _("System Default Language (if available)")) self.styleLabel.setText(_("Style:")) self.styleCombo.setItemText(0, _("Default")) self.systemIcons.setText(_("Use System Icons")) self.systemIcons.setToolTip( _("If checked, icons of the desktop icon theme " "will be used instead of the bundled icons.\n" "This setting takes effect on the next start of {appname}."). format(appname=appinfo.appname)) self.splashScreen.setText(_("Show Splash Screen on Startup")) self.allowRemote.setText(_("Open Files in Running Instance")) self.allowRemote.setToolTip( _("If checked, files will be opened in a running Frescobaldi " "application if available, instead of starting a new instance."))
class NewDocument(preferences.Group): def __init__(self, page): super(NewDocument, self).__init__(page) grid = QGridLayout() self.setLayout(grid) def changed(): self.changed.emit() self.combo.setEnabled(self.template.isChecked()) self.emptyDocument = QRadioButton(toggled=changed) self.lilyVersion = QRadioButton(toggled=changed) self.template = QRadioButton(toggled=changed) self.combo = QComboBox(currentIndexChanged=changed) grid.addWidget(self.emptyDocument, 0, 0, 1, 2) grid.addWidget(self.lilyVersion, 1, 0, 1, 2) grid.addWidget(self.template, 2, 0, 1, 1) grid.addWidget(self.combo, 2, 1, 1, 1) self.loadCombo() app.translateUI(self) def translateUI(self): self.setTitle(_("When creating new documents")) self.emptyDocument.setText(_("Create an empty document")) self.lilyVersion.setText( _("Create a document that contains the LilyPond version statement") ) self.template.setText(_("Create a document from a template:")) from snippet import snippets for i, name in enumerate(self._names): self.combo.setItemText(i, snippets.title(name)) def loadCombo(self): from snippet import snippets self._names = [ name for name in snippets.names() if snippets.get(name).variables.get('template') ] self.combo.clear() self.combo.addItems([''] * len(self._names)) def loadSettings(self): s = QSettings() ndoc = s.value("new_document", "empty", type("")) template = s.value("new_document_template", "", type("")) if template in self._names: self.combo.setCurrentIndex(self._names.index(template)) if ndoc == "template": self.template.setChecked(True) elif ndoc == "version": self.lilyVersion.setChecked(True) else: self.emptyDocument.setChecked(True) def saveSettings(self): s = QSettings() if self._names and self.template.isChecked(): s.setValue("new_document", "template") s.setValue("new_document_template", self._names[self.combo.currentIndex()]) elif self.lilyVersion.isChecked(): s.setValue("new_document", "version") else: s.setValue("new_document", "empty")
class Dialog(QDialog): def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None self._path = None mainLayout = QGridLayout() self.setLayout(mainLayout) tabs = QTabWidget() import_tab = QWidget() post_tab = QWidget() itabLayout = QGridLayout(import_tab) ptabLayout = QGridLayout(post_tab) tabs.addTab(import_tab, "musicxml2ly") tabs.addTab(post_tab, "after import") self.noartCheck = QCheckBox() self.norestCheck = QCheckBox() self.nolayoutCheck = QCheckBox() self.nobeamCheck = QCheckBox() self.useAbsCheck = QCheckBox() self.commMidiCheck = QCheckBox() self.langCombo = QComboBox() self.langLabel = QLabel() self.impChecks = [self.noartCheck, self.norestCheck, self.nolayoutCheck, self.nobeamCheck, self.useAbsCheck, self.commMidiCheck] self.formatCheck = QCheckBox() self.trimDurCheck = QCheckBox() self.removeScalesCheck = QCheckBox() self.runEngraverCheck = QCheckBox() self.postChecks = [self.formatCheck, self.trimDurCheck, self.removeScalesCheck, self.runEngraverCheck] self.commandLineLabel = QLabel() self.commandLine = QTextEdit(acceptRichText=False) self.setChecksObjectNames() self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel) userguide.addButton(self.buttons, "musicxml_import") self.langCombo.addItem('') self.langCombo.addItems(_langlist) itabLayout.addWidget(self.noartCheck, 0, 0, 1, 2) itabLayout.addWidget(self.norestCheck, 1, 0, 1, 2) itabLayout.addWidget(self.nolayoutCheck, 2, 0, 1, 2) itabLayout.addWidget(self.nobeamCheck, 3, 0, 1, 2) itabLayout.addWidget(self.useAbsCheck, 4, 0, 1, 2) itabLayout.addWidget(self.commMidiCheck, 5, 0, 1, 2) itabLayout.addWidget(self.langLabel, 6, 0, 1, 2) itabLayout.addWidget(self.langCombo, 7, 0, 1, 2) itabLayout.addWidget(widgets.Separator(), 8, 0, 1, 2) itabLayout.addWidget(self.commandLineLabel, 9, 0, 1, 2) itabLayout.addWidget(self.commandLine, 10, 0, 1, 2) ptabLayout.addWidget(self.formatCheck, 0, 0, 1, 2) ptabLayout.addWidget(self.trimDurCheck, 1, 0, 1, 2) ptabLayout.addWidget(self.removeScalesCheck, 2, 0, 1, 2) ptabLayout.addWidget(self.runEngraverCheck, 3, 0, 1, 2) ptabLayout.setRowStretch(4, 10) mainLayout.addWidget(tabs, 0, 0, 9, 2) mainLayout.addWidget(self.buttons, 10, 0, 1, 2) app.translateUI(self) qutil.saveDialogSize(self, "xml_import/dialog/size", QSize(480, 260)) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.noartCheck.toggled.connect(self.makeCommandLine) self.norestCheck.toggled.connect(self.makeCommandLine) self.nolayoutCheck.toggled.connect(self.makeCommandLine) self.nobeamCheck.toggled.connect(self.makeCommandLine) self.useAbsCheck.toggled.connect(self.makeCommandLine) self.commMidiCheck.toggled.connect(self.makeCommandLine) self.langCombo.currentIndexChanged.connect(self.makeCommandLine) self.makeCommandLine() self.loadSettings() def setChecksObjectNames(self): self.noartCheck.setObjectName("articulation-directions") self.norestCheck.setObjectName("rest-positions") self.nolayoutCheck.setObjectName("page-layout") self.nobeamCheck.setObjectName("import-beaming") self.useAbsCheck.setObjectName("absolute-mode") self.commMidiCheck.setObjectName("comment-out-midi") self.formatCheck.setObjectName("reformat") self.trimDurCheck.setObjectName("trim-durations") self.removeScalesCheck.setObjectName("remove-scaling") self.runEngraverCheck.setObjectName("engrave-directly") def translateUI(self): self.setWindowTitle(app.caption(_("Import Music XML"))) self.noartCheck.setText(_("Import articulation directions")) self.norestCheck.setText(_("Import rest positions")) self.nolayoutCheck.setText(_("Import page layout")) self.nobeamCheck.setText(_("Import beaming")) self.useAbsCheck.setText(_("Pitches in absolute mode")) self.commMidiCheck.setText(_("Comment out midi block")) self.commandLineLabel.setText(_("Command line:")) self.langLabel.setText(_("Language for pitch names")) self.langCombo.setItemText(0, _("Default")) self.formatCheck.setText(_("Reformat source")) self.trimDurCheck.setText(_("Trim durations (Make implicit per line)")) self.removeScalesCheck.setText(_("Remove fraction duration scaling")) self.runEngraverCheck.setText(_("Engrave directly")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run musicxml2ly")) def setDocument(self, path): """Set the full path to the MusicXML document.""" self._document = path def makeCommandLine(self): """Reads the widgets and builds a command line.""" cmd = ["$musicxml2ly"] if self.useAbsCheck.isChecked(): cmd.append('-a') if not self.noartCheck.isChecked(): cmd.append('--nd') if not self.norestCheck.isChecked(): cmd.append('--nrp') if not self.nolayoutCheck.isChecked(): cmd.append('--npl') if not self.nobeamCheck.isChecked(): cmd.append('--no-beaming') if not self.commMidiCheck.isChecked(): cmd.append('-m') index = self.langCombo.currentIndex() if index > 0: cmd.append('--language=' + _langlist[index-1]) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def getCmd(self): """Returns the command line.""" cmd = [] for t in self.commandLine.toPlainText().split(): if t == '$musicxml2ly': cmd.extend(lilypondinfo.preferred().toolcommand('musicxml2ly')) elif t == '$filename': cmd.append(self._document) else: cmd.append(t) cmd.extend(['--output', '-']) return cmd def run_command(self): """ Run command line """ cmd = self.getCmd() directory = os.path.dirname(self._document) proc = subprocess.Popen(cmd, cwd=directory, universal_newlines = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) stdouterr = proc.communicate() return stdouterr def getPostSettings(self): """ returns settings in the post import tab """ post = [] for p in self.postChecks: post.append(p.isChecked()) return post def loadSettings(self): """ get users previous settings """ imp_default = [False, False, False, False, False, False] post_default = [True, False, False, True] s = QSettings() s.beginGroup('xml_import') for i, d in zip(self.impChecks, imp_default): i.setChecked(s.value(i.objectName(), d, bool)) for p, f in zip(self.postChecks, post_default): p.setChecked(s.value(p.objectName(), f, bool)) lang = s.value("language", "default", type("")) try: index = _langlist.index(lang) except ValueError: index = -1 self.langCombo.setCurrentIndex(index + 1) def saveSettings(self): """ save users last settings """ s = QSettings() s.beginGroup('xml_import') for i in self.impChecks: s.setValue(i.objectName(), i.isChecked()) for p in self.postChecks: s.setValue(p.objectName(), p.isChecked()) index = self.langCombo.currentIndex() s.setValue('language', 'default' if index == 0 else _langlist[index-1])
class Dialog(QDialog): 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.englishCheck = QCheckBox() self.deleteCheck = 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.englishCheck, 4, 0, 1, 4) layout.addWidget(self.deleteCheck, 5, 0, 1, 4) layout.addWidget(self.commandLineLabel, 6, 0, 1, 4) layout.addWidget(self.commandLine, 7, 0, 1, 4) layout.addWidget(widgets.Separator(), 8, 0, 1, 4) layout.addWidget(self.buttons, 9, 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", type("")) == "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.resolutionCombo.editTextChanged.connect(self.makeCommandLine) self.antialiasSpin.valueChanged.connect(self.makeCommandLine) self.makeCommandLine() panelmanager.manager(mainwindow).layoutcontrol.widget().optionsChanged.connect(self.makeCommandLine) def translateUI(self): self.setWindowTitle(app.caption(_("Engrave custom"))) self.versionLabel.setText(_("LilyPond Version:")) self.outputLabel.setText(_("Output Format:")) self.resolutionLabel.setText(_("Resolution:")) self.antialiasLabel.setText(_("Antialias Factor:")) self.modeLabel.setText(_("Engraving mode:")) self.modeCombo.setItemText(0, _("Preview")) self.modeCombo.setItemText(1, _("Publish")) self.modeCombo.setItemText(2, _("Layout Control")) self.englishCheck.setText(_("Run LilyPond with English messages")) self.deleteCheck.setText(_("Delete intermediate output files")) self.commandLineLabel.setText(_("Command line:")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run LilyPond")) self.outputCombo.update() def slotJobFinished(self, doc): if doc == self._document: self.buttons.button(QDialogButtonBox.Ok).setEnabled(True) self._document = None def setDocument(self, doc): self.lilyChooser.setLilyPondInfo(command.info(doc)) job = jobmanager.job(doc) if job and job.isRunning() and not jobattributes.get(job).hidden: self._document = doc self.buttons.button(QDialogButtonBox.Ok).setEnabled(False) def makeCommandLine(self): """Reads the widgets and builds a command line.""" f = formats[self.outputCombo.currentIndex()] self.resolutionCombo.setEnabled('resolution' in f.widgets) self.antialiasSpin.setEnabled('antialias' in f.widgets) cmd = ["$lilypond"] if self.modeCombo.currentIndex() == 0: # preview mode cmd.append('-dpoint-and-click') elif self.modeCombo.currentIndex() == 1: # publish mode cmd.append('-dno-point-and-click') else: # debug mode args = panelmanager.manager(self.parent()).layoutcontrol.widget().preview_options() cmd.extend(args) if self.deleteCheck.isChecked(): cmd.append('-ddelete-intermediate-files') else: cmd.append('-dno-delete-intermediate-files') d = { 'version': self.lilyChooser.lilyPondInfo().version, 'resolution': self.resolutionCombo.currentText(), 'antialias': self.antialiasSpin.value(), } cmd.append("$include") cmd.extend(f.options(d)) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def getJob(self, document): """Returns a Job to start.""" filename, includepath = documentinfo.info(document).jobinfo(True) i = self.lilyChooser.lilyPondInfo() cmd = [] for t in self.commandLine.toPlainText().split(): if t == '$lilypond': cmd.append(i.abscommand() or i.command) elif t == '$filename': cmd.append(filename) elif t == '$include': cmd.extend('-I' + path for path in includepath) else: cmd.append(t) j = job.Job() j.directory = os.path.dirname(filename) j.command = cmd if self.englishCheck.isChecked(): j.environment['LANG'] = 'C' j.setTitle("{0} {1} [{2}]".format( os.path.basename(i.command), i.versionString(), document.documentName())) return j
class Dialog(QDialog): 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.englishCheck = QCheckBox() self.deleteCheck = 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.englishCheck, 4, 0, 1, 4) layout.addWidget(self.deleteCheck, 5, 0, 1, 4) layout.addWidget(self.commandLineLabel, 6, 0, 1, 4) layout.addWidget(self.commandLine, 7, 0, 1, 4) layout.addWidget(widgets.Separator(), 8, 0, 1, 4) layout.addWidget(self.buttons, 9, 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", type("")) == "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.resolutionCombo.editTextChanged.connect(self.makeCommandLine) self.antialiasSpin.valueChanged.connect(self.makeCommandLine) self.makeCommandLine() panelmanager.manager( mainwindow).layoutcontrol.widget().optionsChanged.connect( self.makeCommandLine) def translateUI(self): self.setWindowTitle(app.caption(_("Engrave custom"))) self.versionLabel.setText(_("LilyPond Version:")) self.outputLabel.setText(_("Output Format:")) self.resolutionLabel.setText(_("Resolution:")) self.antialiasLabel.setText(_("Antialias Factor:")) self.modeLabel.setText(_("Engraving mode:")) self.modeCombo.setItemText(0, _("Preview")) self.modeCombo.setItemText(1, _("Publish")) self.modeCombo.setItemText(2, _("Layout Control")) self.englishCheck.setText(_("Run LilyPond with English messages")) self.deleteCheck.setText(_("Delete intermediate output files")) self.commandLineLabel.setText(_("Command line:")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run LilyPond")) self.outputCombo.update() def slotJobFinished(self, doc): if doc == self._document: self.buttons.button(QDialogButtonBox.Ok).setEnabled(True) self._document = None def setDocument(self, doc): self.lilyChooser.setLilyPondInfo(command.info(doc)) if jobmanager.isRunning(doc): self._document = doc self.buttons.button(QDialogButtonBox.Ok).setEnabled(False) def makeCommandLine(self): """Reads the widgets and builds a command line.""" f = formats[self.outputCombo.currentIndex()] self.resolutionCombo.setEnabled('resolution' in f.widgets) self.antialiasSpin.setEnabled('antialias' in f.widgets) cmd = ["$lilypond"] if self.modeCombo.currentIndex() == 0: # preview mode cmd.append('-dpoint-and-click') elif self.modeCombo.currentIndex() == 1: # publish mode cmd.append('-dno-point-and-click') else: # debug mode args = panelmanager.manager( self.parent()).layoutcontrol.widget().preview_options() cmd.extend(args) if self.deleteCheck.isChecked(): cmd.append('-ddelete-intermediate-files') else: cmd.append('-dno-delete-intermediate-files') d = { 'version': self.lilyChooser.lilyPondInfo().version, 'resolution': self.resolutionCombo.currentText(), 'antialias': self.antialiasSpin.value(), } cmd.append("$include") cmd.extend(f.options(d)) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def getJob(self, document): """Returns a Job to start.""" filename, includepath = documentinfo.info(document).jobinfo(True) i = self.lilyChooser.lilyPondInfo() cmd = [] for t in self.commandLine.toPlainText().split(): if t == '$lilypond': cmd.append(i.abscommand() or i.command) elif t == '$filename': cmd.append(filename) elif t == '$include': cmd.extend('-I' + path for path in includepath) else: cmd.append(t) j = job.Job() j.directory = os.path.dirname(filename) j.command = cmd if self.englishCheck.isChecked(): j.environment['LANG'] = 'C' j.setTitle("{0} {1} [{2}]".format(os.path.basename(i.command), i.versionString(), document.documentName())) return j
class Dialog(toly_dialog.ToLyDialog): def __init__(self, parent=None): self.imp_prgm = "musicxml2ly" self.userg = "musicxml_import" self.noartCheck = QCheckBox() self.norestCheck = QCheckBox() self.nolayoutCheck = QCheckBox() self.nobeamCheck = QCheckBox() self.useAbsCheck = QCheckBox() self.commMidiCheck = QCheckBox() self.langCombo = QComboBox() self.langLabel = QLabel() self.impChecks = [self.noartCheck, self.norestCheck, self.nolayoutCheck, self.nobeamCheck, self.useAbsCheck, self.commMidiCheck] self.noartCheck.setObjectName("articulation-directions") self.norestCheck.setObjectName("rest-positions") self.nolayoutCheck.setObjectName("page-layout") self.nobeamCheck.setObjectName("import-beaming") self.useAbsCheck.setObjectName("absolute-mode") self.commMidiCheck.setObjectName("comment-out-midi") self.langCombo.addItem('') self.langCombo.addItems(_langlist) self.impExtra = [self.langLabel, self.langCombo] super(Dialog, self).__init__(parent) self.langCombo.currentIndexChanged.connect(self.makeCommandLine) app.translateUI(self) qutil.saveDialogSize(self, "musicxml_import/dialog/size", QSize(480, 260)) self.makeCommandLine() self.loadSettings() def translateUI(self): self.setWindowTitle(app.caption(_("Import Music XML"))) self.noartCheck.setText(_("Import articulation directions")) self.norestCheck.setText(_("Import rest positions")) self.nolayoutCheck.setText(_("Import page layout")) self.nobeamCheck.setText(_("Import beaming")) self.useAbsCheck.setText(_("Pitches in absolute mode")) self.commMidiCheck.setText(_("Comment out midi block")) self.langLabel.setText(_("Language for pitch names")) self.langCombo.setItemText(0, _("Default")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run musicxml2ly")) super(Dialog, self).translateUI() def makeCommandLine(self): """Reads the widgets and builds a command line.""" cmd = ["$musicxml2ly"] if self.useAbsCheck.isChecked(): cmd.append('-a') if not self.noartCheck.isChecked(): cmd.append('--nd') if not self.norestCheck.isChecked(): cmd.append('--nrp') if not self.nolayoutCheck.isChecked(): cmd.append('--npl') if not self.nobeamCheck.isChecked(): cmd.append('--no-beaming') if not self.commMidiCheck.isChecked(): cmd.append('-m') index = self.langCombo.currentIndex() if index > 0: cmd.append('--language=' + _langlist[index - 1]) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def loadSettings(self): """Get users previous settings.""" self.imp_default = [False, False, False, False, False, False] self.settings = QSettings() self.settings.beginGroup('musicxml_import') super(Dialog, self).loadSettings() lang = self.settings.value("language", "default", type("")) try: index = _langlist.index(lang) except ValueError: index = -1 self.langCombo.setCurrentIndex(index + 1) def saveSettings(self): """Save users last settings.""" self.settings = QSettings() self.settings.beginGroup('musicxml_import') super(Dialog, self).saveSettings() index = self.langCombo.currentIndex() self.settings.setValue('language', 'default' if index == 0 else _langlist[index-1])
class QuickInsert(QWidget): def __init__(self, dockwidget): super(QuickInsert, self).__init__(dockwidget) self._dockwidget = weakref.ref(dockwidget) # filled in by ButtonGroup subclasses self.actionDict = {} layout = QVBoxLayout() self.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) self.helpButton = QToolButton( icon = icons.get("help-contents"), autoRaise = True, clicked = lambda: userguide.show("quickinsert")) self.directionLabel = QLabel() self.direction = QComboBox() self.direction.addItems(['', '', '']) self.direction.setItemIcon(0, icons.get("go-up")) self.direction.setItemIcon(2, icons.get("go-down")) self.direction.setCurrentIndex(1) hor = QHBoxLayout() hor.setContentsMargins(0, 0, 0, 0) hor.addWidget(self.helpButton) hor.addWidget(self.directionLabel) hor.addWidget(self.direction) layout.addLayout(hor) self.toolbox = QToolBox(self) widgets.toolboxwheeler.ToolBoxWheeler(self.toolbox) layout.addWidget(self.toolbox) for cls in ( articulations.Articulations, dynamics.Dynamics, spanners.Spanners, barlines.BarLines, ): widget = cls(self) self.toolbox.addItem(widget, widget.icon(), '') app.translateUI(self) userguide.openWhatsThis(self) # restore remembered current page name = QSettings().value("quickinsert/current_tool", "", type("")) if name: for i in range(self.toolbox.count()): if name == self.toolbox.widget(i).__class__.__name__.lower(): self.toolbox.setCurrentIndex(i) break self.toolbox.currentChanged.connect(self.slotCurrentChanged) def slotCurrentChanged(self, index): name = self.toolbox.widget(index).__class__.__name__.lower() QSettings().setValue("quickinsert/current_tool", name) def translateUI(self): self.setWhatsThis(_( "<p>With the Quick Insert Panel you can add various music " "elements to the current note or selected music.</p>\n" "<p>See {link} for more information.</p>").format(link= userguide.util.format_link("quickinsert"))) self.helpButton.setToolTip(_("Help")) self.directionLabel.setText(_("Direction:")) for item, text in enumerate((_("Up"), _("Neutral"), _("Down"))): self.direction.setItemText(item, text) for i in range(self.toolbox.count()): self.toolbox.setItemText(i, self.toolbox.widget(i).title()) self.toolbox.setItemToolTip(i, self.toolbox.widget(i).tooltip()) def actionForName(self, name): """This is called by the ShortcutCollection of our dockwidget, e.g. if the user presses a key.""" try: return self.actionDict[name] except KeyError: pass def dockwidget(self): return self._dockwidget()
class ActionBar(QFrame): """ SIGNALS: @changeCurrent(PyQt_PyObject) @runFile(QString) @reopenTab(QString) @recentTabsModified() """ def __init__(self, main_combo=False): super(ActionBar, self).__init__() self.setObjectName("actionbar") hbox = QHBoxLayout(self) hbox.setContentsMargins(1, 1, 1, 1) hbox.setSpacing(1) self.lbl_checks = QLabel('') self.lbl_checks.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.lbl_checks.setFixedWidth(48) self.lbl_checks.setVisible(False) hbox.addWidget(self.lbl_checks) self.combo = QComboBox() #model = QStandardItemModel() #self.combo.setModel(model) #self.combo.view().setDragDropMode(QAbstractItemView.InternalMove) self.combo.setMaximumWidth(300) self.combo.setObjectName("combotab") self.connect(self.combo, SIGNAL("currentIndexChanged(int)"), self.current_changed) self.combo.setToolTip(translations.TR_COMBO_FILE_TOOLTIP) self.combo.setContextMenuPolicy(Qt.CustomContextMenu) self.connect(self.combo, SIGNAL("customContextMenuRequested(const QPoint &)"), self._context_menu_requested) hbox.addWidget(self.combo) self.symbols_combo = QComboBox() self.symbols_combo.setObjectName("combo_symbols") self.connect(self.symbols_combo, SIGNAL("activated(int)"), self.current_symbol_changed) hbox.addWidget(self.symbols_combo) self.code_navigator = CodeNavigator() hbox.addWidget(self.code_navigator) self._pos_text = "Line: %d, Col: %d" self.lbl_position = QLabel(self._pos_text % (0, 0)) self.lbl_position.setObjectName("position") self.lbl_position.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.lbl_position) self.btn_close = QPushButton( self.style().standardIcon(QStyle.SP_DialogCloseButton), '') if main_combo: self.btn_close.setObjectName('navigation_button') self.btn_close.setToolTip(translations.TR_CLOSE_FILE) self.connect(self.btn_close, SIGNAL("clicked()"), self.about_to_close_file) else: self.btn_close.setObjectName('close_split') self.btn_close.setToolTip(translations.TR_CLOSE_SPLIT) self.connect(self.btn_close, SIGNAL("clicked()"), self.close_split) self.btn_close.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.btn_close) def resizeEvent(self, event): super(ActionBar, self).resizeEvent(event) if event.size().width() < 350: self.symbols_combo.hide() self.code_navigator.hide() self.lbl_position.hide() else: self.symbols_combo.show() self.code_navigator.show() self.lbl_position.show() def add_item(self, text, neditable): """Add a new item to the combo and add the neditable data.""" self.combo.addItem(text, neditable) self.combo.setCurrentIndex(self.combo.count() - 1) def get_editables(self): editables = [] for index in range(self.combo.count()): neditable = self.combo.itemData(index) editables.append(neditable) return editables def add_symbols(self, symbols): """Add the symbols to the symbols's combo.""" self.symbols_combo.clear() for symbol in symbols: data = symbol[1] if data[1] == 'f': icon = QIcon(":img/function") else: icon = QIcon(":img/class") self.symbols_combo.addItem(icon, data[0]) def set_current_symbol(self, index): self.symbols_combo.setCurrentIndex(index) def update_item_icon(self, neditable, icon): index = self.combo.findData(neditable) self.combo.setItemIcon(index, icon) def update_item_text(self, neditable, text): index = self.combo.findData(neditable) self.combo.setItemText(index, text) def current_changed(self, index): """Change the current item in the combo.""" neditable = self.combo.itemData(index) self.emit(SIGNAL("changeCurrent(PyQt_PyObject, int)"), neditable, index) def current_symbol_changed(self, index): """Change the current symbol in the combo.""" self.emit(SIGNAL("goToSymbol(int)"), index) def update_line_col(self, line, col): """Update the line and column position.""" self.lbl_position.setText(self._pos_text % (line, col)) def _context_menu_requested(self, point): """Display context menu for the combo file.""" if self.combo.count() == 0: # If there is not an Editor opened, don't show the menu return menu = QMenu() actionAdd = menu.addAction(translations.TR_ADD_TO_PROJECT) actionRun = menu.addAction(translations.TR_RUN_FILE) menuSyntax = menu.addMenu(translations.TR_CHANGE_SYNTAX) self._create_menu_syntax(menuSyntax) menu.addSeparator() actionClose = menu.addAction(translations.TR_CLOSE_FILE) actionCloseAll = menu.addAction(translations.TR_CLOSE_ALL_FILES) actionCloseAllNotThis = menu.addAction( translations.TR_CLOSE_OTHER_FILES) menu.addSeparator() actionSplitH = menu.addAction(translations.TR_SPLIT_VERTICALLY) actionSplitV = menu.addAction(translations.TR_SPLIT_HORIZONTALLY) menu.addSeparator() actionCopyPath = menu.addAction( translations.TR_COPY_FILE_PATH_TO_CLIPBOARD) actionReopen = menu.addAction(translations.TR_REOPEN_FILE) actionUndock = menu.addAction(translations.TR_UNDOCK_EDITOR) if len(settings.LAST_OPENED_FILES) == 0: actionReopen.setEnabled(False) #Connect actions self.connect(actionSplitH, SIGNAL("triggered()"), lambda: self._split(False)) self.connect(actionSplitV, SIGNAL("triggered()"), lambda: self._split(True)) self.connect(actionRun, SIGNAL("triggered()"), self._run_this_file) self.connect(actionAdd, SIGNAL("triggered()"), self._add_to_project) self.connect(actionClose, SIGNAL("triggered()"), self.about_to_close_file) self.connect(actionCloseAllNotThis, SIGNAL("triggered()"), self._close_all_files_except_this) self.connect(actionCloseAll, SIGNAL("triggered()"), self._close_all_files) self.connect(actionCopyPath, SIGNAL("triggered()"), self._copy_file_location) self.connect(actionReopen, SIGNAL("triggered()"), self._reopen_last_tab) self.connect(actionUndock, SIGNAL("triggered()"), self._undock_editor) menu.exec_(QCursor.pos()) def _create_menu_syntax(self, menuSyntax): """Create Menu with the list of syntax supported.""" syntax = list(settings.SYNTAX.keys()) syntax.sort() for syn in syntax: menuSyntax.addAction(syn) self.connect(menuSyntax, SIGNAL("triggered(QAction*)"), self._reapply_syntax) def _reapply_syntax(self, syntaxAction): #TODO if [self.currentIndex(), syntaxAction] != self._resyntax: self._resyntax = [self.currentIndex(), syntaxAction] self.emit(SIGNAL("syntaxChanged(QWidget, QString)"), self.currentWidget(), syntaxAction.text()) def set_current_file(self, neditable): index = self.combo.findData(neditable) self.combo.setCurrentIndex(index) def set_current_by_index(self, index): self.combo.setCurrentIndex(index) def about_to_close_file(self, index=None): """Close the NFile object.""" if index is None: index = self.combo.currentIndex() neditable = self.combo.itemData(index) if neditable: neditable.nfile.close() def close_split(self): self.emit(SIGNAL("closeSplit()")) def close_file(self, neditable): """Receive the confirmation to close the file.""" index = self.combo.findData(neditable) self.combo.removeItem(index) return index def _run_this_file(self): """Execute the current file.""" neditable = self.combo.itemData(self.combo.currentIndex()) self.emit(SIGNAL("runFile(QString)"), neditable.file_path) def _add_to_project(self): """Emit a signal to let someone handle the inclusion of the file inside a project.""" neditable = self.combo.itemData(self.combo.currentIndex()) self.emit(SIGNAL("addToProject(QString)"), neditable.file_path) def _reopen_last_tab(self): self.emit(SIGNAL("reopenTab(QString)"), settings.LAST_OPENED_FILES.pop()) self.emit(SIGNAL("recentTabsModified()")) def _undock_editor(self): self.emit(SIGNAL("undockEditor()")) def _split(self, orientation): self.emit(SIGNAL("splitEditor(bool)"), orientation) def _copy_file_location(self): """Copy the path of the current opened file to the clipboard.""" neditable = self.combo.itemData(self.combo.currentIndex()) QApplication.clipboard().setText(neditable.file_path, QClipboard.Clipboard) def _close_all_files(self): """Close all the files opened.""" for i in range(self.combo.count()): self.about_to_close_file(0) def _close_all_files_except_this(self): """Close all the files except the current one.""" neditable = self.combo.itemData(self.combo.currentIndex()) for i in reversed(list(range(self.combo.count()))): ne = self.combo.itemData(i) if ne is not neditable: self.about_to_close_file(i)
class NewDocument(preferences.Group): def __init__(self, page): super(NewDocument, self).__init__(page) grid = QGridLayout() self.setLayout(grid) def changed(): self.changed.emit() self.combo.setEnabled(self.template.isChecked()) self.emptyDocument = QRadioButton(toggled=changed) self.lilyVersion = QRadioButton(toggled=changed) self.template = QRadioButton(toggled=changed) self.combo = QComboBox(currentIndexChanged=changed) grid.addWidget(self.emptyDocument, 0, 0, 1, 2) grid.addWidget(self.lilyVersion, 1, 0, 1, 2) grid.addWidget(self.template, 2, 0, 1, 1) grid.addWidget(self.combo, 2, 1, 1, 1) self.loadCombo() app.translateUI(self) def translateUI(self): self.setTitle(_("When creating new documents")) self.emptyDocument.setText(_("Create an empty document")) self.lilyVersion.setText(_("Create a document that contains the LilyPond version statement")) self.template.setText(_("Create a document from a template:")) from snippet import snippets for i, name in enumerate(self._names): self.combo.setItemText(i, snippets.title(name)) def loadCombo(self): from snippet import snippets self._names = [name for name in snippets.names() if snippets.get(name).variables.get('template')] self.combo.clear() self.combo.addItems([''] * len(self._names)) def loadSettings(self): s = QSettings() ndoc = s.value("new_document", "empty", type("")) template = s.value("new_document_template", "", type("")) if template in self._names: self.combo.setCurrentIndex(self._names.index(template)) if ndoc == "template": self.template.setChecked(True) elif ndoc == "version": self.lilyVersion.setChecked(True) else: self.emptyDocument.setChecked(True) def saveSettings(self): s = QSettings() if self._names and self.template.isChecked(): s.setValue("new_document", "template") s.setValue("new_document_template", self._names[self.combo.currentIndex()]) elif self.lilyVersion.isChecked(): s.setValue("new_document", "version") else: s.setValue("new_document", "empty")
class Window(QMainWindow): def __init__(self,parent = None): QMainWindow.__init__(self,parent) self.resize(1024,768) self.setWindowTitle("Sabel") self.setWindowIcon(Icons.sabel) self.centralwidget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.centralwidget) self.horizontalLayout.setMargin(0) self.cmdList = config.cmds() self.paramList = config.params() '''A.Editor TabWidget''' '''This parent is for findbar and vertical layout''' self.editorLayoutWidget = QWidget(self) self.editorLayoutWidget.setMinimumWidth(800) self.tabWidget = EditorTab(self) self.editorLayout = QVBoxLayout(self.editorLayoutWidget) self.editorLayout.setMargin(0) self.editorLayout.addWidget(self.tabWidget) "0.Style Layout" self.styleLayoutWidget = QFrame() self.styleLayoutWidget.setFrameShape(QFrame.StyledPanel) self.styleLayout = QHBoxLayout(self.styleLayoutWidget) self.styleTest = QPushButton(self.styleLayoutWidget) self.styleTest.setText("Change Styles") self.styleTest.clicked.connect(self.changeStyleSheet) self.popWidget = Popup(self.styleLayoutWidget) self.styleLayout.addWidget(self.styleTest) self.styleLayout.addWidget(self.popWidget) self.styleLayout.setMargin(0) self.editorLayout.addWidget(self.styleLayoutWidget) self.styleLayoutWidget.hide() "1.Find Layout" self.findLayoutWidget = QFrame() self.findLayoutWidget.setFrameShape(QFrame.StyledPanel) self.findLayout = QHBoxLayout(self.findLayoutWidget) self.lineEdit = QLineEdit(self.findLayoutWidget) self.lineEdit_2 = QLineEdit(self.findLayoutWidget) self.findClose = QPushButton(self.findLayoutWidget) self.findClose.setIcon(Icons.close_view) self.findClose.setFlat(True) self.findClose.clicked.connect(self.findBarShow) self.find = QPushButton(self.findLayoutWidget) self.find.setText("Find") self.find.clicked.connect(self.findCurrentText) self.replacefind = QPushButton(self.findLayoutWidget) self.replacefind.setText("Replace/Find") self.replacefind.clicked.connect(self.replaceFindText) self.replace = QPushButton(self.findLayoutWidget) self.replace.setText("Replace") self.replace.clicked.connect(self.replaceCurrentText) self.replaceAll = QPushButton(self.findLayoutWidget) self.replaceAll.setText("Replace All") self.replaceAll.clicked.connect(self.replaceAllText) self.caseSensitive = QToolButton(self.findLayoutWidget) self.caseSensitive.setIcon(Icons.font) self.caseSensitive.setCheckable(True) self.wholeWord = QToolButton(self.findLayoutWidget) self.wholeWord.setText("ww") self.wholeWord.setCheckable(True) self.regex = QToolButton(self.findLayoutWidget) self.regex.setText("re") self.regex.setCheckable(True) self.backward = QToolButton(self.findLayoutWidget) self.backward.setText("bk") self.backward.setCheckable(True) self.backward.setDisabled(True) self.findLayout.addWidget(self.findClose) self.findLayout.addWidget(self.find) self.findLayout.addWidget(self.lineEdit) self.findLayout.addWidget(self.lineEdit_2) self.findLayout.addWidget(self.caseSensitive) self.findLayout.addWidget(self.wholeWord) self.findLayout.addWidget(self.regex) self.findLayout.addWidget(self.backward) self.findLayout.addWidget(self.replacefind) self.findLayout.addWidget(self.replace) self.findLayout.addWidget(self.replaceAll) self.findLayout.setMargin(0) self.findLayoutWidget.setMaximumHeight(25) self.editorLayout.addWidget(self.findLayoutWidget) self.findLayoutWidget.hide() '''B.Designer''' '''This parent is for widgetsbar and design layout''' self.designerLayoutWidget = QWidget(self) self.designerLayoutWidget.setMinimumWidth(800) self.designerWidget = Screen(self) self.designerLayoutWidget.hide() self.designerLayout = QVBoxLayout(self.designerLayoutWidget) self.designerLayout.setMargin(0) self.designerLayout.addWidget(self.designerWidget) '''C.Level Editor''' '''This parent is for spritesheets and level layout''' self.levelLayoutWidget = QWidget(self) self.levelLayoutWidget.setMinimumWidth(800) self.levelWidget = Level(self) self.levelLayoutWidget.hide() self.levelLayout = QVBoxLayout(self.levelLayoutWidget) self.levelLayout.setMargin(0) self.levelLayout.addWidget(self.levelWidget) '''D.Explorer TabWidget''' self.explorerTabWidget = TreeTab(self) #self.explorerTabWidget.setMaximumWidth(200) '''1.Project Tree''' self.tab_5 = QWidget() #self.tab_5.setMaximumWidth(200) self.VerticalLayout_2 = QVBoxLayout(self.tab_5)#QHBoxLayout(self.tab_5) self.VerticalLayout_2.setMargin(0) self.treeWidget = ProjectTree(self.tab_5) #self.treeWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) #self.treeWidget.horizontalScrollBar().show() self.VerticalLayout_2.addWidget(self.treeWidget) '''2.Outline Tree''' self.tab_2 = QWidget() #self.tab_2.setMaximumWidth(200) self.VerticalLayout_3 = QVBoxLayout(self.tab_2) self.VerticalLayout_3.setMargin(0) self.outlineWidget = OutlineTree(self.tab_2) self.outlineWidget.itemDoubleClicked.connect(self.gotoLine) self.VerticalLayout_3.addWidget(self.outlineWidget) '''E.Output TabWidget''' self.outputTabWidget = OutputTab(self) self.tabWidget.currentChanged.connect(self.fileChanged) self.explorerTabWidget.currentChanged.connect(self.closeExplorer) self.outputTabWidget.currentChanged.connect(self.closeConsole) self.tabWidget.setTabsClosable(True) self.tabWidget.setTabShape(0) '''1.Output layout''' #must check self.tab_6 = QWidget() self.horizontalLayout_2 = QVBoxLayout(self.tab_6) self.horizontalLayout_2.setMargin(0) self.textEdit = QTextEdit() self.inputLayout = QHBoxLayout() self.inputLayout.setMargin(0) self.fileButton = QPushButton() self.fileButton.setText("File") self.fileButton.clicked.connect(self.getFile) self.runButton = QPushButton() self.runButton.setFlat(True) self.runButton.setIcon(Icons.go) self.combo = QComboBox() self.combo.setFixedWidth(100) self.comboAdd = QPushButton() self.comboAdd.setIcon(Icons.add) self.comboAdd.setFlat(True) self.comboAdd.clicked.connect(self.addCmd) self.comboDel = QPushButton() self.comboDel.setIcon(Icons.close_view) self.comboDel.setFlat(True) self.comboDel.clicked.connect(self.delCmd) self.combo2 = QComboBox() self.combo2.setFixedWidth(500) self.combo2Add = QPushButton() self.combo2Add.setIcon(Icons.add) self.combo2Add.setFlat(True) self.combo2Add.clicked.connect(self.addParam) self.combo2Del = QPushButton() self.combo2Del.setIcon(Icons.close_view) self.combo2Del.setFlat(True) self.combo2Del.clicked.connect(self.delParam) if(self.checkHasValue(self.cmdList)): for cmd in self.cmdList: self.combo.addItem(cmd) else: self.cmdList = [] if(self.checkHasValue(self.paramList)): for param in self.paramList: self.combo2.addItem(param) else: self.paramList = [] self.horizontalLayout_2.addWidget(self.textEdit) self.inputLayout.addWidget(QLabel("<b>Command:</b>")) self.inputLayout.addWidget(self.combo) self.inputLayout.addWidget(self.comboAdd) self.inputLayout.addWidget(self.comboDel) self.inputLayout.addWidget(QLabel("<b>Parameters:</b>")) self.inputLayout.addWidget(self.combo2) self.inputLayout.addWidget(self.combo2Add) self.inputLayout.addWidget(self.combo2Del) self.inputLayout.addWidget(self.fileButton) self.inputLayout.addWidget(self.runButton) self.horizontalLayout_2.addLayout(self.inputLayout) '''2.Error Layout''' self.tab_7 = QWidget() self.horizontalLayout_4 = QHBoxLayout(self.tab_7) self.horizontalLayout_4.setMargin(0) self.errorTree = ErrorTree(self.tab_7) self.errorTree.itemDoubleClicked.connect(self.errorLine) self.horizontalLayout_4.addWidget(self.errorTree) '''TabWidgets tabs''' #self.designerWidget.addTab(QWidget(self),"") #self.designerWidget.setTabIcon(0,Icons.close_view) #self.levelWidget.addTab(QWidget(self),"") #self.levelWidget.setTabIcon(0,Icons.close_view) self.explorerTabWidget.addTab(self.tab_5,"Projects") self.explorerTabWidget.addTab(self.tab_2,"Outline") self.explorerTabWidget.addTab(QWidget(self),"") self.explorerTabWidget.setTabIcon(0,Icons.cprj) self.explorerTabWidget.setTabIcon(1,Icons.envvar) self.explorerTabWidget.setTabIcon(2,Icons.close_view) self.outputTabWidget.addTab(self.tab_7,"Error") self.outputTabWidget.addTab(self.tab_6,"Output") self.outputTabWidget.addTab(QWidget(self),"") self.outputTabWidget.setTabIcon(0,Icons.error) self.outputTabWidget.setTabIcon(1,Icons.console_view) self.outputTabWidget.setTabIcon(2,Icons.close_view) '''Splitters''' self.split1 = QSplitter(Qt.Horizontal) self.split1.addWidget(self.explorerTabWidget) self.split1.addWidget(self.editorLayoutWidget) self.split1.addWidget(self.designerLayoutWidget) self.split1.addWidget(self.levelLayoutWidget) #self.split1.addWidget(self.tab_5) self.split2 = QSplitter(Qt.Vertical) self.split2.addWidget(self.split1) self.split2.addWidget(self.outputTabWidget) self.horizontalLayout.addWidget(self.split2) '''Status Bar''' self.statusbar = QStatusBar(self) self.aboutButton = QPushButton(self) self.aboutButton.setFlat(True) self.aboutButton.setIcon(Icons.anchor) self.aboutButton.clicked.connect(self.about) self.expButton = QPushButton(self) self.expButton.setFlat(True) self.expButton.setIcon(Icons.prj) self.expButton.clicked.connect(self.exp) self.cmdButton = QPushButton(self) self.cmdButton.setFlat(True) self.cmdButton.setIcon(Icons.console_view) self.cmdButton.clicked.connect(self.cmd) self.cmdButton.setShortcut('Ctrl+D') self.imgButton = QPushButton(self) self.imgButton.setFlat(True) self.imgButton.setIcon(Icons.color_palette) self.imgButton.clicked.connect(self.design) self.imgButton.setShortcut('Ctrl+I') self.findButton = QPushButton(self) self.findButton.setFlat(True) self.findButton.setIcon(Icons.find) self.findButton.setShortcut("Ctrl+F") self.findButton.clicked.connect(self.findBarShow) ''' self.zoominButton = QPushButton(self) self.zoominButton.setFlat(True) self.zoominButton.setIcon(Icons.zoomplus) self.zoominButton.clicked.connect(self.zoomin) self.zoomoutButton = QPushButton(self) self.zoomoutButton.setFlat(True) self.zoomoutButton.setIcon(Icons.zoomminus) self.zoomoutButton.clicked.connect(self.zoomout) ''' '''Status Text,Line Text, Progress Bar and Stop Button''' self.statusText = QLabel("Writable") #self.statusText.setAlignment(Qt.AlignCenter) self.statusText.setFixedWidth(200) self.lineText = QLabel("") self.lineText.setFixedWidth(50) self.progressbar = QProgressBar() self.progressbar.setMinimum(0) self.progressbar.setMaximum(100) self.stopButton = QPushButton(self) self.stopButton.setFlat(True) self.stopButton.setIcon(Icons.stop) self.stopButton.clicked.connect(self.forceStop) self.progressbar.hide() self.stopButton.hide() self.temp = False self.progress = False self.counter = 0 '''Adding all widgets to Status Bar''' self.statusbar.addWidget(self.aboutButton) self.statusbar.addWidget(self.expButton) self.statusbar.addWidget(self.cmdButton) self.statusbar.addWidget(self.imgButton) self.statusbar.addWidget(self.findButton) #self.statusbar.addWidget(QWidget(self)) #self.statusbar.addWidget(self.zoominButton) #self.statusbar.addWidget(self.zoomoutButton) self.statusbar.addWidget(self.statusText) self.statusbar.addWidget(self.lineText) self.statusbar.addWidget(self.progressbar) self.statusbar.addWidget(self.stopButton) #self.statusbar.setFixedHeight(18) ''''Initializing Coloring Style''' self.initEditorStyle() self.initStyleSheet() '''Adding Cental Widget and Status Bar''' self.setCentralWidget(self.centralwidget) self.setStatusBar(self.statusbar) self.textEdit.setReadOnly(True) def initStyleSheet(self): import stylesheet self.setStyleSheet(stylesheet.mainstyl) self.tabWidget.tabBar().setStyleSheet(stylesheet.stletabb) self.explorerTabWidget.tabBar().setStyleSheet(stylesheet.stletabb) self.outputTabWidget.tabBar().setStyleSheet(stylesheet.stletabb) self.popWidget.setStyleSheet(stylesheet.popbg) self.popWidget.hide() ''' This is for changing the palette/window colors to Theme ''' def initEditorStyle(self): pass #editStyle = config.readStyle() #print editStyle #pal = QPalette(self.explorerTabWidget.palette()) #print pal.color(QPalette.Base).name() #print pal.color(QPalette.Window).name() #pal.setColor(QPalette.Base,self.colorStyle.paper) #pal.setColor(QPalette.Text,self.colorStyle.color) #self.explorerTabWidget.setPalette(pal) #self.outputTabWidget.setPalette(pal) ''' This is only for testing dont know if it works for builds ''' def changeStyleSheet(self): ''' Dynamically load the changed stylesheet.py and load the modules and change the style at runtime saves countless deploys ''' import imp foo = imp.load_source('stletabb', workDir+"/stylesheet.py") #print foo.stletabb #self.setStyleSheet(stylesheet.mainstyl) self.tabWidget.tabBar().setStyleSheet(foo.stletabb) self.popWidget.setStyleSheet(foo.popbg) if(self.popWidget.isHidden()): self.popWidget.showPopup() def build_project(self): #current_file = self.files[self.tabWidget.currentIndex()] prj = self.treeWidget.getProject() if(prj != None): self.treeWidget.build(prj) def run_project(self): #current_file = self.files[self.tabWidget.currentIndex()] prj = self.treeWidget.getProject()#current_file) if(prj != None): self.treeWidget.run(prj) def forceStop(self): self.ant.kill() self.progressStop() def kill(self): self.deleteLater() #-----------------------------------------------------------------------------------# # Menu Actions Functions # #-----------------------------------------------------------------------------------# def run(self): if(config.mode() == 0): self.sq.run() elif(config.mode() == 1): self.adb.run() elif(config.mode() == 2): self.ios.run() elif(config.mode() == 3): self.c.run() def setMode(self, action): if(action.text() == "Squ"): config.setMode(0) self.toolBar.action_Build.setEnabled(False) self.toolBar.action_Run.setEnabled(False) elif(action.text() == "Emo"): config.setMode(1) self.toolBar.action_Build.setEnabled(True) self.toolBar.action_Run.setEnabled(True) elif(action.text() == "Android"): config.setMode(2) self.toolBar.action_Build.setEnabled(True) self.toolBar.action_Run.setEnabled(True) elif(action.text() == "ios"): config.setMode(3) self.toolBar.action_Build.setEnabled(False) self.toolBar.action_Run.setEnabled(False) def openCommand(self): text, ok = QInputDialog.getText(self, 'Run Command', 'Command:') cmd = str(text) if ok and cmd != "": import subprocess subprocess.Popen(cmd) def about(self): form = DialogAbout(self) def todo(self): form = DialogTodo(self) form.show() def help(self): QMessageBox.about(self,"Help","This is about all The Help that i can Give you now") def full(self): if not self.isFull: self.setWindowState(Qt.WindowFullScreen) self.isFull = True else: self.setWindowState(Qt.WindowMaximized) self.isFull = False def android(self): form = DialogAndroid(self) form.show() def antt(self): form = DialogAnt(self) form.show() def squirrel(self): form = DialogSquirrel(self) form.show() def findBarShow(self): if(self.findLayoutWidget.isHidden()): self.findLayoutWidget.show() else: self.findLayoutWidget.hide() def exp(self): if(self.explorerTabWidget.isHidden()): self.explorerTabWidget.show() else: self.explorerTabWidget.hide() def cmd(self): if(self.outputTabWidget.isHidden()): self.outputTabWidget.show() else: self.outputTabWidget.hide() def editor(self): if(self.editorLayoutWidget.isHidden()): self.editorLayoutWidget.show() self.levelLayoutWidget.hide() self.designerLayoutWidget.hide() def design(self): if(self.designerLayoutWidget.isHidden()): self.designerLayoutWidget.show() self.editorLayoutWidget.hide() self.levelLayoutWidget.hide() else: self.designerLayoutWidget.hide() self.editorLayoutWidget.show() def level(self): if(self.levelLayoutWidget.isHidden()): self.levelLayoutWidget.show() self.editorLayoutWidget.hide() self.designerLayoutWidget.hide() else: self.levelLayoutWidget.hide() self.editorLayoutWidget.show() def closeDesigner(self,no): pass ''' if(no == self.tiler.closeIndex()): if(self.tiler.isHidden()): self.tiler.show() else: self.tiler.setCurrentIndex(1) self.tiler.hide() ''' '''The current Changed idx of outputTabWidget is passed to this a param''' def closeConsole(self,no = 2): if(no == 2): if(self.outputTabWidget.isHidden()): self.outputTabWidget.show() else: self.outputTabWidget.setCurrentIndex(1) self.outputTabWidget.hide() def popOutput(self): if(self.outputTabWidget.isHidden()): self.outputTabWidget.show() self.outputTabWidget.setCurrentIndex(1) def popError(self): if(self.outputTabWidget.isHidden()): self.outputTabWidget.show() self.outputTabWidget.setCurrentIndex(0) '''The current Changed idx of explorerTabWidget is passed to this a param''' def closeExplorer(self,no = 2): if(no == 2): if(self.explorerTabWidget.isHidden()): self.explorerTabWidget.show() else: self.explorerTabWidget.setCurrentIndex(0) self.explorerTabWidget.hide() elif(no == 1): self.fileChanged(no) ''' This is to refresh the outline widget''' def fileChanged(self,no): if(self.explorerTabWidget.currentIndex() == 1): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) source = edt.text() self.outlineWidget.parseText(source) def statusSaving(self): self.statusText.setText("Saving") def statusParsing(self): self.statusText.setText("Parsing") def statusWriting(self): self.statusText.setText("Writable") def statusRunning(self): self.statusText.setText("Running") def statusStopping(self): self.statusText.setText("Stopping") def statusCommand(self): self.statusText.setText("Command") def statusBuilding(self): self.statusText.setText("Building") def statusInstalling(self): self.statusText.setText("Installing") def statusCleaning(self): self.statusText.setText("Cleaning") def statusCreating(self): self.statusText.setText("Creating") def progressStart(self): self.progress == True self.temp == True if(self.progressbar.isHidden()): self.progressbar.show() if(self.stopButton.isHidden()): self.stopButton.show() self.progressbar.setValue(1) def progressStop(self): self.progress == False self.temp == False self.progressbar.setValue(100) if not(self.progressbar.isHidden()): self.progressbar.hide() if not(self.stopButton.isHidden()): self.stopButton.hide() def progressUpdate(self): if(self.progress): if(self.temp): self.counter += 1 self.progressbar.setValue(self.counter) if(self.counter == 100): self.temp = False else: self.counter -= 1 self.progressbar.setValue(self.counter) if(self.counter == 0): self.temp = True #-----------------------------------------------------------------------------------# # Editor Functions # #-----------------------------------------------------------------------------------# '''Search and Replace Functions''' def findCurrentText(self): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) edt.findText(self.lineEdit.text(),self.regex.isChecked(),self.caseSensitive.isChecked(),self.wholeWord.isChecked(),self.backward.isChecked()) def replaceCurrentText(self): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) edt.replaceText(self.lineEdit_2.text()) def replaceFindText(self): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) edt.replaceText(self.lineEdit_2.text()) self.findCurrentText() def replaceAllText(self): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) while(edt.findText(self.lineEdit.text(),self.regex.isChecked(),self.caseSensitive.isChecked(),self.wholeWord.isChecked(),self.backward.isChecked())): edt.replaceText(self.lineEdit_2.text()) def errorLine(self,error): index = self.tabWidget.currentIndex() edt = self.tabWidget.widget(index) '''To prevent File item double clicking''' if(error.isFile() == False): edt.setLine(error.line) '''Font Functions''' def zoomin(self): pass #for i in range(len(self.files)): # self.tabWidget.widget(i).zoomin() def zoomout(self): pass #for i in range(len(self.files)): # self.tabWidget.widget(i).zoomout() ''' Must implement Lexer ''' def setLexer(self, action): pass #print action.text() def setApi(self, action): #print action.text() for i in range(len(self.files)): #not QString self.tabWidget.widget(i).setApi(str(action.text())) def setFont(self,font): config.setFontName(str(font.family())) for i in range(len(self.files)): self.tabWidget.widget(i).setNewFont(font) def setFontSize(self,idx): fontSize = idx+1 config.setFontSize(fontSize) for i in range(len(self.files)): self.tabWidget.widget(i).setFontSize() def gotoLine(self,item): edt = self.tabWidget.widget(self.tabWidget.currentIndex()) edt.setLine(item.line) def updateLine(self,no,col): self.lineText.setText(str(no)+" : "+str(col)) def setMargin(self): mar = config.margin() if(mar == 0): config.setMargin(1) for i in range(len(self.files)): self.tabWidget.widget(i).setMargin(1) else: config.setMargin(0) for i in range(len(self.files)): self.tabWidget.widget(i).setMargin(0) ''' Toggle ''' def setIndent(self): indent = config.indent() if(indent == 0): config.setIndent(1) for i in range(len(self.files)): self.tabWidget.widget(i).setIndent(1) else: config.setIndent(0) for i in range(len(self.files)): self.tabWidget.widget(i).setIndent(0) ''' Toggle ''' def setWhiteSpace(self): white = config.whiteSpace() if(white == 0): config.setWhiteSpace(1) for i in range(len(self.files)): self.tabWidget.widget(i).setWhitespaceVisibility(True) else: config.setWhiteSpace(0) for i in range(len(self.files)): self.tabWidget.widget(i).setWhitespaceVisibility(False) ''' Toggle ''' def setEndLine(self): for i in range(len(self.files)): edt = self.tabWidget.widget(i) edt.setEolVisibility(not edt.eolVisibility()) def setEncoding(self, action): if(action.text() == "Ascii"): config.setAscii() for i in range(len(self.files)): self.tabWidget.widget(i).setUtf8(False) elif(action.text() == "Unicode"): config.setUnicode() for i in range(len(self.files)): self.tabWidget.widget(i).setUtf8(True) def setThreshold(self,val): config.setThresh(val) for i in range(len(self.files)): #print i self.tabWidget.widget(i).setThreshold(val) def setTabWidth(self,val): config.setTabWidth(val) for i in range(len(self.files)): #print i self.tabWidget.widget(i).setTabWidth(val) '''style Functions''' #-----------------------------------------------------------------------------------# # Command Functions # #-----------------------------------------------------------------------------------# def getFile(self): self.browsedialog = DialogBrowse(self) self.browsedialog.tree.itemDoubleClicked.connect(self.getName) self.browsedialog.show() def getName(self,item): if(item.isFile()): self.browsedialog.accept() fname = item.getPath() if not (fname == ""): index = self.combo2.currentIndex() text = str(self.combo2.itemText(index))+" "+fname self.combo2.setItemText(index,text) self.paramList.pop(index) self.paramList.insert(index,text) config.setParam(self.paramList) def addCmd(self,index): text, ok = QInputDialog.getText(self, 'Add Command', 'Command:') if(ok): if(str(text) != ''): cmd = str(text).upper() self.cmdList.append(cmd) #print self.cmdList self.combo.addItem(cmd) config.setCmd(self.cmdList) config.setParam(self.paramList) def delCmd(self): index = self.combo.currentIndex() self.combo.removeItem(index) self.cmdList.pop(index) #print self.cmdList config.setCmd(self.cmdList) def addParam(self,index): text, ok = QInputDialog.getText(self, 'Add Parameters', 'Params:') if(ok): if(str(text) != ''): param = str(text) self.paramList.append(param) self.combo2.addItem(param) config.setParam(self.paramList) def delParam(self): index = self.combo2.currentIndex() self.combo2.removeItem(index) self.paramList.pop(index) config.setParam(self.paramList) def checkHasValue(self,list): if(list != None and len(list) != 0): return True else: return False
class ActionBar(QFrame): """ SIGNALS: @changeCurrent(PyQt_PyObject) @runFile(QString) @reopenTab(QString) @recentTabsModified() """ def __init__(self, main_combo=False): super(ActionBar, self).__init__() self.setObjectName("actionbar") hbox = QHBoxLayout(self) hbox.setContentsMargins(1, 1, 1, 1) hbox.setSpacing(1) self.lbl_checks = QLabel('') self.lbl_checks.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.lbl_checks.setFixedWidth(48) self.lbl_checks.setVisible(False) hbox.addWidget(self.lbl_checks) self.combo = QComboBox() self.combo.setIconSize(QSize(16, 16)) #model = QStandardItemModel() #self.combo.setModel(model) #self.combo.view().setDragDropMode(QAbstractItemView.InternalMove) self.combo.setMaximumWidth(300) self.combo.setObjectName("combotab") self.connect(self.combo, SIGNAL("currentIndexChanged(int)"), self.current_changed) self.combo.setToolTip(translations.TR_COMBO_FILE_TOOLTIP) self.combo.setContextMenuPolicy(Qt.CustomContextMenu) self.connect(self.combo, SIGNAL( "customContextMenuRequested(const QPoint &)"), self._context_menu_requested) hbox.addWidget(self.combo) self.symbols_combo = QComboBox() self.symbols_combo.setIconSize(QSize(16, 16)) self.symbols_combo.setObjectName("combo_symbols") self.connect(self.symbols_combo, SIGNAL("activated(int)"), self.current_symbol_changed) hbox.addWidget(self.symbols_combo) self.code_navigator = CodeNavigator() hbox.addWidget(self.code_navigator) self._pos_text = "Line: %d, Col: %d" self.lbl_position = QLabel(self._pos_text % (0, 0)) self.lbl_position.setObjectName("position") self.lbl_position.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.lbl_position) self.btn_close = QPushButton( self.style().standardIcon(QStyle.SP_DialogCloseButton), '') self.btn_close.setIconSize(QSize(16, 16)) if main_combo: self.btn_close.setObjectName('navigation_button') self.btn_close.setToolTip(translations.TR_CLOSE_FILE) self.connect(self.btn_close, SIGNAL("clicked()"), self.about_to_close_file) else: self.btn_close.setObjectName('close_split') self.btn_close.setToolTip(translations.TR_CLOSE_SPLIT) self.connect(self.btn_close, SIGNAL("clicked()"), self.close_split) self.btn_close.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox.addWidget(self.btn_close) def resizeEvent(self, event): super(ActionBar, self).resizeEvent(event) if event.size().width() < 350: self.symbols_combo.hide() self.code_navigator.hide() self.lbl_position.hide() else: self.symbols_combo.show() self.code_navigator.show() self.lbl_position.show() def add_item(self, text, neditable): """Add a new item to the combo and add the neditable data.""" self.combo.addItem(text, neditable) self.combo.setCurrentIndex(self.combo.count() - 1) def get_editables(self): editables = [] for index in range(self.combo.count()): neditable = self.combo.itemData(index) editables.append(neditable) return editables def add_symbols(self, symbols): """Add the symbols to the symbols's combo.""" self.symbols_combo.clear() for symbol in symbols: data = symbol[1] if data[1] == 'f': icon = QIcon(":img/function") else: icon = QIcon(":img/class") self.symbols_combo.addItem(icon, data[0]) def set_current_symbol(self, index): self.symbols_combo.setCurrentIndex(index) def update_item_icon(self, neditable, icon): index = self.combo.findData(neditable) self.combo.setItemIcon(index, icon) def update_item_text(self, neditable, text): index = self.combo.findData(neditable) self.combo.setItemText(index, text) def current_changed(self, index): """Change the current item in the combo.""" neditable = self.combo.itemData(index) self.emit(SIGNAL("changeCurrent(PyQt_PyObject, int)"), neditable, index) def current_symbol_changed(self, index): """Change the current symbol in the combo.""" self.emit(SIGNAL("goToSymbol(int)"), index) def update_line_col(self, line, col): """Update the line and column position.""" self.lbl_position.setText(self._pos_text % (line, col)) def _context_menu_requested(self, point): """Display context menu for the combo file.""" if self.combo.count() == 0: # If there is not an Editor opened, don't show the menu return menu = QMenu() actionAdd = menu.addAction(translations.TR_ADD_TO_PROJECT) actionRun = menu.addAction(translations.TR_RUN_FILE) menuSyntax = menu.addMenu(translations.TR_CHANGE_SYNTAX) self._create_menu_syntax(menuSyntax) menu.addSeparator() actionClose = menu.addAction(translations.TR_CLOSE_FILE) actionCloseAll = menu.addAction(translations.TR_CLOSE_ALL_FILES) actionCloseAllNotThis = menu.addAction( translations.TR_CLOSE_OTHER_FILES) menu.addSeparator() actionSplitH = menu.addAction(translations.TR_SPLIT_VERTICALLY) actionSplitV = menu.addAction(translations.TR_SPLIT_HORIZONTALLY) menu.addSeparator() actionCopyPath = menu.addAction( translations.TR_COPY_FILE_PATH_TO_CLIPBOARD) actionReopen = menu.addAction(translations.TR_REOPEN_FILE) actionUndock = menu.addAction(translations.TR_UNDOCK_EDITOR) if len(settings.LAST_OPENED_FILES) == 0: actionReopen.setEnabled(False) #Connect actions self.connect(actionSplitH, SIGNAL("triggered()"), lambda: self._split(False)) self.connect(actionSplitV, SIGNAL("triggered()"), lambda: self._split(True)) self.connect(actionRun, SIGNAL("triggered()"), self._run_this_file) self.connect(actionAdd, SIGNAL("triggered()"), self._add_to_project) self.connect(actionClose, SIGNAL("triggered()"), self.about_to_close_file) self.connect(actionCloseAllNotThis, SIGNAL("triggered()"), self._close_all_files_except_this) self.connect(actionCloseAll, SIGNAL("triggered()"), self._close_all_files) self.connect(actionCopyPath, SIGNAL("triggered()"), self._copy_file_location) self.connect(actionReopen, SIGNAL("triggered()"), self._reopen_last_tab) self.connect(actionUndock, SIGNAL("triggered()"), self._undock_editor) menu.exec_(QCursor.pos()) def _create_menu_syntax(self, menuSyntax): """Create Menu with the list of syntax supported.""" syntax = list(settings.SYNTAX.keys()) syntax.sort() for syn in syntax: menuSyntax.addAction(syn) self.connect(menuSyntax, SIGNAL("triggered(QAction*)"), self._reapply_syntax) def _reapply_syntax(self, syntaxAction): #TODO if [self.currentIndex(), syntaxAction] != self._resyntax: self._resyntax = [self.currentIndex(), syntaxAction] self.emit(SIGNAL("syntaxChanged(QWidget, QString)"), self.currentWidget(), syntaxAction.text()) def set_current_file(self, neditable): index = self.combo.findData(neditable) self.combo.setCurrentIndex(index) def set_current_by_index(self, index): self.combo.setCurrentIndex(index) def about_to_close_file(self, index=None): """Close the NFile object.""" if index is None: index = self.combo.currentIndex() neditable = self.combo.itemData(index) if neditable: neditable.nfile.close() def close_split(self): self.emit(SIGNAL("closeSplit()")) def close_file(self, neditable): """Receive the confirmation to close the file.""" index = self.combo.findData(neditable) self.combo.removeItem(index) return index def _run_this_file(self): """Execute the current file.""" neditable = self.combo.itemData(self.combo.currentIndex()) self.emit(SIGNAL("runFile(QString)"), neditable.file_path) def _add_to_project(self): """Emit a signal to let someone handle the inclusion of the file inside a project.""" neditable = self.combo.itemData(self.combo.currentIndex()) self.emit(SIGNAL("addToProject(QString)"), neditable.file_path) def _reopen_last_tab(self): self.emit(SIGNAL("reopenTab(QString)"), settings.LAST_OPENED_FILES.pop()) self.emit(SIGNAL("recentTabsModified()")) def _undock_editor(self): self.emit(SIGNAL("undockEditor()")) def _split(self, orientation): self.emit(SIGNAL("splitEditor(bool)"), orientation) def _copy_file_location(self): """Copy the path of the current opened file to the clipboard.""" neditable = self.combo.itemData(self.combo.currentIndex()) QApplication.clipboard().setText(neditable.file_path, QClipboard.Clipboard) def _close_all_files(self): """Close all the files opened.""" for i in range(self.combo.count()): self.about_to_close_file(0) def _close_all_files_except_this(self): """Close all the files except the current one.""" neditable = self.combo.itemData(self.combo.currentIndex()) for i in reversed(list(range(self.combo.count()))): ne = self.combo.itemData(i) if ne is not neditable: self.about_to_close_file(i)
class Dialog(toly_dialog.ToLyDialog): def __init__(self, parent=None): self.imp_prgm = "musicxml2ly" self.userg = "musicxml_import" self.noartCheck = QCheckBox() self.norestCheck = QCheckBox() self.nolayoutCheck = QCheckBox() self.nobeamCheck = QCheckBox() self.useAbsCheck = QCheckBox() self.commMidiCheck = QCheckBox() self.langCombo = QComboBox() self.langLabel = QLabel() self.impChecks = [ self.noartCheck, self.norestCheck, self.nolayoutCheck, self.nobeamCheck, self.useAbsCheck, self.commMidiCheck ] self.noartCheck.setObjectName("articulation-directions") self.norestCheck.setObjectName("rest-positions") self.nolayoutCheck.setObjectName("page-layout") self.nobeamCheck.setObjectName("import-beaming") self.useAbsCheck.setObjectName("absolute-mode") self.commMidiCheck.setObjectName("comment-out-midi") self.langCombo.addItem('') self.langCombo.addItems(_langlist) self.impExtra = [self.langLabel, self.langCombo] super(Dialog, self).__init__(parent) self.langCombo.currentIndexChanged.connect(self.makeCommandLine) app.translateUI(self) qutil.saveDialogSize(self, "musicxml_import/dialog/size", QSize(480, 260)) self.makeCommandLine() self.loadSettings() def translateUI(self): self.setWindowTitle(app.caption(_("Import Music XML"))) self.noartCheck.setText(_("Import articulation directions")) self.norestCheck.setText(_("Import rest positions")) self.nolayoutCheck.setText(_("Import page layout")) self.nobeamCheck.setText(_("Import beaming")) self.useAbsCheck.setText(_("Pitches in absolute mode")) self.commMidiCheck.setText(_("Comment out midi block")) self.langLabel.setText(_("Language for pitch names")) self.langCombo.setItemText(0, _("Default")) self.buttons.button(QDialogButtonBox.Ok).setText(_("Run musicxml2ly")) super(Dialog, self).translateUI() def makeCommandLine(self): """Reads the widgets and builds a command line.""" cmd = ["$musicxml2ly"] if self.useAbsCheck.isChecked(): cmd.append('-a') if not self.noartCheck.isChecked(): cmd.append('--nd') if not self.norestCheck.isChecked(): cmd.append('--nrp') if not self.nolayoutCheck.isChecked(): cmd.append('--npl') if not self.nobeamCheck.isChecked(): cmd.append('--no-beaming') if not self.commMidiCheck.isChecked(): cmd.append('-m') index = self.langCombo.currentIndex() if index > 0: cmd.append('--language=' + _langlist[index - 1]) cmd.append("$filename") self.commandLine.setText(' '.join(cmd)) def loadSettings(self): """Get users previous settings.""" self.imp_default = [False, False, False, False, False, False] self.settings = QSettings() self.settings.beginGroup('musicxml_import') super(Dialog, self).loadSettings() lang = self.settings.value("language", "default", type("")) try: index = _langlist.index(lang) except ValueError: index = -1 self.langCombo.setCurrentIndex(index + 1) def saveSettings(self): """Save users last settings.""" self.settings = QSettings() self.settings.beginGroup('musicxml_import') super(Dialog, self).saveSettings() index = self.langCombo.currentIndex() self.settings.setValue( 'language', 'default' if index == 0 else _langlist[index - 1])