class DialogSettings(QtWidgets.QDialog): """ Settings for the coder name, coder table and to display ids. """ settings = {} def __init__(self, app, parent=None): sys.excepthook = exception_handler self.app = app self.settings = app.settings super(QtWidgets.QDialog, self).__init__(parent) # overrride accept method QtWidgets.QDialog.__init__(self) self.ui = Ui_Dialog_settings() self.ui.setupUi(self) font = 'font: ' + str(self.app.settings['fontsize']) + 'pt ' font += '"' + self.app.settings['font'] + '";' self.setStyleSheet(font) self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) new_font = QtGui.QFont(self.settings['font'], self.settings['fontsize'], QtGui.QFont.Normal) self.ui.lineEdit_coderName.setText(self.app.settings['codername']) self.ui.fontComboBox.setCurrentFont(new_font) # get coder names from all tables # Note: does not appear to require a distinct clause sql = "select owner from code_image union select owner from code_text union select owner from code_av " sql += " union select owner from cases union select owner from journal union select owner from attribute " sql += "union select owner from source union select owner from annotation union select owner from code_name " sql += "union select owner from code_cat" coders = [""] if self.app.conn is not None: cur = self.app.conn.cursor() cur.execute(sql) results = cur.fetchall() for row in results: if row[0] != "": coders.append(row[0]) self.ui.comboBox_coders.addItems(coders) languages = [ "Deutsch de", "English en", "Ελληνικά el", "Español es", "Français fr", "Italiano it", "日本 jp" ] self.ui.comboBox_language.addItems(languages) for index, lang in enumerate(languages): if lang[-2:] == self.settings['language']: self.ui.comboBox_language.setCurrentIndex(index) timestampformats = [ "[mm.ss]", "[mm:ss]", "[hh.mm.ss]", "[hh:mm:ss]", "{hh:mm:ss}", "#hh:mm:ss.sss#" ] self.ui.comboBox_timestamp.addItems(timestampformats) for index, ts in enumerate(timestampformats): if ts == self.settings['timestampformat']: self.ui.comboBox_timestamp.setCurrentIndex(index) speakernameformats = ["[]", "{}"] self.ui.comboBox_speaker.addItems(speakernameformats) for index, snf in enumerate(speakernameformats): if snf == self.settings['speakernameformat']: self.ui.comboBox_speaker.setCurrentIndex(index) self.ui.spinBox.setValue(self.settings['fontsize']) self.ui.spinBox_treefontsize.setValue(self.settings['treefontsize']) self.ui.lineEdit_coderName.setText(self.settings['codername']) self.ui.comboBox_coders.currentIndexChanged.connect( self.comboBox_coder_changed) self.ui.checkBox_auto_backup.stateChanged.connect( self.backup_state_changed) if self.settings['showids'] == 'True': self.ui.checkBox.setChecked(True) else: self.ui.checkBox.setChecked(False) if self.settings['backup_on_open'] == 'True': self.ui.checkBox_auto_backup.setChecked(True) else: self.ui.checkBox_auto_backup.setChecked(False) if self.settings['backup_av_files'] == 'True': self.ui.checkBox_backup_AV_files.setChecked(True) else: self.ui.checkBox_backup_AV_files.setChecked(False) if self.settings['directory'] == "": self.settings['directory'] = os.path.expanduser("~") self.ui.label_directory.setText(self.settings['directory']) self.ui.pushButton_choose_directory.clicked.connect( self.choose_directory) def backup_state_changed(self): """ Enable and disable av backup checkbox. Only enable when checkBox_auto_backup is checked. """ if self.ui.checkBox_auto_backup.isChecked(): self.ui.checkBox_backup_AV_files.setEnabled(True) else: self.ui.checkBox_backup_AV_files.setEnabled(False) def comboBox_coder_changed(self): """ Set the coder name to the current selection. """ self.ui.lineEdit_coderName.setText( self.ui.comboBox_coders.currentText()) def choose_directory(self): """ Choose default project directory. """ directory = QtWidgets.QFileDialog.getExistingDirectory( self, _('Choose project directory'), self.settings['directory']) if directory == "": return self.ui.label_directory.setText(directory) def accept(self): self.settings['codername'] = self.ui.lineEdit_coderName.text() if self.settings['codername'] == "": self.settings['codername'] = "default" self.settings['font'] = self.ui.fontComboBox.currentText() self.settings['fontsize'] = self.ui.spinBox.value() self.settings['treefontsize'] = self.ui.spinBox_treefontsize.value() self.settings['directory'] = self.ui.label_directory.text() if self.ui.checkBox.isChecked(): self.settings['showids'] = 'True' else: self.settings['showids'] = 'False' self.settings['language'] = self.ui.comboBox_language.currentText( )[-2:] self.settings[ 'timestampformat'] = self.ui.comboBox_timestamp.currentText() self.settings[ 'speakernameformat'] = self.ui.comboBox_speaker.currentText() if self.ui.checkBox_auto_backup.isChecked(): self.settings['backup_on_open'] = 'True' else: self.settings['backup_on_open'] = 'False' if self.ui.checkBox_backup_AV_files.isChecked(): self.settings['backup_av_files'] = 'True' else: self.settings['backup_av_files'] = 'False' self.save_settings() self.close() def save_settings(self): """ Save settings to text file in user's home directory. Each setting has a variable identifier then a colon followed by the value. """ self.app.write_config_ini(self.settings)
class DialogSettings(QtWidgets.QDialog): ''' Settings for the coder name, coder table and to display ids. ''' settings = {} def __init__(self, app, parent=None): sys.excepthook = exception_handler self.app = app self.settings = app.settings super(QtWidgets.QDialog, self).__init__(parent) # overrride accept method QtWidgets.QDialog.__init__(self) self.ui = Ui_Dialog_settings() self.ui.setupUi(self) new_font = QtGui.QFont(self.settings['font'], self.settings['fontsize'], QtGui.QFont.Normal) self.setFont(new_font) self.ui.fontComboBox.setCurrentFont(new_font) # get coder names from code_text, images and av # Note: does no appear to require a distinct clause sql = "select owner from code_image union select owner from code_text union select owner from code_av" coders = [""] if self.app.conn is not None: cur = self.app.conn.cursor() cur.execute(sql) results = cur.fetchall() for row in results: coders.append(row[0]) self.ui.comboBox_coders.addItems(coders) languages = ["Deutsch de", "English en", "Français fr", "Español es"] self.ui.comboBox_language.addItems(languages) for index, lang in enumerate(languages): if lang[-2:] == self.settings['language']: self.ui.comboBox_language.setCurrentIndex(index) self.ui.spinBox.setValue(self.settings['fontsize']) self.ui.spinBox_treefontsize.setValue(self.settings['treefontsize']) self.ui.lineEdit_coderName.setText(self.settings['codername']) self.ui.comboBox_coders.currentIndexChanged.connect( self.comboBox_coder_changed) self.ui.checkBox_auto_backup.stateChanged.connect( self.backup_state_changed) if self.settings['showids'] == 'True': self.ui.checkBox.setChecked(True) else: self.ui.checkBox.setChecked(False) if self.settings['backup_on_open'] == 'True': self.ui.checkBox_auto_backup.setChecked(True) else: self.ui.checkBox_auto_backup.setChecked(False) if self.settings['backup_av_files'] == 'True': self.ui.checkBox_backup_AV_files.setChecked(True) else: self.ui.checkBox_backup_AV_files.setChecked(False) if self.settings['directory'] == "": self.settings['directory'] = os.path.expanduser("~") self.ui.label_directory.setText(self.settings['directory']) self.ui.pushButton_choose_directory.clicked.connect( self.choose_directory) def backup_state_changed(self): """ Enable and disable av backup checkbox. Only enable when checkBox_auto_backup is checked. """ if self.ui.checkBox_auto_backup.isChecked(): self.ui.checkBox_backup_AV_files.setEnabled(True) else: self.ui.checkBox_backup_AV_files.setEnabled(False) def comboBox_coder_changed(self): ''' Set the coder name to the current selection. ''' self.ui.lineEdit_coderName.setText( self.ui.comboBox_coders.currentText()) def choose_directory(self): ''' Choose default project directory. ''' directory = QtWidgets.QFileDialog.getExistingDirectory( self, _('Choose project directory'), self.settings['directory']) if directory == "": return self.ui.label_directory.setText(directory) def accept(self): self.settings['codername'] = self.ui.lineEdit_coderName.text() if self.settings['codername'] == "": self.settings['codername'] = "default" self.settings['font'] = self.ui.fontComboBox.currentText() self.settings['fontsize'] = self.ui.spinBox.value() self.settings['treefontsize'] = self.ui.spinBox_treefontsize.value() self.settings['directory'] = self.ui.label_directory.text() if self.ui.checkBox.isChecked(): self.settings['showids'] = 'True' else: self.settings['showids'] = 'False' self.settings['language'] = self.ui.comboBox_language.currentText( )[-2:] if self.ui.checkBox_auto_backup.isChecked(): self.settings['backup_on_open'] = 'True' else: self.settings['backup_on_open'] = 'False' if self.ui.checkBox_backup_AV_files.isChecked(): self.settings['backup_av_files'] = 'True' else: self.settings['backup_av_files'] = 'False' self.save_settings() self.close() def save_settings(self): ''' Save settings to text file in user's home directory. Each setting has a variable identifier then a colon followed by the value. ''' self.app.write_config_ini(self.settings)
class DialogSettings(QtWidgets.QDialog): ''' Settings for the coder name, coder table and to display ids. ''' settings = {} def __init__(self, settings, parent=None): sys.excepthook = exception_handler self.settings = settings super(QtWidgets.QDialog, self).__init__(parent) # overrride accept method QtWidgets.QDialog.__init__(self) self.ui = Ui_Dialog_settings() self.ui.setupUi(self) new_font = QtGui.QFont(settings['font'], settings['fontsize'], QtGui.QFont.Normal) self.setFont(new_font) self.ui.fontComboBox.setCurrentFont(new_font) # get coder names from code_text (and from other? may be images?) sql = "select distinct owner from code_text" coders = [""] if settings['conn'] is not None: cur = self.settings['conn'].cursor() cur.execute(sql) results = cur.fetchall() for row in results: coders.append(row[0]) self.ui.comboBox_coders.addItems(coders) self.ui.spinBox.setValue(self.settings['fontsize']) self.ui.spinBox_treefontsize.setValue(self.settings['treefontsize']) self.ui.lineEdit_coderName.setText(self.settings['codername']) self.ui.comboBox_coders.currentIndexChanged.connect( self.comboBox_coder_changed) if self.settings['showIDs'] is True: self.ui.checkBox.setChecked(True) else: self.ui.checkBox.setChecked(False) if self.settings['directory'] == "": self.settings['directory'] = os.path.expanduser("~") self.ui.label_directory.setText(self.settings['directory']) self.ui.pushButton_choose_directory.clicked.connect( self.choose_directory) def comboBox_coder_changed(self): ''' Set the coder name to the current selection. ''' logger.info("coder changed to: " + self.ui.comboBox_coders.currentText()) self.ui.lineEdit_coderName.setText( self.ui.comboBox_coders.currentText()) def choose_directory(self): ''' Choose default project directory. ''' directory = QtWidgets.QFileDialog.getExistingDirectory( self, 'Choose project directory', self.settings['directory']) if directory == "": return self.ui.label_directory.setText(directory) def accept(self): self.settings['codername'] = self.ui.lineEdit_coderName.text() if self.settings['codername'] == "": self.settings['codername'] = "default" self.settings['font'] = self.ui.fontComboBox.currentText() self.settings['fontsize'] = self.ui.spinBox.value() self.settings['treefontsize'] = self.ui.spinBox_treefontsize.value() self.settings['directory'] = self.ui.label_directory.text() if self.ui.checkBox.isChecked(): self.settings['showIDs'] = True else: self.settings['showIDs'] = False self.save_settings() self.close() def save_settings(self): ''' Save settings to text file in user's home directory. ''' txt = self.settings['codername'] + "\n" txt += self.settings['font'] + "\n" txt += str(self.settings['fontsize']) + "\n" txt += str(self.settings['treefontsize']) + "\n" txt += self.settings['directory'] + "\n" txt += str(self.settings['showIDs']) with open(home + '/QualCoder_settings.txt', 'w') as f: f.write(txt)
class DialogSettings(QtWidgets.QDialog): ''' Settings for the coder name, coder table and to display ids. ''' settings = {} def __init__(self, settings, parent=None): sys.excepthook = exception_handler self.settings = settings super(QtWidgets.QDialog, self).__init__(parent) # overrride accept method QtWidgets.QDialog.__init__(self) self.ui = Ui_Dialog_settings() self.ui.setupUi(self) new_font = QtGui.QFont(settings['font'], settings['fontsize'], QtGui.QFont.Normal) self.setFont(new_font) self.ui.fontComboBox.setCurrentFont(new_font) # get coder names from code_text, images and av # Note: does no appear to require a distinct clause sql = "select owner from code_image union select owner from code_text union select owner from code_av" coders = [""] if settings['conn'] is not None: cur = self.settings['conn'].cursor() cur.execute(sql) results = cur.fetchall() for row in results: coders.append(row[0]) self.ui.comboBox_coders.addItems(coders) languages = ["Deutsch de", "English en", "Français fr"] self.ui.comboBox_language.addItems(languages) for index, lang in enumerate(languages): if lang[-2:] == self.settings['language']: self.ui.comboBox_language.setCurrentIndex(index) self.ui.spinBox.setValue(self.settings['fontsize']) self.ui.spinBox_treefontsize.setValue(self.settings['treefontsize']) self.ui.lineEdit_coderName.setText(self.settings['codername']) self.ui.comboBox_coders.currentIndexChanged.connect( self.comboBox_coder_changed) if self.settings['showIDs'] is True: self.ui.checkBox.setChecked(True) else: self.ui.checkBox.setChecked(False) if self.settings['directory'] == "": self.settings['directory'] = os.path.expanduser("~") self.ui.label_directory.setText(self.settings['directory']) self.ui.pushButton_choose_directory.clicked.connect( self.choose_directory) def comboBox_coder_changed(self): ''' Set the coder name to the current selection. ''' self.ui.lineEdit_coderName.setText( self.ui.comboBox_coders.currentText()) def choose_directory(self): ''' Choose default project directory. ''' directory = QtWidgets.QFileDialog.getExistingDirectory( self, _('Choose project directory'), self.settings['directory']) if directory == "": return self.ui.label_directory.setText(directory) def accept(self): self.settings['codername'] = self.ui.lineEdit_coderName.text() if self.settings['codername'] == "": self.settings['codername'] = "default" self.settings['font'] = self.ui.fontComboBox.currentText() self.settings['fontsize'] = self.ui.spinBox.value() self.settings['treefontsize'] = self.ui.spinBox_treefontsize.value() self.settings['directory'] = self.ui.label_directory.text() if self.ui.checkBox.isChecked(): self.settings['showIDs'] = True else: self.settings['showIDs'] = False self.settings['language'] = self.ui.comboBox_language.currentText( )[-2:] self.save_settings() self.close() def save_settings(self): ''' Save settings to text file in user's home directory. ''' txt = self.settings['codername'] + "\n" txt += self.settings['font'] + "\n" txt += str(self.settings['fontsize']) + "\n" txt += str(self.settings['treefontsize']) + "\n" txt += self.settings['directory'] + "\n" txt += str(self.settings['showIDs']) + "\n" txt += self.settings['language'] with open(home + '/.qualcoder/QualCoder_settings.txt', 'w') as f: f.write(txt)