Ejemplo n.º 1
0
class LilyDocBrowser(SettingsGroup):
    def __init__(self, page):
        super(LilyDocBrowser, self).__init__(i18n("LilyPond Documentation"), page)

        layout = QVBoxLayout(self)
        layout.setSpacing(0)

        h = KHBox()
        l = QLabel(i18n("Url:"), h)
        self.lilydoc = KUrlRequester(h)
        self.lilydoc.textChanged.connect(page.changed)
        l.setBuddy(self.lilydoc)
        tooltip = i18n("Url or path to the LilyPond documentation.")
        l.setToolTip(tooltip)
        self.lilydoc.setToolTip(tooltip)
        self.lilydoc.fileDialog().setCaption(i18n("LilyPond Documentation"))
        layout.addWidget(h)
        self.lilydoc.setMode(KFile.Mode(KFile.File | KFile.Directory | KFile.ExistingOnly))

    def defaults(self):
        self.lilydoc.setUrl(KUrl())

    def loadSettings(self):
        self.lilydoc.setUrl(KUrl(config("preferences").readEntry("lilypond documentation", "")))

    def saveSettings(self):
        config("preferences").writeEntry("lilypond documentation", self.lilydoc.url().url())

    def applySettings(self):
        lilydoc = self.page.dialog.mainwin.tools.get("lilydoc")
        if lilydoc:
            lilydoc.newDocFinder()
Ejemplo n.º 2
0
class SavingDocument(CheckGroup):

    configGroup = "preferences"

    def __init__(self, page):
        super(SavingDocument, self).__init__(i18n("When saving documents"), page)
        layout = QVBoxLayout(self)
        layout.setSpacing(0)

        layout.addWidget(self.addCheckBox(i18n("Remember cursor position, bookmarks, etc."), "save metainfo", False))

        # default directory
        h = KHBox()
        l = QLabel(i18n("Default directory:"), h)
        self.folder = KUrlRequester(h)
        l.setBuddy(self.folder)
        tooltip = i18n("The default folder for your LilyPond documents (optional).")
        l.setToolTip(tooltip)
        self.folder.setToolTip(tooltip)
        layout.addWidget(h)
        self.folder.setMode(KFile.Mode(KFile.Directory | KFile.ExistingOnly | KFile.LocalOnly))
        self.folder.button().setIcon(KIcon("document-open-folder"))
        self.folder.textChanged.connect(page.changed)

    def defaults(self):
        super(SavingDocument, self).defaults()

    def loadSettings(self):
        super(SavingDocument, self).loadSettings()
        self.folder.setPath(config("preferences").readPathEntry("default directory", ""))

    def saveSettings(self):
        super(SavingDocument, self).saveSettings()
        config("preferences").writePathEntry("default directory", self.folder.url().path())
Ejemplo n.º 3
0
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(442, 160)
        self.groupBox = QtGui.QGroupBox(Dialog)
        self.groupBox.setGeometry(QtCore.QRect(50, 10, 354, 121))
        self.groupBox.setObjectName("groupBox")
        self.formLayout = QtGui.QFormLayout(self.groupBox)
        self.formLayout.setObjectName("formLayout")
        self.dPfad = KUrlRequester(self.groupBox)
        self.dPfad.setObjectName("dPfad")
        self.dPfad.setMode(KFile.Mode(2))
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.dPfad)
        self.dNeuerName = KLineEdit(self.groupBox)
        self.dNeuerName.setEnabled(True)
        self.dNeuerName.setObjectName("dNeuerName")
        self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.dNeuerName)
        self.dDateiEndung = QtGui.QLineEdit(self.groupBox)
        self.dDateiEndung.setObjectName("dDateiEndung")
        self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.dDateiEndung)
        self.groupBox_2 = QtGui.QGroupBox(Dialog)
        self.groupBox_2.setGeometry(QtCore.QRect(50, 80, 351, 64))
        self.groupBox_2.setObjectName("groupBox_2")
        self.horizontalLayout = QtGui.QHBoxLayout(self.groupBox_2)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.dAbbrechen = QtGui.QPushButton(self.groupBox_2)
        self.dAbbrechen.setObjectName("dAbbrechen")
        self.horizontalLayout.addWidget(self.dAbbrechen)
        self.dAusfuehren = QtGui.QPushButton(self.groupBox_2)
        self.dAusfuehren.setDefault(False)
        self.dAusfuehren.setObjectName("dAusfuehren")
        self.horizontalLayout.addWidget(self.dAusfuehren)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.groupBox.setTitle(QtGui.QApplication.translate("Dialog", "Renamer", None, QtGui.QApplication.UnicodeUTF8))
        self.dNeuerName.setText(QtGui.QApplication.translate("Dialog", "Neuer Name", None, QtGui.QApplication.UnicodeUTF8))
        self.dDateiEndung.setText(QtGui.QApplication.translate("Dialog", "Dateiendung", None, QtGui.QApplication.UnicodeUTF8))
        self.dAbbrechen.setText(QtGui.QApplication.translate("Dialog", "Abbrechen", None, QtGui.QApplication.UnicodeUTF8))
        self.dAusfuehren.setText(QtGui.QApplication.translate("Dialog", "Ok", None, QtGui.QApplication.UnicodeUTF8))
Ejemplo n.º 4
0
class EditorDialog(KPageDialog):
    """A dialog to edit properties of a session.
    
    You can subclass this to add more settings to a session config dialog.
    Add more pages in the __init__() method, and inherit the validate() method
    to check the input if necessary. Implement the load and save methods to
    load and save the settings.
    
    """
    def __init__(self, manager):
        super(EditorDialog, self).__init__(manager.mainwin)
        self.mainwin = manager.mainwin
        self.sm = manager
        self.setButtons(KDialog.ButtonCode(
            KDialog.Help | KDialog.Ok | KDialog.Cancel))
        self.setFaceType(KPageDialog.List)
        self.setHelp("sessions")
        
        # First page with name and auto-save option
        page = QWidget(self)
        item = self.firstPage = self.addPage(page, i18n("Session"))
        item.setHeader(i18n("Properties of this session"))
        item.setIcon(KIcon("configure"))
        
        layout = QGridLayout(page)
        
        l = QLabel(i18n("Name:"))
        self.name = QLineEdit()
        l.setBuddy(self.name)
        layout.addWidget(l, 0, 0)
        layout.addWidget(self.name, 0, 1)
        
        self.autosave = QCheckBox(i18n(
            "Always save the list of documents in this session"))
        layout.addWidget(self.autosave, 1, 1)
        
        l = QLabel(i18n("Base directory:"))
        self.basedir = KUrlRequester()
        self.basedir.setMode(KFile.Mode(
            KFile.Directory | KFile.ExistingOnly | KFile.LocalOnly))
        l.setBuddy(self.basedir)
        layout.addWidget(l, 2, 0)
        layout.addWidget(self.basedir, 2, 1)
        
    def edit(self, name=None):
        """Edit the named or new (if not given) session."""
        # load the session
        self._originalName = name
        if name:
            self.setCaption(i18n("Edit session: %1", name))
            self.name.setText(name)
            conf = self.sm.config(name)
            self.autosave.setChecked(conf.readEntry("autosave", True))
            self.basedir.setUrl(KUrl(conf.readPathEntry("basedir", "")))
            self.loadSessionConfig(conf)
        else:
            self.setCaption(i18n("Edit new session"))
            self.name.clear()
            self.name.setFocus()
            self.autosave.setChecked(True)
            self.basedir.setUrl(KUrl())
            self.loadSessionDefaults()
        self.setCurrentPage(self.firstPage)
        if self.exec_():
            # save
            name = self.name.text()
            if self._originalName and name != self._originalName:
                self.sm.renameSession(self._originalName, name)
            conf = self.sm.config(name)
            conf.writeEntry("autosave", self.autosave.isChecked())
            conf.writePathEntry("basedir", self.basedir.url().path())
            self.saveSessionConfig(conf)
            return name

    def done(self, result):
        if not result or self.validate():
            super(EditorDialog, self).done(result)
        
    def validate(self):
        """Checks if the input is acceptable.
        
        If this method returns True, the dialog is accepted when OK is clicked.
        Otherwise a messagebox could be displayed, and the dialog will remain
        visible.
        """
        # strip off whitespace
        name = self.name.text().strip()
        self.name.setText(name)
        
        if not name:
            self.setCurrentPage(self.firstPage)
            self.name.setFocus()
            KMessageBox.error(self, i18n("Please enter a session name."))
            if self._originalName:
                self.name.setText(self._originalName)
            return False
        
        if name == 'none':
            self.setCurrentPage(self.firstPage)
            self.name.setFocus()
            KMessageBox.error(self, i18n(
                "Please do not use the name '%1'.", "none"))
            return False
        
        if '&' in name:
            self.setCurrentPage(self.firstPage)
            self.name.setFocus()
            KMessageBox.error(self, i18n(
                "Please do not use the ampersand (&) character "
                "in a session name."))
            return False
            
        if self._originalName != name and name in self.sm.names():
            self.setCurrentPage(self.firstPage)
            self.name.setFocus()
            if KMessageBox.warningContinueCancel(self, i18n(
                "Another session with the name %1 exists already.\n\n"
                "Do you want to overwrite it?", name), None,
                KStandardGuiItem.overwrite(), KStandardGuiItem.cancel(),
                "session_overwrite") == KMessageBox.Cancel:
                return False
            
        return True
    
    def loadSessionDefaults(self):
        """Implement to set defaults for your new session."""
        pass
    
    def loadSessionConfig(self, conf):
        """Implement to load settings from the config group for this session."""
        pass
    
    def saveSessionConfig(self, conf):
        """Implement to save settings to the config group for this session."""
        pass