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")
class getFontDialog(QDialog): def __init__(self, parent, currFont): QDialog.__init__(self, parent) #--------------------- self.currFont = currFont if self.currFont.get_file() == None: self.currFontFile = fm.findfont(self.currFont) self.currFontSize = self.currFont.get_size() self.currFontStyle = self.currFont.get_style() self.currFontWeight = self.currFont.get_weight() self.currFont = fm.FontProperties(fname=self.currFontFile, style=self.currFontStyle, weight=self.currFontWeight, size=self.currFontSize) self.currFontFamily = self.currFont.get_name() else: self.currFontFile = self.currFont.get_file() self.currFontSize = self.currFont.get_size() self.currFontStyle = self.currFont.get_style() self.currFontWeight = self.currFont.get_weight() self.currFontFamily = self.currFont.get_name() self.fontsCacheFile = os.path.expanduser("~") +'/.config/pysoundanalyser/fontsCache' if os.path.exists(self.fontsCacheFile): fIn = open(self.fontsCacheFile, 'rb') self.fontsDic = pickle.load(fIn) fIn.close() else: x = fm.FontManager() weight_lookup = { '100': 'ultralight', '200': 'light', '400': 'normal', '500': 'medium', '600': 'demibold', '700': 'bold', '800': 'extra bold', '900': 'black'} fontList = x.ttflist fontNamesAll = [] for i in range(len(x.ttflist)): fontNamesAll.append(x.ttflist[i].name) fontNames = unique(fontNamesAll) self.fontsDic = {} for i in range(len(fontNames)): self.fontsDic[fontNames[i]] = {} self.fontsDic[fontNames[i]]['style'] = [] self.fontsDic[fontNames[i]]['styleAbb'] = [] for font in fontList: style = font.style weight = font.weight self.fontsDic[font.name]['style'].append(style + ':' + str(weight) + ':' + font.fname) weightName = weight_lookup[str(weight)] styleName = style + ' ' + weightName self.fontsDic[font.name]['styleAbb'].append(styleName) f = open(self.fontsCacheFile, 'wb') pickle.dump(self.fontsDic, f) f.close() #--------------------- self.currLocale = self.parent().prm['data']['currentLocale'] self.currLocale.setNumberOptions(self.currLocale.OmitGroupSeparator | self.currLocale.RejectGroupSeparator) grid = QGridLayout() fontNameLabel = QLabel(self.tr('Font Name')) grid.addWidget(fontNameLabel, 0, 0) fontStyleLabel = QLabel(self.tr('Font Style')) grid.addWidget(fontStyleLabel, 0, 1) fontSizeLabel = QLabel(self.tr('Font Size')) grid.addWidget(fontSizeLabel, 0, 2) ind = sorted(self.fontsDic.keys()).index(self.currFontFamily) self.fontListWidget = QListWidget(self) self.fontListWidget.insertItems(0, sorted(self.fontsDic.keys())) self.fontListWidget.setCurrentRow(ind) self.fontListWidget.itemClicked.connect(self.onChangeFontName) grid.addWidget(self.fontListWidget, 1, 0) self.fontStylesWidget = QListWidget(self) self.fontStylesWidget.insertItems(0, self.fontsDic[sorted(self.fontsDic.keys())[ind]]['styleAbb']) indStyle = self.fontsDic[sorted(self.fontsDic.keys())[ind]]['styleAbb'].index(self.currFontStyle + ' ' + self.currFontWeight) self.fontStylesWidget.setCurrentRow(indStyle) grid.addWidget(self.fontStylesWidget, 1, 1) self.fontSizeWidget = QListWidget(self) self.pointSizeList = ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '22', '24', '26', '28', '32', '48', '64', '72', '80', '96', '128'] self.fontSizeWidget.insertItems(0, self.pointSizeList) self.fontSizeWidget.setCurrentRow(self.pointSizeList.index(str(int(self.currFontSize)))) grid.addWidget(self.fontSizeWidget, 1, 2) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok| QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) grid.addWidget(buttonBox, 3, 2) self.setLayout(grid) self.setWindowTitle(self.tr("Choose Font")) def onChangeFontName(self): currFontName = str(self.fontListWidget.currentItem().text()) self.fontStylesWidget.clear() self.fontStylesWidget.insertItems(0, self.fontsDic[currFontName]['styleAbb']) self.fontStylesWidget.setCurrentRow(0)
class FileArgs(QtHelper.EnhancedQDialog, Logger.ClassLogger): """ File arguments dialog """ def __init__(self, dataArgs, parent=None): """ Dialog to fill arguments for the file probe @param dataArgs: @type dataArgs: @param parent: @type parent: """ super(FileArgs, self).__init__(parent) self.dataArgs = dataArgs self.createDialog() self.createConnections() self.loadDefaultData() def createDialog(self): """ Create qt dialog """ mainLayout = QHBoxLayout() dataLayout = QVBoxLayout() self.labelHelp = QLabel("Path of the file to retrieve:") self.lineEdit = QLineEdit() self.listBox = QListWidget() dataLayout.addWidget(self.labelHelp) dataLayout.addWidget(self.lineEdit) dataLayout.addWidget(self.listBox) buttonLayout = QVBoxLayout() self.addButton = QPushButton("Add", self) self.delButton = QPushButton("Remove", self) self.delButton.setEnabled(False) self.editButton = QPushButton("Edit", self) self.editButton.setEnabled(False) self.clearButton = QPushButton("Clear", self) self.okButton = QPushButton("Ok", self) self.cancelButton = QPushButton("Cancel", self) buttonLayout.addWidget(self.addButton) buttonLayout.addWidget(self.delButton) buttonLayout.addWidget(self.editButton) buttonLayout.addWidget(self.clearButton) buttonLayout.addWidget(self.okButton) buttonLayout.addWidget(self.cancelButton) mainLayout.addLayout(dataLayout) mainLayout.addLayout(buttonLayout) self.setLayout(mainLayout) self.setWindowTitle("File Probe > Arguments") def createConnections(self): """ Create qt connections """ self.okButton.clicked.connect(self.accept) self.cancelButton.clicked.connect(self.reject) self.addButton.clicked.connect(self.addItem) self.delButton.clicked.connect(self.delItem) self.editButton.clicked.connect(self.editItem) self.clearButton.clicked.connect(self.clearList) self.listBox.itemClicked.connect(self.onItemSelected) def clearList(self): """ Clear the list """ self.listBox.clear() def onItemSelected(self, itm): """ Called when an item is selected """ self.delButton.setEnabled(True) self.editButton.setEnabled(True) def editItem(self): """ Edit the selected item """ self.delButton.setEnabled(False) self.editButton.setEnabled(False) # retrieve value to put it in the line edit and then remove item model = self.listBox.model() for selectedItem in self.listBox.selectedItems(): qIndex = self.listBox.indexFromItem(selectedItem) if sys.version_info > (3, ): self.lineEdit.setText(model.data(qIndex)) else: self.lineEdit.setText(model.data(qIndex).toString()) model.removeRow(qIndex.row()) def delItem(self): """ Delete the selected item """ self.delButton.setEnabled(False) self.editButton.setEnabled(False) # remove item model = self.listBox.model() for selectedItem in self.listBox.selectedItems(): qIndex = self.listBox.indexFromItem(selectedItem) model.removeRow(qIndex.row()) def addItem(self): """ Add item """ txt = self.lineEdit.text() if txt != '': self.listBox.insertItem(0, txt) self.lineEdit.setText('') def loadDefaultData(self): """ Load the default data """ try: if len(self.dataArgs) == 0: return dat = eval(self.dataArgs) if 'files' in dat: list_files = dat['files'] self.listBox.insertItems(0, list_files) except Exception as e: self.error(e) def getArgs(self): """ Returns arguments Examples: {'files': [ '/etc/init.d/ntpd', '/root/wmi-1.3.14-2.el5.art.x86_64.rpm' ] } """ listFiles = [] model = self.listBox.model() # iterate all items in a QListWidget for index in xrange(self.listBox.count()): itm = self.listBox.item(index) qIndex = self.listBox.indexFromItem(itm) if sys.version_info > (3, ): listFiles.append(model.data(qIndex)) else: listFiles.append(str(model.data(qIndex).toString())) ret = {'files': listFiles} if len(listFiles) == 0: ret = '' return str(ret)
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()