Function¶
Classes used for defining functions as Qt elements. Create a single widget using the Function
class or combine multiple functions into a single widget using the Functions
class
Function¶
-
class
qtap.
Function
(func: callable, arg_opts: dict = None, parent: Optional[PyQt5.QtWidgets.QWidget] = None, kwarg_entry: bool = False)[source]¶ -
__init__
(func: callable, arg_opts: dict = None, parent: Optional[PyQt5.QtWidgets.QWidget] = None, kwarg_entry: bool = False)[source]¶ Creates a widget based on the function signature
Parameters: - func (callable) – A function with type annotations
- arg_opts (dict) – manually set certain features of an Arg
- parent (Optional[QtWidgets.QWidget]) – parent QWidget
- kwarg_entry (bool) – Not yet implemented. include a text box for kwargs entry
-
sig_changed
¶ Emitted when an argument value changes. Emits dict for all function arguments. See
get_data()
for details on the dict.Type: dict
-
sig_set_clicked
¶ Emitted when the “Set” button is clicked. Emits dict for all function arguments. See
get_data()
for details on the dict.Type: dict
-
sig_arg_changed
¶ Emitted when specific argument value changes. Emits argument name and argument value
Type: str, object
Examples
Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from PyQt5 import QtWidgets from qtap import Function # annotated function def f(a: int = 1, b: float = 3.14, c: str = 'yay', d: bool = True): pass app = QtWidgets.QApplication([]) # basic func = Function(f) func.widget.show() app.exec()
Opt Args
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
from PyQt5 import QtWidgets from qtap import Function from pyqtgraph.console import ConsoleWidget def f(a: int = 1, b: float = 3.14, c: str = 'yay', d: bool = True): pass if __name__ == '__main__': app = QtWidgets.QApplication([]) # opt args dict opts = { 'b': { 'use_slider': True, 'minmax': (0, 100), 'step': 1, 'suffix': '%', 'typ': int, 'tooltip': 'yay tooltips' } } func = Function(f, arg_opts=opts) func.widget.show() console = ConsoleWidget(parent=func.widget, namespace={'this': func}) func.vlayout.addWidget(console) app.exec()
-
Functions¶
-
class
qtap.
Functions
(functions: List[callable], arg_opts: Optional[List[dict]] = None, parent: Optional[PyQt5.QtWidgets.QWidget] = None, scroll: bool = False, orient: str = 'V', columns: bool = False, **kwargs)[source]¶ -
__init__
(functions: List[callable], arg_opts: Optional[List[dict]] = None, parent: Optional[PyQt5.QtWidgets.QWidget] = None, scroll: bool = False, orient: str = 'V', columns: bool = False, **kwargs)[source]¶ Parameters: - functions (List[callable]) – list of functions
- arg_opts (List[dict], optional) – optional list of dicts to manually set features of an argument.
passed to
Function
- parent (QtWidgets.QWidget, optional) – parent widget
- scroll (bool) – Not yet implemented
- orient (str) – orientation of the individual functions. One of
V
orH
. Default orientation isV
(vertical) - columns (bool) – Not yet implemented
- **kwargs – passed to QtWidgets.QWidget.__init__()
-
sig_changed
¶ Emitted when an underlying function emits sig_changed(). The emitted dict comes from
get_data()
, see the docstring forget_data()
for details.Type: dict
-
sig_set_clicked
¶ Emitted when an underlying function emits sig_set_clicked(). The emitted dict comes from
get_data()
, see the docstring forget_data()
for details.Type: dict
Examples
Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
from PyQt5 import QtWidgets from qtap import Functions from pyqtgraph.console import ConsoleWidget def func_A(a: int = 1, b: float = 3.14, c: str = 'yay', d: bool = True): pass def func_B(x: float = 50, y: int = 2.7, u: str = 'bah'): pass if __name__ == '__main__': app = QtWidgets.QApplication([]) functions = Functions([func_A, func_B]) console = ConsoleWidget(parent=functions, namespace={'this': functions}) functions.main_layout.addWidget(console) functions.show() app.exec()
Opt Args
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
from PyQt5 import QtWidgets from qtap import Functions from pyqtgraph.console import ConsoleWidget def func_A(a: int = 1, b: float = 3.14, c: str = 'yay', d: bool = True): pass def func_B(x: float = 50, y: int = 2.7, u: str = 'bah'): pass if __name__ == '__main__': app = QtWidgets.QApplication([]) # opt args for ``func_A`` opts_A = { 'b': { 'use_slider': True, 'minmax': (0, 100), 'step': 1, 'suffix': '%', 'typ': int, 'tooltip': 'yay tooltips' } } # functions where one has ``opt_args`` functions = Functions( functions=[func_A, func_B], arg_opts=[opts_A, None], # opt_args in same order as functions ) console = ConsoleWidget(parent=functions, namespace={'this': functions}) functions.main_layout.addWidget(console) functions.show() app.exec()
-