Skip to content

Instantly share code, notes, and snippets.

@rschroll
Created March 28, 2012 00:06
Show Gist options
  • Save rschroll/2221668 to your computer and use it in GitHub Desktop.
Save rschroll/2221668 to your computer and use it in GitHub Desktop.
Delayed resize of sidebar widgets in Reinteract
import gobject as _gobject
class _ResizeBox(_gtk.VBox):
def __init__(self, figure):
_gtk.VBox.__init__(self)
self.figure = figure
# Rounding errors slowly accumlate in the figure height, shrinking it down
# over time. So we make a copy here and use that to keep resetting the
# canvas to the proper size.
self.figsize_inches = self.figure.get_size_inches().copy()
self.eid = None
def _set_sidebar_width(self, width):
dpi = width / self.figsize_inches[0]
self.figure.set_dpi(dpi)
self.figure.canvas.set_size_request(*map(int, self.figsize_inches * dpi))
self.eid = None
return False
def set_sidebar_width(self, width):
if self.eid:
_gobject.source_remove(self.eid)
self.eid = _gobject.timeout_add(200, self._set_sidebar_width, width)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment