From: Kevin A. <al...@se...> - 2001-08-20 20:03:17
|
First of all, this is all Dan Winkler's fault ;-) for putting the idea in my head last night, so that I felt compelled to do at least a proof of concept. Any stupidity in the HyperTalk below is because I haven't done any HyperTalk coding in a long time. I've included both the script and the script output at the end of this message. You can make a copy of the minimal sample directory, copy the output below and replace the contents of the minimal.rsrc.py file to see what the layout looks like. The script builds a valid minimal.rsrc.py file to be used with a copy of the minimal.py script. The HyperCard stack info title, position, size (the height has 20 added to it to make up for the title bar height in HC). Only a single background is processed and only the background fields are exported, so there are no background buttons, card buttons or fields, etc. Once we start doing actual data storage as part of the framework, I'll add the function to iterate through all the cards of a background and dump the data to a nested dictionary for importing into PythonCard; it is easy to do, just a bit premature this early in the life of the prototype. I put a breakpoint at the end of the exportToPythonCard routine so that I could copy the sInfo variable to the clipboard and then paste it into a text file with DOS line endings before moving it over to my machine. That's why there isn't code for writing the file included below, though it is certainly easy to add. There are quite a few utility scripts on the web that will export stack data and stack descriptions. It probably makes more sense to simply read the output from one of those utilities and convert to our own format. I'm not talking about translating the HyperTalk to Python, only the layout and data of the stack. Anyway, this is a good project for a Mac HyperCard user/developer to tackle while they're waiting on wxPython to get ported to the Mac. Feel free to dive in. ka ---- the script I put in the stack script of Addresses on exportToPythonCard put stackInfo() into sInfo put backgroundInfo() after sInfo put "] }" & return & "] }" & return & "}" & return after sInfo -- write results to a 'export.rsrc.py' file -- loop through the cards of the background and export -- the data to a dictionary end exportToPythonCard function stackInfo put "{'stack'}" into bob put "{'stack':{'type':'Stack'," & return into s put "'name':'" & the short name of this stack & "'," & return after s put "'title':'" & the short name of this stack & "'," & return after s put "'position':(" after s put the topLeft of card window & "), " & return after s put "'size':(" after s put the width of this card & ", " after s put (the height of this card) + 20 & ")," & return after s put "'backgrounds':" & return & "[" & return after s return s end stackInfo function backgroundInfo put "{'type':'Background'," & return into s put "'file':'minimal.py'," & return after s put "'classname':'Minimal'," & return after s put "'name':'bgMin'," & return after s put "'components':" & return & "[" & return after s repeat with i = 1 to the number of flds put fldDescription(i) after s end repeat return s end backgroundInfo function fldDescription i -- determine the field type put fldType(i) into fieldType if fieldType = "StaticText" then put "'text':'" & the value of bg fld i & "', " & return into textStr put "'alignment':'" & the textAlign of bg fld i & "', " & return after textStr else if the sharedText of bg fld i then put "'text':'" & the value of bg fld i & "', " & return into textStr else put "" into textStr end if -- this doesn't look all that great, so I commented it out -- if the style of bg fld i = "transparent" then -- put "'border':'none', " & return after textStr -- end if end if -- then build up the attributes appropriately put "{'type':'" & fieldType & "', 'name':'" & fldName(i) & "'," & return into s put "'position':(" & the topLeft of bg fld i & "), " & return after s put "'size':(" & the width of bg fld i & ", " after s put the height of bg fld i & "), " & return after s put textStr after s if fldVisible(i) = 0 then put "'visible':0, " & return after s end if put "}, " & return after s return s end fldDescription function fldName i return the short name of bg fld i end fldName function fldType i if the sharedText of bg fld i then -- maybe look at lockText as well? if the textAlign of bg fld i = "left" then return "TextField" else return "StaticText" end if else if the dontWrap of bg fld i then return "TextField" else -- should probably check the return "TextArea" end if end fldType function fldVisible i if the visible of bg fld i then return 1 else return 0 end if end fldVisible ---- the resulting minimal.rsrc.py file {'stack':{'type':'Stack', 'name':'Addresses', 'title':'Addresses', 'position':(208,183), 'size':(416, 276), 'backgrounds': [ {'type':'Background', 'file':'minimal.py', 'classname':'Minimal', 'name':'bgMin', 'components': [ {'type':'TextField', 'name':'Name', 'position':(100,17), 'size':(241, 24), }, {'type':'TextField', 'name':'Company', 'position':(100,39), 'size':(241, 23), }, {'type':'TextField', 'name':'Street', 'position':(100,72), 'size':(183, 23), }, {'type':'TextField', 'name':'City', 'position':(100,94), 'size':(183, 23), }, {'type':'TextField', 'name':'State', 'position':(100,116), 'size':(183, 23), }, {'type':'TextField', 'name':'Zip', 'position':(100,138), 'size':(183, 23), }, {'type':'TextField', 'name':'Phone 1', 'position':(114,176), 'size':(169, 17), }, {'type':'TextField', 'name':'Phone 2', 'position':(114,192), 'size':(169, 17), }, {'type':'TextField', 'name':'Phone 3', 'position':(114,208), 'size':(169, 17), }, {'type':'TextField', 'name':'Phone 4', 'position':(114,224), 'size':(169, 17), }, {'type':'StaticText', 'name':'Name Label', 'position':(7,24), 'size':(68, 16), 'text':'Name', 'alignment':'right', }, {'type':'StaticText', 'name':'Company Label', 'position':(7,46), 'size':(68, 16), 'text':'Company', 'alignment':'right', }, {'type':'StaticText', 'name':'Street Label', 'position':(8,79), 'size':(68, 16), 'text':'Street', 'alignment':'right', }, {'type':'StaticText', 'name':'City Label', 'position':(8,101), 'size':(68, 16), 'text':'City', 'alignment':'right', }, {'type':'StaticText', 'name':'Zip Code Label', 'position':(8,145), 'size':(68, 16), 'text':'Zip Code', 'alignment':'right', }, {'type':'StaticText', 'name':'Telephone Label', 'position':(7,180), 'size':(68, 16), 'text':'Telephone', 'alignment':'right', }, {'type':'TextField', 'name':'Sort order', 'position':(0,0), 'size':(30, 19), 'text':'1', 'visible':0, }, {'type':'TextField', 'name':'Name Order', 'position':(141,0), 'size':(73, 19), 'text':'last word', 'visible':0, }, {'type':'StaticText', 'name':'State Label', 'position':(8,123), 'size':(68, 16), 'text':'State', 'alignment':'right', }, {'type':'TextArea', 'name':'Notes', 'position':(7,64), 'size':(278, 183), 'visible':0, }, {'type':'TextField', 'name':'Correct Name', 'position':(100,0), 'size':(241, 24), 'visible':0, }, ] } ] } } |