Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude Objects #4716

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Formatting fixes
Signed-off-by: Troy Jacobson <troy.d.jacobson@gmail.com>
  • Loading branch information
troy-jacobson committed Feb 20, 2022
commit ab2e1466b80c697c5e9ed87a13340ceb4f3b48ba
9 changes: 6 additions & 3 deletions klippy/extras/exclude_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def _setup_transform(self):
if not self.next_transform:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's preferable to use if self.next_transform is None when checking an external object because the external object could override the truth check.

tuning_tower = self.printer.lookup_object('tuning_tower', None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to specify the None default parameter here (and on line 81), as the tuning_tower is always loaded by the toolhead. If by some chance it weren't available the call to lookup_object would raise an exception, however that is probably preferable to the AttributeError raised by calling is_testing() on a NoneType.

if self.gcode_move.move_transform == tuning_tower:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't peek into another object's members, so we either need to add a get_move_transform() method to gcode_move, or add the is_testing() method to tuning_tower and perform the check that way. This would apply to the check on line 80 as well.

logging.info('The ExcludeObject move transform is not being loaded due to Tuning tower being Active')
logging.info('The ExcludeObject move transform is not being '
'loaded due to Tuning tower being Active')
return

self.next_transform = self.gcode_move.set_move_transform(self,
Expand All @@ -78,7 +79,8 @@ def _reset_file(self):
self.current_object = None
if self.next_transform:
if self.gcode_move.move_transform != self:
logging.info("ExcludeObject move transform is not being unregistered because it is not at the head of the transform chain.")
logging.info('ExcludeObject move transform is not being '
'unregistered because it is not at the head of the transform chain.')
return

self.gcode_move.set_move_transform(self.next_transform, force=True)
Expand Down Expand Up @@ -239,7 +241,8 @@ def cmd_DEFINE_OBJECT(self, params):
logging.info('The definition for %s was not registered '
'since the Exclude Object move transform is not enabled. This '
'is most likely due to an active Tuning Tower command.', name)
params.respond_info("The Exclude Object module is active while a Tuning Tower test is in progress.")
params.respond_info("The Exclude Object module is active while a Tuning "
"Tower test is in progress.")
return

center = params.get('CENTER', default=None)
Expand Down