fix: use custom combobox to workaround self-closing issues
This commit is contained in:
1 parent
6f38e7db08
commit
6b6b8e0dfe
3 files changed
+35
-21
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GLib
|
||||
|
||||
|
||||
class ComboBoxPlus(Gtk.ComboBox):
|
||||
"""
|
||||
A spcial ComboBox that checks if the dropdown was closed too fast and re-opens it
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._last_open_time = 0
|
||||
self.set_focus_on_click(False)
|
||||
self.connect("notify::popup-shown", self._on_popup_shown)
|
||||
|
||||
def _on_popup_shown(self, combo, pspec):
|
||||
if self.get_property("popup-shown"):
|
||||
self._last_open_time = GLib.get_monotonic_time()
|
||||
return
|
||||
|
||||
# Microseconds to seconds
|
||||
duration = (GLib.get_monotonic_time() - self._last_open_time) / 1000000.0
|
||||
|
||||
if duration < 0.2:
|
||||
GLib.idle_add(self._reopen_now, priority=GLib.PRIORITY_HIGH_IDLE)
|
||||
|
||||
def _reopen_now(self):
|
||||
self.popup()
|
||||
return False
|
||||
+2
-1
@@ -6,6 +6,7 @@ import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GdkPixbuf, GObject, Pango, Gdk
|
||||
from ks_includes.widgets.combo import ComboBoxPlus
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
from ks_includes.KlippyRest import KlippyRest
|
||||
from datetime import datetime
|
||||
@@ -228,7 +229,7 @@ class Panel(ScreenPanel):
|
||||
row.add(hbox)
|
||||
|
||||
label = Gtk.Label(_("Material"))
|
||||
_material_filter = Gtk.ComboBox(model=self._materials, hexpand=True)
|
||||
_material_filter = ComboBoxPlus(model=self._materials, hexpand=True)
|
||||
_material_filter.connect("changed", self._on_material_filter_changed)
|
||||
cellrenderertext = Gtk.CellRendererText()
|
||||
_material_filter.pack_start(cellrenderertext, True)
|
||||
|
||||
+2
-20
@@ -5,7 +5,7 @@ import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Pango, GLib
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
from datetime import datetime
|
||||
from ks_includes.widgets.combo import ComboBoxPlus
|
||||
|
||||
|
||||
class Panel(ScreenPanel):
|
||||
@@ -16,7 +16,6 @@ class Panel(ScreenPanel):
|
||||
def __init__(self, screen, title):
|
||||
title = title or _("Z Calibrate")
|
||||
super().__init__(screen, title)
|
||||
self.last_drop_time = datetime.now()
|
||||
self.initialize_mesh_params()
|
||||
self.initialize_probe_params()
|
||||
self.setup_ui()
|
||||
@@ -100,9 +99,8 @@ class Panel(ScreenPanel):
|
||||
)
|
||||
self.buttons['start'].connect("clicked", self.start_calibration)
|
||||
|
||||
self.dropdown = Gtk.ComboBox.new_with_model(self.set_commands())
|
||||
self.dropdown = ComboBoxPlus(model=self.set_commands())
|
||||
self.dropdown.connect("changed", self.on_dropdown_change)
|
||||
self.dropdown.connect("notify::popup-shown", self.on_popup_shown)
|
||||
renderer_text = Gtk.CellRendererText()
|
||||
renderer_text.set_property("ellipsize", Pango.EllipsizeMode.END)
|
||||
self.dropdown.pack_start(renderer_text, True)
|
||||
@@ -159,22 +157,6 @@ class Panel(ScreenPanel):
|
||||
model = dropdown.get_model()
|
||||
logging.debug(f"Selected {model[iterable][0]}")
|
||||
|
||||
def on_popup_shown(self, combo_box, param):
|
||||
if combo_box.get_property("popup-shown"):
|
||||
logging.debug("Dropdown popup show")
|
||||
self.last_drop_time = datetime.now()
|
||||
else:
|
||||
elapsed = (datetime.now() - self.last_drop_time).total_seconds()
|
||||
if elapsed < 0.2:
|
||||
logging.debug(f"Dropdown closed too fast ({elapsed}s)")
|
||||
GLib.timeout_add(50, self.dropdown_keep_open)
|
||||
return
|
||||
logging.debug("Dropdown popup close")
|
||||
|
||||
def dropdown_keep_open(self):
|
||||
self.dropdown.popup()
|
||||
return False
|
||||
|
||||
def set_commands(self):
|
||||
commands = Gtk.ListStore(str)
|
||||
|
||||
|
||||
Reference in new issue
Block a user