codeaide / codeaide /

import re

from PyQt4.QtCore import (
    Qt, QString, SIGNAL, QVariant, QThread, QLine, QSize, QRect, QTimer,
    QAbstractListModel, QModelIndex)
from PyQt4.QtGui import (
    QApplication, QWidget, QHBoxLayout, QToolTip,
    QTextBlockUserData, QPlainTextEdit, QCompleter, QTextCursor, 
    QColor, QBrush, QPainter, QPen, QPalette, QTextEdit, QTextFormat)


class ModeBase(object):

    keyboard_hooks = {
    paint_hook_before = None
    paint_hook = None
    paint_hook_after = None
    resize_hook = None
    state = 0

    requires = []

    def find(cls, mode):
        for subcls in cls.__subclasses__():
            if isinstance(mode, basestring):
                if subcls.__name__ == mode:
                    return subcls
                if subcls is mode:
                    return subcls
            found = subcls.find(mode)
            if found:
                return found

    def __init__(self, textedit, *args, **kwargs):
        for required_mode in self.requires:
        self.textedit = textedit
        self.init(*args, **kwargs)
        self.keyboard_hooks = self.setup_keyboard_hooks()

    def init(self):

    def setup_keyboard_hooks(self):
        return {}

    def install_hooks(self):

    def install_keyboard_hooks(self):
        import functools
        for key, callback in self.keyboard_hooks.items():
            if isinstance(key, tuple):
                key, modifiers = key
                modifiers = -1
            h = self.textedit.keyboard_hooks.setdefault(self.state, {})
            bound_method = functools.partial(callback, self)
            h.setdefault((key, int(modifiers)), []).append(bound_method)

    def install_paint_hook(self):
        callback = self.paint_hook_before or self.paint_hook 
        if callback:
            h = self.textedit.paint_hooks_before
            h.setdefault(self.state, []).append(callback)
        callback = self.paint_hook_after
        if callback:
            h = self.textedit.paint_hooks_after
            h.setdefault(self.state, []).append(callback)

    def install_resize_hook(self):
        callback = self.resize_hook
        if callback:
            h = self.textedit.resize_hooks
            h.setdefault(self.state, []).append(callback)

class TextCursor(QTextCursor):

    def __enter__(self, *args):

    def __exit__(self, *args):

    def current_word(self):
        return unicode(self.selectedText())

    def current_line(self):
        return unicode(self.block().text())

    def endswith_word(self):
        word = self.current_word()
        pos = self.position()
        line = self.current_line()
        if line[:pos].endswith(word):
            return word

    def select_range(self, start_pos, end_pos):
        self.setPosition(end_pos, QTextCursor.KeepAnchor)

    def remove_range(self, start_pos, end_pos):
        self.select_range(start_pos, end_pos)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.