I'm creating a home-library management program with Python 2.2, PyGTK, and
Glade. While I've been many little programs before, this is my first large
application in Python. My question is how I should organise the OO design
of such a program. There should be, I gather, a core class "MainClass" ,
which coordinates everything, other specialised classes which report to
MainClass, and the GUI should ideally be in its own class "GuiClass".
Now GuiClass at the moment doesn't know anything about MainClass. When the
program is started, an instance "mainClass" is created, which in turn
creates an instance "guiClass". But how can guiClass report anything to
the mainClass? For example, when the user selects a new file in the GUI,
how can I send the chosen pathname to mainClass?
I imagine that I have to initalise the GuiClass instance in such a way
that it knows about mainClass enough to be able to call its methods, but
I've been unable find out how mainClass could pass itself to the GuiClass
__init__.
Be gentle, I'm somewhat of a newbie. If there's documentation out there on
this, I'll happily take a look.
Christopher Culver 3 1740
Christopher Culver schrieb: I'm creating a home-library management program with Python 2.2, PyGTK, and Glade. While I've been many little programs before, this is my first large application in Python. My question is how I should organise the OO design of such a program. There should be, I gather, a core class "MainClass" , which coordinates everything, other specialised classes which report to MainClass, and the GUI should ideally be in its own class "GuiClass".
There is a start up module that will talk to you first, I'd call it
homelib.py. It does the necessary initialisations like loading the
GUI resources, opening the database etc. If you want to encapsulate
this in a class you could call it main or start. I wouldn't give the
feature providing classes generic names like "main". They do something
special, so I would give them names that tell something about their
resonsibilities , e.g. library, libraryItem, book, magazine, storage,
editView, listView etc. Aggregate related classes in a module, related
modules in a package (if you have lots of modules).
The feature modules would be imported by the start up module. It
wouldn't be bad to have a rough plan of your software before you
start to write code. The building blocks (packages, modules) of
your app have "uses" relations. If module a uses b then a has to
import b. A layered approach would probably be helpful:
u | startup, user interface
t |-------------------------------
i | engine (provides the features)
l |-------------------------------
s | storage (file, db, network)
Each layer uses its neighbour below, all layers use utils. The layers
could be distributed across several programs (multi-tiered app) but
that's not necessary, of course.
Mit freundlichen Gruessen,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplu sr.de
-------------------------------------------------------------------
> I'm creating a home-library management program with Python 2.2, PyGTK, and Glade. While I've been many little programs before, this is my first large application in Python. My question is how I should organise the OO design of such a program.
One solution is to use a layered architeture:
.---------------.
| Presentation |
'------+--------'
|
.---------------.
| Application |
'------+--------'
|
.---------------.
| Persistence |
'---------------'
Each layer would be a python package (or multiple
packages if your app is large). The presentation
layer contains your gui classes. The application
layer contains classes that implement the behavior
of the application. The persistence layer handles
storage of your domain objects. Some people would
add a 'domain layer' between the application and
the persistence layer. I suppose that depends on
the size of your project, but for something small
it's overkill and your domain objects are very
likely generated by an oo-rdb mapper tool anyway.
People have differing opinions over whether or not
your gui classes should directly make use of the
domain classes. Technically, layers in this
architecture should not know about layers other
than the immediate one above or below. Java
people like to create structures to pass data
between layers. I think it's not a very good use
of time and prefer to use the domain objects - the
domain should be one thing not changing that much
(a book's a book, right)?
A decent discussion of this architecture is at: http://www.therationaledge.com/conte...tegies_pe.html
The best thing to pull from this is to keep the gui
stuff in its own package python package and put
a little effort into keeping the gui out of
your main application code. This will give you
more options in the future - perhaps you'll find
you'd like a web version of the library, or that
FLTK is a sharper looking gui, or you'd like have
a text reader read the list.
On Tue, 18 Nov 2003 05:16:32 GMT, Christopher Culver
<ch************ *************** ***@yahoo.com> wrote: of such a program. There should be, I gather, a core class "MainClass" , which coordinates everything, other specialised classes which report to MainClass, and the GUI should ideally be in its own class "GuiClass".
That's one solution, it could also be a set of classes - one per
window or "form".
Now GuiClass at the moment doesn't know anything about MainClass. When the program is started, an instance "mainClass" is created, which in turn creates an instance "guiClass". But how can guiClass report anything to the mainClass?
If when you create the guiClass you pass a refernce to mainClass
into the constructor the gui can send messages back to it:
class mainClass:
def __init__(self):
...
self.gui = guiClass(self)
...
class guiClass:
def __init__(self, application):
self.applicatio n = application
...
def someCommand(sel f): # called by a widget somewhere
self.applicatio n.someMethod(se lf.widgetValue)
...
So when the widgets call someCommand it sends the gui
data(widgetValu e) back to the mainClass instance which it stores
in its self.applicatio n member.
You need to define the protocol between the two classes.
There are some fancier variations on this to improve reuse of
Gui elements, do a search on Model View Controller or MVC on
Google for other ideas.
I imagine that I have to initalise the GuiClass instance in such a way that it knows about mainClass enough to be able to call its methods, but I've been unable find out how mainClass could pass itself to the GuiClass __init__.
The self value in the mainClass methods is a reference to the
mainClass instance. Just pass self to the GUI init.
Alan G.
Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Edilmar |
last post by:
Hi,
First of all, I'm new in Python...
I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse,
Borland C++, Perl, etc...
Then, today I think IDEs like Delphi have a excelent environment to develop
apps with little time. I saw many people talking about Python like a easy
lang to learn and to develop. But I have look at IDEs for Python, or ways
|
by: Andrea Griffini |
last post by:
I did it.
I proposed python as the main language for our next CAD/CAM
software because I think that it has all the potential needed
for it. I'm not sure yet if the decision will get through, but
something I'll need in this case is some experience-based set
of rules about how to use python in this context.
For example... is defining readonly attributes in classes
worth the hassle ? Does duck-typing scale well in complex
|
by: Davor |
last post by:
Is it possible to write purely procedural code in Python, or the OO
constructs in both language and supporting libraries have got so
embedded that it's impossible to avoid them? Also, is anyone aware of
any scripting language that could be considered as "Python minus OO
stuff"? (As you can see I'm completely new to Python and initially
believed it's a nice&simple scripting language before seeing all this
OO stuff that was added in over...
|
by: Kenneth McDonald |
last post by:
If this is not an appropriate newsgroup for this type of posting,
please let me know and (if possible) suggest an alternative. I've
done a fair bit of research on the net, but information is scattered
all over the place and I haven't been able to find mailing lists
relating specifically to python and UIs.
I'd like to start using Python for some GUI programming again. I'd
like to use Tk, but it seems to be dying a slow death, so it's...
|
by: zlst |
last post by:
Many technological innovations rely upon User Interface Design to elevate
their technical complexity to a usable product. Technology alone may not win
user acceptance and subsequent marketability. The User Experience, or how
the user experiences the end product, is the key to acceptance. And that is
where User Interface Design enters the design process. While product
engineers focus on the technology, usability specialists focus on the user...
| |
by: Michael Tobis |
last post by:
Someone asked me to write a brief essay regarding the value-add
proposition for Python in the Fortran community. Slightly modified to
remove a few climatology-related specifics, here it is.
I would welcome comments and corrections, and would be happy to
contribute some version of this to the Python website if it is of
interest.
===
|
by: Xah Lee |
last post by:
Python, Lambda, and Guido van Rossum
Xah Lee, 2006-05-05
In this post, i'd like to deconstruct one of Guido's recent blog about
lambda in Python.
In Guido's blog written in 2006-02-10 at
http://www.artima.com/weblogs/viewpost.jsp?thread=147358
|
by: cmk128 |
last post by:
Hi
I am an os developer, i am developing a gui library. I found that
java swing is the most easiest to use gui library , am i correct?
I am trying to port swing to c++, is there any thing i should be
careful?
thanks
from Peter (cmk128@hotmail.com)
|
by: gord |
last post by:
As a complete novice in the study of Python, I am asking myself where this
language is superior or better suited than others. For example, all I see in
the tutorials are lots of examples of list processing, arithmetic
calculations - all in a DOS-like environment.
What is particularly disappointing is the absence of a Windows IDE,
components and an event driven paradigm. How does Python stand relative to
the big 3, namely Visual C++,...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |