Palette fixes

This commit is contained in:
Eduardo Silva 2007-05-30 13:29:29 -04:00
parent 75130719b5
commit dd00dda41f
2 changed files with 40 additions and 31 deletions

View File

@ -44,7 +44,6 @@ class Palette(gtk.Window):
_WIN_BORDER = 5 _WIN_BORDER = 5
def __init__(self): def __init__(self):
gobject.GObject.__init__(self, type=gtk.WINDOW_POPUP) gobject.GObject.__init__(self, type=gtk.WINDOW_POPUP)
gtk.Window.__init__(self) gtk.Window.__init__(self)
@ -75,25 +74,14 @@ class Palette(gtk.Window):
vbox.show() vbox.show()
# Widget events # Widget events
self.connect('motion-notify-event', self._mouse_over_widget) self.connect('motion-notify-event', self._mouse_over_widget_cb)
self.connect('leave-notify-event', self._mouse_out_widget) self.connect('leave-notify-event', self._mouse_out_widget_cb)
self.connect('button-press-event', self._close_palette) self.connect('button-press-event', self._close_palette_cb)
self.connect('key-press-event', self._on_key_press_event) self.connect('key-press-event', self._on_key_press_event_cb)
self.set_border_width(self._WIN_BORDER) self.set_border_width(self._WIN_BORDER)
self.add(vbox) self.add(vbox)
def _is_mouse_out(self, window, event):
# If we're clicking outside of the Palette
# return True
if (event.window != self.window or
(tuple(self.allocation.intersect(
gdk.Rectangle(x=int(event.x), y=int(event.y),
width=1, height=1)))) == (0, 0, 0, 0)):
return True
else:
return False
def do_set_property(self, pspec, value): def do_set_property(self, pspec, value):
if pspec.name == 'parent': if pspec.name == 'parent':
@ -145,10 +133,6 @@ class Palette(gtk.Window):
self.move(move_x, move_y) self.move(move_x, move_y)
def _close_palette(self, widget=None, event=None):
gtk.gdk.pointer_ungrab()
self.hide()
def set_primary_state(self, label, accel_path=None): def set_primary_state(self, label, accel_path=None):
if accel_path != None: if accel_path != None:
item = gtk.MenuItem(label) item = gtk.MenuItem(label)
@ -168,15 +152,27 @@ class Palette(gtk.Window):
widget.show() widget.show()
def append_button(self, button): def append_button(self, button):
button.connect('released', self._close_palette) button.connect('released', self._close_palette_cb)
self._button_bar.pack_start(button, True, True, self._PADDING) self._button_bar.pack_start(button, True, True, self._PADDING)
button.show() button.show()
def display(self, button): def popup(self):
self.show() self.show()
self.set_position() self.set_position()
self._pointer_grab() self._pointer_grab()
# PRIVATE METHODS
def _is_mouse_out(self, window, event):
# If we're clicking outside of the Palette
# return True
event_rect = gdk.Rectangle(event.x, event.y, 1, 1)
if (event.window != self.window or self.allocation.intersect(event_rect).width==0):
return True
else:
return False
def _pointer_grab(self): def _pointer_grab(self):
gtk.gdk.pointer_grab(self.window, owner_events=False, gtk.gdk.pointer_grab(self.window, owner_events=False,
event_mask=gtk.gdk.BUTTON_PRESS_MASK | event_mask=gtk.gdk.BUTTON_PRESS_MASK |
@ -187,15 +183,24 @@ class Palette(gtk.Window):
gdk.keyboard_grab(self.window, False) gdk.keyboard_grab(self.window, False)
def _mouse_out_widget(self, widget, event): # SIGNAL HANDLERS
# Release the GDK pointer and hide the palette
def _close_palette_cb(self, widget=None, event=None):
gtk.gdk.pointer_ungrab()
self.hide()
# Mouse is out of the widget
def _mouse_out_widget_cb(self, widget, event):
if (widget == self) and self._is_mouse_out(widget, event): if (widget == self) and self._is_mouse_out(widget, event):
self._pointer_grab() self._pointer_grab()
def _mouse_over_widget(self, widget, event): # Mouse inside the widget
def _mouse_over_widget_cb(self, widget, event):
gtk.gdk.pointer_ungrab() gtk.gdk.pointer_ungrab()
def _on_key_press_event(self, window, event): # Some key is pressed
def _on_key_press_event_cb(self, window, event):
# Escape or Alt+Up: Close # Escape or Alt+Up: Close
# Enter, Return or Space: Select # Enter, Return or Space: Select
@ -204,6 +209,6 @@ class Palette(gtk.Window):
if (keyval == keysyms.Escape or if (keyval == keysyms.Escape or
((keyval == keysyms.Up or keyval == keysyms.KP_Up) and ((keyval == keysyms.Up or keyval == keysyms.KP_Up) and
state == gdk.MOD1_MASK)): state == gdk.MOD1_MASK)):
self._close_palette() self._close_palette_cb()
elif keyval == keysyms.Tab: elif keyval == keysyms.Tab:
self._close_palette() self._close_palette()

View File

@ -31,10 +31,14 @@ class ToolButton(gtk.ToolButton):
icon.show() icon.show()
def set_palette(self, palette): def set_palette(self, palette):
self.connect('clicked', palette.display) self._palette = palette
palette.props.parent = self self._palette.props.parent = self
palette.props.alignment = ALIGNMENT_BOTTOM_LEFT self._palette.props.alignment = ALIGNMENT_BOTTOM_LEFT
self.connect('clicked', self._display_palette_cb)
def set_tooltip(self, text): def set_tooltip(self, text):
tp = gtk.Tooltips() tp = gtk.Tooltips()
self.set_tooltip(tp, text, text) self.set_tooltip(tp, text, text)
def _display_palette_cb(self, widget):
self._palette.popup()