-
Notifications
You must be signed in to change notification settings - Fork 24
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
Show previous message sent on up and down arrow keys press #33
base: master
Are you sure you want to change the base?
Conversation
Pressing the up arrow key shows previously entered messages and the entry seems to lose focus but pressing the up arrow key still works even if there's no visible indication of the entry gaining focus, pressing the down arrow key at this point doesn't work as the entry doesn't have focus. Pressing the down arrow key when the entry has focus works as expected and when they're no more messages to show, the entry is empty for any new messages. I'm not sure if this is a Gtk or Sugar bug but same thing doesn't happen in a standalone program so it is most likely a Sugar problem. Signed-off-by: Chihurumnaya Ibiam <[email protected]>
Had a quick look, did not test. You mentioned another program that gets it right. What program was that? Sometimes we have had to fix problems in the Sugar Toolkit. |
A standalone I wrote to test the bug. import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
class Entry(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, type=Gtk.WindowType.TOPLEVEL)
self.text = []
self._index = -1
fixed = Gtk.Fixed()
self.add(fixed)
fixed.show()
self.entry = Gtk.Entry()
fixed.put(self.entry, 0, 0)
self.entry.connect('activate', self._entry_activated_cb)
self.entry.connect('key-press-event', self._entry_keypress_cb)
self.entry.show()
self.show_all()
def _entry_activated_cb(self, entry):
text = entry.props.text
if text:
self.text.append(text)
entry.props.text = ''
def _entry_keypress_cb(self, widget, event):
if event.keyval == Gdk.KEY_Up:
self._last_key = 'Up'
self._set_text_on_key_press(widget)
elif event.keyval == Gdk.KEY_Down:
self._last_key = 'Down'
self._set_text_on_key_press(widget)
def _set_text_on_key_press(self, entry):
if self._index < -(len(self.text)):
self._index = -(len(self.text))
if self._last_key == 'Up' and len(self.text) > 0:
entry.set_text(self.text[self._index])
self._index -= 1
if self._last_key == 'Down':
if self._index < -1:
self._index += 1
entry.set_text(self.text[self._index])
elif self._index == -1:
entry.set_text("")
self.entry.set_position(-1)
self.entry.grab_focus_without_selecting()
if __name__ == "__main__":
a = Entry()
a.connect("destroy", Gtk.main_quit)
Gtk.main() |
Thanks. It shows the problem is likely to be the toolkit. I suggest adding the toolkit to the test program as a first step, to verify the theory. |
I'd put the program in a test activity and the issue persisted, any ideas for what to look for?
|
Given that a contributing cause of the problem is the spontaneous change to focus, I suggest looking in particular at the Testing with a modified toolkit can be as simple as copying |
Fixes #27
Pressing the up arrow key shows previously entered messages and the entry seems to lose focus but pressing the up arrow key still works even if there's no visible indication of the entry gaining focus, pressing the down arrow key at this point doesn't work as the entry doesn't have focus.
Pressing the down arrow key when the entry has focus works as expected and when they're no more messages to show, the entry is empty for any new messages.
I'm not sure if this is a Gtk or Sugar bug but same thing doesn't happen in a standalone program so it is most likely a Sugar problem.
I'm wondering if we should leave the behaviour as it is right now but I'm still taking a look to see if I"ll find a solution to the issue stated above.
@quozl kindly review.