puzzlepiece.action module
- class puzzlepiece.action.Action(function, parent, shortcut=None, visible=True)[source]
Bases:
QObject
An action is a function that a
Piece
object can call.It will be given a button in the GUI (if
visible
is True), and can be executed from code in other Pieces or elsewhere as if it was a method:puzzle['piece_name'].actions['action_name']()
Any arguments provided when calling an action will be passed to the registered function.
To register an action, use the
define()
decorator as shown below.- Parameters:
function – The function to call when the action is executed.
parent – The Piece this action belongs to.
shortcut – A keyboard shortcut for this action, works only when the Piece is visible.
visible – Bool flag, whether a button for the action is generated in the GUI.
- called
A Qt signal emitted when the action is executed.
- shortcut
Keyboard shortcut associated with the param.
- property visible
Bool flag, indicates whether this action is visible as a button in the GUI.
- puzzlepiece.action.define(piece, name, shortcut=None, visible=True)[source]
A decorator generator for registering a
Action
in a Piece’sdefine_action()
method with a given function.To register an action for a function, do this:
@puzzlepiece.action.define(self, 'action_name') def action(self): print("Hello world!")
- Parameters:
piece – The
Piece
this param should be registered with. Usually self, as this method should be called from withinpuzzlepiece.piece.Piece.define_actions()
name – a unique (per Piece) name for the action
shortcut – The keyboard shortcut for this action. See https://doc.qt.io/qt-6/qt.html#Key-enum for possible values. Example:
QtCore.Qt.Key.Key_F1
visible – bool flag, determined if a GUI button will be shown for this param.