Skip to content

Commit 5f853ed

Browse files
author
manuelgitgomes
committed
#374 Bugfix to the keyboard commands
1 parent ad8d4c4 commit 5f853ed

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

atom_calibration/scripts/dataset_playback

+14-15
Original file line numberDiff line numberDiff line change
@@ -142,37 +142,39 @@ def signal_handler(sig, frame, dataset, args):
142142

143143

144144
# 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
146147
idx_collection = int(selection['collection_key'])
148+
idx_max_collection = len(dataset['collections'].keys()) - 1
147149

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.
149154
if idx_collection < idx_max_collection:
150155
selection['previous_collection_key'] = selection['collection_key']
151-
# print("Before: "+idx_collection)
152156
selection['collection_key'] = str(idx_collection + 1)
153-
# print("After: " + collections_list[idx_collection])
154157
print('Changed selected_collection_key to ' +
155-
str(collections_list[idx_collection]))
158+
selection['collection_key'])
156159
else:
157160
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.
159162
if idx_collection > 0:
160163
selection['previous_collection_key'] = selection['collection_key']
161164
selection['collection_key'] = str(idx_collection - 1)
162165
print('Changed selected_collection_key to ' +
163-
str(collections_list[idx_collection]))
166+
selection['collection_key'])
164167
else:
165168
print(Fore.RED + 'This is the first collection!!' + Fore.RESET)
166-
elif key.char.lower() == 's':
169+
elif key == "'s'": # Saves dataset.
167170
output_file = '/'.join(args['json_file'].split('/')[:-1]) + '/dataset_corrected.json'
168171

169172
# TODO why not use the standard in atom_core.dataset_io.saveResultsJSON
170173
saveResultsJSON(output_file, dataset, freeze_dataset=True)
171174
# atom_core.dataset_io.saveResultsJSON(output_file, D, freeze_dataset = True)
172175

173176
print('A new dataset was saved in ' + output_file)
174-
175-
elif key.char.lower() == 'q':
177+
elif key == "'q'": # Saves dataset and quits.
176178
output_file = '/'.join(args['json_file'].split('/')[:-1]) + '/dataset_corrected.json'
177179

178180
# 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
184186
print('Exiting ...')
185187
selection['exit'] = True
186188

189+
187190
def selected_points_callback(selected_point_cloud, models):
188191
global idx_collection
189192
selected_collection_key = list(models['dataset']['collections'].keys())[
@@ -540,11 +543,7 @@ def main():
540543
# ---------------------------------------
541544
# --- Define callback to change idx_collection
542545
# ---------------------------------------
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)
548547
listener = keyboard.Listener(
549548
on_press=key_pressed_partial)
550549
listener.start()

0 commit comments

Comments
 (0)