From d937c4c0a4f3b4e910197a71a3ba8b62cd050786 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 11 Nov 2021 11:06:18 +0100 Subject: [PATCH] v0.2.1, minor fixes. --- about.py | 2 +- app.py | 36 ++++++++++++++++++++++++++++++------ model.py | 16 ++++------------ presenter.py | 3 --- tk_call_wrapper.py | 5 +++++ 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/about.py b/about.py index 0fc4ceb..97595ff 100644 --- a/about.py +++ b/about.py @@ -51,7 +51,7 @@ def __init__(self, master, skin): frame = tk.Frame(frame, bg='#ff0000') frame.pack(side=tk.TOP, expand=True, fill=tk.X, padx=10) tk.Label(frame, text='Image Viewer MK2', fg=self.skin.fg_color, bg=self.skin.bg_color, font=('Segoe UI', 14, 'bold')).pack(side=tk.TOP, expand=False, fill=tk.X) - tk.Label(frame, text='v0.2.0 (2021-11-10)', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X) + tk.Label(frame, text='v0.2.1 (2021-11-11)', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X) tk.Label(frame, text='Author: Jan Kukačka, 2021', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X) tk.Label(frame, text='Provided under MIT license.', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X) tk.Label(frame, text='Icon credits: Icon home, Gregor Cresnar,\nFreepik and Pancracysdh.', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X) diff --git a/app.py b/app.py index 9a6fb07..ed783eb 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,7 @@ # ------------------------------------------------------------------------------ import numpy as np - +import argparse try: from . import view as view_ from . import model as model_ @@ -18,6 +18,18 @@ import model as model_ import presenter as presenter_ + +# argument parsing +parser = argparse.ArgumentParser(description='Image Viewer MKII: Spectral image viewer') +parser.add_argument('-i', '--input', type=str, help='Filename of the image to open', default=argparse.SUPPRESS) +parser.add_argument('-c', '--config', type=str, help='Filename of the config file to import', default=argparse.SUPPRESS) + +parser.add_argument('-d', '--debug', help='Print errors to console.', action='store_true', default=argparse.SUPPRESS) +parser.add_argument('-g', '--gpu', help='Use GPU rendering (default)', action='store_true', default=argparse.SUPPRESS) +parser.add_argument('-ng', '--no_gpu', help='Use CPU rendering', action='store_true', default=argparse.SUPPRESS) + + + def main(file=None, image=None, **kwargs): ''' Starts the app and opens optionally given file or uses given image. @@ -39,7 +51,7 @@ def main(file=None, image=None, **kwargs): - (config dictionary. Only if return_config was set to True.) ''' - gpu = False + gpu = True if 'gpu' in kwargs: gpu = kwargs['gpu'] @@ -81,7 +93,19 @@ def main(file=None, image=None, **kwargs): if __name__ == '__main__': import sys - files = sys.argv[1:] - if len(files) == 0: - files = [None] - main(files[0]) + kwargs = vars(parser.parse_args(sys.argv[1:])) + kwargs2 = {} + + if 'no_gpu' in kwargs: + kwargs2['gpu'] = not kwargs['no_gpu'] + if 'gpu' in kwargs: + kwargs2['gpu'] = kwargs['gpu'] + if 'input' in kwargs: + kwargs2['file'] = kwargs['input'] + if 'config' in kwargs: + kwargs2['config_filename'] = kwargs['config'] + if 'debug' in kwargs: + kwargs2['debug'] = kwargs['debug'] + + print('Image Viewer MKII. Jan Kukacka, 2021') + main(**kwargs2) diff --git a/model.py b/model.py index b53a8a7..2ed7f77 100644 --- a/model.py +++ b/model.py @@ -230,29 +230,21 @@ def update_render(self, event=None): def save(self): model_dict = {} - # model_dict['colors'] = list(self.colors) - # model_dict['color_space'] = self.color_space - # model_dict['imoptions'] = dict(self.imoptions) model_dict['channel_props'] = [dict(cp) for cp in self.channel_props] - # model_dict['special_options'] = dict(self.special_options) return model_dict def load(self, model_dict): ## Suspend rendering while loading self.suspend_render = True - # for i, color in enumerate(model_dict['colors']): - # self.colors[i] = color - # self.color_space = model_dict['color_space'] - # for key, value in model_dict['imoptions'].items(): - # self.imoptions[key] = value for i, channel_property in enumerate(model_dict['channel_props']): if i >= len(self.channel_props): break for key, value in channel_property.items(): - self.channel_props[i][key] = value - # if 'special_options' in model_dict: - # self.special_options = model_dict['special_options'] + if key in self.channel_props[i]: + self.channel_props[i][key] = value + else: + print(f'Config key {key} could not be loaded.') self.suspend_render = False self.update_render() diff --git a/presenter.py b/presenter.py index 9466db0..6575053 100644 --- a/presenter.py +++ b/presenter.py @@ -256,9 +256,6 @@ def color_onchage(self): if is_color_like(color) and channel_index < len(self.model.channel_props): self.model.channel_props[channel_index]['color'] = str(to_hex(color)) - # def colorspace_onchange(self, var): - # self.model.color_space = var.get() - def channel_var_onchange(self, var, key, cindex=None): if cindex is None: cindex = self.view.get_active_channel() diff --git a/tk_call_wrapper.py b/tk_call_wrapper.py index 9e52735..e7d8492 100644 --- a/tk_call_wrapper.py +++ b/tk_call_wrapper.py @@ -24,4 +24,9 @@ def __call__(self, *args): raise SystemExit(msg) except tk.TclError as err: + ## Raised when numbers from textboxes cannot be parsed + pass + + except ValueError as err: + ## Raised when colors from textboxes cannot be parsed pass