def initUI(self): """Create and fill the `QGridLayout`""" self.setWindowTitle(dwstr.arxDailyTitle) self.grid = QGridLayout() self.grid.setSpacing(1) ##combo boxes self.grid.addWidget(PBLabel(dwstr.arxCat), 0, 0) self.comboCat = PBComboBox( self, [""] + sorted(physBiblioWeb.webSearch["arxiv"].categories.keys())) self.comboCat.currentIndexChanged[str].connect(self.updateCat) self.grid.addWidget(self.comboCat, 0, 1) self.grid.addWidget(PBLabel(dwstr.arxSub), 1, 0) self.comboSub = PBComboBox(self, [""]) self.grid.addWidget(self.comboSub, 1, 1) # OK button self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.grid.addWidget(self.acceptButton, 2, 0) # cancel button self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.grid.addWidget(self.cancelButton, 2, 1) self.setLayout(self.grid) self.setGeometry(100, 100, 400, 100) self.centerWindow()
def createForm(self): """Create the form labels, fields, buttons""" self.setWindowTitle(ewstr.expEdit) i = 0 for k in pBDB.tableCols["experiments"]: val = self.data[k] if k != "idExp" or (k == "idExp" and self.data[k] != ""): i += 1 self.currGrid.addWidget(PBLabel(k), i * 2 - 1, 0) self.currGrid.addWidget( PBLabel("(%s)" % pBDB.descriptions["experiments"][k]), i * 2 - 1, 1 ) self.textValues[k] = QLineEdit(str(val)) if k == "idExp": self.textValues[k].setEnabled(False) self.currGrid.addWidget(self.textValues[k], i * 2, 0, 1, 2) # OK button self.acceptButton = QPushButton(ewstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.currGrid.addWidget(self.acceptButton, i * 2 + 1, 0) # cancel button self.cancelButton = QPushButton(ewstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.currGrid.addWidget(self.cancelButton, i * 2 + 1, 1) self.setGeometry(100, 100, 400, 50 * i) self.centerWindow()
def initUI(self): """Create the main `QTextEdit`, the buttons and the `QProgressBar`""" self.setWindowTitle(self.title) grid = QGridLayout() self.grid = grid grid.setSpacing(1) if self.message is not None and self.message.strip() != "": grid.addWidget(PBLabel("%s" % self.message)) self.textEdit = QTextEdit() grid.addWidget(self.textEdit) if self.setProgressBar: self.progressBar = QProgressBar(self) grid.addWidget(self.progressBar) # cancel button...should learn how to connect it with a thread kill if not self.noStopButton: self.cancelButton = QPushButton(dwstr.stop, self) self.cancelButton.clicked.connect(self.stopExec) self.cancelButton.setAutoDefault(True) grid.addWidget(self.cancelButton) self.closeButton = QPushButton(dwstr.close, self) self.closeButton.setDisabled(True) grid.addWidget(self.closeButton) self.setGeometry(100, 100, 600, 600) self.setLayout(grid) self.centerWindow()
def initUI(self): """Create window layout and buttons, read log file content and print it in the `QPlainTextEdit` """ self.setWindowTitle(self.title) grid = QVBoxLayout() grid.setSpacing(1) grid.addWidget( PBLabel(dwstr.logFileRead % pbConfig.params["logFileName"])) try: with open(pbConfig.params["logFileName"]) as r: text = r.read() except IOError: text = dwstr.clearLogFailRead pBLogger.exception(text) self.textEdit = QPlainTextEdit(text) self.textEdit.setReadOnly(True) grid.addWidget(self.textEdit) self.closeButton = QPushButton(dwstr.close, self) self.closeButton.setAutoDefault(True) self.closeButton.clicked.connect(self.close) grid.addWidget(self.closeButton) self.clearButton = QPushButton(dwstr.clearLogTitle, self) self.clearButton.clicked.connect(self.clearLog) grid.addWidget(self.clearButton) self.setGeometry(100, 100, 800, 800) self.setLayout(grid)
def __init__(self, fig, title=None, parent=None): """Constructor. Defines some properties and buttons Parameters: fig: the figure to be shown title (optional): the window title parent (default None): the parent object, which should have a property lastPaperStats """ super(PaperStatsPlots, self).__init__(parent) self.fig = fig self.canvas = None if title is not None: self.setWindowTitle(title) layout = QGridLayout(self) layout.setSpacing(1) self.setLayout(layout) self.updatePlots() nlines = 1 self.layout().addWidget(PBLabel(igstr.lineMoreInfo), nlines + 1, 0) self.textBox = QLineEdit("") self.textBox.setReadOnly(True) self.layout().addWidget(self.textBox, nlines + 2, 0, 1, 2) self.saveButton = QPushButton(igstr.save, self) self.saveButton.clicked.connect(self.saveAction) self.layout().addWidget(self.saveButton, nlines + 3, 0) self.clButton = QPushButton(igstr.close, self) self.clButton.clicked.connect(self.onClose) self.clButton.setAutoDefault(True) self.layout().addWidget(self.clButton, nlines + 3, 1)
def populateAskExp(self): """If selection of experiments is allowed, add some information on the bibtex/category for which the experiments are requested and a simple message, then create few required empty lists """ if self.askExps: if self.askForBib is not None: try: bibitem = pBDB.bibs.getByBibkey(self.askForBib, saveQuery=False)[0] except IndexError: pBGUILogger.warning( ewstr.entryNotInDb % self.askForBib, exc_info=True, ) return try: if bibitem["inspire"] != "" and bibitem["inspire"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "inspire"), self.askForBib, ) elif bibitem["arxiv"] != "" and bibitem["arxiv"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "arxiv"), self.askForBib, ) elif bibitem["doi"] != "" and bibitem["doi"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "doi"), self.askForBib, ) else: link = self.askForBib bibtext = PBLabel( ewstr.markExpKAT % (link, bibitem["author"], bibitem["title"]) ) except KeyError: bibtext = PBLabel(ewstr.markExpK % (self.askForBib)) self.currLayout.addWidget(bibtext) elif self.askForCat is not None: raise NotImplementedError(ewstr.featureNYI) else: self.currLayout.addWidget(PBLabel(ewstr.selectDesired)) self.marked = [] self.parent().selectedExps = [] return True
def createForm(self): """Prepare the window widgets""" self.setWindowTitle(cwstr.catEdit) i = 0 for k in pBDB.tableCols["categories"]: val = self.data[k] if k != "idCat" or (k == "idCat" and self.data[k] != ""): i += 1 self.currGrid.addWidget( PBLabel(pBDB.descriptions["categories"][k]), i * 2 - 1, 0) self.currGrid.addWidget(PBLabel("(%s)" % k), i * 2 - 1, 1) if k == "parentCat": try: val = self.selectedCats[0] self.textValues[k] = QPushButton( "%s - %s" % (str(val), pBDB.cats.getByID(val)[0]["name"]), self, ) except IndexError: self.textValues[k] = QPushButton( cwstr.selectParent, self) self.textValues[k].clicked.connect(self.onAskParent) else: self.textValues[k] = QLineEdit(str(val)) if k == "idCat": self.textValues[k].setEnabled(False) self.currGrid.addWidget(self.textValues[k], i * 2, 0, 1, 2) # OK button self.acceptButton = QPushButton(cwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.currGrid.addWidget(self.acceptButton, i * 2 + 1, 1) # cancel button self.cancelButton = QPushButton(cwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.currGrid.addWidget(self.cancelButton, i * 2 + 1, 0) self.setGeometry(100, 100, 400, 50 * i) self.centerWindow()
def __init__(self, figs, title=None, parent=None): """Constructor. Parameters: figs: the list of figures title (optional): the window title parent (default None): the parent object, which should have a property `lastAuthorStats` """ super(AuthorStatsPlots, self).__init__(parent) self.figs = figs self.canvas = None if title is not None: self.setWindowTitle(title) layout = QGridLayout(self) layout.setSpacing(1) self.setLayout(layout) self.updatePlots() nlines = int(len(figs) / 2) self.layout().addWidget(PBLabel(igstr.linesMoreInfo), nlines + 1, 0) try: hIndex = "%d" % self.parent().lastAuthorStats["h"] except (TypeError, AttributeError): hIndex = igstr.hIndexE self.hIndex = PBLabel(igstr.hIndexV % hIndex) largerFont = QFont("Times", 15, QFont.Bold) self.hIndex.setFont(largerFont) self.layout().addWidget(self.hIndex, nlines + 1, 1) self.textBox = QLineEdit("") self.textBox.setReadOnly(True) self.layout().addWidget(self.textBox, nlines + 2, 0, 1, 2) self.saveButton = QPushButton(igstr.save, self) self.saveButton.clicked.connect(self.saveAction) self.layout().addWidget(self.saveButton, nlines + 3, 0) self.clButton = QPushButton(igstr.close, self) self.clButton.clicked.connect(self.onClose) self.clButton.setAutoDefault(True) self.layout().addWidget(self.clButton, nlines + 3, 1)
def initUI(self): """Create a `QGridLayout` with the `PBComboBox` and the two selection buttons """ self.setWindowTitle(pmstr.selectProfile) grid = QGridLayout() grid.setSpacing(10) i = 0 if self.message is not None: grid.addWidget(PBLabel("%s" % self.message), 0, 0) i += 1 grid.addWidget(PBLabel(pmstr.availableProfiles), i, 0) self.combo = PBComboBox( self, [ "%s%s%s" % (p, pmstr.splitter, pbConfig.profiles[p]["d"]) for p in pbConfig.profileOrder ], current="%s%s%s" % ( pbConfig.currentProfileName, pmstr.splitter, pbConfig.profiles[pbConfig.currentProfileName]["d"], ), ) grid.addWidget(self.combo, i, 1) i += 1 # Load and Cancel button self.loadButton = QPushButton(bastr.load, self) self.loadButton.clicked.connect(self.onLoad) grid.addWidget(self.loadButton, i, 0) self.cancelButton = QPushButton(bastr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) grid.addWidget(self.cancelButton, i, 1) self.setLayout(grid)
def initUI(self): """Create and fill the `QGridLayout`""" self.setWindowTitle(dwstr.advImpTitle) grid = QGridLayout() self.grid = grid grid.setSpacing(1) ##search grid.addWidget(PBLabel(dwstr.advImpSearch), 0, 0) self.searchStr = QLineEdit("") grid.addWidget(self.searchStr, 0, 1) grid.addWidget(PBLabel(dwstr.advImpMethod), 1, 0) self.comboMethod = PBComboBox( self, ["INSPIRE-HEP", "ADS-NASA", "arXiv", "DOI", "ISBN"], current="INSPIRE-HEP", ) grid.addWidget(self.comboMethod, 1, 1) # OK button self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) grid.addWidget(self.acceptButton, 2, 0) # cancel button self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) grid.addWidget(self.cancelButton, 2, 1) self.setGeometry(100, 100, 400, 100) self.setLayout(grid) self.searchStr.setFocus() self.centerWindow()
def initUI(self): """Create and fill the `QGridLayout`""" self.setWindowTitle(dwstr.advImpResults) self.currLayout.setSpacing(1) self.currLayout.addWidget(PBLabel(dwstr.importSelRes)) headers = ["ID", "title", "author", "eprint", "doi"] for k in self.bibs.keys(): try: self.bibs[k]["bibpars"]["eprint"] = self.bibs[k]["bibpars"][ "arxiv"] except KeyError: pass try: self.bibs[k]["bibpars"]["author"] = self.bibs[k]["bibpars"][ "authors"] except KeyError: pass for f in headers: try: self.bibs[k]["bibpars"][f] = self.bibs[k]["bibpars"][ f].replace("\n", " ") except KeyError: pass self.tableModel = PBImportedTableModel(self, self.bibs, headers) self.addFilterInput(dwstr.filterEntries, gridPos=(1, 0)) self.setProxyStuff(0, Qt.AscendingOrder) self.finalizeTable(gridPos=(2, 0, 1, 2)) i = 3 self.askCats = QCheckBox(dwstr.askCats, self) self.askCats.toggle() self.currLayout.addWidget(self.askCats, i, 0) # OK button self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.currLayout.addWidget(self.acceptButton, i + 1, 0) # cancel button self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.currLayout.addWidget(self.cancelButton, i + 2, 0)
def initUI(self): """Initialize the `PBDDTableWidget`s and their content, plus the buttons and labels """ self.gridlayout = QGridLayout() self.setLayout(self.gridlayout) self.items = [] self.listAll = PBDDTableWidget(self, dwstr.colsAvailable) self.listSel = PBDDTableWidget(self, dwstr.colsSelected) self.gridlayout.addWidget(PBLabel(dwstr.colsDragAndDrop), 0, 0, 1, 2) self.gridlayout.addWidget(self.listAll, 1, 0) self.gridlayout.addWidget(self.listSel, 1, 1) self.allItems = list(pBDB.descriptions["entries"]) + self.moreCols self.selItems = self.previousSelected isel = 0 iall = 0 for col in self.selItems + [ i for i in self.allItems if i not in self.selItems ]: if col in self.excludeCols: continue item = QTableWidgetItem(col) self.items.append(item) if col in self.selItems: self.listSel.insertRow(isel) self.listSel.setItem(isel, 0, item) isel += 1 else: self.listAll.insertRow(iall) self.listAll.setItem(iall, 0, item) iall += 1 self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.gridlayout.addWidget(self.acceptButton, 2, 0) self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.gridlayout.addWidget(self.cancelButton, 2, 1)
def initUI(self): """Initialize the widget content, with the buttons and labels""" self.setWindowTitle(dwstr.arxResTitle) self.currLayout.setSpacing(1) self.currLayout.addWidget(PBLabel(dwstr.importSelRes)) headers = ["eprint", "type", "title", "author", "primaryclass"] self.tableModel = PBImportedTableModel(self, self.bibs, headers + ["abstract"], idName="eprint") self.addFilterInput(dwstr.filterEntries, gridPos=(1, 0)) self.setProxyStuff(0, Qt.AscendingOrder) self.finalizeTable(gridPos=(2, 0, 1, 2)) i = 3 self.askCats = QCheckBox(dwstr.askCats, self) self.askCats.toggle() self.currLayout.addWidget(self.askCats, i, 0) # OK button self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.currLayout.addWidget(self.acceptButton, i + 1, 0) # cancel button self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.currLayout.addWidget(self.cancelButton, i + 2, 0) self.abstractArea = QTextEdit(dwstr.abstract, self) self.currLayout.addWidget(self.abstractArea, i + 3, 0, 4, 2)
def populateAskCat(self): """If selection of categories is allowed, add some information on the bibtex/experiment for which the categories are requested and a simple message, then create few required empty lists """ if self.askCats: if self.askForBib is not None: try: bibitem = pBDB.bibs.getByBibkey(self.askForBib, saveQuery=False)[0] except IndexError: pBGUILogger.warning( cwstr.entryNotInDb % self.askForBib, exc_info=True, ) return try: if bibitem["inspire"] != "" and bibitem[ "inspire"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "inspire"), self.askForBib, ) elif bibitem["arxiv"] != "" and bibitem[ "arxiv"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "arxiv"), self.askForBib, ) elif bibitem["doi"] != "" and bibitem["doi"] is not None: link = "<a href='%s'>%s</a>" % ( pBView.getLink(self.askForBib, "doi"), self.askForBib, ) else: link = self.askForBib bibtext = PBLabel( cwstr.markCatBibKAT % (link, bibitem["author"], bibitem["title"])) except KeyError: bibtext = PBLabel(cwstr.markCatBibK % (self.askForBib)) self.currLayout.addWidget(bibtext) elif self.askForExp is not None: try: expitem = pBDB.exps.getByID(self.askForExp)[0] except IndexError: pBGUILogger.warning( cwstr.expNotInDb % self.askForExp, exc_info=True, ) return try: exptext = PBLabel( cwstr.markCatExpINC % (self.askForExp, expitem["name"], expitem["comments"])) except KeyError: exptext = PBLabel(cwstr.markCatExpI % (self.askForExp)) self.currLayout.addWidget(exptext) else: if self.single: comment = PBLabel(cwstr.selectCat) else: comment = PBLabel(cwstr.selectCats) self.currLayout.addWidget(comment) self.marked = [] self.parent().selectedCats = [] return True
class AuthorStatsPlots(PBDialog): """Class that constructs a window to show the results of `authorStats` """ def __init__(self, figs, title=None, parent=None): """Constructor. Parameters: figs: the list of figures title (optional): the window title parent (default None): the parent object, which should have a property `lastAuthorStats` """ super(AuthorStatsPlots, self).__init__(parent) self.figs = figs self.canvas = None if title is not None: self.setWindowTitle(title) layout = QGridLayout(self) layout.setSpacing(1) self.setLayout(layout) self.updatePlots() nlines = int(len(figs) / 2) self.layout().addWidget(PBLabel(igstr.linesMoreInfo), nlines + 1, 0) try: hIndex = "%d" % self.parent().lastAuthorStats["h"] except (TypeError, AttributeError): hIndex = igstr.hIndexE self.hIndex = PBLabel(igstr.hIndexV % hIndex) largerFont = QFont("Times", 15, QFont.Bold) self.hIndex.setFont(largerFont) self.layout().addWidget(self.hIndex, nlines + 1, 1) self.textBox = QLineEdit("") self.textBox.setReadOnly(True) self.layout().addWidget(self.textBox, nlines + 2, 0, 1, 2) self.saveButton = QPushButton(igstr.save, self) self.saveButton.clicked.connect(self.saveAction) self.layout().addWidget(self.saveButton, nlines + 3, 0) self.clButton = QPushButton(igstr.close, self) self.clButton.clicked.connect(self.onClose) self.clButton.setAutoDefault(True) self.layout().addWidget(self.clButton, nlines + 3, 1) def onClose(self): """Close dialog""" QDialog.close(self) def saveAction(self): """Save the plot into a file, after asking the directory where to save them """ savePath = askDirName(self, igstr.whereSavePlots) if savePath != "": try: self.parent().lastAuthorStats["figs"] = pBStats.plotStats( author=True, save=True, path=savePath) except AttributeError: pBGUILogger.warning("", exc_info=True) else: infoMessage(igstr.plotsSaved) self.saveButton.setDisabled(True) def onPress(self, event): """Print the plot coordinates where a click was performed. To be connected through `mpl_connect`. Used for testing. Parameter: a `matplotlib.backend_bases.Event` """ print(event.xdata, event.ydata) def pickEvent(self, event): """Save into `self.textBox` the coordinates of the clicked object (`Line2D` or `Rectangle`) in the plot. Parameter: a `matplotlib.backend_bases.Event` """ ob = event.artist ix = -1 for i, f in enumerate(self.figs): if f == ob.figure: ix = i if isinstance(ob, Rectangle): self.textBox.setText( igstr.xInYearIs % (figTitles[ix], int(ob.get_x()), int(ob.get_height()))) elif isinstance(ob, Line2D): xdata = ob.get_xdata() ydata = ob.get_ydata() ind = event.ind if ix == 4: formatString = igstr.xInDateIsF else: formatString = igstr.xInDateIsD self.textBox.setText(formatString % ( figTitles[ix], np.take(xdata, ind)[0].strftime(igstr.datefmt), np.take(ydata, ind)[0], )) def updatePlots(self): """Reset the dialog window removing all the previous items and create new canvas for the figures. """ i = 0 while True: item = self.layout().takeAt(i) if item is None: break del item if hasattr(self, "canvas"): del self.canvas self.canvas = [] for fig in self.figs: if fig is not None: self.canvas.append(FigureCanvas(fig)) self.layout().addWidget(self.canvas[-1], int(i / 2), i % 2) self.canvas[-1].mpl_connect("pick_event", self.pickEvent) self.canvas[-1].draw() i += 1
def createForm( self, profilesData=None, profileOrder=None, defaultProfile=None, newLine={ "r": False, "n": "", "db": "", "d": "", "c": "None" }, ): """Create the form for managing profiles, using previous form content if requested. Parameters: profilesData (optional): a dictionary of dictionaries, containing the information of each profile. Each element has the profile name as key, and this structure: "n": profile name "d": description "db": name of the database file "r": True if the profile was marked as default in the form "x": True if the profile was selected for deletion If `None`, use `pbConfig.profiles` profileOrder (optional): the list containing the order of the profiles, by their name in the database. If `None`, use `pbConfig.profileOrder` defaultProfile (optional): the name of the default profile. If `None`, use `pbConfig.defaultProfileName` newLine (optional): the content of the line corresponding to the potentially new profile. It is a dictionary with the following fields: "n": profile name "d": description "db": name of the database file "r": True if the profile was marked as default in the form "c": previous content of "Copy from:" """ if profilesData is None: profilesData = pbConfig.profiles if profileOrder is None: profileOrder = pbConfig.profileOrder if defaultProfile is None: defaultProfile = pbConfig.defaultProfileName self.setWindowTitle(pmstr.editProfile) labels = [ PBLabel(bastr.default), PBLabel(bastr.shortName), PBLabel(bastr.filename), PBLabel(bastr.description), ] for i, e in enumerate(labels): self.currGrid.addWidget(e, 0, i) self.currGrid.addWidget(PBLabel(bastr.order), 0, 4, 1, 2) self.currGrid.addWidget(PBLabel(bastr.deleteQ), 0, 6) self.addButtons(profilesData, profileOrder) for f in ["c", "db", "d", "n", "r"]: if f not in newLine.keys(): pBLogger.warning(pmstr.missingField % (f, sorted(list(newLine)))) newLine[f] = "" i = len(profilesData) + 3 self.currGrid.addWidget(PBLabel(""), i - 2, 0) tempEl = {} self.currGrid.addWidget(PBLabel(pmstr.addNew), i - 1, 0) tempEl["r"] = QRadioButton("") self.def_group.addButton(tempEl["r"]) if newLine["r"]: tempEl["r"].setChecked(True) else: tempEl["r"].setChecked(False) self.currGrid.addWidget(tempEl["r"], i, 0) tempEl["n"] = QLineEdit(newLine["n"]) self.currGrid.addWidget(tempEl["n"], i, 1) tempEl["f"] = QComboBox(self) tempEl["f"].setEditable(True) dbFiles = [ f.split(os.sep)[-1] for f in list(glob.iglob(os.path.join(pbConfig.dataPath, "*.db"))) ] registeredDb = sorted( [a["db"].split(os.sep)[-1] for a in profilesData.values()]) tempEl["f"].addItems([newLine["db"]] + [f for f in dbFiles if f not in registeredDb]) self.currGrid.addWidget(tempEl["f"], i, 2) tempEl["d"] = QLineEdit(newLine["d"]) self.currGrid.addWidget(tempEl["d"], i, 3) self.currGrid.addWidget(PBLabel(pmstr.copyFrom), i, 4, 1, 2) tempEl["c"] = QComboBox(self) copyElements = ["None"] + registeredDb tempEl["c"].addItems(copyElements) tempEl["c"].setCurrentIndex( copyElements.index(newLine["c"]) if newLine["c"] in copyElements else 0) self.currGrid.addWidget(tempEl["c"], i, 6) self.elements.append(tempEl) i += 1 self.currGrid.addWidget(PBLabel(""), i, 0) # OK button self.acceptButton = QPushButton(bastr.ok, self) self.acceptButton.clicked.connect(self.onOk) self.currGrid.addWidget(self.acceptButton, i + 1, 1) # cancel button self.cancelButton = QPushButton(bastr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) self.currGrid.addWidget(self.cancelButton, i + 1, 2)
def initUI(self): """Create and fill the `QGridLayout`""" self.setWindowTitle(dwstr.config) grid = QGridLayout() self.grid = grid grid.setSpacing(1) i = 0 for k in pbConfig.paramOrder: i += 1 val = (pbConfig.params[k] if isinstance(pbConfig.params[k], six.string_types) else str(pbConfig.params[k])) grid.addWidget( PBLabel("%s (<i>%s</i>%s)" % ( configuration_params[k].description, k, (" - " + dwstr.globalSett) if configuration_params[k].isGlobal else "", )), i - 1, 0, 1, 2, ) if k == "bibtexListColumns": self.textValues.append([k, QPushButton(val)]) self.textValues[-1][1].clicked.connect(self.editColumns) elif k == "pdfFolder": self.textValues.append([k, QPushButton(val)]) self.textValues[-1][1].clicked.connect(self.editPDFFolder) elif k == "loggingLevel": try: self.textValues.append([ k, PBComboBox( self, pbConfig.loggingLevels, pbConfig.loggingLevels[int(val)], ), ]) except (IndexError, ValueError): pBGUILogger.warning(dwstr.invalidLoggingLevel) self.textValues.append([ k, PBComboBox( self, pbConfig.loggingLevels, pbConfig.loggingLevels[int( configuration_params["loggingLevel"].default)], ), ]) elif k == "logFileName": self.textValues.append([k, QPushButton(val)]) self.textValues[-1][1].clicked.connect(self.editFile) elif k == "defaultCategories": self.textValues.append([k, QPushButton(val)]) self.textValues[-1][1].clicked.connect(self.editDefCats) elif configuration_params[k].special == "boolean": self.textValues.append([k, PBTrueFalseCombo(self, val)]) else: self.textValues.append([k, QLineEdit(val)]) grid.addWidget(self.textValues[i - 1][1], i - 1, 2, 1, 2) # OK button self.acceptButton = QPushButton(dwstr.ok, self) self.acceptButton.clicked.connect(self.onOk) # width = self.acceptButton.fontMetrics().boundingRect('OK').width() + 7 # self.acceptButton.setMaximumWidth(width) grid.addWidget(self.acceptButton, i, 0) # cancel button self.cancelButton = QPushButton(dwstr.cancel, self) self.cancelButton.clicked.connect(self.onCancel) self.cancelButton.setAutoDefault(True) # width = self.cancelButton.fontMetrics().boundingRect('Cancel').width() + 7 # self.cancelButton.setMaximumWidth(width) grid.addWidget(self.cancelButton, i, 1) self.setGeometry(100, 100, 1000, 30 * i) self.setLayout(grid)