def __init__(self, parent): QDialog.__init__(self, parent) self.parent = parent self.initConfigOptions() self.layout = QVBoxLayout(self) path = getSettingsFilePath() pathLabel = QLabel( self.tr('Using configuration file at:') + ' <a href="%(path)s">%(path)s</a>' % {'path': path}, self) pathLabel.linkActivated.connect(self.openLink) self.layout.addWidget(pathLabel) self.tabWidget = QTabWidget(self) self.layout.addWidget(self.tabWidget) buttonBox = QDialogButtonBox(self) buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Apply | QDialogButtonBox.StandardButton.Cancel) buttonBox.accepted.connect(self.acceptSettings) buttonBox.button( QDialogButtonBox.StandardButton.Apply).clicked.connect( self.saveSettings) buttonBox.rejected.connect(self.close) self.initWidgets() self.configurators['rightMargin'].valueChanged.connect( self.handleRightMarginSet) self.configurators['rightMarginWrap'].stateChanged.connect( self.handleRightMarginWrapSet) self.layout.addWidget(buttonBox)
def __init__(self, parent): QDialog.__init__(self, parent) self.parent = parent self.initConfigOptions() self.layout = QVBoxLayout(self) path = getSettingsFilePath() pathLabel = QLabel(self.tr('Using configuration file at:') + ' <a href="%(path)s">%(path)s</a>' % {'path': path}, self) pathLabel.linkActivated.connect(self.openLink) self.layout.addWidget(pathLabel) self.tabWidget = QTabWidget(self) self.layout.addWidget(self.tabWidget) buttonBox = QDialogButtonBox(self) buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.saveSettings) buttonBox.rejected.connect(self.close) self.initWidgets() self.configurators['rightMargin'].valueChanged.connect(self.handleRightMarginSet) self.configurators['rightMarginWrap'].stateChanged.connect(self.handleRightMarginWrapSet) self.layout.addWidget(buttonBox)
def initWidgets(self): self.configurators = {} for index, option in enumerate(self.options): displayname, name = option[:2] fileselector = option[2] if len(option) > 2 else False if name is None: header = QLabel('<h3>%s</h3>' % displayname, self) self.layout.addWidget(header, index, 0, 1, 2, Qt.AlignHCenter) continue if displayname: label = QLabel(displayname + ':', self) if name == 'markdownExtensions': if displayname: url = QUrl( 'https://github.com/retext-project/retext/wiki/Markdown-extensions' ) helpButton = QPushButton(self.tr('Help'), self) helpButton.clicked.connect( lambda: QDesktopServices.openUrl(url)) self.layout.addWidget(label, index, 0) self.layout.addWidget(helpButton, index, 1) continue try: extsFile = open(MKD_EXTS_FILE) value = extsFile.read().rstrip().replace( extsFile.newlines, ', ') extsFile.close() except Exception: value = '' self.configurators[name] = QLineEdit(self) self.configurators[name].setText(value) self.layout.addWidget(self.configurators[name], index, 0, 1, 2) continue value = getattr(globalSettings, name) if isinstance(value, bool): self.configurators[name] = QCheckBox(self) self.configurators[name].setChecked(value) if name == 'rightMarginWrap' and (globalSettings.rightMargin == 0): self.configurators[name].setEnabled(False) elif isinstance(value, int): self.configurators[name] = QSpinBox(self) if name == 'tabWidth': self.configurators[name].setRange(1, 10) else: self.configurators[name].setMaximum(200) self.configurators[name].setValue(value) elif isinstance(value, str) and fileselector: self.configurators[name] = FileSelectButton(self, value) elif isinstance(value, str): self.configurators[name] = QLineEdit(self) self.configurators[name].setText(value) self.layout.addWidget(label, index, 0) self.layout.addWidget(self.configurators[name], index, 1, Qt.AlignRight) # Display the current config file label = QLabel(self.tr('Using configuration file at:'), self) self.layout.addWidget(label, len(self.options), 0) path = getSettingsFilePath() pathLabel = QLabel('<a href="file://' + path + '">' + path + '</a>', self) pathLabel.linkActivated.connect(self.openLink) self.layout.addWidget(pathLabel, len(self.options), 1)