def launch_editor(path_to_edit, path_is_raw=False, syntax='html', callback=None): from calibre.gui2.tweak_book import dictionaries from calibre.gui2.tweak_book.main import option_parser from calibre.gui2.tweak_book.ui import Main from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status dictionaries.initialize() refresh_spell_check_status() opts = option_parser().parse_args([]) app = QApplication([]) # Create the actions that are placed into the editors toolbars main = Main(opts) # noqa if path_is_raw: raw = path_to_edit else: with open(path_to_edit, 'rb') as f: raw = f.read().decode('utf-8') ext = path_to_edit.rpartition('.')[-1].lower() if ext in ('html', 'htm', 'xhtml', 'xhtm'): syntax = 'html' elif ext in ('css', ): syntax = 'css' t = Editor(syntax) t.data = raw if callback is not None: callback(t) t.show() app.exec_()
def launch_editor(path_to_edit, path_is_raw=False, syntax='html', callback=None): from calibre.gui2.tweak_book import dictionaries from calibre.gui2.tweak_book.main import option_parser from calibre.gui2.tweak_book.ui import Main from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status dictionaries.initialize() refresh_spell_check_status() opts = option_parser().parse_args([]) app = QApplication([]) # Create the actions that are placed into the editors toolbars main = Main(opts) # noqa if path_is_raw: raw = path_to_edit else: with open(path_to_edit, 'rb') as f: raw = f.read().decode('utf-8') ext = path_to_edit.rpartition('.')[-1].lower() if ext in ('html', 'htm', 'xhtml', 'xhtm'): syntax = 'html' elif ext in ('css',): syntax = 'css' t = Editor(syntax) t.data = raw if callback is not None: callback(t) t.show() app.exec_()
def __init__(self, parent=None): self.__current_word = None self.thread = None self.cancel = False dictionaries.initialize() self.current_word_changed_timer = t = QTimer() t.timeout.connect(self.do_current_word_changed) t.setSingleShot(True), t.setInterval(100) Dialog.__init__(self, _('Check spelling'), 'spell-check', parent) self.work_finished.connect(self.work_done, type=Qt.QueuedConnection) self.setAttribute(Qt.WA_DeleteOnClose, False)
if current_editor_name not in files: current_editor_name = None locations = [(fname, {l.original_word for l in _locations}, False) for fname, _locations in files.iteritems()] else: # Re-order the list of locations to search so that we search in the # current editor first lfiles = list(files) idx = lfiles.index(current_editor_name) before, after = lfiles[:idx], lfiles[idx+1:] lfiles = after + before + [current_editor_name] locations = [(current_editor_name, {l.original_word for l in files[current_editor_name]}, True)] for fname in lfiles: locations.append((fname, {l.original_word for l in files[fname]}, False)) for file_name, original_words, from_cursor in locations: ed = editors.get(file_name, None) if ed is None: edit_file(file_name) ed = editors[file_name] if ed.find_spell_word(original_words, word[1].langcode, from_cursor=from_cursor): show_editor(file_name) return True return False # }}} if __name__ == '__main__': app = QApplication([]) dictionaries.initialize() SpellCheck.test() del app