def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QGridLayout(self) def add_row(*args): r = l.rowCount() if len(args) == 1: l.addWidget(args[0], r, 0, 1, 2) else: la = QLabel(args[0]) l.addWidget(la, r, 0, Qt.AlignmentFlag.AlignRight), l.addWidget(args[1], r, 1) la.setBuddy(args[1]) self.heading = la = QLabel('<h2>\xa0') add_row(la) self.helpl = la = QLabel(_('For help with snippets, see the <a href="%s">User Manual</a>') % localize_user_manual_link('https://manual.calibre-ebook.com/snippets.html')) la.setOpenExternalLinks(True) add_row(la) self.name = n = QLineEdit(self) n.setPlaceholderText(_('The name of this snippet')) add_row(_('&Name:'), n) self.trig = t = QLineEdit(self) t.setPlaceholderText(_('The text used to trigger this snippet')) add_row(_('Tri&gger:'), t) self.template = t = QPlainTextEdit(self) la.setBuddy(t) add_row(_('&Template:'), t) self.types = t = QListWidget(self) t.setFlow(QListView.Flow.LeftToRight) t.setWrapping(True), t.setResizeMode(QListView.ResizeMode.Adjust), t.setSpacing(5) fm = t.fontMetrics() t.setMaximumHeight(2*(fm.ascent() + fm.descent()) + 25) add_row(_('&File types:'), t) t.setToolTip(_('Which file types this snippet should be active in')) self.frame = f = QFrame(self) f.setFrameShape(f.HLine) add_row(f) self.test = d = SnippetTextEdit('', self) d.snippet_manager.snip_func = self.snip_func d.setToolTip(_('You can test your snippet here')) d.setMaximumHeight(t.maximumHeight() + 15) add_row(_('T&est:'), d) i = QListWidgetItem(_('All'), t) i.setData(Qt.ItemDataRole.UserRole, '*') i.setCheckState(Qt.CheckState.Checked) i.setFlags(i.flags() | Qt.ItemFlag.ItemIsUserCheckable) for ftype in sorted(all_text_syntaxes): i = QListWidgetItem(ftype, t) i.setData(Qt.ItemDataRole.UserRole, ftype) i.setCheckState(Qt.CheckState.Checked) i.setFlags(i.flags() | Qt.ItemFlag.ItemIsUserCheckable) self.creating_snippet = False
def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QGridLayout(self) def add_row(*args): r = l.rowCount() if len(args) == 1: l.addWidget(args[0], r, 0, 1, 2) else: la = QLabel(args[0]) l.addWidget(la, r, 0, Qt.AlignRight), l.addWidget(args[1], r, 1) la.setBuddy(args[1]) self.heading = la = QLabel('<h2>\xa0') add_row(la) self.helpl = la = QLabel(_('For help with snippets, see the <a href="%s">User Manual</a>') % localize_user_manual_link('https://manual.calibre-ebook.com/snippets.html')) la.setOpenExternalLinks(True) add_row(la) self.name = n = QLineEdit(self) n.setPlaceholderText(_('The name of this snippet')) add_row(_('&Name:'), n) self.trig = t = QLineEdit(self) t.setPlaceholderText(_('The text used to trigger this snippet')) add_row(_('Tri&gger:'), t) self.template = t = QPlainTextEdit(self) la.setBuddy(t) add_row(_('&Template:'), t) self.types = t = QListWidget(self) t.setFlow(t.LeftToRight) t.setWrapping(True), t.setResizeMode(t.Adjust), t.setSpacing(5) fm = t.fontMetrics() t.setMaximumHeight(2*(fm.ascent() + fm.descent()) + 25) add_row(_('&File types:'), t) t.setToolTip(_('Which file types this snippet should be active in')) self.frame = f = QFrame(self) f.setFrameShape(f.HLine) add_row(f) self.test = d = SnippetTextEdit('', self) d.snippet_manager.snip_func = self.snip_func d.setToolTip(_('You can test your snippet here')) d.setMaximumHeight(t.maximumHeight() + 15) add_row(_('T&est:'), d) i = QListWidgetItem(_('All'), t) i.setData(Qt.UserRole, '*') i.setCheckState(Qt.Checked) i.setFlags(i.flags() | Qt.ItemIsUserCheckable) for ftype in sorted(all_text_syntaxes): i = QListWidgetItem(ftype, t) i.setData(Qt.UserRole, ftype) i.setCheckState(Qt.Checked) i.setFlags(i.flags() | Qt.ItemIsUserCheckable) self.creating_snippet = False
def set_bookmarks(self, bookmarks=()): csb = self.current_sort_by if csb == 'name': sk = lambda x: sort_key(x['title']) elif csb == 'timestamp': sk = itemgetter('timestamp') else: from calibre.ebooks.epub.cfi.parse import cfi_sort_key defval = cfi_sort_key('/99999999') def pos_key(b): if b.get('pos_type') == 'epubcfi': return cfi_sort_key(b['pos'], only_path=False) return defval sk = pos_key bookmarks = sorted(bookmarks, key=sk) current_bookmark_id = self.current_bookmark_id self.bookmarks_list.clear() for bm in bookmarks: i = QListWidgetItem(bm['title']) i.setData(Qt.UserRole, self.bm_to_item(bm)) i.setFlags(i.flags() | Qt.ItemIsEditable) self.bookmarks_list.addItem(i) if bm.get('removed'): i.setHidden(True) for i in range(self.bookmarks_list.count()): item = self.bookmarks_list.item(i) if not item.isHidden(): self.bookmarks_list.setCurrentItem( item, QItemSelectionModel.ClearAndSelect) break if current_bookmark_id is not None: self.current_bookmark_id = current_bookmark_id
def refill_all_boxes(self): if self.refilling: return self.refilling = True self.current_device = None self.current_format = None self.clear_fields(new_boxes=True) self.edit_format.clear() self.edit_format.addItem('') for format_ in self.current_plugboards: self.edit_format.addItem(format_) self.edit_format.setCurrentIndex(0) self.edit_device.clear() self.ok_button.setEnabled(False) self.del_button.setEnabled(False) self.existing_plugboards.clear() for f in self.formats: if f not in self.current_plugboards: continue for d in sorted(self.devices + self.disabled_devices, key=lambda x:x.lower()): if d not in self.current_plugboards[f]: continue ops = [] for op in self.current_plugboards[f][d]: ops.append('([' + op[0] + '] -> ' + op[1] + ')') txt = '%s:%s = %s\n'%(f, d, ', '.join(ops)) item = QListWidgetItem(txt) item.setData(Qt.UserRole, (f, d)) if d in self.disabled_devices: item.setFlags(item.flags() & ~Qt.ItemIsEnabled) self.existing_plugboards.addItem(item) self.refilling = False
def refill_all_boxes(self): if self.refilling: return self.refilling = True self.current_device = None self.current_format = None self.clear_fields(new_boxes=True) self.edit_format.clear() self.edit_format.addItem('') for format_ in self.current_plugboards: self.edit_format.addItem(format_) self.edit_format.setCurrentIndex(0) self.edit_device.clear() self.ok_button.setEnabled(False) self.del_button.setEnabled(False) self.existing_plugboards.clear() for f in self.formats: if f not in self.current_plugboards: continue for d in sorted(self.devices + self.disabled_devices, key=lambda x: x.lower()): if d not in self.current_plugboards[f]: continue ops = [] for op in self.current_plugboards[f][d]: ops.append('([' + op[0] + '] -> ' + op[1] + ')') txt = '%s:%s = %s\n' % (f, d, ', '.join(ops)) item = QListWidgetItem(txt) item.setData(Qt.UserRole, (f, d)) if d in self.disabled_devices: item.setFlags(item.flags() & ~Qt.ItemIsEnabled) self.existing_plugboards.addItem(item) self.refilling = False
def image_import(self): """ Take the path(s) of one or more images and import them to the application. :return: Nothing """ file_dialog = QFileDialog() # Create QFileDialog # Open the file dialog as Open File Names dialog (for image choice) f_path = file_dialog.getOpenFileNames(parent=None, caption="Open Image(s)", directory=QDir.homePath(), filter=self.IMG_FILTER, options=self.DIALOG_FLAG)[0] if f_path: # If user chose at least one image img_id_counter = 0 # Set a counter for id for file in f_path: # For all paths in f_paths image_tmp = Image() # Create an Image object success = image_tmp.img_open(file) # Set image parameters if success: # If image exists image_tmp.img_set_image_id(img_id_counter) # Set image counter img_id_counter += 1 # increase the counter by 1 # image_tmp.img_print_info() # print image info for debugging self.image_list.append(image_tmp) # Append image to list item_name = "../" + image_tmp.info.dir_name + "/" + image_tmp.info.name # Set name for view item_widget = QListWidgetItem(item_name) # Append item to window image list item_widget.setFlags(item_widget.flags() | QtCore.Qt.ItemIsUserCheckable) # Set it checkable item_widget.setCheckState(QtCore.Qt.Checked) # Set it checked self.ui_main_win.listImage.addItem(item_widget) # Add item to list self.ui_main_win.menuCamera_Settings.setEnabled(self.UP) # Enable Camera menu self.ui_main_win.actionCrabSFM.setEnabled(self.UP) # Enable SFM action
def set_bookmarks(self, bookmarks=()): self.bookmarks_list.clear() for bm in bookmarks: i = QListWidgetItem(bm['title']) i.setData(Qt.UserRole, self.bm_to_item(bm)) i.setFlags(i.flags() | Qt.ItemIsEditable) self.bookmarks_list.addItem(i) if self.bookmarks_list.count() > 0: self.bookmarks_list.setCurrentItem(self.bookmarks_list.item(0), QItemSelectionModel.ClearAndSelect)
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.ItemFlag.ItemIsDragEnabled)
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)
def create_color_scheme(self): scheme = self.colors_map[self.current_colors].data(Qt.ItemDataRole.UserRole) d = CreateColorScheme('#' + _('My Color Scheme'), scheme, set(self.colors_map), parent=self) if d.exec_() == QDialog.DialogCode.Accepted: name, scheme = d.data li = QListWidgetItem(name) li.setData(Qt.ItemDataRole.UserRole, scheme), li.setFlags(li.flags() | Qt.ItemFlag.ItemIsUserCheckable), li.setCheckState(Qt.CheckState.Checked) self.insert_scheme(name, li) self.emit_changed() self.original_prefs['color_themes'] = self.current_prefs['color_themes']
def set_bookmarks(self, bookmarks=()): self.bookmarks_list.clear() for bm in bookmarks: if bm['title'] != 'calibre_current_page_bookmark': i = QListWidgetItem(bm['title']) i.setData(Qt.UserRole, self.bm_to_item(bm)) i.setFlags(i.flags() | Qt.ItemIsEditable) self.bookmarks_list.addItem(i) if self.bookmarks_list.count() > 0: self.bookmarks_list.setCurrentItem(self.bookmarks_list.item(0), QItemSelectionModel.ClearAndSelect)
def create_color_scheme(self): scheme = self.colors_map[self.current_colors].data(Qt.UserRole) d = CreateColorScheme('#' + _('My Color Scheme'), scheme, set(self.colors_map), parent=self) if d.exec_() == d.Accepted: name, scheme = d.data li = QListWidgetItem(name) li.setData(Qt.UserRole, scheme), li.setFlags(li.flags() | Qt.ItemIsUserCheckable), li.setCheckState(Qt.Checked) self.insert_scheme(name, li) self.emit_changed() self.original_prefs['color_themes'] = self.current_prefs['color_themes']
def video_import(self): """ Take the path(s) of one or more videos and import them to the application. :return: """ file_dialog = QFileDialog() f_path = file_dialog.getOpenFileNames(parent=None, caption="Open Video(s)", directory=QDir.homePath(), filter=self.VID_FILTER, options=self.DIALOG_FLAG)[0] if f_path: for file in f_path: video_tmp = Video() success = video_tmp.vid_open(file) if success: self.video_list.append(video_tmp) item_name = "../" + video_tmp.info.dir_name + "/" + video_tmp.info.name item_widget = QListWidgetItem(item_name) item_widget.setFlags(item_widget.flags() | QtCore.Qt.ItemIsUserCheckable) item_widget.setCheckState(QtCore.Qt.Checked) self.ui_main_win.listVideo.addItem(item_widget) self.video_list_info()
def populate_list_item(self, fav_menu, idx= -1): self.blockSignals(True) if fav_menu is None: item = QListWidgetItem(self.SEP) item.setIcon(self.blank_icon) else: text = fav_menu['display'] item = QListWidgetItem(text) item.setFlags(Qt.ItemIsEditable | item.flags()) paths = fav_menu['path'] item.setToolTip(' -> '.join(paths)) item.setData(Qt.UserRole, (fav_menu,)) icon = fav_menu.get('icon', None) if icon is None: # This is a menu item that hasn't been found in this session # We will display it with a blank icon and disabled icon = self.blank_icon item.setForeground(QBrush(Qt.darkGray)) item.setIcon(icon) if idx < 0: self.addItem(item) else: self.insertItem(idx + 1, item) self.blockSignals(False)
def __init__(self, plugin): QWidget.__init__(self) self.plugin = plugin self.layout = QVBoxLayout() self.setLayout(self.layout) self.engine_location_label = QLabel('ElasticSearch engine location:') self.layout.addWidget(self.engine_location_label) self.elasticsearch_url_textbox = QLineEdit(self) self.elasticsearch_url_textbox.setText(prefs['elasticsearch_url']) self.layout.addWidget(self.elasticsearch_url_textbox) self.engine_location_label.setBuddy(self.elasticsearch_url_textbox) self.layout.addSpacing(10) self.pdftotext_path_label = QLabel('Path to pdftotext tool:') self.layout.addWidget(self.pdftotext_path_label) self.pdftotext_path_textbox = QLineEdit(self) self.pdftotext_path_textbox.setText(prefs['pdftotext_path']) self.layout.addWidget(self.pdftotext_path_textbox) self.pdftotext_path_label.setBuddy(self.pdftotext_path_textbox) self.layout.addSpacing(10) self.concurrency_label = QLabel( 'Number of parallel processes for text extraction:') self.layout.addWidget(self.concurrency_label) self.concurrency_textbox = QLineEdit(self) self.concurrency_textbox.setText(str(prefs['concurrency'])) self.layout.addWidget(self.concurrency_textbox) self.concurrency_label.setBuddy(self.concurrency_textbox) self.layout.addSpacing(10) self.formats_label = QLabel('Index book formats:') self.layout.addWidget(self.formats_label) file_formats = prefs['file_formats'].split(',') self.formats_list = QListWidget(self) for fmt in SUPPORTED_FORMATS: item = QListWidgetItem(fmt) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked if fmt in file_formats else Qt.Unchecked) self.formats_list.addItem(item) self.layout.addWidget(self.formats_list) self.formats_label.setBuddy(self.formats_list) self.layout.addSpacing(10) self.autoindex_checkbox = QCheckBox( "Automatically index new books on search", self) self.autoindex_checkbox.setCheckState( Qt.Checked if prefs['autoindex'] else Qt.Unchecked) self.layout.addWidget(self.autoindex_checkbox) self.layout.addSpacing(10) self.privacy_label = QLabel('Privacy:') self.layout.addWidget(self.privacy_label) self.clear_search_history_button = QPushButton('Clear search &history', self) self.clear_search_history_button.clicked.connect(self.on_clear_history) self.layout.addWidget(self.clear_search_history_button) self.clear_search_index_buttin = QPushButton('Clear search &index', self) self.clear_search_index_buttin.clicked.connect(self.on_clear_index) self.layout.addWidget(self.clear_search_index_buttin)