def new_console(tabto=None, floating=False, dockingarea=QtCore.Qt.RightDockWidgetArea):
    """
    Create a new console and float it as a max widget
    tabto: name of a widget on top of which the console should be tabbed
    floating: True to float the console, False to leave it docked
    dockingarea: The docking area for docking the window (default = right)
    """
    main_window = GetQMaxMainWindow()

    # create and setup a console
    console = PythonConsole(formats=HUGOS_THEME)
    console.setStyleSheet("background-color: #333333;")

    # create a dock widget for the console
    dock_widget = QDockWidget(main_window)
    dock_widget.setWidget(console)
    dock_widget.setObjectName("pyconsole")
    dock_widget.setWindowTitle("Python Console")
    main_window.addDockWidget(dockingarea, dock_widget)
    if not tabto is None:
        tabw = main_window.findChild(QWidget, tabto)
        main_window.tabifyDockWidget(tabw, dock_widget)
    dock_widget.setFloating(floating)
    dock_widget.show()

    # make the console do stuff
    console.eval_queued()
    return console
Example #2
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys

from qtpy.QtWidgets import QApplication
from pyqtconsole.console import PythonConsole
from pyqtconsole.highlighter import format


def greet():
    print("hello world")


if __name__ == '__main__':
    app = QApplication([])

    console = PythonConsole(formats={'keyword': format('darkBlue', 'bold')})
    console.push_local_ns('greet', greet)
    console.show()

    console.eval_queued()

    sys.exit(app.exec_())