Re: [Goocanvas-devel] Model Rewrite and Connecting Signal Handlers
Status: Beta
Brought to you by:
dachaplin
From: John S. <joh...@gm...> - 2006-12-02 23:03:14
|
> > This creates some wierd coupling between different parts of the application. > > Out of interest, what weird coupling is happening? In conduit[1] I have a number of derived classes which sit on the canvas (which is derived from CavasView). For example class Conduit derives from goocanvas.Group. It also holds some other items (eg class Connector), which are also derived from goocanvas.Group. When items are added to the canvas I connect signal handlers (for mouse enter/exit and click) to the derived goocanvas.Group items by waiting for the item-view-created signal in CanvasView. For those items that are inside the Conduit class (that is the groups children) I have this weird situation where I must do all these checks (in item-view-created) to see if it is the Conduit or the Connector class. - as Connector signals are handled within class Conduit. I hope this makes sense. I would much rather be able to do (excuse the pseudo python from memory) class Connector(goocanvs.Group): pass class Conduit(goocanvas.Group) def __init__(self) self.connector = Connector() self.add_child(self.connector) self.connecor.connect("clicked", self.connector_clicked) Than what I am currently doing class Canvas(goocanvas.CanvasView) def on_item_view_created(thing) if thing == Conduit: thing.connect("clicked", savedConduitClass.on_connector_clicked) <--- Eeew Does this make sense? It looks as though the new API will make this possible. Any other comments on what I could do better would be appreciated John > > > With the GooCanvas rewrite, if you don't need a model/view canvas it > will become simpler. > > You can just do this: > > rect_item = goo_canvas_rect_new (root, 100, 100, 400, 400, > "line-width", 10.0, > "radius-x", 20.0, > "radius-y", 10.0, > "stroke-color", "yellow", > "fill-color", "red", > NULL); > > g_signal_connect (rect_item, "button_press_event", > (GtkSignalFunc) on_rect_button_press, NULL); > > > > For the model/view canvas I can't currently think of anything better > than the "on_item_view_created" signal handler. The views need to be > created dynamically as the underlying model is changed, and the > application's signal handlers need to be connected to the new views > somehow. > > Anyone have any ideas? > > > Damon > > > |