Refactoring question

Kevin Walzer kw at codebykevin.com
Tue Apr 3 20:05:58 EDT 2007


I currently have a GUI application (using Tkinter) in which all the code 
is placed in a single script. This means that the GUI bits are a bit too 
tightly bound to the "under-the-hood" logic of the app. Here's an 
example snippet:

def installPackage(self):

         self.package = self.infotable.getcurselection()
         if not self.package:
             showwarning('Error', 'Please select a package name.')
             return
         else:
             self.packagename = self.package[0][1]
             self.status.set('Installing %s' % self.packagename)
             self.showProgress()
             self.file = os.popen('echo %s | sudo -S /sw/bin/fink -y 
install %s' % (self.passtext, self.packagename), 'r', os.O_NONBLOCK)
             for line in self.file:
                 self.textdisplay.configure(state='normal')
                 self.textdisplay.insert(END, line)
                 self.update()
                 self.textdisplay.see(END)
                 self.textdisplay.configure(state='disabled')
             self.endProgress()
             self.categorytree.selection_set('All')
             self.listCategoryPackages()

I'd like to refactor and separate the GUI code from the back-end code; 
for instance, to move the "self.file = os.popen" bits into a separate 
category. I want to do this so that I can redesign the GUI using another 
toolkit, if I so choose, such as wxPython.

What's the best way to do this? Can anyone point me in the right 
direction? How could, for instance, the top snippet be rewritten to 
separate the Tkinter parts from the generic stuff?

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com



More information about the Python-list mailing list