From: Kevin A. <al...@se...> - 2004-11-10 18:35:28
|
On Nov 9, 2004, at 8:30 PM, Chad Crabtree wrote: > I am making a new component that I have figured out from looking at > the > source and stuff and resolving error messages as they come. However > I'm > having a difficulty. I am not able to get the resource to save the > size > but I cannot figure out why because I have the Spec set up right from > > what I understand. > > class ScrolledImageSpec(widget.WidgetSpec): > def __init__( self ) : > events = [] > attributes = { > 'file':{'presence':'optional','default':None}, > 'size' : { 'presence' : 'optional', 'default' : [ 50, 50 > ] } > } > widget.WidgetSpec.__init__( self, 'ScrolledImage', 'Widget' , > > events, attributes ) > > I do not see that I must implement a method to get this to work. But > > perhaps I'm wrong. > The problem is almost certainly the following bit of code. In order to avoid saving explicit attribute values that are actually defaults and might be different on other platforms (e.g. height of a TextField), the resourceOutput code does a lot of special-casing for particular attributes like size. You will probably have to add your component to the list below. Ideally, the component would be able to return the appropriate size, so what we probably need is a special method that would return -1 values when appropriate. So, maybe a getDefaultSize (or getBestSize) method can be added to the base Widget class and components such as yours, BitmapCanvas, etc. would override that so this special-case code can go away. For now, you'll have to just patch your own copy of resourceOutput.py # resourceEditor/modules/resourceOutput.py, line 48 # try and determine default sizes width, height = aWidget.size if aWidget.__class__.__name__ in imgWidgets: width, height = aWidget._size elif aWidget.__class__.__name__ not in ['BitmapCanvas', 'HtmlWindow', 'IEHtmlWindow', 'Gauge', 'StaticBox']: bestWidth, bestHeight = aWidget.GetBestSize() if bestWidth == width: width = -1 if bestHeight == height: height = -1 if width != -1 or height != -1: dStr += " 'size':(%d, %d), \n" % (width, height) ka |