コード例 #1
0
def init(app):
    import logging

    from qtpy import QtCore, QtWidgets

    from exectools.qt import QtOutputPane, QtLoggingHandler

    panel = QtWidgets.QDockWidget('Output Log', app, objectName='outputPanel')
    # @TODO: try to add actions to a QTextEdit widget instead of using a
    #        custom widget
    logpane = QtOutputPane()
    panel.setWidget(logpane)

    app.addDockWidget(QtCore.Qt.BottomDockWidgetArea, panel)

    # setupLogger
    formatter = logging.Formatter('%(levelname)s: %(message)s')
    handler = QtLoggingHandler(logpane)
    handler.setFormatter(formatter)
    app.logger.addHandler(handler)

    # Connect signals
    logpane.paneHideRequest.connect(panel.hide)
コード例 #2
0
ファイル: logpane.py プロジェクト: avalentino/gsdview
def init(app):
    import logging

    from qtsix import QtCore, QtWidgets

    from exectools.qt import QtOutputPane, QtLoggingHandler

    panel = QtWidgets.QDockWidget('Output Log', app, objectName='outputPanel')
    # @TODO: try to add actions to a QTextEdit widget instead of using a
    #        custom widget
    logpane = QtOutputPane()
    panel.setWidget(logpane)

    app.addDockWidget(QtCore.Qt.BottomDockWidgetArea, panel)

    # setupLogger
    formatter = logging.Formatter('%(levelname)s: %(message)s')
    handler = QtLoggingHandler(logpane)
    handler.setFormatter(formatter)
    app.logger.addHandler(handler)

    # Connect signals
    logpane.paneHideRequest.connect(panel.hide)
コード例 #3
0
    def __init__(self, debug=False):
        super(QtShell, self).__init__()

        # Icon
        self.setWindowIcon(
            self.style().standardIcon(QtWidgets.QStyle.SP_ComputerIcon))

        # Command box
        self.cmdbox = QtWidgets.QComboBox()
        self.cmdbox.setEditable(True)
        self.cmdbox.addItem('')
        self.cmdbox.setCurrentIndex(self.cmdbox.count() - 1)
        # @TODO: complete
        #self.entry.populate_popup.connect(self.on_populate_popup)

        icon = self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay)
        self.cmdbutton = QtWidgets.QPushButton(icon, 'Run')
        self.cmdbutton.clicked.connect(self.execute)

        lineedit = self.cmdbox.lineEdit()
        lineedit.returnPressed.connect(self.cmdbutton.click)

        hLayout = QtWidgets.QHBoxLayout()
        hLayout.addWidget(QtWidgets.QLabel('cmd > '))
        hLayout.addWidget(self.cmdbox, 1)
        hLayout.addWidget(self.cmdbutton)

        # Output pane
        outputpane = QtOutputPane()
        outputpane.setReadOnly(True)
        outputpane.actions.removeAction(outputpane.actionHide)
        vLayout = QtWidgets.QVBoxLayout()
        vLayout.addLayout(hLayout)
        vLayout.addWidget(outputpane)

        # Main window
        centralWidget = QtWidgets.QWidget()
        centralWidget.setLayout(vLayout)
        self.setCentralWidget(centralWidget)

        self.quit_shortcut = QtWidgets.QShortcut(QtGui.QKeySequence.Quit, self)
        self.eof_shortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_D), self)

        self.setWindowTitle('Qt Shell')
        self.setGeometry(0, 0, 800, 600)
        self.quit_shortcut.activated.connect(self.close)
        self.eof_shortcut.activated.connect(self.close)

        # Setup the log system
        if debug:
            level = logging.DEBUG
            logging.basicConfig(level=level)
        else:
            level = logging.INFO

        self.logger = logging.getLogger()

        formatter = logging.Formatter('%(levelname)s: %(message)s')
        handler = QtLoggingHandler(outputpane)
        handler.setLevel(level)
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        formatter = logging.Formatter('%(message)s')
        handler = QtDialogLoggingHandler(parent=self, dialog=None)
        handler.setLevel(logging.WARNING)
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        self.logger.setLevel(level)

        # Setup high level components and initialize the parent classes
        handler = QtOutputHandler(self.logger, self.statusBar())
        self.tool = exectools.ToolDescriptor('', stdout_handler=handler)
        self.controller = QtToolController(self.logger, parent=self)
        self.controller.finished.connect(lambda returncode: self.reset())

        #self.shell = True
        self._state = 'ready'   # or maybe __state

        self.logger.debug('qtshell session started at %s.' % time.asctime())
        self.load_history()