@@ -142,37 +142,39 @@ def signal_handler(sig, frame, dataset, args):
142
142
143
143
144
144
# keyboard listener
145
- def key_pressed (key , idx_max_collection , collections_list , selection , dataset , args ):
145
+ def key_pressed (key , selection , dataset , args ):
146
+ # Shortcut variables
146
147
idx_collection = int (selection ['collection_key' ])
148
+ idx_max_collection = len (dataset ['collections' ].keys ()) - 1
147
149
148
- if key == keyboard .Key .right :
150
+ # Convert from type to string to keep uniform.
151
+ key = str (key )
152
+
153
+ if key == 'Key.right' : # Move to collection + 1.
149
154
if idx_collection < idx_max_collection :
150
155
selection ['previous_collection_key' ] = selection ['collection_key' ]
151
- # print("Before: "+idx_collection)
152
156
selection ['collection_key' ] = str (idx_collection + 1 )
153
- # print("After: " + collections_list[idx_collection])
154
157
print ('Changed selected_collection_key to ' +
155
- str ( collections_list [ idx_collection ]) )
158
+ selection [ 'collection_key' ] )
156
159
else :
157
160
print (Fore .RED + 'This is the last collection!!' + Fore .RESET )
158
- elif key == keyboard . Key .left :
161
+ elif key == ' Key.left' : # Move to collection - 1.
159
162
if idx_collection > 0 :
160
163
selection ['previous_collection_key' ] = selection ['collection_key' ]
161
164
selection ['collection_key' ] = str (idx_collection - 1 )
162
165
print ('Changed selected_collection_key to ' +
163
- str ( collections_list [ idx_collection ]) )
166
+ selection [ 'collection_key' ] )
164
167
else :
165
168
print (Fore .RED + 'This is the first collection!!' + Fore .RESET )
166
- elif key . char . lower () == 's' :
169
+ elif key == " 's'" : # Saves dataset.
167
170
output_file = '/' .join (args ['json_file' ].split ('/' )[:- 1 ]) + '/dataset_corrected.json'
168
171
169
172
# TODO why not use the standard in atom_core.dataset_io.saveResultsJSON
170
173
saveResultsJSON (output_file , dataset , freeze_dataset = True )
171
174
# atom_core.dataset_io.saveResultsJSON(output_file, D, freeze_dataset = True)
172
175
173
176
print ('A new dataset was saved in ' + output_file )
174
-
175
- elif key .char .lower () == 'q' :
177
+ elif key == "'q'" : # Saves dataset and quits.
176
178
output_file = '/' .join (args ['json_file' ].split ('/' )[:- 1 ]) + '/dataset_corrected.json'
177
179
178
180
# TODO why not use the standard in atom_core.dataset_io.saveResultsJSON
@@ -184,6 +186,7 @@ def key_pressed(key, idx_max_collection, collections_list, selection, dataset, a
184
186
print ('Exiting ...' )
185
187
selection ['exit' ] = True
186
188
189
+
187
190
def selected_points_callback (selected_point_cloud , models ):
188
191
global idx_collection
189
192
selected_collection_key = list (models ['dataset' ]['collections' ].keys ())[
@@ -540,11 +543,7 @@ def main():
540
543
# ---------------------------------------
541
544
# --- Define callback to change idx_collection
542
545
# ---------------------------------------
543
- # key_pressed_partial = partial(key_pressed, idx_max_collection=len(collections_list) - 1,
544
- # collections_list=collections_list, dataset=opt.data_models['dataset'], args=args)
545
- key_pressed_partial = partial (key_pressed , idx_max_collection = len (collections_list ) - 1 ,
546
- collections_list = collections_list , selection = selection ,
547
- dataset = opt .data_models ['dataset' ], args = args )
546
+ key_pressed_partial = partial (key_pressed , selection = selection , dataset = opt .data_models ['dataset' ], args = args )
548
547
listener = keyboard .Listener (
549
548
on_press = key_pressed_partial )
550
549
listener .start ()
0 commit comments