From: John H. <jdh...@ac...> - 2005-10-07 16:04:01
|
>>>>> "Ted" == Ted Drain <ted...@jp...> writes: Ted> John, I had some questions about this resize work. Here is Ted> the code for resize from backend_gtk.py: Ted> def resize(self, w, h): 'set the drawing area size in Ted> pixels' winw, winh = self.parent.parent.get_size() tmp, tmp, Ted> myw, myh = self.allocation padw = winw-myw padh = winh-myh Ted> self.parent.parent.resize(w+padw, h+padh) Ted> I'm a little concerned about this implementation. It looks Ted> like the widget is telling it's parent's parent to resize. Ted> Doesn't this mean that the ability of the widget to be used Ted> as a modular component is reduced because this code requires Ted> a certain parent child relationship? Oops, you're right. Good catch. This implementation will fail for some widget packings, eg a canvas in a scrolled window... Ted> I think it's fairly important that a widget have only very Ted> minimum interactions with it's parent. Is there some way Ted> this could be implemented that doesn't require the child Ted> widget to be calling methods on the parent? Ted> If I understand the basic premise you've outlined below, you Ted> want a resize in the child (the drawing widget) to cause the Ted> parent window to resize. Only the parent can figure out what Ted> it's size needs to be (since it knows about it's margins, Ted> toolbars, etc). On the surface, it seems like there are two Ted> ways to handling this: 1) Tell the window to resize the Ted> canvas. The window can use it's own layout classes, etc and Ted> correctly resize itself and the canvas. 2) Tell the canvas Ted> to resize and have this trigger a window resize. Ted> I think the first option is much cleaner. However, if that Ted> isn't possible, I suggest that we do something like this: Right, we don't need a resize method. As you suggest, all we need is a way to tell the canvas and its parent(s) to auto_adjust itself to accommodate the figure (using the width, height and dpi settings ....) Then whenever fig.set_dpi or fig.set_figsize_inches or fig.set_figsize_pixels (to be added) is called, we could call self.canvas.update_size() if we can figure out the right way to propagate up containment chain. The update_size method will have to send a signal to the parent, but how this is done can be backend dependent. I think the logic in my first implementation is still correct if we replace self.parent.parent (which as you note makes certain parent/child assumptions) with the gtk.Window the canvas resides in because it sets it computes the width and height of all the other widgets in the canvas by subtracting the canvas width/height from the window width/height. winw, winh = self.gtkwin.get_size() tmp, tmp, myw, myh = self.allocation padw = winw-myw padh = winh-myh self.gtkwin.resize(w+padw, h+padh) Of course this would require that the canvas user sets gtkwin. Other than for the philosophical reason that the child calls methods on the parent, do you still think this implementation is problematic? I personally don't find it problematic, but I'm willing to be corrected :-) Of course, in QT you could handle it anyway you want, eg using signals to the parent. If you can sketch a cleaner implementation that makes more sense let me know. Since only GTK has an implementation currently and it is broken, and no mpl code is currently using the resize function, the field is wide open. Thanks, JDH |