codeaide / codeaide / modes / language /

Full commit
# -*- coding: utf-8 -*-
from PyQt4.QtCore import SIGNAL
from codeaide.base import ModeBase
from codeaide.utils import IdleBackgroundCall

class OutlineBase(ModeBase):

    def init(self):
        self.textedit.structure = [] = None

    def init_outline(self):

    def contents_change_hook(self, block_number, block, text, user_data):
        # XXX: better call on QPlainTextEdit.blockCountChanged(int) or
        #      QAbstractTextDocumentLayout.updateBlock(QTextBlock) ?
        if not
   = IdleCall(self.textedit, self.update_structure)
   = IdleBackgroundCall(
                self.textedit, self.update_structure, self.on_new_structure)

    def update_structure(self):
        This method is called as a background thread and should return the nodes
        raise NotImplementedError, "%s: %s" % (
            self.update_structure, self.update_structure.__doc__)

    def on_new_structure(self, nodes): = None

    def show_structure(self, nodes):
        This called after update_structure.
        Implement your treeview-/list-update here.
        self.textedit.structure = nodes
        self.textedit.emit(SIGNAL("structure_changed"), nodes)