fsleyes_widgets.utils.runwindow
¶
This module provides classes and functions for running a non-interactive process, and displaying its output.
This module provides the RunPanel
and ProcessManager
classes, and a couple of associated convenience functions.
RunPanel |
A panel which displays a multiline text control, and a couple of buttons along the bottom. |
ProcessManager |
A thread which manages the execution of a child process, and capture of its output. |
run |
Runs the given command, displaying the output in a RunPanel . |
-
class
fsleyes_widgets.utils.runwindow.
RunPanel
(parent)¶ Bases:
wx._core.Panel
A panel which displays a multiline text control, and a couple of buttons along the bottom.
RunPanel
instances are created by therun()
function, and used/controlled by theProcessManager
.One of the buttons is intended to closes the window in which this panel is contained. The second button is intended to terminate the running process. Both buttons are unbound by default, so must be manually configured by the creator.
The text panel and buttons are available as the following attributes:
text
: The text panel.closeButton
: The Close window button.killButton
: The Terminate process button.
Create a
RunPanel
.Parameters: parent – The wx
parent object.-
__init__
(parent)¶ Create a
RunPanel
.Parameters: parent – The wx
parent object.
-
__module__
= 'fsleyes_widgets.utils.runwindow'¶
-
class
fsleyes_widgets.utils.runwindow.
ProcessManager
(cmd, parent, runPanel, onFinish)¶ Bases:
threading.Thread
A thread which manages the execution of a child process, and capture of its output.
The process output is displayed in a
RunPanel
which must be passed to theProcessManager
on creation.The
termProc()
method can be used to terminate the child process before it has completed.Create a
ProcessManager
.Parameters: - cmd – String or list of strings, the command to be executed.
- parent –
wx
parent object. - runPanel – A
RunPanel
instance , for displaying the child process output. - onFinish – Callback function to be called when the process
finishes. May be
None
. Must accept two parameters, the GUIparent
object, and the process return code.
-
__init__
(cmd, parent, runPanel, onFinish)¶ Create a
ProcessManager
.Parameters: - cmd – String or list of strings, the command to be executed.
- parent –
wx
parent object. - runPanel – A
RunPanel
instance , for displaying the child process output. - onFinish – Callback function to be called when the process
finishes. May be
None
. Must accept two parameters, the GUIparent
object, and the process return code.
-
run
()¶ Starts the process, then reads its output line by line, writing each line asynchronously to the
RunPanel
. When the process ends, theonFinish
method (if there is one) is called. If the process finishes abnormally (with a non-0 exit code) a warning dialog is displayed.
-
termProc
()¶ Attempts to kill the running child process.
-
_ProcessManager__writeToPanel
()¶ Reads a string from the output queue, and appends it to the
RunPanel
. This method is intended to be executed viawx.CallAfter()
.
-
__module__
= 'fsleyes_widgets.utils.runwindow'¶
-
fsleyes_widgets.utils.runwindow.
run
(name, cmd, parent, onFinish=None, modal=True)¶ Runs the given command, displaying the output in a
RunPanel
.Parameters: - name – Name of the tool to be run, used in the window title.
- cmd – String or list of strings, specifying the command to be executed.
- parent –
wx
parent object. - modal – If
True
, the frame which contains theRunPanel
will be modal. - onFinish – Function to be called when the process ends. Must
accept two parameters - a reference to the
wx
frame/dialog displaying the process output, and the exit code of the application.