本文整理汇总了Python中calibre.gui2.tweak_book.editor.text.TextEdit.change_document_name方法的典型用法代码示例。如果您正苦于以下问题:Python TextEdit.change_document_name方法的具体用法?Python TextEdit.change_document_name怎么用?Python TextEdit.change_document_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.gui2.tweak_book.editor.text.TextEdit
的用法示例。
在下文中一共展示了TextEdit.change_document_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Editor
# 需要导入模块: from calibre.gui2.tweak_book.editor.text import TextEdit [as 别名]
# 或者: from calibre.gui2.tweak_book.editor.text.TextEdit import change_document_name [as 别名]
class Editor(QMainWindow):
has_line_numbers = True
modification_state_changed = pyqtSignal(object)
undo_redo_state_changed = pyqtSignal(object, object)
copy_available_state_changed = pyqtSignal(object)
data_changed = pyqtSignal(object)
cursor_position_changed = pyqtSignal()
word_ignored = pyqtSignal(object, object)
link_clicked = pyqtSignal(object)
smart_highlighting_updated = pyqtSignal()
def __init__(self, syntax, parent=None):
QMainWindow.__init__(self, parent)
if parent is None:
self.setWindowFlags(Qt.Widget)
self.is_synced_to_container = False
self.syntax = syntax
self.editor = TextEdit(self)
self.editor.setContextMenuPolicy(Qt.CustomContextMenu)
self.editor.customContextMenuRequested.connect(self.show_context_menu)
self.setCentralWidget(self.editor)
self.create_toolbars()
self.undo_available = False
self.redo_available = False
self.copy_available = self.cut_available = False
self.editor.modificationChanged.connect(self._modification_state_changed)
self.editor.undoAvailable.connect(self._undo_available)
self.editor.redoAvailable.connect(self._redo_available)
self.editor.textChanged.connect(self._data_changed)
self.editor.copyAvailable.connect(self._copy_available)
self.editor.cursorPositionChanged.connect(self._cursor_position_changed)
self.editor.link_clicked.connect(self.link_clicked)
self.editor.smart_highlighting_updated.connect(self.smart_highlighting_updated)
@dynamic_property
def current_line(self):
def fget(self):
return self.editor.textCursor().blockNumber()
def fset(self, val):
self.editor.go_to_line(val)
return property(fget=fget, fset=fset)
@dynamic_property
def current_editing_state(self):
def fget(self):
c = self.editor.textCursor()
return {'cursor':(c.anchor(), c.position())}
def fset(self, val):
anchor, position = val.get('cursor', (None, None))
if anchor is not None and position is not None:
c = self.editor.textCursor()
c.setPosition(anchor), c.setPosition(position, c.KeepAnchor)
self.editor.setTextCursor(c)
return property(fget=fget, fset=fset)
def current_tag(self, for_position_sync=True):
return self.editor.current_tag(for_position_sync=for_position_sync)
@property
def number_of_lines(self):
return self.editor.blockCount()
@dynamic_property
def data(self):
def fget(self):
ans = self.get_raw_data()
ans, changed = replace_encoding_declarations(ans, enc='utf-8', limit=4*1024)
if changed:
self.data = ans
return ans.encode('utf-8')
def fset(self, val):
self.editor.load_text(val, syntax=self.syntax, doc_name=editor_name(self))
return property(fget=fget, fset=fset)
def init_from_template(self, template):
self.editor.load_text(template, syntax=self.syntax, process_template=True, doc_name=editor_name(self))
def change_document_name(self, newname):
self.editor.change_document_name(newname)
self.editor.completion_doc_name = newname
def get_raw_data(self):
# The EPUB spec requires NFC normalization, see section 1.3.6 of
# http://www.idpf.org/epub/20/spec/OPS_2.0.1_draft.htm
return unicodedata.normalize('NFC', unicode(self.editor.toPlainText()).rstrip('\0'))
def replace_data(self, raw, only_if_different=True):
if isinstance(raw, bytes):
raw = raw.decode('utf-8')
current = self.get_raw_data() if only_if_different else False
if current != raw:
self.editor.replace_text(raw)
def apply_settings(self, prefs=None, dictionaries_changed=False):
self.editor.apply_settings(prefs=None, dictionaries_changed=dictionaries_changed)
#.........这里部分代码省略.........