class RumorSettings(KDialog): """ Dialog with more Rumor settings. """ def __init__(self, mainwin): KDialog.__init__(self, mainwin) self.setAttribute(Qt.WA_DeleteOnClose) self.setCaption(i18n("Rumor Settings")) self.setButtons(KDialog.ButtonCode( KDialog.Ok | KDialog.Cancel | KDialog.Help)) self.setHelp("rumor") layout = QGridLayout(self.mainWidget()) # MIDI input and output. # Get the list of available OSS and ALSA devices oslist = [('oss:{0}'.format(i), i18n("OSS device %1", i)) for i in range(getOSSnrMIDIs())] i = oslist + parseAconnect('i') + [("keyboard", i18n("Keyboard"))] o = oslist + parseAconnect('o') self.ilist, ititles = map(list, zip(*i)) self.olist, otitles = map(list, zip(*o)) # input l = QLabel(i18n("MIDI input:")) layout.addWidget(l, 1, 0) self.ibut = QComboBox() self.ibut.addItems(ititles) self.ibut.setToolTip(i18n("MIDI input to use. Choose 'Keyboard' if " "you want to play on the keyboard of your computer.")) layout.addWidget(self.ibut, 1, 1) l.setBuddy(self.ibut) # output l = QLabel(i18n("MIDI output:")) layout.addWidget(l, 2, 0) self.obut = QComboBox() self.obut.addItems(otitles) self.obut.setToolTip(i18n("MIDI output to use.")) layout.addWidget(self.obut, 2, 1) l.setBuddy(self.obut) # Language l = QLabel(i18n("Language:")) layout.addWidget(l, 3, 0) self.lang = QComboBox() self.lang.addItems(( AUTO(), 'ne', 'en', 'en-short', 'de', 'no', 'sv', 'it', 'ca', 'es')) self.lang.setToolTip(i18n("The LilyPond language you want Rumor to " "output the pitches in.")) layout.addWidget(self.lang, 3, 1) l.setBuddy(self.lang) hb = QHBoxLayout() layout.addLayout(hb, 4, 0, 1, 2) # explicit durations self.explDur = QCheckBox(i18n("Explicit durations")) self.explDur.setToolTip(i18n( "Add a duration after every note, even if it is the same as the " "preceding note.")) hb.addWidget(self.explDur) # absolute pitches self.absPitches = QCheckBox(i18n("Absolute pitch")) self.absPitches.setToolTip(i18n( "Use absolute pitches instead of relative.")) hb.addWidget(self.absPitches) hb = QHBoxLayout() layout.addLayout(hb, 5, 0, 1, 2) # No Barlines self.noBar = QCheckBox(i18n("No barlines")) self.noBar.setToolTip(i18n( "Filter the barlines out of Rumor's output.")) hb.addWidget(self.noBar) # No dots self.noDots = QCheckBox(i18n("No dots")) self.noDots.setToolTip(i18n( "Do not use dotted notes, but ties instead.")) hb.addWidget(self.noDots) # Legato self.legato = QCheckBox(i18n("Legato")) self.legato.setToolTip(i18n("Do not use rests, but give all notes " "the maximum length.")) hb.addWidget(self.legato) # Strip rests self.stripRests = QCheckBox(i18n("Strip rests")) self.stripRests.setToolTip(i18n( "Strip leading and trialing rests from output.")) hb.addWidget(self.stripRests) layout.addWidget(QLabel(i18n( "Guile scripts to load:")), 6, 0, 1, 2) # Guile scripts listview self.scripts = QTreeWidget() self.scripts.setRootIsDecorated(False) self.scripts.setHeaderLabels((i18n("Name"), i18n("Description"))) self.scripts.setToolTip(i18n( "Here you can select which Guile scripts you want Rumor to load. " "Check \"What's this\" for more information.")) localRumorDir = "~/.kde/share/apps/frescobaldi/rumor/" self.scripts.setWhatsThis(i18n( "Here you can select which Guile scripts you want Rumor to load. " "You can add your own scripts by putting them in %1. " "If the first line of your script starts with a semicolon (;) " "that line will be shown as description.", localRumorDir)) layout.addWidget(self.scripts, 7, 0, 1, 2) self.loadSettings() def done(self, result): if result: self.saveSettings() KDialog.done(self, result) def loadSettings(self): """ Load the settings """ conf = config("rumor") if 'oss:1' in self.ilist: idefault = odefault = 'oss:1' else: idefault = 'kbd' odefault = self.olist and self.olist[-1] or "" i = conf.readEntry("midi in", idefault) o = conf.readEntry("midi out", odefault) if i in self.ilist: self.ibut.setCurrentIndex(self.ilist.index(i)) if o in self.olist: self.obut.setCurrentIndex(self.olist.index(o)) setComboBox(self.lang, unautofy(conf.readEntry("language", "auto"))) self.absPitches.setChecked(conf.readEntry("absolute pitches", False)) self.explDur.setChecked(conf.readEntry("explicit durations", False)) self.noBar.setChecked(conf.readEntry("no barlines", False)) self.noDots.setChecked(conf.readEntry("no dots", False)) self.legato.setChecked(conf.readEntry("legato", False)) self.stripRests.setChecked(conf.readEntry("strip rests", False)) # Guile scripts self.scripts.clear() scripts = conf.readEntry("scripts", []) for path in rumorScripts(): name = os.path.basename(path) try: desc = open(path).readline().strip() item = QTreeWidgetItem(self.scripts) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setCheckState(0, (name in scripts) and Qt.Checked or Qt.Unchecked) item.setText(0, name) if desc.startswith(';'): item.setText(1, desc.strip(";")) except IOError: pass for col in 0, 1: self.scripts.resizeColumnToContents(col) def saveSettings(self): """ Save the settings """ conf = config("rumor") conf.writeEntry("midi in", self.ilist[self.ibut.currentIndex()]) conf.writeEntry("midi out", self.olist[self.obut.currentIndex()]) conf.writeEntry("language", autofy(self.lang.currentText())) conf.writeEntry("absolute pitches", self.absPitches.isChecked()) conf.writeEntry("explicit durations", self.explDur.isChecked()) conf.writeEntry("no barlines", self.noBar.isChecked()) conf.writeEntry("no dots", self.noDots.isChecked()) conf.writeEntry("legato", self.legato.isChecked()) conf.writeEntry("strip rests", self.stripRests.isChecked()) # Read script treeview names = [] for row in range(self.scripts.topLevelItemCount()): item = self.scripts.topLevelItem(row) if item.checkState(0) == Qt.Checked: names.append(item.text(0)) conf.writeEntry("scripts", names)