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

Support capitals in prompt_text (fixes #47) #50

Merged
merged 1 commit into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
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
16 changes: 2 additions & 14 deletions esp32/modules/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,8 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
ugfx.set_default_font(font)
label = ugfx.Label(5, 1, int(width*4/5), height-kb_height-5-edit_height-5, description, parent=window)

def vkey_pressed(key):
new_text = edit.text() + key
edit.text(new_text)
edit.cursor_pos(len(new_text))
edit.text(new_text)
ugfx.flush()

def vkey_backspace():
new_text = edit.text()[:-1]
edit.text(new_text)
edit.cursor_pos(len(new_text))
edit.text(new_text)
edit.backspace()
ugfx.flush()

focus = 0
Expand All @@ -111,10 +101,8 @@ def toggle_focus(pressed):
if focus == 0:
edit.set_focus()
kb.enabled(1)
# Do we manually have to transfer keypresses to the editbox?
print("attaching")
ugfx.input_attach(ugfx.BTN_B, lambda pressed: vkey_backspace() if pressed else 0)
ugfx.input_attach(ugfx.BTN_A, lambda pressed: vkey_pressed(kb.selected_key()) if pressed else 0)
ugfx.input_attach(ugfx.BTN_A, lambda pressed: 0 if pressed else ugfx.flush())
focus = 1
elif focus == 1 or not button_no:
button_yes.set_focus()
Expand Down
13 changes: 13 additions & 0 deletions esp32/ugfx_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,18 @@ STATIC mp_obj_t ugfx_textbox_cursor_pos(mp_uint_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ugfx_textbox_cursor_pos_obj, 1, 2, ugfx_textbox_cursor_pos);

/// \method backspace()
///
/// removes the character before the cursor
STATIC mp_obj_t ugfx_textbox_backspace(mp_obj_t self_in) {
ugfx_textbox_obj_t *self = self_in;

gwinTexteditBackspace(self->ghTextbox);

return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ugfx_textbox_backspace_obj, ugfx_textbox_backspace);

/// \method destroy()
///
/// frees up all resources
Expand All @@ -447,6 +459,7 @@ STATIC const mp_map_elem_t ugfx_textbox_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_destroy), (mp_obj_t)&ugfx_textbox_destroy_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&ugfx_textbox_destroy_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_cursor_pos), (mp_obj_t)&ugfx_textbox_cursor_pos_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_backspace), (mp_obj_t)&ugfx_textbox_backspace_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_visible), (mp_obj_t)&ugfx_widget_visible_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_attach_input), (mp_obj_t)&ugfx_widget_attach_input_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_detach_input), (mp_obj_t)&ugfx_widget_detach_input_obj },
Expand Down