473,386 Members | 1,823 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,386 software developers and data experts.

MVC with Python

Hello,

I need some advice on how to implement model-view-controller. I am
trying to develop a GUI application with PyQt, yet the problem rather
applies to mvc in general, not just GUI applications.

Let's say the data is a list of objects with a common base class. The
views are either a graphical representation of the objects or some form
of textual input. The views shall change the model by using command
objects (for undo, e.g. QUndoCommand).

My current approach is to implement the model as a class with a
list-like interface, with methods insert(), remove(), __getitem__(),
__setitem__(),... and a signal to notify the views. The objects in the
list have methods to change their state as well.

My problem is, how do the commands interact with the model?
Let's say I have a command that modifies an object o in the list.

1) If list[key_to_o] returns a reference to the object, the command can
modify the object by using this reference, i.e. list[key_to_o].setX().
So there is no way for the list to know when the object changed - how
can it emit a singal then?

2) If list[key_to_o] returns a deep copy of the object,
copy_of_o = list[key_to_o], the command mofifies the copy and the
updates the list: list[key_to_o] = copy_of_o. Now the list can emit a
signal in __setitem__().
While this may work, it seems awkward to copy around objects just to
perform a possibly simple operation on them. Additionally it might not
be feasible once objects get complex.

3) The interface of the classes of the objects could be reflected in the
list class, i.e. list.set_x_on_obj(key_to_obj,x). This would probably
make the list class interface very bloated.

Of course the problem is not really limited to Python, my apologies if
I'm totally off-topic here.

Regards
Georg

Sep 15 '08 #1
2 1425
On Monday 15 September 2008 21:37, Georg Altmann wrote:
I need some advice on how to implement model-view-controller. I am
trying to develop a GUI application with PyQt, yet the problem rather
applies to mvc in general, not just GUI applications.

Let's say the data is a list of objects with a common base class. The
views are either a graphical representation of the objects or some form
of textual input. The views shall change the model by using command
objects (for undo, e.g. QUndoCommand).
[...]
My problem is, how do the commands interact with the model?
One approach that combines the undo framework with the model/view framework
is described here:

http://doc.trolltech.com/qq/qq25-undo.html

The implementation is in C++, but it may be possible to pick up some
useful tips from the article.

David
Sep 15 '08 #2
David Boddie schrieb:
On Monday 15 September 2008 21:37, Georg Altmann wrote:
>I need some advice on how to implement model-view-controller. I am
trying to develop a GUI application with PyQt, yet the problem rather
applies to mvc in general, not just GUI applications.

Let's say the data is a list of objects with a common base class. The
views are either a graphical representation of the objects or some form
of textual input. The views shall change the model by using command
objects (for undo, e.g. QUndoCommand).

[...]
>My problem is, how do the commands interact with the model?

One approach that combines the undo framework with the model/view framework
is described here:

http://doc.trolltech.com/qq/qq25-undo.html

The implementation is in C++, but it may be possible to pick up some
useful tips from the article.
Thanks for the pointer. I studied the article before, but it doesn't
seem to work for my problem:
If I understand the Qt model/view architecture correctly, data is always
based on items which are wrapped into QVariant.
(see http://doc.trolltech.com/4.4/qabstra...odel.html#data)

So to use the Qt model/view architecture items have to be represented as
a value. I think this leaves me with the problem of copying objects I
described before.

Regards
Georg
Sep 16 '08 #3

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

Similar topics

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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.