Source

codeaide / codeaide / editors.py

# -*- coding: utf-8 -*-
"""
Here you will find redefined editor widgets
which install some sensitive modes
"""

import sys
from codeaide.base import *
from codeaide.main import *
import codeaide.modes



class BaseEditor(CodeAide):

    modes = (
        "AutoTyping",
        "WrapIndicator",
        "HighlightLine",
        "LineNumbers",  # installs Sidebar as a dependency
        "LineIcons",
        "LineStatus",
        "Occurrences",
        #"EmacsCore",
        "ParentheseMatcher",
        "Whitespace",
        "EditExtras",
        "Snippets",
        )
    require_modules = ()


    def __init__(self, parent=None):
        if not codeaide.modes.loaded:
            codeaide.modes.load_all(verbose=False)
        CodeAide.__init__(self, parent)
        for mod_name in self.require_modules:
            mod = __import__(mod_name, {}, {}, [])
        self.install(*self.modes)
        self.init_editor()


    def init_editor(self):
        pass


    @classmethod
    def create_window(cls, *args, **kwargs):
        edit = cls(*args, **kwargs)
        edit.resize(800,600)
        edit.show()
        return edit


    @classmethod
    def test(cls, *args, **kwargs):
        app = QApplication.instance() or QApplication(sys.argv)
        edit = cls.create_window(*args, **kwargs)
        return app.exec_()



class CodeEditor(BaseEditor):
    modes = BaseEditor.modes + ("AutoloadLanguage",)

    @classmethod
    def create_window(cls, *args, **kwargs):
        edit = super(CodeEditor, cls).create_window(*args, **kwargs)
        if len(sys.argv) == 2:
            filename = sys.argv[1]
        else: filename = __file__.rstrip("co")
        edit.load_buffer(filename)
        return edit



class PythonEditor(CodeEditor):
    modes = CodeEditor.modes + ("Python",)



class BaseConsole(BaseEditor):
    modes =  (
        "AutoTyping",
        #"WrapIndicator",
        #"LineNumbers",  # installs Sidebar as a dependency
        "ParentheseMatcher",
        "Whitespace",
        "Session"
        )


    @classmethod
    def create_window(cls, *args, **kwargs):
        edit = super(BaseConsole, cls).create_window(*args, **kwargs)
        return edit


class PythonConsole(BaseConsole):
    modes = BaseConsole.modes + ("PythonConsole",)



class QtScriptConsole(BaseConsole):
    modes = BaseConsole.modes + ("QtScriptConsole",)


    
class ShellConsole(BaseConsole):
    modes = BaseConsole.modes + ("Shell",)