Elementary: Improve input event example.
- prevent focusing the log entry or the clear button widgets - move log entry widgets cursor to end when it changes - set weight size hints to allocate more space for log entry widget - clarify the output messages
This commit is contained in:
parent
3473e92379
commit
75ee95a7d6
|
@ -3,6 +3,7 @@
|
|||
|
||||
from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL
|
||||
from efl import elementary
|
||||
|
||||
from efl.elementary.box import Box
|
||||
from efl.elementary.button import Button
|
||||
from efl.elementary.entry import Entry, utf8_to_markup
|
||||
|
@ -15,6 +16,9 @@ FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL
|
|||
def filter_cb(obj, text, data):
|
||||
return None
|
||||
|
||||
def changed_cb(obj):
|
||||
obj.cursor_end_set()
|
||||
|
||||
def events_cb(obj, src, event_type, event, data):
|
||||
|
||||
entry = data
|
||||
|
@ -23,23 +27,24 @@ def events_cb(obj, src, event_type, event, data):
|
|||
append(utf8_to_markup(
|
||||
"Obj: %r\n\nSrc: %r\n\nEvent: %s" % (obj, src, event)
|
||||
))
|
||||
append("<br><br>Modifiers:<br>")
|
||||
append(utf8_to_markup(
|
||||
"Control: %s Shift: %s Alt: %s" % (
|
||||
event.modifier_is_set("Control"),
|
||||
event.modifier_is_set("Shift"),
|
||||
event.modifier_is_set("Alt")
|
||||
)
|
||||
))
|
||||
|
||||
if event_type == EVAS_CALLBACK_KEY_UP:
|
||||
append("<br><br>Modifiers:<br>")
|
||||
append(utf8_to_markup(
|
||||
"Control: %s Shift: %s Alt: %s" % (
|
||||
event.modifier_is_set("Control"),
|
||||
event.modifier_is_set("Shift"),
|
||||
event.modifier_is_set("Alt")
|
||||
)
|
||||
))
|
||||
append("<br><br>This event was handled so it won't propagate to window.<br>")
|
||||
append("<br><br>This event was handled so it won't propagate to a parent of Obj.<br><br>")
|
||||
append("---------------------------------------------------------------")
|
||||
append("<br><br>")
|
||||
|
||||
return True
|
||||
|
||||
append("<br>---------------------------------------------------------------")
|
||||
append("<br><br>This event was not handled so it will propagate to a parent of Obj if it has one.<br><br>")
|
||||
append("---------------------------------------------------------------")
|
||||
append("<br><br>")
|
||||
|
||||
return False
|
||||
|
@ -53,21 +58,23 @@ def elm_input_events_clicked(obj, item=None):
|
|||
win.resize_object_add(box)
|
||||
box.show()
|
||||
|
||||
entry = Entry(win, scrollable=True,
|
||||
size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
|
||||
entry = Entry(win, scrollable=True, size_hint_align=FILL_BOTH,
|
||||
size_hint_weight=(1.0, 0.2))
|
||||
entry.text = (
|
||||
"This example will show how Elementary input events are handled. "
|
||||
"Typing in this entry will log in the entry box below all events "
|
||||
"caught by event handlers set to this Entry widget and its parent, "
|
||||
"the Window widget."
|
||||
"the Window widget. Key up events are checked for in the callback "
|
||||
"and won't propagate to a parent widget."
|
||||
)
|
||||
entry.show()
|
||||
|
||||
log_entry = Entry(win, editable=False, scrollable=True,
|
||||
size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
|
||||
log_entry = Entry(win, editable=False, scrollable=True, focus_allow=False,
|
||||
size_hint_align=FILL_BOTH, size_hint_weight=(1.0, 0.8))
|
||||
log_entry.callback_changed_add(changed_cb)
|
||||
log_entry.show()
|
||||
|
||||
btn = Button(win, text="Clear log")
|
||||
btn = Button(win, text="Clear log", focus_allow=False)
|
||||
btn.callback_clicked_add(lambda x: setattr(log_entry, "entry", ""))
|
||||
btn.show()
|
||||
|
||||
|
|
Loading…
Reference in New Issue