473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Splitting MainWindow Class over several modules.

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
Jun 27 '08 #1
2 999
On Apr 16, 10:47 am, Iain King <iaink...@gmail.comwrote:
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
I don't think there's anything wrong with it. The main thing to
remember is to try to keep the interface and the logic separate. I
have a fairly complex program with lots of tabs and sub tabs. So I
stuck each of the tab's display code in a separate file and imported
them into my main program.

One good place to learn from would be the wxPython demo. See how Dunn
et al did it with that. Or check out Editra's source. I know there's a
few wxPython-istas that love XRC for the GUI layout stuff, so that's
an option too. I don't use it myself as I couldn't figure out how to
implement some of the widgets with it.

Mike
Jun 27 '08 #2
On Behalf Of Mike Driscoll
I don't think there's anything wrong with it. The main thing
to remember is to try to keep the interface and the logic
separate. I have a fairly complex program with lots of tabs
and sub tabs. So I stuck each of the tab's display code in a
separate file and imported them into my main program.
There are also several signaling techniques that make it easy to separate
the GUI logic from the message-processing logic. Or you could simply have a
controller class that instantiates the GUI class and registers itself as the
message listener.

Regards,
Ryan Ginstrom

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias Pfeiffer | last post by:
Hi! I want to write a package of modules that deal with mathematical graphs. So my plan is to have a main.py file where the basic operations are done, like reading the file and creating an...
2
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
8
by: M O J O | last post by:
Hi, I'm creating an CRM solution for my company. I want to split up the solution into several classlibraries, so I dont need to build the entire solution every time I run my project. First...
0
by: Metal2You | last post by:
I have several modules that each have several of their own Crystal reports. When I compile these modules as Windows Applications the reports work fine. When I compile the modules as Class...
5
by: Shaun Pudwell | last post by:
Hi, I'm new to c# and come from a C / C++ background. My MainWindow class has a function called DrawChart. I open an MDI Child Window and want it to make a call from its class MDIChild to...
1
by: Nelson Smith | last post by:
I have created a web based application using .net frame work 1.1. It has several modules (I mean screens). Some of the screens are used by shipping department; some of them are used by purchase...
3
by: Corobori | last post by:
I developed a vb.net application which has about 90 forms an 70 reports. I have got the following question: my customer asked me to split up my application in several application. One containing...
0
by: Marcus | last post by:
How can I access the windows that are not the current mainwindow. For instance with Internet Explorer (iexplore) one can create several browser windows within the same "instance" of iexplore. I...
0
by: Phil Thompson | last post by:
On Sunday 04 May 2008, Lance Gamet wrote: I think QMainWindow.setCentralWidget() is what you are looking for. The eric4 IDE probably covers most things you'll ever need. Phil
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.