Giter Site home page Giter Site logo

pyqtconsole's Introduction

pyqtconsole

Latest Version Python versions License: MIT Test status

pyqtconsole is a lightweight python console for Qt applications. It's made to be easy to embed in other Qt applications and comes with some examples that show how this can be done. The interpreter can run in a separate thread, in the UI main thread or in a gevent task.

Installing

Simply type:

pip install pyqtconsole

Or to install a development version from local checkout, type:

pip install -e .

Simple usage

The following snippet shows how to create a console that will execute user input in a separate thread. Be aware that long running tasks will still block the main thread due to the GIL. See the examples directory for more examples.

import sys
from threading import Thread
from PyQt5.QtWidgets import QApplication

from pyqtconsole.console import PythonConsole

app = QApplication([])
console = PythonConsole()
console.show()
console.eval_in_thread()

sys.exit(app.exec_())

Embedding

  • Separate thread - Runs the interpreter in a separate thread, see the example threaded.py. Running the interpreter in a separate thread obviously limits the interaction with the Qt application. The parts of Qt that needs to be called from the main thread will not work properly, but is excellent way for having a 'plain' python console in your Qt app.
  • main thread - Runs the interpreter in the main thread, see the example inuithread.py. Makes full interaction with Qt possible, lenghty operations will of course freeze the UI (as any lenghty operation that is called from the main thread). This is a great alternative for people who does not want to use the gevent based approach but still wants full interactivity with Qt.
  • gevent - Runs the interpreter in a gevent task, see the example _gevent.py. Allows for full interactivity with Qt without special consideration (at least to some extent) for longer running processes. The best method if you want to use pyQtgraph, Matplotlib, PyMca or similar.

Customizing syntax highlighting

The coloring of the syntax highlighting can be customized by passing a formats dictionary to the PythonConsole constructer. This dictionary must be shaped as follows:

import pyqtconsole.highlighter as hl
console = PythonConsole(formats={
    'keyword':    hl.format('blue', 'bold'),
    'operator':   hl.format('red'),
    'brace':      hl.format('darkGray'),
    'defclass':   hl.format('black', 'bold'),
    'string':     hl.format('magenta'),
    'string2':    hl.format('darkMagenta'),
    'comment':    hl.format('darkGreen', 'italic'),
    'self':       hl.format('black', 'italic'),
    'numbers':    hl.format('brown'),
    'inprompt':   hl.format('darkBlue', 'bold'),
    'outprompt':  hl.format('darkRed', 'bold'),
})

All keys are optional and default to the value shown above if left unspecified.

Credits

This module depends on QtPy which provides a compatibility layer for Qt4 and Qt5. The console is tested under both Qt4 and Qt5.

pyqtconsole's People

Contributors

marcus-oscarsson avatar coldfix avatar roberthdevries avatar robertoroos avatar liametc avatar irgolic avatar the-compiler avatar hiaselhans avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.