#!/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 argparse import ArgumentParser
from exiftool import ExifToolHelper # type: ignore
import gi # type: ignore
gi.require_version('Gtk', '4.0')
return True
if a_cmp is None:
return False
- elif b_cmp is None:
+ if b_cmp is None:
return True
return a_cmp > b_cmp
class Application(Gtk.Application):
"""Image browser application class."""
+ img_dir_absolute: str
def __init__(self, *args, **kwargs):
- 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])
+ super().__init__(*args, **kwargs)
+
+ def do_activate(self, *args, **kwargs):
+ """Parse arguments, start window, and keep it open."""
+ parser = ArgumentParser()
+ parser.add_argument('directory', default=IMG_DIR_DEFAULT, nargs='?')
+ opts = parser.parse_args()
+ self.img_dir_absolute = abspath(opts.directory)
win = MainWindow(self)
win.present()
self.hold()
main_app = Application(application_id='plomlompom.com.StablePixBrowser.App')
-main_app.run(sys_argv)
+main_app.run()