Enable focus when there is content. Remove the focus

out check on the invoker toplevel, we will have to do
that differently.
This commit is contained in:
Marco Pesenti Gritti 2007-08-08 11:53:41 +02:00
parent 9c0df1c6c5
commit 3a33e4cedd

View File

@ -139,6 +139,7 @@ class Palette(gtk.Window):
self._menu.remove(self._menu.get_children()[index]) self._menu.remove(self._menu.get_children()[index])
def set_content(self, widget): def set_content(self, widget):
self._update_accept_focus()
self._content.pack_start(widget) self._content.pack_start(widget)
def append_button(self, button): def append_button(self, button):
@ -158,7 +159,6 @@ class Palette(gtk.Window):
self._invoker = value self._invoker = value
self._invoker.connect('mouse-enter', self._invoker_mouse_enter_cb) self._invoker.connect('mouse-enter', self._invoker_mouse_enter_cb)
self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb) self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb)
self._invoker.connect('focus-out', self._invoker_focus_out_cb)
elif pspec.name == 'position': elif pspec.name == 'position':
self._position = value self._position = value
else: else:
@ -172,9 +172,14 @@ class Palette(gtk.Window):
else: else:
raise AssertionError raise AssertionError
def _update_accept_focus(self):
accept_focus = len(self._content.get_children())
if self.window:
self.window.set_accept_focus(accept_focus)
def _realize_cb(self, widget): def _realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.window.set_accept_focus(False) self._update_accept_focus()
def _in_screen(self, x, y): def _in_screen(self, x, y):
[width, height] = self._full_request [width, height] = self._full_request
@ -299,9 +304,8 @@ class Palette(gtk.Window):
self._update_cursor_position() self._update_cursor_position()
self._update_full_request() self._update_full_request()
self._invoker.connect_to_parent() self._palette_popup_sid = _palette_observer.connect(
self._palette_popup_sid = _palette_observer.connect('popup', 'popup', self._palette_observer_popup_cb)
self._palette_observer_popup_cb)
self._update_position() self._update_position()
self._menu.set_active(True) self._menu.set_active(True)
@ -365,9 +369,6 @@ class Palette(gtk.Window):
def _invoker_mouse_leave_cb(self, invoker): def _invoker_mouse_leave_cb(self, invoker):
self.popdown() self.popdown()
def _invoker_focus_out_cb(self, invoker):
self._hide()
def _enter_notify_event_cb(self, widget, event): def _enter_notify_event_cb(self, widget, event):
if event.detail == gtk.gdk.NOTIFY_NONLINEAR: if event.detail == gtk.gdk.NOTIFY_NONLINEAR:
self._popdown_anim.stop() self._popdown_anim.stop()
@ -430,13 +431,6 @@ class Invoker(gobject.GObject):
height = gtk.gdk.screen_height() height = gtk.gdk.screen_height()
return gtk.gdk.Rectangle(0, 0, width, height) return gtk.gdk.Rectangle(0, 0, width, height)
def connect_to_parent(self):
window = self.get_toplevel()
window.connect('focus-out-event', self._window_focus_out_event_cb)
def _window_focus_out_event_cb(self, widget, event):
self.emit('focus-out')
class WidgetInvoker(Invoker): class WidgetInvoker(Invoker):
def __init__(self, widget): def __init__(self, widget):
Invoker.__init__(self) Invoker.__init__(self)