This commit is contained in:
Sam Parkinson 2016-07-10 20:55:58 +10:00
commit e0c38a8b8a
No known key found for this signature in database
GPG Key ID: 34E268B2FA2F8B13
2 changed files with 3 additions and 74 deletions

View File

@ -123,7 +123,6 @@ class Palette(PaletteWindow):
self._secondary_text = None self._secondary_text = None
self._icon = None self._icon = None
self._icon_visible = True self._icon_visible = True
self._palette_state = self.PRIMARY
self._primary_event_box = Gtk.EventBox() self._primary_event_box = Gtk.EventBox()
self._primary_event_box.show() self._primary_event_box.show()
@ -165,9 +164,7 @@ class Palette(PaletteWindow):
self._separator = Gtk.HSeparator() self._separator = Gtk.HSeparator()
self._secondary_box.pack_start(self._separator, True, True, 0) self._secondary_box.pack_start(self._separator, True, True, 0)
self._secondary_box.show()
self._secondary_anim = animator.Animator(2.0, 10)
self._secondary_anim.add(_SecondaryAnimation(self))
# we init after initializing all of our containers # we init after initializing all of our containers
PaletteWindow.__init__(self, **kwargs) PaletteWindow.__init__(self, **kwargs)
@ -186,7 +183,6 @@ class Palette(PaletteWindow):
self.action_bar.show() self.action_bar.show()
self.connect('notify::invoker', self.__notify_invoker_cb) self.connect('notify::invoker', self.__notify_invoker_cb)
self.connect('popdown', self.__popdown_cb)
# Default to a normal window palette # Default to a normal window palette
self._content_widget = None self._content_widget = None
@ -203,15 +199,11 @@ class Palette(PaletteWindow):
self._widget.present() self._widget.present()
def __destroy_cb(self, palette): def __destroy_cb(self, palette):
self._secondary_anim.stop()
self.popdown(immediate=True) self.popdown(immediate=True)
# Break the reference cycle. It looks like the gc is not able to free # Break the reference cycle. It looks like the gc is not able to free
# it, possibly because Gtk.Menu memory handling is very special. # it, possibly because Gtk.Menu memory handling is very special.
self._widget = None self._widget = None
def __popdown_cb(self, widget):
self._secondary_anim.stop()
def __notify_invoker_cb(self, palette, pspec): def __notify_invoker_cb(self, palette, pspec):
invoker = self.props.invoker invoker = self.props.invoker
if invoker is not None and hasattr(invoker.props, 'widget'): if invoker is not None and hasattr(invoker.props, 'widget'):
@ -225,33 +217,20 @@ class Palette(PaletteWindow):
def get_full_size_request(self): def get_full_size_request(self):
return self._full_request return self._full_request
def popup(self, immediate=False, state=None): def popup(self, immediate=False):
if self._invoker is not None: if self._invoker is not None:
self._update_full_request() self._update_full_request()
if state is None:
state = self.PRIMARY
self.set_palette_state(state)
if state == self.PRIMARY:
self._secondary_anim.start()
else:
self._secondary_anim.stop()
PaletteWindow.popup(self, immediate) PaletteWindow.popup(self, immediate)
def popdown(self, immediate=False): def popdown(self, immediate=False):
if immediate: if immediate:
self._secondary_anim.stop()
# to suppress glitches while later re-opening
self.set_palette_state(self.PRIMARY)
if self._widget: if self._widget:
self._widget.size_request() self._widget.size_request()
PaletteWindow.popdown(self, immediate) PaletteWindow.popdown(self, immediate)
def on_enter(self): def on_enter(self):
PaletteWindow.on_enter(self) PaletteWindow.on_enter(self)
self._secondary_anim.start()
def _add_content(self): def _add_content(self):
# The content is not shown until a widget is added # The content is not shown until a widget is added
@ -430,27 +409,9 @@ class Palette(PaletteWindow):
self._widget.set_accept_focus(accept_focus) self._widget.set_accept_focus(accept_focus)
def _update_full_request(self): def _update_full_request(self):
if self._palette_state == self.PRIMARY:
self._secondary_box.show()
if self._widget is not None: if self._widget is not None:
self._full_request = self._widget.size_request() self._full_request = self._widget.size_request()
if self._palette_state == self.PRIMARY:
self._secondary_box.hide()
def _set_palette_state(self, state):
if self._palette_state == state:
return
if state == self.PRIMARY:
self._secondary_box.hide()
elif state == self.SECONDARY:
self._secondary_box.show()
self.update_position()
self._palette_state = state
def get_menu(self): def get_menu(self):
assert self._content_widget is None assert self._content_widget is None
@ -475,13 +436,7 @@ class Palette(PaletteWindow):
menu = GObject.property(type=object, getter=get_menu) menu = GObject.property(type=object, getter=get_menu)
def _invoker_right_click_cb(self, invoker): def _invoker_right_click_cb(self, invoker):
self.popup(immediate=True, state=self.SECONDARY) self.popup(immediate=True)
def _invoker_toggle_state_cb(self, invoker):
if self.is_up() and self._palette_state == self.SECONDARY:
self.popdown(immediate=True)
else:
self.popup(immediate=True, state=self.SECONDARY)
class PaletteActionBar(Gtk.HButtonBox): class PaletteActionBar(Gtk.HButtonBox):
@ -496,14 +451,3 @@ class PaletteActionBar(Gtk.HButtonBox):
self.pack_start(button, True, True, 0) self.pack_start(button, True, True, 0)
button.show() button.show()
class _SecondaryAnimation(animator.Animation):
def __init__(self, palette):
animator.Animation.__init__(self, 0.0, 1.0)
self._palette = palette
def next_frame(self, current):
if current == 1.0:
self._palette.set_palette_state(Palette.SECONDARY)

View File

@ -487,9 +487,6 @@ class PaletteWindow(GObject.GObject):
Provides basic management of child widget, invoker, and animation. Provides basic management of child widget, invoker, and animation.
""" """
PRIMARY = 0
SECONDARY = 1
__gsignals__ = { __gsignals__ = {
'popup': (GObject.SignalFlags.RUN_FIRST, None, ([])), 'popup': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'popdown': (GObject.SignalFlags.RUN_FIRST, None, ([])), 'popdown': (GObject.SignalFlags.RUN_FIRST, None, ([])),
@ -503,7 +500,6 @@ class PaletteWindow(GObject.GObject):
self._cursor_y = 0 self._cursor_y = 0
self._alignment = None self._alignment = None
self._up = False self._up = False
self._palette_state = None
self._widget = None self._widget = None
self._popup_anim = animator.Animator(.5, 10) self._popup_anim = animator.Animator(.5, 10)
@ -758,17 +754,6 @@ class PaletteWindow(GObject.GObject):
return rect return rect
def get_palette_state(self):
return self._palette_state
def _set_palette_state(self, state):
self._palette_state = state
def set_palette_state(self, state):
self._set_palette_state(state)
palette_state = property(get_palette_state)
class _PopupAnimation(animator.Animation): class _PopupAnimation(animator.Animation):