本文整理匯總了Python中calibre.gui2.tweak_book.editor.smarts.NullSmarts.set_text_alignment方法的典型用法代碼示例。如果您正苦於以下問題:Python NullSmarts.set_text_alignment方法的具體用法?Python NullSmarts.set_text_alignment怎麽用?Python NullSmarts.set_text_alignment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calibre.gui2.tweak_book.editor.smarts.NullSmarts
的用法示例。
在下文中一共展示了NullSmarts.set_text_alignment方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import set_text_alignment [as 別名]
#.........這裏部分代碼省略.........
if ev.modifiers() & Qt.CTRL:
url = self.link_for_position(ev.pos())
if url is not None:
ev.accept()
self.link_clicked.emit(url)
return
return PlainTextEdit.mousePressEvent(self, ev)
def get_range_inside_tag(self):
c = self.textCursor()
left = min(c.anchor(), c.position())
right = max(c.anchor(), c.position())
# For speed we use QPlainTextEdit's toPlainText as we dont care about
# spaces in this context
raw = unicode(QPlainTextEdit.toPlainText(self))
# Make sure the left edge is not within a <>
gtpos = raw.find('>', left)
ltpos = raw.find('<', left)
if gtpos < ltpos:
left = gtpos + 1 if gtpos > -1 else left
right = max(left, right)
if right != left:
gtpos = raw.find('>', right)
ltpos = raw.find('<', right)
if ltpos > gtpos:
ltpos = raw.rfind('<', left, right+1)
right = max(ltpos, left)
return left, right
def format_text(self, formatting):
if self.syntax != 'html':
return
if formatting.startswith('justify_'):
return self.smarts.set_text_alignment(self, formatting.partition('_')[-1])
color = 'currentColor'
if formatting in {'color', 'background-color'}:
color = QColorDialog.getColor(QColor(Qt.black if formatting == 'color' else Qt.white), self, _('Choose color'), QColorDialog.ShowAlphaChannel)
if not color.isValid():
return
r, g, b, a = color.getRgb()
if a == 255:
color = 'rgb(%d, %d, %d)' % (r, g, b)
else:
color = 'rgba(%d, %d, %d, %.2g)' % (r, g, b, a/255)
prefix, suffix = {
'bold': ('<b>', '</b>'),
'italic': ('<i>', '</i>'),
'underline': ('<u>', '</u>'),
'strikethrough': ('<strike>', '</strike>'),
'superscript': ('<sup>', '</sup>'),
'subscript': ('<sub>', '</sub>'),
'color': ('<span style="color: %s">' % color, '</span>'),
'background-color': ('<span style="background-color: %s">' % color, '</span>'),
}[formatting]
left, right = self.get_range_inside_tag()
c = self.textCursor()
c.setPosition(left)
c.setPosition(right, c.KeepAnchor)
prev_text = unicode(c.selectedText()).rstrip('\0')
c.insertText(prefix + prev_text + suffix)
if prev_text:
right = c.position()
c.setPosition(left)
c.setPosition(right, c.KeepAnchor)
else:
c.setPosition(c.position() - len(suffix))
示例2: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import set_text_alignment [as 別名]
#.........這裏部分代碼省略.........
if ev.modifiers() & Qt.CTRL:
url = self.link_for_position(ev.pos())
if url is not None:
ev.accept()
self.link_clicked.emit(url)
return
return PlainTextEdit.mousePressEvent(self, ev)
def get_range_inside_tag(self):
c = self.textCursor()
left = min(c.anchor(), c.position())
right = max(c.anchor(), c.position())
# For speed we use QPlainTextEdit's toPlainText as we dont care about
# spaces in this context
raw = unicode(QPlainTextEdit.toPlainText(self))
# Make sure the left edge is not within a <>
gtpos = raw.find(">", left)
ltpos = raw.find("<", left)
if gtpos < ltpos:
left = gtpos + 1 if gtpos > -1 else left
right = max(left, right)
if right != left:
gtpos = raw.find(">", right)
ltpos = raw.find("<", right)
if ltpos > gtpos:
ltpos = raw.rfind("<", left, right + 1)
right = max(ltpos, left)
return left, right
def format_text(self, formatting):
if self.syntax != "html":
return
if formatting.startswith("justify_"):
return self.smarts.set_text_alignment(self, formatting.partition("_")[-1])
color = "currentColor"
if formatting in {"color", "background-color"}:
color = QColorDialog.getColor(
QColor(Qt.black if formatting == "color" else Qt.white),
self,
_("Choose color"),
QColorDialog.ShowAlphaChannel,
)
if not color.isValid():
return
r, g, b, a = color.getRgb()
if a == 255:
color = "rgb(%d, %d, %d)" % (r, g, b)
else:
color = "rgba(%d, %d, %d, %.2g)" % (r, g, b, a / 255)
prefix, suffix = {
"bold": ("<b>", "</b>"),
"italic": ("<i>", "</i>"),
"underline": ("<u>", "</u>"),
"strikethrough": ("<strike>", "</strike>"),
"superscript": ("<sup>", "</sup>"),
"subscript": ("<sub>", "</sub>"),
"color": ('<span style="color: %s">' % color, "</span>"),
"background-color": ('<span style="background-color: %s">' % color, "</span>"),
}[formatting]
left, right = self.get_range_inside_tag()
c = self.textCursor()
c.setPosition(left)
c.setPosition(right, c.KeepAnchor)
prev_text = unicode(c.selectedText()).rstrip("\0")
c.insertText(prefix + prev_text + suffix)
if prev_text:
示例3: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import set_text_alignment [as 別名]
#.........這裏部分代碼省略.........
if ev.modifiers() & Qt.CTRL:
url = self.link_for_position(ev.pos())
if url is not None:
ev.accept()
self.link_clicked.emit(url)
return
return PlainTextEdit.mousePressEvent(self, ev)
def get_range_inside_tag(self):
c = self.textCursor()
left = min(c.anchor(), c.position())
right = max(c.anchor(), c.position())
# For speed we use QPlainTextEdit's toPlainText as we dont care about
# spaces in this context
raw = unicode_type(QPlainTextEdit.toPlainText(self))
# Make sure the left edge is not within a <>
gtpos = raw.find('>', left)
ltpos = raw.find('<', left)
if gtpos < ltpos:
left = gtpos + 1 if gtpos > -1 else left
right = max(left, right)
if right != left:
gtpos = raw.find('>', right)
ltpos = raw.find('<', right)
if ltpos > gtpos:
ltpos = raw.rfind('<', left, right+1)
right = max(ltpos, left)
return left, right
def format_text(self, formatting):
if self.syntax != 'html':
return
if formatting.startswith('justify_'):
return self.smarts.set_text_alignment(self, formatting.partition('_')[-1])
color = 'currentColor'
if formatting in {'color', 'background-color'}:
color = QColorDialog.getColor(QColor(Qt.black if formatting == 'color' else Qt.white), self, _('Choose color'), QColorDialog.ShowAlphaChannel)
if not color.isValid():
return
r, g, b, a = color.getRgb()
if a == 255:
color = 'rgb(%d, %d, %d)' % (r, g, b)
else:
color = 'rgba(%d, %d, %d, %.2g)' % (r, g, b, a/255)
prefix, suffix = {
'bold': ('<b>', '</b>'),
'italic': ('<i>', '</i>'),
'underline': ('<u>', '</u>'),
'strikethrough': ('<strike>', '</strike>'),
'superscript': ('<sup>', '</sup>'),
'subscript': ('<sub>', '</sub>'),
'color': ('<span style="color: %s">' % color, '</span>'),
'background-color': ('<span style="background-color: %s">' % color, '</span>'),
}[formatting]
left, right = self.get_range_inside_tag()
c = self.textCursor()
c.setPosition(left)
c.setPosition(right, c.KeepAnchor)
prev_text = unicode_type(c.selectedText()).rstrip('\0')
c.insertText(prefix + prev_text + suffix)
if prev_text:
right = c.position()
c.setPosition(left)
c.setPosition(right, c.KeepAnchor)
else:
c.setPosition(c.position() - len(suffix))