#!/usr/bin/env python3
"""Browser for image files."""
+from sys import argv as sys_argv
from json import dump as json_dump, load as json_load
from os.path import exists as path_exists, join as path_join, abspath
from exiftool import ExifToolHelper # type: ignore
from stable.gen_params import (GenParams, # noqa: E402
GEN_PARAMS, GEN_PARAMS_STR) # noqa: E402
-IMG_DIR = '.'
+IMG_DIR_DEFAULT = '.'
UPPER_DIR = '..'
CACHE_PATH = 'cache.json'
sort_selection: Gtk.SingleSelection
prev_key: list
- def __init__(self, _app, **kwargs):
+ def __init__(self, app, **kwargs):
super().__init__(**kwargs)
+ self.app = app
def init_navbar():
def add_button(label_, on_click, parent_box):
self.add_controller(key_ctl)
self.prev_key = [0]
- self.img_dir_absolute = abspath(IMG_DIR)
self.block_once_hit_file_selection = False
self.block_file_selection_updates = False
self.force_width, self.force_height = 0, 0
return
selected = self.gallery_selection.props.selected_item
if isinstance(selected, DirItem):
- self.img_dir_absolute = selected.full_path
+ self.app.img_dir_absolute = selected.full_path
self.load_directory()
def update_file_selection(self):
# navbar callables
def load_directory(self, update_gallery=True):
- """Load into gallery directory at self.img_dir_absolute."""
+ """Load into gallery directory at .app.img_dir_absolute."""
def read_directory_into_gallery_items(cache, dir_path,
make_parent=False):
json_dump({}, f)
with open(CACHE_PATH, 'r', encoding='utf8') as f:
cache = json_load(f)
- read_directory_into_gallery_items(cache, self.img_dir_absolute, True)
+ read_directory_into_gallery_items(cache, self.app.img_dir_absolute,
+ True)
with open(CACHE_PATH, 'w', encoding='utf8') as f:
json_dump(cache, f)
if update_gallery:
"""Image browser application class."""
def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.connect('activate', self.on_activate)
-
- def on_activate(self, app_):
- """Start window and keep it open."""
- win = MainWindow(app_)
+ super().__init__(flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
+ *args, **kwargs)
+ self.img_dir_absolute = abspath(IMG_DIR_DEFAULT)
+
+ def do_command_line(self, *args, **kwargs):
+ """Parse directory from command_line, start window and keep it open."""
+ command_line = args[0]
+ argv = command_line.get_arguments()
+ if len(argv) > 1:
+ self.img_dir_absolute = abspath(argv[1])
+ win = MainWindow(self)
win.present()
self.hold()
+ return 0
-app = Application(application_id='plomlompom.com.StablePixBrowser.App')
-app.run(None)
+main_app = Application(application_id='plomlompom.com.StablePixBrowser.App')
+main_app.run(sys_argv)