From ff734de4e8829c9873fb84f0a9cc0166860cdd96 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Mon, 22 Oct 2012 14:34:46 +0000 Subject: Control Panel: defocus the search entry by default - SL #3998 Do the same behavior as in the shell views and Journal, explained in detail in commit 1570f774 . - overrite grab_focus in the window to grab it in the view widget, the one that have the icons. - grab the focus in the view widget on startup. - connect the clear icon of the search entry to a callback that grabs the focus again in the view widget. - clear the search when a section is closed Signed-off-by: Simon Schampijer Signed-off-by: Manuel QuiƱones --- diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py index f8afca3..f28b248 100644 --- a/src/jarabe/controlpanel/gui.py +++ b/src/jarabe/controlpanel/gui.py @@ -55,6 +55,9 @@ class ControlPanel(Gtk.Window): self.set_resizable(False) self.set_modal(True) + self.set_can_focus(True) + self.connect('key-press-event', self.__key_press_event_cb) + self._toolbar = None self._canvas = None self._table = None @@ -90,6 +93,10 @@ class ControlPanel(Gtk.Window): self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.get_window().set_accept_focus(True) + def grab_focus(self): + # overwrite grab focus in order to grab focus on the view + self._main_view.get_child().grab_focus() + def _set_canvas(self, canvas): if self._canvas: self._main_view.remove(self._canvas) @@ -186,8 +193,18 @@ class ControlPanel(Gtk.Window): self._table.show() self._scrolledwindow.show() entry = self._main_toolbar.get_entry() - entry.grab_focus() entry.set_text('') + entry.connect('icon-press', self.__clear_icon_pressed_cb) + self.grab_focus() + + def __key_press_event_cb(self, window, event): + entry = self._main_toolbar.get_entry() + if not entry.has_focus(): + entry.grab_focus() + return False + + def __clear_icon_pressed_cb(self, entry, icon_pos, event): + self.grab_focus() def _update(self, query): for option in self._options: -- cgit v0.9.1