Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 | <html> | |
3 | <head> | |
4 | <title>SPARC Architectural Model: User Commands</title> | |
5 | </head> | |
6 | <body bgcolor="#FFFFFF" LANG="en-US"> | |
7 | <div STYLE="margin-bottom: 0cm"></div> | |
8 | ||
9 | <h2> | |
10 | run-python-file | |
11 | </h2> | |
12 | ||
13 | <h4> | |
14 | NAME | |
15 | </h4> | |
16 | <ul> | |
17 | run-python-file - execute python script file | |
18 | </ul> | |
19 | ||
20 | <h4>SYNOPSIS</h4> | |
21 | <tt> | |
22 | <ul> | |
23 | run-python-file <i>filename</i> | |
24 | </ul> | |
25 | </tt> | |
26 | ||
27 | <h4>DESCRIPTION</h4> | |
28 | <ul> | |
29 | Read Python code from <i>filename</i>. Any definitions are entered | |
30 | into the top | |
31 | level name-space in the Python environment. This command can be used to | |
32 | start Python scripts inside simulation. | |
33 | <p> | |
34 | SAM provides a python method, sam.ui_register(), to register python | |
35 | methods with the user interface. | |
36 | This method can be used to add arbitrary functionality to the SAM UI. | |
37 | <p> | |
38 | The ui_exec() method allows SamUI commands to be executed from python. | |
39 | <p> | |
40 | The sam python object provides the following methods to access the | |
41 | SamUI, registers and unregister methods as commands with the SamUI. | |
42 | <br><br> | |
43 | <table> | |
44 | <tr> | |
45 | <th>Method Name</th><th>Description</th> | |
46 | </tr> | |
47 | <tr valign="top"> | |
48 | <td>ui_exec ("<i>cmd</i>")</td> | |
49 | <td>Sends <i>cmd</i> to the SamUI.</td> | |
50 | </tr> | |
51 | <tr valign="top"> | |
52 | <td>ui_register ("<i>cmd_name</i>", "<i>help_string</i>", <i>cmd_function<i>) </td> | |
53 | <td>Registers the python function <i>cmd_function</i> with the SamUI | |
54 | as "<i>cmd_name</i>". The commands help string is | |
55 | "<i>help_string</i>".</td> | |
56 | </tr> | |
57 | <tr valign="top"> | |
58 | <td>ui_unregister ("<i>cmd_name</i>")</td> | |
59 | <td>Unregisters the command registered with the SamUI, | |
60 | "<i>cmd_name</i>".</td> | |
61 | </tr> | |
62 | </table><br> | |
63 | <p> | |
64 | Here is an example that registers the python method | |
65 | <code>echo()</code> as "py_echo". | |
66 | <div> | |
67 | <code> | |
68 | def echo(*argv):<br> | |
69 | print argv<br> | |
70 | <br> | |
71 | sam.ui_register("py_echo", "Prints its arguments", echo)<br> | |
72 | </code> | |
73 | </div> | |
74 | <p> | |
75 | Here is another example that runs python code from the SamUI: | |
76 | <div> | |
77 | <code> | |
78 | def exec_py(*argv):<br> | |
79 | cmd = " ".join(argv[1:])<br> | |
80 | try:<br> | |
81 | exec(cmd)<br> | |
82 | except:<br> | |
83 | print "ERROR"<br> | |
84 | <br> | |
85 | sam.ui_register("exec_py","exec_py runs python code",exec_py) | |
86 | </code> | |
87 | </div> | |
88 | <p> | |
89 | Now from the SamUI, one can type: | |
90 | <br> | |
91 | <div> | |
92 | <code> | |
93 | exec_py xyz = 10<br> | |
94 | exec_py print "xyz is %d" % xyz<br> | |
95 | </code> | |
96 | </div> | |
97 | <p> | |
98 | and see | |
99 | <br> | |
100 | <div> | |
101 | <code> | |
102 | xyz is 10 | |
103 | </code> | |
104 | </div> | |
105 | <h4>RETURN VALUES</h4> | |
106 | <ul> | |
107 | None. | |
108 | </ul> | |
109 | ||
110 | <h4>SEE ALSO</h4> | |
111 | <ul><a href="cmd_run-cmd-file.html">run-command-file</a></ul> | |
112 | <ul><a href="http://www.python.org">python</a></ul> | |
113 | ||
114 | <hr> | |
115 | </body> | |
116 | </html> |