From: Kevin A. <al...@se...> - 2001-08-22 02:45:13
|
> From: Ronald D Stephens [mailto:rd...@ea...] ... > modify, at this vey early stage, and get "results". But when I rename the > two files (minimal.py and minimal.rsrc) I get error > messages. Just in case, make sure the file is named 'minimal.rsrc.py', not 'minimal.rsrc'; you need the trailing .py extension. If that isn't the problem, you can include both files in a post to the list and we'll debug from there. > In working my way through the various error messages, I learn and fix some > things,. But I have one question that I woudl apprecite > help on: > > In the backgrounds section of the rsrc files (I am looking at most of the > sample rscr files or all of them) , I do not yet > understnad where the 'name': comes from, as in bgWidgets in the following > code snippet; > > 'backgrounds': > [ > {'type':'Background', > 'file':'test_widgets.py', > 'classname':'WidgetsTest', > 'name':'bgWidgets', <= <=<=<=<= > #'image':'tile.bmp', > #'tiled':1, > 'components': > > I do not understand where bgWidgets comes from , and also the > anologous name > under resource file backgrounds of the other samples. I > think if I could understand this I might be able to fix my problems and > create successfully renamed files that allow me to claim a > "significant" ;-))) > (bear with me OK ) first newbie PythonCard "program". This to me > would be a > stunning breakthrough. All components in PythonCard require a unique 'name' along with a 'type' (type really means a Python class), so there is a 'name' for all the widgets (components) in the Background as well as the 'Background' itself, the 'Stack', each 'Menu' and 'MenuItem'. The exception is the 'MenuBar', but that is actually a bug that will be fixed when we add support for multiple menubars that you can switch between. The spec.py file defines the optional and required elements used in the .rsrc.py files and is used to validate the contents when your application starts up. The 'name' item for the 'Background' becomes important when you write background handlers that can deal with events for multiple widgets. The tictactoe sample shows this usage. The background 'name' is 'bg1' and the handler in the tic.py file does the work for all nine ImageButtons. The script for btn0 was left in the code just to show that you can mix a background handler and specific widget handler in the same script. --- from tic.rsrc.py { 'type':'Background', 'file':'tic.py', 'classname':'Tic', 'name':'bg1', 'image':'lines.jpg', --- from tic.py def on_bg1_mouseClick(self, button, event): # make sure that we only handle a mouseClick for # the ImageButtons on the playfield if self.playfieldButton(button): print "bg1 mouseClick handler" btnName = button.name pos = int(btnName[3]) #print button.getName(), 'clicked' if self.legalMove(btnName): self.board[pos] = self.human self.setButtonImage(btnName, self.humanImage) self.doComputerMove() else: print "illegal move" When an mouseClick event is generated, PythonCard first looks to see if there is a handler for the target (widget) that generated the event and if so, it calls that method. If it doesn't find a method for the target, it then looks for a handler matching the parent (bg1 in the case above), and then the next parent and so on. > Anyway, I am sufficiently "hooked" to keep at it in my "spare" time. Great! > I am really looking forward to a visual gui layout tool, but I can wait; I > am enjoying studying the Python code of this project! Even if you are looking at the .rsrc.py files, you should still give the resourceEditor a try. In a few days you should be able to use it for most of your layout needs. > I think I will also post about the availability of this project on Byte > magazine's John Udell online forum, unless Kevin objects. I > just discovered this forum and lots of folks there are interested in this > sort of thing, and Python is often intelligently > disucussed. Also great! The more people, the merrier. ka |