wxGlade and __init__

Discussion in 'Python' started by crystalattice, Aug 26, 2006.

  1. 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
    crystalattice, Aug 26, 2006
    #1
    1. Advertising

  2. 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
    Tim N. van der Leeuw, Aug 26, 2006
    #2
    1. Advertising

  3. 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.
    crystalattice, Aug 27, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. http://www.stani.be
    Replies:
    0
    Views:
    346
    http://www.stani.be
    Feb 6, 2005
  2. Steven Bethard
    Replies:
    2
    Views:
    456
    Steven Bethard
    Feb 16, 2005
  3. Replies:
    0
    Views:
    410
  4. Kent Johnson
    Replies:
    7
    Views:
    914
    Jan Niklas Fingerle
    Feb 12, 2006
  5. Ramchandra Apte
    Replies:
    17
    Views:
    338
    Manuel Pégourié-Gonnard
    Sep 30, 2012
Loading...

Share This Page