forked from CreatBot/CreatBotKlipperScreen
Squashed commit of the following: commit02c7556cda
Merge:6bfa42e0
991003e6
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:07:54 2024 +0800 Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release commit991003e6cb
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:03:34 2024 +0800 优化完整 简体中文和繁体中文的翻译 commit1a177e90d0
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 14:10:03 2024 +0800 优化排除对象的英文语法错误 commite8d509cb6c
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 16:40:52 2024 +0800 优化耗材检测显示内容 commit1b7670485a
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 14:56:25 2024 +0800 完善断料自动切头功能描述 commitecc0c3dd16
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 13:40:01 2024 +0800 实现弹窗翻译功能 commitbc6d60fa18
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 09:53:16 2024 +0800 优化不合理名称和不合理大小写 commit2e650926bd
Author: zkk <1007518571@qq.com> Date: Thu Dec 26 15:06:11 2024 +0800 修复10寸屏幕偏移值微调页面出界问题 commitc481b551f7
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 15:28:26 2024 +0800 优化移轴设置页面没有返回按钮的问题 commit2b3c9936bd
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 10:05:04 2024 +0800 删除移动设置页面中轴反转的选项 commit5e37d59497
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 09:05:03 2024 +0800 优化选择语言标题 commit5214c3697b
Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:57:41 2024 +0800 增加设置hostname功能 commit3709a7465c
Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:43:46 2024 +0800 增加工厂设置中打包模式 commit0c2a2618be
Author: zkk <1007518571@qq.com> Date: Mon Dec 23 16:25:37 2024 +0800 实现恢复出厂设置功能 commite3a38f8561
Author: zkk <1007518571@qq.com> Date: Mon Dec 23 15:48:17 2024 +0800 一点格式化 commit4e9e452e8b
Author: zkk <1007518571@qq.com> Date: Sat Dec 21 14:20:22 2024 +0800 优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头 commit3b85e8e8d5
Merge:882850db
10ec2029
Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:26:08 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit882850dbde
Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:21:16 2024 +0800 补充双喷头偏移校准页面二维码图片 commit10ec2029eb
Author: ruipeng <1041589370@qq.com> Date: Wed Dec 18 17:17:18 2024 +0800 增加自动切换喷头开关选项 commit3d6eed9d95
Author: zkk <1007518571@qq.com> Date: Mon Dec 16 16:33:34 2024 +0800 喷头偏移值校准功能的实现 commit40ecbb3ea4
Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:20:00 2024 +0800 z探针校准时指定默认激活工具头为第一个头 commitbce3caa409
Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:19:19 2024 +0800 优化z探针校准时候移动过慢问题 commit6bfa42e036
Merge:1a87ced3
4f3aa9aa
Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:33:58 2024 +0800 Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release commit4f3aa9aa4c
Merge:e3fd413d
1a69b518
Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:30:00 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit1a69b5180d
Author: ruipeng <1041589370@qq.com> Date: Wed Dec 11 11:44:36 2024 +0800 新增D600pro2、D1000的V0版机型 commite3fd413d62
Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:34:13 2024 +0800 修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug commit594fb668fe
Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:25:04 2024 +0800 设置自适应调平选项默认为关闭状态 commit1a87ced3f5
Merge:629416d1
6064a6e1
Author: zkk <1007518571@qq.com> Date: Fri Nov 29 10:18:32 2024 +0800 Merge branch 'develop' into release # Conflicts: # panels/advanced.py # panels/nozzle_offset.py # panels/offset_fine_tune.py # panels/zcalibrate.py
118 lines
5.4 KiB
Python
118 lines
5.4 KiB
Python
import logging
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk, Pango
|
|
from ks_includes.screen_panel import ScreenPanel
|
|
from ks_includes.widgets.objectmap import ObjectMap
|
|
|
|
|
|
class Panel(ScreenPanel):
|
|
def __init__(self, screen, title):
|
|
title = title or _("Exclude Object")
|
|
super().__init__(screen, title)
|
|
self._screen = screen
|
|
self.object_list = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, hexpand=True, vexpand=True)
|
|
self.buttons = {}
|
|
self.current_object = self._gtk.Button("extrude", "", scale=self.bts, position=Gtk.PositionType.LEFT, lines=1)
|
|
self.current_object.connect("clicked", self.exclude_current)
|
|
self.current_object.set_vexpand(False)
|
|
self.excluded_objects = self._printer.get_stat("exclude_object", "excluded_objects")
|
|
logging.info(f'Excluded: {self.excluded_objects}')
|
|
self.objects = self._printer.get_stat("exclude_object", "objects")
|
|
self.labels['map'] = None
|
|
for obj in self.objects:
|
|
logging.info(f"Adding {obj['name']}")
|
|
self.add_object(obj["name"])
|
|
|
|
scroll = self._gtk.ScrolledWindow()
|
|
scroll.add(self.object_list)
|
|
|
|
grid = Gtk.Grid(column_homogeneous=True)
|
|
grid.attach(self.current_object, 0, 0, 2, 1)
|
|
grid.attach(Gtk.Separator(), 0, 1, 2, 1)
|
|
|
|
if self.objects and "polygon" in self.objects[0]:
|
|
self.labels['map'] = ObjectMap(self._screen, self._printer, self._gtk.font_size)
|
|
if self._screen.vertical_mode:
|
|
grid.attach(self.labels['map'], 0, 2, 2, 1)
|
|
grid.attach(scroll, 0, 3, 2, 1)
|
|
else:
|
|
grid.attach(self.labels['map'], 0, 2, 1, 1)
|
|
grid.attach(scroll, 1, 2, 1, 1)
|
|
else:
|
|
grid.attach(scroll, 0, 2, 2, 1)
|
|
|
|
self.content.add(grid)
|
|
self.content.show_all()
|
|
|
|
def add_object(self, name):
|
|
if name not in self.buttons and name not in self.excluded_objects:
|
|
self.buttons[name] = self._gtk.Button(label=name.replace("_", " "))
|
|
self.buttons[name].get_children()[0].set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
|
self.buttons[name].get_children()[0].set_line_wrap(True)
|
|
self.buttons[name].connect("clicked", self.exclude_object, name)
|
|
self.buttons[name].get_style_context().add_class("frame-item")
|
|
self.object_list.add(self.buttons[name])
|
|
|
|
def exclude_object(self, widget, name):
|
|
if len(self.excluded_objects) == len(self.objects) - 1:
|
|
# Do not exclude the last object, this is a workaround for a bug of klipper that starts
|
|
# to move the toolhead really fast skipping gcode until the file ends
|
|
# Remove this if they fix it.
|
|
self._screen._confirm_send_action(
|
|
widget,
|
|
_("Are you sure you wish to cancel this print?"),
|
|
"printer.print.cancel",
|
|
)
|
|
return
|
|
script = {"script": f"EXCLUDE_OBJECT NAME={name}"}
|
|
self._screen._confirm_send_action(
|
|
widget,
|
|
_("Are you sure you want to exclude the object?") + f"\n\n{name}",
|
|
"printer.gcode.script",
|
|
script
|
|
)
|
|
|
|
def exclude_current(self, widget):
|
|
self.exclude_object(widget, f"{self.current_object.get_label()}")
|
|
|
|
def process_update(self, action, data):
|
|
if action == "notify_status_update":
|
|
if "exclude_object" in data:
|
|
if "object" in data["exclude_object"]: # Update objects
|
|
self.objects = data["exclude_object"]["objects"]
|
|
logging.info(f'Objects: {data["exclude_object"]["objects"]}')
|
|
for obj in self.buttons:
|
|
self.object_list.remove(self.buttons[obj])
|
|
self.buttons = {}
|
|
for obj in self.objects:
|
|
logging.info(f"Adding {obj['name']}")
|
|
self.add_object(obj["name"])
|
|
self.content.show_all()
|
|
if "current_object" in data["exclude_object"]: # Update objects
|
|
# Update current objects
|
|
if data["exclude_object"]["current_object"]:
|
|
self.current_object.set_label(f'{data["exclude_object"]["current_object"].replace("_", " ")}')
|
|
self.update_graph()
|
|
if "excluded_objects" in data["exclude_object"]: # Update objects
|
|
# Update excluded objects
|
|
logging.info(f'Excluded objects: {data["exclude_object"]["excluded_objects"]}')
|
|
self.excluded_objects = data["exclude_object"]["excluded_objects"]
|
|
for name in self.excluded_objects:
|
|
if name in self.buttons:
|
|
self.object_list.remove(self.buttons[name])
|
|
self.update_graph()
|
|
if len(self.excluded_objects) == len(self.objects):
|
|
self._screen._menu_go_back()
|
|
elif action == "notify_gcode_response" and "Excluding object" in data:
|
|
self._screen.show_popup_message(data, level=1)
|
|
self.update_graph()
|
|
|
|
def activate(self):
|
|
self.update_graph()
|
|
|
|
def update_graph(self):
|
|
if self.labels['map']:
|
|
self.labels['map'].queue_draw()
|