|
From: Kevin A. <al...@se...> - 2001-08-23 17:39:07
|
The resourceEditor is now dumping the full attribute list for each widget.
The code is below.
The problem I have is a generic Python problem that I need an answer to in
order to finish the method. I'm adding string attributes like so:
dStr += " '%s':'%s', \n" % (key, value)
This doesn't escape the string, so if you have a single quote, newline, tab,
etc. in the string then the output isn't going to be correct. I thought
there was a general string escape method, but I'm not finding it. I can
write my own to parse the string and put in \n \t \xhh for hex... but there
has to be a routine that already does this for me in the standard libraries.
Pointers please.
BTW, I'm not super happy with this attribute listing. It doesn't deal with
defaults, such as using -1 for the x, y position or width, height size...
I'm having a mental block and am not sure how to suppress the defaults
correctly, so that if the widget is using a default value as defined in
spec.py, then it is not output in the listing. Yet another reason you have
to hand tweak the output, sigh.
Finally, the resourceEditor in cvs now forces the Property Editor to be
visible when the app starts up, and I added a Help menu and an About menu
item.
ka
---
def widgetAttributes(self, widget):
# make sure these primary attributes show up
# at the beginning of the listing
# the remaining ones will be in alphabetical order
dStr = "{'type':'%s', \n" % widget.__class__.__name__
dStr += " 'name':'%s', \n" % widget.name
dStr += " 'position':%s, \n" % getattr(widget, 'position')
dStr += " 'size':%s, \n" % getattr(widget, 'size')
for key in widget._getAttributeNames():
if key in ['bitmap', 'name', 'position', 'size', 'toolTip']:
pass
elif getattr(widget, key) != None:
value = getattr(widget, key)
if type(value) == types.StringType:
# need to escape strings
dStr += " '%s':'%s', \n" % (key, value)
else:
if key in ['editable', 'enabled', 'visible'] and value
== 1:
# don't include default values
pass
else:
dStr += " '%s':%s, \n" % (key, value)
dStr += ' },\n'
return dStr
|