Skip to content

Commit

Permalink
Merge pull request meerk40t#2583 from meerk40t/warning
Browse files Browse the repository at this point in the history
Allow filtering / suppressing warning indicator
  • Loading branch information
jpirnay authored Sep 17, 2024
2 parents 4852d83 + cff1b98 commit 5d3f495
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 23 deletions.
99 changes: 76 additions & 23 deletions meerk40t/gui/gui_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,23 @@ def on_click(self, *args):
else:
self.state = INACTIVE

CONCERN_LOW = 1
CONCERN_NORMAL = 2
CONCERN_CRITICAL = 3

class Warnings:
def __init__(self, context=None, button=None, *args, **kwargs):
self.context = context
self.button = button
self._concerns = list()
self._device_acceleration_info = dict()
self.context.setting(int, "concern_level", 1)
self.context.kernel.register(
self.button,
{
"label": _("Warning"),
"icon": icon_warning,
"rule_visible": lambda d: len(self._concerns) > 0,
"rule_visible": lambda d: len(self.concerns) > 0,
"action": self.show_concerns,
"tip": _("There are issues with your project"),
"size": STD_ICON_SIZE,
Expand All @@ -223,11 +227,39 @@ def __init__(self, context=None, button=None, *args, **kwargs):

@property
def concerns(self):
return "\n".join(self._concerns)
list_critical = []
list_normal = []
list_low = []
warn_level = self.context.setting(int, "concern_level", 1)

for msg, level in self._concerns:
if level < warn_level:
continue
if level == CONCERN_LOW:
list_low.append(msg)
if level == CONCERN_NORMAL:
list_normal.append(msg)
if level == CONCERN_CRITICAL:
list_critical.append(msg)
s = ""
if len(list_critical):
if s:
s += "\n"
s += "CRITICAL:\n" + "\n".join(list_critical)
if len(list_normal):
if s:
s += "\n"
s += "NORMAL:\n" + "\n".join(list_normal)
if len(list_low):
if s:
s += "\n"
s += "LOW:\n" + "\n".join(list_low)
return s

def show_concerns(self, *args):
if len(self._concerns):
wx.MessageBox(self.concerns, _("Warning"), style=wx.OK | wx.ICON_WARNING)
msg = self.concerns
if msg:
wx.MessageBox(msg, _("Warning"), style=wx.OK | wx.ICON_WARNING)

def warning_indicator(self):
def has_ambitious_operations(maxspeed, optypes):
Expand Down Expand Up @@ -390,54 +422,75 @@ def has_hidden_elements():
flag = True
count += 1
return flag, count

self._concerns.clear()
max_speed = getattr(self.context.device, "max_vector_speed", None)
if has_ambitious_operations(max_speed, ("op cut", "op engrave")):
self._concerns.append(
_("- Vector operations are too fast.")
+ "\n "
+ _("Could lead to erratic stepper behaviour and incomplete burns.")
(
_("- Vector operations are too fast.")
+ "\n "
+ _("Could lead to erratic stepper behaviour and incomplete burns."),
CONCERN_CRITICAL
)
)
max_speed = getattr(self.context.device, "max_raster_speed", None)
if has_ambitious_operations(max_speed, ("op raster", "op image")):
self._concerns.append(
_("- Raster operations are too fast.")
+ "\n "
+ _("Could lead to erratic stepper behaviour and incomplete burns.")
(
_("- Raster operations are too fast.")
+ "\n "
+ _("Could lead to erratic stepper behaviour and incomplete burns."),
CONCERN_CRITICAL
)
)
if has_objects_outside():
self._concerns.append(
_("- Elements are lying outside the burnable area.")
+ "\n "
+ _("Could lead to the laserhead bumping into the rails.")
(
_("- Elements are lying outside the burnable area.")
+ "\n "
+ _("Could lead to the laserhead bumping into the rails."),
CONCERN_CRITICAL
)
)
flag, info = has_close_to_edge_rasters()
if flag:
self._concerns.append(
_("- Raster operations get very close to the edge.")
+ "\n "
+ _("Could lead to the laserhead bumping into the rails.")
+ "\n "
+ info
(
_("- Raster operations get very close to the edge.")
+ "\n "
+ _("Could lead to the laserhead bumping into the rails.")
+ "\n "
+ info,
CONCERN_NORMAL
)
)

non_assigned, non_burn = self.context.elements.have_unburnable_elements()
if non_assigned:
self._concerns.append(
_("- Elements aren't assigned to an operation and will not be burnt")
(
_("- Elements aren't assigned to an operation and will not be burnt"),
CONCERN_NORMAL
)
)
if non_burn:
self._concerns.append(
_(
"- Some operations containing elements aren't active, so some elements will not be burnt"
(
_(
"- Some operations containing elements aren't active, so some elements will not be burnt"
),
CONCERN_LOW
)
)

non_visible, info = has_hidden_elements()
if non_visible:
self._concerns.append(
_("- Elements are hidden and will not be burnt") + f" ({info})\n"
(
_("- Elements are hidden and will not be burnt") + f" ({info})\n",
CONCERN_LOW
)
)

self.context.signal("icons")
19 changes: 19 additions & 0 deletions meerk40t/gui/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ def gui_start(**kwargs):
"section": "Tooltips",
"signals": "restart",
},
{
"attr": "concern_level",
"object": kernel.root,
"default": 0,
"type": int,
"style": "option",
"display": (
_("Low + Normal + Critical"),
_("Normal + Critical"),
_("Critical"),
_("Ignore all"),
),
"choices": (1, 2, 3, 4),
"label": _("Level"),
"tip": _("Which warning severity level do you want to recognize"),
"page": "Gui",
"section": "Warning-Indicator",
"signals": "icons",
},
]
kernel.register_choices("preferences", choices)

Expand Down

0 comments on commit 5d3f495

Please sign in to comment.