Author: Date: Subject:
Steve Freedenburg
2008-07-20 23:10:57
[wxpython-users] DRY question.
I'm trying use the DRY concept in some code...
It looks like the code works, but I don't think it's really going to work. There is alot of code not put in there
yet, like the methods for dialogs, text controls and stuff...
<CODE>
for i in range(1,7):
self.ContainerP = wx.Panel(self, -1)
self.ContainerSBS = wx.StaticBoxSizer(wx.StaticBox(self.ContainerP, -1, 'Container %i:'%i), wx.VERTICAL)
self.ContainerBorder = wx.BoxSizer()
self.ContainerBorder.Add(self.ContainerSBS, 1, wx.EXPAND | wx.ALL, 2)
self.ContainerP.SetSizer(self.ContainerBorder)
self.CDBS.Add(self.ContainerP, 0, wx.EXPAND)
self.Fit()
</CODE>
This code does in fact put 6 static box sizers on the frame. And it changes the label of each static box
sizer from Contianer 1 to Contianer 6.
Is there a way to put the %i in other places other than a string like I put in the label for the static box sizer?
For example:
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...
That way everything has it's on identity, so there will be a Container1P, and a Container2P etc. For everything.
My thinking is if I can use more DRY, and do things that you guys would do, then when I'm done I'll run
Py2Exe and the gods will be happy, and the EXE will work.
Thanks,
Steve
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16674" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I'm trying use the DRY concept in some
code...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>It looks like the code works, but I don't think
it's really going to work. There is alot of code not put in
there</FONT></DIV>
<DIV><FONT face=Arial size=2>yet, like the methods for dialogs, text controls
and stuff... </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><CODE></FONT></DIV>
<DIV><FONT face=Arial size=2>for i in range(1,7):</FONT></DIV>
<DIV><FONT face=Arial size=2> self.ContainerP = wx.Panel(self,
-1)<BR> self.ContainerSBS =
wx.StaticBoxSizer(wx.StaticBox(self.ContainerP, -1, 'Container %i:'%i),
wx.VERTICAL)<BR> self.ContainerBorder =
wx.BoxSizer()<BR> self.ContainerBorder.Add(self.ContainerSBS,
1, wx.EXPAND | wx.ALL,
2)<BR> self.ContainerP.SetSizer(self.ContainerBorder)<BR> self.CDBS.Add(self.ContainerP,
0, wx.EXPAND)<BR> self.Fit()</FONT></DIV>
<DIV><FONT face=Arial size=2></CODE></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This code does in fact put 6 static box sizers on
the frame. And it changes the label of each static box</FONT></DIV>
<DIV><FONT face=Arial size=2>sizer from Contianer 1 to Contianer 6.
</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Is there a way to put the %i in other places other
than a string like I put in the label for the static box
sizer?</FONT></DIV>
<DIV><FONT face=Arial size=2>For example:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>self.Container"%i"P = wx.Panel(self,
-1)</FONT></DIV>
<DIV><FONT face=Arial size=2>self.Container%iSBS =
wx.StaticBoxSizer(wx.StaticBox(self.Container%iP, -1, 'Container %i:'%i),
wx.VERTICAL</FONT></DIV>
<DIV><FONT face=Arial size=2>so on and so forth...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>That way everything has it's on identity, so there
will be a Container1P, and a Container2P etc. For
everything.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>My thinking is if I can use more DRY, and do things
that you guys would do, then when I'm done I'll run </FONT></DIV>
<DIV><FONT face=Arial size=2>Py2Exe and the gods will be happy, and the EXE will
work.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks, </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Steve</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Author: Date: Subject:
Cody Precord
2008-07-20 22:28:38
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<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br><div><div>On Jul 20, 2008, at 10:10 PM, Steve Freedenburg wrote:</div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div bgcolor="#ffffff"><div><span class="Apple-style-span" style="color: rgb(20, 79, 174); -webkit-text-stroke-width: -1; "></span></div></div></span></blockquote><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div bgcolor="#ffffff"><div><span class="Apple-style-span" style="color: rgb(20, 79, 174); -webkit-text-stroke-width: -1; "> </span></div><div><font face="Arial" size="2">self.Container"%i"P = wx.Panel(self, -1)</font></div><div><font face="Arial" size="2">self.Container%iSBS = wx.StaticBoxSizer(wx.StaticBox(self.Container%iP, -1, 'Container %i:'%i), wx.VERTICAL</font></div><div><font face="Arial" size="2">so on and so forth...</font></div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2"></font></div></div></span></blockquote><br></div><div>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.</div><div><br></div><div>for i in range(1, 7):</div><div> setattr(self, "Container%iP" % i, wx.Panel(self, -1))</div><div> ...</div><div><br></div><div><br></div><div>Cody</div></div></body></html>_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Author: Date: Subject:
Steve Freedenburg
2008-07-21 00:24:26
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
To: [email protected]
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
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16674" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"
bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Cody</FONT></DIV>
<DIV><FONT face=Arial size=2>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</FONT></DIV>
<DIV><FONT face=Arial size=2>what to google to find out.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks for the help</FONT></DIV>
<DIV><FONT face=Arial size=2>Steve</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=codyprecord@gmail.com href="mailto:codyprecord@gmail.com">Cody
Precord</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
title=wxpython-users@lists.wxwidgets.org
href="mailto:wxpython-users@lists.wxwidgets.org">wxpython-users@lists.wxwidgets.org</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, 20 July, 2008 23:28</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [wxpython-users] DRY
question.</DIV>
<DIV><BR></DIV>Hello,
<DIV><BR>
<DIV>
<DIV>On Jul 20, 2008, at 10:10 PM, Steve Freedenburg wrote:</DIV>
<BLOCKQUOTE type="cite"><SPAN class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">
<DIV bgcolor="#ffffff">
<DIV><SPAN class=Apple-style-span
style="COLOR: rgb(20,79,174); -webkit-text-stroke-width: -1"></SPAN></DIV></DIV></SPAN></BLOCKQUOTE><BR>
<BLOCKQUOTE type="cite"><SPAN class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">
<DIV bgcolor="#ffffff">
<DIV><SPAN class=Apple-style-span
style="COLOR: rgb(20,79,174); -webkit-text-stroke-width: -1"></SPAN> </DIV>
<DIV><FONT face=Arial size=2>self.Container"%i"P = wx.Panel(self,
-1)</FONT></DIV>
<DIV><FONT face=Arial size=2>self.Container%iSBS =
wx.StaticBoxSizer(wx.StaticBox(self.Container%iP, -1, 'Container %i:'%i),
wx.VERTICAL</FONT></DIV>
<DIV><FONT face=Arial size=2>so on and so forth...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT></DIV></DIV></SPAN></BLOCKQUOTE><BR></DIV>
<DIV>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.</DIV>
<DIV><BR></DIV>
<DIV>for i in range(1, 7):</DIV>
<DIV> setattr(self, "Container%iP" % i, wx.Panel(self,
-1))</DIV>
<DIV> ...</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>Cody</DIV></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>wxpython-users
mailing
list<BR>wxpython-users@lists.wxwidgets.org<BR> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users<BR></BLOCKQUOTE></BODY></HTML>
_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
|