Re: [pygtk] gtkmvc (was: pygtk + glade: code decomposition best practices?)

2004-10-01 Thread Roberto Cavada
On Thu, 2004-09-30 at 13:51 -0400, Brett Viren wrote:
> I want it to trigger an XML-RPC call to set the "something" parameter
> on the server.  I've implemented MyModel.__setattr__() to do this
> interception and from there pass the call along to the parent by
> calling Model.__setattr__().
> 
> This seems to work, but is it the best way?  For example, in the end
> my __setattr__ will have a big list of if blocks, one for each
> intercepted property which isn't so pretty.
It is not obvious to decide here. You might think to keep your solution,
maximizing locality of the handling code, that is not necessarily a bad
idea. From one hand, the code might become bigger and bigger, but the
locality of the comunication with the server might improve code
inspection, bug fixing, commitment of new code, etc.  

>From the other hand, there is the necessity of catching modification on
the server's data. How the view/controller pair would be notified of
this modification? What happens whether other data that depend on the
changed one must be updated? 

In my opinion everytime you have mutual dependencies between data,
bidirectional data flows, and need for separation of model and data
representation, you might think to consider the use of mvc and observer
patterns. 

I am not sure gtkmvc would capture all requirements in your case, since
it "forces" you to put notification about observable properties in
separate class methods. 

Actually, if you were able to adapt the metaclass that generates the
code that implements the observer pattern, you might think to make the
model comunicate with the server via RPC for free, since the
comunication code would be generated as well. This would be possible
only if the function that maps model's data to server's data were
injective. Under the necessary condition, it is a matter of deriving a
new metaclass from the one that gtkmvc.model.Model currently uses. 

Feel free to ask for further details, maybe out of this list since I
think this is going OT. 
rob

-- 
  _/_/_/   _/_/_/   Roberto Cavada
 _/   _/ _/ITC-irst   http://www.irst.itc.it
_/   _/ _/Automated Reasoning Systems - Formal Methods Group
/_/_/  _/Via Sommarive, 18 - 38050 Povo (TN) - Italy
   _/  _/   Tel: +39 0461 314 328   Fax: +39 0461 302 040
_/   _/_/  [EMAIL PROTECTED]   http://sra.itc.it/people/cavada

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] gtkmvc (was: pygtk + glade: code decomposition best practices?)

2004-09-30 Thread Brett Viren
Roberto Cavada <[EMAIL PROTECTED]> writes:

> On Thu, 2004-09-30 at 13:18 +0300, Ruslan wrote:
>> I would like to ask people using pygtk + glade to share their approach
>> on code decomposition. 
> I use a mvc+observer pattern from my gtkmvc (see
> ). Each pair controller+view can be
> associated to a separate glade file, or to a set of subtrees of one or
> more glade trees. In my opinion this approach helps a lot in separating
> the different parts of a GUI. The model(s) can also be splitted, so
> obtaining good a separation of the application logic as well. 
> rob

Thanks from me too!  This looks really nice and happens to fall in my
lap at just the moment I needed something like it.

For the application I'm working on my model would shadow the state of
a networked server.  The desire is to have the model sync to the
server's state through XML-RPC calls.  The model updates through
periodic polling of the server and changes to the model by the client
application should, likewise, get pushed to the server.

So, in the controller, when I do something like:

  self.model.something = new_something

I want it to trigger an XML-RPC call to set the "something" parameter
on the server.  I've implemented MyModel.__setattr__() to do this
interception and from there pass the call along to the parent by
calling Model.__setattr__().

This seems to work, but is it the best way?  For example, in the end
my __setattr__ will have a big list of if blocks, one for each
intercepted property which isn't so pretty.

Thanks,
-Brett.


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/