def __init__(self, window, db, id_=None, key=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db if key: key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [ tag.strip() for tag in tags.split(',') if tag.strip() ] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if tags: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] self.tags = tags if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = list(set(all_tags)) all_tags.sort(key=sort_key) for tag in all_tags: if tag not in tags: self.available_tags.addItem(tag) self.connect(self.apply_button, SIGNAL('clicked()'), self.apply_tags) self.connect(self.unapply_button, SIGNAL('clicked()'), self.unapply_tags) self.connect(self.add_tag_button, SIGNAL('clicked()'), self.add_tag) self.connect(self.delete_button, SIGNAL('clicked()'), self.delete_tags) self.connect(self.add_tag_input, SIGNAL('returnPressed()'), self.add_tag) if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.connect(self.available_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags) self.connect(self.applied_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: self.restoreGeometry(geom)
def __init__(self, window, db, id_=None, key=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db if key: key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [tag.strip() for tag in tags.split(',') if tag.strip()] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if tags: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] self.tags = tags if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = list(set(all_tags)) all_tags.sort(key=sort_key) for tag in all_tags: if tag not in tags: self.available_tags.addItem(tag) self.connect(self.apply_button, SIGNAL('clicked()'), self.apply_tags) self.connect(self.unapply_button, SIGNAL('clicked()'), self.unapply_tags) self.connect(self.add_tag_button, SIGNAL('clicked()'), self.add_tag) self.connect(self.delete_button, SIGNAL('clicked()'), self.delete_tags) self.connect(self.add_tag_input, SIGNAL('returnPressed()'), self.add_tag) # add the handlers for the filter input clear buttons for x in ('available', 'applied'): getattr(self, '%s_filter_input_clear_btn' % x).clicked.connect(getattr(self, '%s_filter_input' % x).clear) # add the handlers for the filter input fields self.available_filter_input.textChanged.connect(self.filter_tags) self.applied_filter_input.textChanged.connect(partial(self.filter_tags, which='applied_tags')) if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.connect(self.available_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags) self.connect(self.applied_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: self.restoreGeometry(geom)
def __init__(self, window, db, id_=None, key=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db self.sep = ',' self.is_names = False if key: # Assume that if given a key then it is a custom column try: self.is_names = db.field_metadata[key]['display'].get( 'is_names', False) if self.is_names: self.sep = '&' except Exception: pass key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [ tag.strip() for tag in tags.split(',') if tag.strip() ] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if tags: if not self.is_names: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] if self.is_names: self.applied_tags.setDragDropMode(QAbstractItemView.InternalMove) self.applied_tags.setSelectionMode( QAbstractItemView.ExtendedSelection) if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = list(set(all_tags)) all_tags.sort(key=sort_key) for tag in all_tags: if tag not in tags: self.available_tags.addItem(tag) self.apply_button.clicked.connect(lambda: self.apply_tags()) self.unapply_button.clicked.connect(lambda: self.unapply_tags()) self.add_tag_button.clicked.connect(self.add_tag) self.delete_button.clicked.connect(lambda: self.delete_tags()) self.add_tag_input.returnPressed[()].connect(self.add_tag) # add the handlers for the filter input clear buttons for x in ('available', 'applied'): getattr(self, '%s_filter_input_clear_btn' % x).clicked.connect( getattr(self, '%s_filter_input' % x).clear) # add the handlers for the filter input fields self.available_filter_input.textChanged.connect(self.filter_tags) self.applied_filter_input.textChanged.connect( partial(self.filter_tags, which='applied_tags')) # Restore the focus to the last input box used (typed into) self.add_tag_input.textChanged.connect( partial(self.edit_box_changed, which="add_tag_input")) self.available_filter_input.textChanged.connect( partial(self.edit_box_changed, which="available_filter_input")) self.applied_filter_input.textChanged.connect( partial(self.edit_box_changed, which="applied_filter_input")) getattr(self, gprefs.get('tag_editor_last_filter', 'add_tag_input')).setFocus() if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.available_tags.itemActivated.connect(self.apply_tags) self.applied_tags.itemActivated.connect(self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: self.restoreGeometry(geom)
def __init__(self, window, db, id_=None, key=None, current_tags=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db self.sep = ',' self.is_names = False if key: # Assume that if given a key then it is a custom column try: fm = db.field_metadata[key] self.is_names = fm['display'].get('is_names', False) if self.is_names: self.sep = '&' self.setWindowTitle(_('Edit %s') % fm['name']) except Exception: pass key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [tag.strip() for tag in tags.split(',') if tag.strip()] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if current_tags is not None: tags = sorted(set(current_tags), key=sort_key) if tags: if not self.is_names: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] if self.is_names: self.applied_tags.setDragDropMode(QAbstractItemView.InternalMove) self.applied_tags.setSelectionMode(QAbstractItemView.ExtendedSelection) if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = sorted(set(all_tags), key=sort_key) q = set(tags) for tag in all_tags: if tag not in q: self.available_tags.addItem(tag) connect_lambda(self.apply_button.clicked, self, lambda self: self.apply_tags()) connect_lambda(self.unapply_button.clicked, self, lambda self: self.unapply_tags()) self.add_tag_button.clicked.connect(self.add_tag) connect_lambda(self.delete_button.clicked, self, lambda self: self.delete_tags()) self.add_tag_input.returnPressed[()].connect(self.add_tag) # add the handlers for the filter input fields connect_lambda(self.available_filter_input.textChanged, self, lambda self, text: self.filter_tags(text)) connect_lambda(self.applied_filter_input.textChanged, self, lambda self, text: self.filter_tags(text, which='applied_tags')) # Restore the focus to the last input box used (typed into) for x in ('add_tag_input', 'available_filter_input', 'applied_filter_input'): ibox = getattr(self, x) ibox.setObjectName(x) connect_lambda(ibox.textChanged, self, lambda self: self.edit_box_changed(self.sender().objectName())) getattr(self, gprefs.get('tag_editor_last_filter', 'add_tag_input')).setFocus() if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.available_tags.itemActivated.connect(self.apply_tags) self.applied_tags.itemActivated.connect(self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: QApplication.instance().safe_restore_geometry(self, geom)
def __init__(self, window, db, id_=None, key=None, current_tags=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db self.sep = ',' self.is_names = False if key: # Assume that if given a key then it is a custom column try: self.is_names = db.field_metadata[key]['display'].get('is_names', False) if self.is_names: self.sep = '&' except Exception: pass key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [tag.strip() for tag in tags.split(',') if tag.strip()] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if current_tags is not None: tags = sorted(set(current_tags), key=sort_key) if tags: if not self.is_names: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] if self.is_names: self.applied_tags.setDragDropMode(QAbstractItemView.InternalMove) self.applied_tags.setSelectionMode(QAbstractItemView.ExtendedSelection) if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = sorted(set(all_tags), key=sort_key) q = set(tags) for tag in all_tags: if tag not in q: self.available_tags.addItem(tag) self.apply_button.clicked.connect(lambda: self.apply_tags()) self.unapply_button.clicked.connect(lambda: self.unapply_tags()) self.add_tag_button.clicked.connect(self.add_tag) self.delete_button.clicked.connect(lambda: self.delete_tags()) self.add_tag_input.returnPressed[()].connect(self.add_tag) # add the handlers for the filter input clear buttons for x in ('available', 'applied'): getattr(self, '%s_filter_input_clear_btn' % x).clicked.connect(getattr(self, '%s_filter_input' % x).clear) # add the handlers for the filter input fields self.available_filter_input.textChanged.connect(self.filter_tags) self.applied_filter_input.textChanged.connect(partial(self.filter_tags, which='applied_tags')) # Restore the focus to the last input box used (typed into) self.add_tag_input.textChanged.connect(partial(self.edit_box_changed, which="add_tag_input")) self.available_filter_input.textChanged.connect(partial(self.edit_box_changed, which="available_filter_input")) self.applied_filter_input.textChanged.connect(partial(self.edit_box_changed, which="applied_filter_input")) getattr(self, gprefs.get('tag_editor_last_filter', 'add_tag_input')).setFocus() if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.available_tags.itemActivated.connect(self.apply_tags) self.applied_tags.itemActivated.connect(self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: self.restoreGeometry(geom)
def __init__(self, window, db, id_=None, key=None, current_tags=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db self.sep = ',' self.is_names = False if key: # Assume that if given a key then it is a custom column try: fm = db.field_metadata[key] self.is_names = fm['display'].get('is_names', False) if self.is_names: self.sep = '&' self.setWindowTitle(self.windowTitle() + ': ' + fm['name']) except Exception: pass key = db.field_metadata.key_to_label(key) else: self.setWindowTitle(self.windowTitle() + ': ' + db.field_metadata['tags']['name']) if self.sep == '&': self.add_tag_input.setToolTip( '<p>' + _('If the item you want is not in the available list, ' 'you can add it here. Accepts an ampersand-separated ' 'list of items. The items will be applied to ' 'the book.') + '</p>') else: self.add_tag_input.setToolTip( '<p>' + _('If the item you want is not in the available list, ' 'you can add it here. Accepts a comma-separated ' 'list of items. The items will be applied to ' 'the book.') + '</p>') self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [ tag.strip() for tag in tags.split(',') if tag.strip() ] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if current_tags is not None: tags = sorted(set(current_tags), key=sort_key) if tags: if not self.is_names: tags.sort(key=sort_key) else: tags = [] self.applied_model = QStringListModel(tags) p = QSortFilterProxyModel() p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) p.setSourceModel(self.applied_model) self.applied_tags.setModel(p) if self.is_names: self.applied_tags.setDragDropMode( QAbstractItemView.DragDropMode.InternalMove) self.applied_tags.setSelectionMode( QAbstractItemView.SelectionMode.ExtendedSelection) if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = sorted(set(all_tags) - set(tags), key=sort_key) self.all_tags_model = QStringListModel(all_tags) p = QSortFilterProxyModel() p.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) p.setSourceModel(self.all_tags_model) self.available_tags.setModel(p) connect_lambda(self.apply_button.clicked, self, lambda self: self.apply_tags()) connect_lambda(self.unapply_button.clicked, self, lambda self: self.unapply_tags()) self.add_tag_button.clicked.connect(self.add_tag) connect_lambda(self.delete_button.clicked, self, lambda self: self.delete_tags()) self.add_tag_input.returnPressed[()].connect(self.add_tag) # add the handlers for the filter input fields connect_lambda(self.available_filter_input.textChanged, self, lambda self, text: self.filter_tags(text)) connect_lambda( self.applied_filter_input.textChanged, self, lambda self, text: self.filter_tags(text, which='applied_tags')) # Restore the focus to the last input box used (typed into) for x in ('add_tag_input', 'available_filter_input', 'applied_filter_input'): ibox = getattr(self, x) ibox.setObjectName(x) connect_lambda( ibox.textChanged, self, lambda self: self.edit_box_changed(self.sender().objectName())) getattr(self, gprefs.get('tag_editor_last_filter', 'add_tag_input')).setFocus() self.available_tags.setEditTriggers( QAbstractItemView.EditTrigger.NoEditTriggers) self.applied_tags.setEditTriggers( QAbstractItemView.EditTrigger.NoEditTriggers) if islinux: self.available_tags.doubleClicked.connect(self.apply_tags) self.applied_tags.doubleClicked.connect(self.unapply_tags) else: self.available_tags.activated.connect(self.apply_tags) self.applied_tags.activated.connect(self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: QApplication.instance().safe_restore_geometry(self, geom)
def __init__(self, window, db, id_=None, key=None): QDialog.__init__(self, window) Ui_TagEditor.__init__(self) self.setupUi(self) self.db = db if key: key = db.field_metadata.key_to_label(key) self.key = key self.index = db.row(id_) if id_ is not None else None if self.index is not None: if key is None: tags = self.db.tags(self.index) if tags: tags = [ tag.strip() for tag in tags.split(',') if tag.strip() ] else: tags = self.db.get_custom(self.index, label=key) else: tags = [] if tags: tags.sort(key=sort_key) for tag in tags: self.applied_tags.addItem(tag) else: tags = [] self.tags = tags if key: all_tags = [tag for tag in self.db.all_custom(label=key)] else: all_tags = [tag for tag in self.db.all_tags()] all_tags = list(set(all_tags)) all_tags.sort(key=sort_key) for tag in all_tags: if tag not in tags: self.available_tags.addItem(tag) self.apply_button.clicked.connect(lambda: self.apply_tags()) self.unapply_button.clicked.connect(lambda: self.unapply_tags()) self.add_tag_button.clicked.connect(self.add_tag) self.delete_button.clicked.connect(lambda: self.delete_tags()) self.add_tag_input.returnPressed[()].connect(self.add_tag) # add the handlers for the filter input clear buttons for x in ('available', 'applied'): getattr(self, '%s_filter_input_clear_btn' % x).clicked.connect( getattr(self, '%s_filter_input' % x).clear) # add the handlers for the filter input fields self.available_filter_input.textChanged.connect(self.filter_tags) self.applied_filter_input.textChanged.connect( partial(self.filter_tags, which='applied_tags')) if islinux: self.available_tags.itemDoubleClicked.connect(self.apply_tags) else: self.available_tags.itemActivated.connect(self.apply_tags) self.applied_tags.itemActivated.connect(self.unapply_tags) geom = gprefs.get('tag_editor_geometry', None) if geom is not None: self.restoreGeometry(geom)