Example #1
0
 def __init__(self, *args, **kwargs):
     super(StdoutWidget, self).__init__(*args, **kwargs)
     self.setReadOnly(True)
     metrics = QtGui.QFontMetrics(self.currentFont())
     self.setTabStopWidth(4 * metrics.width(' '))
     self.decoder = AnsiDecoder()
     #self.document().setDefaultStyleSheet(DefaultStyle)
     self.current_style = TextStyle()
Example #2
0
 def __init__(self, theme, *args, **kwargs):
     super(TerminalWidget, self).__init__(*args, **kwargs)
     self.ui = Ui_TerminalWidget()
     self.ui.setupUi(self)
     self.decoder = AnsiDecoder()
     self.theme = theme
     self.ui.stdout.document().setDefaultStyleSheet(self.theme.term)
     self.ui.prompt.setText("<html></html>")
     self.ui.prompt.findChild(QtGui.QTextDocument).setDefaultStyleSheet(self.theme.term)
Example #3
0
 def __init__(self, *args, **kwargs):
     super(StdoutWidget, self).__init__(*args, **kwargs)
     self.setReadOnly(True)
     metrics = QtGui.QFontMetrics(self.currentFont())
     self.setTabStopWidth(4 * metrics.width(' '))
     self.decoder = AnsiDecoder()
     #self.document().setDefaultStyleSheet(DefaultStyle)
     self.current_style = TextStyle()
Example #4
0
class StdoutWidget(QtGui.QTextEdit):
    forwardKey = QtCore.Signal(QtGui.QKeyEvent)

    def __init__(self, *args, **kwargs):
        super(StdoutWidget, self).__init__(*args, **kwargs)
        self.setReadOnly(True)
        metrics = QtGui.QFontMetrics(self.currentFont())
        self.setTabStopWidth(4 * metrics.width(' '))
        self.decoder = AnsiDecoder()
        #self.document().setDefaultStyleSheet(DefaultStyle)
        self.current_style = TextStyle()

    @QtCore.Slot()
    def appendAnsi(self, txt):
        #self.insertPlainText(txt)
        self.moveCursor(QtGui.QTextCursor.End)
        for (html, style) in self.decoder.html(txt, self.current_style,
                                               'stdout-text'):
            self.insertHtml(html)
            self.current_style = style
            #self.current_style = p.style
        self.ensureCursorVisible()

    @QtCore.Slot()
    def appendHtml(self, html):
        self.moveCursor(QtGui.QTextCursor.End)
        self.insertHtml(html)
        self.ensureCursorVisible()

    #TODO keypress -> set focus on stdin
    def keyPressEvent(self, event):
        print("stdout::keyPressEvent()")
        shift = QtCore.Qt.ShiftModifier
        if event.text() and event.modifiers() in (0, shift):
            self.forwardKey.emit(event)
        else:
            super(StdoutWidget, self).keyPressEvent(event)
Example #5
0
class StdoutWidget(QtGui.QTextEdit):
    forwardKey = QtCore.Signal(QtGui.QKeyEvent)

    def __init__(self, *args, **kwargs):
        super(StdoutWidget, self).__init__(*args, **kwargs)
        self.setReadOnly(True)
        metrics = QtGui.QFontMetrics(self.currentFont())
        self.setTabStopWidth(4 * metrics.width(' '))
        self.decoder = AnsiDecoder()
        #self.document().setDefaultStyleSheet(DefaultStyle)
        self.current_style = TextStyle()

    @QtCore.Slot()
    def appendAnsi(self, txt):
        #self.insertPlainText(txt)
        self.moveCursor(QtGui.QTextCursor.End)
        for (html, style) in self.decoder.html(txt, self.current_style, 'stdout-text'):
            self.insertHtml(html)
            self.current_style = style
            #self.current_style = p.style
        self.ensureCursorVisible()

    @QtCore.Slot()
    def appendHtml(self, html):
        self.moveCursor(QtGui.QTextCursor.End)
        self.insertHtml(html)
        self.ensureCursorVisible()

    #TODO keypress -> set focus on stdin
    def keyPressEvent(self, event):
        print("stdout::keyPressEvent()")
        shift = QtCore.Qt.ShiftModifier
        if event.text() and event.modifiers() in (0, shift):
            self.forwardKey.emit(event)
        else:
            super(StdoutWidget, self).keyPressEvent(event)
Example #6
0
class TerminalWidget(QtGui.QWidget):
    post = QtCore.Signal((str, str))
    complete = QtCore.Signal(str)

    def __init__(self, theme, *args, **kwargs):
        super(TerminalWidget, self).__init__(*args, **kwargs)
        self.ui = Ui_TerminalWidget()
        self.ui.setupUi(self)
        self.decoder = AnsiDecoder()
        self.theme = theme
        self.ui.stdout.document().setDefaultStyleSheet(self.theme.term)
        self.ui.prompt.setText("<html></html>")
        self.ui.prompt.findChild(QtGui.QTextDocument).setDefaultStyleSheet(
            self.theme.term)

    @QtCore.Slot()
    def on_stdin_returnPressed(self):
        self.fire_post()

    @QtCore.Slot()
    def on_stdin_sigint(self):
        self.fire_post('int')

    @QtCore.Slot()
    def on_stdin_sigeof(self):
        self.fire_post('eof')

    @QtCore.Slot()
    def on_stdin_complete(self):
        txt = self.stdin.text()
        index = self.stdin.cursorPosition()
        self.complete.emit(txt[:index])

    @QtCore.Slot()
    def set_completions(self, completions):
        pass

    @QtCore.Slot()
    def append(self, txt):
        self.ui.stdout.appendAnsi(txt)

    @QtCore.Slot()
    def set_prompt(self, prompt):
        html = "<span class='prompt'>"
        for (e, style) in self.decoder.html(prompt, TextStyle(), ""):
            html += e
        html += "</span>"
        self.ui.prompt.setText(html)
        #self.ui.prompt.setStyleSheet(".fg-intense-32 { color: rgb(0,255,0); }")
        #self.ui.prompt.setText(self.decoder.html(prompt, TextStyle(), "prompt"))
        #self.ui.prompt.setText()

    @QtCore.Slot(QtGui.QKeyEvent)
    def on_stdout_forwardKey(self, event):
        self.ui.stdin.setFocus()
        self.ui.stdin.keyPressEvent(event)

    @QtCore.Slot(int)
    def on_stdin_scrollLine(self, direction):
        vbar = self.ui.stdout.verticalScrollBar()
        if vbar:
            vbar.triggerAction(QtGui.QAbstractSlider.
                               SliderSingleStepAdd if direction < 0 else QtGui.
                               QAbstractSlider.SliderSingleStepSub)

    @QtCore.Slot(int)
    def on_stdin_scrollPage(self, direction):
        vbar = self.ui.stdout.verticalScrollBar()
        if vbar:
            vbar.triggerAction(
                QtGui.QAbstractSlider.SliderPageStepAdd
                if direction < 0 else QtGui.QAbstractSlider.SliderPageStepSub)

    def fire_post(self, sig=None):
        txt = self.ui.stdin.text()
        if sig == 'int':
            txt += '^C'
        elif sig == 'eof':
            txt += '^D'
        self.ui.stdin.submit(sig)
        self.ui.stdout.appendHtml(self.ui.prompt.text())
        self.ui.stdout.appendAnsi(txt + "\n")
        self.post.emit(txt, sig)
Example #7
0
class TerminalWidget(QtGui.QWidget):
    post = QtCore.Signal((str, str))
    complete = QtCore.Signal(str)

    def __init__(self, theme, *args, **kwargs):
        super(TerminalWidget, self).__init__(*args, **kwargs)
        self.ui = Ui_TerminalWidget()
        self.ui.setupUi(self)
        self.decoder = AnsiDecoder()
        self.theme = theme
        self.ui.stdout.document().setDefaultStyleSheet(self.theme.term)
        self.ui.prompt.setText("<html></html>")
        self.ui.prompt.findChild(QtGui.QTextDocument).setDefaultStyleSheet(self.theme.term)

    @QtCore.Slot()
    def on_stdin_returnPressed(self):
        self.fire_post()

    @QtCore.Slot()
    def on_stdin_sigint(self):
        self.fire_post('int')

    @QtCore.Slot()
    def on_stdin_sigeof(self):
        self.fire_post('eof')

    @QtCore.Slot()
    def on_stdin_complete(self):
        txt = self.stdin.text()
        index = self.stdin.cursorPosition()
        self.complete.emit(txt[:index])

    @QtCore.Slot()
    def set_completions(self, completions):
        pass

    @QtCore.Slot()
    def append(self, txt):
        self.ui.stdout.appendAnsi(txt)

    @QtCore.Slot()
    def set_prompt(self, prompt):
        html = "<span class='prompt'>"
        for (e, style) in self.decoder.html(prompt, TextStyle(), ""):
            html += e
        html += "</span>"
        self.ui.prompt.setText(html)
        #self.ui.prompt.setStyleSheet(".fg-intense-32 { color: rgb(0,255,0); }")
        #self.ui.prompt.setText(self.decoder.html(prompt, TextStyle(), "prompt"))
        #self.ui.prompt.setText()

    @QtCore.Slot(QtGui.QKeyEvent)
    def on_stdout_forwardKey(self, event):
        self.ui.stdin.setFocus()
        self.ui.stdin.keyPressEvent(event)

    @QtCore.Slot(int)
    def on_stdin_scrollLine(self, direction):
        vbar = self.ui.stdout.verticalScrollBar()
        if vbar:
            vbar.triggerAction(
                QtGui.QAbstractSlider.SliderSingleStepAdd if direction < 0 else
                QtGui.QAbstractSlider.SliderSingleStepSub
            )

    @QtCore.Slot(int)
    def on_stdin_scrollPage(self, direction):
        vbar = self.ui.stdout.verticalScrollBar()
        if vbar:
            vbar.triggerAction(
                QtGui.QAbstractSlider.SliderPageStepAdd if direction < 0 else
                QtGui.QAbstractSlider.SliderPageStepSub
            )

    def fire_post(self, sig=None):
        txt = self.ui.stdin.text()
        if sig == 'int':
            txt += '^C'
        elif sig == 'eof':
            txt += '^D'
        self.ui.stdin.submit(sig)
        self.ui.stdout.appendHtml(self.ui.prompt.text())
        self.ui.stdout.appendAnsi(txt+"\n")
        self.post.emit(txt, sig)