Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set focus to icons box by default #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions uroute/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ def _build_url_entry_hbox(self):
def _build_browser_buttons(self):
# pylint: disable=attribute-defined-outside-init
self.browser_store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, object)
iconview = Gtk.IconView.new()
iconview.set_model(self.browser_store)
iconview.set_pixbuf_column(0)
iconview.set_text_column(1)
iconview.connect('item-activated', self._on_browser_icon_activated)
iconview.connect('selection-changed', self._on_browser_icon_selected)
# pylint: disable=attribute-defined-outside-init
self.iconview = Gtk.IconView.new()
self.iconview.set_model(self.browser_store)
self.iconview.set_pixbuf_column(0)
self.iconview.set_text_column(1)
self.iconview.connect('item-activated', self._on_browser_icon_activated)
self.iconview.connect('selection-changed', self._on_browser_icon_selected)

default_itr = None
default_program = self.uroute.get_program()
Expand All @@ -255,11 +256,11 @@ def _build_browser_buttons(self):
default_itr = itr

if default_itr:
iconview.select_path(self.browser_store.get_path(default_itr))
self._on_browser_icon_selected(iconview)
self.iconview.select_path(self.browser_store.get_path(default_itr))
self._on_browser_icon_selected(self.iconview)

scroll = Gtk.ScrolledWindow()
scroll.add(iconview)
scroll.add(self.iconview)
return scroll

def _build_command_hbox(self):
Expand Down Expand Up @@ -316,8 +317,14 @@ def _on_key_pressed(self, _wnd, event):
self._on_cancel_clicked(None)
if event.keyval == Gdk.KEY_Return:
self._on_run_clicked(None)
# Ctrl+L shortcut to focus the URL bar (like in web browsers)
if event.keyval == Gdk.KEY_l and event.state & Gdk.ModifierType.CONTROL_MASK:
self.url_entry.grab_focus()
self.url_entry.select_region(0, -1) # Select all text

def _on_window_show(self, _window):
# Hack required because gtk
self.clean_url_btn.set_visible(not self.orig_url)
self.restore_url_btn.set_visible(bool(self.orig_url))
# Set focus to the browser buttons area instead of the URL entry
self.iconview.grab_focus()