def _set_labelframe_files(self): frame = self.frame_files opt = {'padx': 5, 'pady': 5, 'sticky': 'nw'} self.combobox_files = tkw.ComboboxWidget( frame, align='horizontal', title='Show file', items=self.settings_files.get_list(), callback_target=self._on_select_file, **opt) frame_save = tk.Frame(frame) frame_save.grid(row=0, column=1, **opt) tkw.grid_configure(frame, nr_rows=1, nr_columns=2) self.button_save = tk.Button(frame_save, text='Save', command=self._save_file) self.button_save.grid(row=0, column=0, **opt) self.button_save_as = tk.Button(frame_save, text='Save as', command=self._save_file_as) self.button_save_as.grid(row=0, column=1, **opt) tkw.grid_configure(frame_save, nr_rows=0, nr_columns=2) self.combobox_files.set_value( self.user.sampling_type_settings.setdefault( 'show_file', self.settings_files.get_list()[0]))
def _set_frame_color_maps(self): labelframe = self.labelframe_color_maps frame = tk.Frame(labelframe) frame.grid(row=0, column=0, sticky='nw') tkw.grid_configure(labelframe) cmap_list = core.Colormaps().get_list() self.widget_selected_cmap = tkw.ComboboxWidget( frame, items=cmap_list, title='', callback_target=self._on_select_colormap, row=0, column=0, sticky='w') # self.button_save_cmap = tk.Button(frame, text='Save colormaps', command=self._save_colormap, bg='lightgreen') # self.button_save_cmap.grid(row=0, column=1, sticky='w', padx=5, pady=5) self.widget_listbox_cmap = tkw.ListboxSelectionWidget( frame, row=1, column=0, sticky='nw', target=self._on_select_par_for_colormap) tkw.grid_configure(frame, nr_rows=2) self.current_pars_in_cmap = {}
def _set_labelframe_dependent_parameters(self): frame = self.frame_dependent_parameters opt = {'padx': 5, 'pady': 5, 'sticky': 'nw'} frame_left = tk.Frame(frame) frame_left.grid(row=0, column=0, **opt) frame_right = tk.Frame(frame) frame_right.grid(row=0, column=1, **opt) tkw.grid_configure(frame, nr_columns=2) # Frame left tk.Label(frame_left, text='If this parameter is flagged:').grid(row=0, column=0, columnspan=2, **opt) self.combobox_widget_dependent_parameters = tkw.ComboboxWidget( frame_left, callback_target=self._on_select_dependent_parameter, columnspan=2, row=1) self.button_add_dependent_parameter = tk.Button( frame_left, text='Add', command=self._add_dependent_parameter) self.button_add_dependent_parameter.grid(row=2, column=0, **opt) self.button_remove_dependent_parameter = tk.Button( frame_left, text='Remove', command=self._remove_dependent_parameter) self.button_remove_dependent_parameter.grid(row=2, column=1, **opt) self.button_parameter_file = tk.Button( frame_left, text='Load parameter file', command=self._load_parameter_file) self.button_parameter_file.grid(row=3, column=0, columnspan=2, **opt) tkw.grid_configure(frame_left, nr_columns=2, nr_rows=4) # Frame right prop = {'height': 6} tk.Label(frame_right, text='The selected parameters below are also flagged:').grid( row=0, column=0, **opt) self.listbox_selection_widget_dependent_parameters = tkw.ListboxSelectionWidget( frame_right, prop_items=prop, prop_selected=prop, sort_selected=True, target=self. _on_select_listbox_selection_widget_dependent_parameters, row=1, sticky='w') tkw.grid_configure(frame_right, nr_rows=2, nr_columns=1)
def _set_frame(self): self.combobox_metadata_files = tkw.ComboboxWidget(self, title='Show metadata for file', prop_combobox={'width': 60}, sticky='w', callback_target=self._update_treeview) self.treeview_metadata = tkw.TreeviewWidget(self, columns=['Metadata', 'Value'], row=1) tkw.grid_configure(self, nr_rows=2, r1=20)
def _create_new_user(self): def _create_user(): source_user = widget_source_user.get_value().strip() new_user_name = widget_new_user_name.get_value().strip() if not new_user_name: gui.show_information('Create user', 'No user name given!') return if not source_user: source_user = None try: self.user_manager.add_user(new_user_name, source_user) if intvar_load_user.get(): self._change_user(new_user_name) self._update_menubar_users() except GUIExceptionUserError as e: gui.show_error('Creating user', '{}\nUser not created. Try again!'.format(e.message)) popup_frame.destroy() def _cancel(): popup_frame.destroy() popup_frame = tk.Toplevel(self) current_user_list = [''] + self.user_manager.get_user_list() grid = dict(sticky='w', padx=5, pady=5) widget_source_user = tkw.ComboboxWidget(popup_frame, title='Create copy of user', items=current_user_list, **grid) widget_new_user_name = tkw.EntryWidget(popup_frame, row=1, **grid) intvar_load_user = tk.IntVar() widget_checkbutton_load_user = tk.Checkbutton(popup_frame, text="Load new user", variable=intvar_load_user) widget_checkbutton_load_user.grid(row=1, column=1, **grid) intvar_load_user.set(1) widget_button_done = tk.Button(popup_frame, text='Create user', command=_create_user) widget_button_done.grid(row=2, column=0, **grid) widget_button_done = tk.Button(popup_frame, text='Cancel', command=_cancel) widget_button_done.grid(row=2, column=1, **grid) tkw.grid_configure(popup_frame, nr_rows=3, nr_columns=2)
def _set_frame_plot_style(self): labelframe = self.labelframe_plot_style frame = tk.Frame(labelframe) frame.grid(row=0, column=0, sticky='nw') tkw.grid_configure(labelframe) style_list = plt.style.available self.widget_selected_plotstyle = tkw.ComboboxWidget( frame, items=style_list, title='', callback_target=self._on_select_plotstyle, row=0, column=0, sticky='nw') self.widget_selected_plotstyle.set_value( self.user.layout.setdefault('plotstyle', self.settings['default']['plotstyle'])) tk.Label( frame, text= 'Note that you have to restart\nthe program to activate the\nnew plot style.' ).grid(row=1, column=0, pady=10, sticky='nw') tkw.grid_configure(frame, nr_rows=2)
def _add_dependent_parameter(self): def _add_parameter(): parameter = widget_parameter.get_value() if not parameter: main_gui.show_information('Create dependencies', 'No parameter selected') return try: current_par = self.combobox_widget_dependent_parameters.get_value( ) # Add parameter to settings self.settings_object.add_data('dependent_parameters', parameter, []) print(self.settings_object.get_data('dependent_parameters')) # Set parameter list self.combobox_widget_dependent_parameters.update_items( self._get_dependent_parameters_from_settings()) if intvar_show_parameter.get(): self.combobox_widget_dependent_parameters.set_value( parameter) else: self.combobox_widget_dependent_parameters.set_value( current_par) self._update_listbox_selection_widget_dependent_parameters() except GUIException as e: main_gui.show_error( 'Creating dependencies', '{}\nSomething went wrong Try again!'.format(e.message)) popup_frame.destroy() def _cancel(): popup_frame.destroy() popup_frame = tk.Toplevel(self) current_parameter_list = self._get_parameter_list_from_user() grid = dict(sticky='w', padx=5, pady=5) widget_parameter = tkw.ComboboxWidget( popup_frame, title='Add dependent parameters for parameter', items=current_parameter_list, **grid) intvar_show_parameter = tk.IntVar() widget_checkbutton_show_parameter = tk.Checkbutton( popup_frame, text="Show dependencies", variable=intvar_show_parameter) widget_checkbutton_show_parameter.grid(row=1, column=1, **grid) intvar_show_parameter.set(1) widget_button_done = tk.Button(popup_frame, text='Add parameter', command=_add_parameter) widget_button_done.grid(row=2, column=0, **grid) widget_button_done = tk.Button(popup_frame, text='Cancel', command=_cancel) widget_button_done.grid(row=2, column=1, **grid) tkw.grid_configure(popup_frame, nr_rows=3, nr_columns=2)
def _on_focus_man_col(self, grid_widget): def _ok(): value = widget.get_value() values_string = '; '.join(value) grid_widget.set_value(values_string) self.settings_object.set_data('mandatory_columns', item, value) popup_frame.destroy() grid_widget.unfocus() def _cancel(): popup_frame.destroy() grid_widget.unfocus() col = grid_widget.col_in_grid row = grid_widget.row_in_grid if col == 0: return popup_frame = tk.Toplevel(self) app_geometry = self.main_app.geometry() rest, x, y = app_geometry.split('+') px = int(x) + 200 py = int(y) + 200 popup_geometry = f'{400}x{200}+{px}+{py}' popup_frame.geometry(popup_geometry) print('self.main_app.geometry()', self.main_app.geometry()) print('popup_frame.geometry()', popup_frame.geometry()) popup_frame.protocol('WM_DELETE_WINDOW', _cancel) current_parameter_list = self._get_parameter_list_from_user() grid = dict(sticky='w', padx=5, pady=5) item = self.man_col_grid_widget.get_value(row, 0) value = self.man_col_grid_widget.get_value(row, col) settings_value = self.settings_object.get_data('mandatory_columns', item) settings_type = type(settings_value) r = 0 if settings_type == list: value_list = [v.strip() for v in value.split(';')] self._save_parameter_list_to_user(value_list) current_parameter_list = self._get_parameter_list_from_user() tk.Label( popup_frame, text=f'Select parameters to build mandatory column "{item}"' ).grid(row=r, column=0, **grid) r += 1 widget = tkw.ListboxSelectionWidget(popup_frame, items=current_parameter_list, selected_items=value_list, row=1, **grid) r += 1 else: widget = tkw.ComboboxWidget( popup_frame, title=f'Set parameter for mandatory column "{item}"', items=current_parameter_list, default_item=value, **grid) r += 1 widget_button_done = tk.Button(popup_frame, text='Ok', command=_ok) widget_button_done.grid(row=r, column=0, **grid) widget_button_done = tk.Button(popup_frame, text='Cancel', command=_cancel) widget_button_done.grid(row=r, column=1, **grid) tkw.grid_configure(popup_frame, nr_rows=3, nr_columns=2)
def _set_labelframe_station_mapping(self): frame = self.frame_station_mapping opt = {'padx': 5, 'pady': 5, 'sticky': 'nw'} combobox_width = 40 r = 0 # File name mapping_files = self.mapping_files.get_list() tk.Label(frame, text='File name').grid(row=r, column=0, **opt) self.sta_map_combobox_file = tkw.ComboboxWidget( frame, row=r, column=1, prop_combobox={'width': combobox_width}, items=mapping_files, callback_target=self._on_select_station_mapping_file, **opt) r += 1 # External column tk.Label(frame, text='External column').grid(row=r, column=0, **opt) self.sta_map_combobox_ext_col = tkw.ComboboxWidget( frame, row=r, column=1, callback_target=self._on_change_station_mapping, prop_combobox={'width': combobox_width}, **opt) r += 1 # Internal column tk.Label(frame, text='Internal column').grid(row=r, column=0, **opt) self.sta_map_combobox_int_col = tkw.ComboboxWidget( frame, row=r, column=1, callback_target=self._on_change_station_mapping, prop_combobox={'width': combobox_width}, **opt) r = 0 # File encoding tk.Label(frame, text='File encoding').grid(row=r, column=2, **opt) self.sta_map_entry_encoding = tkw.EntryWidget(frame, row=r, column=3, prop_entry={'width': 20}, **opt) self.sta_map_entry_encoding.disable_widget() r += 1 # qf_prefix tk.Label(frame, text='Header starts with').grid(row=r, column=2, **opt) self.sta_map_entry_header_start = tkw.EntryWidget( frame, row=r, column=3, prop_entry={'width': 20}, **opt) self.sta_map_entry_header_start.disable_widget() r += 1 # qf_suffix tk.Label(frame, text='QF suffix').grid(row=r, column=2, **opt) self.par_map_entry_qf_suffix = tkw.EntryWidget( frame, row=r, column=3, prop_entry={'width': 20}, **opt) self.par_map_entry_qf_suffix.disable_widget() r += 1 # Unit starts with tk.Label(frame, text='Unit starts with (if in external column)').grid( row=r, column=2, **opt) self.par_map_entry_unit_start = tkw.EntryWidget( frame, row=r, column=3, prop_entry={'width': 20}, **opt) self.par_map_entry_unit_start.disable_widget()
def _set_frame_plot_ref(self): def save(item): value = self.combobox_time_series_ref[item].get_value() if value: if 'size' in item: value = int(value) self.user.plot_time_series_ref.set(item, value) if 'color' in item: self.labels_time_series_ref[item].config(fg=value) frame = self.labelframe_plot_ref self.combobox_time_series_ref = {} self.labels_time_series_ref = {} padx = 5 pady = 5 r = 0 self.labels_time_series_ref['marker'] = tk.Label(frame, text='Marker') self.labels_time_series_ref['marker'].grid(row=r, column=0, sticky='w', padx=padx, pady=pady) self.combobox_time_series_ref['marker'] = tkw.ComboboxWidget( frame, callback_target=lambda x='marker': save(x), items=self.marker_list, default_item=self.user.plot_time_series_ref.setdefault( 'marker', '*'), row=r, column=1) r += 1 default_marker_size = str( self.user.plot_time_series_ref.setdefault('markersize', 10)) self.labels_time_series_ref['markersize'] = tk.Label(frame, text='Markersize') self.labels_time_series_ref['markersize'].grid(row=r, column=0, sticky='w', padx=padx, pady=pady) self.combobox_time_series_ref['markersize'] = tkw.ComboboxWidget( frame, callback_target=lambda x='markersize': save(x), items=list(range(2, 20)), default_item=default_marker_size, row=r, column=1) r += 1 default_color = self.user.plot_time_series_ref.setdefault( 'color', 'red') self.labels_time_series_ref['color'] = tk.Label(frame, text='Color') self.labels_time_series_ref['color'].grid(row=r, column=0, sticky='w', padx=padx, pady=pady) self.labels_time_series_ref['color'].config(fg=default_color) self.combobox_time_series_ref['color'] = tkw.ComboboxWidget( frame, callback_target=lambda x='color': save(x), items=self.color_list[:], default_item=default_color, row=r, column=1) self.user.plot_time_series_ref.setdefault('marker', 'x'), self.user.plot_time_series_ref.setdefault('markersize', 'red'), self.user.plot_time_series_ref.setdefault('color', 'red')
def _set_frame_map(self): def save_color(item): color = self.combobox_map_color[item].get_value() if color: self.user.map_prop.set(item, color) self.labels_map_color[item].config(fg=color) frame = self.labelframe_map padx = 5 pady = 5 frame_boundaries = tk.LabelFrame(frame, text='Boundaries') frame_boundaries.grid(row=0, column=0, padx=padx, pady=pady, sticky='nw') frame_properties = tk.LabelFrame(frame, text='Properties') frame_properties.grid(row=1, column=0, padx=padx, pady=pady, sticky='nw') tkw.grid_configure(frame, nr_rows=2) # -------------------------------------------------------------------------------------------------------------- # Boundaries # Labels tk.Label(frame_boundaries, text='Latitude MIN').grid(row=0, column=0, sticky='w', padx=padx, pady=pady) tk.Label(frame_boundaries, text='Latitude MAX').grid(row=1, column=0, sticky='w', padx=padx, pady=pady) tk.Label(frame_boundaries, text='Longitude MIN').grid(row=2, column=0, sticky='w', padx=padx, pady=pady) tk.Label(frame_boundaries, text='Longitude MAX').grid(row=3, column=0, sticky='w', padx=padx, pady=pady) # Entries prop_entry = {'width': 10} self.widget_lat_min = tkw.EntryWidget( frame_boundaries, entry_type='float', entry_id='lat_min', prop_entry=prop_entry, callback_on_focus_out=self._on_change_map_boundries, row=0, column=1, sticky='w', padx=padx, pady=pady) self.widget_lat_max = tkw.EntryWidget( frame_boundaries, entry_type='float', entry_id='lat_max', prop_entry=prop_entry, callback_on_focus_out=self._on_change_map_boundries, row=1, column=1, sticky='w', padx=padx, pady=pady) self.widget_lon_min = tkw.EntryWidget( frame_boundaries, entry_type='float', entry_id='lon_min', prop_entry=prop_entry, callback_on_focus_out=self._on_change_map_boundries, row=2, column=1, sticky='w', padx=padx, pady=pady) self.widget_lon_max = tkw.EntryWidget( frame_boundaries, entry_type='float', entry_id='lon_max', prop_entry=prop_entry, callback_on_focus_out=self._on_change_map_boundries, row=3, column=1, sticky='w', padx=padx, pady=pady) tk.Label(frame_boundaries, text="""Hit RETURN to confirm. Note that you have to restart the program to activate the new boundries.""").grid(row=4, column=0, columnspan=2, pady=10, sticky='nw') tkw.grid_configure(frame_boundaries, nr_rows=4, nr_columns=2) # Link entries self.widget_lat_min.south_entry = self.widget_lat_max self.widget_lat_max.south_entry = self.widget_lon_min self.widget_lon_min.south_entry = self.widget_lon_max self.widget_lon_max.south_entry = self.widget_lat_min # Map resolution self.widget_map_resolution = None # -------------------------------------------------------------------------------------------------------------- # Properties # TODO: ferrybox_track_color_background # TODO: fixed_platform_color_background # TODO: fixed_platforms_markersize_background # TODO: physicalchemical_color_background # TODO: physicalchemical_markersize_background map_color_list = [ 'ferrybox_track_color', 'ferrybox_track_color_highlighted', 'ferrybox_track_color_background', 'fixed_platform_color', 'fixed_platform_color_background', 'physicalchemical_color_background', 'ctd_profile_color_background', 'ctd_profile_color' ] default_colors = dict(ferrybox_track_color_background='gray', ferrybox_track_color='pink', ferrybox_track_color_highlighted='red', fixed_platform_color='green', fixed_platform_color_background='gray', physicalchemical_color_background='gray', ctd_profile_color_background='gray', ctd_profile_color='blue') # default_marker = dict(ferrybox_track_color_background='gray', # ferrybox_track_color='pink', # ferrybox_track_color_highlighted='red', # fixed_platform_color='green', # fixed_platform_color_background='gray', # physicalchemical_color_background='gray', # ctd_profile_color_background='gray', # ctd_profile_color='blue') self.combobox_map_color = {} self.labels_map_color = {} grid_items = dict(sticky='w') r = 0 for item in map_color_list: title = item.replace('_', ' ').capitalize() default_color = self.user.map_prop.setdefault( item, default_colors.get(item, 'black')) self.labels_map_color[item] = tk.Label(frame_properties, text=title) self.labels_map_color[item].grid(row=r, column=0, sticky='w', padx=padx, pady=pady) self.labels_map_color[item].config(fg=default_color) self.combobox_map_color[item] = tkw.ComboboxWidget( frame_properties, callback_target=lambda x=item: save_color(x), items=self.color_list[:], default_item=default_color, align='horizontal', grid_items=grid_items, row=r, column=1, padx=padx, pady=pady, sticky='e') save_color(item) r += 1
def _set_frame_add_file(self): # Three main frames frame = self.frame_add frame_data = tk.LabelFrame(frame, text='Get data file') frame_settings = tk.LabelFrame(frame, text='Settings file') frame_sampling_type = tk.LabelFrame(frame, text='Sampling type') frame_platform_depth = tk.LabelFrame(frame, text='Platform depth') frame_load = tk.Frame(frame) # Grid padx = 5 pady = 5 frame_data.grid(row=0, column=0, columnspan=4, sticky='nsew', padx=padx, pady=pady) frame_settings.grid(row=1, column=0, sticky='nsew', padx=padx, pady=pady) frame_sampling_type.grid(row=1, column=1, sticky='nsew', padx=padx, pady=pady) frame_platform_depth.grid(row=1, column=2, sticky='nsew', padx=padx, pady=pady) frame_load.grid(row=1, column=3, sticky='nsew', padx=padx, pady=pady) # Gridconfigure tkw.grid_configure(frame, nr_rows=2, nr_columns=4, r0=50) #---------------------------------------------------------------------- # Data frame self.button_get_ferrybox_data_file = tk.Button( frame_data, text='Ferrybox CMEMS', command=lambda: self._get_data_file_path('Ferrybox CMEMS')) self.button_get_fixed_platform_data_file = tk.Button( frame_data, text='Fixed platform CMEMS', command=lambda: self._get_data_file_path('Fixed platforms CMEMS')) self.button_get_ctd_data_file = tk.Button( frame_data, text='DV CTD standard format', command=lambda: self._get_data_file_paths('CTD DV')) self.button_get_ctd_nodc_data_file = tk.Button( frame_data, text='NODC CTD standard format', command=lambda: self._get_data_file_paths('CTD NODC')) self.button_get_sampling_file = tk.Button( frame_data, text='SHARKweb bottle data', command=lambda: self._get_data_file_path('PhysicalChemical SHARK')) # tkw.disable_widgets(self.button_get_ctd_data_file) self.stringvar_data_file = tk.StringVar() self.entry_data_file = tk.Entry(frame_data, textvariable=self.stringvar_data_file, state='disabled') # Grid padx = 5 pady = 5 self.button_get_ferrybox_data_file.grid(row=0, column=0, padx=padx, pady=pady, sticky='nsew') self.button_get_fixed_platform_data_file.grid(row=0, column=1, padx=padx, pady=pady, sticky='nsew') self.button_get_ctd_data_file.grid(row=0, column=2, padx=padx, pady=pady, sticky='nsew') self.button_get_ctd_nodc_data_file.grid(row=0, column=3, padx=padx, pady=pady, sticky='nsew') self.button_get_sampling_file.grid(row=0, column=4, padx=padx, pady=pady, sticky='nsew') self.entry_data_file.grid(row=1, column=0, columnspan=5, padx=padx, pady=pady, sticky='nsew') # Grid configure tkw.grid_configure(frame_data, nr_rows=2, nr_columns=5) # Settings frame self.combobox_widget_settings_file = tkw.ComboboxWidget( frame_settings, items=[], title='', callback_target=self._save_type_and_file, prop_combobox={'width': 40}, column=0, columnspan=1, row=0, sticky='nsew') self._update_settings_combobox_widget() self.button_import_settings_file = ttk.Button( frame_settings, text='Import settings file', command=self._import_settings_file) self.button_import_settings_file.grid(row=0, column=1, padx=padx, pady=pady, sticky='nsew') tkw.grid_configure(frame_settings, nr_rows=1, nr_columns=2) #---------------------------------------------------------------------- # Sampling type frame self.combobox_widget_sampling_type = tkw.ComboboxWidget( frame_sampling_type, items=sorted(self.session.get_sampling_types()), title='', callback_target=self._save_type_and_file, prop_combobox={'width': 30}, column=0, columnspan=1, row=0, sticky='nsew') # Platform depth frame self.entry_widget_platform_depth = tkw.EntryWidget( frame_platform_depth, entry_type='int', prop_entry=dict(width=5), row=0, column=0, padx=padx, pady=pady, sticky='nsew') self.entry_widget_platform_depth.disable_widget() tk.Label(frame_platform_depth, text='meters').grid(row=0, column=1, padx=padx, pady=pady, sticky='nsew') tkw.grid_configure(frame_platform_depth) # Gridconfigure tkw.grid_configure(frame_sampling_type) # Load file button self.button_load_file = tk.Button(frame_load, text='Load file', command=self._load_file, bg='lightgreen', font=(30)) self.button_load_file.grid(row=0, column=0, padx=padx, pady=pady, sticky='nsew') self.button_load_file.configure(state='disabled') tkw.grid_configure(frame_load)