def setup_ui(self): self.l = l = QVBoxLayout(self) self.la = la = QLabel( _('Create rules to convert identifiers into links.')) la.setWordWrap(True) l.addWidget(la) items = [] for k, lx in iteritems(msprefs['id_link_rules']): for n, t in lx: items.append((k, n, t)) items.sort(key=lambda x: sort_key(x[1])) self.table = t = QTableWidget(len(items), 3, self) t.setHorizontalHeaderLabels([_('Key'), _('Name'), _('Template')]) for r, (key, val, template) in enumerate(items): t.setItem(r, 0, QTableWidgetItem(key)) t.setItem(r, 1, QTableWidgetItem(val)) t.setItem(r, 2, QTableWidgetItem(template)) l.addWidget(t) t.horizontalHeader().setSectionResizeMode(2, t.horizontalHeader().Stretch) self.cb = b = QPushButton(QIcon(I('plus.png')), _('&Add rule'), self) connect_lambda(b.clicked, self, lambda self: self.edit_rule()) self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole) self.rb = b = QPushButton(QIcon(I('minus.png')), _('&Remove rule'), self) connect_lambda(b.clicked, self, lambda self: self.remove_rule()) self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole) self.eb = b = QPushButton(QIcon(I('modified.png')), _('&Edit rule'), self) connect_lambda(b.clicked, self, lambda self: self.edit_rule(self.table.currentRow())) self.bb.addButton(b, QDialogButtonBox.ButtonRole.ActionRole) l.addWidget(self.bb)
def __init__(self, parent, db, key): QDialog.__init__(self, parent) self.setWindowTitle(_('Edit permissible values for {0}').format(key)) self.db = db l = QGridLayout() bbox = QVBoxLayout() bbox.addStretch(10) self.del_button = QToolButton() self.del_button.setIcon(QIcon(I('trash.png'))) self.del_button.setToolTip(_('Remove the currently selected value')) self.ins_button = QToolButton() self.ins_button.setIcon(QIcon(I('plus.png'))) self.ins_button.setToolTip(_('Add a new permissible value')) self.move_up_button = QToolButton() self.move_up_button.setIcon(QIcon(I('arrow-up.png'))) self.move_down_button = QToolButton() self.move_down_button.setIcon(QIcon(I('arrow-down.png'))) bbox.addWidget(self.del_button) bbox.addStretch(1) bbox.addWidget(self.ins_button) bbox.addStretch(1) bbox.addWidget(self.move_up_button) bbox.addStretch(1) bbox.addWidget(self.move_down_button) bbox.addStretch(10) l.addItem(bbox, 0, 0) self.del_button.clicked.connect(self.del_line) self.all_colors = {unicode_type(s) for s in list(QColor.colorNames())} tl = QVBoxLayout() l.addItem(tl, 0, 1) self.table = t = QTableWidget(parent) t.setColumnCount(2) t.setRowCount(1) t.setHorizontalHeaderLabels([_('Value'), _('Color')]) t.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) tl.addWidget(t) self.fm = fm = db.field_metadata[key] permitted_values = fm.get('display', {}).get('enum_values', '') colors = fm.get('display', {}).get('enum_colors', '') t.setRowCount(len(permitted_values)) for i, v in enumerate(permitted_values): t.setItem(i, 0, QTableWidgetItem(v)) c = self.make_color_combobox(i, -1) if colors: c.setCurrentIndex(c.findText(colors[i])) else: c.setCurrentIndex(0) t.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeMode.Stretch) self.setLayout(l) self.bb = bb = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) l.addWidget(bb, 1, 0, 1, 2) self.ins_button.clicked.connect(self.ins_button_clicked) self.move_down_button.clicked.connect(self.move_down_clicked) self.move_up_button.clicked.connect(self.move_up_clicked) geom = gprefs.get('enum-values-edit-geometry') if geom is not None: QApplication.instance().safe_restore_geometry(self, geom)
def keyPressEvent(self, event): if event.key() == Qt.Key.Key_Delete: self.delete_pressed.emit() event.accept() return return QTableWidget.keyPressEvent(self, event)
def __init__(self, parent, mi, op_label, op_value, locals_, line_number): super().__init__(parent) self.mi = mi self.setModal(True) l = QVBoxLayout(self) t = self.table = QTableWidget(self) t.setColumnCount(2) t.setHorizontalHeaderLabels((_('Name'), _('Value'))) t.setRowCount(2) l.addWidget(t) self.table_column_widths = None try: self.table_column_widths = \ gprefs.get('template_editor_break_table_widths', None) t.setColumnWidth(0, self.table_column_widths[0]) except: t.setColumnWidth(0, t.fontMetrics().averageCharWidth() * 20) t.horizontalHeader().sectionResized.connect(self.table_column_resized) t.horizontalHeader().setStretchLastSection(True) bb = QDialogButtonBox() b = bb.addButton(_('&Continue'), QDialogButtonBox.ButtonRole.AcceptRole) b.setIcon(QIcon(I('sync-right.png'))) b.setToolTip(_('Continue running the template')) b.setDefault(True) l.addWidget(bb) b = bb.addButton(_('&Stop'), QDialogButtonBox.ButtonRole.RejectRole) b.setIcon(QIcon(I('list_remove.png'))) b.setToolTip(_('Stop running the template')) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.setLayout(l) self.setWindowTitle( _('Break: line {0}, Book {1}').format(line_number, self.mi.title)) local_names = sorted(locals_.keys()) rows = len(local_names) self.table.setRowCount(rows + 2) self.table.setItem(0, 0, BreakReporterItem(op_label)) self.table.item(0, 0).setToolTip( _('The name of the template language operation')) self.table.setItem(0, 1, BreakReporterItem(op_value)) self.mi_combo = QComboBox() t.setCellWidget(1, 0, self.mi_combo) self.mi_combo.addItems(self.get_field_keys()) self.mi_combo.setToolTip('Choose a book metadata field to display') self.mi_combo.setCurrentIndex(-1) self.mi_combo.currentTextChanged.connect(self.get_field_value) for i, k in enumerate(local_names): itm = BreakReporterItem(k) itm.setToolTip(_('A variable in the template')) self.table.setItem(i + 2, 0, itm) itm = BreakReporterItem(locals_[k]) itm.setToolTip(_('The value of the variable')) self.table.setItem(i + 2, 1, itm) try: geom = gprefs.get('template_editor_break_geometry', None) if geom is not None: QApplication.instance().safe_restore_geometry( self, QByteArray(geom)) except Exception: pass
def __init__(self, parent=None): QTableWidget.__init__(self, parent=parent)