예제 #1
0
    def __init__(self, debug=False):
        # Command box
        cmdlabel = Gtk.Label(label='cmd >')
        cmdlabel.set_padding(5, 0)

        self.cmdbox = Gtk.ComboBoxText.new_with_entry()
        self.cmdbox.set_active(0)
        self.cmdbox.set_focus_on_click(False)
        self.cmdbox.connect('changed', self.on_item_selected)

        completion = Gtk.EntryCompletion()
        completion.set_model(self.cmdbox.get_model())
        completion.set_text_column(0)

        self.entry = self.cmdbox.get_child()
        self.entry.set_completion(completion)
        self.entry.connect('activate', self.on_entry_activate)
        self.entry.connect('key-press-event', self.on_key_pressed)
        self.entry.connect('populate-popup', self.on_populate_popup)

        # self.cmdbutton = Gtk.Button.new_with_mnemonic('_Execute')
        self.cmdbutton = Gtk.Button(stock=Gtk.STOCK_EXECUTE)
        self.cmdbutton.connect('clicked', self.on_cmdbutton_clicked)

        # Note: set_always_show_image is new in Gtk 3.6
        self.cmdbutton.set_always_show_image(True)

        hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing=3)
        hbox.pack_start(cmdlabel, expand=False, fill=False, padding=0)
        hbox.pack_start(self.cmdbox, expand=True, fill=True, padding=0)
        hbox.pack_start(self.cmdbutton, expand=False, fill=False, padding=0)

        # Output pane
        outputpane = GtkOutputPane(hide_button=False)
        outputpane.set_editable(False)
        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.AUTOMATIC,
                               Gtk.PolicyType.AUTOMATIC)
        scrolledwin.add(outputpane)

        # Status bar
        self.statusbar = Gtk.Statusbar()
        id_ = self.statusbar.get_context_id('ready')
        self.statusbar.push(id_, 'Ready.')

        # Main window
        vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, spacing=3)
        vbox.set_border_width(3)
        vbox.pack_start(hbox, expand=False, fill=True, padding=0)
        vbox.pack_start(scrolledwin, expand=True, fill=True, padding=0)
        vbox.pack_start(self.statusbar, expand=False, fill=True, padding=0)

        accelgroup = Gtk.AccelGroup()
        accelgroup.connect(ord('d'), Gdk.ModifierType.CONTROL_MASK,
                           Gtk.AccelFlags.VISIBLE, self.quit)

        self.mainwin = Gtk.Window()
        self.mainwin.set_title('GTK Shell')
        theme = Gtk.IconTheme.get_default()
        icon = theme.load_icon(Gtk.STOCK_EXECUTE, Gtk.IconSize.LARGE_TOOLBAR,
                               Gtk.IconLookupFlags(0))
        self.mainwin.set_icon(icon)
        self.mainwin.add(vbox)
        self.mainwin.set_default_size(650, 500)
        self.mainwin.add_accel_group(accelgroup)
        self.mainwin.connect('destroy', self.quit)
        self.mainwin.show_all()

        # 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 = GtkLoggingHandler(outputpane)
        handler.setLevel(level)
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        formatter = logging.Formatter('%(message)s')
        handler = GtkDialogLoggingHandler(parent=self.mainwin, 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 = GtkOutputHandler(self.logger, self.statusbar)
        self.tool = exectools.ToolDescriptor('', stdout_handler=handler)
        self.controller = GtkToolController(logger=self.logger)
        self.controller.connect('finished', self.on_finished)

        # Final setup
        self._state = 'ready'  # or maybe __state

        self.logger.debug('gtkshell session started at %s.' % time.asctime())
        self.load_history()
예제 #2
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()
예제 #3
0
    def __init__(self, debug=False):

        ### Command box ###
        cmdlabel = gtk.Label('cmd >')
        cmdlabel.set_padding(5, 0)

        self.cmdbox = gtk.combo_box_entry_new_text()
        self.cmdbox.set_active(0)
        self.cmdbox.set_focus_on_click(False)
        self.cmdbox.connect('changed', self.on_item_selected)

        completion = gtk.EntryCompletion()
        completion.set_model(self.cmdbox.get_model())
        completion.set_text_column(0)

        self.entry = self.cmdbox.get_child()
        self.entry.set_completion(completion)
        self.entry.connect('activate', self.on_entry_activate)
        self.entry.connect('key-press-event', self.on_key_pressed)
        self.entry.connect('populate-popup', self.on_populate_popup)

        self.cmdbutton = gtk.Button(stock=gtk.STOCK_EXECUTE)
        self.cmdbutton.connect('clicked', self.on_cmdbutton_clicked)

        hbox = gtk.HBox(spacing=3)
        hbox.pack_start(cmdlabel, fill=False, expand=False)
        hbox.pack_start(self.cmdbox)
        hbox.pack_start(self.cmdbutton, fill=False, expand=False)

        ### Output plane ###
        outputplane = GtkOutputPlane(hide_button=False)
        outputplane.set_editable(False)
        scrolledwin = gtk.ScrolledWindow()
        scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolledwin.add(outputplane)

        ### Status bar ###
        self.statusbar = gtk.Statusbar()
        id_ = self.statusbar.get_context_id('ready')
        self.statusbar.push(id_, 'Ready.')

        ### Main window ###
        vbox = gtk.VBox(spacing=3)
        vbox.set_border_width(3)
        vbox.pack_start(hbox, fill=True, expand=False)
        vbox.pack_start(scrolledwin)
        vbox.pack_start(self.statusbar, fill=True, expand=False)

        accelgroup = gtk.AccelGroup()
        accelgroup.connect_group(ord('d'), gtk.gdk.CONTROL_MASK,
                                 gtk.ACCEL_VISIBLE, self.quit)

        self.mainwin = gtk.Window()
        self.mainwin.set_title('GTK Shell')
        self.mainwin.add(vbox)
        self.mainwin.set_default_size(650, 500)
        self.mainwin.add_accel_group(accelgroup)
        self.mainwin.connect('destroy', self.quit)
        self.mainwin.show_all()

        ### 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 = GtkLoggingHandler(outputplane)
        handler.setLevel(level)
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        formatter = logging.Formatter('%(message)s')
        handler = GtkDialogLoggingHandler(parent=self.mainwin, 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 = GtkOutputHandler(self.logger, self.statusbar)
        self.tool = exectools.ToolDescriptor('', stdout_handler=handler)
        self.controller = GtkToolController(logger=self.logger)
        self.controller.connect('finished', self.on_finished)

        ### Final setup ###
        self._state = 'ready'  # or maybe __state

        self.logger.debug('gtkshell session started at %s.' % time.asctime())
        self.load_history()
예제 #4
0
    def __init__(self, debug=False):
        QtGui.QMainWindow.__init__(self)

        ### Command box ###
        self.cmdbox = QtGui.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)

        self.cmdbutton = QtGui.QPushButton('Run')
        self.cmdbutton.clicked.connect(self.execute)

        lineedit = self.cmdbox.lineEdit()
        lineedit.returnPressed.connect(self.cmdbutton.clicked[''])

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

        ### Output plane ###
        outputplane = Qt4OutputPlane()
        outputplane.setReadOnly(True)
        outputplane.actions.removeAction(outputplane.actionHide)
        vLayout = QtGui.QVBoxLayout()
        vLayout.addLayout(hLayout)
        vLayout.addWidget(outputplane)

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

        # @TODO: complete
        #~ accelgroup = gtk.AccelGroup()
        #~ accelgroup.connect_group(ord('d'), gtk.gdk.CONTROL_MASK,
        #~ gtk.ACCEL_VISIBLE, self.quit)

        self.setWindowTitle('Qt4 Shell')
        self.setGeometry(0, 0, 800, 600)
        #~ self.mainwin.add_accel_group(accelgroup)
        #~ self.mainwin.destroy.connect(self.quit)

        ### 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 = Qt4LoggingHandler(outputplane)
        handler.setLevel(level)
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        formatter = logging.Formatter('%(message)s')
        handler = Qt4DialogLoggingHandler(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 = Qt4OutputHandler(self.logger, self.statusBar())
        self.tool = exectools.ToolDescriptor('', stdout_handler=handler)
        self.controller = Qt4ToolController(self.logger, parent=self)
        self.controller.finished.connect(lambda returncode: self.reset())

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

        self.logger.debug('qt4shell session started at %s.' % time.asctime())
        self.load_history()
예제 #5
0
#!/usr/bin/env python

import logging
import exectools, exectools.std


logging.basicConfig(level=logging.DEBUG, format='%(message)s')

echo = exectools.ToolDescriptor(
    'echo', stdout_handler=exectools.BaseOutputHandler())

c = exectools.std.StdToolController()
c.run_tool(echo, 'ciao', 'ciao2')
c.finalize_run()
print(c.isbusy)