feat: add keyboard to keypad switchs to macro panel

This commit is contained in:
Alfredo Monclus 2024-09-19 00:46:35 -03:00
parent f045393dc3
commit 822f5400cf
9 changed files with 41 additions and 3 deletions

View File

@ -209,7 +209,7 @@ class Keyboard(Gtk.Box):
if key == "":
Gtk.Entry.do_backspace(self.entry)
elif key == "":
self.close_cb()
self.close_cb(entry=self.entry)
return
elif key == "":
self.toggle_shift()

View File

@ -86,18 +86,40 @@ class Panel(ScreenPanel):
if result:
result = result.groupdict()
default = result["default"] if "default" in result else ""
entry = Gtk.Entry(placeholder_text=default)
entry = Gtk.Entry(placeholder_text=default, input_purpose=Gtk.InputPurpose.ALPHA)
icon = self._gtk.PixbufFromIcon("hashtag")
entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
entry.connect("icon-press", self.on_icon_pressed)
self.macros[macro]["params"].update({result["param"]: entry})
for param in self.macros[macro]["params"]:
labels.add(Gtk.Label(param))
self.macros[macro]["params"][param].connect("focus-in-event", self._screen.show_keyboard)
self.macros[macro]["params"][param].connect("focus-in-event", self.scroll_to_entry)
self.macros[macro]["params"][param].connect("focus-out-event", self._screen.remove_keyboard)
labels.add(self.macros[macro]["params"][param])
def scroll_to_entry(self, entry, event):
self.labels['macros_list'].get_vadjustment().set_value(
entry.get_allocation().y - 50
)
def on_icon_pressed(self, entry, icon_pos, event):
entry.grab_focus()
self._screen.remove_keyboard()
if entry.get_input_purpose() == Gtk.InputPurpose.ALPHA:
entry.set_input_purpose(Gtk.InputPurpose.DIGITS)
entry.get_style_context().add_class("active")
else:
entry.set_input_purpose(Gtk.InputPurpose.ALPHA)
entry.get_style_context().remove_class("active")
self._screen.show_keyboard(entry)
def run_gcode_macro(self, widget, macro):
params = ""
for param in self.macros[macro]["params"]:
self.macros[macro]["params"][param].set_sensitive(False) # Move focus to prevent
self.macros[macro]["params"][param].set_sensitive(True) # reopening the osk
value = self.macros[macro]["params"][param].get_text()
if value:
if re.findall(r'[G|M]\d{1,3}', macro):

View File

@ -1207,13 +1207,16 @@ class KlipperScreen(Gtk.Window):
}
return
def remove_keyboard(self, widget=None, event=None):
def remove_keyboard(self, entry=None, event=None):
if self.keyboard is None:
return
if 'process' in self.keyboard:
os.kill(self.keyboard['process'].pid, SIGTERM)
self.base_panel.content.remove(self.keyboard['box'])
self.keyboard = None
if entry:
entry.set_sensitive(False) # Move the focus
entry.set_sensitive(True)
def _key_press_event(self, widget, event):
keyval_name = Gdk.keyval_name(event.keyval)

View File

@ -73,6 +73,7 @@ button {
-gtk-icon-shadow: none;
}
.active image,
button:active,
.button_active,
button.active {
@ -166,6 +167,13 @@ entry {
background-color: @active;
border: .2em solid @bg;
padding: .2em;
margin-right: .5em;
}
entry image {
margin: 0 .1em;
border-radius: 1em;
padding: .5em;
}
label {

View File

@ -32,6 +32,7 @@ button {
background-color: @solarized-base03;
}
.active image,
button:active {
background-color: @solarized-orange;
}

View File

@ -58,6 +58,7 @@ button.color4 {
border-radius: 1em;
}
.active image,
button.color1:active,
button.color2:active,
button.color3:active,

View File

@ -66,6 +66,7 @@ button.invalid:active,
background-color: #424242;
}
.active image,
button.update {
color: #2196f3;
background-color: #121212;

View File

@ -31,6 +31,7 @@ button label{
color: @text;
}
.active image,
button:active {
background-color: @active;
}

View File

@ -58,6 +58,7 @@ button.active {
background-color: @active;
}
.active image,
button.update {
background: @color3;
border-color: @color3;