Move dictionary from instance to class level

Dave Angel davea at
Thu Aug 27 11:24:14 CEST 2009

Frank Millman wrote:
> Dave Angel wrote:
>> Show me a sample client event handler, and maybe I can suggest how to 
>> encode it.  For example in wxPython, events are encoded  with 
>> an event 
>> object.  You could have the event send the object's type-string as an 
>> event ID.  No lookup at all.  And in fact, one event handler 
>> then might 
>> handle several of the events for a given widget, or even for multiple 
>> ones.  I guess it's not that simple, since you frequently 
>> have to pass 
>> other information, such as the state of the Ctrl-key, or the mouse 
>> position on the screen, which is not directly encoded in the 
>> event type.
> That is definitely *not* what I want to do.
> I want to make the server as generic as possible, so that it can handle any
> type of client, hopefully even including a browser eventually. Therefore the
> server has no knowledge of wxPython event types.
> I have abstracted all the event types I am interested in (the list is fairly
> stable now). My protocol requires that the client maps a specific gui event
> type to a message identifier, and the server maps the message identifier to
> a method that handles the message.
> Hope that makes sense.
> Frank
Yes, it makes sense. Sorry for heading down that particular dead-end.  
But the more I think about it, the more likely I think it is that you'll 
be adding new message types, even if they're just variants of ones 
already defined.  So it might behoove you to have a shared "data 
structure" that describes the whole message, not just equates a name to 
an integer.

Or consider pickling.  I don't know the tradeoffs, but the idea is that 
an object is constructed at the other end that has all the same data 
members as the object you had at this end.  Perhaps with a flexible 
enough class definition, you could represent all or at least several of 
your messages with the same object.

I am curious about your topology.  You're sending events from the client 
(which presumably has a mouse and keyboard) to a server.  But what does 
the server do with those?  Does it have its own screen, or what?


More information about the Python-list mailing list