def _initialize_file_type_settings(self, layout): '''Initialize file creation/sending type settings''' separator_b = QFrame() separator_b.setFrameStyle(QFrame.HLine) separator_b.setFrameShadow(QFrame.Sunken) layout.addWidget(separator_b) book_types_to_create = QGroupBox() book_types_to_create.setTitle('Book types to create files for:') book_types_to_create.setLayout(QHBoxLayout(book_types_to_create)) self._settings['mobi'] = QCheckBox('MOBI') self._settings['mobi'].setChecked('mobi' in __prefs__['formats']) book_types_to_create.layout().addWidget(self._settings['mobi']) self._settings['azw3'] = QCheckBox('AZW3') self._settings['azw3'].setChecked('azw3' in __prefs__['formats']) book_types_to_create.layout().addWidget(self._settings['azw3']) layout.addWidget(book_types_to_create) file_preference_layout = QGroupBox() file_preference_layout.setTitle('If device has both (mobi and azw3) formats, prefer:') file_preference_layout.setLayout(QHBoxLayout(file_preference_layout)) file_preference_group = QButtonGroup() self._settings['file_preference_mobi'] = QRadioButton('MOBI') self._settings['file_preference_mobi'].setChecked(__prefs__['file_preference'] == 'mobi') file_preference_group.addButton(self._settings['file_preference_mobi']) file_preference_layout.layout().addWidget(self._settings['file_preference_mobi']) self._settings['file_preference_azw3'] = QRadioButton('AZW3') self._settings['file_preference_azw3'].setChecked(__prefs__['file_preference'] == 'azw3') file_preference_group.addButton(self._settings['file_preference_azw3']) file_preference_layout.layout().addWidget(self._settings['file_preference_azw3']) layout.addWidget(file_preference_layout)
def __init__(self, dicTitle, dicList): super(LLT_MC, self).__init__() self.w = QWidget() self.setCentralWidget(self.w) self.title = dicTitle self.wordList = dicList self.setWindowTitle("Multiple Choice") self.setGeometry(0, 0, 300, 400) self.currentWordS = random.sample(self.wordList, 3) self.currentQWord = self.currentWordS[0][0] self.currentAWord = self.currentWordS[0][1] self.topLabel = QLabel("Multiple Choice: " + str(dicTitle)) self.wordLabel = QLabel() self.wordLabel.setFont(QFont('Times New Roman', 16)) self.wordLabel.setAlignment(Qt.AlignCenter) self.resultLabel = QLabel() self.resultLabel.setAlignment(Qt.AlignCenter) self.aRad = QRadioButton() self.bRad = QRadioButton() self.cRad = QRadioButton() self.group = QButtonGroup() self.group.addButton(self.aRad) self.group.addButton(self.bRad) self.group.addButton(self.cRad) self.checkBut = QPushButton("Check") self.checkBut.setMinimumWidth(100) self.checkBut.setMinimumHeight(70) self.checkBut.clicked.connect(self.check) self.nextBut = QPushButton("Next Word") self.nextBut.setMinimumWidth(100) self.nextBut.setMinimumHeight(70) self.nextBut.clicked.connect(self.next) self.exitBut = QPushButton("Exit") self.exitBut.setMinimumWidth(130) self.exitBut.setMinimumHeight(70) self.exitBut.clicked.connect(self.exit) self.hbox = QHBoxLayout() self.hbox.addWidget(self.checkBut) self.hbox.addWidget(self.nextBut) self.vbox = QVBoxLayout() self.vbox.addWidget(self.topLabel) self.vbox.addWidget(self.wordLabel) self.vbox.addWidget(self.aRad) self.vbox.addWidget(self.bRad) self.vbox.addWidget(self.cRad) self.vbox.addWidget(self.resultLabel) self.vbox.addLayout(self.hbox) self.vbox.addWidget(self.exitBut) self.w.setLayout(self.vbox) self.setWord()
def __init__(self, *args, **kwargs): super().__init__(*args) self.allModeGroup = QButtonGroup(self) self.npkModeGroup = QButtonGroup(self) if "mainWin" in kwargs.keys(): self.mainWin = kwargs["mainWin"] self.setObjectName("settingWin") self.setUi() self.npkModeBox() self.allExtractBox() self.checkBox() self.saveDirSelectBtn() self.img2DirBtn() self.portBtn = self.testPortBtn() self.inputPort() self.hide()
def _addRaidoInGroup(self): self.__ui.group_title = QButtonGroup() # 创建按钮组 self.__ui.group_title.addButton(self.__ui.rbTerminal, 0) self.__ui.group_title.addButton(self.__ui.rbFiles, 1) self.__ui.group_title.addButton(self.__ui.rbCatalog, 2) self.__ui.group_title.addButton(self.__ui.rbSourceMake, 3) self.__ui.group_title.addButton(self.__ui.rbSet, 4) self.__ui.group_title.addButton(self.__ui.rbAdmin, 5) # 设置组内按钮互斥 self.__ui.group_title.setExclusive(True)
def adjust_sbutile(self): btn_group = QButtonGroup(self) btn_group.addButton(self.random_search_cb) btn_group.addButton(self.grid_search_cb) self.setStyleSheet("background:None;") self.load_model_cb.toggled['bool'].connect( self.load_model_cb_toggled_handler) self.open_model_btn.clicked.connect( self.open_model_btn_clicked_handler) self.save_file_cb.toggled['bool'].connect( self.save_file_cb_toggled_handler) self.save_file_btn.clicked.connect(self.save_file_btn_clicked_handler) self.save_model_cb.toggled['bool'].connect( self.save_model_cb_toggled_handler) self.save_model_btn.clicked.connect( self.save_model_btn_clicked_handler) self.apply_btn.clicked.connect(self.apply_handler) self.finish_btn.clicked.connect(self.finish_handler) self.linear_kernel_cb.toggled['bool'].connect(self.compat_kernels) self.poly_kernel_cb.toggled['bool'].connect(self.compat_kernels) self.rbf_kernel_cb.toggled['bool'].connect(self.compat_kernels) self.sigmoid_kernel_cb.toggled['bool'].connect(self.compat_kernels) self.rbf_kernel_cb.setChecked(False) self.rbf_kernel_cb.setChecked(True) self.balanced_class_weight_cb.setChecked(True)
def adjust_sbutile(self): self.setStyleSheet("background:None;") btn_group = QButtonGroup(self) btn_group.addButton(self.random_search_cb) btn_group.addButton(self.grid_search_cb) validator01 = Validator01() self.feature_importance_le.setValidator(validator01)
def _initialize_file_type_settings(self, layout): '''Initialize file creation/sending type settings''' separator_b = QFrame() separator_b.setFrameStyle(QFrame.HLine) separator_b.setFrameShadow(QFrame.Sunken) layout.addWidget(separator_b) book_types_to_create = QGroupBox() book_types_to_create.setTitle('Book types to create files for:') book_types_to_create.setLayout(QHBoxLayout(book_types_to_create)) self._settings['mobi'] = QCheckBox('MOBI') self._settings['mobi'].setChecked('mobi' in __prefs__['formats']) book_types_to_create.layout().addWidget(self._settings['mobi']) self._settings['azw3'] = QCheckBox('AZW3') self._settings['azw3'].setChecked('azw3' in __prefs__['formats']) book_types_to_create.layout().addWidget(self._settings['azw3']) layout.addWidget(book_types_to_create) file_preference_layout = QGroupBox() file_preference_layout.setTitle( 'If device has both (mobi and azw3) formats, prefer:') file_preference_layout.setLayout(QHBoxLayout(file_preference_layout)) file_preference_group = QButtonGroup() self._settings['file_preference_mobi'] = QRadioButton('MOBI') self._settings['file_preference_mobi'].setChecked( __prefs__['file_preference'] == 'mobi') file_preference_group.addButton(self._settings['file_preference_mobi']) file_preference_layout.layout().addWidget( self._settings['file_preference_mobi']) self._settings['file_preference_azw3'] = QRadioButton('AZW3') self._settings['file_preference_azw3'].setChecked( __prefs__['file_preference'] == 'azw3') file_preference_group.addButton(self._settings['file_preference_azw3']) file_preference_layout.layout().addWidget( self._settings['file_preference_azw3']) layout.addWidget(file_preference_layout)
def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) fileButton = QPushButton('Select a DataSet', self) fileButton.move(60, 30) fileButton.clicked.connect(self.getfile) self.applyButton = QPushButton('Apply Tests', self) self.applyButton.move(215, 30) self.applyButton.clicked.connect(self.newWindow) self.applyButton.setEnabled(False) self.displayText = QLabel("", self) self.displayText.move(375, 0) self.displayText.setFixedHeight(150) self.displayText.setFixedWidth(250) self.displayText.setAlignment(Qt.AlignTop) self.displayText.setAlignment(Qt.AlignLeft) self.displayText.setWordWrap(True) self.displayText.setAutoFillBackground(True) self.displayText.setStyleSheet( "QLabel { background-color: rgba(169,169,169); }") self.displayResult = QLabel("", self) self.displayResult.move(375, 155) self.displayResult.setFixedHeight(200) self.displayResult.setFixedWidth(250) self.displayResult.setAlignment(Qt.AlignTop) self.displayResult.setAlignment(Qt.AlignLeft) self.displayResult.setWordWrap(True) self.displayResult.setAutoFillBackground(True) self.displayResult.setStyleSheet( "QLabel { background-color: rgba(169,169,169); }") paraNonPara = QButtonGroup(self) anovaPara = QButtonGroup(self) pairUnPair = QButtonGroup(self) studentAnova = QButtonGroup(self) self.anova = QRadioButton('Anova', self) self.anova.move(250, 90) self.anova.setChecked(False) self.student = QRadioButton('Student-T', self) self.student.move(60, 90) self.student.setChecked(False) studentAnova.addButton(self.anova) studentAnova.addButton(self.student) self.stuPara = QRadioButton('Parametric', self) self.stuPara.move(10, 120) self.stuPara.setChecked(False) self.stuNonpara = QRadioButton('non-Parametric', self) self.stuNonpara.move(10, 150) self.stuNonpara.setChecked(False) paraNonPara.addButton(self.stuPara) paraNonPara.addButton(self.stuNonpara) self.anoPara = QRadioButton('Parametric', self) self.anoPara.move(250, 120) self.anoPara.setChecked(False) self.anoNonpara = QRadioButton('non-Parametric', self) self.anoNonpara.move(250, 150) self.anoNonpara.setChecked(False) anovaPara.addButton(self.anoPara) anovaPara.addButton(self.anoNonpara) self.pair = QRadioButton('Paired', self) self.pair.move(130, 120) self.pair.setChecked(False) self.unPair = QRadioButton('Unpaired', self) self.unPair.move(130, 150) self.unPair.setChecked(False) pairUnPair.addButton(self.pair) pairUnPair.addButton(self.unPair) self.pair.setEnabled(False) self.unPair.setEnabled(False) self.anoPara.setEnabled(False) self.anoNonpara.setEnabled(False) self.stuPara.setEnabled(False) self.stuNonpara.setEnabled(False) self.anova.setEnabled(False) self.student.setEnabled(False)
def setup_ui(self): self.quote_for_trad_target = _("Update quotes: "",'' -> 「」,『』") self.quote_for_simp_target = _("Update quotes: 「」,『』 -> "",''") # Create layout for entire dialog layout = QVBoxLayout(self) self.setLayout(layout) #Create a scroll area for the top part of the dialog self.scrollArea = QScrollArea(self) self.scrollArea.setWidgetResizable(True) # Create widget for all the contents of the dialog except the OK and Cancel buttons self.scrollContentWidget = QWidget(self.scrollArea) self.scrollArea.setWidget(self.scrollContentWidget) widgetLayout = QVBoxLayout(self.scrollContentWidget) # Add scrollArea to dialog layout.addWidget(self.scrollArea) self.operation_group_box = QGroupBox(_('Conversion Direction')) widgetLayout.addWidget(self.operation_group_box) operation_group_box_layout = QVBoxLayout() self.operation_group_box.setLayout(operation_group_box_layout) operation_group = QButtonGroup(self) self.no_conversion_button = QRadioButton(_('No Conversion')) operation_group.addButton(self.no_conversion_button) self.trad_to_simp_button = QRadioButton(_('Traditional to Simplified')) operation_group.addButton(self.trad_to_simp_button) self.simp_to_trad_button = QRadioButton(_('Simplified to Traditional')) operation_group.addButton(self.simp_to_trad_button) self.trad_to_trad_button = QRadioButton( _('Traditional to Traditional')) operation_group.addButton(self.trad_to_trad_button) operation_group_box_layout.addWidget(self.no_conversion_button) operation_group_box_layout.addWidget(self.trad_to_simp_button) operation_group_box_layout.addWidget(self.simp_to_trad_button) operation_group_box_layout.addWidget(self.trad_to_trad_button) self.no_conversion_button.toggled.connect(self.update_gui) self.trad_to_simp_button.toggled.connect(self.update_gui) self.simp_to_trad_button.toggled.connect(self.update_gui) self.trad_to_trad_button.toggled.connect(self.update_gui) self.style_group_box = QGroupBox(_('Language Styles')) widgetLayout.addWidget(self.style_group_box) style_group_box_layout = QVBoxLayout() self.style_group_box.setLayout(style_group_box_layout) input_layout = QHBoxLayout() style_group_box_layout.addLayout(input_layout) self.input_region_label = QLabel(_('Input:')) input_layout.addWidget(self.input_region_label) self.input_combo = QComboBox() input_layout.addWidget(self.input_combo) self.input_combo.addItems([_('Mainland'), _('Hong Kong'), _('Taiwan')]) self.input_combo.setToolTip(_('Select the origin region of the input')) self.input_combo.currentIndexChanged.connect(self.update_gui) output_layout = QHBoxLayout() style_group_box_layout.addLayout(output_layout) self.output_region_label = QLabel(_('Output:')) output_layout.addWidget(self.output_region_label) self.output_combo = QComboBox() output_layout.addWidget(self.output_combo) self.output_combo.addItems( [_('Mainland'), _('Hong Kong'), _('Taiwan')]) self.output_combo.setToolTip( _('Select the desired region of the output')) self.output_combo.currentIndexChanged.connect(self.update_gui) self.use_target_phrases = QCheckBox( _('Use output target phrases if possible')) self.use_target_phrases.setToolTip( _('Check to allow region specific word replacements if available')) style_group_box_layout.addWidget(self.use_target_phrases) self.use_target_phrases.stateChanged.connect(self.update_gui) self.quotation_group_box = QGroupBox(_('Quotation Marks')) widgetLayout.addWidget(self.quotation_group_box) quotation_group_box_layout = QVBoxLayout() self.quotation_group_box.setLayout(quotation_group_box_layout) quotation_group = QButtonGroup(self) self.quotation_no_conversion_button = QRadioButton(_('No Conversion')) quotation_group.addButton(self.quotation_no_conversion_button) self.quotation_trad_to_simp_button = QRadioButton( self.quote_for_simp_target) quotation_group.addButton(self.quotation_trad_to_simp_button) self.quotation_simp_to_trad_button = QRadioButton( self.quote_for_trad_target) quotation_group.addButton(self.quotation_simp_to_trad_button) quotation_group_box_layout.addWidget( self.quotation_no_conversion_button) quotation_group_box_layout.addWidget( self.quotation_simp_to_trad_button) quotation_group_box_layout.addWidget( self.quotation_trad_to_simp_button) self.quotation_no_conversion_button.toggled.connect(self.update_gui) self.quotation_trad_to_simp_button.toggled.connect(self.update_gui) self.quotation_simp_to_trad_button.toggled.connect(self.update_gui) self.use_smart_quotes = QCheckBox( """Use curved 'Smart" quotes if applicable""") self.use_smart_quotes.setToolTip( _('Use smart curved half-width quotes rather than straight full-width quotes' )) quotation_group_box_layout.addWidget(self.use_smart_quotes) self.use_smart_quotes.stateChanged.connect(self.update_gui) self.other_group_box = QGroupBox(_('Other Changes')) widgetLayout.addWidget(self.other_group_box) other_group_box_layout = QVBoxLayout() self.other_group_box.setLayout(other_group_box_layout) text_dir_layout = QHBoxLayout() other_group_box_layout.addLayout(text_dir_layout) direction_label = QLabel(_('Text Direction:')) text_dir_layout.addWidget(direction_label) self.text_dir_combo = QComboBox() text_dir_layout.addWidget(self.text_dir_combo) self.text_dir_combo.addItems( [_('No Conversion'), _('Horizontal'), _('Vertical')]) self.text_dir_combo.setToolTip( _('Select the desired text orientation')) self.text_dir_combo.currentIndexChanged.connect(self.update_gui) self.optimization_group_box = QGroupBox( _('Reader Device Optimization')) other_group_box_layout.addWidget(self.optimization_group_box) optimization_group_box_layout = QVBoxLayout() self.optimization_group_box.setLayout(optimization_group_box_layout) punc_group = QButtonGroup(self) self.text_dir_punc_none_button = QRadioButton( """No presentation optimization""") optimization_group_box_layout.addWidget(self.text_dir_punc_none_button) self.text_dir_punc_button = QRadioButton( """Optimize presentation for Readium reader""") self.text_dir_punc_button.setToolTip( _('Use vert/horiz punctuation presentation forms for Chrome Readium Epub3 reader' )) optimization_group_box_layout.addWidget(self.text_dir_punc_button) self.text_dir_punc_kindle_button = QRadioButton( """Optimize presentation for Kindle reader""") self.text_dir_punc_kindle_button.setToolTip( _('Use vert/horiz puncuation presentation forms for Kindle reader') ) optimization_group_box_layout.addWidget( self.text_dir_punc_kindle_button) self.text_dir_punc_none_button.toggled.connect(self.update_gui) self.text_dir_punc_button.toggled.connect(self.update_gui) self.text_dir_punc_kindle_button.toggled.connect(self.update_gui) source_group = QButtonGroup(self) self.file_source_button = QRadioButton(_('Selected File Only')) self.book_source_button = QRadioButton(_('Entire eBook')) source_group.addButton(self.file_source_button) source_group.addButton(self.book_source_button) self.source_group_box = QGroupBox(_('Source')) if not self.force_entire_book: widgetLayout.addWidget(self.source_group_box) source_group_box_layout = QVBoxLayout() self.source_group_box.setLayout(source_group_box_layout) source_group_box_layout.addWidget(self.file_source_button) source_group_box_layout.addWidget(self.book_source_button) layout.addSpacing(10) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._ok_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self.input_combo.setCurrentIndex(self.prefs['input_format']) self.output_combo.setCurrentIndex(self.prefs['output_format']) self.no_conversion_button.setChecked(self.prefs['no_conversion']) self.trad_to_simp_button.setChecked(self.prefs['trad_to_simp']) self.simp_to_trad_button.setChecked(self.prefs['simp_to_trad']) self.trad_to_trad_button.setChecked(self.prefs['trad_to_trad']) if not self.force_entire_book: self.file_source_button.setChecked(self.prefs['use_html_file']) self.book_source_button.setChecked(self.prefs['use_entire_book']) else: self.file_source_button.setChecked(False) self.book_source_button.setChecked(True) self.quotation_no_conversion_button.setChecked( self.prefs['quote_no_conversion']) self.quotation_trad_to_simp_button.setChecked( self.prefs['quote_trad_to_simp']) self.quotation_simp_to_trad_button.setChecked( self.prefs['quote_simp_to_trad']) self.use_smart_quotes.setChecked(self.prefs['use_smart_quotes']) self.text_dir_combo.setCurrentIndex(self.prefs['orientation']) self.text_dir_punc_none_button.setChecked( self.prefs['no_optimization']) self.text_dir_punc_button.setChecked( self.prefs['readium_optimization']) self.text_dir_punc_kindle_button.setChecked( self.prefs['kindle_optimization']) self.update_gui()
class SettingChildWin(QDialog): height_ = 25 def __init__(self, *args, **kwargs): super().__init__(*args) self.allModeGroup = QButtonGroup(self) self.npkModeGroup = QButtonGroup(self) if "mainWin" in kwargs.keys(): self.mainWin = kwargs["mainWin"] self.setObjectName("settingWin") self.setUi() self.npkModeBox() self.allExtractBox() self.checkBox() self.saveDirSelectBtn() self.img2DirBtn() self.portBtn = self.testPortBtn() self.inputPort() self.hide() def setUi(self): self.setFixedSize(400, 220) self.setWindowModality(Qt.ApplicationModal) self.setWindowTitle("设置") # 0 def npkModeBox(self): label_ = QLabel(self) label_.resize(self.width() // 3, 25) label_.setText("NPK提取模式:") label_.setAlignment(Qt.AlignCenter) label_.setStyleSheet("font-size: 15px") # 选项AB npkYes = QRadioButton(self) npkYes.resize(self.width() // 3, 25) npkYes.move(self.width() // 3, 0) npkYes.setText("提取") npkNo = QRadioButton(self) npkNo.resize(self.width() // 3, 25) npkNo.move(self.width() // 3 * 2, 0) npkNo.setText("不提取") npkNo.setChecked(True) def npkYesFunc(): if not self.mainWin.npkDict: QMessageBox.warning(self, "未设置NPK词典", "未设置NPK词典将不能设置NPK提取", QMessageBox.Yes, QMessageBox.Yes) npkNo.setChecked(True) return False if not self.mainWin.img2Dir: QMessageBox.warning(self, "未设置img2目录", "未设置img2目录将不能设置NPK提取", QMessageBox.Yes, QMessageBox.Yes) npkNo.setChecked(True) return False npkYes.clicked.connect(npkYesFunc) def yes(): self.mainWin.npkMode = True npkYes.toggled.connect(yes) def no(): self.mainWin.npkMode = False npkNo.toggled.connect(no) self.npkModeGroup.setObjectName("npkExtractMode") self.npkModeGroup.addButton(npkYes) self.npkModeGroup.addButton(npkNo) # 1 def allExtractBox(self): label_ = QLabel(self) label_.resize(self.width() // 3, 25) label_.move(0, 25) label_.setText("全部提取模式:") label_.setAlignment(Qt.AlignCenter) label_.setStyleSheet("font-size: 15px") # 选项AB allYes = QRadioButton(self) allYes.resize(self.width() // 3, 25) allYes.move(self.width() // 3, 25) allYes.setText("全部提取") allNo = QRadioButton(self) allNo.resize(self.width() // 3, 25) allNo.move(self.width() // 3 * 2, 25) allNo.setText("单个提取") allNo.setChecked(True) self.allModeGroup.setObjectName("allExtractMode") self.allModeGroup.addButton(allYes) self.allModeGroup.addButton(allNo) # def setImg2Dir(self): # 2 def saveDirSelectBtn(self): btn = QPushButton("保存文件夹", self) btn.setObjectName("saveDirSelectBtn") btn.resize(self.width() / 2, self.height_) btn.move(0, self.height_ * 2) # btn.setStyleSheet("background-color: pink") def btnFunc(): saveDirFunc(self) btn.clicked.connect(btnFunc) def img2DirBtn(self): btn = QPushButton("ImagePacks2文件夹", self) btn.setObjectName("saveDirSelectBtn") btn.resize(self.width() / 2, self.height_) btn.move(self.width() / 2, self.height_ * 2) # btn.setStyleSheet("background-color: pink") def btnFunc(): if img2DirFunc(self) is False: QMessageBox.warning(self, "img2文件夹选择错误", "文件夹下无NPK文件,请重新选择", QMessageBox.Yes, QMessageBox.Yes) btn.clicked.connect(btnFunc) # 3 def testPortBtn(self): portBtn = QPushButton("默认端口测试", self) portBtn.setObjectName("testPortBtn") portBtn.resize((self.width() - 30) / 2, self.height_) portBtn.move(0, self.height_ * 3) # portBtn.setEnabled(False) def portBtnFunc(): testPortFunc(self) portBtn.clicked.connect(portBtnFunc) return portBtn # 3 def inputPort(self): self.checkPort = QPushButton("√", self) self.checkPort.resize(30, self.height_) self.checkPort.move(self.width() - 30, self.height_ * 3) # self.checkPort.hide() self.inputLine = QLineEdit("输入端口", self) self.inputLine.resize((self.width() - 30) / 2, 25) self.inputLine.move((self.width() - 30) / 2, 25 * 3) # self.inputLine.hide() def inputPortF(): self.mainWin.port = self.inputLine.text() self.portBtn.click() self.checkPort.clicked.connect(inputPortF) def checkBox(self): # confirmBtn = QPushButton("确认", self) confirmBtn.resize(self.width() // 2, 25) confirmBtn.move(0, self.height() - 25) confirmBtn.clicked.connect(self.hide) # cancelBtn = QPushButton("取消", self) cancelBtn.resize(self.width() // 2, 25) cancelBtn.move(self.width() // 2, self.height() - 25) cancelBtn.clicked.connect(self.close) def closeEvent(self, closeEvt): reply = QMessageBox.question(self, "", "关闭后,设置将不会保存", QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: for button in self.checkedList: button.setChecked(True) self.hide() else: closeEvt.ignore() def showEvent(self, showEvt): self.checkedList = [ group.checkedButton() for group in self.findChildren(QButtonGroup) ] return super().showEvent(showEvt)
class LibraryCodesTab(QWidget): def __init__(self, mygui, myguidb, mymainprefs, myparam_dict, myuiexit, mysavedialoggeometry): super(LibraryCodesTab, self).__init__() #----------------------------------------------------- #----------------------------------------------------- self.gui = mygui #----------------------------------------------------- #----------------------------------------------------- self.guidb = myguidb #----------------------------------------------------- #----------------------------------------------------- self.lib_path = self.gui.library_view.model().db.library_path #----------------------------------------------------- #----------------------------------------------------- self.mytabprefs = mymainprefs #----------------------------------------------------- #----------------------------------------------------- self.param_dict = myparam_dict #----------------------------------------------------- #----------------------------------------------------- self.ui_exit = myuiexit #----------------------------------------------------- #----------------------------------------------------- self.save_dialog_geometry = mysavedialoggeometry #----------------------------------------------------- #----------------------------------------------------- font = QFont() font.setBold(False) font.setPointSize(10) #----------------------------------------------------- self.layout_top = QVBoxLayout() self.layout_top.setSpacing(0) self.layout_top.setAlignment(Qt.AlignLeft) self.setLayout(self.layout_top) #----------------------------------------------------- self.scroll_area_frame = QScrollArea() self.scroll_area_frame.setAlignment(Qt.AlignLeft) self.scroll_area_frame.setWidgetResizable(True) self.scroll_area_frame.ensureVisible(400, 400) self.layout_top.addWidget( self.scroll_area_frame ) # the scroll area is now the child of the parent of self.layout_top # NOTE: the self.scroll_area_frame.setWidget(self.scroll_widget) is at the end of the init() AFTER all children have been created and assigned to a layout... #----------------------------------------------------- self.scroll_widget = QWidget() self.layout_top.addWidget( self.scroll_widget ) # causes automatic reparenting of QWidget to the parent of self.layout_top, which is: self . #----------------------------------------------------- self.layout_frame = QVBoxLayout() self.layout_frame.setSpacing(0) self.layout_frame.setAlignment(Qt.AlignLeft) self.scroll_widget.setLayout( self.layout_frame ) # causes automatic reparenting of any widget later added to self.layout_frame to the parent of self.layout_frame, which is: QWidget . #----------------------------------------------------- self.lc_groupbox = QGroupBox('Settings:') self.lc_groupbox.setMaximumWidth(400) self.lc_groupbox.setToolTip( "<p style='white-space:wrap'>The settings that control 'Library Codes'. Using only ISBN or ISSN or Author/Title, Library Codes for selected books will be derived using the Current Settings." ) self.layout_frame.addWidget(self.lc_groupbox) self.lc_layout = QGridLayout() self.lc_groupbox.setLayout(self.lc_layout) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.spacing0 = QLabel() self.layout_frame.addWidget(self.spacing0) self.spacing0.setMaximumHeight(20) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.button_box = QDialogButtonBox() self.button_box.setOrientation(Qt.Horizontal) self.button_box.setCenterButtons(True) self.layout_frame.addWidget(self.button_box) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.push_button_save_only = QPushButton("Save") self.push_button_save_only.clicked.connect(self.save_settings) self.push_button_save_only.setDefault(True) self.push_button_save_only.setFont(font) self.push_button_save_only.setToolTip( "<p style='white-space:wrap'>Save all user settings.") self.button_box.addButton(self.push_button_save_only, 0) self.push_button_exit_only = QPushButton("Exit") self.push_button_exit_only.clicked.connect(self.exit_only) self.push_button_exit_only.setDefault(False) self.push_button_exit_only.setFont(font) self.push_button_exit_only.setToolTip( "<p style='white-space:wrap'>Exit immediately without saving anything." ) self.button_box.addButton(self.push_button_exit_only, 0) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- r = 4 self.ddc_labelname = QLineEdit(self) self.ddc_labelname.setText(self.mytabprefs['DDC']) self.ddc_labelname.setFont(font) self.ddc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for DDC.<br><br>See: https://www.oclc.org/dewey/features/summaries.en.html" ) self.ddc_labelname.setMaximumWidth(100) self.lc_layout.addWidget(self.ddc_labelname, r, 0) self.ddc_activate_checkbox = QCheckBox( "Activate 'Dewey Decimal Code' Classification?") self.ddc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive DDC?") r = r + 1 self.lc_layout.addWidget(self.ddc_activate_checkbox, r, 0) if prefs['DDC_IS_ACTIVE'] == unicode_type(S_TRUE): self.ddc_activate_checkbox.setChecked(True) else: self.ddc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing1 = QLabel() r = r + 1 self.lc_layout.addWidget(self.spacing1, r, 0) self.spacing1.setMaximumHeight(10) #----------------------------------------------------- self.lcc_labelname = QLineEdit(self) self.lcc_labelname.setText(self.mytabprefs['LCC']) self.lcc_labelname.setFont(font) self.lcc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for LCC.<br><br>See: http://www.loc.gov/catdir/cpso/lcco/ " ) self.lcc_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.lcc_labelname, r, 0) self.lcc_activate_checkbox = QCheckBox( "Activate 'Library of Congress Code' Classification?") self.lcc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive LCC?") r = r + 1 self.lc_layout.addWidget(self.lcc_activate_checkbox, r, 0) if prefs['LCC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lcc_activate_checkbox.setChecked(True) else: self.lcc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing2 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing2, r, 0) self.spacing2.setMaximumHeight(10) #----------------------------------------------------- self.fast_labelname = QLineEdit(self) self.fast_labelname.setText(self.mytabprefs['FAST']) self.fast_labelname.setFont(font) self.fast_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for FAST Tag Values. " ) self.fast_labelname.setMinimumWidth(100) self.fast_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.fast_labelname, r, 0) self.fast_activate_checkbox = QCheckBox("Activate 'FAST' Tags?") self.fast_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive FAST Tags?\ <br><br>Text. Behaves like Tags. Not Names.<br><br>" ) r = r + 1 self.lc_layout.addWidget(self.fast_activate_checkbox, r, 0) if prefs['FAST_IS_ACTIVE'] == unicode_type(S_TRUE): self.fast_activate_checkbox.setChecked(True) else: self.fast_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing6 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing6, r, 0) self.spacing6.setMaximumHeight(10) #----------------------------------------------------- self.oclc_labelname = QLineEdit(self) self.oclc_labelname.setText(self.mytabprefs['OCLC']) self.oclc_labelname.setFont(font) self.oclc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for OCLC-OWI.<br><br>See: #http://classify.oclc.org/classify2/ " ) self.oclc_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.oclc_labelname, r, 0) self.oclc_activate_checkbox = QCheckBox( "Activate 'Online Computer Library Center' Work ID Code?") self.oclc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive OCLC-OWI?") r = r + 1 self.lc_layout.addWidget(self.oclc_activate_checkbox, r, 0) if self.mytabprefs['OCLC_IS_ACTIVE'] == unicode_type(S_TRUE): self.oclc_activate_checkbox.setChecked(True) else: self.oclc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing5 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing5, r, 0) self.spacing5.setMaximumHeight(10) #----------------------------------------------------- self.lc_author_details_labelname = QLineEdit(self) self.lc_author_details_labelname.setText( self.mytabprefs['EXTRA_AUTHOR_DETAILS']) self.lc_author_details_labelname.setFont(font) self.lc_author_details_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for 'LC Extra Author Details'.\ <br><br>Text. Behaves like Tags. Not Names.<br><br>" ) self.lc_author_details_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.lc_author_details_labelname, r, 0) self.lc_author_details_checkbox = QCheckBox( "Activate 'Library Codes Extra Author Details'?") self.lc_author_details_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to add (never delete or replace) any available Tag-like values to this Custom Column if they are associated with the OCLC-OWI Identifier?" ) r = r + 1 self.lc_layout.addWidget(self.lc_author_details_checkbox, r, 0) if self.mytabprefs['EXTRA_AUTHOR_DETAILS_IS_ACTIVE'] == unicode_type( S_TRUE): self.lc_author_details_checkbox.setChecked(True) else: self.lc_author_details_checkbox.setChecked(False) #----------------------------------------------------- #----------------------------------------------------- self.spacing4 = QLabel() r = r + 1 self.lc_layout.addWidget(self.spacing4, r, 0) self.spacing4.setMaximumHeight(10) #----------------------------------------------------- font.setBold(False) font.setPointSize(7) #----------------------------------------------------- self.push_button_autoadd_custom_columns = QPushButton( "Automatically Add Activated Custom Columns?") self.push_button_autoadd_custom_columns.clicked.connect( self.autoadd_custom_columns) self.push_button_autoadd_custom_columns.setDefault(False) self.push_button_autoadd_custom_columns.setFont(font) self.push_button_autoadd_custom_columns.setToolTip( "<p style='white-space:wrap'>Do you want to automatically add the Custom Columns selected above?<br><br>If you have any issues, please add them manually." ) r = r + 4 self.lc_layout.addWidget(self.push_button_autoadd_custom_columns, r, 0) self.push_button_autoadd_custom_columns.setMaximumWidth(250) #----------------------------------------------------- self.lc_custom_columns_generation_label = QLabel() r = r + 1 self.lc_layout.addWidget(self.lc_custom_columns_generation_label, r, 0) self.lc_custom_columns_generation_label.setText( " ") self.lc_custom_columns_generation_label.setMaximumHeight(10) self.lc_custom_columns_generation_label.setFont(font) self.oclc_identifier_only_checkbox = QCheckBox( "Always Create OCLC-OWI as an 'Identifier' (à la ISBN)?") self.oclc_identifier_only_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to update Calibre's Identifiers for an Identifier of 'OCLC-OWI',\ regardless of whether you want its own Custom Column updated?\ <br><br>REQUIRED to derive DDC/LCC using Author/Title." ) r = r + 2 self.lc_layout.addWidget(self.oclc_identifier_only_checkbox, r, 0) if prefs['OCLC_IDENTIFIER'] == unicode_type(S_TRUE): self.oclc_identifier_only_checkbox.setChecked(True) else: self.oclc_identifier_only_checkbox.setChecked(False) #----------------------------------------------------- self.spacing3 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing3, r, 0) self.spacing3.setMaximumHeight(10) #----------------------------------------------------- font.setBold(False) font.setPointSize(10) #----------------------------------------------------- self.lc_genre_labelname = QLineEdit(self) self.lc_genre_labelname.setText(self.mytabprefs['GENRE']) self.lc_genre_labelname.setFont(font) self.lc_genre_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for 'Genre'.\ <br><br>Text. Behaves like Tags.<br><br>" ) self.lc_genre_labelname.setMaximumWidth(100) r = r + 1 self.lc_layout.addWidget(self.lc_genre_labelname, r, 0) self.lc_checkbox_buttongroup = QButtonGroup() self.lc_checkbox_buttongroup.setExclusive(True) self.lc_genre_ddc_checkbox = QCheckBox( "Update 'Genre' using DDC-to-Genre Mappings?") self.lc_genre_ddc_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want LC to update 'Genre' using the DDC-to-Genre mapping in Table _lc_genre_mapping?" ) r = r + 1 self.lc_layout.addWidget(self.lc_genre_ddc_checkbox, r, 0) self.lc_genre_lcc_checkbox = QCheckBox( "Update 'Genre' using LCC-to-Genre Mappings?") self.lc_genre_lcc_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want LC to update 'Genre' using the LCC-to-Genre mapping in Table _lc_genre_mapping?" ) r = r + 1 self.lc_layout.addWidget(self.lc_genre_lcc_checkbox, r, 0) self.lc_genre_inactive_checkbox = QCheckBox( "Do not update 'Genre' at all") self.lc_genre_inactive_checkbox.setToolTip( "<p style='white-space:wrap'>Do no 'Genre' processing at all?") r = r + 1 self.lc_layout.addWidget(self.lc_genre_inactive_checkbox, r, 0) self.lc_checkbox_buttongroup.addButton(self.lc_genre_ddc_checkbox) self.lc_checkbox_buttongroup.addButton(self.lc_genre_lcc_checkbox) self.lc_checkbox_buttongroup.addButton(self.lc_genre_inactive_checkbox) if self.mytabprefs['GENRE_DDC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lc_genre_ddc_checkbox.setChecked(True) elif self.mytabprefs['GENRE_LCC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lc_genre_lcc_checkbox.setChecked(True) elif self.mytabprefs['GENRE_IS_INACTIVE'] == unicode_type(S_TRUE): self.lc_genre_inactive_checkbox.setChecked(True) self.lc_exact_match_checkbox = QCheckBox( "DDC: Require an 'Exact Match', not a 'Best Match'?") self.lc_exact_match_checkbox.setToolTip( "<p style='white-space:wrap'>Check this checkbox if you want an exact DDC match to be required in Table _lc_genre_mapping. Otherwise, a 'best match' will be used via progressive shortening from right to left, but not past any decimal point. If there is no decimal point in a book's DDC, then no progressive shortening will be performed at all." ) r = r + 1 self.lc_layout.addWidget(self.lc_exact_match_checkbox, r, 0) if self.mytabprefs['GENRE_EXACT_MATCH'] == unicode_type(S_TRUE): self.lc_exact_match_checkbox.setChecked(True) self.spin_lcc = QSpinBox(self) self.spin_lcc.setMinimum(1) self.spin_lcc.setMaximum(50) self.spin_lcc.setProperty('value', prefs['GENRE_LCC_MATCH_LENGTH']) self.spin_lcc.setMaximumWidth(250) self.spin_lcc.setSuffix(" LCC: Maximum Length to Match") self.spin_lcc.setToolTip( "<p style='white-space:nowrap'>Maximum number of characters in the LCC that should be used to map to the 'Genre', starting from the left. A maximum of 1 guarantees a (broad) match.\ <br><br>LCCs are structured with either 1 or 2 beginning letters, so 2-character LCCs have special matching logic.\ <br><br>Example: Assume maximum = 2 for a LCC of 'Q1': Q1 would be attempted. If it failed, because the 2nd digit is a number, 'Q' would be attempted.\ <br><br>Example: Assume maximum = 2 for a LCC of 'PN1969.C65': PN would be attempted. If it failed, nothing else would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'PN1969.C65': PN19 would be attempted. If it failed, nothing else would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'Q1': Q1 would be attempted. If it failed, because the 2nd digit is a number, 'Q' would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'Q389': Q389 would be attempted. If it failed, nothing else would be attempted." ) r = r + 2 self.lc_layout.addWidget(self.spin_lcc, r, 0) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.scroll_widget.resize(self.sizeHint()) #----------------------------------------------------- #----------------------------------------------------- self.scroll_area_frame.setWidget( self.scroll_widget ) # now that all widgets have been created and assigned to a layout... #----------------------------------------------------- #----------------------------------------------------- self.scroll_area_frame.resize(self.sizeHint()) #----------------------------------------------------- #----------------------------------------------------- self.resize(self.sizeHint()) #----------------------------------------------------------------------------------------- def validate(self): return True #----------------------------------------------------------------------------------------- def autoadd_custom_columns(self): number_active = self.save_settings() if number_active == 0: return error_dialog( self.gui, _('Automatically Add Custom Columns'), _('No Activated Library Codes Custom Columns Found. Nothing to Add.' ), show=True) self.cli_param_list = self.create_cli_parameters() is_valid, restart_required = self.create_new_lc_custom_columns( self.cli_param_list) if is_valid: if restart_required: self.lc_custom_columns_generation_label.setText( "Addition of Custom Columns Complete. Restart Calibre Now." ) self.repaint() info_dialog( self.gui, 'Automatically Add Custom Columns', 'All Selected Custom Customs Were Added If They Did Not Already Exist. Please Restart Calibre now.' ).show() else: self.lc_custom_columns_generation_label.setText( "Selected Custom Columns Already Exist. Nothing Done.") self.repaint() else: self.lc_custom_columns_generation_label.setText( "Not Completed. Please Restart Calibre, then Add Manually.") self.repaint() msg = "Fatal error experienced in adding new Custom Columns." error_dialog(self.gui, _('Automatically Add Custom Columns'), _(msg), show=True) #----------------------------------------------------------------------------------------- def create_cli_parameters(self): try: del self.cli_param_list except: pass self.cli_param_list = [] temp_list = [] cc_taglike_list = [] cc_fast_name = "" if self.mytabprefs['DDC_IS_ACTIVE'] == unicode_type(S_TRUE): cc = self.mytabprefs['DDC'] if cc > '#': cc = cc.replace('#', "").strip() cc = unicode_type(cc) temp_list.append(cc) else: error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Illogical DDC Settings. Please Correct.'), show=True) return self.cli_param_list if self.mytabprefs['LCC_IS_ACTIVE'] == unicode_type(S_TRUE): cc = self.mytabprefs['LCC'] if cc > '#': cc = cc.replace('#', "").strip() cc = unicode_type(cc) temp_list.append(cc) else: error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Illogical LCC Settings. Please Correct.'), show=True) return self.cli_param_list if self.mytabprefs['FAST_IS_ACTIVE'] == unicode_type(S_TRUE): cc = self.mytabprefs['FAST'] if cc > '#': cc = cc.replace('#', "").strip() cc = unicode_type(cc) temp_list.append(cc) cc_taglike_list.append(cc) cc_fast_name = cc else: error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Illogical FAST Settings. Please Correct.'), show=True) return self.cli_param_list if self.mytabprefs['OCLC_IS_ACTIVE'] == unicode_type(S_TRUE): cc = self.mytabprefs['OCLC'] if cc > '#': cc = cc.replace('#', "").strip() cc = unicode_type(cc) temp_list.append(cc) else: error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Illogical OCLC Settings. Please Correct.'), show=True) return self.cli_param_list if self.mytabprefs['EXTRA_AUTHOR_DETAILS_IS_ACTIVE'] == unicode_type( S_TRUE): cc = self.mytabprefs['EXTRA_AUTHOR_DETAILS'] if cc > '#': cc = cc.replace('#', "").strip() cc = unicode_type(cc) temp_list.append(cc) cc_taglike_list.append(cc) else: error_dialog( self.gui, _('Automatically Add Custom Columns'), _('Illogical LC Extra Author Details Settings. Please Correct.' ), show=True) return self.cli_param_list else: pass if len(temp_list) == 0: del temp_list error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Nothing to do. Please Review Settings.'), show=True) return self.cli_param_list cc_to_add_list = [] # for each cc currently set to active, create a parameter...but only if the cc does NOT already exist... my_db, my_cursor, is_valid = self.apsw_connect_to_library() if not is_valid: error_dialog(self.gui, _('Automatically Add Custom Columns'), _('Database Connection Error. Restart Calibre.'), show=True) return self.lc_custom_columns_generation_label.setText( "...Adding Custom Columns...") self.repaint() mysql = "SELECT label,name FROM custom_columns" my_cursor.execute(mysql) tmp_rows = my_cursor.fetchall() if not tmp_rows: for cc in temp_list: cc_to_add_list.append(cc) #END FOR else: if len(tmp_rows) == 0: for cc in temp_list: cc_to_add_list.append(cc) #END FOR else: for cc in temp_list: label_already_exists = False for row in tmp_rows: label, name = row if unicode_type(label) == unicode_type(cc): label_already_exists = True break else: continue #END FOR if not label_already_exists: cc_to_add_list.append(cc) #END FOR del tmp_rows del temp_list if len(cc_to_add_list) == 0: return self.cli_param_list cc_to_add_list.sort() for label in cc_to_add_list: label = unicodedata.normalize('NFKD', label).encode('ascii', 'ignore') label = unicode_type(label) label = label.lower() name = label.upper() datatype = 'text' if label in cc_taglike_list: is_multiple = "--is-multiple" if label == cc_fast_name: name = "FAST Tags" else: name = '"LC Extra Author Details"' param = is_multiple + '|||' + label + '|||' + name + '|||' + datatype else: param = label + '|||' + name + '|||' + datatype param = param.replace("[LIBRARY]", self.lib_path) self.cli_param_list.append(param) #END FOR del cc_to_add_list return self.cli_param_list #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- def apsw_connect_to_library(self): my_db = self.gui.library_view.model().db self.lib_path = my_db.library_path self.lib_path = self.lib_path.replace(os.sep, '/') if isbytestring(self.lib_path): self.lib_path = self.lib_path.decode(filesystem_encoding) path = my_db.library_path if isbytestring(path): path = path.decode(filesystem_encoding) path = path.replace(os.sep, '/') path = os.path.join(path, 'metadata.db') path = path.replace(os.sep, '/') if isbytestring(path): path = path.decode(filesystem_encoding) if path.endswith("/"): path = path[0:-1] if path.count("metadata.db") == 0: path = path + "/metadata.db" try: my_db = apsw.Connection(path) is_valid = True except Exception as e: if DEBUG: print("path to metadata.db is: ", path) if DEBUG: print("error: ", as_unicode(e)) is_valid = False return None, None, is_valid my_cursor = my_db.cursor() mysql = "PRAGMA main.busy_timeout = 5000;" #PRAGMA busy_timeout = milliseconds; my_cursor.execute(mysql) return my_db, my_cursor, is_valid #----------------------------------------------------------------------------------------- def exit_only(self): self.save_dialog_geometry() # inherited from SizePersistedDialog self.ui_exit() #----------------------------------------------------------------------------------------- def save_settings(self): self.save_dialog_geometry() # inherited from SizePersistedDialog self.mytabprefs['DDC'] = self.ddc_labelname.text() self.mytabprefs['LCC'] = self.lcc_labelname.text() self.mytabprefs['FAST'] = self.fast_labelname.text() self.mytabprefs['OCLC'] = self.oclc_labelname.text() self.mytabprefs['DDC_IS_ACTIVE'] = unicode_type( self.ddc_activate_checkbox.isChecked()) self.mytabprefs['LCC_IS_ACTIVE'] = unicode_type( self.lcc_activate_checkbox.isChecked()) self.mytabprefs['FAST_IS_ACTIVE'] = unicode_type( self.fast_activate_checkbox.isChecked()) self.mytabprefs['OCLC_IS_ACTIVE'] = unicode_type( self.oclc_activate_checkbox.isChecked()) self.mytabprefs['OCLC_IDENTIFIER'] = unicode_type( self.oclc_identifier_only_checkbox.isChecked()) label = self.mytabprefs['DDC'] label = unicode_type(label) label = unicodedata.normalize('NFKD', label).encode('ascii', 'ignore') label = label.lower().strip() if not label.startswith("#"): label = "#" + label if label == "#": label = "" self.ddc_activate_checkbox.setChecked(False) self.mytabprefs['DDC'] = unicode_type(label) label = self.mytabprefs['LCC'] label = unicode_type(label) label = unicodedata.normalize('NFKD', label).encode('ascii', 'ignore') label = label.lower().strip() if not label.startswith("#"): label = "#" + label if label == "#": label = "" self.lcc_activate_checkbox.setChecked(False) self.mytabprefs['LCC'] = unicode_type(label) label = self.mytabprefs['FAST'] label = unicode_type(label) label = unicodedata.normalize('NFKD', label).encode('ascii', 'ignore') label = label.lower().strip() if not label.startswith("#"): label = "#" + label if label == "#": label = "" self.fast_activate_checkbox.setChecked(False) self.mytabprefs['FAST'] = unicode_type(label) label = self.mytabprefs['OCLC'] label = unicode_type(label) label = unicodedata.normalize('NFKD', label).encode('ascii', 'ignore') label = label.lower().strip() if not label.startswith("#"): label = "#" + label if label == "#": label = "" self.oclc_activate_checkbox.setChecked(False) self.mytabprefs['OCLC'] = unicode_type(label) if self.mytabprefs['DDC'] == unicode_type( "") and self.mytabprefs['LCC'] == unicode_type( "") and self.mytabprefs['FAST'] == unicode_type( "") and self.mytabprefs['OCLC'] == unicode_type(""): self.mytabprefs['DDC'] = unicode_type("#ddc") self.mytabprefs['LCC'] = unicode_type("#lcc") self.mytabprefs['FAST'] = unicode_type("#fast") self.mytabprefs['OCLC'] = unicode_type("#oclc_owi") else: if self.mytabprefs['DDC'] == unicode_type( "") and self.mytabprefs['LCC'] == unicode_type(""): self.oclc_identifier_only_checkbox.setChecked(False) #--------------------------------------- s = unicode_type(self.lc_genre_labelname.text()) s = s.strip() if s.startswith("#") and len(s) > 1: self.mytabprefs['GENRE'] = unicode_type(s) self.mytabprefs['GENRE_DDC_IS_ACTIVE'] = unicode_type( self.lc_genre_ddc_checkbox.isChecked()) self.mytabprefs['GENRE_LCC_IS_ACTIVE'] = unicode_type( self.lc_genre_lcc_checkbox.isChecked()) self.mytabprefs['GENRE_IS_INACTIVE'] = unicode_type( self.lc_genre_inactive_checkbox.isChecked()) self.mytabprefs['GENRE_EXACT_MATCH'] = unicode_type( self.lc_exact_match_checkbox.isChecked()) self.mytabprefs['GENRE_LCC_MATCH_LENGTH'] = self.spin_lcc.value() else: self.mytabprefs['GENRE'] = unicode_type("#genre") self.lc_genre_labelname.setText(unicode_type("#genre")) self.lc_genre_ddc_checkbox.setChecked(False) self.lc_genre_lcc_checkbox.setChecked(False) self.lc_genre_inactive_checkbox.setChecked(True) self.mytabprefs['GENRE_DDC_IS_ACTIVE'] = unicode_type(S_FALSE) self.mytabprefs['GENRE_LCC_IS_ACTIVE'] = unicode_type(S_FALSE) self.mytabprefs['GENRE_IS_INACTIVE'] = unicode_type(S_TRUE) self.mytabprefs['GENRE_EXACT_MATCH'] = unicode_type(S_TRUE) self.mytabprefs['GENRE_LCC_MATCH_LENGTH'] = 2 self.repaint() sleep(2) #--------------------------------------- #~ for k,v in self.mytabprefs.iteritems(): for k, v in iteritems(self.mytabprefs): v = unicode_type(v) v = v.strip() prefs[k] = v #END FOR prefs #--------------------------------------- self.ddc_labelname.setText(self.mytabprefs['DDC']) self.lcc_labelname.setText(self.mytabprefs['LCC']) self.fast_labelname.setText(self.mytabprefs['FAST']) self.oclc_labelname.setText(self.mytabprefs['OCLC']) self.repaint() sleep(0) #~ for k,v in self.mytabprefs.iteritems(): for k, v in iteritems(self.mytabprefs): self.param_dict[k] = v #END FOR number_active = 0 if self.mytabprefs['DDC_IS_ACTIVE'] == unicode_type(S_TRUE): number_active = number_active + 1 if self.mytabprefs['LCC_IS_ACTIVE'] == unicode_type(S_TRUE): number_active = number_active + 1 if self.mytabprefs['FAST_IS_ACTIVE'] == unicode_type(S_TRUE): number_active = number_active + 1 if self.mytabprefs['OCLC_IS_ACTIVE'] == unicode_type(S_TRUE): number_active = number_active + 1 self.ddc_name = self.mytabprefs['DDC'].replace("#", "").strip() self.lcc_name = self.mytabprefs['LCC'].replace("#", "").strip() self.fast_name = self.mytabprefs['FAST'].replace("#", "").strip() self.oclc_name = self.mytabprefs['OCLC'].replace("#", "").strip() if self.oclc_identifier_only_checkbox.isChecked(): self.oclc_identifier_is_desired = True else: self.oclc_identifier_is_desired = False return number_active #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- def create_new_lc_custom_columns(self, execution_param_list): if len(self.cli_param_list) == 0: return True, False # successful since the labels already exist; no restart is required. dbpath = self.lib_path was_successful = True restart_required = True for param in execution_param_list: try: lc_cli_add_custom_column(self.guidb, param, dbpath) except Exception as e: if DEBUG: print("Exception: ", as_unicode(e)) was_successful = False break #END FOR return was_successful, restart_required #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------- #END of library_codes_dialog.py
class LLT_MC(QMainWindow): def __init__(self, dicTitle, dicList): super(LLT_MC, self).__init__() self.w = QWidget() self.setCentralWidget(self.w) self.title = dicTitle self.wordList = dicList self.setWindowTitle("Multiple Choice") self.setGeometry(0, 0, 300, 400) self.currentWordS = random.sample(self.wordList, 3) self.currentQWord = self.currentWordS[0][0] self.currentAWord = self.currentWordS[0][1] self.topLabel = QLabel("Multiple Choice: " + str(dicTitle)) self.wordLabel = QLabel() self.wordLabel.setFont(QFont('Times New Roman', 16)) self.wordLabel.setAlignment(Qt.AlignCenter) self.resultLabel = QLabel() self.resultLabel.setAlignment(Qt.AlignCenter) self.aRad = QRadioButton() self.bRad = QRadioButton() self.cRad = QRadioButton() self.group = QButtonGroup() self.group.addButton(self.aRad) self.group.addButton(self.bRad) self.group.addButton(self.cRad) self.checkBut = QPushButton("Check") self.checkBut.setMinimumWidth(100) self.checkBut.setMinimumHeight(70) self.checkBut.clicked.connect(self.check) self.nextBut = QPushButton("Next Word") self.nextBut.setMinimumWidth(100) self.nextBut.setMinimumHeight(70) self.nextBut.clicked.connect(self.next) self.exitBut = QPushButton("Exit") self.exitBut.setMinimumWidth(130) self.exitBut.setMinimumHeight(70) self.exitBut.clicked.connect(self.exit) self.hbox = QHBoxLayout() self.hbox.addWidget(self.checkBut) self.hbox.addWidget(self.nextBut) self.vbox = QVBoxLayout() self.vbox.addWidget(self.topLabel) self.vbox.addWidget(self.wordLabel) self.vbox.addWidget(self.aRad) self.vbox.addWidget(self.bRad) self.vbox.addWidget(self.cRad) self.vbox.addWidget(self.resultLabel) self.vbox.addLayout(self.hbox) self.vbox.addWidget(self.exitBut) self.w.setLayout(self.vbox) self.setWord() #define methods def setWord(self): newText = [] for item in self.currentWordS: newText.append(item[1]) random.shuffle(newText) self.group.setExclusive(False) self.aRad.setText(newText[0]) self.bRad.setText(newText[1]) self.cRad.setText(newText[2]) self.wordLabel.setText(self.currentQWord) self.group.setExclusive(True) def check(self): if self.aRad.isChecked() and self.aRad.text() == self.currentAWord: self.resultLabel.setText("CORRECT") elif self.aRad.isChecked() and self.aRad.text() != self.currentAWord: self.resultLabel.setText("Try again") if self.bRad.isChecked() and self.bRad.text() == self.currentAWord: self.resultLabel.setText("CORRECT") elif self.bRad.isChecked() and self.bRad.text() != self.currentAWord: self.resultLabel.setText("Try again") if self.cRad.isChecked() and self.cRad.text() == self.currentAWord: self.resultLabel.setText("CORRECT") elif self.cRad.isChecked() and self.cRad.text() != self.currentAWord: self.resultLabel.setText("Try again") def next(self): self.currentWordS = random.sample(self.wordList, 3) self.currentQWord = self.currentWordS[0][0] self.currentAWord = self.currentWordS[0][1] self.wordLabel.setText(self.currentQWord) self.resultLabel.setText('') self.group.setExclusive(False) self.aRad.setChecked(False) self.bRad.setChecked(False) self.cRad.setChecked(False) self.group.setExclusive(True) newText = [] for item in self.currentWordS: newText.append(item[1]) random.shuffle(newText) self.aRad.setText(newText[0]) self.bRad.setText(newText[1]) self.cRad.setText(newText[2]) def exit(self): confirm = QMessageBox.question(self.w, 'Quit', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No) if confirm == QMessageBox.Yes: self.close() else: pass
def __init__(self, mygui, myguidb, mymainprefs, myparam_dict, myuiexit, mysavedialoggeometry): super(LibraryCodesTab, self).__init__() #----------------------------------------------------- #----------------------------------------------------- self.gui = mygui #----------------------------------------------------- #----------------------------------------------------- self.guidb = myguidb #----------------------------------------------------- #----------------------------------------------------- self.lib_path = self.gui.library_view.model().db.library_path #----------------------------------------------------- #----------------------------------------------------- self.mytabprefs = mymainprefs #----------------------------------------------------- #----------------------------------------------------- self.param_dict = myparam_dict #----------------------------------------------------- #----------------------------------------------------- self.ui_exit = myuiexit #----------------------------------------------------- #----------------------------------------------------- self.save_dialog_geometry = mysavedialoggeometry #----------------------------------------------------- #----------------------------------------------------- font = QFont() font.setBold(False) font.setPointSize(10) #----------------------------------------------------- self.layout_top = QVBoxLayout() self.layout_top.setSpacing(0) self.layout_top.setAlignment(Qt.AlignLeft) self.setLayout(self.layout_top) #----------------------------------------------------- self.scroll_area_frame = QScrollArea() self.scroll_area_frame.setAlignment(Qt.AlignLeft) self.scroll_area_frame.setWidgetResizable(True) self.scroll_area_frame.ensureVisible(400, 400) self.layout_top.addWidget( self.scroll_area_frame ) # the scroll area is now the child of the parent of self.layout_top # NOTE: the self.scroll_area_frame.setWidget(self.scroll_widget) is at the end of the init() AFTER all children have been created and assigned to a layout... #----------------------------------------------------- self.scroll_widget = QWidget() self.layout_top.addWidget( self.scroll_widget ) # causes automatic reparenting of QWidget to the parent of self.layout_top, which is: self . #----------------------------------------------------- self.layout_frame = QVBoxLayout() self.layout_frame.setSpacing(0) self.layout_frame.setAlignment(Qt.AlignLeft) self.scroll_widget.setLayout( self.layout_frame ) # causes automatic reparenting of any widget later added to self.layout_frame to the parent of self.layout_frame, which is: QWidget . #----------------------------------------------------- self.lc_groupbox = QGroupBox('Settings:') self.lc_groupbox.setMaximumWidth(400) self.lc_groupbox.setToolTip( "<p style='white-space:wrap'>The settings that control 'Library Codes'. Using only ISBN or ISSN or Author/Title, Library Codes for selected books will be derived using the Current Settings." ) self.layout_frame.addWidget(self.lc_groupbox) self.lc_layout = QGridLayout() self.lc_groupbox.setLayout(self.lc_layout) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.spacing0 = QLabel() self.layout_frame.addWidget(self.spacing0) self.spacing0.setMaximumHeight(20) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.button_box = QDialogButtonBox() self.button_box.setOrientation(Qt.Horizontal) self.button_box.setCenterButtons(True) self.layout_frame.addWidget(self.button_box) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.push_button_save_only = QPushButton("Save") self.push_button_save_only.clicked.connect(self.save_settings) self.push_button_save_only.setDefault(True) self.push_button_save_only.setFont(font) self.push_button_save_only.setToolTip( "<p style='white-space:wrap'>Save all user settings.") self.button_box.addButton(self.push_button_save_only, 0) self.push_button_exit_only = QPushButton("Exit") self.push_button_exit_only.clicked.connect(self.exit_only) self.push_button_exit_only.setDefault(False) self.push_button_exit_only.setFont(font) self.push_button_exit_only.setToolTip( "<p style='white-space:wrap'>Exit immediately without saving anything." ) self.button_box.addButton(self.push_button_exit_only, 0) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- r = 4 self.ddc_labelname = QLineEdit(self) self.ddc_labelname.setText(self.mytabprefs['DDC']) self.ddc_labelname.setFont(font) self.ddc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for DDC.<br><br>See: https://www.oclc.org/dewey/features/summaries.en.html" ) self.ddc_labelname.setMaximumWidth(100) self.lc_layout.addWidget(self.ddc_labelname, r, 0) self.ddc_activate_checkbox = QCheckBox( "Activate 'Dewey Decimal Code' Classification?") self.ddc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive DDC?") r = r + 1 self.lc_layout.addWidget(self.ddc_activate_checkbox, r, 0) if prefs['DDC_IS_ACTIVE'] == unicode_type(S_TRUE): self.ddc_activate_checkbox.setChecked(True) else: self.ddc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing1 = QLabel() r = r + 1 self.lc_layout.addWidget(self.spacing1, r, 0) self.spacing1.setMaximumHeight(10) #----------------------------------------------------- self.lcc_labelname = QLineEdit(self) self.lcc_labelname.setText(self.mytabprefs['LCC']) self.lcc_labelname.setFont(font) self.lcc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for LCC.<br><br>See: http://www.loc.gov/catdir/cpso/lcco/ " ) self.lcc_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.lcc_labelname, r, 0) self.lcc_activate_checkbox = QCheckBox( "Activate 'Library of Congress Code' Classification?") self.lcc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive LCC?") r = r + 1 self.lc_layout.addWidget(self.lcc_activate_checkbox, r, 0) if prefs['LCC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lcc_activate_checkbox.setChecked(True) else: self.lcc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing2 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing2, r, 0) self.spacing2.setMaximumHeight(10) #----------------------------------------------------- self.fast_labelname = QLineEdit(self) self.fast_labelname.setText(self.mytabprefs['FAST']) self.fast_labelname.setFont(font) self.fast_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for FAST Tag Values. " ) self.fast_labelname.setMinimumWidth(100) self.fast_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.fast_labelname, r, 0) self.fast_activate_checkbox = QCheckBox("Activate 'FAST' Tags?") self.fast_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive FAST Tags?\ <br><br>Text. Behaves like Tags. Not Names.<br><br>" ) r = r + 1 self.lc_layout.addWidget(self.fast_activate_checkbox, r, 0) if prefs['FAST_IS_ACTIVE'] == unicode_type(S_TRUE): self.fast_activate_checkbox.setChecked(True) else: self.fast_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing6 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing6, r, 0) self.spacing6.setMaximumHeight(10) #----------------------------------------------------- self.oclc_labelname = QLineEdit(self) self.oclc_labelname.setText(self.mytabprefs['OCLC']) self.oclc_labelname.setFont(font) self.oclc_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for OCLC-OWI.<br><br>See: #http://classify.oclc.org/classify2/ " ) self.oclc_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.oclc_labelname, r, 0) self.oclc_activate_checkbox = QCheckBox( "Activate 'Online Computer Library Center' Work ID Code?") self.oclc_activate_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to derive OCLC-OWI?") r = r + 1 self.lc_layout.addWidget(self.oclc_activate_checkbox, r, 0) if self.mytabprefs['OCLC_IS_ACTIVE'] == unicode_type(S_TRUE): self.oclc_activate_checkbox.setChecked(True) else: self.oclc_activate_checkbox.setChecked(False) #----------------------------------------------------- self.spacing5 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing5, r, 0) self.spacing5.setMaximumHeight(10) #----------------------------------------------------- self.lc_author_details_labelname = QLineEdit(self) self.lc_author_details_labelname.setText( self.mytabprefs['EXTRA_AUTHOR_DETAILS']) self.lc_author_details_labelname.setFont(font) self.lc_author_details_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for 'LC Extra Author Details'.\ <br><br>Text. Behaves like Tags. Not Names.<br><br>" ) self.lc_author_details_labelname.setMaximumWidth(100) r = r + 4 self.lc_layout.addWidget(self.lc_author_details_labelname, r, 0) self.lc_author_details_checkbox = QCheckBox( "Activate 'Library Codes Extra Author Details'?") self.lc_author_details_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to add (never delete or replace) any available Tag-like values to this Custom Column if they are associated with the OCLC-OWI Identifier?" ) r = r + 1 self.lc_layout.addWidget(self.lc_author_details_checkbox, r, 0) if self.mytabprefs['EXTRA_AUTHOR_DETAILS_IS_ACTIVE'] == unicode_type( S_TRUE): self.lc_author_details_checkbox.setChecked(True) else: self.lc_author_details_checkbox.setChecked(False) #----------------------------------------------------- #----------------------------------------------------- self.spacing4 = QLabel() r = r + 1 self.lc_layout.addWidget(self.spacing4, r, 0) self.spacing4.setMaximumHeight(10) #----------------------------------------------------- font.setBold(False) font.setPointSize(7) #----------------------------------------------------- self.push_button_autoadd_custom_columns = QPushButton( "Automatically Add Activated Custom Columns?") self.push_button_autoadd_custom_columns.clicked.connect( self.autoadd_custom_columns) self.push_button_autoadd_custom_columns.setDefault(False) self.push_button_autoadd_custom_columns.setFont(font) self.push_button_autoadd_custom_columns.setToolTip( "<p style='white-space:wrap'>Do you want to automatically add the Custom Columns selected above?<br><br>If you have any issues, please add them manually." ) r = r + 4 self.lc_layout.addWidget(self.push_button_autoadd_custom_columns, r, 0) self.push_button_autoadd_custom_columns.setMaximumWidth(250) #----------------------------------------------------- self.lc_custom_columns_generation_label = QLabel() r = r + 1 self.lc_layout.addWidget(self.lc_custom_columns_generation_label, r, 0) self.lc_custom_columns_generation_label.setText( " ") self.lc_custom_columns_generation_label.setMaximumHeight(10) self.lc_custom_columns_generation_label.setFont(font) self.oclc_identifier_only_checkbox = QCheckBox( "Always Create OCLC-OWI as an 'Identifier' (à la ISBN)?") self.oclc_identifier_only_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want to update Calibre's Identifiers for an Identifier of 'OCLC-OWI',\ regardless of whether you want its own Custom Column updated?\ <br><br>REQUIRED to derive DDC/LCC using Author/Title." ) r = r + 2 self.lc_layout.addWidget(self.oclc_identifier_only_checkbox, r, 0) if prefs['OCLC_IDENTIFIER'] == unicode_type(S_TRUE): self.oclc_identifier_only_checkbox.setChecked(True) else: self.oclc_identifier_only_checkbox.setChecked(False) #----------------------------------------------------- self.spacing3 = QLabel("") r = r + 1 self.lc_layout.addWidget(self.spacing3, r, 0) self.spacing3.setMaximumHeight(10) #----------------------------------------------------- font.setBold(False) font.setPointSize(10) #----------------------------------------------------- self.lc_genre_labelname = QLineEdit(self) self.lc_genre_labelname.setText(self.mytabprefs['GENRE']) self.lc_genre_labelname.setFont(font) self.lc_genre_labelname.setToolTip( "<p style='white-space:wrap'>Custom Column Search/Lookup #name for 'Genre'.\ <br><br>Text. Behaves like Tags.<br><br>" ) self.lc_genre_labelname.setMaximumWidth(100) r = r + 1 self.lc_layout.addWidget(self.lc_genre_labelname, r, 0) self.lc_checkbox_buttongroup = QButtonGroup() self.lc_checkbox_buttongroup.setExclusive(True) self.lc_genre_ddc_checkbox = QCheckBox( "Update 'Genre' using DDC-to-Genre Mappings?") self.lc_genre_ddc_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want LC to update 'Genre' using the DDC-to-Genre mapping in Table _lc_genre_mapping?" ) r = r + 1 self.lc_layout.addWidget(self.lc_genre_ddc_checkbox, r, 0) self.lc_genre_lcc_checkbox = QCheckBox( "Update 'Genre' using LCC-to-Genre Mappings?") self.lc_genre_lcc_checkbox.setToolTip( "<p style='white-space:wrap'>Do you want LC to update 'Genre' using the LCC-to-Genre mapping in Table _lc_genre_mapping?" ) r = r + 1 self.lc_layout.addWidget(self.lc_genre_lcc_checkbox, r, 0) self.lc_genre_inactive_checkbox = QCheckBox( "Do not update 'Genre' at all") self.lc_genre_inactive_checkbox.setToolTip( "<p style='white-space:wrap'>Do no 'Genre' processing at all?") r = r + 1 self.lc_layout.addWidget(self.lc_genre_inactive_checkbox, r, 0) self.lc_checkbox_buttongroup.addButton(self.lc_genre_ddc_checkbox) self.lc_checkbox_buttongroup.addButton(self.lc_genre_lcc_checkbox) self.lc_checkbox_buttongroup.addButton(self.lc_genre_inactive_checkbox) if self.mytabprefs['GENRE_DDC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lc_genre_ddc_checkbox.setChecked(True) elif self.mytabprefs['GENRE_LCC_IS_ACTIVE'] == unicode_type(S_TRUE): self.lc_genre_lcc_checkbox.setChecked(True) elif self.mytabprefs['GENRE_IS_INACTIVE'] == unicode_type(S_TRUE): self.lc_genre_inactive_checkbox.setChecked(True) self.lc_exact_match_checkbox = QCheckBox( "DDC: Require an 'Exact Match', not a 'Best Match'?") self.lc_exact_match_checkbox.setToolTip( "<p style='white-space:wrap'>Check this checkbox if you want an exact DDC match to be required in Table _lc_genre_mapping. Otherwise, a 'best match' will be used via progressive shortening from right to left, but not past any decimal point. If there is no decimal point in a book's DDC, then no progressive shortening will be performed at all." ) r = r + 1 self.lc_layout.addWidget(self.lc_exact_match_checkbox, r, 0) if self.mytabprefs['GENRE_EXACT_MATCH'] == unicode_type(S_TRUE): self.lc_exact_match_checkbox.setChecked(True) self.spin_lcc = QSpinBox(self) self.spin_lcc.setMinimum(1) self.spin_lcc.setMaximum(50) self.spin_lcc.setProperty('value', prefs['GENRE_LCC_MATCH_LENGTH']) self.spin_lcc.setMaximumWidth(250) self.spin_lcc.setSuffix(" LCC: Maximum Length to Match") self.spin_lcc.setToolTip( "<p style='white-space:nowrap'>Maximum number of characters in the LCC that should be used to map to the 'Genre', starting from the left. A maximum of 1 guarantees a (broad) match.\ <br><br>LCCs are structured with either 1 or 2 beginning letters, so 2-character LCCs have special matching logic.\ <br><br>Example: Assume maximum = 2 for a LCC of 'Q1': Q1 would be attempted. If it failed, because the 2nd digit is a number, 'Q' would be attempted.\ <br><br>Example: Assume maximum = 2 for a LCC of 'PN1969.C65': PN would be attempted. If it failed, nothing else would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'PN1969.C65': PN19 would be attempted. If it failed, nothing else would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'Q1': Q1 would be attempted. If it failed, because the 2nd digit is a number, 'Q' would be attempted.\ <br><br>Example: Assume maximum = 4 for a LCC of 'Q389': Q389 would be attempted. If it failed, nothing else would be attempted." ) r = r + 2 self.lc_layout.addWidget(self.spin_lcc, r, 0) #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- #----------------------------------------------------- self.scroll_widget.resize(self.sizeHint()) #----------------------------------------------------- #----------------------------------------------------- self.scroll_area_frame.setWidget( self.scroll_widget ) # now that all widgets have been created and assigned to a layout... #----------------------------------------------------- #----------------------------------------------------- self.scroll_area_frame.resize(self.sizeHint()) #----------------------------------------------------- #----------------------------------------------------- self.resize(self.sizeHint())
def make_exclusive(self, item_list): excl_group = QButtonGroup(self) for item in item_list: item = getattr(self, item) excl_group.addButton(item)
def request_octo_init_settings(self, wizard, method): vbox = QVBoxLayout() next_enabled = True label = QLabel(_("Enter a label to name your device:")) name = QLineEdit() hl = QHBoxLayout() hl.addWidget(label) hl.addWidget(name) hl.addStretch(1) vbox.addLayout(hl) def clean_text(widget): text = widget.toPlainText().strip() return ' '.join(text.split()) if method in [TIM_NEW, TIM_RECOVER]: gb = QGroupBox() hbox1 = QHBoxLayout() gb.setLayout(hbox1) vbox.addWidget(gb) gb.setTitle(_("Select your seed length:")) bg_numwords = QButtonGroup() for i, count in enumerate([12, 18, 24]): rb = QRadioButton(gb) rb.setText(_("%d words") % count) bg_numwords.addButton(rb) bg_numwords.setId(rb, i) hbox1.addWidget(rb) rb.setChecked(True) cb_pin = QCheckBox(_('Enable PIN protection')) cb_pin.setChecked(True) else: text = QTextEdit() text.setMaximumHeight(60) if method == TIM_MNEMONIC: msg = _("Enter your BIP39 mnemonic:") else: msg = _("Enter the master private key beginning with xprv:") def set_enabled(): from electrum.keystore import is_xprv wizard.next_button.setEnabled(is_xprv(clean_text(text))) text.textChanged.connect(set_enabled) next_enabled = False vbox.addWidget(QLabel(msg)) vbox.addWidget(text) pin = QLineEdit() pin.setValidator(QRegExpValidator(QRegExp('[1-9]{0,9}'))) pin.setMaximumWidth(100) hbox_pin = QHBoxLayout() hbox_pin.addWidget(QLabel(_("Enter your PIN (digits 1-9):"))) hbox_pin.addWidget(pin) hbox_pin.addStretch(1) if method in [TIM_NEW, TIM_RECOVER]: vbox.addWidget(WWLabel(RECOMMEND_PIN)) vbox.addWidget(cb_pin) else: vbox.addLayout(hbox_pin) passphrase_msg = WWLabel(PASSPHRASE_HELP_SHORT) passphrase_warning = WWLabel(PASSPHRASE_NOT_PIN) passphrase_warning.setStyleSheet("color: red") cb_phrase = QCheckBox(_('Enable passphrases')) cb_phrase.setChecked(False) vbox.addWidget(passphrase_msg) vbox.addWidget(passphrase_warning) vbox.addWidget(cb_phrase) # ask for recovery type (random word order OR matrix) if method == TIM_RECOVER: gb_rectype = QGroupBox() hbox_rectype = QHBoxLayout() gb_rectype.setLayout(hbox_rectype) vbox.addWidget(gb_rectype) gb_rectype.setTitle(_("Select recovery type:")) bg_rectype = QButtonGroup() rb1 = QRadioButton(gb_rectype) rb1.setText(_('Scrambled words')) bg_rectype.addButton(rb1) bg_rectype.setId(rb1, RECOVERY_TYPE_SCRAMBLED_WORDS) hbox_rectype.addWidget(rb1) rb1.setChecked(True) rb2 = QRadioButton(gb_rectype) rb2.setText(_('Matrix')) bg_rectype.addButton(rb2) bg_rectype.setId(rb2, RECOVERY_TYPE_MATRIX) hbox_rectype.addWidget(rb2) else: bg_rectype = None wizard.exec_layout(vbox, next_enabled=next_enabled) if method in [TIM_NEW, TIM_RECOVER]: item = bg_numwords.checkedId() pin = cb_pin.isChecked() recovery_type = bg_rectype.checkedId() if bg_rectype else None else: item = ' '.join(str(clean_text(text)).split()) pin = str(pin.text()) recovery_type = None return (item, name.text(), pin, cb_phrase.isChecked(), recovery_type)
def setTableTabLayout(self): # Create Table Tab --------------------### # Create Layouts self.Vlayout = QVBoxLayout() self.H1layout = QHBoxLayout() self.H11layout = QHBoxLayout() self.H12layout = QHBoxLayout() self.H21layout = QHBoxLayout() self.V11layout = QVBoxLayout() self.V21layout = QVBoxLayout() # Create Widgets for H1layout # First buttons self.clearTableButt = QPushButton('Clear Table') self.clearTableButt.clicked.connect(self.clearTable) self.autoClearCheck = QCheckBox('Auto Clear') self.autoClearCheck.stateChanged.connect(self.checkAutoClearChanged) self.searchInputField = QLineEdit() self.searchInputField.setPlaceholderText('Enter search term, then click search') self.searchButt = QPushButton('Search Table') self.searchButt.clicked.connect(lambda: self.searchInTable(self.searchInputField.text(),2)) self.showSummaryButt = QPushButton('Show Summary') self.showSummaryButt.clicked.connect(self.showSummary) self.filterGroup = QButtonGroup() self.localFilterRadio = QRadioButton('Local',self) self.globalFilterRadio = QRadioButton('Global', self) self.configureFilterButt = QPushButton('Configure Filter') self.configureFilterButt.clicked.connect(self.configureFilter) self.localFilterRadio.clicked.connect(self.localRadioSelected) self.globalFilterRadio.clicked.connect(self.globalRadioSelected) self.H21layout.addWidget(self.localFilterRadio) self.H21layout.addWidget(self.globalFilterRadio) self.H21layout.addWidget(self.showSummaryButt) self.V21layout.addLayout(self.H21layout) self.V21layout.addWidget(self.configureFilterButt) # Add Widgets to H11layout self.H11layout.addWidget(self.clearTableButt) self.H11layout.addWidget(self.autoClearCheck) # Add Widgets to H12layout self.H12layout.addWidget(self.searchInputField) self.H12layout.addWidget(self.searchButt) self.H12layout.addStretch() self.V11layout.addLayout(self.H11layout) self.V11layout.addLayout(self.H12layout) self.H1layout.addLayout(self.V11layout) self.H1layout.addLayout(self.V21layout) self.syncUiToConfig() #------------------------------------ # Create Table self.detailTableIndex = 0 self.detailTable = QTableWidget() self.detailTableItem = QTableWidgetItem() self.detailTable.setRowCount(0) self.detailTable.setColumnCount(6) self.detailTable.setHorizontalHeaderLabels('packID;Tick;Timer;Type;Message;Length'.split(';')) self.detailTable.resizeColumnsToContents() self.detailTableHeader = self.detailTable.horizontalHeader() self.detailTableHeader.setSectionResizeMode(0, QHeaderView.ResizeToContents) self.detailTableHeader.setSectionResizeMode(1, QHeaderView.ResizeToContents) self.detailTableHeader.setSectionResizeMode(2, QHeaderView.ResizeToContents) self.detailTableHeader.setSectionResizeMode(3, QHeaderView.ResizeToContents) self.detailTableHeader.setSectionResizeMode(4, QHeaderView.Stretch) self.detailTableHeader.setSectionResizeMode(5, QHeaderView.ResizeToContents) #------------------------------------ self.Vlayout.addLayout(self.H1layout) self.Vlayout.addWidget(self.detailTable) self.dockContents.setLayout(self.Vlayout)
def setup_ui(self): # Create layout for entire dialog layout = QVBoxLayout(self) self.setLayout(layout) #Create a scroll area for the top part of the dialog self.scrollArea = QScrollArea(self) self.scrollArea.setWidgetResizable(True) # Create widget for all the contents of the dialog except the OK and Cancel buttons self.scrollContentWidget = QWidget(self.scrollArea) self.scrollArea.setWidget(self.scrollContentWidget) widgetLayout = QVBoxLayout(self.scrollContentWidget) # Add scrollArea to dialog layout.addWidget(self.scrollArea) self.other_group_box = QGroupBox(_('Other Changes')) widgetLayout.addWidget(self.other_group_box) other_group_box_layout = QVBoxLayout() self.other_group_box.setLayout(other_group_box_layout) text_dir_layout = QHBoxLayout() other_group_box_layout.addLayout(text_dir_layout) direction_label = QLabel(_('Text Direction:')) text_dir_layout.addWidget(direction_label) self.text_dir_combo = QComboBox() text_dir_layout.addWidget(self.text_dir_combo) self.text_dir_combo.addItems([_('No Conversion'), _('Horizontal'), _('Vertical')]) self.text_dir_combo.setToolTip(_('Select the desired text orientation')) self.text_dir_combo.currentIndexChanged.connect(self.update_gui) self.optimization_group_box = QGroupBox(_('Reader Device Optimization')) other_group_box_layout.addWidget(self.optimization_group_box) optimization_group_box_layout = QVBoxLayout() self.optimization_group_box.setLayout(optimization_group_box_layout) punc_group=QButtonGroup(self) self.text_dir_punc_none_button = QRadioButton("""No presentation optimization""") optimization_group_box_layout.addWidget(self.text_dir_punc_none_button) self.text_dir_punc_button = QRadioButton("""Optimize presentation for Readium reader""") self.text_dir_punc_button.setToolTip(_('Use vert/horiz punctuation presentation forms for Chrome Readium Epub3 reader')) optimization_group_box_layout.addWidget(self.text_dir_punc_button) self.text_dir_punc_kindle_button = QRadioButton("""Optimize presentation for Kindle reader""") self.text_dir_punc_kindle_button.setToolTip(_('Use vert/horiz puncuation presentation forms for Kindle reader')) optimization_group_box_layout.addWidget(self.text_dir_punc_kindle_button) self.text_dir_punc_none_button.toggled.connect(self.update_gui) self.text_dir_punc_button.toggled.connect(self.update_gui) self.text_dir_punc_kindle_button.toggled.connect(self.update_gui) source_group=QButtonGroup(self) self.file_source_button = QRadioButton(_('Selected File Only')) self.book_source_button = QRadioButton(_('Entire eBook')) source_group.addButton(self.file_source_button) source_group.addButton(self.book_source_button) self.source_group_box = QGroupBox(_('Source')) if not self.force_entire_book: widgetLayout.addWidget(self.source_group_box) source_group_box_layout = QVBoxLayout() self.source_group_box.setLayout(source_group_box_layout) source_group_box_layout.addWidget(self.file_source_button) source_group_box_layout.addWidget(self.book_source_button) layout.addSpacing(10) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._ok_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) if not self.force_entire_book: self.file_source_button.setChecked(self.prefs['use_html_file']) self.book_source_button.setChecked(self.prefs['use_entire_book']) else: self.file_source_button.setChecked(False) self.book_source_button.setChecked(True) self.text_dir_combo.setCurrentIndex(self.prefs['orientation']) self.text_dir_punc_none_button.setChecked(self.prefs['no_optimization']) self.text_dir_punc_button.setChecked(self.prefs['readium_optimization']) self.text_dir_punc_kindle_button.setChecked(self.prefs['kindle_optimization']) self.update_gui()
def make_exclusive(self, name, lst): name = QButtonGroup(self) for item in lst: name.addButton(item)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'ipetrash' from PyQt5.Qt import QApplication, QGroupBox, QCheckBox, QButtonGroup, QGridLayout def _on_button_clicked(button: QCheckBox): print(button, button.text(), button.isChecked()) app = QApplication([]) button_group = QButtonGroup() button_group.setExclusive(False) button_group.buttonClicked.connect(_on_button_clicked) buttons_array = [ [QCheckBox('a1'), QCheckBox('a2'), QCheckBox('a3')], [QCheckBox('b1'), QCheckBox('b2'), QCheckBox('b3')], [QCheckBox('c1'), QCheckBox('c2'), QCheckBox('c3')], ] main_layout = QGridLayout() for i, row in enumerate(buttons_array): for j, button in enumerate(row):
def __init__(self, plugin): DefaultConfigWidget.__init__(self, plugin) c = plugin_prefs[STORE_NAME] other_group_box = QGroupBox('Other options', self) self.l.addWidget(other_group_box, self.l.rowCount(), 0, 1, 2) other_group_box_layout = QGridLayout() other_group_box.setLayout(other_group_box_layout) # Guess Series guess_series_label = QLabel( 'Guess Series and Series Index from Title:', self) guess_series_label.setToolTip( 'DNB only rarely provides data about a book\'s series.\n' 'This plugin can try to extract series and series_index from the book title.\n' ) other_group_box_layout.addWidget(guess_series_label, 0, 0, 1, 1) self.guess_series_checkbox = QCheckBox(self) self.guess_series_checkbox.setChecked( c.get(KEY_GUESS_SERIES, DEFAULT_STORE_VALUES[KEY_GUESS_SERIES])) other_group_box_layout.addWidget(self.guess_series_checkbox, 0, 1, 1, 1) # Append Edition to Title append_edition_to_title_label = QLabel('Append Edition to Title:', self) append_edition_to_title_label.setToolTip( 'For some books DNB has information about the edition.\n' 'This plugin can fetch this information and append it to the book\'s title,\n' 'e.g. "Mord am Tegernsee : Ein Bayern-Krimi : 2. Aufl.".\n' 'Of course this only works reliable if you search for a book with a known unique identifier such as dnb-idn or ISBN.' ) other_group_box_layout.addWidget(append_edition_to_title_label, 1, 0, 1, 1) self.append_edition_to_title_checkbox = QCheckBox(self) self.append_edition_to_title_checkbox.setChecked( c.get(KEY_APPEND_EDITION_TO_TITLE, DEFAULT_STORE_VALUES[KEY_APPEND_EDITION_TO_TITLE])) other_group_box_layout.addWidget(self.append_edition_to_title_checkbox, 1, 1, 1, 1) # Fetch Subjects fetch_subjects_label = QLabel('Fetch Subjects:', self) fetch_subjects_label.setToolTip( 'DNB provides several types of subjects:\n' ' - Standardized subjects according to the GND\n' ' - Subjects delivered by the publisher\n' 'You can choose which ones to fetch.') other_group_box_layout.addWidget(fetch_subjects_label, 2, 0, 1, 1) self.fetch_subjects_radios_group = QButtonGroup(other_group_box) titles = [ 'only GND subjects', 'GND subjects if available, otherwise non-GND subjects', 'GND and non-GND subjects', 'non-GND subjects if available, otherwise GND subjects', 'only non-GND subjects', 'none' ] self.fetch_subjects_radios = [QRadioButton(title) for title in titles] for i, radio in enumerate(self.fetch_subjects_radios): if i == c.get(KEY_FETCH_SUBJECTS, DEFAULT_STORE_VALUES[KEY_FETCH_SUBJECTS]): radio.setChecked(True) self.fetch_subjects_radios_group.addButton(radio, i) other_group_box_layout.addWidget(radio, 2 + i, 1, 1, 1)
def __initUI(self): if self.__quantity == "position": for w in (self.btn_smooth_Vx, self.btn_smooth_Vy, self.x_mav_nb_pts, self.y_mav_nb_pts): w.setVisible(False) w.setEnabled(False) group = QButtonGroup(self) group.addButton(self.btn_imageSize) group.addButton(self.btn_autoSize) self.btn_imageSize.toggled.connect(self.__ImageSizePlotXYLim) self.btn_imageSize.setEnabled(False) texte = "Tracé avec les bornes min et max de l'image" self.btn_imageSize.setStatusTip(texte) self.btn_imageSize.setChecked(True) self.btn_autoSize.toggled.connect(self.__AutoSizePlotXYLim) self.btn_autoSize.setEnabled(False) texte = "Tracé avec les bornes min et max de la " texte += "trajectoire calculée" self.btn_autoSize.setStatusTip(texte) elif self.__quantity == "velocity": for w in (self.btn_imageSize, self.btn_autoSize): w.setVisible(False) w.setEnabled(False) self.btn_smooth_Vx.stateChanged.connect(self.__smooth_Vx_wanted) self.btn_smooth_Vy.stateChanged.connect(self.__smooth_Vy_wanted) self.x_mav_nb_pts.setEnabled(False) self.y_mav_nb_pts.setEnabled(False) self.x_mav_nb_pts.setRange(3, 100) self.y_mav_nb_pts.setRange(3, 100) self.x_mav_nb_pts.setSingleStep(2) self.y_mav_nb_pts.setSingleStep(2) self.x_mav_nb_pts.valueChanged.connect(self.__smooth_vX) self.y_mav_nb_pts.valueChanged.connect(self.__smooth_vY) vbox = QVBoxLayout() self.setLayout(vbox) # Ligne 1 : tracé de l'image self.setLayout(vbox) self.__figure = Figure() self.__axes1 = self.__figure.add_subplot(211) self.__axes2 = self.__figure.add_subplot(212) self.__figure.subplots_adjust(left=0.120, right=0.99, bottom=0.11, top=0.98) self.__canvas = FigureCanvas(self.__figure) self.__toolbar = NavigationToolbar(self.__canvas, self) #self.__toolbar.setMinimumWidth(450) vbox.addWidget(self.__canvas) hbox = QHBoxLayout() hbox.addWidget(self.__toolbar) hbox.addStretch() if self.__quantity == "position": hbox.addWidget(self.btn_imageSize) hbox.addWidget(self.btn_autoSize) elif self.__quantity == "velocity": vb = QVBoxLayout() hb = QHBoxLayout() hb.addWidget(self.btn_smooth_Vx) hb.addWidget(self.x_mav_nb_pts) vb.addLayout(hb) hb = QHBoxLayout() hb.addWidget(self.btn_smooth_Vy) hb.addWidget(self.y_mav_nb_pts) vb.addLayout(hb) hbox.addLayout(vb) vbox.addLayout(hbox)
def __init__(self, mainWindow): # call the base class constructor: QWidget.__init__(self, mainWindow) self.mw = mainWindow # remember he application main windwos # Attributes (persistant data) self.__figure = Figure() # the plot figure self.__axes = None # axis system self.__canvas = None # area for matplotlib plot self.__toolbar = None # plot tool bar self.__xlim = None # xmin, xmay of the plo self.__ylim = None # ymin, ymax of the plot self.__axes_aspect = 'equal' # 'equal' or 'auto' self.btn_imageSize = QRadioButton("ImageSize", self) self.btn_autoSize = QRadioButton("AutoSize", self) self.btn_axesEqual = QRadioButton("Equal", self) self.btn_axesAuto = QRadioButton("Auto", self) group = QButtonGroup(self) # pour les 2 boutons imageSize, autoSize group.addButton(self.btn_imageSize) group.addButton(self.btn_autoSize) group = QButtonGroup(self) group.addButton(self.btn_axesEqual) group.addButton(self.btn_axesAuto) self.__initUI() # Initialisation de l'interface utilisateur