Skip to content

Commit

Permalink
Merge pull request #126 from Ulauncher/issue-125
Browse files Browse the repository at this point in the history
Issue #125. Fixed bug with SetUserQueryAction
  • Loading branch information
gornostal committed May 3, 2017
2 parents f39898e + baf6d66 commit d3846b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
13 changes: 7 additions & 6 deletions tests/api/shared/action/test_SetUserQueryAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ def window(self, mocker):

@pytest.fixture
def action(self, window):
return SetUserQueryAction('new_query')
return SetUserQueryAction('new query')

def test_keep_app_open(self, action):
assert action.keep_app_open()

def test_run(self, action, mocker, window):
mocker.patch.object(action, 'set_position')
action.run()
window.input.set_text.assert_called_with('new_query')
action.set_position.assert_called_with()
def test_update_query(self, action, mocker, window):
action._update_query()

input = window.get_input.return_value
input.set_text.assert_called_with('new query')
input.set_position.assert_called_with(len('new query'))
16 changes: 9 additions & 7 deletions ulauncher/api/shared/action/SetUserQueryAction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from time import sleep
from gi.repository import GLib

from ulauncher.util.decorator.run_async import run_async
from .BaseAction import BaseAction
Expand All @@ -13,19 +14,20 @@ class SetUserQueryAction(BaseAction):

def __init__(self, new_query):
self.new_query = new_query
from ulauncher.ui.windows.UlauncherWindow import UlauncherWindow
self._input = UlauncherWindow.get_instance().input

def keep_app_open(self):
return True

def run(self):
self._input.set_text(self.new_query)
self.set_position()
GLib.idle_add(self._update_query)

def _update_query(self):
from ulauncher.ui.windows.UlauncherWindow import UlauncherWindow

input = UlauncherWindow.get_instance().get_input()
input.set_text(self.new_query)

@run_async
def set_position(self):
# Ugly hack:
# Defer set position, because GTK sets position after change event occurs
sleep(0.002)
self._input.set_position(len(self.new_query))
input.set_position(len(self.new_query))
3 changes: 3 additions & 0 deletions ulauncher/ui/windows/UlauncherWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def on_input_key_press_event(self, widget, event):
# Helpers
######################################

def get_input(self):
return self.input

def init_theme(self):
# workaround for issue with a caret-color
# GTK+ < 3.20 doesn't support that prop
Expand Down

0 comments on commit d3846b5

Please sign in to comment.