source: orange/docs/widgets/rst/data/pythonscript.rst @ 11433:5d4e7e616510

Revision 11433:5d4e7e616510, 3.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 13 months ago (diff)

Added documentation for 'Python Script' widget.

RevLine 
[11433]1.. _Python Script:
2
3Python Script
4=============
5
6.. image:: ../../../../Orange/OrangeWidgets/Data/icons/PythonScript.svg
7   :alt: Python Script
8
9
10Signals
11-------
12
13Inputs:
14
15
16   - in_data (Orange.data.Table)
17      Input data set bound to ``in_data`` variable in the script's local
18      namespace.
19
20   - in_distance (Orange.core.SymMatrix)
21      Input symmetric matrix bound to ``in_distance`` variable in the script's
22      local namespace.
23
24   - in_learner (Orange.classification.Learner)
25      Input learner bound to ``in_learner`` variable in the script's
26      local namespace.
27
28   - in_classifier (Orange.classification.Learner)
29      Input classifier bound to ``in_classifier`` variable in the script's
30      local namespace.
31
32   - in_object (object)
33      Input python object bound to ``in_object`` variable in the script's
34      local namespace.
35
36
37Outputs:
38
39
40   - out_data (Orange.data.Table)
41      Data set retrieved from ``out_data`` variable in the script's local
42      namespace after execution.
43
44   - out_distance (Orange.core.SymMatrix)
45      Symmetric matrix retrieved from ``out_distance`` variable in the
46      script's local namespace after execution.
47
48   - out_learner (Orange.classification.Learner)
49      Learner retrieved from ``out_learner`` variable in the script's local
50      namespace.
51
52   - out_classifier (Orange.classification.Learner), *Dynamic*
53      Classifier retrieved from ``out_classifier`` variable in the script's
54      local namespace after execution.
55
56   - out_object (object), *Dynamic*
57      Python object retrieved from ``out_object`` variable in the script's
58      local namespace after execution.
59
60
61Description
62-----------
63
64.. image:: images/PythonScript.png
65   :alt: Python Script widget with an example script
66
67`Python Script` widget can be used to run a python script on the inputs,
68when a suitable functionality is not implemented in an existing widgets.
69The scripts have ``in_data``, ``in_distance``, ``in_learner``,
70``in_classifier`` and ``in_object`` varaibles (from input signals) in their
71local namespace. If a signal is not connected or it did not yet receive any
72data, those variables contain ``None``.
73
74After the script is executed ``out_data``, ``out_distance``, ... variables
75from the script's local namespace are extracted and used as outputs of the
76widget.
77
78For instance the following script would simply pass on all signals it
79receives::
80
81   out_data = in_data
82   out_distance = in_distance
83   out_learner = in_learner
84   out_classifier = in_classifier
85   out_object = in_object
86
87
88.. note:: You should not modify the input objects inplace.
89
90The :guilabel:`Python script` editor on the left can be used to edit
91a script (it supports some rudimentary syntax highlighting).
92
93Pressing the :guilabel:`Execute` in the :guilabel:`Run` box executes the
94script (using ``exec``). Any script output (from ``print``) is captured
95and displayed in the :guilabel:`Console` below the script.
96
97If the :guilabel:`Auto execute` is checked the script is run any time the
98inputs to the widget change.
99
100Library
101+++++++
102
103The :guilabel:`Library` control can be used to manage multiple scripts.
104
105Pressing :guilabel:`+` will add a new entry and open it in the
106:guilabel:`Python script` editor`. When the script is modified its entry in the
107:guilabel:`Library` will change to indicate it has unsaved changes. Pressing
108:guilabel:`Update` will save the script (keyboard shortcut `ctrl + s`). A
109script can be removed by selecting it and pressing the :guilabel:`-` button.
Note: See TracBrowser for help on using the repository browser.