示例#1
0
文件: shell.py 项目: halbbob/dff
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
        console.__init__(self, sigstp=False)
        self.setupUi(self)
        self.name = self.windowTitle()
	self.completion = completion.Completion(self)
        self.hookTermSize()
	taskmanager = TaskManager()
        self.vfs = vfs.vfs()
        self.log = log or ''
        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.pointer = 0
        self.cursor_pos   = 0

        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")

        self.preloop()
	self.redirect = RedirectIO()
	self.sig = "Sputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.shell", "ui.console.console", "ui.console.completion", "ui.console.line_to_arguments", "api.taskmanager.taskmanager", "api.taskmanager.scheduler", "api.taskmanager.processus"], True)
        self.writePrompt()
示例#2
0
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
        console.__init__(self)
	self.completion = completion.Completion(self)
	taskmanager = TaskManager()
        self.vfs = vfs.vfs()
        self.log = log or ''
        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.pointer = 0
        self.cursor_pos   = 0
	font = QFont("Courier")
	font.setFixedPitch(1)
	fm = QFontMetrics(font)	
       	self.fontwidth = fm.averageCharWidth()
	self.setFont(font)
        self.bgcolor = QColor("black")
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        pal = QPalette()
        pal.setColor(pal.Base, self.bgcolor)
        pal.setColor(pal.Text, self.fgcolor)
        self.setPalette(pal)
        self.preloop()
        self.cwd = self.vfs.getcwd()
        self.ps1 = self.cwd.path + "/" + self.cwd.name + " > "
	self.redirect = RedirectIO()
	self.sig = "Sputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.shell", "ui.console.console", "ui.console.completion", "ui.console.line_to_arguments", "api.taskmanager.taskmanager", "api.taskmanager.scheduler", "api.taskmanager.processus"], True)
        self.write('Welcome to dff shell\n')
        self.write(self.ps1)
示例#3
0
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
	InteractiveInterpreter.__init__(self, None)
        self.log = log or ''

        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
       
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.history = []
        self.pointer = 0
        self.cursor_pos   = 0
        self.bgcolor = QColor("black")
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        self.strcolor = QColor("red")
        pal = QPalette()
        pal.setColor(pal.Base, self.bgcolor)
        pal.setColor(pal.Text, self.fgcolor)
        self.setPalette(pal)

	self.redirect = RedirectIO()
	self.sig = "Iputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.interpreter", "code", "__console__", "pydoc"])

        self.ps1 = ">>> "
        self.ps2 = "... "
        self.write('Python Interpreter\n')
        self.write(self.ps1)
        self.more = self.runsource("from api.vfs import *; v = vfs.vfs()")
示例#4
0
 def __init__(self, mainWindow):
     super(IO, self).__init__()
     self.__mainWindow = mainWindow
     self.addAction()
     self.configure()
     self.io = self.initIO()
     self.sigout = "IOOUTputtext"
     self.connect(self, SIGNAL(self.sigout), self.puttextout)
     self.sigerr = "IOERRputtext"
     self.connect(self, SIGNAL(self.sigerr), self.puttexterr)
     self.redirect = RedirectIO(self)
     self.cioout = CIO(self, sys.__stdout__.fileno(), self.sigout)
     self.cioout.start()
     self.cioerr = CIO(self, sys.__stderr__.fileno(), self.sigerr)
     self.cioerr.start()
示例#5
0
    def __init__(self, parent=None, log=""):
        QTextEdit.__init__(self, parent)
        InteractiveInterpreter.__init__(self, None)
        self.setupUi(self)
        self.name = self.windowTitle()
        self.log = log or ""
        self.__canwrite = True

        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None

        self.line = QString()
        self.lines = []
        self.point = 0
        self.more = 0
        self.reading = 0
        self.history = []
        self.pointer = 0
        self.cursor_pos = 0
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        self.strcolor = QColor("red")

        self.redirect = RedirectIO()
        self.sig = "Iputtext"
        self.connect(self, SIGNAL(self.sig), self.puttext)
        self.redirect.addparent(self, ["ui.gui.widget.interpreter", "code", "__console__", "pydoc"])

        self.ps1 = ">>> "
        self.ps2 = "... "
        self.writePrompt()
        api_imports = [
            "from api.types.libtypes import Variant, VList, VMap, vtime, typeId, Argument, Parameter, ConfigManager, Constant, Config, Path",
            "from api.vfs.vfs import vfs",
            "from api.vfs.libvfs import VFS, FileMapping, ABSOLUTE_ATTR_NAME, RELATIVE_ATTR_NAME",
            "from api.filters.libfilters import Filter",
            "from api.search.libsearch import Search",
            "from api.events.libevents import EventHandler, event",
            "from api.datatype.libdatatype import DataTypeManager, DataTypeHandler",
            "from api.loader.loader import loader",
            "from api.module.module import Module, Script",
            "from api.magic.libmagichandler import MagicType, MimeType",
            "from api.taskmanager.taskmanager import TaskManager",
        ]
        for api_import in api_imports:
            self.more = self.runsource(api_import)
示例#6
0
class InterpreterView(QTextEdit, InteractiveInterpreter):
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
	InteractiveInterpreter.__init__(self, None)
        self.log = log or ''

        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
       
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.history = []
        self.pointer = 0
        self.cursor_pos   = 0
        self.bgcolor = QColor("black")
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        self.strcolor = QColor("red")
        pal = QPalette()
        pal.setColor(pal.Base, self.bgcolor)
        pal.setColor(pal.Text, self.fgcolor)
        self.setPalette(pal)

	self.redirect = RedirectIO()
	self.sig = "Iputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.interpreter", "code", "__console__", "pydoc"])

        self.ps1 = ">>> "
        self.ps2 = "... "
        self.write('Python Interpreter\n')
        self.write(self.ps1)
        self.more = self.runsource("from api.vfs import *; v = vfs.vfs()")

    def write(self, str):
	self.redirect.write(str)

    def puttext(self, text):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        pos1 = cursor.position()
        cursor.insertText(text)
        self.cursor_pos = cursor.position()
        self.setTextCursor(cursor)
        self.ensureCursorVisible()
        cursor.setPosition(pos1, QTextCursor.KeepAnchor)
        format = cursor.charFormat()
        format.setForeground(QBrush(self.fgcolor))
        cursor.setCharFormat(format)


    def get_interpreter(self):
        """ Return the interpreter object """
	return self

    def moveCursor(self, operation, mode=QTextCursor.MoveAnchor):
        """
        Convenience function to move the cursor
        This function will be present in PyQT4.2
        """
        cursor = self.textCursor()
        cursor.movePosition(operation, mode)
        self.setTextCursor(cursor)

    def flush(self):
        pass

    def isatty(self):
        return 1

    def clear(self):
        """ Clear """

    def readline(self):
        self.reading = 1
        self.__clearLine()
        self.moveCursor(QTextCursor.End)
        while self.reading:
            QtGui.qApp.processEvents()
        if self.line.length() == 0:
            return '\n'
        else:
            return str(self.line) 
    

    def writelines(self, text):
        """
        Simulate stdin, stdout, and stderr.
        """
        map(self.write, text)


    def fakeUser(self, lines):
        """
        Simulate a user: lines is a sequence of strings, (Python statements).
        """
        for line in lines:
            self.line = QString(line.rstrip())
            self.write(self.line)
            self.write('\n')
            self.run()

    def run(self):
        self.pointer = 0
        self.history.append(QString(self.line))
        try:
            self.lines.append(str(self.line))
        except Exception,e:
            print e
	source = '\n'.join(self.lines)
        self.more = self.runsource(source)

        if self.more:
            self.write(self.ps2)
        else:
            self.write(self.ps1)
            self.lines = []
        self.__clearLine()
示例#7
0
文件: shell.py 项目: halbbob/dff
class ShellView(QTextEdit, console, Ui_Shell):
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
        console.__init__(self, sigstp=False)
        self.setupUi(self)
        self.name = self.windowTitle()
	self.completion = completion.Completion(self)
        self.hookTermSize()
	taskmanager = TaskManager()
        self.vfs = vfs.vfs()
        self.log = log or ''
        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.pointer = 0
        self.cursor_pos   = 0

        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")

        self.preloop()
	self.redirect = RedirectIO()
	self.sig = "Sputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.shell", "ui.console.console", "ui.console.completion", "ui.console.line_to_arguments", "api.taskmanager.taskmanager", "api.taskmanager.scheduler", "api.taskmanager.processus"], True)
        self.writePrompt()


    def hookTermSize(self):
        ca = getattr(sys.modules['ui.console.utils'], "ConsoleAttributes")
        nt = getattr(ca, "_ConsoleAttributes__nt")
        posix = getattr(ca, "_ConsoleAttributes__posix")
        setattr(nt, "terminalSize", self.get_term_size)
        setattr(posix, "terminalSize", self.get_term_size)


    def writePrompt(self):
        self.cwd = self.vfs.getcwd()
        self.ps1 = self.cwd.absolute() + " > "
        self.write('\n')
        self.write(self.ps1)

    def write(self, str):
	self.redirect.write(str)

    def puttext(self, text):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        pos1 = cursor.position()
        cursor.insertText(text)
        self.cursor_pos = cursor.position()
        self.setTextCursor(cursor)
        self.ensureCursorVisible()
        cursor.setPosition(pos1, QTextCursor.KeepAnchor)
        format = cursor.charFormat()
        format.setForeground(QBrush(self.fgcolor))
        cursor.setCharFormat(format)


    def get_interpreter(self):
        return self.interpreter

    def moveCursor(self, operation, mode=QTextCursor.MoveAnchor):
        cursor = self.textCursor()
        cursor.movePosition(operation, mode)
        self.setTextCursor(cursor)

    def flush(self):
        pass

    def isatty(self):
        return 1

    def clear(self):
	pass

    def readline(self):
        self.reading = 1
        self.__clearLine()
        self.moveCursor(QTextCursor.End)
        while self.reading:
            QtGui.qApp.processEvents()
        if self.line.length() == 0:
            return '\n'
        else:
            return str(self.line) 
    
    def writelines(self, text):
        map(self.write, text)

    def fakeUser(self, lines):
        for line in lines:
            self.line = QString(line.rstrip())
            self.write(self.line)
            self.write('\n')
            self.run()

    def run(self):
        self.pointer = 0
        try:
            self.lines.append(str(self.line))
        except Exception,e:
            print e
        line = '\n'.join(self.lines)
	line = self.precmd(line)
	stop = self.onecmd(line, True)
        stop = self.postcmd(stop, line)
	self.cwd = self.vfs.getcwd()
	self.ps1 = self.cwd.absolute() + " > "
        if self.more:
            self.write(self.ps2)
        else:
            self.write(self.ps1)
            self.lines = []
        self.__clearLine()
示例#8
0
class InterpreterView(QTextEdit, InteractiveInterpreter, Ui_Interpreter):
    def __init__(self, parent=None, log=""):
        QTextEdit.__init__(self, parent)
        InteractiveInterpreter.__init__(self, None)
        self.setupUi(self)
        self.name = self.windowTitle()
        self.log = log or ""
        self.__canwrite = True

        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None

        self.line = QString()
        self.lines = []
        self.point = 0
        self.more = 0
        self.reading = 0
        self.history = []
        self.pointer = 0
        self.cursor_pos = 0
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        self.strcolor = QColor("red")

        self.redirect = RedirectIO()
        self.sig = "Iputtext"
        self.connect(self, SIGNAL(self.sig), self.puttext)
        self.redirect.addparent(self, ["ui.gui.widget.interpreter", "code", "__console__", "pydoc"])

        self.ps1 = ">>> "
        self.ps2 = "... "
        self.writePrompt()
        api_imports = [
            "from api.types.libtypes import Variant, VList, VMap, vtime, typeId, Argument, Parameter, ConfigManager, Constant, Config, Path",
            "from api.vfs.vfs import vfs",
            "from api.vfs.libvfs import VFS, FileMapping, ABSOLUTE_ATTR_NAME, RELATIVE_ATTR_NAME",
            "from api.filters.libfilters import Filter",
            "from api.search.libsearch import Search",
            "from api.events.libevents import EventHandler, event",
            "from api.datatype.libdatatype import DataTypeManager, DataTypeHandler",
            "from api.loader.loader import loader",
            "from api.module.module import Module, Script",
            "from api.magic.libmagichandler import MagicType, MimeType",
            "from api.taskmanager.taskmanager import TaskManager",
        ]
        for api_import in api_imports:
            self.more = self.runsource(api_import)

    def writePrompt(self):
        self.write("\n")
        self.write(self.ps1)

    def write(self, str):
        self.redirect.write(str)

    def puttext(self, text):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        pos1 = cursor.position()
        cursor.insertText(text)
        self.cursor_pos = cursor.position()
        self.setTextCursor(cursor)
        self.ensureCursorVisible()
        cursor.setPosition(pos1, QTextCursor.KeepAnchor)
        format = cursor.charFormat()
        format.setForeground(QBrush(self.fgcolor))
        cursor.setCharFormat(format)

    def get_interpreter(self):
        """ Return the interpreter object """
        return self

    def moveCursor(self, operation, mode=QTextCursor.MoveAnchor):
        """
        Convenience function to move the cursor
        This function will be present in PyQT4.2
        """
        cursor = self.textCursor()
        cursor.movePosition(operation, mode)
        self.setTextCursor(cursor)

    def flush(self):
        pass

    def isatty(self):
        return 1

    def clear(self):
        """ Clear """

    def readline(self):
        self.reading = 1
        self.__clearLine()
        self.moveCursor(QTextCursor.End)
        while self.reading:
            QtGui.qApp.processEvents()
        if self.line.length() == 0:
            return "\n"
        else:
            return str(self.line)

    def writelines(self, text):
        """
        Simulate stdin, stdout, and stderr.
        """
        map(self.write, text)

    def fakeUser(self, lines):
        """
        Simulate a user: lines is a sequence of strings, (Python statements).
        """
        for line in lines:
            self.line = QString(line.rstrip())
            self.write(self.line)
            self.write("\n")
            self.run()

    def runsource_callback(self, source):
        self.__canwrite = False
        self.more = self.runsource(source)
        if self.more:
            self.write(self.ps2)
        else:
            self.write(self.ps1)
            self.lines = []
        self.__clearLine()
        self.__canwrite = True

    def run(self):
        self.pointer = 0
        self.history.append(QString(self.line))
        try:
            self.lines.append(str(self.line))
        except Exception, e:
            print e
        source = "\n".join(self.lines)
        thread = threading.Thread(target=self.runsource_callback, args=(source,))
        thread.start()
示例#9
0
class ShellView(QTextEdit, console):
    def __init__(self, parent=None, log=''):
        QTextEdit.__init__(self, parent)
        console.__init__(self)
	self.completion = completion.Completion(self)
	taskmanager = TaskManager()
        self.vfs = vfs.vfs()
        self.log = log or ''
        if parent is None:
            self.eofKey = Qt.Key_D
        else:
            self.eofKey = None
        self.line    = QString()
        self.lines   = []
        self.point   = 0
        self.more    = 0
        self.reading = 0
        self.pointer = 0
        self.cursor_pos   = 0
	font = QFont("Courier")
	font.setFixedPitch(1)
	fm = QFontMetrics(font)	
       	self.fontwidth = fm.averageCharWidth()
	self.setFont(font)
        self.bgcolor = QColor("black")
        self.fgcolor = QColor("white")
        self.selcolor = QColor("green")
        pal = QPalette()
        pal.setColor(pal.Base, self.bgcolor)
        pal.setColor(pal.Text, self.fgcolor)
        self.setPalette(pal)
        self.preloop()
        self.cwd = self.vfs.getcwd()
        self.ps1 = self.cwd.path + "/" + self.cwd.name + " > "
	self.redirect = RedirectIO()
	self.sig = "Sputtext"
	self.connect(self, SIGNAL(self.sig), self.puttext)
	self.redirect.addparent(self, ["ui.gui.widget.shell", "ui.console.console", "ui.console.completion", "ui.console.line_to_arguments", "api.taskmanager.taskmanager", "api.taskmanager.scheduler", "api.taskmanager.processus"], True)
        self.write('Welcome to dff shell\n')
        self.write(self.ps1)

    def write(self, str):
	self.redirect.write(str)
	#self.redirect.write(str, inspect.currentframe().f_back.f_globals['__name__'])
#	self.redirect.write(str,  [sys._getframe(0).f_globals['__name__'], sys._getframe(1).f_globals['__name__'], sys._getframe(2).f_globals['__name__'] ])

    def puttext(self, text):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        pos1 = cursor.position()
        cursor.insertText(text)
        self.cursor_pos = cursor.position()
        self.setTextCursor(cursor)
        self.ensureCursorVisible()
        cursor.setPosition(pos1, QTextCursor.KeepAnchor)
        format = cursor.charFormat()
        format.setForeground(QBrush(self.fgcolor))
        cursor.setCharFormat(format)


    def get_interpreter(self):
        return self.interpreter

    def moveCursor(self, operation, mode=QTextCursor.MoveAnchor):
        cursor = self.textCursor()
        cursor.movePosition(operation, mode)
        self.setTextCursor(cursor)

    def flush(self):
        pass

    def isatty(self):
        return 1

    def clear(self):
	pass

    def readline(self):
        self.reading = 1
        self.__clearLine()
        self.moveCursor(QTextCursor.End)
        while self.reading:
            QtGui.qApp.processEvents()
        if self.line.length() == 0:
            return '\n'
        else:
            return str(self.line) 
    
    def writelines(self, text):
        map(self.write, text)

    def fakeUser(self, lines):
        for line in lines:
            self.line = QString(line.rstrip())
            self.write(self.line)
            self.write('\n')
            self.run()

    def run(self):
        self.pointer = 0
        try:
            self.lines.append(str(self.line))
        except Exception,e:
            print e
        line = '\n'.join(self.lines)
	line = self.precmd(line)
	stop = self.onecmd(line)
        stop = self.postcmd(stop, line)
	self.cwd = self.vfs.getcwd()
	self.ps1 = self.cwd.path + "/" + self.cwd.name + " > "
        if self.more:
            self.write(self.ps2)
        else:
            self.write(self.ps1)
            self.lines = []
        self.__clearLine()