The latest version of this document can be found at www.broad.ology.org.uk/amiga/proaction/ProActionControl.html
1: #!python
2:
3: #
4: # ProAction Control
5: # Script to start ProAction and set various attributes syuch as debug level and delay.
6: #
7:
8: import os
9: import arexx
10:
11:
12: def SetDebug(guiKey):
13:
14: global debugLevelID
15: global debugDelayID
16: global debugSerialID
17:
18: # Get the values of the debug gadgets
19:
20: (rc,rc2,level) = arexx.dorexx("PROACTION","GETATTR GUIID " + guiKey + " OBJECTID " + debugLevelID + " TAGNAME "INTEGER_Number"")
21:
22: (rc,rc2,delay) = arexx.dorexx("PROACTION","GETATTR GUIID " + guiKey + " OBJECTID " + debugDelayID + " TAGNAME "INTEGER_Number"")
23:
24: (rc,rc2,serial) = arexx.dorexx("PROACTION","GETATTR GUIID " + guiKey + " OBJECTID " + debugSerialID + " TAGNAME "GA_Selected"")
25:
26:
27: debugCmd = "DEBUG LEVEL " + level + " DELAY " + delay
28: if serial == "1":
29: debugCmd += " SERIAL"
30:
31: (rc,rc2,dummy) = arexx.dorexx("PROACTION",debugCmd)
32:
33: def HandleInput(port,guiKey):
34:
35: global debugLevelID
36: global debugDelayID
37: global debugSerialID
38: global stopButtonID
39: global restartButtonID
40:
41: result = 0;
42:
43: die = 0
44: while die == 0:
45: # wait on our incoming port
46: port.wait()
47: # get the msg (if any)
48: msg = port.getmsg()
49: if msg:
50: # it's a real msg get the cmd from it and reply quickly
51: cmd = msg.msg
52: msg.reply()
53: # now process the command.
54: if cmd == "QUIT":
55: die = 1
56: break
57: if cmd[:5] == "CLOSE":
58: die = 1
59: break
60: if cmd[:8] == "GADGETUP":
61: # format is
62: # GADGETUP GUIKID guikey GADGETID gid CODE code
63: (dummy,dummy,lguikey,dummy,gid,dummy,code) = cmd.split()
64:
65: # Check the message is from the correct GUI
66: # We are only running one in this example, but a script could
67: # handle an arbitrary number
68:
69: if lguikey == guiKey:
70: if gid == debugSerialID or gid == debugDelayID or gid == debugLevelID:
71: SetDebug(guiKey)
72: if gid == stopButtonID:
73: result = 1
74: die = 1
75: if gid == restartButtonID:
76: result = 2
77: die = 1
78: return result
79:
80: # DoGUI handles setup and disposal of the GUI
81: # Then passes control onto handle input
82:
83: def DoGUI(pubscreen):
84:
85: # Declare som globals here:
86: # Gadgets IDs we want to allow HandleInput() etc access to etc.
87:
88: global debugLevelID
89: global debugDelayID
90: global debugSerialID
91: global stopButtonID
92: global restartButtonID
93:
94: # First setup our ARexx Port
95: # We only want one ProActionControl script active so we choose a unique name.
96: eventPortName = 'ProActionControl'
97: eventPort = arexx.Port(eventPortName)
98:
99: if eventPort:
100:
101:
102: # First we'll build our window.class tagslist
103: # Python can't use send StemVars at the moment so we'll
104: # use the TAGSTRING tecnique throughout.
105:
106: winTags = ""
107: winTags += "WA_Width,400,"
108: winTags += "WA_Height,10,"
109: winTags += "WINDOW_LockHeight,1,"
110: winTags += "WA_DragBar,1,"
111: winTags += "WA_DepthGadget,1,"
112: winTags += "WA_SizeGadget,1,"
113: winTags += "WA_CloseGadget,1,"
114: winTags += "WA_Title,ProAction Control,"
115: winTags += "WA_PubScreenFallBack,1,"
116: winTags += "WA_PubScreenName," + pubscreen + ","
117: winTags += "WINDOW_Position,WPOS_CENTERSCREEN,"
118: winTags += "WA_Activate,1,"
119: winTags += "WINDOW_GadgetHelp,1,"
120: winTags += "TAG_DONE"
121:
122: topLayoutTags = ""
123: topLayoutTags += "LAYOUT_Orientation,LAYOUT_ORIENT_VERT,"
124: topLayoutTags += "TAG_DONE"
125:
126:
127: debugLayoutTags = ""
128: debugLayoutTags += "LAYOUT_Orientation,LAYOUT_ORIENT_VERT,"
129: debugLayoutTags += "LAYOUT_BevelStyle,BVS_GROUP,"
130: debugLayoutTags += "LAYOUT_Label,Debug Settings,"
131: debugLayoutTags += "TAG_DONE"
132:
133: stopLayoutTags = ""
134: stopLayoutTags += "LAYOUT_Orientation,LAYOUT_ORIENT_HORIZ,"
135: stopLayoutTags += "LAYOUT_BevelStyle,BVS_GROUP,"
136: stopLayoutTags += "LAYOUT_Label,Server Control,"
137: stopLayoutTags += "TAG_DONE"
138:
139: # NOTE: The TAG_DONE is deleiberatly missing from the next set of tag
140: # definitions. We'll add it later after we have queried the DEBUG status
141: # of ProAction
142:
143: debugLevelGadTags = ""
144: debugLevelGadTags += "INTEGER_Minimum,0,"
145: debugLevelGadTags += "INTEGER_Maximum,20,"
146: debugLevelGadTags += "INTEGER_MinVisible,3,"
147: debugLevelGadTags += "INTEGER_MaxChars,2,"
148: debugLevelGadTags += "GA_RelVerify,1,"
149: debugLevelGadTags += "GA_HintInfo,Sets the amount of debug info ouput *NHigher equals more - range 0 to 20,"
150:
151:
152: debugDelayGadTags = ""
153: debugDelayGadTags += "INTEGER_Minimum,0,"
154: debugDelayGadTags += "INTEGER_Maximum,100,"
155: debugDelayGadTags += "INTEGER_MinVisible,4,"
156: debugDelayGadTags += "INTEGER_MaxChars,3,"
157: debugDelayGadTags += "GA_RelVerify,1,"
158: debugDelayGadTags += "GA_HintInfo,Introduce a delay after each debug output *NDelay Time is measured in ticks (1/50 sec),"
159:
160: debugSerialGadTags = ""
161: debugSerialGadTags += "GA_RelVerify,1,"
162: debugSerialGadTags += "GA_HintInfo,Sends Debug to the serial port instead of the console,"
163:
164: # These ones are complete...
165: stopButtonTags = ""
166: stopButtonTags += "GA_Text,Stop Server,"
167: stopButtonTags += "GA_RelVerify,1,"
168: stopButtonTags += "GA_HintInfo,Force an *"Emergency Stop*" *N(killing all running GUIs),"
169: stopButtonTags += "TAG_DONE"
170:
171: restartButtonTags = ""
172: restartButtonTags += "GA_Text,Restart Server,"
173: restartButtonTags += "GA_RelVerify,1,"
174: restartButtonTags += "GA_HintInfo,Attempt to stop and restart the server *N(killng all running GUIs),"
175: restartButtonTags += "TAG_DONE"
176:
177: (rc,rc2,guiKey) = arexx.dorexx("PROACTION","CREATEGUI PORTNAME "" + eventPortName + "" TAGSTRING "" + winTags + """)
178:
179: if rc == 0:
180: # Our reuest for anew GUI was granted so we can start builing our gadget list.
181:
182: # But first query the current debug status of ProAction
183:
184:
185: level = "0"
186: delay = "0"
187: serial = "0"
188:
189: (rc,rc2,status) = arexx.dorexx("PROACTION", "GETGUIATTR GUIID " + guiKey + " ATTRNAME "DEBUG"")
190: if rc == 0:
191: # Format of the reply is "LEVEL number DELAY number SERIAL bool"
192: (dummy,level,dummy,delay,dummy,serial) = status.split()
193:
194: # Put in the mising tags inc the TAG_DONE mentioned above;
195:
196: debugLevelGadTags += "INTEGER_Number," + level + ",TAG_DONE"
197: debugDelayGadTags += "INTEGER_Number," + delay + ",TAG_DONE"
198: debugSerialGadTags += "GA_Selected," + serial + ",TAG_DONE"
199:
200: # We will have two sections 'DEBUG' and STOPPROACTION
201: # So we set the top level to vertical orientaion then add the debug
202: # layout to that.
203:
204: (rc,rc2,topLayoutID) = arexx.dorexx("PROACTION","ADDLAYOUT GUIID " + guiKey + " TAGSTRING "" + topLayoutTags + """)
205: (rc,rc2,debugLayoutID) = arexx.dorexx("PROACTION","ADDLAYOUT GUIID " + guiKey + " TAGSTRING "" + debugLayoutTags + """)
206:
207: # Add our debug gadgets to the debugLayout */
208:
209: (rc,rc2,debugLevelID) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guiKey + " GADGETCLASS "integer.gadget" TAGSTRING "" + debugLevelGadTags + """)
210:
211: (rc,rc2,debugDelayID) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guiKey + " GADGETCLASS "integer.gadget" TAGSTRING "" + debugDelayGadTags + """)
212: (rc,rc2,debugSerialID) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guiKey + " GADGETCLASS "checkbox.gadget" TAGSTRING "" + debugSerialGadTags + """)
213:
214: # Create a label image for each and add via modify child.
215: labelTags = ""
216: labelTags += "LABEL_Text,Debug Level:,"
217: labelTags += "TAG_DONE"
218:
219: (rc,rc2,labelID) = arexx.dorexx("PROACTION", "NEWIMAGE GUIID " + guiKey + " IMAGECLASS "label.image" NODISPOSE TAGSTRING "" + labelTags + """)
220:
221: (rc,rc2,dummy) = arexx.dorexx("PROACTION", "SETATTRS GUIID " + guiKey + " OBJECTID " + debugLayoutID + " TAGSTRING "LAYOUT_ModifyChild," + debugLevelID + ",CHILD_Label," + labelID + ",TAG_DONE"")
222:
223: labelTags = ""
224: labelTags += "LABEL_Text,Debug Delay:,"
225: labelTags += "TAG_DONE"
226:
227: (rc,rc2,labelID) = arexx.dorexx("PROACTION", "NEWIMAGE GUIID " + guiKey + " IMAGECLASS "label.image" NODISPOSE TAGSTRING "" + labelTags + """)
228:
229: (rc,rc2,dummy) = arexx.dorexx("PROACTION", "SETATTRS GUIID " + guiKey + " OBJECTID " + debugLayoutID + " TAGSTRING "LAYOUT_ModifyChild," + debugDelayID + ",CHILD_Label," + labelID + ",TAG_DONE"")
230:
231: labelTags = ""
232: labelTags += "LABEL_Text,Serial:,"
233: labelTags += "TAG_DONE"
234:
235: (rc,rc2,labelID) = arexx.dorexx("PROACTION", "NEWIMAGE GUIID " + guiKey + " IMAGECLASS "label.image" NODISPOSE TAGSTRING "" + labelTags + """)
236:
237: (rc,rc2,dummy) = arexx.dorexx("PROACTION", "SETATTRS GUIID " + guiKey + " OBJECTID " + debugLayoutID + " TAGSTRING "LAYOUT_ModifyChild," + debugSerialID + ",CHILD_Label," + labelID + ",TAG_DONE"")
238:
239: # End of Debug Layout
240: (rc,rc2,dummy) = arexx.dorexx("PROACTION","ENDLAYOUT GUIID " + guiKey )
241:
242: # Add The Stop / Restart layout
243:
244: (rc,rc2,stopLayoutID) = arexx.dorexx("PROACTION","ADDLAYOUT GUIID " + guiKey + " TAGSTRING "" + stopLayoutTags + """)
245:
246: (rc,rc2,stopButtonID) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guiKey + " GADGETCLASS "button.gadget" TAGSTRING "" + stopButtonTags + """)
247: (rc,rc2,restartButtonID) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guiKey + " GADGETCLASS "button.gadget" TAGSTRING "" + restartButtonTags + """)
248:
249: # End of Stop Restart Layout
250: (rc,rc2,dummy) = arexx.dorexx("PROACTION","ENDLAYOUT GUIID " + guiKey )
251:
252: # End of TopLevel Layout
253: (rc,rc2,dummy) = arexx.dorexx("PROACTION","ENDLAYOUT GUIID " + guiKey )
254:
255: (rc,rc2,result) = arexx.dorexx("PROACTION","OPENGUIWINDOW GUIID " + guiKey)
256:
257: result = HandleInput(eventPort,guiKey)
258:
259: arexx.dorexx("PROACTION","CLOSEGUIWINDOW GUIID " + guiKey)
260: arexx.dorexx("PROACTION","DESTROYGUI GUIID " + guiKey)
261:
262: return result
263:
264:
265: def StartProAction():
266:
267: # First we need to check if ProAction is runing and start it if not.
268: # The python ARexx module lacks a ShowPorts function
269: # Borrow it from ARexx
270: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')")
271:
272: if rc == 0:
273: if -1 == ports.find("PROACTION"):
274: # No ProAction start it
275: os.system("RUN >NIL: APPDIR:PROACTION")
276: os.system("C:WaitForPort PROACTION")
277: # Now check again
278: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')")
279: if rc == 0:
280: if -1 == ports.find("PROACTION"):
281: # Still not there :-(
282: # A standard script may stop at this point.
283: # But one of the purposes of ProActionControl
284: # Is to startup proaction for the first time
285: # and "populate" the appdir: mechanism.
286:
287: # Call again without path (in srtanadard installation our
288: # ProAction script will be in the same directory.
289:
290: os.system("RUN >NIL: PROACTION")
291: os.system("C:WaitForPort PROACTION")
292: # Now check again
293: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')")
294: if rc == 0:
295: if -1 == ports.find("PROACTION"):
296: os.system('RequestChoice "SaveAsBrush.py" "Unable To Start ProAction GUIServer" "OK"')
297: exit()
298: else:
299:
300: os.system('RequestChoice "PAFindTag.py" "Couldn't Find ARexx!" "OK"')
301: exit()
302: else:
303:
304: os.system('RequestChoice "PAFindTag.py" "Couldn't Find ARexx!" "OK"')
305: exit()
306:
307:
308: # The real sequence of event starts here:
309:
310: StartProAction()
311:
312: # Okay we should be good to go now
313:
314: die = 0
315:
316: while die == 0:
317: result = DoGUI("Workbench")
318: if result == 0:
319: die = 1
320:
321: if result == 1:
322: die = 1
323: arexx.dorexx("PROACTION","QUIT")
324:
325: if result == 2:
326: arexx.dorexx("PROACTION","QUIT")
327:
328: # Wait for a short while
329: os.system("C:Wait 5")
330: StartProAction()
331:
332: