Mercurial > repos > rv43 > tomo
diff general.py @ 56:ca61007a60fa draft
"planemo upload for repository https://github.com/rolfverberg/galaxytools commit fc9b26da497e467c28b0adf3f94422b4cb61f59c"
author | rv43 |
---|---|
date | Tue, 02 Aug 2022 19:52:47 +0000 |
parents | 26f99fdd8d61 |
children | 98a83f03d91b |
line wrap: on
line diff
--- a/general.py Thu Jul 28 17:44:49 2022 +0000 +++ b/general.py Tue Aug 02 19:52:47 2022 +0000 @@ -334,6 +334,7 @@ i = input() if isinstance(i, str) and not len(i): v = default + print(f'{v}') else: v = literal_eval(i) if inset and v not in inset: @@ -389,6 +390,7 @@ i = input() if isinstance(i, str) and not len(i): v = default + print(f'{v}') else: v = literal_eval(i) except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError): @@ -460,6 +462,7 @@ i = input() if isinstance(i, str) and not len(i): i = default + print(f'{i}') if i is not None and i.lower() in 'yes': v = True elif i is not None and i.lower() in 'no': @@ -487,16 +490,25 @@ print(f'{header} (1, {len(items)}){default_string}:') for i, choice in enumerate(items): print(f' {i+1}: {choice}') - choice = input() - if isinstance(choice, str) and not len(choice): - choice = items.index(default) - else: - choice = literal_eval(choice) - if isinstance(choice, int) and 1 <= choice <= len(items): - choice -= 1 + try: + choice = input() + if isinstance(choice, str) and not len(choice): + choice = items.index(default) + print(f'{choice+1}') else: - print(f'Illegal choice, enter a number between 1 and {len(items)}') - choice = input_menu(items, default) + choice = literal_eval(choice) + if isinstance(choice, int) and 1 <= choice <= len(items): + choice -= 1 + else: + raise ValueError + except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError): + choice = None + except: + print('Unexpected error') + raise + if choice is None: + print(f'Illegal choice, enter a number between 1 and {len(items)}') + choice = input_menu(items, default) return choice def create_mask(x, bounds=None, reverse_mask=False, current_mask=None): @@ -525,7 +537,7 @@ return mask def draw_mask_1d(ydata, xdata=None, current_index_ranges=None, current_mask=None, - select_mask=True, num_index_ranges_max=None, title=None, legend=None): + select_mask=True, num_index_ranges_max=None, title=None, legend=None, test_mode=False): def draw_selections(ax): ax.clear() ax.set_title(title) @@ -679,30 +691,32 @@ if current_include[-1][1] < num_data-1: current_exclude.append((current_include[-1][1]+1, num_data-1)) - # Set up matplotlib figure - plt.close('all') - fig, ax = plt.subplots() - plt.subplots_adjust(bottom=0.2) - draw_selections(ax) + if not test_mode: - # Set up event handling for click-and-drag range selection - cid_click = fig.canvas.mpl_connect('button_press_event', onclick) - cid_release = fig.canvas.mpl_connect('button_release_event', onrelease) + # Set up matplotlib figure + plt.close('all') + fig, ax = plt.subplots() + plt.subplots_adjust(bottom=0.2) + draw_selections(ax) + + # Set up event handling for click-and-drag range selection + cid_click = fig.canvas.mpl_connect('button_press_event', onclick) + cid_release = fig.canvas.mpl_connect('button_release_event', onrelease) - # Set up confirm / clear range selection buttons - confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm') - clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear') - cid_confirm = confirm_b.on_clicked(confirm_selection) - cid_clear = clear_b.on_clicked(clear_last_selection) + # Set up confirm / clear range selection buttons + confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm') + clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear') + cid_confirm = confirm_b.on_clicked(confirm_selection) + cid_clear = clear_b.on_clicked(clear_last_selection) - # Show figure - plt.show(block=True) + # Show figure + plt.show(block=True) - # Disconnect callbacks when figure is closed - fig.canvas.mpl_disconnect(cid_click) - fig.canvas.mpl_disconnect(cid_release) - confirm_b.disconnect(cid_confirm) - clear_b.disconnect(cid_clear) + # Disconnect callbacks when figure is closed + fig.canvas.mpl_disconnect(cid_click) + fig.canvas.mpl_disconnect(cid_release) + confirm_b.disconnect(cid_confirm) + clear_b.disconnect(cid_clear) # Swap selection depending on select_mask if not select_mask: