This may not make sense to anyone here, it’s late, and I’m really just using this as a sounding board for myself…
I spent some time reading the thread “problem with mass controls” which is similar to my own question. In my situation, trying
to follow “DRY” I have 6 panels, 12 box sizers, 18 static box sizers, 18 buttsons, 6 methods for 6 of the buttons, setting 6 sizers
and maybe even some stuff I forgot. I’m not finding any examples on setattr that will let me set attributes for all these widgets.
Here is new question on the same subject. The amount of dictionary keys, and multiple values probably isn’t assounding.
‘Panels’:[‘Container1P’, ‘Container2P’ …], ‘NextKey’:[‘val1’, ‘val2’] etc etc… and I think 2 for loops, and quite a bit of thinking
(atleast for me to wrap my mind around it all.)
When does the "need’ to write code in contortionist ways utilizing the “Don’t Repeat Yourself” priciple get outwayed by simple
cut / paste?
I think that the dictionairy keys/values may STILL be the way to go, because repeating 50+ lines of code per “container config”
multiplied by 6 would be work writing 1 time, and using a dictionairy to define it, and I even think it’s scalable… Maybe.
change the range, and add new values to the respective keys.
Say Panels for example… I’m not sure how it all is constructed, but from what I read, and what you guys have said to me already
I think it can be done. Panels for example:
The dictionary’s first key is for the wxPanels reference. as in “abc = wx.Panel(self, -1)”, “def = wx.Panel(self, -1)”, “ghi = wx.Panel(self, -1)”
etc. I think i’d have to throw in some box sizers though… but i think it’s doable…
···
----- Original Message -----
From:
Steve Freedenburg
Sent: Monday, 21 July, 2008 00:24
Subject: Re: [wxpython-users] DRY question.
Cody
I’ll research the setattr construction more. I knew my way was wrong, it didn’t work when I tried it, but didn’t know
what to google to find out.
Thanks for the help
Steve
----- Original Message -----
From:
Cody Precord
Sent: Sunday, 20 July, 2008 23:28
Subject: Re: [wxpython-users] DRY question.
Hello,
On Jul 20, 2008, at 10:10 PM, Steve Freedenburg wrote:
self.Container"%i"P = wx.Panel(self, -1)
self.Container%iSBS = wx.StaticBoxSizer(wx.StaticBox(self.Container%iP, -1, 'Container %i:'%i), wx.VERTICAL
so on and so forth…
No, this is incorrect syntax. Format statements only work with strings. If you want to do something like this you can do it in the following manner.
for i in range(1, 7):
setattr(self, "Container%iP" % i, wx.Panel(self, -1))
…
Cody
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users