Пример #1
0
 def __init__(self, mainwin, pdfs):
     KDialog.__init__(self, mainwin)
     self.mainwin = mainwin
     self.setAttribute(Qt.WA_DeleteOnClose)
     self.setButtons(KDialog.ButtonCode(
         KDialog.User1 | KDialog.Ok | KDialog.Cancel))
     self.setButtonGuiItem(KDialog.Ok, KStandardGuiItem.print_())
     self.setButtonIcon(KDialog.User1, KIcon("edit-select-all"))
     self.setButtonText(KDialog.User1, i18n("Select all"))
     self.setCaption(i18n("Print documents"))
     b = KVBox(self)
     b.setSpacing(4)
     QLabel(i18n("Please select the files you want to print:"), b)
     fileList = QListWidget(b)
     fileList.setIconSize(QSize(22, 22))
     fileList.setWhatsThis(i18n(
         "These are the PDF documents that are up-to-date (i.e. newer than "
         "the LilyPond source document). "
         "Check the documents you want to send to the printer."))
     
     for pdf in pdfs:
         i = QListWidgetItem(KIcon("application-pdf"), os.path.basename(pdf),
             fileList)
         i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable |
             Qt.ItemIsUserCheckable)
         i.setCheckState(Qt.Unchecked)
     
     fileList.item(0).setCheckState(Qt.Checked)
     self.fileList = fileList
     self.setMainWidget(b)
     self.resize(350, 200)
     self.pdfs = pdfs
     self.user1Clicked.connect(self.selectAll)
Пример #2
0
class RMirrorBrowser(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        kwargs = {"local.only":False}
        m = robjects.r.getCRANmirrors(all=False, **kwargs)
        names = QStringList(list(m.rx('Name')[0]))
        urls = list(m.rx('URL')[0])
        self.links = dict(zip(names, urls))
        names = QStringList(names)
        self.setWindowTitle("manageR - Choose CRAN Mirror")
        self.setWindowIcon(QIcon(":icon"))
        self.links = dict(zip(names, urls))
        self.currentMirror = None
        self.mirrorList = QListWidget(self)
        self.mirrorList.setAlternatingRowColors(True)
        self.mirrorList.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.mirrorList.setSortingEnabled(True)
        self.mirrorList.setSelectionMode(QAbstractItemView.SingleSelection)
        self.mirrorList.setToolTip("Double-click to select mirror location")
        self.mirrorList.setWhatsThis("List of CRAN mirrors")
        self.mirrorList.insertItems(0, names)
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        vbox = QVBoxLayout(self)
        vbox.addWidget(self.mirrorList)
        vbox.addWidget(buttonBox)

        self.connect(buttonBox, SIGNAL("accepted()"), self.accept)
        self.connect(buttonBox, SIGNAL("rejected()"), self.reject)
        self.connect(self.mirrorList,
            SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.accept)

    def currentMirror(self):
        return robjects.r("getOption('repos')")[0]

    def setCurrentMirror(self, mirror):
        robjects.r("options('repos'='%s')" % mirror)

    def accept(self):
        items = self.mirrorList.selectedItems()
        if len(items) > 0:
            name = items[0].text()
            url = self.links[name]
            self.setCurrentMirror(url)
            QDialog.accept(self)
        else:
            QMessageBox.warning(self, "manageR - Warning",
                "Please choose a valid CRAN mirror")
Пример #3
0
    def __init__(self, parent, updatedFiles, warnpreview):
        KDialog.__init__(self, parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel))
        self.setCaption(i18n("Email documents"))
        self.showButtonSeparator(True)
        b = KVBox(self)
        b.setSpacing(4)
        QLabel(i18n("Please select the files you want to send:"), b)
        fileList = QListWidget(b)
        fileList.setIconSize(QSize(22, 22))
        fileList.setWhatsThis(i18n(
            "These are the files that are up-to-date (i.e. newer than "
            "the LilyPond source document). Also LilyPond files included "
            "by the source document are shown."))
        
        lyFiles = ly.parse.findIncludeFiles(updatedFiles.lyfile,
            config("preferences").readPathEntry("lilypond include path", []))
        pdfFiles = updatedFiles("pdf")
        midiFiles = updatedFiles("mid*")
        
        if warnpreview and pdfFiles:
            QLabel(i18np(
                "Note: this PDF file has been created with "
                "embedded point-and-click URLs (preview mode), which "
                "increases the file size dramatically. "
                "Please consider to rebuild the file in publish mode, "
                "because then the PDF file is much smaller.",
                "Note: these PDF files have been created with "
                "embedded point-and-click URLs (preview mode), which "
                "increases the file size dramatically. "
                "Please consider to rebuild the files in publish mode, "
                "because then the PDF files are much smaller.",
                len(pdfFiles)), b).setWordWrap(True)
        
        if not pdfFiles and not midiFiles:
            QLabel(i18n(
                "Note: If there are no PDF and no MIDI files, you "
                "probably need to run LilyPond to update those files, "
                "before sending the e-mail."),
                b).setWordWrap(True)
            
        self.fileList = fileList
        self.setMainWidget(b)
        self.resize(450, 300)
        
        basedir = os.path.dirname(updatedFiles.lyfile)
        exts = config("general").readEntry("email_extensions", [".pdf"])
        
        def item(icon, fileName):
            """ Add item to the fileList list widget. """
            directory, name = os.path.split(fileName)
            if directory != basedir:
                name += " ({0})".format(os.path.normpath(directory))
            i = QListWidgetItem(KIcon(icon), name, fileList)
            i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
            i.ext = os.path.splitext(fileName)[1]
            i.url = KUrl.fromPath(fileName).url()
            i.setCheckState(Qt.Checked if i.ext in exts else Qt.Unchecked)

        # insert the files
        for lyfile in lyFiles:
            item("text-x-lilypond", lyfile)
        for pdf in pdfFiles:
            item("application-pdf", pdf)
        for midi in midiFiles:
            item("audio-midi", midi)
Пример #4
0
class RRepositoryBrowser(QDialog):

    def __init__(self, pipe, parent=None):
        QDialog.__init__(self, parent)
        mirror = robjects.r.getOption('repos')
        contrib_url = robjects.r.get('contrib.url', mode='function')
        available_packages = robjects.r.get('available.packages', mode='function')
        self.setWindowTitle("manageR - Install R Packages")
        self.setWindowIcon(QIcon(":icon"))
        p = available_packages()
        self.pipe = pipe
        self.names = QStringList(p.rownames)
        self.parent = parent
        self.packageList = QListWidget(self)
        self.packageList.setAlternatingRowColors(True)
        self.packageList.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.packageList.setSortingEnabled(True)
        self.packageList.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.packageList.setToolTip("Select packages to install")
        self.packageList.setWhatsThis("List of packages available on CRAN")
        self.packageList.insertItems(0, self.names)
        self.dependCheckbox = QCheckBox(self)
        self.dependCheckbox.setText("Install all dependencies")
        self.dependCheckbox.setChecked(True)
        self.closeCheckbox = QCheckBox(self)
        self.closeCheckbox.setText("Close dialog on completion")
        self.closeCheckbox.setChecked(False)
        filterEdit = QLineEdit(self)
        filterLabel = QLabel("Filter packages", self)
        self.outputEdit = QTextEdit(self)
        self.outputEdit.setReadOnly(True)
        self.outputEdit.setVisible(False)
        self.buttonBox = QDialogButtonBox(QDialogButtonBox.Apply|QDialogButtonBox.Close)
        self.buttonBox.addButton("Details >>", QDialogButtonBox.ActionRole)
        vbox = QVBoxLayout(self)
        hbox = QHBoxLayout()
        hbox.addWidget(filterLabel)
        hbox.addWidget(filterEdit)
        vbox.addLayout(hbox)
        vbox.addWidget(self.dependCheckbox)
        vbox.addWidget(self.packageList)
        vbox.addWidget(self.closeCheckbox)
        vbox.addWidget(self.outputEdit)
        vbox.addWidget(self.buttonBox)
        self.started = False
        self.setMinimumSize(80,50)

        self.connect(filterEdit, SIGNAL("textChanged(QString)"), self.filterPackages)
        #self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
        self.connect(self.buttonBox, SIGNAL("clicked(QAbstractButton*)"), self.buttonClicked)

    def buttonClicked(self, button):
        if button.text() == "Details >>":
            self.showDetails()
            button.setText("Details <<")
        elif button.text() == "Details <<":
            self.hideDetails()
            button.setText("Details >>")
        if not self.started:
            if self.buttonBox.standardButton(button) == QDialogButtonBox.Apply:
                self.installPackages()
            else:
                self.reject()

    def showDetails(self):
        self.outputEdit.setVisible(True)

    def hideDetails(self):
        self.outputEdit.setVisible(False)

    def filterPackages(self, text):
        self.packageList.clear()
        self.packageList.insertItems(0, self.names.filter(QRegExp(r"^%s" % text)))
        firstItem = self.packageList.item(0)
        if firstItem.text().startsWith(text):
            self.packageList.setCurrentItem(firstItem)
#        else:
#            self.packageList.clearSelection()

    def currentPackages(self):
        return [unicode(item.text()) for item in self.packageList.selectedItems()]

    def installPackages(self):
        pkgs = self.currentPackages()
        count = len(pkgs)
        if count < 1:
            QMessageBox.warning(self, "manageR - Warning",
            "Please choose at least one valid package")
            return False
        pkgs = QStringList(pkgs).join("','")
        checked = self.dependCheckbox.isChecked()
        if checked: depends = "TRUE"
        else: depends = "FALSE"
        self.pipe.send("install.packages(c('%s'), dependencies=%s, repos=%s)" 
            % (pkgs, depends, robjects.r.getOption("repos")))
        self.started = True
        self.startTimer(30)
        return True

    def timerEvent(self, e):
        if self.started:
            try:
                output = self.pipe.recv()
                if output is None:
                    self.started=False
                    self.killTimer(e.timerId())
                else:
                    self.printOutput(output)
            except EOFError:
                pass
        QApplication.processEvents()

    def printOutput(self, output):
        self.outputEdit.insertPlainText(output)
        self.outputEdit.ensureCursorVisible()