class SelectNames(QDialog): # {{{ def __init__(self, names, txt, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout(self) self.setLayout(l) self.la = la = QLabel(_("Create a Virtual Library based on %s") % txt) l.addWidget(la) self._names = QListWidget(self) self._names.addItems(QStringList(sorted(names, key=sort_key))) self._names.setSelectionMode(self._names.ExtendedSelection) l.addWidget(self._names) self._or = QRadioButton(_("Match any of the selected %s names") % txt) self._and = QRadioButton(_("Match all of the selected %s names") % txt) self._or.setChecked(True) l.addWidget(self._or) l.addWidget(self._and) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) l.addWidget(self.bb) self.resize(self.sizeHint()) @property def names(self): for item in self._names.selectedItems(): yield unicode(item.data(Qt.DisplayRole).toString()) @property def match_type(self): return " and " if self._and.isChecked() else " or "
def genesis(self, gui): self.gui = gui self.l = l = QVBoxLayout() self.setLayout(l) self.la = la = QLabel( _('The list of devices that you have asked calibre to ignore. ' 'Uncheck a device to have calibre stop ignoring it.')) la.setWordWrap(True) l.addWidget(la) self.devices = f = QListWidget(self) l.addWidget(f) f.itemChanged.connect(self.changed_signal) f.itemDoubleClicked.connect(self.toggle_item) self.la2 = la = QLabel( _('The list of device plugins you have disabled. Uncheck an entry ' 'to enable the plugin. calibre cannot detect devices that are ' 'managed by disabled plugins.')) la.setWordWrap(True) l.addWidget(la) self.device_plugins = f = QListWidget(f) l.addWidget(f) f.itemChanged.connect(self.changed_signal) f.itemDoubleClicked.connect(self.toggle_item)
def __init__(self, parent=None, dm=None, casanova_id=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:format download dialog') self.setWindowTitle('Select format to download:') self.gui = parent self.dm = dm self.casanova_id = casanova_id layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_formats() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
def __init__(self, names, txt, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout(self) self.setLayout(l) self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt) l.addWidget(la) self._names = QListWidget(self) self._names.addItems(QStringList(sorted(names, key=sort_key))) self._names.setSelectionMode(self._names.ExtendedSelection) l.addWidget(self._names) self._or = QRadioButton(_('Match any of the selected %s names') % txt) self._and = QRadioButton(_('Match all of the selected %s names') % txt) self._or.setChecked(True) l.addWidget(self._or) l.addWidget(self._and) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) l.addWidget(self.bb) self.resize(self.sizeHint())
def __init__(self, parent, modal=True, flags=Qt.WindowFlags(), caption="Select Tags", ok_button="Select"): QDialog.__init__(self, parent, flags) self.setModal(modal) self.setWindowTitle(caption) lo = QVBoxLayout(self) lo.setMargin(10) lo.setSpacing(5) # tag selector self.wtagsel = QListWidget(self) lo.addWidget(self.wtagsel) # self.wtagsel.setColumnMode(QListBox.FitToWidth) self.wtagsel.setSelectionMode(QListWidget.MultiSelection) QObject.connect(self.wtagsel, SIGNAL("itemSelectionChanged()"), self._check_tag) # buttons lo.addSpacing(10) lo2 = QHBoxLayout() lo.addLayout(lo2) lo2.setContentsMargins(0, 0, 0, 0) lo2.setMargin(5) self.wokbtn = QPushButton(ok_button, self) self.wokbtn.setMinimumWidth(128) QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept) self.wokbtn.setEnabled(False) cancelbtn = QPushButton("Cancel", self) cancelbtn.setMinimumWidth(128) QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject) lo2.addWidget(self.wokbtn) lo2.addStretch(1) lo2.addWidget(cancelbtn) self.setMinimumWidth(384) self._tagnames = []
def __init__(self, parent=None, mm=None, choices=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:author update dialog') self.setWindowTitle('Select authors to update:') self.gui = parent self.mm = mm self.choices = choices layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_choices() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
def _init_controls(self): layout = QVBoxLayout(self) self.setLayout(layout) ml = QHBoxLayout() layout.addLayout(ml, 1) self.keys_list = QListWidget(self) self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection) self.keys_list.setFixedWidth(150) self.keys_list.setAlternatingRowColors(True) ml.addWidget(self.keys_list) self.value_text = QTextEdit(self) self.value_text.setTabStopWidth(24) self.value_text.setReadOnly(False) ml.addWidget(self.value_text, 1) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self._apply_changes) button_box.rejected.connect(self.reject) self.clear_button = button_box.addButton('Clear', QDialogButtonBox.ResetRole) self.clear_button.setIcon(get_icon('trash.png')) self.clear_button.setToolTip('Clear all settings for this plugin') self.clear_button.clicked.connect(self._clear_settings) layout.addWidget(button_box)
class SelectNames(QDialog): # {{{ def __init__(self, names, txt, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout(self) self.setLayout(l) self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt) l.addWidget(la) self._names = QListWidget(self) self._names.addItems(QStringList(sorted(names, key=sort_key))) self._names.setSelectionMode(self._names.ExtendedSelection) l.addWidget(self._names) self._and = QCheckBox(_('Match all selected %s names')%txt) l.addWidget(self._and) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) l.addWidget(self.bb) self.resize(self.sizeHint()) @property def names(self): for item in self._names.selectedItems(): yield unicode(item.data(Qt.DisplayRole).toString()) @property def match_type(self): return ' and ' if self._and.isChecked() else ' or '
def dial(self): dial = QDialog(self) dial.setWindowTitle("Select a layer") layerList = QListWidget(dial) db = GPostGISDatabase() for t in db.tables(): layerList.addItem(t) dial.setBaseSize(layerList.minimumSize()) dial.show()
def __init__(self, all_authors, parent): QListWidget.__init__(self, parent) self.setDragEnabled(True) self.setSelectionMode(self.ExtendedSelection) self.setDropIndicatorShown(True) self.setDragDropMode(self.InternalMove) self.setAlternatingRowColors(True) self.d = ItemDelegate(all_authors, self) self.d.edited.connect(self.edited, type=Qt.QueuedConnection) self.setItemDelegate(self.d)
def _loadClipboardGroupbox(self): """ Load the L{self.clipboardListWidget} widget used to display a list of clipboard items inside this clipboard groupbox. """ self.clipboardListWidget = QListWidget(self) self.gridLayout.addWidget(self.clipboardListWidget) #Append to the widget list. This is important for expand -collapse #functions (of the groupbox) to work properly. self._widgetList.append(self.clipboardListWidget)
def __init__(self, parent, layerSet=None): QListWidget.__init__(self, parent) self.setSelectionMode(QAbstractItemView.SingleSelection) if layerSet: self._layerSet = layerSet else: self._layerSet = GLayerSet() if layerSet: for l in layerSet.rawLayers: self.addItem(QListWidgetItem(l.name(), self)) self.show()
def setCurrentRow(self, row, setAsDefault=False): """ Select new row. @param row: The new row to select. @type row: int @param setAsDefault: If True, I{row} becomes the default row when "Restore Defaults" is clicked. """ if setAsDefault: self.setAsDefault = setAsDefault self.defaultRow = row QListWidget.setCurrentRow(self, row)
def setCurrentRow(self, row, setAsDefault = False ): """ Select new row. @param row: The new row to select. @type row: int @param setAsDefault: If True, I{row} becomes the default row when "Restore Defaults" is clicked. """ if setAsDefault: self.setAsDefault = setAsDefault self.defaultRow = row QListWidget.setCurrentRow(self, row)
class ChoosePluginToolbarsDialog(QDialog): def __init__(self, parent, plugin, locations): QDialog.__init__(self, parent) self.locations = locations self.setWindowTitle( _('Add "%s" to toolbars or menus')%plugin.name) self._layout = QVBoxLayout(self) self.setLayout(self._layout) self._header_label = QLabel( _('Select the toolbars and/or menus to add <b>%s</b> to:') % plugin.name) self._layout.addWidget(self._header_label) self._locations_list = QListWidget(self) self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) self._locations_list.setSizePolicy(sizePolicy) for key, text in locations: self._locations_list.addItem(text) if key in {'toolbar', 'toolbar-device'}: self._locations_list.item(self._locations_list.count()-1 ).setSelected(True) self._layout.addWidget(self._locations_list) self._footer_label = QLabel( _('You can also customise the plugin locations ' 'using <b>Preferences -> Customise the toolbar</b>')) self._layout.addWidget(self._footer_label) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) self._layout.addWidget(button_box) self.resize(self.sizeHint()) def selected_locations(self): selected = [] for row in self._locations_list.selectionModel().selectedRows(): selected.append(self.locations[row.row()]) return selected
def makeAddDataTab(self, grid): self.author_label = QLabel("Author") self.author_text = QLineEdit() self.author_text.setPlaceholderText("Author") grid.addWidget(self.author_label, 0, 0) grid.addWidget(self.author_text, 1, 0) self.title_label = QLabel("Title") self.title_text = QLineEdit() self.title_text.setPlaceholderText("Title") grid.addWidget(self.title_label, 0, 1) grid.addWidget(self.title_text, 1, 1) self.date_label = QLabel("Date Read") self.date_text = QtGui.QCalendarWidget() self.connect(self.date_text, QtCore.SIGNAL('selectionChanged()'), self.date_changed) grid.addWidget(self.date_label, 2, 1) grid.addWidget(self.date_text, 3, 1) self.grade_label = QLabel("Grade") self.grade_text = QLineEdit() self.grade_text.setPlaceholderText("Grade 1-5") grid.addWidget(self.grade_label, 2, 0) grid.addWidget(self.grade_text, 3, 0) self.comments_label = QLabel("Comments") self.comments_text = QLineEdit() self.comments_text.setPlaceholderText("Comments here") grid.addWidget(self.comments_label, 4, 0) grid.addWidget(self.comments_text, 5, 0) self.genre_label = QLabel("Genre") self.genre_list = QListWidget(self) self.genre_list.addItems(self.genreList) self.genre_list.setObjectName('genre_list') self.genre_list.itemClicked.connect(self.item_clicked) grid.addWidget(self.genre_label, 6, 0) grid.addWidget(self.genre_list, 7, 0) self.genre2_label = QLabel("Genre2") self.genre2_list = QListWidget(self) self.genre2_list.setObjectName("genre2") self.genre2_list.addItem("Select genre first") grid.addWidget(self.genre2_label, 6, 1) grid.addWidget(self.genre2_list, 7, 1) self.submit = QtGui.QPushButton("Submit Data", self) self.submit.clicked.connect(self.buttonClicked) grid.addWidget(self.submit, 8, 1) self.quit = QtGui.QPushButton("Exit", self) self.quit.clicked.connect(self.buttonClicked) self.quit.setMaximumWidth(80) grid.addWidget(self.quit, 8, 0)
def __init__(self, parent, duplicates, loc): QDialog.__init__(self, parent) l = QVBoxLayout() self.setLayout(l) self.la = la = QLabel(_('Books with the same title and author as the following already exist in the library %s.' ' Select which books you want copied anyway.') % os.path.basename(loc)) la.setWordWrap(True) l.addWidget(la) self.setWindowTitle(_('Duplicate books')) self.books = QListWidget(self) self.items = [] for book_id, (title, authors) in duplicates.iteritems(): i = QListWidgetItem(_('{0} by {1}').format(title, ' & '.join(authors[:3])), self.books) i.setData(Qt.UserRole, book_id) i.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) i.setCheckState(Qt.Checked) self.items.append(i) l.addWidget(self.books) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.a = b = bb.addButton(_('Select &all'), bb.ActionRole) b.clicked.connect(self.select_all), b.setIcon(QIcon(I('plus.png'))) self.n = b = bb.addButton(_('Select &none'), bb.ActionRole) b.clicked.connect(self.select_none), b.setIcon(QIcon(I('minus.png'))) self.ctc = b = bb.addButton(_('&Copy to clipboard'), bb.ActionRole) b.clicked.connect(self.copy_to_clipboard), b.setIcon(QIcon(I('edit-copy.png'))) l.addWidget(bb) self.resize(600, 400)
def __init__(self, parent=None, mm=None, mi = None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:add book dialog') self.setWindowTitle('Add text to Casanova:') self.gui = parent self.mm = mm self.mi = mi self.one_line_description = '' layout = QVBoxLayout(self) self.setLayout(layout) self.one_liner_label = QLabel('Enter a short description (255 chars max) before pressing OK') layout.addWidget(self.one_liner_label) self.one_liner_str = QLineEdit(self) self.one_liner_str.setText('') layout.addWidget(self.one_liner_str) self.one_liner_label.setBuddy(self.one_liner_str) self.values_label = QLabel('Below are potential matches of texts that already exist - please make sure you are adding something new') layout.addWidget(self.values_label) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_choices() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
def __init__(self, pdfpath, parent=None): QDialog.__init__(self, parent) self.pdfpath = pdfpath self.l = l = QGridLayout() self.setLayout(l) self.la = la = QLabel( _('Choose a cover from the list of PDF pages below')) l.addWidget(la) self.loading = la = QLabel('<b>' + _('Rendering PDF pages, please wait...')) l.addWidget(la) self.covers = c = QListWidget(self) l.addWidget(c) c.setIconSize(QSize(120, 160)) c.setSelectionMode(c.SingleSelection) c.setViewMode(c.IconMode) c.setUniformItemSizes(True) c.setResizeMode(c.Adjust) c.itemDoubleClicked.connect(self.accept) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) l.addWidget(bb) self.rendering_done.connect(self.show_pages, type=Qt.QueuedConnection) self.tdir = PersistentTemporaryDirectory('_pdf_covers') self.thread = Thread(target=self.render) self.thread.daemon = True self.thread.start() self.setWindowTitle(_('Choose cover from PDF')) self.setWindowIcon(file_icon_provider().icon_from_ext('pdf')) self.resize(QSize(800, 600))
def __init__(self, parent=None): QSplitter.__init__(self, parent) self.setChildrenCollapsible(False) self.items = i = QListWidget(self) i.setContextMenuPolicy(Qt.CustomContextMenu) i.customContextMenuRequested.connect(self.context_menu) self.items.setSpacing(3) self.items.itemDoubleClicked.connect(self.current_item_activated) self.items.currentItemChanged.connect(self.current_item_changed) self.items.setSelectionMode(self.items.NoSelection) self.delegate = Delegate(self.items) self.items.setItemDelegate(self.delegate) self.addWidget(i) self.help = h = QTextBrowser(self) h.anchorClicked.connect(self.link_clicked) h.setOpenLinks(False) self.addWidget(h) self.clear_help(_('Check has not been run')) self.setStretchFactor(0, 100) self.setStretchFactor(1, 50) state = tprefs.get('check-book-splitter-state', None) if state is not None: self.restoreState(state)
def __init__(self, gui, initial_panel=None): QDialog.__init__(self, gui) self.l = l = QGridLayout(self) self.setLayout(l) self.setWindowTitle(_('Preferences for Edit Book')) self.setWindowIcon(QIcon(I('config.png'))) self.stacks = QStackedWidget(self) l.addWidget(self.stacks, 0, 1, 1, 1) self.categories_list = cl = QListWidget(self) cl.currentRowChanged.connect(self.stacks.setCurrentIndex) cl.clearPropertyFlags() cl.setViewMode(cl.IconMode) cl.setFlow(cl.TopToBottom) cl.setMovement(cl.Static) cl.setWrapping(False) cl.setSpacing(15) cl.setWordWrap(True) l.addWidget(cl, 0, 0, 1, 1) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.rdb = b = bb.addButton(_('Restore all defaults'), bb.ResetRole) b.setToolTip(_('Restore defaults for all preferences')) b.clicked.connect(self.restore_all_defaults) self.rcdb = b = bb.addButton(_('Restore current defaults'), bb.ResetRole) b.setToolTip(_('Restore defaults for currently displayed preferences')) b.clicked.connect(self.restore_current_defaults) l.addWidget(bb, 1, 0, 1, 2) self.resize(800, 600) geom = tprefs.get('preferences_geom', None) if geom is not None: self.restoreGeometry(geom) self.keyboard_panel = ShortcutConfig(self) self.keyboard_panel.initialize(gui.keyboard) self.editor_panel = EditorSettings(self) self.integration_panel = IntegrationSettings(self) for name, icon, panel in [ (_('Editor settings'), 'modified.png', 'editor'), (_('Keyboard shortcuts'), 'keyboard-prefs.png', 'keyboard'), (_('Integration with calibre'), 'lt.png', 'integration'), ]: i = QListWidgetItem(QIcon(I(icon)), name, cl) cl.addItem(i) self.stacks.addWidget(getattr(self, panel + '_panel')) cl.setCurrentRow(0) cl.item(0).setSelected(True) w, h = cl.sizeHintForColumn(0), 0 for i in xrange(cl.count()): h = max(h, cl.sizeHintForRow(i)) cl.item(i).setSizeHint(QSize(w, h)) cl.setMaximumWidth(cl.sizeHintForColumn(0) + 35) cl.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
def __init__(self, parent=None, mm=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:search dialog') self.setWindowTitle('Search Casanova:') self.gui = parent self.mm = mm layout = QVBoxLayout(self) self.setLayout(layout) self.search_label = QLabel('Search for:') layout.addWidget(self.search_label) self.search_str = QLineEdit(self) self.search_str.setText('') layout.addWidget(self.search_str) self.search_label.setBuddy(self.search_str) self.find_button = QPushButton("&Find") self.search_button_box = QDialogButtonBox(Qt.Horizontal) self.search_button_box.addButton(self.find_button, QDialogButtonBox.ActionRole) self.search_button_box.clicked.connect(self._find_clicked) layout.addWidget(self.search_button_box) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
def initGui(self): layout = QtGui.QVBoxLayout() self.label = QtGui.QLabel("<b>Filter by layer</b>") layout.addWidget(self.label) self.layersList = QListWidget() layout.addWidget(self.layersList) self.label = QtGui.QLabel("<b>Filter by text</b>") layout.addWidget(self.label) self.text = QtGui.QLineEdit() layout.addWidget(self.text) self.button = QtGui.QPushButton("Apply") self.button.clicked.connect(self.apply) layout.addWidget(self.button) self.setLayout(layout) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Popup) self.resize(200, 150)
def __init__(self, all_formats, format_map): QWidget.__init__(self) self.l = l = QGridLayout() self.setLayout(l) self.f = f = QListWidget(self) l.addWidget(f, 0, 0, 3, 1) unchecked_formats = sorted(all_formats - set(format_map)) for fmt in format_map + unchecked_formats: item = QListWidgetItem(fmt, f) item.setData(Qt.UserRole, fmt) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsSelectable) item.setCheckState(Qt.Checked if fmt in format_map else Qt.Unchecked) self.button_up = b = QToolButton(self) b.setIcon(QIcon(I('arrow-up.png'))) l.addWidget(b, 0, 1) b.clicked.connect(self.up) self.button_down = b = QToolButton(self) b.setIcon(QIcon(I('arrow-down.png'))) l.addWidget(b, 2, 1) b.clicked.connect(self.down)
def __init__(self, names, txt, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout(self) self.setLayout(l) self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt) l.addWidget(la) self._names = QListWidget(self) self._names.addItems(QStringList(sorted(names, key=sort_key))) self._names.setSelectionMode(self._names.ExtendedSelection) l.addWidget(self._names) self._or = QRadioButton(_('Match any of the selected %s names')%txt) self._and = QRadioButton(_('Match all of the selected %s names')%txt) self._or.setChecked(True) l.addWidget(self._or) l.addWidget(self._and) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) l.addWidget(self.bb) self.resize(self.sizeHint())
class SelectTagsDialog(QDialog): def __init__(self, parent, modal=True, flags=Qt.WindowFlags(), caption="Select Tags", ok_button="Select"): QDialog.__init__(self, parent, flags) self.setModal(modal) self.setWindowTitle(caption) lo = QVBoxLayout(self) lo.setMargin(10) lo.setSpacing(5) # tag selector self.wtagsel = QListWidget(self) lo.addWidget(self.wtagsel) # self.wtagsel.setColumnMode(QListBox.FitToWidth) self.wtagsel.setSelectionMode(QListWidget.MultiSelection) QObject.connect(self.wtagsel, SIGNAL("itemSelectionChanged()"), self._check_tag) # buttons lo.addSpacing(10) lo2 = QHBoxLayout() lo.addLayout(lo2) lo2.setContentsMargins(0, 0, 0, 0) lo2.setMargin(5) self.wokbtn = QPushButton(ok_button, self) self.wokbtn.setMinimumWidth(128) QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept) self.wokbtn.setEnabled(False) cancelbtn = QPushButton("Cancel", self) cancelbtn.setMinimumWidth(128) QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject) lo2.addWidget(self.wokbtn) lo2.addStretch(1) lo2.addWidget(cancelbtn) self.setMinimumWidth(384) self._tagnames = [] def setTags(self, tagnames): self._tagnames = tagnames self.wtagsel.clear() self.wtagsel.insertItems(0, list(tagnames)) def _check_tag(self): for i in range(len(self._tagnames)): if self.wtagsel.item(i).isSelected(): self.wokbtn.setEnabled(True) return else: self.wokbtn.setEnabled(False) def getSelectedTags(self): return [ tag for i, tag in enumerate(self._tagnames) if self.wtagsel.item(i).isSelected() ]
class ChoosePluginToolbarsDialog(QDialog): def __init__(self, parent, plugin, locations): QDialog.__init__(self, parent) self.locations = locations self.setWindowTitle(_('Add "%s" to toolbars or menus') % plugin.name) self._layout = QVBoxLayout(self) self.setLayout(self._layout) self._header_label = QLabel( _('Select the toolbars and/or menus to add <b>%s</b> to:') % plugin.name) self._layout.addWidget(self._header_label) self._locations_list = QListWidget(self) self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) self._locations_list.setSizePolicy(sizePolicy) for key, text in locations: self._locations_list.addItem(text) if key in {'toolbar', 'toolbar-device'}: self._locations_list.item(self._locations_list.count() - 1).setSelected(True) self._layout.addWidget(self._locations_list) self._footer_label = QLabel( _('You can also customise the plugin locations ' 'using <b>Preferences -> Customise the toolbar</b>')) self._layout.addWidget(self._footer_label) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) self._layout.addWidget(button_box) self.resize(self.sizeHint()) def selected_locations(self): selected = [] for row in self._locations_list.selectionModel().selectedRows(): selected.append(self.locations[row.row()]) return selected
def __init__(self, parent=None, initial=None): QDialog.__init__(self, parent) self.setWindowTitle(_('Choose a texture')) self.l = l = QVBoxLayout() self.setLayout(l) self.tdir = texture_dir() self.images = il = QListWidget(self) il.itemDoubleClicked.connect(self.accept, type=Qt.QueuedConnection) il.setIconSize(QSize(256, 256)) il.setViewMode(il.IconMode) il.setFlow(il.LeftToRight) il.setSpacing(20) il.setSelectionMode(il.SingleSelection) il.itemSelectionChanged.connect(self.update_remove_state) l.addWidget(il) self.ad = ad = QLabel(_('The builtin textures come from <a href="http://subtlepatterns.com">subtlepatterns.com</a>.')) ad.setOpenExternalLinks(True) ad.setWordWrap(True) l.addWidget(ad) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) b = self.add_button = bb.addButton(_('Add texture'), bb.ActionRole) b.setIcon(QIcon(I('plus.png'))) b.clicked.connect(self.add_texture) b = self.remove_button = bb.addButton(_('Remove texture'), bb.ActionRole) b.setIcon(QIcon(I('minus.png'))) b.clicked.connect(self.remove_texture) l.addWidget(bb) images = [{ 'fname': ':'+os.path.basename(x), 'path': x, 'name': ' '.join(map(string.capitalize, os.path.splitext(os.path.basename(x))[0].split('_'))) } for x in glob.glob(I('textures/*.png'))] + [{ 'fname': os.path.basename(x), 'path': x, 'name': os.path.splitext(os.path.basename(x))[0], } for x in glob.glob(os.path.join(self.tdir, '*')) if x.rpartition('.')[-1].lower() in {'jpeg', 'png', 'jpg'}] images.sort(key=lambda x:sort_key(x['name'])) map(self.create_item, images) self.update_remove_state() if initial: existing = {unicode(i.data(Qt.UserRole).toString()):i for i in (self.images.item(c) for c in xrange(self.images.count()))} item = existing.get(initial, None) if item is not None: item.setSelected(True) QTimer.singleShot(100, partial(il.scrollToItem, item)) self.resize(QSize(950, 650))
def __init__(self, dev, ignored_folders=None, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout() self.setLayout(l) self.la = la = QLabel( "<p>" + _("<b>Scanned folders:</b>") + " " + _("You can select which top level folders calibre will " "scan when searching this device for books.") ) la.setWordWrap(True) l.addWidget(la) self.tabs = QTabWidget(self) l.addWidget(self.tabs) self.widgets = [] for storage in dev.filesystem_cache.entries: w = QListWidget(self) w.storage = storage self.tabs.addTab(w, storage.name) self.widgets.append(w) for child in sorted(storage.folders, key=attrgetter("name")): i = QListWidgetItem(child.name) i.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) i.setCheckState( Qt.Unchecked if dev.is_folder_ignored(storage, child.name, ignored_folders=ignored_folders) else Qt.Checked ) w.addItem(i) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) self.sab = self.bb.addButton(_("Select &All"), self.bb.ActionRole) self.sab.clicked.connect(self.select_all) self.snb = self.bb.addButton(_("Select &None"), self.bb.ActionRole) self.snb.clicked.connect(self.select_none) l.addWidget(self.bb) self.setWindowTitle(_("Choose folders to scan")) self.setWindowIcon(QIcon(I("devices/tablet.png"))) self.resize(500, 500)
class SearchDialog(SizePersistedDialog): def __init__(self, parent=None, mm=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:search dialog') self.setWindowTitle('Search Casanova:') self.gui = parent self.mm = mm layout = QVBoxLayout(self) self.setLayout(layout) self.search_label = QLabel('Search for:') layout.addWidget(self.search_label) self.search_str = QLineEdit(self) self.search_str.setText('') layout.addWidget(self.search_str) self.search_label.setBuddy(self.search_str) self.find_button = QPushButton("&Find") self.search_button_box = QDialogButtonBox(Qt.Horizontal) self.search_button_box.addButton(self.find_button, QDialogButtonBox.ActionRole) self.search_button_box.clicked.connect(self._find_clicked) layout.addWidget(self.search_button_box) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_choices(self, choices): self.values_list.clear() for id, name in choices.items(): item = QListWidgetItem(get_icon('images/books.png'), name, self.values_list) item.setData(1, (id, )) self.values_list.addItem(item) def _find_clicked(self): query = unicode(self.search_str.text()) self._display_choices(self.mm.search(query)) def _accept_clicked(self): #self._save_preferences() self.selected_texts = [] for item in self.values_list.selectedItems(): self.selected_texts.append(item.data(1).toPyObject()[0]) self.accept()
def _init_controls(self): layout = QVBoxLayout(self) self.setLayout(layout) ml = QHBoxLayout() layout.addLayout(ml, 1) self.keys_list = QListWidget(self) self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection) self.keys_list.setFixedWidth(150) self.keys_list.setAlternatingRowColors(True) ml.addWidget(self.keys_list) self.value_text = QTextEdit(self) self.value_text.setTabStopWidth(24) self.value_text.setReadOnly(True) ml.addWidget(self.value_text, 1) button_box = QDialogButtonBox(QDialogButtonBox.Ok) button_box.accepted.connect(self.accept) button_box.setCenterButtons(True) layout.addWidget(button_box)
def __init__(self, dev, ignored_folders=None, parent=None): QDialog.__init__(self, parent) self.l = l = QVBoxLayout() self.setLayout(l) self.la = la = QLabel( '<p>' + _('<b>Scanned folders:</b>') + ' ' + _('You can select which top level folders calibre will ' 'scan when searching this device for books.')) la.setWordWrap(True) l.addWidget(la) self.tabs = QTabWidget(self) l.addWidget(self.tabs) self.widgets = [] for storage in dev.filesystem_cache.entries: w = QListWidget(self) w.storage = storage self.tabs.addTab(w, storage.name) self.widgets.append(w) for child in sorted(storage.folders, key=attrgetter('name')): i = QListWidgetItem(child.name) i.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) i.setCheckState(Qt.Unchecked if dev.is_folder_ignored( storage, child.name, ignored_folders=ignored_folders ) else Qt.Checked) w.addItem(i) self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) self.sab = self.bb.addButton(_('Select &All'), self.bb.ActionRole) self.sab.clicked.connect(self.select_all) self.snb = self.bb.addButton(_('Select &None'), self.bb.ActionRole) self.snb.clicked.connect(self.select_none) l.addWidget(self.bb) self.setWindowTitle(_('Choose folders to scan')) self.setWindowIcon(QIcon(I('devices/tablet.png'))) self.resize(500, 500)
class SearchDialog(SizePersistedDialog): def __init__(self, parent=None, mm=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:search dialog') self.setWindowTitle('Search Casanova:') self.gui = parent self.mm = mm layout = QVBoxLayout(self) self.setLayout(layout) self.search_label = QLabel('Search for:') layout.addWidget(self.search_label) self.search_str = QLineEdit(self) self.search_str.setText('') layout.addWidget(self.search_str) self.search_label.setBuddy(self.search_str) self.find_button = QPushButton("&Find") self.search_button_box = QDialogButtonBox(Qt.Horizontal) self.search_button_box.addButton(self.find_button, QDialogButtonBox.ActionRole) self.search_button_box.clicked.connect(self._find_clicked) layout.addWidget(self.search_button_box) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_choices(self, choices): self.values_list.clear() for id, name in choices.items(): item = QListWidgetItem(get_icon('images/books.png'), name, self.values_list) item.setData(1, (id,)) self.values_list.addItem(item) def _find_clicked(self): query = unicode(self.search_str.text()) self._display_choices(self.mm.search(query)) def _accept_clicked(self): #self._save_preferences() self.selected_texts = [] for item in self.values_list.selectedItems(): self.selected_texts.append(item.data(1).toPyObject()[0]) self.accept()
class SelectTagsDialog(QDialog): def __init__(self, parent, modal=True, flags=Qt.WindowFlags(), caption="Select Tags", ok_button="Select"): QDialog.__init__(self, parent, flags) self.setModal(modal) self.setWindowTitle(caption) lo = QVBoxLayout(self) lo.setMargin(10) lo.setSpacing(5) # tag selector self.wtagsel = QListWidget(self) lo.addWidget(self.wtagsel) # self.wtagsel.setColumnMode(QListBox.FitToWidth) self.wtagsel.setSelectionMode(QListWidget.MultiSelection) QObject.connect(self.wtagsel, SIGNAL("itemSelectionChanged()"), self._check_tag) # buttons lo.addSpacing(10) lo2 = QHBoxLayout() lo.addLayout(lo2) lo2.setContentsMargins(0, 0, 0, 0) lo2.setMargin(5) self.wokbtn = QPushButton(ok_button, self) self.wokbtn.setMinimumWidth(128) QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept) self.wokbtn.setEnabled(False) cancelbtn = QPushButton("Cancel", self) cancelbtn.setMinimumWidth(128) QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject) lo2.addWidget(self.wokbtn) lo2.addStretch(1) lo2.addWidget(cancelbtn) self.setMinimumWidth(384) self._tagnames = [] def setTags(self, tagnames): self._tagnames = tagnames self.wtagsel.clear() self.wtagsel.insertItems(0, list(tagnames)) def _check_tag(self): for i in range(len(self._tagnames)): if self.wtagsel.item(i).isSelected(): self.wokbtn.setEnabled(True) return else: self.wokbtn.setEnabled(False) def getSelectedTags(self): return [tag for i, tag in enumerate(self._tagnames) if self.wtagsel.item(i).isSelected()]
def __init__(self, parent=None, mm=None, mi=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:add book dialog') self.setWindowTitle('Add text to Casanova:') self.gui = parent self.mm = mm self.mi = mi self.one_line_description = '' layout = QVBoxLayout(self) self.setLayout(layout) self.one_liner_label = QLabel( 'Enter a short description (255 chars max) before pressing OK') layout.addWidget(self.one_liner_label) self.one_liner_str = QLineEdit(self) self.one_liner_str.setText('') layout.addWidget(self.one_liner_str) self.one_liner_label.setBuddy(self.one_liner_str) self.values_label = QLabel( 'Below are potential matches of texts that already exist - please make sure you are adding something new' ) layout.addWidget(self.values_label) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_choices() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
def link_stylesheets(self, names): s = self.categories['styles'] sheets = [ unicode(s.child(i).data(0, NAME_ROLE).toString()) for i in xrange(s.childCount()) ] if not sheets: return error_dialog( self, _('No stylesheets'), _('This book currently has no stylesheets. You must first create a stylesheet' ' before linking it.'), show=True) d = QDialog(self) d.l = l = QVBoxLayout(d) d.setLayout(l) d.setWindowTitle(_('Choose stylesheets')) d.la = la = QLabel( _('Choose the stylesheets to link. Drag and drop to re-arrange')) la.setWordWrap(True) l.addWidget(la) d.s = s = QListWidget(d) l.addWidget(s) s.setDragEnabled(True) s.setDropIndicatorShown(True) s.setDragDropMode(self.InternalMove) s.setAutoScroll(True) s.setDefaultDropAction(Qt.MoveAction) for name in sheets: i = QListWidgetItem(name, s) flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable i.setFlags(flags) i.setCheckState(Qt.Checked) d.r = r = QCheckBox(_('Remove existing links to stylesheets')) r.setChecked(tprefs['remove_existing_links_when_linking_sheets']) l.addWidget(r) d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.accepted.connect(d.accept), bb.rejected.connect(d.reject) l.addWidget(bb) if d.exec_() == d.Accepted: tprefs['remove_existing_links_when_linking_sheets'] = r.isChecked() sheets = [ unicode(s.item(il).text()) for il in xrange(s.count()) if s.item(il).checkState() == Qt.Checked ] if sheets: self.link_stylesheets_requested.emit(names, sheets, r.isChecked())
def insertItems(self, row, items, setAsDefault=True): """ Insert items of widget starting at <row>. If <setAsDefault> is True, <items> become the default list of items for this widget. "Restore Defaults" will reset the list of items to <items>. Note: <items> will always replace the list of current items in the widget. <row> is ignored. This is considered a bug. -- Mark 2007-06-04 """ if row <> 0: msg = "PM_ListWidget.insertItems(): <row> must be zero."\ "See docstring for details:" print_compact_traceback(msg) return if setAsDefault: self.setAsDefault = setAsDefault self.defaultItems = items self.clear() QListWidget.insertItems(self, row, items)
def insertItems(self, row, items, setAsDefault = True): """ Insert items of widget starting at <row>. If <setAsDefault> is True, <items> become the default list of items for this widget. "Restore Defaults" will reset the list of items to <items>. Note: <items> will always replace the list of current items in the widget. <row> is ignored. This is considered a bug. -- Mark 2007-06-04 """ if row <> 0: msg = "PM_ListWidget.insertItems(): <row> must be zero."\ "See docstring for details:" print_compact_traceback(msg) return if setAsDefault: self.setAsDefault = setAsDefault self.defaultItems = items self.clear() QListWidget.insertItems(self, row, items)
def __init__(self, parent=None): QDialog.__init__(self, parent) self._layout = l = QGridLayout(self) self.setLayout(l) self.setWindowIcon(QIcon(I('mail.png'))) self.setWindowTitle(_('Select recipients')) self.recipients = r = QListWidget(self) l.addWidget(r, 0, 0, 1, -1) self.la = la = QLabel(_('Add a new recipient:')) la.setStyleSheet('QLabel { font-weight: bold }') l.addWidget(la, l.rowCount(), 0, 1, -1) self.labels = tuple( map(QLabel, (_('&Address'), _('A&lias'), _('&Formats'), _('&Subject')))) tooltips = ( _('The email address of the recipient'), _('The optional alias (simple name) of the recipient'), _('Formats to email. The first matching one will be sent (comma separated list)' ), _('The optional subject for email sent to this recipient')) for i, name in enumerate(('address', 'alias', 'formats', 'subject')): c = i % 2 row = l.rowCount() - c self.labels[i].setText(unicode(self.labels[i].text()) + ':') l.addWidget(self.labels[i], row, (2 * c)) le = QLineEdit(self) le.setToolTip(tooltips[i]) setattr(self, name, le) self.labels[i].setBuddy(le) l.addWidget(le, row, (2 * c) + 1) self.formats.setText(prefs['output_format'].upper()) self.add_button = b = QPushButton(QIcon(I('plus.png')), _('&Add recipient'), self) b.clicked.connect(self.add_recipient) l.addWidget(b, l.rowCount(), 0, 1, -1) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) l.addWidget(bb, l.rowCount(), 0, 1, -1) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.setMinimumWidth(500) self.setMinimumHeight(400) self.resize(self.sizeHint()) self.init_list()
class ChooseFormatToDownloadDialog(SizePersistedDialog): def __init__(self, parent=None, dm=None, casanova_id=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:format download dialog') self.setWindowTitle('Select format to download:') self.gui = parent self.dm = dm self.casanova_id = casanova_id layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_formats() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_formats(self): self.values_list.clear() formats = self.dm.get_download_info(self.casanova_id) if isinstance(formats, list): for format in formats: item = QListWidgetItem(get_icon('images/books.png'), format['type'], self.values_list) item.setData(1, (format, )) self.values_list.addItem(item) else: return error_dialog(self.gui, 'Casanova message', unicode(formats), show=True) def _accept_clicked(self): #self._save_preferences() self.selected_format = None for item in self.values_list.selectedItems(): self.selected_format = item.data(1).toPyObject()[0] self.accept()
class ChooseFormatToDownloadDialog(SizePersistedDialog): def __init__(self, parent=None, dm=None, casanova_id=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:format download dialog') self.setWindowTitle('Select format to download:') self.gui = parent self.dm = dm self.casanova_id = casanova_id layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_formats() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_formats(self): self.values_list.clear() formats = self.dm.get_download_info(self.casanova_id) if isinstance(formats, list): for format in formats: item = QListWidgetItem(get_icon('images/books.png'), format['type'], self.values_list) item.setData(1, (format,)) self.values_list.addItem(item) else: return error_dialog(self.gui, 'Casanova message', unicode(formats), show=True) def _accept_clicked(self): #self._save_preferences() self.selected_format = None for item in self.values_list.selectedItems(): self.selected_format = item.data(1).toPyObject()[0] self.accept()
def makeGetDataTab(self, vbox_inner): self.authorData = QLineEdit() self.authorData.setPlaceholderText("Author") self.authorData.setReadOnly(True) vbox_inner.addWidget(self.authorData) self.titleData = QLineEdit() self.titleData.setPlaceholderText("Title") self.titleData.setReadOnly(True) vbox_inner.addWidget(self.titleData) self.genreData = QLineEdit() self.genreData.setPlaceholderText("Genre") self.genreData.setReadOnly(True) vbox_inner.addWidget(self.genreData) self.genre2Data = QLineEdit() self.genre2Data.setPlaceholderText("Genre2") self.genre2Data.setReadOnly(True) vbox_inner.addWidget(self.genre2Data) self.dateData = QLineEdit() self.dateData.setPlaceholderText("Date read") self.dateData.setReadOnly(True) vbox_inner.addWidget(self.dateData) self.gradeData = QLineEdit() self.gradeData.setPlaceholderText("Grade") self.gradeData.setReadOnly(True) vbox_inner.addWidget(self.gradeData) self.commentsData = QLineEdit() self.commentsData.setPlaceholderText("Comments") self.commentsData.setReadOnly(True) vbox_inner.addWidget(self.commentsData) self.titles_list = QListWidget(self) vbox_inner.addWidget(self.titles_list) hbox_inner = QtGui.QHBoxLayout() self.getTitleData = QtGui.QPushButton("Get title data", self) self.getTitleData.clicked.connect(self.buttonClicked) hbox_inner.addWidget(self.getTitleData) self.refreshList = QtGui.QPushButton("Refresh list", self) self.refreshList.clicked.connect(self.buttonClicked) hbox_inner.addWidget(self.refreshList) return hbox_inner
def __init__(self, parent=None, mm=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:issues update dialog') self.setWindowTitle('Select issues to update:') self.gui = parent self.mm = mm layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_issues() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog()
class ChooseIssuesToUpdateDialog(SizePersistedDialog): def __init__(self, parent=None, mm=None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:issues update dialog') self.setWindowTitle('Select issues to update:') self.gui = parent self.mm = mm layout = QVBoxLayout(self) self.setLayout(layout) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_issues() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_issues(self): self.values_list.clear() issues = self.mm.get_all_issues(True) for id, issue in issues: item = QListWidgetItem(get_icon('images/books.png'), issue, self.values_list) item.setData(1, (id,)) self.values_list.addItem(item) def _accept_clicked(self): #self._save_preferences() self.selected_issues = [] for item in self.values_list.selectedItems(): self.selected_issues.append(item.data(1).toPyObject()[0]) self.accept()
def order_widget(self, name, prefs=None): prefs = prefs or tprefs widget = QListWidget(self) widget.addItems(prefs.defaults[name]) widget.setDragEnabled(True) widget.setDragDropMode(widget.InternalMove) widget.viewport().setAcceptDrops(True) widget.setDropIndicatorShown(True) widget.indexesMoved.connect(self.emit_changed) widget.setDefaultDropAction(Qt.MoveAction) widget.setMovement(widget.Snap) widget.setSpacing(5) widget.defaults = prefs.defaults[name] def getter(w): return list(map(unicode, (w.item(i).text() for i in xrange(w.count())))) def setter(w, val): order_map = {x:i for i, x in enumerate(val)} items = list(w.defaults) limit = len(items) items.sort(key=lambda x:order_map.get(x, limit)) w.clear() for x in items: i = QListWidgetItem(w) i.setText(x) i.setFlags(i.flags() | Qt.ItemIsDragEnabled) return self(name, widget=widget, getter=getter, setter=setter, prefs=prefs)
def __init__(self, parent=None): QListWidget.__init__(self, parent) self.setSelectionMode(self.ExtendedSelection)
class PrefsViewerDialog(SizePersistedDialog): def __init__(self, gui, namespace): SizePersistedDialog.__init__(self, gui, 'Prefs Viewer dialog') self.setWindowTitle('Preferences for: '+namespace) self.gui = gui self.db = gui.current_db self.namespace = namespace self._init_controls() self.resize_dialog() self._populate_settings() if self.keys_list.count(): self.keys_list.setCurrentRow(0) def _init_controls(self): layout = QVBoxLayout(self) self.setLayout(layout) ml = QHBoxLayout() layout.addLayout(ml, 1) self.keys_list = QListWidget(self) self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection) self.keys_list.setFixedWidth(150) self.keys_list.setAlternatingRowColors(True) ml.addWidget(self.keys_list) self.value_text = QTextEdit(self) self.value_text.setTabStopWidth(24) self.value_text.setReadOnly(True) ml.addWidget(self.value_text, 1) button_box = QDialogButtonBox(QDialogButtonBox.Ok) button_box.accepted.connect(self.accept) self.clear_button = button_box.addButton('Clear', QDialogButtonBox.ResetRole) self.clear_button.setIcon(get_icon('trash.png')) self.clear_button.setToolTip('Clear all settings for this plugin') self.clear_button.clicked.connect(self._clear_settings) layout.addWidget(button_box) def _populate_settings(self): self.keys_list.clear() ns_prefix = self._get_ns_prefix() keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)]) for key in keys: self.keys_list.addItem(key) self.keys_list.setMinimumWidth(self.keys_list.sizeHintForColumn(0)) self.keys_list.currentRowChanged[int].connect(self._current_row_changed) def _current_row_changed(self, new_row): if new_row < 0: self.value_text.clear() return key = unicode(self.keys_list.currentItem().text()) val = self.db.prefs.get_namespaced(self.namespace, key, '') self.value_text.setPlainText(self.db.prefs.to_raw(val)) def _get_ns_prefix(self): return 'namespaced:%s:'% self.namespace def _clear_settings(self): from calibre.gui2.dialogs.confirm_delete import confirm message = '<p>Are you sure you want to clear your settings in this library for this plugin?</p>' \ '<p>Any settings in other libraries or stored in a JSON file in your calibre plugins ' \ 'folder will not be touched.</p>' \ '<p>You must restart calibre afterwards.</p>' if not confirm(message, self.namespace+'_clear_settings', self): return ns_prefix = self._get_ns_prefix() keys = [k for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)] for k in keys: del self.db.prefs[k] self._populate_settings() d = info_dialog(self, 'Settings deleted', '<p>All settings for this plugin in this library have been cleared.</p>' '<p>Please restart calibre now.</p>', show_copy_button=False) b = d.bb.addButton(_('Restart calibre now'), d.bb.AcceptRole) b.setIcon(QIcon(I('lt.png'))) d.do_restart = False def rf(): d.do_restart = True b.clicked.connect(rf) d.set_details('') d.exec_() b.clicked.disconnect() self.close() if d.do_restart: self.gui.quit(restart=True)
def __init__(self, parentWidget, label = '', labelColumn = 0, items = [], defaultRow = 0, setAsDefault = True, heightByRows = 6, spanWidth = False ): """ Appends a QListWidget (Qt) widget to the bottom of I{parentWidget}, a Property Manager group box. @param parentWidget: The parent group box containing this widget. @type parentWidget: PM_GroupBox @param label: The label that appears to the left or right of the checkbox. If spanWidth is True, the label will be displayed on its own row directly above the list widget. To suppress the label, set I{label} to an empty string. @type label: str @param labelColumn: The column number of the label in the group box grid layout. The only valid values are 0 (left column) and 1 (right column). The default is 0 (left column). @type labelColumn: int @param items: list of items (strings) to be inserted in the widget. @type items: list @param defaultRow: The default row (item) selected, where 0 is the first row. @type defaultRow: int @param setAsDefault: If True, will restore <idx> as the current index when the "Restore Defaults" button is clicked. @type setAsDefault: bool @param heightByRows: The height of the list widget. @type heightByRows: int @param spanWidth: If True, the widget and its label will span the width of the group box. Its label will appear directly above the widget (unless the label is empty) and is left justified. @type spanWidth: bool @see: U{B{QListWidget}<http://doc.trolltech.com/4/qlistwidget.html>} """ if 0: # Debugging code print "PM_ListWidget.__init__():" print " label = ", label print " labelColumn = ", labelColumn print " items = ", items print " defaultRow = ", defaultRow print " setAsDefault = ", setAsDefault print " heightByRows = ", heightByRows print " spanWidth = ", spanWidth QListWidget.__init__(self) self.parentWidget = parentWidget self.label = label self.labelColumn = labelColumn self.setAsDefault = setAsDefault self.spanWidth = spanWidth if label: # Create this widget's QLabel. self.labelWidget = QLabel() self.labelWidget.setText(label) # Load QComboBox widget choice items and set initial choice (index). self.insertItems(0, items, setAsDefault) self.setCurrentRow(defaultRow, setAsDefault) # Set height of list widget. margin = self.fontMetrics().leading() * 2 # Mark 2007-05-28 height = heightByRows * self.fontMetrics().lineSpacing() + margin self.setMaximumHeight(height) #As of 2008-04-16, the items in any list widgets won't be sorted #automatically. It can be changes by simply uncommentting the lines #below -- Ninad ##self.setSortingEnabled(True) ##self.sortItems() self.setAlternatingRowColors(True) parentWidget.addPmWidget(self)
def __init__(self, *args): QListWidget.__init__(self, *args) self.setContextMenuPolicy(Qt.CustomContextMenu) QObject.connect(self, SIGNAL('customContextMenuRequested(const QPoint &)'), self._request_context_menu)
class ManageKeysDialog(QDialog): def __init__(self, parent, key_type_name, plugin_keys, create_key, keyfile_ext = u""): QDialog.__init__(self,parent) self.parent = parent self.key_type_name = key_type_name self.plugin_keys = plugin_keys self.create_key = create_key self.keyfile_ext = keyfile_ext self.import_key = (keyfile_ext != u"") self.binary_file = (key_type_name == u"Adobe Digital Editions Key") self.json_file = (key_type_name == u"Kindle for Mac and PC Key") self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name)) # Start Qt Gui dialog layout layout = QVBoxLayout(self) self.setLayout(layout) help_layout = QHBoxLayout() layout.addLayout(help_layout) # Add hyperlink to a help file at the right. We will replace the correct name when it is clicked. help_label = QLabel('<a href="http://www.foo.com/">Help</a>', self) help_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_label.setAlignment(Qt.AlignRight) help_label.linkActivated.connect(self.help_link_activated) help_layout.addWidget(help_label) keys_group_box = QGroupBox(_(u"{0}s".format(self.key_type_name)), self) layout.addWidget(keys_group_box) keys_group_box_layout = QHBoxLayout() keys_group_box.setLayout(keys_group_box_layout) self.listy = QListWidget(self) self.listy.setToolTip(u"{0}s that will be used to decrypt ebooks".format(self.key_type_name)) self.listy.setSelectionMode(QAbstractItemView.SingleSelection) self.populate_list() keys_group_box_layout.addWidget(self.listy) button_layout = QVBoxLayout() keys_group_box_layout.addLayout(button_layout) self._add_key_button = QtGui.QToolButton(self) self._add_key_button.setToolTip(u"Create new {0}".format(self.key_type_name)) self._add_key_button.setIcon(QIcon(I('plus.png'))) self._add_key_button.clicked.connect(self.add_key) button_layout.addWidget(self._add_key_button) self._delete_key_button = QtGui.QToolButton(self) self._delete_key_button.setToolTip(_(u"Delete highlighted key")) self._delete_key_button.setIcon(QIcon(I('list_remove.png'))) self._delete_key_button.clicked.connect(self.delete_key) button_layout.addWidget(self._delete_key_button) if type(self.plugin_keys) == dict: self._rename_key_button = QtGui.QToolButton(self) self._rename_key_button.setToolTip(_(u"Rename highlighted key")) self._rename_key_button.setIcon(QIcon(I('edit-select-all.png'))) self._rename_key_button.clicked.connect(self.rename_key) button_layout.addWidget(self._rename_key_button) self.export_key_button = QtGui.QToolButton(self) self.export_key_button.setToolTip(u"Save highlighted key to a .{0} file".format(self.keyfile_ext)) self.export_key_button.setIcon(QIcon(I('save.png'))) self.export_key_button.clicked.connect(self.export_key) button_layout.addWidget(self.export_key_button) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) button_layout.addItem(spacerItem) layout.addSpacing(5) migrate_layout = QHBoxLayout() layout.addLayout(migrate_layout) if self.import_key: migrate_layout.setAlignment(Qt.AlignJustify) self.migrate_btn = QPushButton(u"Import Existing Keyfiles", self) self.migrate_btn.setToolTip(u"Import *.{0} files (created using other tools).".format(self.keyfile_ext)) self.migrate_btn.clicked.connect(self.migrate_wrapper) migrate_layout.addWidget(self.migrate_btn) migrate_layout.addStretch() self.button_box = QDialogButtonBox(QDialogButtonBox.Close) self.button_box.rejected.connect(self.close) migrate_layout.addWidget(self.button_box) self.resize(self.sizeHint()) def populate_list(self): if type(self.plugin_keys) == dict: for key in self.plugin_keys.keys(): self.listy.addItem(QListWidgetItem(key)) else: for key in self.plugin_keys: self.listy.addItem(QListWidgetItem(key)) def add_key(self): d = self.create_key(self) d.exec_() if d.result() != d.Accepted: # New key generation cancelled. return new_key_value = d.key_value if type(self.plugin_keys) == dict: if new_key_value in self.plugin_keys.values(): old_key_name = [name for name, value in self.plugin_keys.iteritems() if value == new_key_value][0] info_dialog(None, "{0} {1}: Duplicate {2}".format(PLUGIN_NAME, PLUGIN_VERSION,self.key_type_name), u"The new {1} is the same as the existing {1} named <strong>{0}</strong> and has not been added.".format(old_key_name,self.key_type_name), show=True) return self.plugin_keys[d.key_name] = new_key_value else: if new_key_value in self.plugin_keys: info_dialog(None, "{0} {1}: Duplicate {2}".format(PLUGIN_NAME, PLUGIN_VERSION,self.key_type_name), u"This {0} is already in the list of {0}s has not been added.".format(self.key_type_name), show=True) return self.plugin_keys.append(d.key_value) self.listy.clear() self.populate_list() def rename_key(self): if not self.listy.currentItem(): errmsg = u"No {0} selected to rename. Highlight a keyfile first.".format(self.key_type_name) r = error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), _(errmsg), show=True, show_copy_button=False) return d = RenameKeyDialog(self) d.exec_() if d.result() != d.Accepted: # rename cancelled or moot. return keyname = unicode(self.listy.currentItem().text().toUtf8(),'utf8') if not question_dialog(self, "{0} {1}: Confirm Rename".format(PLUGIN_NAME, PLUGIN_VERSION), u"Do you really want to rename the {2} named <strong>{0}</strong> to <strong>{1}</strong>?".format(keyname,d.key_name,self.key_type_name), show_copy_button=False, default_yes=False): return self.plugin_keys[d.key_name] = self.plugin_keys[keyname] del self.plugin_keys[keyname] self.listy.clear() self.populate_list() def delete_key(self): if not self.listy.currentItem(): return keyname = unicode(self.listy.currentItem().text().toUtf8(), 'utf8') if not question_dialog(self, "{0} {1}: Confirm Delete".format(PLUGIN_NAME, PLUGIN_VERSION), u"Do you really want to delete the {1} <strong>{0}</strong>?".format(keyname, self.key_type_name), show_copy_button=False, default_yes=False): return if type(self.plugin_keys) == dict: del self.plugin_keys[keyname] else: self.plugin_keys.remove(keyname) self.listy.clear() self.populate_list() def help_link_activated(self, url): def get_help_file_resource(): # Copy the HTML helpfile to the plugin directory each time the # link is clicked in case the helpfile is updated in newer plugins. help_file_name = u"{0}_{1}_Help.htm".format(PLUGIN_NAME, self.key_type_name) file_path = os.path.join(config_dir, u"plugins", u"DeDRM", u"help", help_file_name) with open(file_path,'w') as f: f.write(self.parent.load_resource(help_file_name)) return file_path url = 'file:///' + get_help_file_resource() open_url(QUrl(url)) def migrate_files(self): dynamic[PLUGIN_NAME + u"config_dir"] = config_dir files = choose_files(self, PLUGIN_NAME + u"config_dir", u"Select {0} files to import".format(self.key_type_name), [(u"{0} files".format(self.key_type_name), [self.keyfile_ext])], False) counter = 0 skipped = 0 if files: for filename in files: fpath = os.path.join(config_dir, filename) filename = os.path.basename(filename) new_key_name = os.path.splitext(os.path.basename(filename))[0] with open(fpath,'rb') as keyfile: new_key_value = keyfile.read() if self.binary_file: new_key_value = new_key_value.encode('hex') elif self.json_file: new_key_value = json.loads(new_key_value) match = False for key in self.plugin_keys.keys(): if uStrCmp(new_key_name, key, True): skipped += 1 msg = u"A key with the name <strong>{0}</strong> already exists!\nSkipping key file <strong>{1}</strong>.\nRename the existing key and import again".format(new_key_name,filename) inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), _(msg), show_copy_button=False, show=True) match = True break if not match: if new_key_value in self.plugin_keys.values(): old_key_name = [name for name, value in self.plugin_keys.iteritems() if value == new_key_value][0] skipped += 1 info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), u"The key in file {0} is the same as the existing key <strong>{1}</strong> and has been skipped.".format(filename,old_key_name), show_copy_button=False, show=True) else: counter += 1 self.plugin_keys[new_key_name] = new_key_value msg = u"" if counter+skipped > 1: if counter > 0: msg += u"Imported <strong>{0:d}</strong> key {1}. ".format(counter, u"file" if counter == 1 else u"files") if skipped > 0: msg += u"Skipped <strong>{0:d}</strong> key {1}.".format(skipped, u"file" if counter == 1 else u"files") inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), _(msg), show_copy_button=False, show=True) return counter > 0 def migrate_wrapper(self): if self.migrate_files(): self.listy.clear() self.populate_list() def export_key(self): if not self.listy.currentItem(): errmsg = u"No keyfile selected to export. Highlight a keyfile first." r = error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), _(errmsg), show=True, show_copy_button=False) return filter = QString(u"{0} Files (*.{1})".format(self.key_type_name, self.keyfile_ext)) keyname = unicode(self.listy.currentItem().text().toUtf8(), 'utf8') if dynamic.get(PLUGIN_NAME + 'save_dir'): defaultname = os.path.join(dynamic.get(PLUGIN_NAME + 'save_dir'), u"{0}.{1}".format(keyname , self.keyfile_ext)) else: defaultname = os.path.join(os.path.expanduser('~'), u"{0}.{1}".format(keyname , self.keyfile_ext)) filename = unicode(QtGui.QFileDialog.getSaveFileName(self, u"Save {0} File as...".format(self.key_type_name), defaultname, u"{0} Files (*.{1})".format(self.key_type_name,self.keyfile_ext), filter)) if filename: dynamic[PLUGIN_NAME + 'save_dir'] = os.path.split(filename)[0] with file(filename, 'w') as fname: if self.binary_file: fname.write(self.plugin_keys[keyname].decode('hex')) elif self.json_file: fname.write(json.dumps(self.plugin_keys[keyname])) else: fname.write(self.plugin_keys[keyname])
def __init__(self, parent, key_type_name, plugin_keys, create_key, keyfile_ext = u""): QDialog.__init__(self,parent) self.parent = parent self.key_type_name = key_type_name self.plugin_keys = plugin_keys self.create_key = create_key self.keyfile_ext = keyfile_ext self.import_key = (keyfile_ext != u"") self.binary_file = (key_type_name == u"Adobe Digital Editions Key") self.json_file = (key_type_name == u"Kindle for Mac and PC Key") self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name)) # Start Qt Gui dialog layout layout = QVBoxLayout(self) self.setLayout(layout) help_layout = QHBoxLayout() layout.addLayout(help_layout) # Add hyperlink to a help file at the right. We will replace the correct name when it is clicked. help_label = QLabel('<a href="http://www.foo.com/">Help</a>', self) help_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_label.setAlignment(Qt.AlignRight) help_label.linkActivated.connect(self.help_link_activated) help_layout.addWidget(help_label) keys_group_box = QGroupBox(_(u"{0}s".format(self.key_type_name)), self) layout.addWidget(keys_group_box) keys_group_box_layout = QHBoxLayout() keys_group_box.setLayout(keys_group_box_layout) self.listy = QListWidget(self) self.listy.setToolTip(u"{0}s that will be used to decrypt ebooks".format(self.key_type_name)) self.listy.setSelectionMode(QAbstractItemView.SingleSelection) self.populate_list() keys_group_box_layout.addWidget(self.listy) button_layout = QVBoxLayout() keys_group_box_layout.addLayout(button_layout) self._add_key_button = QtGui.QToolButton(self) self._add_key_button.setToolTip(u"Create new {0}".format(self.key_type_name)) self._add_key_button.setIcon(QIcon(I('plus.png'))) self._add_key_button.clicked.connect(self.add_key) button_layout.addWidget(self._add_key_button) self._delete_key_button = QtGui.QToolButton(self) self._delete_key_button.setToolTip(_(u"Delete highlighted key")) self._delete_key_button.setIcon(QIcon(I('list_remove.png'))) self._delete_key_button.clicked.connect(self.delete_key) button_layout.addWidget(self._delete_key_button) if type(self.plugin_keys) == dict: self._rename_key_button = QtGui.QToolButton(self) self._rename_key_button.setToolTip(_(u"Rename highlighted key")) self._rename_key_button.setIcon(QIcon(I('edit-select-all.png'))) self._rename_key_button.clicked.connect(self.rename_key) button_layout.addWidget(self._rename_key_button) self.export_key_button = QtGui.QToolButton(self) self.export_key_button.setToolTip(u"Save highlighted key to a .{0} file".format(self.keyfile_ext)) self.export_key_button.setIcon(QIcon(I('save.png'))) self.export_key_button.clicked.connect(self.export_key) button_layout.addWidget(self.export_key_button) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) button_layout.addItem(spacerItem) layout.addSpacing(5) migrate_layout = QHBoxLayout() layout.addLayout(migrate_layout) if self.import_key: migrate_layout.setAlignment(Qt.AlignJustify) self.migrate_btn = QPushButton(u"Import Existing Keyfiles", self) self.migrate_btn.setToolTip(u"Import *.{0} files (created using other tools).".format(self.keyfile_ext)) self.migrate_btn.clicked.connect(self.migrate_wrapper) migrate_layout.addWidget(self.migrate_btn) migrate_layout.addStretch() self.button_box = QDialogButtonBox(QDialogButtonBox.Close) self.button_box.rejected.connect(self.close) migrate_layout.addWidget(self.button_box) self.resize(self.sizeHint())
def keyPressEvent(self, event): if event.key() == Qt.Key_Delete: self.delete_format.emit() else: return QListWidget.keyPressEvent(self, event)
class AddBookDialog(SizePersistedDialog): def __init__(self, parent=None, mm=None, mi = None): SizePersistedDialog.__init__(self, parent, 'casanova plugin:add book dialog') self.setWindowTitle('Add text to Casanova:') self.gui = parent self.mm = mm self.mi = mi self.one_line_description = '' layout = QVBoxLayout(self) self.setLayout(layout) self.one_liner_label = QLabel('Enter a short description (255 chars max) before pressing OK') layout.addWidget(self.one_liner_label) self.one_liner_str = QLineEdit(self) self.one_liner_str.setText('') layout.addWidget(self.one_liner_str) self.one_liner_label.setBuddy(self.one_liner_str) self.values_label = QLabel('Below are potential matches of texts that already exist - please make sure you are adding something new') layout.addWidget(self.values_label) self.values_list = QListWidget(self) self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection) layout.addWidget(self.values_list) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_box.accepted.connect(self._accept_clicked) self.button_box.rejected.connect(self.reject) layout.addWidget(self.button_box) self._display_choices() # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def _display_choices(self): self.values_list.clear() choices = self.mm.search(self.mi.title) if choices is None or len(choices)==0: item = QListWidgetItem(get_icon('images/books.png'), _('there seem to be no matches'), self.values_list) self.values_list.addItem(item) for id, name in choices.items(): item = QListWidgetItem(get_icon('images/books.png'), name, self.values_list) item.setData(1, (id,)) self.values_list.addItem(item) def _accept_clicked(self): #self._save_preferences() one_liner = unicode(self.one_liner_str.text()) if one_liner=='': self.values_list.clear() item = QListWidgetItem(get_icon('images/books.png'), _('you need to enter a short description'), self.values_list) self.values_list.addItem(item) else: self.one_line_description = one_liner self.accept()