增加开门检测功能选项
This commit is contained in:
parent
58d8df6652
commit
1b1322dffc
@ -3,17 +3,19 @@ import logging
|
|||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk
|
from gi.repository import GLib, Gtk
|
||||||
|
|
||||||
from ks_includes.KlippyFactory import KlippyFactory
|
from ks_includes.KlippyFactory import KlippyFactory
|
||||||
from ks_includes.KlippyGcodes import KlippyGcodes
|
from ks_includes.KlippyGcodes import KlippyGcodes
|
||||||
from ks_includes.screen_panel import ScreenPanel
|
from ks_includes.screen_panel import ScreenPanel
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Panel(ScreenPanel):
|
class Panel(ScreenPanel):
|
||||||
def __init__(self, screen, title):
|
def __init__(self, screen, title):
|
||||||
title = title or _("Advanced")
|
title = title or _("Advanced")
|
||||||
super().__init__(screen, title)
|
super().__init__(screen, title)
|
||||||
|
self.last_drop_time = datetime.now()
|
||||||
self.advanced = {}
|
self.advanced = {}
|
||||||
self.menu_list = {}
|
self.menu_list = {}
|
||||||
self.advanced_options = [
|
self.advanced_options = [
|
||||||
@ -59,6 +61,27 @@ class Panel(ScreenPanel):
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
if self._printer.get_macro("_door_detection"):
|
||||||
|
self.advanced_options.append(
|
||||||
|
{
|
||||||
|
"door_open_detection": {
|
||||||
|
"section": "main",
|
||||||
|
"name": _("Door Open Protection Mode"),
|
||||||
|
"type": "dropdown",
|
||||||
|
"tooltip": _(
|
||||||
|
"This feature allows you to customize the printer's response when door opening is detected"
|
||||||
|
),
|
||||||
|
"value": "Disabled",
|
||||||
|
"callback": self.door_open_detection,
|
||||||
|
"options": [
|
||||||
|
{"name": _("Disabled") + " " + _("(default)"), "value": "Disabled"},
|
||||||
|
{"name": _("Pause Print"), "value": "Pause Print"},
|
||||||
|
{"name": _("Emergency Stop"), "value": "Emergency Stop"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
options = self.advanced_options
|
options = self.advanced_options
|
||||||
self.labels["advanced_menu"] = self._gtk.ScrolledWindow()
|
self.labels["advanced_menu"] = self._gtk.ScrolledWindow()
|
||||||
self.labels["advanced"] = Gtk.Grid()
|
self.labels["advanced"] = Gtk.Grid()
|
||||||
@ -69,6 +92,9 @@ class Panel(ScreenPanel):
|
|||||||
self.menu_list.update(res)
|
self.menu_list.update(res)
|
||||||
self.content.add(self.labels["advanced_menu"])
|
self.content.add(self.labels["advanced_menu"])
|
||||||
|
|
||||||
|
if "door_open_detection" in self.menu_list:
|
||||||
|
self.menu_list["door_open_detection"].connect("notify::popup-shown", self.on_popup_shown)
|
||||||
|
|
||||||
def reset_factory_settings(self, *args):
|
def reset_factory_settings(self, *args):
|
||||||
text = _("Confirm factory reset?\n") + "\n\n" + _("The system will reboot!")
|
text = _("Confirm factory reset?\n") + "\n\n" + _("The system will reboot!")
|
||||||
label = Gtk.Label(wrap=True, vexpand=True)
|
label = Gtk.Label(wrap=True, vexpand=True)
|
||||||
@ -111,6 +137,26 @@ class Panel(ScreenPanel):
|
|||||||
if response_id == Gtk.ResponseType.OK:
|
if response_id == Gtk.ResponseType.OK:
|
||||||
KlippyFactory.user_factory_reset(self._screen._ws.klippy, self._config, clear_files_checkbox.get_active())
|
KlippyFactory.user_factory_reset(self._screen._ws.klippy, self._config, clear_files_checkbox.get_active())
|
||||||
|
|
||||||
|
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.1:
|
||||||
|
logging.debug(f"Dropdown closed too fast ({elapsed}s)")
|
||||||
|
GLib.timeout_add(50, lambda: self.dropdown_keep_open(combo_box))
|
||||||
|
return
|
||||||
|
logging.debug("Dropdown popup close")
|
||||||
|
|
||||||
|
def dropdown_keep_open(self, combo_box):
|
||||||
|
if isinstance(combo_box, Gtk.ComboBox):
|
||||||
|
combo_box.popup()
|
||||||
|
return False
|
||||||
|
|
||||||
|
def door_open_detection(self, str):
|
||||||
|
self.set_configuration_string("door_detect", str)
|
||||||
|
|
||||||
def set_adaptive_leveling(self, *args):
|
def set_adaptive_leveling(self, *args):
|
||||||
self.set_configuration_feature("adaptive_meshing", *args)
|
self.set_configuration_feature("adaptive_meshing", *args)
|
||||||
|
|
||||||
@ -120,6 +166,11 @@ class Panel(ScreenPanel):
|
|||||||
def set_auto_change_nozzle(self, *args):
|
def set_auto_change_nozzle(self, *args):
|
||||||
self.set_configuration_feature("auto_change_nozzle", *args)
|
self.set_configuration_feature("auto_change_nozzle", *args)
|
||||||
|
|
||||||
|
def set_configuration_string(self, feature_name, str):
|
||||||
|
script = KlippyGcodes.set_save_variables(feature_name, str)
|
||||||
|
self._screen._send_action(None, "printer.gcode.script", {"script": script})
|
||||||
|
logging.info(f"Set {feature_name}: {str}")
|
||||||
|
|
||||||
def set_configuration_feature(self, feature_name, *args):
|
def set_configuration_feature(self, feature_name, *args):
|
||||||
enable_feature = any(args)
|
enable_feature = any(args)
|
||||||
script_value = True if enable_feature else False
|
script_value = True if enable_feature else False
|
||||||
@ -143,3 +194,10 @@ class Panel(ScreenPanel):
|
|||||||
self.menu_list["auto_change_nozzle"].set_active(variables["auto_change_nozzle"])
|
self.menu_list["auto_change_nozzle"].set_active(variables["auto_change_nozzle"])
|
||||||
else:
|
else:
|
||||||
self.menu_list["auto_change_nozzle"].set_active(False)
|
self.menu_list["auto_change_nozzle"].set_active(False)
|
||||||
|
|
||||||
|
if self._printer.get_macro("_door_detection"):
|
||||||
|
if "door_detect" in variables:
|
||||||
|
model = self.menu_list["door_open_detection"].get_model()
|
||||||
|
for i, row in enumerate(model):
|
||||||
|
if row[0] == variables["door_detect"]:
|
||||||
|
self.menu_list["door_open_detection"].set_active(i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user