keyboard: fix size while vertical

This commit is contained in:
alfrix 2022-06-10 14:24:42 -03:00 committed by Alfredo Monclus
parent da26bf3143
commit d3ce521bb0
4 changed files with 30 additions and 43 deletions

View File

@ -10,7 +10,6 @@ from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, Pango
class KlippyGtk: class KlippyGtk:
labels = {} labels = {}
keyboard_ratio = .22
width_ratio = 16 width_ratio = 16
height_ratio = 9.375 height_ratio = 9.375
@ -22,8 +21,10 @@ class KlippyGtk:
if self.screen.vertical_mode: if self.screen.vertical_mode:
self.font_ratio = [33, 49] self.font_ratio = [33, 49]
self.keyboard_ratio = .25
else: else:
self.font_ratio = [43, 29] self.font_ratio = [43, 29]
self.keyboard_ratio = .33
self.font_size = int(min( self.font_size = int(min(
self.width / self.font_ratio[0], self.width / self.font_ratio[0],
self.height / self.font_ratio[1] self.height / self.font_ratio[1]
@ -84,7 +85,7 @@ class KlippyGtk:
return self.img_height return self.img_height
def get_keyboard_height(self): def get_keyboard_height(self):
return (self.width - self.get_action_bar_width()) * self.keyboard_ratio return self.get_content_height() * self.keyboard_ratio
def get_temp_color(self, device): def get_temp_color(self, device):
# logging.debug("Color list %s" % self.color_list) # logging.debug("Color list %s" % self.color_list)

View File

@ -264,37 +264,35 @@ class BedMeshPanel(ScreenPanel):
self.content.remove(child) self.content.remove(child)
if "create_profile" not in self.labels: if "create_profile" not in self.labels:
self.labels['create_profile'] = Gtk.VBox()
self.labels['create_profile'].set_valign(Gtk.Align.START)
box = Gtk.Box(spacing=5)
box.set_size_request(self._gtk.get_content_width(), self._gtk.get_content_height() -
self._screen.keyboard_height - 20)
box.set_hexpand(True)
box.set_vexpand(False)
self.labels['create_profile'].add(box)
pl = self._gtk.Label(_("Profile Name:")) pl = self._gtk.Label(_("Profile Name:"))
pl.set_hexpand(False) pl.set_hexpand(False)
entry = Gtk.Entry() entry = Gtk.Entry()
entry.set_text('')
entry.set_hexpand(True) entry.set_hexpand(True)
entry.connect("activate", self.create_profile) entry.connect("activate", self.create_profile)
entry.connect("focus-in-event", self._show_keyboard)
entry.connect("focus-out-event", self._remove_keyboard)
save = self._gtk.ButtonImage("sd", _("Save"), "color3") save = self._gtk.ButtonImage("sd", _("Save"), "color3")
save.set_hexpand(False) save.set_hexpand(False)
save.connect("clicked", self.create_profile) save.connect("clicked", self.create_profile)
self.labels['profile_name'] = entry box = Gtk.HBox()
box.pack_start(pl, False, False, 5)
box.pack_start(entry, True, True, 5) box.pack_start(entry, True, True, 5)
box.pack_start(save, False, False, 5) box.pack_start(save, False, False, 5)
self.show_create = True self.labels['create_profile'] = Gtk.VBox(spacing=5)
self.labels['profile_name'].set_text('') self.labels['create_profile'].set_valign(Gtk.Align.CENTER)
self.labels['create_profile'].set_hexpand(True)
self.labels['create_profile'].set_vexpand(True)
self.labels['create_profile'].pack_start(pl, True, True, 5)
self.labels['create_profile'].pack_start(box, True, True, 5)
self.content.add(self.labels['create_profile']) self.content.add(self.labels['create_profile'])
self.content.show()
self._screen.show_keyboard() self._screen.show_keyboard()
self.labels['profile_name'] = entry
self.labels['profile_name'].grab_focus_without_selecting() self.labels['profile_name'].grab_focus_without_selecting()
self.show_create = True
def show_mesh(self, widget, profile): def show_mesh(self, widget, profile):
_ = self.lang.gettext _ = self.lang.gettext

View File

@ -349,35 +349,33 @@ class NetworkPanel(ScreenPanel):
if "add_network" in self.labels: if "add_network" in self.labels:
del self.labels['add_network'] del self.labels['add_network']
self.labels['add_network'] = Gtk.VBox()
self.labels['add_network'].set_valign(Gtk.Align.START)
box = Gtk.Box(spacing=5)
box.set_size_request(self._gtk.get_content_width(), self._gtk.get_content_height() -
self._screen.keyboard_height - 20)
box.set_hexpand(True)
box.set_vexpand(False)
self.labels['add_network'].add(box)
label = self._gtk.Label("%s %s:" % (_("PSK for"), ssid)) label = self._gtk.Label("%s %s:" % (_("PSK for"), ssid))
label.set_hexpand(False) label.set_hexpand(False)
entry = Gtk.Entry() entry = Gtk.Entry()
entry.set_text('')
entry.set_hexpand(True) entry.set_hexpand(True)
entry.connect("activate", self.add_new_network, ssid, True) entry.connect("activate", self.add_new_network, ssid, True)
entry.connect("focus-in-event", self._show_keyboard)
entry.connect("focus-out-event", self._remove_keyboard)
save = self._gtk.ButtonImage("sd", _("Save"), "color3") save = self._gtk.ButtonImage("sd", _("Save"), "color3")
save.set_hexpand(False) save.set_hexpand(False)
save.connect("clicked", self.add_new_network, ssid, True) save.connect("clicked", self.add_new_network, ssid, True)
self.labels['network_psk'] = entry box = Gtk.HBox()
box.pack_start(label, False, False, 5)
box.pack_start(entry, True, True, 5) box.pack_start(entry, True, True, 5)
box.pack_start(save, False, False, 5) box.pack_start(save, False, False, 5)
self.show_create = True self.labels['add_network'] = Gtk.VBox(spacing=5)
self.labels['network_psk'].set_text('') self.labels['add_network'].set_valign(Gtk.Align.CENTER)
self.labels['add_network'].set_hexpand(True)
self.labels['add_network'].set_vexpand(True)
self.labels['add_network'].pack_start(label, True, True, 5)
self.labels['add_network'].pack_start(box, True, True, 5)
self.content.add(self.labels['add_network']) self.content.add(self.labels['add_network'])
self._screen.show_keyboard() self._screen.show_keyboard()
self.labels['network_psk'] = entry
self.labels['network_psk'].grab_focus_without_selecting() self.labels['network_psk'].grab_focus_without_selecting()
self.content.show_all() self.content.show_all()
self.show_add = True self.show_add = True

View File

@ -63,7 +63,6 @@ class KlipperScreen(Gtk.Window):
files = None files = None
filename = "" filename = ""
keyboard = None keyboard = None
keyboard_height = 200
last_update = {} last_update = {}
load_panel = {} load_panel = {}
number_tools = 1 number_tools = 1
@ -122,7 +121,6 @@ class KlipperScreen(Gtk.Window):
self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False) self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False)
self.gtk = KlippyGtk(self, self.width, self.height, self.theme, self.show_cursor, self.gtk = KlippyGtk(self, self.width, self.height, self.theme, self.show_cursor,
self._config.get_main_config_option("font_size", "medium")) self._config.get_main_config_option("font_size", "medium"))
self.keyboard_height = self.gtk.get_keyboard_height()
self.init_style() self.init_style()
self.base_panel = BasePanel(self, title="Base Panel", back=False) self.base_panel = BasePanel(self, title="Base Panel", back=False)
@ -500,11 +498,6 @@ class KlipperScreen(Gtk.Window):
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
) )
def is_keyboard_showing(self):
if self.keyboard is None:
return False
return True
def is_printing(self): def is_printing(self):
return self.printer.get_state() == "printing" return self.printer.get_state() == "printing"
@ -593,6 +586,7 @@ class KlipperScreen(Gtk.Window):
logging.debug("Showing Screensaver") logging.debug("Showing Screensaver")
if self.screensaver is not None: if self.screensaver is not None:
self.close_screensaver() self.close_screensaver()
self.remove_keyboard()
close = Gtk.Button() close = Gtk.Button()
close.connect("clicked", self.close_screensaver) close.connect("clicked", self.close_screensaver)
@ -1037,11 +1031,7 @@ class KlipperScreen(Gtk.Window):
box = Gtk.VBox() box = Gtk.VBox()
box.set_vexpand(False) box.set_vexpand(False)
if self._screen.vertical_mode: box.set_size_request(self.gtk.get_content_width(), self.gtk.get_keyboard_height())
box.set_size_request(self.width, self.keyboard_height)
else:
action_bar_width = self.gtk.get_action_bar_width()
box.set_size_request(self.width - action_bar_width, self.keyboard_height)
box.add(keyboard) box.add(keyboard)
self.base_panel.get_content().pack_end(box, False, 0, 0) self.base_panel.get_content().pack_end(box, False, 0, 0)