当前位置: 首页>>代码示例>>Python>>正文


Python smarts.NullSmarts类代码示例

本文整理汇总了Python中calibre.gui2.tweak_book.editor.smarts.NullSmarts的典型用法代码示例。如果您正苦于以下问题:Python NullSmarts类的具体用法?Python NullSmarts怎么用?Python NullSmarts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NullSmarts类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, *args, **kwargs):
     if not hasattr(Smarts, 'regexps_compiled'):
         Smarts.regexps_compiled = True
         Smarts.tag_pat = re.compile(r'<[^>]+>')
         Smarts.closing_tag_pat = re.compile(r'<\s*/[^>]+>')
         Smarts.closing_pat = re.compile(r'<\s*/')
         Smarts.self_closing_pat = re.compile(r'/\s*>')
     NullSmarts.__init__(self, *args, **kwargs)
     self.last_matched_tag = None
开发者ID:GRiker,项目名称:calibre,代码行数:9,代码来源:html.py

示例2: __init__

 def __init__(self, *args, **kwargs):
     if not hasattr(Smarts, 'regexps_compiled'):
         Smarts.regexps_compiled = True
         Smarts.tag_pat = re.compile(r'<[^>]+>')
         Smarts.closing_tag_pat = re.compile(r'<\s*/[^>]+>')
         Smarts.closing_pat = re.compile(r'<\s*/')
         Smarts.self_closing_pat = re.compile(r'/\s*>')
         Smarts.complete_attr_pat = re.compile(r'''([a-zA-Z0-9_-]+)\s*=\s*(?:'([^']*)|"([^"]*))$''')
     NullSmarts.__init__(self, *args, **kwargs)
     self.last_matched_tag = self.last_matched_closing_tag = None
开发者ID:JimmXinu,项目名称:calibre,代码行数:10,代码来源:html.py

示例3: __init__

 def __init__(self, *args, **kwargs):
     if not hasattr(Smarts, "regexps_compiled"):
         Smarts.regexps_compiled = True
         Smarts.tag_pat = re.compile(r"<[^>]+>")
         Smarts.closing_tag_pat = re.compile(r"<\s*/[^>]+>")
         Smarts.closing_pat = re.compile(r"<\s*/")
         Smarts.self_closing_pat = re.compile(r"/\s*>")
         Smarts.complete_attr_pat = re.compile(r"""([a-zA-Z0-9_-]+)\s*=\s*(?:'([^']*)|"([^"]*))$""")
     NullSmarts.__init__(self, *args, **kwargs)
     self.last_matched_tag = None
开发者ID:mihailim,项目名称:calibre,代码行数:10,代码来源:html.py

示例4: __init__

 def __init__(self, parent=None, expected_geometry=(100, 50)):
     PlainTextEdit.__init__(self, parent)
     self.snippet_manager = SnippetManager(self)
     self.completion_popup = CompletionPopup(self)
     self.request_completion = self.completion_doc_name = None
     self.clear_completion_cache_timer = t = QTimer(self)
     t.setInterval(5000), t.timeout.connect(self.clear_completion_cache), t.setSingleShot(True)
     self.textChanged.connect(t.start)
     self.last_completion_request = -1
     self.gutter_width = 0
     self.tw = 2
     self.expected_geometry = expected_geometry
     self.saved_matches = {}
     self.syntax = None
     self.smarts = NullSmarts(self)
     self.current_cursor_line = None
     self.current_search_mark = None
     self.smarts_highlight_timer = t = QTimer()
     t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections)
     self.highlighter = SyntaxHighlighter()
     self.line_number_area = LineNumbers(self)
     self.apply_settings()
     self.setMouseTracking(True)
     self.cursorPositionChanged.connect(self.highlight_cursor_line)
     self.blockCountChanged[int].connect(self.update_line_number_area_width)
     self.updateRequest.connect(self.update_line_number_area)
开发者ID:timpalpant,项目名称:calibre,代码行数:26,代码来源:text.py

示例5: __init__

 def __init__(self, parent=None, expected_geometry=(100, 50)):
     PlainTextEdit.__init__(self, parent)
     self.gutter_width = 0
     self.expected_geometry = expected_geometry
     self.saved_matches = {}
     self.syntax = None
     self.smarts = NullSmarts(self)
     self.current_cursor_line = None
     self.current_search_mark = None
     self.smarts_highlight_timer = t = QTimer()
     t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections)
     self.highlighter = SyntaxHighlighter()
     self.line_number_area = LineNumbers(self)
     self.apply_settings()
     self.setMouseTracking(True)
     self.cursorPositionChanged.connect(self.highlight_cursor_line)
     self.blockCountChanged[int].connect(self.update_line_number_area_width)
     self.updateRequest.connect(self.update_line_number_area)
开发者ID:zhanleewo,项目名称:calibre,代码行数:18,代码来源:text.py

示例6: TextEdit

class TextEdit(PlainTextEdit):

    link_clicked = pyqtSignal(object)
    smart_highlighting_updated = pyqtSignal()

    def __init__(self, parent=None, expected_geometry=(100, 50)):
        PlainTextEdit.__init__(self, parent)
        self.snippet_manager = SnippetManager(self)
        self.completion_popup = CompletionPopup(self)
        self.request_completion = self.completion_doc_name = None
        self.clear_completion_cache_timer = t = QTimer(self)
        t.setInterval(5000), t.timeout.connect(self.clear_completion_cache), t.setSingleShot(True)
        self.textChanged.connect(t.start)
        self.last_completion_request = -1
        self.gutter_width = 0
        self.tw = 2
        self.expected_geometry = expected_geometry
        self.saved_matches = {}
        self.syntax = None
        self.smarts = NullSmarts(self)
        self.current_cursor_line = None
        self.current_search_mark = None
        self.smarts_highlight_timer = t = QTimer()
        t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections)
        self.highlighter = SyntaxHighlighter()
        self.line_number_area = LineNumbers(self)
        self.apply_settings()
        self.setMouseTracking(True)
        self.cursorPositionChanged.connect(self.highlight_cursor_line)
        self.blockCountChanged[int].connect(self.update_line_number_area_width)
        self.updateRequest.connect(self.update_line_number_area)

    @dynamic_property
    def is_modified(self):
        """ True if the document has been modified since it was loaded or since
        the last time is_modified was set to False. """

        def fget(self):
            return self.document().isModified()

        def fset(self, val):
            self.document().setModified(bool(val))

        return property(fget=fget, fset=fset)

    def sizeHint(self):
        return self.size_hint

    def apply_settings(self, prefs=None, dictionaries_changed=False):  # {{{
        prefs = prefs or tprefs
        self.setAcceptDrops(prefs.get("editor_accepts_drops", True))
        self.setLineWrapMode(QPlainTextEdit.WidgetWidth if prefs["editor_line_wrap"] else QPlainTextEdit.NoWrap)
        theme = get_theme(prefs["editor_theme"])
        self.apply_theme(theme)
        w = self.fontMetrics()
        self.space_width = w.width(" ")
        self.tw = (
            self.smarts.override_tab_stop_width
            if self.smarts.override_tab_stop_width is not None
            else prefs["editor_tab_stop_width"]
        )
        self.setTabStopWidth(self.tw * self.space_width)
        if dictionaries_changed:
            self.highlighter.rehighlight()

    def apply_theme(self, theme):
        self.theme = theme
        pal = self.palette()
        pal.setColor(pal.Base, theme_color(theme, "Normal", "bg"))
        pal.setColor(pal.AlternateBase, theme_color(theme, "CursorLine", "bg"))
        pal.setColor(pal.Text, theme_color(theme, "Normal", "fg"))
        pal.setColor(pal.Highlight, theme_color(theme, "Visual", "bg"))
        pal.setColor(pal.HighlightedText, theme_color(theme, "Visual", "fg"))
        self.setPalette(pal)
        self.tooltip_palette = pal = QPalette()
        pal.setColor(pal.ToolTipBase, theme_color(theme, "Tooltip", "bg"))
        pal.setColor(pal.ToolTipText, theme_color(theme, "Tooltip", "fg"))
        self.line_number_palette = pal = QPalette()
        pal.setColor(pal.Base, theme_color(theme, "LineNr", "bg"))
        pal.setColor(pal.Text, theme_color(theme, "LineNr", "fg"))
        pal.setColor(pal.BrightText, theme_color(theme, "LineNrC", "fg"))
        self.match_paren_format = theme_format(theme, "MatchParen")
        font = self.font()
        ff = tprefs["editor_font_family"]
        if ff is None:
            ff = default_font_family()
        font.setFamily(ff)
        font.setPointSize(tprefs["editor_font_size"])
        self.tooltip_font = QFont(font)
        self.tooltip_font.setPointSize(font.pointSize() - 1)
        self.setFont(font)
        self.highlighter.apply_theme(theme)
        w = self.fontMetrics()
        self.number_width = max(map(lambda x: w.width(str(x)), xrange(10)))
        self.size_hint = QSize(self.expected_geometry[0] * w.averageCharWidth(), self.expected_geometry[1] * w.height())
        self.highlight_color = theme_color(theme, "HighlightRegion", "bg")
        self.highlight_cursor_line()
        self.completion_popup.clear_caches(), self.completion_popup.update()

    # }}}
#.........这里部分代码省略.........
开发者ID:timpalpant,项目名称:calibre,代码行数:101,代码来源:text.py

示例7: __init__

 def __init__(self, *args, **kwargs):
     if not hasattr(Smarts, 'regexps_compiled'):
         Smarts.regexps_compiled = True
         Smarts.complete_attr_pat = re.compile(r'''url\s*\(\s*['"]{0,1}([^)]*)$''')
     NullSmarts.__init__(self, *args, **kwargs)
开发者ID:j-howell,项目名称:calibre,代码行数:5,代码来源:css.py

示例8: TextEdit

class TextEdit(PlainTextEdit):

    link_clicked = pyqtSignal(object)
    smart_highlighting_updated = pyqtSignal()

    def __init__(self, parent=None, expected_geometry=(100, 50)):
        PlainTextEdit.__init__(self, parent)
        self.gutter_width = 0
        self.tw = 2
        self.expected_geometry = expected_geometry
        self.saved_matches = {}
        self.syntax = None
        self.smarts = NullSmarts(self)
        self.current_cursor_line = None
        self.current_search_mark = None
        self.smarts_highlight_timer = t = QTimer()
        t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections)
        self.highlighter = SyntaxHighlighter()
        self.line_number_area = LineNumbers(self)
        self.apply_settings()
        self.setMouseTracking(True)
        self.cursorPositionChanged.connect(self.highlight_cursor_line)
        self.blockCountChanged[int].connect(self.update_line_number_area_width)
        self.updateRequest.connect(self.update_line_number_area)

    @dynamic_property
    def is_modified(self):
        ''' True if the document has been modified since it was loaded or since
        the last time is_modified was set to False. '''
        def fget(self):
            return self.document().isModified()
        def fset(self, val):
            self.document().setModified(bool(val))
        return property(fget=fget, fset=fset)

    def sizeHint(self):
        return self.size_hint

    def apply_settings(self, prefs=None, dictionaries_changed=False):  # {{{
        prefs = prefs or tprefs
        self.setLineWrapMode(QPlainTextEdit.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.NoWrap)
        theme = get_theme(prefs['editor_theme'])
        self.apply_theme(theme)
        w = self.fontMetrics()
        self.space_width = w.width(' ')
        self.tw = self.smarts.override_tab_stop_width if self.smarts.override_tab_stop_width is not None else prefs['editor_tab_stop_width']
        self.setTabStopWidth(self.tw * self.space_width)
        if dictionaries_changed:
            self.highlighter.rehighlight()

    def apply_theme(self, theme):
        self.theme = theme
        pal = self.palette()
        pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg'))
        pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg'))
        pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg'))
        pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg'))
        pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg'))
        self.setPalette(pal)
        self.tooltip_palette = pal = QPalette()
        pal.setColor(pal.ToolTipBase, theme_color(theme, 'Tooltip', 'bg'))
        pal.setColor(pal.ToolTipText, theme_color(theme, 'Tooltip', 'fg'))
        self.line_number_palette = pal = QPalette()
        pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg'))
        pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg'))
        pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg'))
        self.match_paren_format = theme_format(theme, 'MatchParen')
        font = self.font()
        ff = tprefs['editor_font_family']
        if ff is None:
            ff = default_font_family()
        font.setFamily(ff)
        font.setPointSize(tprefs['editor_font_size'])
        self.tooltip_font = QFont(font)
        self.tooltip_font.setPointSize(font.pointSize() - 1)
        self.setFont(font)
        self.highlighter.apply_theme(theme)
        w = self.fontMetrics()
        self.number_width = max(map(lambda x:w.width(str(x)), xrange(10)))
        self.size_hint = QSize(self.expected_geometry[0] * w.averageCharWidth(), self.expected_geometry[1] * w.height())
        self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg')
        self.highlight_cursor_line()
    # }}}

    def load_text(self, text, syntax='html', process_template=False, doc_name=None):
        self.syntax = syntax
        self.highlighter = get_highlighter(syntax)()
        self.highlighter.apply_theme(self.theme)
        self.highlighter.set_document(self.document(), doc_name=doc_name)
        sclass = get_smarts(syntax)
        if sclass is not None:
            self.smarts = sclass(self)
            if self.smarts.override_tab_stop_width is not None:
                self.tw = self.smarts.override_tab_stop_width
                self.setTabStopWidth(self.tw * self.space_width)
        self.setPlainText(unicodedata.normalize('NFC', unicode(text)))
        if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
            c = self.textCursor()
            c.insertText('')

#.........这里部分代码省略.........
开发者ID:GRiker,项目名称:calibre,代码行数:101,代码来源:text.py

示例9: __init__

 def __init__(self, *args, **kwargs):
     NullSmarts.__init__(self, *args, **kwargs)
     c = re.compile
     self.escape_scope_pat = c(r'\s+(continue|break|return|pass)(\s|$)')
     self.dedent_pat = c(r'\s+(else|elif|except)(\(|\s|$)')
开发者ID:andriniaina,项目名称:calibre,代码行数:5,代码来源:python.py

示例10: TextEdit

class TextEdit(PlainTextEdit):

    link_clicked = pyqtSignal(object)
    smart_highlighting_updated = pyqtSignal()

    def __init__(self, parent=None, expected_geometry=(100, 50)):
        PlainTextEdit.__init__(self, parent)
        self.snippet_manager = SnippetManager(self)
        self.completion_popup = CompletionPopup(self)
        self.request_completion = self.completion_doc_name = None
        self.clear_completion_cache_timer = t = QTimer(self)
        t.setInterval(5000), t.timeout.connect(self.clear_completion_cache), t.setSingleShot(True)
        self.textChanged.connect(t.start)
        self.last_completion_request = -1
        self.gutter_width = 0
        self.tw = 2
        self.expected_geometry = expected_geometry
        self.saved_matches = {}
        self.syntax = None
        self.smarts = NullSmarts(self)
        self.current_cursor_line = None
        self.current_search_mark = None
        self.smarts_highlight_timer = t = QTimer()
        t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections)
        self.highlighter = SyntaxHighlighter()
        self.line_number_area = LineNumbers(self)
        self.apply_settings()
        self.setMouseTracking(True)
        self.cursorPositionChanged.connect(self.highlight_cursor_line)
        self.blockCountChanged[int].connect(self.update_line_number_area_width)
        self.updateRequest.connect(self.update_line_number_area)

    def get_droppable_files(self, md):

        def is_mt_ok(mt):
            return self.syntax == 'html' and (
                mt in OEB_DOCS or mt in OEB_STYLES or mt.startswith('image/')
            )

        if md.hasFormat(CONTAINER_DND_MIMETYPE):
            for line in as_unicode(bytes(md.data(CONTAINER_DND_MIMETYPE))).splitlines():
                mt = current_container().mime_map.get(line, 'application/octet-stream')
                if is_mt_ok(mt):
                    yield line, mt, True
            return
        for qurl in md.urls():
            if qurl.isLocalFile() and os.access(qurl.toLocalFile(), os.R_OK):
                path = qurl.toLocalFile()
                mt = guess_type(path)
                if is_mt_ok(mt):
                    yield path, mt, False

    def canInsertFromMimeData(self, md):
        if md.hasText() or (md.hasHtml() and self.syntax == 'html') or md.hasImage():
            return True
        elif tuple(self.get_droppable_files(md)):
            return True
        return False

    def insertFromMimeData(self, md):
        files = tuple(self.get_droppable_files(md))
        base = self.highlighter.doc_name or None

        def get_name(name):
            folder = get_recommended_folders(current_container(), (name,))[name] or ''
            if folder:
                folder += '/'
            return folder + name

        def get_href(name):
            return current_container().name_to_href(name, base)

        def insert_text(text):
            c = self.textCursor()
            c.insertText(text)
            self.setTextCursor(c)
            self.ensureCursorVisible()

        def add_file(name, data, mt=None):
            from calibre.gui2.tweak_book.boss import get_boss
            name = current_container().add_file(name, data, media_type=mt, modify_name_if_needed=True)
            get_boss().refresh_file_list()
            return name

        if files:
            for path, mt, is_name in files:
                if is_name:
                    name = path
                else:
                    name = get_name(os.path.basename(path))
                    with lopen(path, 'rb') as f:
                        name = add_file(name, f.read(), mt)
                href = get_href(name)
                if mt.startswith('image/'):
                    self.insert_image(href)
                elif mt in OEB_STYLES:
                    insert_text('<link href="{}" rel="stylesheet" type="text/css"/>'.format(href))
                elif mt in OEB_DOCS:
                    self.insert_hyperlink(href, name)
            self.ensureCursorVisible()
#.........这里部分代码省略.........
开发者ID:j-howell,项目名称:calibre,代码行数:101,代码来源:text.py

示例11: __init__

 def __init__(self, *args, **kwargs):
     NullSmarts.__init__(self, *args, **kwargs)
     self.last_matched_tag = None
开发者ID:andriniaina,项目名称:calibre,代码行数:3,代码来源:html.py


注:本文中的calibre.gui2.tweak_book.editor.smarts.NullSmarts类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。