@@ -36,13 +36,8 @@ def remove_print_settings(self):
3636 self .remove_element (print_setting )
3737
3838 def remove_params (self ):
39- if not self .svg .selection :
40- xpath = ".//svg:path|.//svg:circle|.//svg:rect|.//svg:ellipse"
41- elements = find_elements (self .svg , xpath )
42- self .remove_inkstitch_attributes (elements )
43- else :
44- elements = self .get_selected_elements ()
45- self .remove_inkstitch_attributes (elements )
39+ elements = self .get_elements ()
40+ self .remove_inkstitch_attributes (elements , self .options .del_params )
4641
4742 def remove_all_commands (self ):
4843 xpath = ".//svg:g[starts-with(@id,'command_group')]"
@@ -76,9 +71,7 @@ def remove_specific_commands(self, command):
7671 symbols = f".//*[starts-with(@id, 'inkstitch_{ command } ')]"
7772 self .remove_elements (symbols )
7873
79- def remove_selected_commands (self ):
80- del_option = self .options .del_commands
81- elements = self .get_selected_elements ()
74+ def remove_commands_from_selection (self , elements , del_option ):
8275 for element in elements :
8376 if is_command_symbol (element ) and (del_option in element .get ('xlink:href' ) or del_option == 'all' ):
8477 group = element .getparent ()
@@ -94,15 +87,28 @@ def remove_selected_commands(self):
9487 group .delete ()
9588
9689 def remove_commands (self ):
90+ elements = self .get_elements ()
91+ del_option = self .options .del_commands
92+
93+ # trim and stop params are percepted as commands,
94+ # so let's remove them as well
95+ if del_option in ['all' , 'trim' ]:
96+ self .remove_inkstitch_attributes (elements , 'trim_after' )
97+ elif del_option in ['all' , 'stop' ]:
98+ self .remove_inkstitch_attributes (elements , 'stop_after' )
99+
97100 if self .svg .selection :
98- self .remove_selected_commands ( )
101+ self .remove_commands_from_selection ( elements , del_option )
99102 elif self .options .del_commands == "all" :
100103 self .remove_all_commands ()
101104 else :
102105 self .remove_specific_commands (self .options .del_commands )
103106
104- def get_selected_elements (self ):
105- return self .svg .selection .get (ShapeElement )
107+ def get_elements (self ):
108+ if self .svg .selection :
109+ return self .svg .selection .get (ShapeElement )
110+ else :
111+ return self .svg .descendants ().filter (ShapeElement )
106112
107113 def remove_elements (self , xpath ):
108114 elements = find_elements (self .svg , xpath )
@@ -112,8 +118,7 @@ def remove_elements(self, xpath):
112118 def remove_element (self , element ):
113119 element .delete ()
114120
115- def remove_inkstitch_attributes (self , elements ):
116- param_to_remove = self .options .del_params
121+ def remove_inkstitch_attributes (self , elements , param_to_remove ):
117122 for element in elements :
118123 for attrib in element .attrib :
119124 if attrib .startswith (NSS ['inkstitch' ], 1 ):
0 commit comments