Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Accessing wx.TextCtrl after refactoring

Reply
Thread Tools

Accessing wx.TextCtrl after refactoring

 
 
alex
Guest
Posts: n/a
 
      03-27-2009
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()




 
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
Refactoring test units after an extract method Virgil Dupras Python 0 06-05-2007 11:29 AM
What does "refactoring" of a project mean ? Anan H. Samiti Java 33 07-30-2004 08:07 PM
Odd Multi-thread behavior when refactoring Christian Bongiorno Java 1 06-22-2004 07:46 AM
Survey on refactoring activities using IDEs Sebastian Jekutsch Java 5 06-09-2004 06:15 AM
come learn all about refactoring Refactorit Java 0 02-22-2004 06:36 PM



Advertisments