Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > wxGlade and __init__

Reply
Thread Tools

wxGlade and __init__

 
 
crystalattice
Guest
Posts: n/a
 
      08-26-2006
I'm making a GUI for a console-based program I just wrote. I figured
it would be mostly straight forward to convert it over in wxPython but
now I'm confused.

In my console program, I have __init__ making the dictionaries et al.
and then my methods will populate them. However, when I use wxGlade
under SPE to make the GUI, wxGlade makes it's own __init__. I know not
to add anything to this section because it's written over everytime I
make changes in wxGlade.

How do I reconcile having the auto created __init__ from wxGlade and
the __init__ I want to use from my console version?

Here's an example of my console program:

def __init__(self):
"""Constructor to initialize each data member to zero."""

#---Attribute info
self.attrib = 0
self.attrib_dict = self.default_attribs.copy() #instance
version
self.setAttribute("str")
self.setAttribute("intel")
self.setAttribute("build")
self.setAttribute("char")
self.setAttribute("will")
self.setAttribute("throw")
self.setAttribute("mass")
self.setAttribute("load")
self.setAttribute("dex")
self.coreInitiative = 0

#---Create attributes---
def setAttribute(self, attr):
"""Generate value for an attribute, between 2 and 20."""

#---Get secondary attributes
if attr == "throw":
self.attrib_dict[attr] = self.attrib_dict["str"] * 2
#meters
elif attr == "mass":
self.attrib_dict[attr] = (self.attrib_dict["build"] * 5) +
15 #kg
elif attr == "load":
self.attrib_dict[attr] = (self.attrib_dict["str"] +
self.attrib_dict["build"]) #kg
#---Get core attributes
else:
self.attrib_dict[attr] = multiDie(2, 2) #2d10

Here's the code created by wxGlade:

class Attributes(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: Attributes.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_2 = wx.Panel(self, -1)
self.btnAttributes = wx.Button(self.panel_2, -1, "Get
Attributes")
self.lblAge = wx.StaticText(self.panel_2, -1, "Age:")
self.txtAge = wx.TextCtrl(self.panel_2, -1, "")
self.lblChar = wx.StaticText(self.panel_2, -1, "Charisma:")
self.txtChar = wx.TextCtrl(self.panel_2, -1, "")
self.lblStr = wx.StaticText(self.panel_2, -1, "Strength:")
self.txtStr = wx.TextCtrl(self.panel_2, -1, "")
self.lblBuild = wx.StaticText(self.panel_2, -1, "Build:")
self.txtBuild = wx.TextCtrl(self.panel_2, -1, "")
self.lblIntel = wx.StaticText(self.panel_2, -1,
"Intelligence:")
self.txtIntel = wx.TextCtrl(self.panel_2, -1, "")
self.lblThrow = wx.StaticText(self.panel_2, -1, "Throw Range:")
self.txtThrow = wx.TextCtrl(self.panel_2, -1, "")
self.lblWill = wx.StaticText(self.panel_2, -1, "Willpower:")
self.txtWill = wx.TextCtrl(self.panel_2, -1, "")
self.lblMass = wx.StaticText(self.panel_2, -1, "Mass:")
self.txtMass = wx.TextCtrl(self.panel_2, -1, "")
self.lblDex = wx.StaticText(self.panel_2, -1, "Dexterity:")
self.txtDex = wx.TextCtrl(self.panel_2, -1, "")
self.lblLoad = wx.StaticText(self.panel_2, -1, "Load:")
self.txtLoad = wx.TextCtrl(self.panel_2, -1, "")
self.lblHP = wx.StaticText(self.panel_2, -1, "Hit Points")
self.lblHead = wx.StaticText(self.panel_2, -1, "Head:")
self.txtHead = wx.TextCtrl(self.panel_2, -1, "")
self.lblTorso = wx.StaticText(self.panel_2, -1, "Torso:")
self.txtTorso = wx.TextCtrl(self.panel_2, -1, "")
self.lblRArm = wx.StaticText(self.panel_2, -1, "Right Arm:")
self.txtRArm = wx.TextCtrl(self.panel_2, -1, "")
self.lblLArm = wx.StaticText(self.panel_2, -1, "Left Arm:")
self.txtLArm = wx.TextCtrl(self.panel_2, -1, "")
self.lblRLeg = wx.StaticText(self.panel_2, -1, "Right Leg:")
self.txtRLeg = wx.TextCtrl(self.panel_2, -1, "")
self.lblLLeg = wx.StaticText(self.panel_2, -1, "Left Leg:")
self.text_ctrl_18 = wx.TextCtrl(self.panel_2, -1, "")
self.btnNext2 = wx.Button(self.panel_2, -1, "Next Page")

self.__set_properties()
self.__do_layout()
# end wxGlade

 
Reply With Quote
 
 
 
 
Tim N. van der Leeuw
Guest
Posts: n/a
 
      08-26-2006

crystalattice wrote:
> I'm making a GUI for a console-based program I just wrote. I figured
> it would be mostly straight forward to convert it over in wxPython but
> now I'm confused.
>


Hi Crystalattice,

One thing you could do is make your original console-program a subclass
of the wxGlade-generated GUI.

Another thing you could do is to keep the original console program code
intact, and to make the GUI program create an instance of your original
console program, and call it.

You can modify to some extent the code generated by wxGlade, or you can
subclass it (which is what I do, following advice found on this list).

Good luck,

--Tim

 
Reply With Quote
 
 
 
 
crystalattice
Guest
Posts: n/a
 
      08-27-2006
Tim N. van der Leeuw wrote:
> crystalattice wrote:
> > I'm making a GUI for a console-based program I just wrote. I figured
> > it would be mostly straight forward to convert it over in wxPython but
> > now I'm confused.
> >

>
> Hi Crystalattice,
>
> One thing you could do is make your original console-program a subclass
> of the wxGlade-generated GUI.
>
> Another thing you could do is to keep the original console program code
> intact, and to make the GUI program create an instance of your original
> console program, and call it.
>
> You can modify to some extent the code generated by wxGlade, or you can
> subclass it (which is what I do, following advice found on this list).
>
> Good luck,
>
> --Tim


I think I get it. I'll mess with it and see what happens. Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Should one always add super().__init__() to the __init__? Ramchandra Apte Python 17 09-30-2012 12:04 PM
super(...).__init__() vs Base.__init__(self) Kent Johnson Python 7 02-12-2006 08:59 PM
ANN: SPE 0.7.3.a Python IDE with wxGlade, Blender and PyChecker support s_t_a_n_i@gmx.net Python 0 03-24-2005 12:30 AM
__new__ does not call __init__ as described in descrintro.html (WAS:Can __new__ prevent __init__ from being called?) Steven Bethard Python 2 02-16-2005 06:50 AM
ANN: SPE 0.7.2.A IDE with uml, wxGlade and blender support http://www.stani.be Python 0 02-06-2005 03:01 AM



Advertisments