def rehighlight(self): QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor)) QSyntaxHighlighter.rehighlight(self) QApplication.restoreOverrideCursor()
def __init__(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
def __enter__(self): self.stacks.setCurrentIndex(0) self.busy.setVisible(True) self.busy.pi.startAnimation() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents(QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers)
def __enter__(self): QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
def busy_cursor(): try: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) yield finally: QApplication.restoreOverrideCursor()
def ontableWidgetBridgeRightClicked(self, pos): index = self.tableWidgetBridge.indexAt(pos) clickedRow.rightClickedRow = index.row() clickedRow.mousePos = QCursor().pos() self.popMenu.move(QCursor().pos()) self.popMenu.show()
def _context_menu(self, pos): text = self._view.text if not text.textCursor().hasSelection(): # move to mouse position text.setTextCursor(text.cursorForPosition(pos)) image, width, height, fmt = None, -1, -1, "" if self._doc.in_image(): # select image text.setTextCursor(text.cursorForPosition(pos)) cursor = text.textCursor() p = cursor.position() cursor.setPosition(p) cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor) text.setTextCursor(cursor) if "<img" not in cursor.selection().toHtml(): cursor.setPosition(p) cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor) text.setTextCursor(cursor) image, width, height, fmt = ( self._doc.get_image(cursor.selection().toHtml())) menu = text.createStandardContextMenu() # --------------------------------------------------------------------- # menu for change size of image if image: menu.insertSeparator(menu.actions()[0]) param = (image, width, height, fmt) change_size = QAction(self.tr("Change size of image"), None) change_size.triggered.connect( lambda y, x=param: self._change_image_size(x)) menu.insertAction(menu.actions()[0], change_size) # --------------------------------------------------------------------- # menu for spell checker if self._spell.enabled() and text.toPlainText(): old_cur = text.textCursor() cursor = text.cursorForPosition(pos) curchar = text.document().characterAt(cursor.position()) isalpha = curchar.isalpha() cursor.select(QTextCursor.WordUnderCursor) word = "" if isalpha: text.setTextCursor(cursor) word = cursor.selectedText() text.setTextCursor(old_cur) if word and not self._spell.check_word(word): to_dict_action = QAction( self.tr("Add to the dictionary"), None) to_dict_action.triggered.connect( lambda y, x=word: self._add_word_to_spell(x)) font = to_dict_action.font() repl_actions = [] to_repl = self._spell.candidates(word) if to_repl: self._cursor_to_change_word = cursor font.setBold(True) enabled = not self._view.text.isReadOnly() for wrd in to_repl: repl_actions.append(QAction(wrd, None)) repl_actions[-1].setFont(font) repl_actions[-1].setEnabled(enabled) repl_actions[-1].triggered.connect( lambda y, x=wrd: self._fix_word(x)) else: repl_actions.append(QWidgetAction(self)) label = QLabel(self.tr("There are no words to replace")) label.setContentsMargins(28, 6, 6, 6) label.setStyleSheet("color: red") repl_actions[0].setDefaultWidget(label) repl_actions[0].setEnabled(False) menu.insertSeparator(menu.actions()[0]) menu.insertAction(menu.actions()[0], to_dict_action) menu.insertSeparator(menu.actions()[0]) for a in reversed(repl_actions): menu.insertAction(menu.actions()[0], a) # --------------------------------------------------------------------- # solving the problem of missing icons in Windows name_actions = { self.tr("Undo"): "Undo", self.tr("Redo"): "Redo", self.tr("Cut"): "Cut", self.tr("Copy"): "Copy", self.tr("Paste"): "Paste", self.tr("Delete"): "Delete", } for a in menu.actions(): txt = a.text().replace("&", "") if txt in name_actions: a.setIcon(QIcon(img(f"edit-{name_actions[txt].lower()}"))) # --------------------------------------------------------------------- # menu for table if self._doc.in_table() and not self._view.text.isReadOnly(): menu.addSeparator() t_menu = menu.addMenu(self.tr("Table")) t_menu.addAction(self._actions["add-row"]) t_menu.addAction(self._actions["add-col"]) t_menu.addSeparator() t_menu.addAction(self._actions["del-row"]) t_menu.addAction(self._actions["del-col"]) t_menu.addSeparator() t_menu.addAction(self._actions["ins-row"]) t_menu.addAction(self._actions["ins-col"]) t_menu.addSeparator() t_menu.addAction(self._actions["merge-cells"]) t_menu.addAction(self._actions["split-cells"]) cursor = text.textCursor() self._actions["merge-cells"].setEnabled(cursor.hasSelection()) cell = cursor.currentTable().cellAt(cursor) self._actions["split-cells"].setEnabled( cell.rowSpan() > 1 or cell.columnSpan() > 1) menu.addSeparator() menu.addAction(self._actions["toPDF"]) menu.addAction(self._actions["print"]) menu.exec_(QCursor().pos()) self._restore_cursor()
def _do_split(self, db, source_id, misource, splitepub, origlines, newspecs, deftitle=None): linenums, changedtocs, checkedalways = newspecs # logger.debug("updated tocs:%s"%changedtocs) if not self.has_lines(linenums): return #logger.debug("2:%s"%(time.time()-self.t)) self.t = time.time() #logger.debug("linenums:%s"%linenums) defauthors = None if not deftitle and prefs['copytoctitle']: if linenums[0] in changedtocs: deftitle = changedtocs[linenums[0]][0] # already unicoded()'ed elif len(origlines[linenums[0]]['toc']) > 0: deftitle = unicode(origlines[linenums[0]]['toc'][0]) #logger.debug("deftitle:%s"%deftitle) if not deftitle and prefs['copytitle']: deftitle = _("%s Split") % misource.title if prefs['copyauthors']: defauthors = misource.authors mi = MetaInformation(deftitle, defauthors) if prefs['copytags']: mi.tags = misource.tags # [item for sublist in tagslists for item in sublist] if prefs['copylanguages']: mi.languages = misource.languages if prefs['copyseries']: mi.series = misource.series if prefs['copydate']: mi.timestamp = misource.timestamp if prefs['copyrating']: mi.rating = misource.rating if prefs['copypubdate']: mi.pubdate = misource.pubdate if prefs['copypublisher']: mi.publisher = misource.publisher if prefs['copyidentifiers']: mi.set_identifiers(misource.get_identifiers()) if prefs['copycomments'] and misource.comments: mi.comments = "<p>" + _("Split from:") + "</p>" + misource.comments #logger.debug("mi:%s"%mi) book_id = db.create_book_entry(mi, add_duplicates=True) if prefs['copycover'] and misource.has_cover: db.set_cover(book_id, db.cover(source_id, index_is_id=True)) #logger.debug("3:%s"%(time.time()-self.t)) self.t = time.time() custom_columns = self.gui.library_view.model().custom_columns for col, action in six.iteritems(prefs['custom_cols']): #logger.debug("col: %s action: %s"%(col,action)) if col not in custom_columns: #logger.debug("%s not an existing column, skipping."%col) continue coldef = custom_columns[col] #logger.debug("coldef:%s"%coldef) label = coldef['label'] value = db.get_custom(source_id, label=label, index_is_id=True) if value: db.set_custom(book_id, value, label=label, commit=False) #logger.debug("3.5:%s"%(time.time()-self.t)) self.t = time.time() if prefs['sourcecol'] != '' and prefs['sourcecol'] in custom_columns \ and prefs['sourcetemplate']: val = SafeFormat().safe_format(prefs['sourcetemplate'], misource, 'EpubSplit Source Template Error', misource) #logger.debug("Attempting to set %s to %s"%(prefs['sourcecol'],val)) label = custom_columns[prefs['sourcecol']]['label'] if custom_columns[prefs['sourcecol']]['datatype'] == 'series': val = val + (" [%s]" % self.book_count) db.set_custom(book_id, val, label=label, commit=False) self.book_count = self.book_count + 1 db.commit() #logger.debug("4:%s"%(time.time()-self.t)) self.t = time.time() self.gui.library_view.model().books_added(1) self.gui.library_view.select_rows([book_id]) #logger.debug("5:%s"%(time.time()-self.t)) self.t = time.time() editconfig_txt = _( 'You can enable or disable Edit Metadata in Preferences > Plugins > EpubSplit.' ) if prefs['editmetadata']: confirm( '\n' + _('''The book for the new Split EPUB has been created and default metadata filled in. However, the EPUB will *not* be created until after you've reviewed, edited, and closed the metadata dialog that follows. You can fill in the metadata yourself, or use download metadata for known books. If you download or add a cover image, it will be included in the generated EPUB.''' ) + '\n\n' + editconfig_txt + '\n', 'epubsplit_created_now_edit_again', self.gui) self.gui.iactions['Edit Metadata'].edit_metadata(False) try: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) #logger.debug("5:%s"%(time.time()-self.t)) self.t = time.time() self.gui.tags_view.recount() self.gui.status_bar.show_message(_('Splitting off from EPUB...'), 60000) mi = db.get_metadata(book_id, index_is_id=True) outputepub = PersistentTemporaryFile(suffix='.epub') coverjpgpath = None if mi.has_cover: # grab the path to the real image. coverjpgpath = os.path.join(db.library_path, db.path(book_id, index_is_id=True), 'cover.jpg') outlist = list(set(linenums + checkedalways)) outlist.sort() splitepub.write_split_epub(outputepub, outlist, changedtocs=changedtocs, authoropts=mi.authors, titleopt=mi.title, descopt=mi.comments, tags=mi.tags, languages=mi.languages, coverjpgpath=coverjpgpath) #logger.debug("6:%s"%(time.time()-self.t)) self.t = time.time() db.add_format_with_hooks(book_id, 'EPUB', outputepub, index_is_id=True) #logger.debug("7:%s"%(time.time()-self.t)) self.t = time.time() self.gui.status_bar.show_message(_('Finished splitting off EPUB.'), 3000) self.gui.library_view.model().refresh_ids([book_id]) self.gui.tags_view.recount() current = self.gui.library_view.currentIndex() self.gui.library_view.model().current_changed( current, self.previous) if self.gui.cover_flow: self.gui.cover_flow.dataChanged() finally: QApplication.restoreOverrideCursor() if not prefs['editmetadata']: confirm( '<p>' + '</p><p>'.join([ _('<b><u>%s</u> by %s</b> has been created and default metadata filled in.' ) % (mi.title, ', '.join(mi.authors)), _('EpubSplit now skips the Edit Metadata step by default.' ), editconfig_txt ]) + '</p>', 'epubsplit_created_now_no_edit_again', self.gui)
def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor))
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() #获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.OpenHandCursor)) #更改鼠标图标
def dispatcher(self): container = self.current_container # The book being edited as a container object if not container: return info_dialog(self.gui, _('No book open'), _('Need to have a book open first.'), show=True) self.filesChanged = False self.changed_files = [] from calibre_plugins.chinese_text.dialogs import ConversionDialog from calibre_plugins.chinese_text.resources.dialogs import ResultsDialog dlg = ConversionDialog(self.gui) if dlg.exec_(): criteria = dlg.getCriteria() # Ensure any in progress editing the user is doing is present in the container self.boss.commit_all_editors_to_container() self.boss.add_savepoint(_('Before: Text Conversion')) try: conversion = get_configuration(criteria) if conversion == 'None': info_dialog( self.gui, _('No Changes'), _('The output configuration selected is not supported.\n Please use a different input/output style combination' ), show=True) else: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() if conversion != 'no_conversion': self.converter.set_conversion( get_configuration(criteria)) self.process_files(criteria) QApplication.restoreOverrideCursor() except Exception: QApplication.restoreOverrideCursor() # Something bad happened report the error to the user import traceback error_dialog( self.gui, _('Failed'), _('Failed to convert Chinese, click "Show details" for more info' ), det_msg=traceback.format_exc(), show=True) # Revert to the saved restore point self.boss.revert_requested( self.boss.global_undo.previous_container) else: if self.filesChanged: # Show the user what changes we have made, # allowing then to revert them if necessary accepted = ResultsDialog(self.gui, self.changed_files).exec_() if accepted == QDialog.Accepted: self.boss.show_current_diff() # Update the editor UI to take into account all the changes we # have made self.boss.apply_container_update_to_gui() elif conversion != 'None': info_dialog( self.gui, _('No Changes'), _('No text meeting your criteria was found to change.\nNo changes made.' ), show=True)