def edit_rule(self, index): try: kind, col, rule = self.model.data(index, Qt.UserRole) except: return if isinstance(rule, Rule): d = RuleEditor(self.model.fm, self.pref_name) d.apply_rule(kind, col, rule) elif self.pref_name == 'column_color_rules': d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col) else: d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, icon_field_key=col, icon_rule_kind=kind) if d.exec_() == d.Accepted: if len(d.rule) == 2: # Convert template dialog rules to a triple d.rule = ('color', d.rule[0], d.rule[1]) kind, col, r = d.rule if kind and r is not None and col: self.model.replace_rule(index, kind, col, r) self.rules_view.scrollTo(index) self.changed.emit()
def do_open_editor(self): t = TemplateDialog(self, self.opt_template.text(), fm=self.field_metadata) t.setWindowTitle(_('Edit template')) if t.exec_(): self.opt_template.set_value(t.rule[1])
def show_template_editor(self, *args): view = self.gui.current_view() if view is not self.gui.library_view: return error_dialog( self.gui, _('No template tester available'), _('Template tester is not available for books ' 'on the device.')).exec_() rows = view.selectionModel().selectedRows() if not rows: return error_dialog(self.gui, _('No books selected'), _('At least one book must be selected'), show=True) mi = [] db = view.model().db for row in rows: if row.isValid(): mi.append( db.new_api.get_proxy_metadata( db.data.index_to_id(row.row()))) if mi: t = TemplateDialog(self.gui, self.previous_text, mi, text_is_placeholder=self.first_time) t.setWindowTitle(_('Template tester')) if t.exec_() == QDialog.DialogCode.Accepted: self.previous_text = t.rule[1] self.first_time = False
def show_template_editor(self, *args): view = self.gui.current_view() if view is not self.gui.library_view: return error_dialog(self.gui, _('No template tester available'), _('Template tester is not available for books ' 'on the device.')).exec_() rows = view.selectionModel().selectedRows() if not rows: return error_dialog(self.gui, _('No books selected'), _('One book must be selected'), show=True) if len(rows) > 1: return error_dialog(self.gui, _('Selected multiple books'), _('Only one book can be selected'), show=True) index = rows[0] if index.isValid(): db = view.model().db t = TemplateDialog(self.gui, self.previous_text, mi=db.get_metadata(index.row(), index_is_id=False, get_cover=False), text_is_placeholder=self.first_time) t.setWindowTitle(_('Template tester')) if t.exec_() == t.Accepted: self.previous_text = t.rule[1] self.first_time = False
def edit_cb_title_template(self): t = TemplateDialog(self, self.opt_cover_browser_title_template.text(), fm=self.gui.current_db.field_metadata) t.setWindowTitle(_('Edit template for caption')) if t.exec_(): self.opt_cover_browser_title_template.setText(t.rule[1])
def show_template_editor(self, *args): view = self.gui.current_view() if view is not self.gui.library_view: return error_dialog( self.gui, _('No template tester available'), _('Template tester is not available for books ' 'on the device.')).exec_() rows = view.selectionModel().selectedRows() if not rows: return error_dialog(self.gui, _('No books selected'), _('One book must be selected'), show=True) if len(rows) > 1: return error_dialog(self.gui, _('Selected multiple books'), _('Only one book can be selected'), show=True) index = rows[0] if index.isValid(): db = view.model().db t = TemplateDialog(self.gui, self.previous_text, mi=db.get_metadata(index.row(), index_is_id=False, get_cover=False), text_is_placeholder=self.first_time) t.setWindowTitle(_('Template tester')) if t.exec_() == t.Accepted: self.previous_text = t.rule[1] self.first_time = False
def add_advanced(self): td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') if td.exec_() == td.Accepted: col, r = td.rule if r and col: idx = self.model.add_rule('color', col, r) self.rules_view.scrollTo(idx) self.changed.emit()
def createEditor(self, parent, option, index): m = index.model() mi = m.db.get_metadata(index.row(), index_is_id=False) text = m.custom_columns[m.column_map[index.column()]]['display']['composite_template'] editor = TemplateDialog(parent, text, mi) editor.setWindowTitle(_("Edit template")) editor.textbox.setTabChangesFocus(False) editor.textbox.setTabStopWidth(20) d = editor.exec_() if d: m.setData(index, QVariant(editor.rule[1]), Qt.EditRole) return None
def createEditor(self, parent, option, index): m = index.model() mi = m.db.get_metadata(index.row(), index_is_id=False) text = m.custom_columns[m.column_map[index.column()]]['display']['composite_template'] editor = TemplateDialog(parent, text, mi) editor.setWindowTitle(_("Edit template")) editor.textbox.setTabChangesFocus(False) editor.textbox.setTabStopWidth(20) d = editor.exec_() if d: m.setData(index, (editor.rule[1]), Qt.EditRole) return None
def add_advanced(self): if self.pref_name == 'column_color_rules': td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') if td.exec_() == td.Accepted: col, r = td.rule if r and col: idx = self.model.add_rule('color', col, r) self.rules_view.scrollTo(idx) self.changed.emit() else: if self.pref_name == 'cover_grid_icon_rules': td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, doing_emblem=True) else: td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, icon_field_key='') if td.exec_() == td.Accepted: typ, col, r = td.rule if typ and r and col: idx = self.model.add_rule(typ, col, r) self.rules_view.scrollTo(idx) self.changed.emit()
def createEditor(self, parent, option, index): m = index.model() mi = m.db.get_metadata(index.row(), index_is_id=False) if check_key_modifier(Qt.KeyboardModifier.ControlModifier): text = '' else: text = m.custom_columns[m.column_map[index.column()]]['display']['composite_template'] editor = TemplateDialog(parent, text, mi) editor.setWindowTitle(_("Edit template")) editor.textbox.setTabChangesFocus(False) editor.textbox.setTabStopWidth(20) d = editor.exec_() if d: m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole) return None
def change_template(self, which): from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.ui import get_gui gui = get_gui() if gui is None: from calibre.ebooks.metadata.book.base import field_metadata else: field_metadata = gui.current_db.new_api.field_metadata attr = which + '_template' templ = getattr(self, attr).text() d = TemplateDialog(self, templ, mi=self.mi, fm=field_metadata) if d.exec_() == d.Accepted: templ = d.rule[1] getattr(self, attr).setText(templ) self.emit_changed()
def change_template(self, which): from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.ui import get_gui gui = get_gui() if gui is None: from calibre.ebooks.metadata.book.base import field_metadata else: field_metadata = gui.current_db.new_api.field_metadata attr = which + '_template' templ = getattr(self, attr).text() d = TemplateDialog(self, templ, mi=self.mi, fm=field_metadata) if d.exec_() == QDialog.DialogCode.Accepted: templ = d.rule[1] getattr(self, attr).setText(templ) self.emit_changed()
def add_advanced(self): if self.pref_name == 'column_color_rules': td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') if td.exec_() == td.Accepted: col, r = td.rule if r and col: idx = self.model.add_rule('color', col, r) self.rules_view.scrollTo(idx) self.changed.emit() else: td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, icon_field_key='') if td.exec_() == td.Accepted: print(td.rule) typ, col, r = td.rule if typ and r and col: idx = self.model.add_rule(typ, col, r) self.rules_view.scrollTo(idx) self.changed.emit()
def st_test_template(self): if self.mi: self.st_replace_button_clicked() all_funcs = copy.copy(formatter_functions().get_functions()) for n, f in self.st_funcs.items(): all_funcs[n] = f t = TemplateDialog(self.gui, self.st_previous_text, mi=self.mi, fm=self.fm, text_is_placeholder=self.st_first_time, all_functions=all_funcs) t.setWindowTitle(_('Template tester')) if t.exec() == QDialog.DialogCode.Accepted: self.st_previous_text = t.rule[1] self.st_first_time = False else: error_dialog(self.gui, _('Template functions'), _('Cannot "test" when no books are selected'), show=True)
def show_template_editor(self, *args): view = self.gui.current_view() if view is not self.gui.library_view: return error_dialog(self.gui, _('No template tester available'), _('Template tester is not available for books ' 'on the device.')).exec_() rows = view.selectionModel().selectedRows() if not rows: return error_dialog(self.gui, _('No books selected'), _('One book must be selected'), show=True) if len(rows) > 1: return error_dialog(self.gui, _('Selected multiple books'), _('Only one book can be selected'), show=True) index = rows[0] if index.isValid(): db = view.model().db t = TemplateDialog(self.gui, _('Enter a template to test using data from the selected book'), mi=db.get_metadata(index.row(), index_is_id=False, get_cover=False)) t.setWindowTitle(_('Template tester')) t.exec_()
def edit_rule(self, index): try: col, rule = self.model.data(index, Qt.UserRole) except: return if isinstance(rule, Rule): d = RuleEditor(self.model.fm) d.apply_rule(col, rule) else: d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col) if d.exec_() == d.Accepted: col, r = d.rule if r is not None and col: self.model.replace_rule(index, col, r) self.rules_view.scrollTo(index) self.changed.emit()
def createEditor(self, parent, option, index): if self.disallow_edit: editor = QLineEdit(parent) editor.setText(_('Template editing disabled')) return editor self.disallow_edit = gprefs[ 'edit_metadata_templates_only_F2_on_booklist'] from calibre.gui2.dialogs.template_dialog import TemplateDialog m = index.model() mi = m.db.get_metadata(index.row(), index_is_id=False) if check_key_modifier(Qt.KeyboardModifier.ControlModifier): text = '' else: text = m.custom_columns[m.column_map[ index.column()]]['display']['composite_template'] editor = TemplateDialog(parent, text, mi) editor.setWindowTitle(_("Edit template")) editor.textbox.setTabChangesFocus(False) editor.textbox.setTabStopWidth(20) d = editor.exec() if d: m.setData(index, (editor.rule[1]), Qt.ItemDataRole.EditRole) return None
def open_editor(self): t = TemplateDialog(self, self.text(), mi=self.mi) t.setWindowTitle(_('Edit template')) if t.exec_(): self.setText(t.rule[1])
def edit_template(self): t = TemplateDialog(self, self.template) t.setWindowTitle(_("Edit template")) if t.exec_(): self.t.setText(t.rule[1])
def edit_template(self): t = TemplateDialog(self, self.template) t.setWindowTitle(_('Edit template')) if t.exec_(): self.t.setText(t.rule[1])
def add_advanced(self): td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') self._add_rule(td)