magicclass.ext.qtconsole package

Submodules

magicclass.ext.qtconsole.widgets module

class magicclass.ext.qtconsole.widgets.QtConsole(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

execute()[source]

Execute current code block.

executed

Declares a signal emitter on a class.

This is class implements the [descriptor protocol](https://docs.python.org/3/howto/descriptor.html#descriptorhowto) and is designed to be used as a class attribute, with the supported signature types provided in the contructor:

```python from psygnal import Signal

class MyEmitter:

changed = Signal(int)

def receiver(arg: int):

print("new value:", arg)

emitter = MyEmitter() emitter.changed.connect(receiver) emitter.changed.emit(1) # prints 'new value: 1' ```

!!! note

in the example above, MyEmitter.changed is an instance of Signal, and emitter.changed is an instance of SignalInstance. See the documentation on [SignalInstance][psygnal.SignalInstance] for details on how to connect to and/or emit a signal on an instance of an object that has a Signal.

Parameters
  • *types (Union[Type[Any], Signature]) -- A sequence of individual types, or a single [inspect.Signature][] object.

  • description (str) -- Optional descriptive text for the signal. (not used internally).

  • name (Optional[str]) -- Optional name of the signal. If it is not specified then the name of the class attribute that is bound to the signal will be used. default None

  • check_nargs_on_connect (bool) -- Whether to check the number of positional args against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_nargs=True). By default, True.

  • check_types_on_connect (bool) -- Whether to check the callback parameter types against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_types=True). By default, False.

property value: str

Get current code block

Module contents

Jupyter QtConsole widget with callback signals.

You can embed a console widget in a magic class.

from magicclass import magicclass
from magicclass.widgets import QtConsole

class Main:
    console = QtConsole()

ui = Main()
ui.show()

There are some additional methods that would be very useful for developing a Python script executable GUI.

# programmatically add code to console.
ui.console.value = "a = 1"

# callback when code is executed.
@console.executed.connect
def _():
    print("executed!")

# programmatically execute code.
ui.console.execute()
class magicclass.ext.qtconsole.QtConsole(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

central_widget: QWidget | None
execute()[source]

Execute current code block.

executed

Declares a signal emitter on a class.

This is class implements the [descriptor protocol](https://docs.python.org/3/howto/descriptor.html#descriptorhowto) and is designed to be used as a class attribute, with the supported signature types provided in the contructor:

```python from psygnal import Signal

class MyEmitter:

changed = Signal(int)

def receiver(arg: int):

print("new value:", arg)

emitter = MyEmitter() emitter.changed.connect(receiver) emitter.changed.emit(1) # prints 'new value: 1' ```

!!! note

in the example above, MyEmitter.changed is an instance of Signal, and emitter.changed is an instance of SignalInstance. See the documentation on [SignalInstance][psygnal.SignalInstance] for details on how to connect to and/or emit a signal on an instance of an object that has a Signal.

Parameters
  • *types (Union[Type[Any], Signature]) -- A sequence of individual types, or a single [inspect.Signature][] object.

  • description (str) -- Optional descriptive text for the signal. (not used internally).

  • name (Optional[str]) -- Optional name of the signal. If it is not specified then the name of the class attribute that is bound to the signal will be used. default None

  • check_nargs_on_connect (bool) -- Whether to check the number of positional args against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_nargs=True). By default, True.

  • check_types_on_connect (bool) -- Whether to check the callback parameter types against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_types=True). By default, False.

name: str
property value: str

Get current code block