From: Christian Heller Date: Sat, 24 Aug 2024 00:15:47 +0000 (+0200) Subject: In Browser, improve metadata translation. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/todos?a=commitdiff_plain;h=cbfe027b2d2bcc4a90a16d26de18621fc0291e7f;p=stable_plom In Browser, improve metadata translation. --- diff --git a/browser.py b/browser.py index 10fecfb..6f13d7e 100755 --- a/browser.py +++ b/browser.py @@ -19,16 +19,22 @@ class FileItem(GObject.GObject): super().__init__() self.name = info.get_name() self.last_mod_time = info.get_modification_date_time().format_iso8601() - self.seed = '' self.full_path = path_join(path, self.name) - self.metadata = '' + self.seed = '' + self.guidance = 0.0 + self.n_steps = 0 + self.height = 0 + self.width = 0 + self.scheduler = '' + self.model = '' + self.prompt = '' if self.full_path in cache: if self.last_mod_time in cache[self.full_path]: cached = cache[self.full_path][self.last_mod_time] - self.seed = cached[0] - self.metadata = cached[1] + for k in cached.keys(): + setattr(self, k, cached[k]) - def set_metadata(self, et): + def set_metadata(self, et, cache): self.metadata = 'no SD comment' for d in et.get_tags([self.name], ['Comment']): for k, v in d.items(): @@ -36,9 +42,12 @@ class FileItem(GObject.GObject): self.metadata = '' gen_params = GenParams.from_str(v) for k, v_ in gen_params.as_dict.items(): - if k == 'seed': - self.seed = v_ - self.metadata += f'\n{k}: {v_}' + setattr(self, k, v_) + cached = {} + for k in ('seed', 'guidance', 'n_steps', 'height', + 'width', 'scheduler', 'model', 'prompt'): + cached[k] = getattr(self, k) + cache[self.full_path] = {self.last_mod_time: cached} class Window(Gtk.ApplicationWindow): @@ -106,9 +115,8 @@ class Window(Gtk.ApplicationWindow): item = FileItem(img_dir_absolute, info, cache) self.unsorted += [item] with ExifToolHelper() as et: - for item in [item for item in self.unsorted if not item.metadata]: - item.set_metadata(et) - cache[item.full_path] = {item.last_mod_time: [item.seed, item.metadata]} + for item in [item for item in self.unsorted if item.seed == '']: + item.set_metadata(et, cache) self.max_index = len(self.unsorted) - 1 self.sort('last_mod_time') with open('cache.json', 'w') as f: @@ -129,7 +137,11 @@ class Window(Gtk.ApplicationWindow): def reload(self): self.viewer.remove(self.viewer.get_last_child()) if self.item: - metadata = f'{self.item.full_path}: {self.item.metadata}' + metadata = f'{self.item.full_path}: PROMPT: {self.item.prompt}\n' +\ + f'SEED: {self.item.seed} / MODEL: {self.item.model} / ' +\ + f'SCHEDULER: {self.item.scheduler}\nGUIDANCE: {self.item.guidance}\n' +\ + f'N_STEPS: {self.item.n_steps}\nHEIGHT: {self.item.height} / ' +\ + f'WIDTH: {self.item.width}' self.metadata.props.label = metadata pic = Gtk.Picture.new_for_filename(self.item.name) self.viewer.append(pic)