def __init__(self, label=None, image=gtk.STOCK_PROPERTIES, orientation=gtk.ORIENTATION_VERTICAL): gtk.Frame.__init__(self) self.set_shadow_type(gtk.SHADOW_NONE) if orientation is gtk.ORIENTATION_VERTICAL: self.mainbox = gtk.VBox(False, 2) else: self.mainbox = gtk.HBox(False, 2) # What we need is the arrow button a label with markup and # optionally a close button :) self._arrow = HIGArrowButton(orientation) self._arrow.set_relief(gtk.RELIEF_NONE) self._arrow.set_size_request(20, 20) self._arrow.connect('clicked', self.do_toggle_animation) self._arrow.connect('force-clicked', self.do_force_animation) self._label = gtk.Label('') self.label = label self._image = gtk.Image() self.image = image # The layout part self._layout = Layout(orientation) self._layout.connect('animation-end', lambda w, z: self.emit('activate')) # Pack all if orientation is gtk.ORIENTATION_VERTICAL: box = gtk.HBox(False, 2) self._label.set_alignment(0, 0.5) else: box = gtk.VBox(False, 2) self._label.set_angle(270) self._label.set_alignment(0.5, 0) box.pack_start(self._arrow, False, False) box.pack_start(self._image, False, False) box.pack_start(self._label) frame = gtk.Frame() frame.add(box) self._happy_box = gtk.EventBox() self._happy_box.add(frame) self.mainbox.pack_start(self._happy_box, False, False) self.mainbox.pack_start(self._layout) gtk.Frame.add(self, self.mainbox) self.show_all()
class AnimatedExpander(gtk.Frame): __gtype_name__ = "AnimatedExpander" __gsignals__ = { 'activate': (gobject.SIGNAL_RUN_LAST, None, ()), } def __init__(self, label=None, image=gtk.STOCK_PROPERTIES, orientation=gtk.ORIENTATION_VERTICAL): gtk.Frame.__init__(self) self.set_shadow_type(gtk.SHADOW_NONE) if orientation is gtk.ORIENTATION_VERTICAL: self.mainbox = gtk.VBox(False, 2) else: self.mainbox = gtk.HBox(False, 2) # What we need is the arrow button a label with markup and # optionally a close button :) self._arrow = HIGArrowButton(orientation) self._arrow.set_relief(gtk.RELIEF_NONE) self._arrow.set_size_request(20, 20) self._arrow.connect('clicked', self.do_toggle_animation) self._arrow.connect('force-clicked', self.do_force_animation) self._label = gtk.Label('') self.label = label self._image = gtk.Image() self.image = image # The layout part self._layout = Layout(orientation) self._layout.connect('animation-end', lambda w, z: self.emit('activate')) # Pack all if orientation is gtk.ORIENTATION_VERTICAL: box = gtk.HBox(False, 2) self._label.set_alignment(0, 0.5) else: box = gtk.VBox(False, 2) self._label.set_angle(270) self._label.set_alignment(0.5, 0) box.pack_start(self._arrow, False, False) box.pack_start(self._image, False, False) box.pack_start(self._label) frame = gtk.Frame() frame.add(box) self._happy_box = gtk.EventBox() self._happy_box.add(frame) self.mainbox.pack_start(self._happy_box, False, False) self.mainbox.pack_start(self._layout) gtk.Frame.add(self, self.mainbox) self.show_all() def do_realize(self): gtk.Frame.do_realize(self) bg_color = gtk.gdk.color_parse("#FFFFDC") gtk.gdk.colormap_get_system().alloc_color(bg_color) self._happy_box.modify_bg(gtk.STATE_NORMAL, bg_color) # Uhmma uhmma bad trick! if not self._layout._to_show: self._layout.hide() def add_widget(self, widget, show=False): """ Add a widget to the expander. @param widget the widget to add @param show if the widget should be showed """ self._layout.add(widget) self._layout.set_expanded(show) def add(self, widget): self.add_widget(widget, True) def get_label(self): return self._label.get_text() def set_label(self, txt): if not txt: txt = "" self._label.set_text(txt) self._label.set_use_markup(True) def do_force_animation(self, btn): "override me!" pass def do_toggle_animation(self, btn): if self._layout.toggle_animation(): self._arrow.set_active(not self._arrow.get_active()) def get_image(self): return self._image def set_image(self, stock): self._image.set_from_stock(stock, gtk.ICON_SIZE_MENU) def get_expanded(self): return self._layout.get_active() label = property(get_label, set_label) image = property(get_image, set_image)
class AnimatedExpander(gtk.Frame): __gtype_name__ = "AnimatedExpander" __gsignals__ = { 'activate' : (gobject.SIGNAL_RUN_LAST, None, ()), } def __init__(self, label=None, image=gtk.STOCK_PROPERTIES, orientation=gtk.ORIENTATION_VERTICAL): gtk.Frame.__init__(self) self.set_shadow_type(gtk.SHADOW_NONE) if orientation is gtk.ORIENTATION_VERTICAL: self.mainbox = gtk.VBox(False, 2) else: self.mainbox = gtk.HBox(False, 2) # What we need is the arrow button a label with markup and # optionally a close button :) self._arrow = HIGArrowButton(orientation) self._arrow.set_relief(gtk.RELIEF_NONE) self._arrow.set_size_request(20, 20) self._arrow.connect('clicked', self.do_toggle_animation) self._arrow.connect('force-clicked', self.do_force_animation) self._label = gtk.Label('') self.label = label self._image = gtk.Image() self.image = image # The layout part self._layout = Layout(orientation) self._layout.connect('animation-end', lambda w, z: self.emit('activate')) # Pack all if orientation is gtk.ORIENTATION_VERTICAL: box = gtk.HBox(False, 2) self._label.set_alignment(0, 0.5) else: box = gtk.VBox(False, 2) self._label.set_angle(270) self._label.set_alignment(0.5, 0) box.pack_start(self._arrow, False, False) box.pack_start(self._image, False, False) box.pack_start(self._label) frame = gtk.Frame() frame.add(box) self._happy_box = gtk.EventBox() self._happy_box.add(frame) self.mainbox.pack_start(self._happy_box, False, False) self.mainbox.pack_start(self._layout) gtk.Frame.add(self, self.mainbox) self.show_all() def do_realize(self): gtk.Frame.do_realize(self) bg_color = gtk.gdk.color_parse("#FFFFDC") gtk.gdk.colormap_get_system().alloc_color(bg_color) self._happy_box.modify_bg(gtk.STATE_NORMAL, bg_color) # Uhmma uhmma bad trick! if not self._layout._to_show: self._layout.hide() def add_widget(self, widget, show=False): """ Add a widget to the expander. @param widget the widget to add @param show if the widget should be showed """ self._layout.add(widget) self._layout.set_expanded(show) def add(self, widget): self.add_widget(widget, True) def get_label(self): return self._label.get_text() def set_label(self, txt): if not txt: txt = "" self._label.set_text(txt) self._label.set_use_markup(True) def do_force_animation(self, btn): "override me!" pass def do_toggle_animation(self, btn): if self._layout.toggle_animation(): self._arrow.set_active(not self._arrow.get_active()) def get_image(self): return self._image def set_image(self, stock): self._image.set_from_stock(stock, gtk.ICON_SIZE_MENU) def get_expanded(self): return self._layout.get_active() label = property(get_label, set_label) image = property(get_image, set_image)