Accessing wx.TextCtrl after refactoring

Discussion in 'Python' started by alex, Mar 27, 2009.

  1. alex

    alex Guest

    Hi all
    I am working on a Dialog window for a gui in wxPython and started
    refactoring it, below code is a simplified version of it.
    "def createInput1" should create a static text, a button and a
    textcontrol using the information in "def box1Labels".
    "def makeStaticBox1" then arranges all widgets in staticbox1.

    My problem is that it works fine for the static text and the button
    label but I cant "rename" self.txtctrl that it
    becomes self.txtctrl_inpath or self.txtctrl_outpath for getting the
    path from either "def BrowseInDlg" or "def BrowseOutDlg".

    I must admit that I am still a beginner but searching through my books
    does not get me further. I like the idea of refactoring for
    "automatising" widgets creation instead of hardcoding each widgetID.
    But I am completely stuck here. Maybe can somebody help?

    Coming from the Fortran world my programming style may be quite
    "fortranic" instead of being "pythonic" but I am trying to improve and
    enjoy what I learned so far...

    Thanks Alex



    #
    #
    #!/usr/bin/env python
    #
    #
    """Add Python docs string"""
    import wx
    import os
    #
    #
    class Dialog1(wx.Dialog):
    def __init__(self):
    wx.Dialog.__init__(self, None, -1, "Test", size=(500, 600))
    self.makeStaticBox1()
    self.makeSizer()


    def box1Labels(self):
    return (("Label1:", "Browse", self.BrowseInDlg,
    txtctrl_inpath),
    ("Label2:", "Browse", self.BrowseOutDlg,
    txtctrl_outpath))


    def makeStaticBox1(self):
    box1 = wx.StaticBox(self, -1, "Box1")
    pathFlexGridSizer = wx.FlexGridSizer(4, 0, 0, 0)
    pathFlexGridSizer.AddGrowableCol(1)

    for label, pth_btn_label, btn_funct, txtctrl_path in
    self.box1Labels():
    self.createInput1(label, pth_btn_label, txtctrl_path)

    pathFlexGridSizer.Add(self.stattxt, 0,
    wx.ALIGN_CENTER_VERTICAL|wx.TOP|wx.BOTTOM, 2)
    pathFlexGridSizer.Add((10, 10))
    pathFlexGridSizer.Add(self.pth_Btn, 0, wx.ALIGN_LEFT)
    pathFlexGridSizer.Add(self.txtctrl, 0, wx.ALIGN_RIGHT|
    wx.TOP|wx.BOTTOM, 2)
    self.Bind(wx.EVT_BUTTON, btn_funct, self.pth_Btn)


    self.path_sizer = wx.StaticBoxSizer(box1, wx.VERTICAL)
    self.path_sizer.Add(pathFlexGridSizer, 2, wx.ALL|wx.EXPAND, 0)


    def createInput1(self, label, pth_btn_label, txtctrl_path):
    self.stattxt=wx.StaticText(self, -1, label)
    self.pth_Btn = wx.Button(self, -1, pth_btn_label)
    self.txtctrl=wx.TextCtrl(self, -1, "", size=(300, -1))




    def makeSizer(self):
    GridSizer = wx.BoxSizer(wx.VERTICAL)
    GridSizer.Add(self.path_sizer, 1, wx.ALL|wx.EXPAND, 2)


    self.SetSizer(GridSizer)
    self.Fit()
    self.Centre()
    self.Show(True)


    def BrowseInDlg(self, event):
    #
    dialog = wx.DirDialog(None, "Choose directory:",
    style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
    if dialog.ShowModal() == wx.ID_OK:
    inpath=dialog.GetPath()
    self.txtctrl_inpath.SetValue(inpath)
    print inpath
    dialog.Destroy()


    def BrowseOutDlg(self, event):
    #
    dialog = wx.DirDialog(None, "Choose directory:",
    style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
    if dialog.ShowModal() == wx.ID_OK:
    outpath=dialog.GetPath()
    self.txtctrl_outpath.SetValue(outpath)
    print outpath
    dialog.Destroy()
    alex, Mar 27, 2009
    #1
    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. newgene
    Replies:
    0
    Views:
    841
    newgene
    Jul 28, 2003
  2. Logan
    Replies:
    3
    Views:
    445
    Edward K. Ream
    Dec 2, 2003
  3. Hako
    Replies:
    6
    Views:
    3,700
    Frank Millman
    Jan 20, 2006
  4. Simon Hibbs

    TextCtrl focus events in wxWidgets

    Simon Hibbs, Jul 19, 2006, in forum: Python
    Replies:
    12
    Views:
    13,869
    Frank Millman
    Jul 19, 2006
  5. abcd
    Replies:
    10
    Views:
    747
    Peter Decker
    Nov 1, 2006
Loading...

Share This Page