The latest version of this document can be found at www.broad.ology.org.uk/amiga/proaction/PAFindTag.html
1: #!python 2: # 3: # PAFindTag.py 4: # Example Script which allows the users to search for a tag and see if it is currently supported. 5: # 6: 7: import os 8: import arexx 9: 10: def HandleInput(pyport,guikey): 11: 12: global find_gid 13: global tagname_gid 14: global tagresult_gid 15: die = 0 16: while die == 0: 17: # wait on our incoming port 18: pyport.wait() 19: # get the msg (if any) 20: msg = pyport.getmsg() 21: if msg: 22: # it's a real msg get the cmd from it and reply quickly 23: cmd = msg.msg 24: msg.reply() 25: # now process the command. 26: if cmd == "QUIT": 27: die = 1 28: break 29: if cmd[:5] == "CLOSE": 30: die = 1 31: break 32: if cmd[:8] == "GADGETUP": 33: # format is 34: # GADGETUP GUIKID guikey GADGETID gid CODE code 35: (dummy,dummy,lguikey,dummy,gid,dummy,code) = cmd.split() 36: 37: # Check the message is from the correct GUI 38: # We are only running one in this example, but a script could 39: # handle an arbitrary number 40: 41: if lguikey == guikey: 42: if gid == find_gid or gid == tagname_gid: 43: (rc,rc2,result) = arexx.dorexx("PROACTION","GETATTR GUIID " + guikey + " OBJECTID " + tagname_gid + " TAGNAME "STRINGA_TextVal"") 44: if rc == 0: 45: (rc, rc2, supported) = arexx.dorexx("PROACTION", "GETGUIATTR GUIID " + guikey + " ATTRNAME TAGSUPPORTED "" + result + """) 46: if rc != 0: 47: supported = "Tag: *"" + result + "*" Unsupported." 48: else: 49: (tag,type) = supported.split() 50: supported = "Tag: *"" + tag + "*" Supported. Type: " + type 51: arexx.dorexx("PROACTION","SETATTRS GUIID " + guikey + " OBJECTID " + tagresult_gid + " TAGSTRING "STRINGA_TextVal," + supported + ",TAG_DONE"") 52: 53: 54: 55: # DoGUI does all the work for the GUI 56: 57: def DoGUI(pubscreen): 58: # Setup The ARexx Port for our script 59: # 60: global find_gid 61: global tagname_gid 62: global tagresult_gid 63: 64: 65: pyport = arexx.Port("PYPORT") 66: if pyport: 67: 68: # First we'll build our window.class tagslist 69: # Python can't use send StemVars at the moment so we'll 70: # use the TAGSTRING tecnique throughout. 71: 72: wintags = "" 73: wintags += "WA_Width,400," 74: wintags += "WA_Height,10," 75: wintags += "WINDOW_LockHeight,1," 76: wintags += "WA_DragBar,1," 77: wintags += "WA_DepthGadget,1," 78: wintags += "WA_SizeGadget,1," 79: wintags += "WA_CloseGadget,1," 80: wintags += "WA_Title,Find Tag," 81: wintags += "WA_PubScreenFallBack,1," 82: wintags += "WA_PubScreenName," + pubscreen + "," 83: wintags += "WINDOW_Position,WPOS_CENTERSCREEN," 84: wintags += "WA_Activate,1," 85: wintags += "TAG_DONE" 86: 87: layouttags = "" 88: layouttags += "LAYOUT_Orientation,LAYOUT_ORIENT_VERT," 89: layouttags += "TAG_DONE" 90: 91: 92: 93: taglayouttags = "" 94: taglayouttags += "LAYOUT_Orientation,LAYOUT_ORIENT_HORIZ," 95: taglayouttags += "TAG_DONE" 96: 97: (rc,rc2,guikey) = arexx.dorexx("PROACTION","CREATEGUI PORTNAME "PYPORT" TAGSTRING "" + wintags + """) 98: 99: if rc == 0: 100: (rc,rc2,current_layout_gid) = arexx.dorexx("PROACTION","ADDLAYOUT GUIID " + guikey + " TAGSTRING "" + layouttags + """) 101: 102: 103: 104: (rc,rc2,tagname_layout_gid) = arexx.dorexx("PROACTION","ADDLAYOUT GUIID " + guikey + " TAGSTRING "" + taglayouttags + """) 105: 106: (rc,rc2,tagname_gid) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guikey + " GADGETCLASS "string.gadget" TAGSTRING "STRINGA_TextVal,Enter Tagname here...,GA_RelVerify,1,TAG_DONE"") 107: (rc,rc2,find_gid) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guikey + " GADGETCLASS "button.gadget" TAGSTRING "GA_Text,Find Tag,GA_RelVerify,1,TAG_DONE"") 108: (rc,rc2,dummy) = arexx.dorexx("PROACTION","SETATTRS GUIID " + guikey + " OBJECTID " + tagname_layout_gid + " TAGSTRING "LAYOUT_ModifyChild," + find_gid + ",CHILD_WeightedWidth,0,TAG_DONE"") 109: 110: # End of tagname layout. 111: (rc,rc2,current_layout_gid) = arexx.dorexx("PROACTION","ENDLAYOUT GUIID " + guikey ) 112: # Set it's height to minimum. 113: (rc,rc2,dummy) = arexx.dorexx("PROACTION","SETATTRS GUIID " + guikey + " OBJECTID " + current_layout_gid + " TAGSTRING "LAYOUT_ModifyChild," + tagname_layout_gid + ",CHILD_WeightedHeight,0,TAG_DONE"") 114: 115: (rc,rc2,tagresult_gid) = arexx.dorexx("PROACTION","ADDGADGET GUIID " + guikey + " GADGETCLASS "string.gadget" TAGSTRING "GA_ReadOnly,1,TAG_DONE"") 116: # End of top level layout. 117: (rc,rc2,current_layout_gid) = arexx.dorexx("PROACTION","ENDLAYOUT GUIID " + guikey ) 118: 119: (rc,rc2,result) = arexx.dorexx("PROACTION","OPENGUIWINDOW GUIID " + guikey) 120: 121: HandleInput(pyport,guikey) 122: 123: arexx.dorexx("PROACTION","CLOSEGUIWINDOW GUIID " + guikey) 124: arexx.dorexx("PROACTION","DESTROYGUI GUIID " + guikey) 125: else: 126: os.system('RequestChoice "PAFindTag.py" "Couldn't Create ARexx Port" "OK"') 127: exit() 128: 129: 130: # The real sequence of event starts here: 131: 132: # First we need to check if ProAction is runing and start it if not. 133: # The python ARexx module lacks a ShowPorts function 134: # Borrow it from ARexx 135: 136: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')") 137: 138: if rc == 0: 139: if -1 == ports.find("PROACTION"): 140: # No ProAction start it 141: os.system("RUN >NIL: APPDIR:PROACTION") 142: os.system("C:WaitForPort PROACTION") 143: # Now check again 144: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')") 145: if rc == 0: 146: if -1 == ports.find("PROACTION"): 147: # Still not there :-( 148: os.system('RequestChoice "SaveAsBrush.py" "Unable To Start ProAction GUIServer" "OK"') 149: exit() 150: 151: else: 152: 153: os.system('RequestChoice "PAFindTag.py" "Couldn't Find ARexx!" "OK"') 154: exit() 155: 156: # Okay we should be good to go now 157: 158: DoGUI("Workbench") 159: 160: 161: