class AudioInfoDialog(QDialog): def __init__(self, audios_name, audios_delay, audios_language, audios_track_name, audios_set_default, audios_set_forced, audios_default_value_delay, audios_default_value_language, audios_default_value_track_name, audios_default_value_set_default, audios_default_value_set_forced, audio_set_default_disabled=False, audio_set_forced_disabled=False, disable_edit=False, parent=None): super().__init__(parent) self.window_title = "Audio Info" self.state = "no" self.audios_count = len(audios_delay) self.messageIcon = QLabel() self.audio_tab_comboBox = InfoCellDialogTabComboBox( hint="Audios Groups") for i in range(self.audios_count): self.audio_tab_comboBox.addItem("Audio #" + str(i + 1)) self.audio_tab_comboBox.setCurrentIndex(0) self.audio_tab_comboBox.currentIndexChanged.connect( self.update_current_audio_index) self.current_audio_index = 0 self.disable_edit = disable_edit self.current_audio_name = audios_name self.current_audio_language = audios_language self.current_audio_delay = audios_delay self.current_audio_track_name = audios_track_name self.current_audio_set_default = audios_set_default self.current_audio_set_forced = audios_set_forced self.default_audio_language = audios_default_value_language self.default_audio_delay = audios_default_value_delay self.default_audio_track_name = audios_default_value_track_name self.default_audio_set_default = audios_default_value_set_default self.default_audio_set_forced = audios_default_value_set_forced self.audio_set_default_disabled = audio_set_default_disabled self.audio_set_forced_disabled = audio_set_forced_disabled self.audio_name_label = QLabel("Audio Name:") self.audio_name_value = QLabel( str(self.current_audio_name[self.current_audio_index])) width_to_be_fixed = 0 for i in range(len(self.current_audio_name)): width_to_be_fixed = max( width_to_be_fixed, self.audio_name_value.fontMetrics().boundingRect( self.current_audio_name[i]).width()) self.audio_name_value.setFixedWidth(width_to_be_fixed + 10) self.audio_delay_label = QLabel("Audio Delay:") self.audio_delay_spin = QDoubleSpinBox() self.setup_audio_delay_spin() self.audio_language_label = QLabel("Audio Language:") self.audio_language_comboBox = QComboBox() self.setup_audio_language_comboBox() self.audio_track_name_label = QLabel("Audio Track Name:") self.audio_track_name_lineEdit = QLineEdit() self.setup_audio_track_name_lineEdit() self.audio_set_forced_label = QLabel("Audio Forced State:") self.audio_set_forced_checkBox = QCheckBox() self.setup_audio_set_forced_checkBox() self.audio_set_default_label = QLabel("Audio Default State:") self.audio_set_default_checkBox = QCheckBox() self.setup_audio_set_default_checkBox() self.yes_button = QPushButton("OK") self.no_button = QPushButton("Cancel") self.reset_button = QPushButton("Reset To Default") self.buttons_layout = QHBoxLayout() self.audio_delay_layout = QHBoxLayout() self.audio_language_layout = QHBoxLayout() self.audio_track_name_layout = QHBoxLayout() self.audio_set_default_layout = QHBoxLayout() self.audio_set_forced_layout = QHBoxLayout() self.buttons_layout.addWidget(QLabel(""), stretch=3) self.buttons_layout.addWidget(self.reset_button, stretch=2) self.buttons_layout.addWidget(self.yes_button, stretch=2) self.buttons_layout.addWidget(self.no_button, stretch=2) self.buttons_layout.addWidget(QLabel(""), stretch=3) self.audio_setting_layout = QGridLayout() self.audio_editable_setting_layout = QFormLayout() self.audio_editable_setting_layout.addRow(self.audio_name_label, self.audio_name_value) self.audio_editable_setting_layout.addRow( self.audio_track_name_label, self.audio_track_name_lineEdit) self.audio_editable_setting_layout.addRow(self.audio_language_label, self.audio_language_comboBox) self.audio_editable_setting_layout.addRow(self.audio_delay_label, self.audio_delay_spin) self.audio_editable_setting_layout.addRow( self.audio_set_default_label, self.audio_set_default_checkBox) self.audio_editable_setting_layout.addRow( self.audio_set_forced_label, self.audio_set_forced_checkBox) self.audio_setting_layout.addWidget(self.audio_tab_comboBox, 0, 0) self.audio_setting_layout.addLayout(self.audio_editable_setting_layout, 1, 0, 5, 2) self.audio_setting_layout.addWidget(self.messageIcon, 1, 3, 5, -1) self.main_layout = QGridLayout() self.main_layout.addLayout(self.audio_setting_layout, 0, 0, 2, 3) self.main_layout.addLayout(self.buttons_layout, 2, 0, 1, -1) self.main_layout.setContentsMargins(20, 20, 20, 20) self.setLayout(self.main_layout) self.setup_ui() self.signal_connect() def setup_ui(self): self.disable_question_mark_window() self.messageIcon.setPixmap( QtGui.QPixmap(GlobalFiles.AudioIconPath).scaledToHeight(100)) self.set_dialog_values() self.set_default_buttons() if self.audio_set_default_disabled: self.audio_set_default_disable() if self.audio_set_forced_disabled: self.audio_set_forced_disable() if self.disable_edit: self.audio_track_name_lineEdit.setEnabled(False) self.audio_language_comboBox.setEnabled(False) self.audio_delay_spin.setEnabled(False) self.audio_set_default_checkBox.setEnabled(False) self.audio_set_forced_checkBox.setEnabled(False) self.reset_button.setEnabled(False) self.setup_tool_tip_hint_audio_set_default() self.setup_tool_tip_hint_audio_set_forced() def signal_connect(self): self.audio_track_name_lineEdit.textEdited.connect( self.update_current_audio_track_name) self.audio_delay_spin.editingFinished.connect( self.update_current_audio_delay) self.audio_language_comboBox.currentTextChanged.connect( self.update_current_audio_language) self.audio_set_default_checkBox.stateChanged.connect( self.update_current_audio_set_default) self.audio_set_forced_checkBox.stateChanged.connect( self.update_current_audio_set_forced) self.yes_button.clicked.connect(self.click_yes) self.no_button.clicked.connect(self.click_no) self.reset_button.clicked.connect(self.reset_audio_setting) def click_yes(self): self.state = "yes" self.close() def click_no(self): self.state = "no" self.close() def set_dialog_values(self): self.setWindowTitle(self.window_title) self.setWindowIcon(GlobalFiles.InfoSettingIcon) def disable_question_mark_window(self): self.setWindowFlag(Qt.WindowContextHelpButtonHint, on=False) def increase_message_font_size(self, value): message_font = self.message.font() message_font.setPointSize(self.message.fontInfo().pointSize() + value) self.message.setFont(message_font) def set_default_buttons(self): self.yes_button.setDefault(True) self.yes_button.setFocus() def showEvent(self, a0: QtGui.QShowEvent) -> None: super().showEvent(a0) self.setFixedSize(self.size()) def setup_audio_track_name_lineEdit(self): self.audio_track_name_lineEdit.setClearButtonEnabled(True) self.audio_track_name_lineEdit.setText( self.current_audio_track_name[self.current_audio_index]) def setup_audio_language_comboBox(self): self.audio_language_comboBox.addItems(AllAudiosLanguages) self.audio_language_comboBox.setCurrentIndex( AllAudiosLanguages.index( self.current_audio_language[self.current_audio_index])) self.audio_language_comboBox.setMaxVisibleItems(8) self.audio_language_comboBox.setStyleSheet( "QComboBox { combobox-popup: 0; }") def setup_audio_delay_spin(self): # self.audio_delay_spin.setMaximumWidth(screen_size.width() // 16) self.audio_delay_spin.setDecimals(3) self.audio_delay_spin.setMinimum(-9999.0) self.audio_delay_spin.setMaximum(9999.0) self.audio_delay_spin.setSingleStep(0.5) self.audio_delay_spin.setValue( float(self.current_audio_delay[self.current_audio_index])) def setup_audio_set_default_checkBox(self): self.audio_set_default_checkBox.setText("Set Default") self.audio_set_default_checkBox.setChecked( bool(self.current_audio_set_default[self.current_audio_index])) def setup_audio_set_forced_checkBox(self): self.audio_set_forced_checkBox.setText("Set Forced") self.audio_set_forced_checkBox.setChecked( bool(self.current_audio_set_forced[self.current_audio_index])) def update_current_audio_track_name(self): self.current_audio_track_name[self.current_audio_index] = str( self.audio_track_name_lineEdit.text()) def update_current_audio_delay(self): self.current_audio_delay[self.current_audio_index] = round( self.audio_delay_spin.value(), 5) def update_current_audio_language(self): self.current_audio_language[self.current_audio_index] = str( self.audio_language_comboBox.currentText()) def update_current_audio_set_default(self): new_state = self.audio_set_default_checkBox.checkState() == Qt.Checked self.current_audio_set_default[self.current_audio_index] = new_state if new_state: for i in range(len(self.current_audio_set_default)): if i != self.current_audio_index: self.current_audio_set_default[i] = False def update_current_audio_set_forced(self): new_state = self.audio_set_forced_checkBox.checkState() == Qt.Checked self.current_audio_set_forced[self.current_audio_index] = new_state if new_state: for i in range(len(self.current_audio_set_forced)): if i != self.current_audio_index: self.current_audio_set_forced[i] = False def reset_audio_setting(self): self.current_audio_language[ self.current_audio_index] = self.default_audio_language[ self.current_audio_index] self.current_audio_delay[ self.current_audio_index] = self.default_audio_delay[ self.current_audio_index] self.current_audio_track_name[ self.current_audio_index] = self.default_audio_track_name[ self.current_audio_index] self.current_audio_set_default[ self.current_audio_index] = self.default_audio_set_default[ self.current_audio_index] self.current_audio_set_forced[ self.current_audio_index] = self.default_audio_set_forced[ self.current_audio_index] self.audio_language_comboBox.setCurrentIndex( AllAudiosLanguages.index( self.current_audio_language[self.current_audio_index])) self.audio_delay_spin.setValue( float(self.current_audio_delay[self.current_audio_index])) self.audio_track_name_lineEdit.setText( self.current_audio_track_name[self.current_audio_index]) self.audio_set_default_checkBox.setChecked( bool(self.current_audio_set_default[self.current_audio_index])) self.audio_set_forced_checkBox.setChecked( bool(self.current_audio_set_forced[self.current_audio_index])) def audio_set_default_disable(self): self.audio_set_default_checkBox.setDisabled(True) def audio_set_forced_disable(self): self.audio_set_forced_checkBox.setDisabled(True) def setup_tool_tip_hint_audio_set_default(self): if self.audio_set_default_checkBox.isEnabled(): self.audio_set_default_checkBox.setToolTip( "<nobr>set this audio to be the default audio track " "when play") self.audio_set_default_checkBox.setToolTipDuration(12000) else: self.audio_set_default_checkBox.setToolTip( "<nobr>set this audio to be the default audio track when play<br><b>Disabled</b> because " "option " "<b>make this audio default</b> is enabled on mux setting tab " ) self.audio_set_default_checkBox.setToolTipDuration(12000) def setup_tool_tip_hint_audio_set_forced(self): if self.audio_set_forced_checkBox.isEnabled(): self.audio_set_forced_checkBox.setToolTip( "<nobr>set this audio to be the forced audio track when " "play") self.audio_set_forced_checkBox.setToolTipDuration(12000) else: self.audio_set_forced_checkBox.setToolTip( "<nobr>set this audio to be the forced audio track when play<br><b>Disabled</b> because " "option " "<b>make this audio default and forced</b> is enabled on mux setting tab " ) self.audio_set_forced_checkBox.setToolTipDuration(12000) def update_current_audio_index(self, new_index): self.current_audio_index = new_index self.audio_delay_spin.setValue( float(self.current_audio_delay[self.current_audio_index])) self.audio_set_default_checkBox.setChecked( bool(self.current_audio_set_default[self.current_audio_index])) self.audio_set_forced_checkBox.setChecked( bool(self.current_audio_set_forced[self.current_audio_index])) self.audio_language_comboBox.setCurrentIndex( AllAudiosLanguages.index( self.current_audio_language[self.current_audio_index])) self.audio_track_name_lineEdit.setText( self.current_audio_track_name[self.current_audio_index]) self.audio_name_value.setText( str(self.current_audio_name[self.current_audio_index])) def execute(self): self.exec_()
class SubtitleInfoDialog(QDialog): def __init__(self, subtitle_name="Test", subtitle_delay=0.0, subtitle_language=Default_Subtitle_Language, subtitle_track_name="Test", subtitle_set_default=False, subtitle_set_forced=False, subtitle_default_value_delay=0.0, subtitle_default_value_language=Default_Subtitle_Language, subtitle_default_value_track_name="Test", subtitle_default_value_set_default=False, subtitle_default_value_set_forced=False, subtitle_set_default_disabled=False, subtitle_set_forced_disabled=False, disable_edit=False, parent=None): super().__init__(parent) self.window_title = "Subtitle Info" self.state = "no" self.messageIcon = QLabel() self.disable_edit = disable_edit self.current_subtitle_language = str(subtitle_language) self.current_subtitle_delay = str(subtitle_delay) self.current_subtitle_track_name = str(subtitle_track_name) self.current_subtitle_set_default = subtitle_set_default self.current_subtitle_set_forced = subtitle_set_forced self.default_subtitle_language = str(subtitle_default_value_language) self.default_subtitle_delay = str(subtitle_default_value_delay) self.default_subtitle_track_name = str( subtitle_default_value_track_name) self.default_subtitle_set_default = subtitle_default_value_set_default self.default_subtitle_set_forced = subtitle_default_value_set_forced self.subtitle_set_default_disabled = subtitle_set_default_disabled self.subtitle_set_forced_disabled = subtitle_set_forced_disabled self.subtitle_name_label = QLabel("Subtitle Name:") self.subtitle_name_value = QLabel(str(subtitle_name)) self.subtitle_delay_label = QLabel("Subtitle Delay:") self.subtitle_delay_spin = QDoubleSpinBox() self.setup_subtitle_delay_spin() self.subtitle_language_label = QLabel("Subtitle Language:") self.subtitle_language_comboBox = QComboBox() self.setup_subtitle_language_comboBox() self.subtitle_track_name_label = QLabel("Subtitle Track Name:") self.subtitle_track_name_lineEdit = QLineEdit() self.setup_subtitle_track_name_lineEdit() self.subtitle_set_forced_label = QLabel("Subtitle Forced State:") self.subtitle_set_forced_checkBox = QCheckBox() self.setup_subtitle_set_forced_checkBox() self.subtitle_set_default_label = QLabel("Subtitle Default State:") self.subtitle_set_default_checkBox = QCheckBox() self.setup_subtitle_set_default_checkBox() self.yes_button = QPushButton("OK") self.no_button = QPushButton("Cancel") self.reset_button = QPushButton("Reset To Default") self.buttons_layout = QHBoxLayout() self.subtitle_delay_layout = QHBoxLayout() self.subtitle_language_layout = QHBoxLayout() self.subtitle_track_name_layout = QHBoxLayout() self.subtitle_set_default_layout = QHBoxLayout() self.subtitle_set_forced_layout = QHBoxLayout() self.buttons_layout.addWidget(QLabel(""), stretch=3) self.buttons_layout.addWidget(self.reset_button, stretch=2) self.buttons_layout.addWidget(self.yes_button, stretch=2) self.buttons_layout.addWidget(self.no_button, stretch=2) self.buttons_layout.addWidget(QLabel(""), stretch=3) self.subtitle_setting_layout = QGridLayout() self.subtitle_changeble_setting_layout = QFormLayout() self.subtitle_changeble_setting_layout.addRow(self.subtitle_name_label, self.subtitle_name_value) self.subtitle_changeble_setting_layout.addRow( self.subtitle_track_name_label, self.subtitle_track_name_lineEdit) self.subtitle_changeble_setting_layout.addRow( self.subtitle_language_label, self.subtitle_language_comboBox) self.subtitle_changeble_setting_layout.addRow( self.subtitle_delay_label, self.subtitle_delay_spin) self.subtitle_changeble_setting_layout.addRow( self.subtitle_set_default_label, self.subtitle_set_default_checkBox) self.subtitle_changeble_setting_layout.addRow( self.subtitle_set_forced_label, self.subtitle_set_forced_checkBox) self.subtitle_setting_layout.addLayout( self.subtitle_changeble_setting_layout, 0, 0, 5, 2) self.subtitle_setting_layout.addWidget(self.messageIcon, 0, 3, 5, -1) self.main_layout = QGridLayout() self.main_layout.addLayout(self.subtitle_setting_layout, 0, 0, 2, 3) self.main_layout.addLayout(self.buttons_layout, 2, 0, 1, -1) self.main_layout.setContentsMargins(20, 20, 20, 20) self.setLayout(self.main_layout) self.setup_ui() self.signal_connect() def setup_ui(self): self.disable_question_mark_window() self.messageIcon.setPixmap( QtGui.QPixmap(GlobalFiles.SubtitleIconPath).scaledToHeight(100)) self.set_dialog_values() self.set_default_buttons() if self.subtitle_set_default_disabled: self.subtitle_set_default_disable() if self.subtitle_set_forced_disabled: self.subtitle_set_forced_disable() if self.disable_edit: self.subtitle_track_name_lineEdit.setEnabled(False) self.subtitle_language_comboBox.setEnabled(False) self.subtitle_delay_spin.setEnabled(False) self.subtitle_set_default_checkBox.setEnabled(False) self.subtitle_set_forced_checkBox.setEnabled(False) self.reset_button.setEnabled(False) self.setup_tool_tip_hint_subtitle_set_default() self.setup_tool_tip_hint_subtitle_set_forced() def signal_connect(self): self.subtitle_track_name_lineEdit.textEdited.connect( self.update_current_subtitle_track_name) self.subtitle_delay_spin.editingFinished.connect( self.update_current_subtitle_delay) self.subtitle_language_comboBox.currentTextChanged.connect( self.update_current_subtitle_language) self.subtitle_set_default_checkBox.stateChanged.connect( self.update_current_subtitle_set_default) self.subtitle_set_forced_checkBox.stateChanged.connect( self.update_current_subtitle_set_forced) self.yes_button.clicked.connect(self.click_yes) self.no_button.clicked.connect(self.click_no) self.reset_button.clicked.connect(self.reset_subtitle_setting) def click_yes(self): self.state = "yes" self.close() def click_no(self): self.close() def set_dialog_values(self): self.setWindowTitle(self.window_title) self.setWindowIcon(GlobalFiles.InfoSettingIcon) def disable_question_mark_window(self): self.setWindowFlag(Qt.WindowContextHelpButtonHint, on=False) def increase_message_font_size(self, value): message_font = self.message.font() message_font.setPointSize(self.message.fontInfo().pointSize() + value) self.message.setFont(message_font) def set_default_buttons(self): self.yes_button.setDefault(True) self.yes_button.setFocus() def showEvent(self, a0: QtGui.QShowEvent) -> None: super().showEvent(a0) self.setFixedSize(self.size()) def setup_subtitle_track_name_lineEdit(self): self.subtitle_track_name_lineEdit.setClearButtonEnabled(True) self.subtitle_track_name_lineEdit.setText( self.current_subtitle_track_name) def setup_subtitle_language_comboBox(self): self.subtitle_language_comboBox.addItems(AllSubtitlesLanguages) self.subtitle_language_comboBox.setCurrentIndex( AllSubtitlesLanguages.index(self.current_subtitle_language)) self.subtitle_language_comboBox.setMaxVisibleItems(8) self.subtitle_language_comboBox.setStyleSheet( "QComboBox { combobox-popup: 0; }") def setup_subtitle_delay_spin(self): # self.subtitle_delay_spin.setMaximumWidth(screen_size.width() // 16) self.subtitle_delay_spin.setDecimals(3) self.subtitle_delay_spin.setMinimum(-9999.0) self.subtitle_delay_spin.setMaximum(9999.0) self.subtitle_delay_spin.setSingleStep(0.5) self.subtitle_delay_spin.setValue(float(self.current_subtitle_delay)) def setup_subtitle_set_default_checkBox(self): self.subtitle_set_default_checkBox.setText("Set Default") self.subtitle_set_default_checkBox.setChecked( bool(self.current_subtitle_set_default)) def setup_subtitle_set_forced_checkBox(self): self.subtitle_set_forced_checkBox.setText("Set Forced") self.subtitle_set_forced_checkBox.setChecked( bool(self.current_subtitle_set_forced)) def update_current_subtitle_track_name(self): self.current_subtitle_track_name = str( self.subtitle_track_name_lineEdit.text()) def update_current_subtitle_delay(self): self.current_subtitle_delay = round(self.subtitle_delay_spin.value(), 5) def update_current_subtitle_language(self): self.current_subtitle_language = str( self.subtitle_language_comboBox.currentText()) def update_current_subtitle_set_default(self): self.current_subtitle_set_default = ( self.subtitle_set_default_checkBox.checkState() == Qt.Checked) def update_current_subtitle_set_forced(self): self.current_subtitle_set_forced = ( self.subtitle_set_forced_checkBox.checkState() == Qt.Checked) def reset_subtitle_setting(self): self.current_subtitle_language = self.default_subtitle_language self.current_subtitle_delay = self.default_subtitle_delay self.current_subtitle_track_name = self.default_subtitle_track_name self.current_subtitle_set_default = self.default_subtitle_set_default self.current_subtitle_set_forced = self.default_subtitle_set_forced self.subtitle_language_comboBox.setCurrentIndex( AllSubtitlesLanguages.index(self.current_subtitle_language)) self.subtitle_delay_spin.setValue(float(self.current_subtitle_delay)) self.subtitle_track_name_lineEdit.setText( self.current_subtitle_track_name) self.subtitle_set_default_checkBox.setChecked( bool(self.current_subtitle_set_default)) self.subtitle_set_forced_checkBox.setChecked( bool(self.current_subtitle_set_forced)) def subtitle_set_default_disable(self): self.subtitle_set_default_checkBox.setDisabled(True) def subtitle_set_forced_disable(self): self.subtitle_set_forced_checkBox.setDisabled(True) def setup_tool_tip_hint_subtitle_set_default(self): if self.subtitle_set_default_checkBox.isEnabled(): self.subtitle_set_default_checkBox.setToolTip( "<nobr>set this subtitle to be the default subtitle track " "when play") self.subtitle_set_default_checkBox.setToolTipDuration(12000) else: self.subtitle_set_default_checkBox.setToolTip( "<nobr>set this subtitle to be the default subtitle track when play<br><b>Disabled</b> because " "option " "<b>make this subtitle default</b> is enabled on mux setting tab " ) self.subtitle_set_default_checkBox.setToolTipDuration(12000) def setup_tool_tip_hint_subtitle_set_forced(self): if self.subtitle_set_forced_checkBox.isEnabled(): self.subtitle_set_forced_checkBox.setToolTip( "<nobr>set this subtitle to be the forced subtitle track when " "play") self.subtitle_set_forced_checkBox.setToolTipDuration(12000) else: self.subtitle_set_forced_checkBox.setToolTip( "<nobr>set this subtitle to be the forced subtitle track when play<br><b>Disabled</b> because " "option " "<b>make this subtitle default and forced</b> is enabled on mux setting tab " ) self.subtitle_set_forced_checkBox.setToolTipDuration(12000) def execute(self): self.exec_()
class guiMain(QMainWindow): def __init__(self, bk, prefs): super(guiMain, self).__init__() self.taglist = taglist # Edit Plugin container object self.bk = bk # Handy prefs groupings self.gui_prefs = prefs['gui_selections'] self.misc_prefs = prefs['miscellaneous_settings'] self.update_prefs = prefs['update_settings'] self.combobox_values = prefs['combobox_values'] self._ok_to_close = False # Check online github files for newer version self.update, self.newversion = self.check_for_update() self.setup_ui() def setup_ui(self): app = QApplication.instance() p = app.palette() link_color = p.color(p.Active, p.Link).name() DELETE_STR = _t('guiMain', 'Delete') MODIFY_STR = _t('guiMain', 'Modify') self.NO_ATTRIB_STR = _t('guiMain', 'No attributes (naked tag)') self.NO_CHANGE_STR = _t('guiMain', 'No change') self.setWindowTitle(_t('guiMain', 'Tag Mechanic')) configAct = QAction(_t('guiMain', '&Config'), self) configAct.triggered.connect(self.showConfig) menubar = self.menuBar() fileMenu = menubar.addMenu(_t('guiMain', '&Edit')) fileMenu.addAction(configAct) layout = QVBoxLayout() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) if self.update: update_layout = QHBoxLayout() layout.addLayout(update_layout) self.label = QLabel() self.label.setText( _t('guiMain', 'Plugin Update Available') + ' ' + str(self.newversion)) self.label.setStyleSheet( 'QLabel {{color: {};}}'.format(link_color)) update_layout.addWidget(self.label) action_layout = QHBoxLayout() layout.addLayout(action_layout) label = QLabel(_t('guiMain', 'Action type:'), self) action_layout.addWidget(label) self.action_combo = QComboBox() action_layout.addWidget(self.action_combo) self.action_combo.addItems([DELETE_STR, MODIFY_STR]) self.action_combo.setCurrentIndex(self.gui_prefs['action']) self.action_combo.currentIndexChanged.connect(self.update_gui) tag_layout = QHBoxLayout() layout.addLayout(tag_layout) label = QLabel(_t('guiMain', 'Tag name:'), self) tag_layout.addWidget(label) self.tag_combo = QComboBox() tag_layout.addWidget(self.tag_combo) self.tag_combo.addItems(self.taglist) self.tag_combo.setCurrentIndex(self.gui_prefs['tag']) self.tag_combo.currentIndexChanged.connect(self.update_gui) attr_layout = QHBoxLayout() layout.addLayout(attr_layout) label = QLabel(_t('guiMain', 'Having the attribute:'), self) attr_layout.addWidget(label) self.attr_combo = QComboBox() attr_layout.addWidget(self.attr_combo) self.attr_combo.addItems(self.combobox_values['attrs']) self.attr_combo.addItem(self.NO_ATTRIB_STR) self.attr_combo.setCurrentIndex(self.gui_prefs['attrs']) self.attr_combo.currentIndexChanged.connect(self.update_gui) srch_layout = QHBoxLayout() layout.addLayout(srch_layout) label = QLabel(_t('guiMain', 'Whose value is (no quotes):'), self) srch_layout.addWidget(label) self.srch_txt = QLineEdit('', self) srch_layout.addWidget(self.srch_txt) self.srch_method = QCheckBox(_t('guiMain', 'Regex'), self) srch_layout.addWidget(self.srch_method) newtag_layout = QHBoxLayout() layout.addLayout(newtag_layout) label = QLabel(_t('guiMain', 'Change tag to:'), self) newtag_layout.addWidget(label) self.newtag_combo = QComboBox() newtag_layout.addWidget(self.newtag_combo) self.newtag_combo.addItem(self.NO_CHANGE_STR) self.newtag_combo.addItems(self.combobox_values['{}_changes'.format( str(self.tag_combo.currentText()))]) if self.action_combo.currentIndex() == 0: self.newtag_combo.setDisabled(True) newattr_layout = QVBoxLayout() layout.addLayout(newattr_layout) label = QLabel( _t('guiMain', 'New attribute string to insert (entire):'), self) newattr_layout.addWidget(label) self.newattr_txt = QLineEdit('', self) newattr_layout.addWidget(self.newattr_txt) self.copy_attr = QCheckBox( _t('guiMain', 'Copy existing attribute string'), self) self.copy_attr.stateChanged.connect(self.update_txt_box) newattr_layout.addWidget(self.copy_attr) if self.action_combo.currentIndex() == 0: self.copy_attr.setDisabled(True) self.newattr_txt.setDisabled(True) layout.addSpacing(10) self.text_panel = QTextEdit() self.text_panel.setReadOnly(True) layout.addWidget(self.text_panel) layout.addSpacing(10) button_layout = QHBoxLayout() layout.addLayout(button_layout) self.process_button = QPushButton(_t('guiMain', 'Process'), self) self.process_button.setToolTip('<p>{}'.format( _t('guiMain', 'Process selected files with current criteria'))) self.process_button.clicked.connect(self._process_clicked) button_layout.addWidget(self.process_button) self.abort_button = QPushButton(_t('guiMain', 'Abort Changes'), self) self.abort_button.setToolTip('<p>{}'.format( _t('guiMain', 'Make no changes and exit'))) self.abort_button.clicked.connect(self._abort_clicked) self.abort_button.setDisabled(True) button_layout.addWidget(self.abort_button) self.quit_button = QPushButton(_t('guiMain', 'Quit'), self) self.quit_button.setToolTip('<p>{}'.format( _t('guiMain', 'Quit with no changes'))) self.quit_button.clicked.connect(self._quit_clicked) button_layout.addWidget(self.quit_button) if self.misc_prefs['windowGeometry'] is not None: try: self.restoreGeometry( QByteArray.fromHex( self.misc_prefs['windowGeometry'].encode('ascii'))) except Exception: pass self.show() def update_gui(self): if self.attr_combo.currentIndex() == self.attr_combo.count() - 1: self.srch_txt.clear() self.srch_txt.setDisabled(True) self.srch_method.setChecked(False) self.srch_method.setDisabled(True) else: self.srch_txt.setDisabled(False) self.srch_method.setDisabled(False) self.newtag_combo.clear() self.newtag_combo.addItem(self.NO_CHANGE_STR) self.newtag_combo.addItems(self.combobox_values['{}_changes'.format( str(self.tag_combo.currentText()))]) if self.action_combo.currentIndex() == 0: self.newtag_combo.setCurrentIndex(0) self.newtag_combo.setDisabled(True) self.newattr_txt.clear() self.newattr_txt.setDisabled(True) self.copy_attr.setChecked(False) self.copy_attr.setDisabled(True) else: self.newtag_combo.setDisabled(False) self.newattr_txt.setDisabled(False) self.copy_attr.setDisabled(False) self.update_txt_box() def update_txt_box(self): if self.copy_attr.isChecked() or not self.copy_attr.isEnabled(): self.newattr_txt.clear() self.newattr_txt.setDisabled(True) else: self.newattr_txt.setDisabled(False) def refresh_attr_values(self): self.attr_combo.clear() self.attr_combo.addItems(self.combobox_values['attrs']) self.attr_combo.addItem(self.NO_ATTRIB_STR) def _process_clicked(self): criteria = {} global PROCESSED criteria['tag'] = str(self.tag_combo.currentText()) if self.action_combo.currentIndex() == 0: criteria['action'] = 'delete' else: criteria['action'] = 'modify' if self.attr_combo.currentIndex() == self.attr_combo.count() - 1: criteria['attrib'] = None else: criteria['attrib'] = str(self.attr_combo.currentText()) srch_str = str(self.srch_txt.displayText()) if not len(srch_str): srch_str = None if srch_str is None and criteria['attrib'] is not None: title = _t('guiMain', 'Error') msg = '<p>{0}'.format( _t('guiMain', 'Must enter a value for the attribute selected')) return QMessageBox.warning(self, title, msg, QMessageBox.Ok) criteria['srch_str'] = srch_str criteria['srch_method'] = 'normal' if self.srch_method.isChecked(): criteria['srch_method'] = 'regex' if self.newtag_combo.currentIndex() == 0: criteria['new_tag'] = None else: criteria['new_tag'] = str(self.newtag_combo.currentText()) if criteria['action'] == 'modify' and criteria[ 'new_tag'] is None and self.copy_attr.isChecked(): title = _t('guiMain', 'Error') msg = '<p>{0}'.format( _t('guiMain', 'What--exactly--would that achieve?')) return QMessageBox.question(self, title, msg, QMessageBox.Ok) criteria['new_str'] = str(self.newattr_txt.displayText()) criteria['copy'] = False if self.copy_attr.isChecked(): criteria['copy'] = True if not len(criteria['new_str']): criteria['new_str'] = '' # Disable the 'Process' button, disable the context customization menu self.process_button.setDisabled(True) PROCESSED = True totals = 0 self.text_panel.clear() self.text_panel.insertHtml('<h4>{}...</h4><br>'.format( _t('guiMain', 'Starting'))) # Loop through the files selected in Sigil's Book View for (typ, ident) in self.bk.selected_iter(): # Skip the ones that aren't the "Text" mimetype. if self.bk.id_to_mime(ident) != 'application/xhtml+xml': continue href = self.bk.id_to_href(ident) # Param 1 - the contents of the (x)html file. criteria['html'] = self.bk.readfile(ident) if not isinstance(criteria['html'], str): criteria['html'] = str(criteria['html'], 'utf-8') # Hand off the "criteria" parameters dictionary to the parsing engine parser = MarkupParser(criteria) # Retrieve the new markup and the number of occurrences changed try: html, occurrences = parser.processml() except Exception: self.text_panel.insertHtml('<p>{} {}! {}.</p>\n'.format( _t('guiMain', 'Error parsing'), href, _t('guiMain', 'File skipped'))) continue # Report whether or not changes were made (and how many) totals += occurrences if occurrences: # write changed markup back to file self.bk.writefile(ident, html) self.text_panel.insertHtml( '<p>{} {}:   {}</p>\n'.format( _t('guiMain', 'Occurrences found/changed in'), href, int(occurrences))) else: self.text_panel.insertHtml('<p>{} {}</p>\n'.format( _t('guiMain', 'Criteria not found in'), href)) # report totals if totals: self.quit_button.setText(_t('guiMain', 'Commit and Exit')) self.quit_button.setToolTip('<p>{}'.format( _t('guiMain', 'Commit all changes and exit'))) self.abort_button.setDisabled(False) self.text_panel.insertHtml( '<br><h4>{}:   {}</h4>'.format( _t('guiMain', 'Total occurrences found/changed'), int(totals))) else: self.text_panel.insertHtml('<br><h4>{}</h4>'.format( _t('guiMain', 'No changes made to book'))) self.text_panel.insertHtml('<br><h4>{}</h4>'.format( _t('guiMain', 'Finished'))) def _quit_clicked(self): self.misc_prefs['windowGeometry'] = self.saveGeometry().toHex().data( ).decode('ascii') if PROCESSED: self.gui_prefs['action'] = self.action_combo.currentIndex() self.gui_prefs['tag'] = self.tag_combo.currentIndex() self.gui_prefs['attrs'] = self.attr_combo.currentIndex() self._ok_to_close = True self.close() def _abort_clicked(self): global BAIL_OUT BAIL_OUT = True self._ok_to_close = True self.close() def getAbort(self): return BAIL_OUT def showConfig(self): ''' Launch Customization Dialog ''' dlg = ConfigDialog(self, self.combobox_values) if dlg.exec_() == QDialog.Accepted: self.refresh_attr_values() self.update_gui() def check_for_update(self): '''Use updatecheck.py to check for newer versions of the plugin''' last_time_checked = self.update_prefs['last_time_checked'] last_online_version = self.update_prefs['last_online_version'] chk = UpdateChecker(last_time_checked, last_online_version, self.bk._w) update_available, online_version, time = chk.update_info() # update preferences with latest date/time/version self.update_prefs['last_time_checked'] = time if online_version is not None: self.update_prefs['last_online_version'] = online_version if update_available: return (True, online_version) return (False, online_version) def closeEvent(self, event): if self._ok_to_close: event.accept() # let the window close else: self._abort_clicked()