Splitting MainWindow Class over several modules.

Iain King iainking at gmail.com
Wed Apr 16 17:47:05 CEST 2008


Until recently almost all my python programs were held 1 file for 1
program.  This had grown unwieldy for one of my projects, so i decided
to refactor it, and ended up with something like this:

---

import wx

import options
import gui
import scf

class MainWindow(wx.Frame):
	def __init__(self):
		self.title = "SFtools v%s" % VERSION
		wx.Frame.__init__(self, None, wx.ID_ANY, self.title, size=(800,600))
		self.SetMinSize((800,600))

	readOptions  = options.readOptions
	writeOptions = options.writeOptions

	createBindings      = gui.createBindings
	createControls      = gui.createControls
	createMenus         = gui.createMenus
	reportError         = gui.reportError

	loadSCF               = scf.loadSCF
	onOpen                = scf.onOpen
	reloadSCF             = scf.reloadSCF
	setMenuMode           = scf.setMenuMode
	unloadSCF             = scf.unloadSCF

---

Now, this works fine.  I like how it reads and that everything being
imported can be clearly seen.  I have this funny feeling though, that
this isn't the standard way of doing this.  What is?  And is there
anything about doing it this way which could be detrimental?

Iain



More information about the Python-list mailing list