How to do_size_allocate properly in a gtk.Viewport subclass

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joel Hedlund

    How to do_size_allocate properly in a gtk.Viewport subclass

    Hi!

    I've raised this issue on #pygtk and #gtk+ but with no luck. I haven't
    been able to solve this even with aid of google, the pygtk reference and
    the gtk C source, so pretty please help?

    I'm making an application that you can think of as an image viewer. I
    want to display a widget in a gtk.Viewport. The widget can have any size
    from tiny to humungous. I don't want the viewport to ever give the
    widget a larger size allocation than requested, and I don't want the
    viewport to ever resize to accomodate a large widget. It should rather
    leave grey areas around the widget/show only a portion of the widget.

    To do this I have subclassed gtk.Viewport (MyViewport) and overrided the
    do_size_allocat e method:
    def do_size_allocat e(self, allocation):
    self.allocation = allocation
    child_req = self.child.get_ child_requisiti on()
    child_alloc = gtk.gdk.Rectang le(0, 0, *child_req)
    self.child.size _allocate(child _alloc)
    self.props.hadj ustment.update( allocation.widt h, child_alloc.wid th)
    self.props.vadj ustment.update( allocation.heig ht, child_alloc.hei ght)
    if self.flags() & gtk.REALIZED:
    self.window.mov e_resize(*self. allocation)
    self.child.wind ow()
    When I add a very large widget (a gtk.DrawingArea ) to MyViewport only
    the originally visible portion of the widget is redrawn when I resize
    the window using the mouse, and the grey area around widget gets
    littered with grey lines that are not redrawn if you minimize and
    restore the window. I assume this comes from that the proper gdk windows
    haven't been updated, and that the grey lines are remnants of old
    Viewport borders.

    In gtk_viewport_si ze_allocate in gtkviewport.c, gdk_window_move _resize
    is called on three gdk windows: viewport->window, viewport->view_window
    and viewport->bin_window, but in pygtk I only have gtk.Viewport.wi ndow.
    I assume that this is the problem? If so, how can I fix this? Or is
    there something else that I have overlooked?

    And another relevant question: am I overcomplicatin g this? Is there some
    kind of flag that I could set on a vanilla viewport to accomplish this?

    Thanks in advance,
    Joel
  • Hrvoje Niksic

    #2
    Re: How to do_size_allocat e properly in a gtk.Viewport subclass

    Joel Hedlund <joel.hedlund@g mail.comwrites:
    I've raised this issue on #pygtk and #gtk+ but with no luck.
    Note that there's a mailing list dedicated to PyGTK,
    <pygtk@daa.com. au>, so you might also want to ask your question there.

    Comment

    • Joel Hedlund

      #3
      Re: How to do_size_allocat e properly in a gtk.Viewport subclass

      Hrvoje Niksic wrote:
      Note that there's a mailing list dedicated to PyGTK,
      <pygtk@daa.com. au>, so you might also want to ask your question there.
      Thanks. I'll try that and hope people won't take offense from
      cross-posting. I'll be wathching this thread for answers too though. In
      my experience, c.l.p usually delivers.

      Cheers!
      /Joel

      Comment

      • Joel Hedlund

        #4
        Re: How to do_size_allocat e properly in a gtk.Viewport subclass

        Joel Hedlund wrote:
        And another relevant question: am I overcomplicatin g this?
        Yes. :-)

        The proper way of doing this is to pack the widget in a container, and
        then add the container (with viewport) to a scrolledwindow.

        For example, for a centered widget choose a 1x1 gtk.Table and attach the
        widget using xoptions = yoptions = gtk.EXPAND (and not gtk.FILL). For a
        widget glued to the upper left corner choose a gtk.Alignment() .

        Thanks John Finlay at pygtk@daa.com.a u!

        /Joel

        Comment

        Working...