From 3dad35fbffe475d16b41803719ec7a9437fefb98 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 10 Aug 2025 17:54:09 +0200 Subject: [PATCH] feat: add --zenity --- README.md | 6 ++++-- flicksave.py | 26 +++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f78e739..0ccb7f2 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ Currently, FlickSave can perform the following actions: - `--inkscape`, - `--git`, - `--log`, -- `--dbus`, +- `--dbus` (disabled if the `sdbus` python module is not installed), +- `--zenity` (disabled if the `zenity` command is not installed, or if no graphical display is available), - `--cmd [COMMAND]`. You can pass multiple actions. @@ -52,8 +53,9 @@ Actions: * `--save`: Save a snapshot of the watched file. * `--inkscape`: Save a PNG snpashot of the watched SVG file. * `--git`: Commit the watched file if it has been modified. -* `--log`: Print a message when the watched file is touched. +* `--log`: Print a message. * `--dbus`: Send a notification to the system's D-Bus. +* `--zenity`: Pop-up a dialog window. * `--cmd [COMMAND]: Run the passed command for each watched file. You can use tags, which will be replaced by actual data: - {target} (the current watched file), diff --git a/flicksave.py b/flicksave.py index 1f4d6ea..66f891a 100755 --- a/flicksave.py +++ b/flicksave.py @@ -238,11 +238,11 @@ class Command(Save): try: # We want the shell because we may call shell command or need environment variables. proc = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as err: logging.error("ERROR while calling command") - logging.error("\tReturn code: %s",proc.returncode) - logging.error("\tOut: %s",proc.stdout) - logging.error("\tErr: %s",proc.stderr) + logging.error("\tReturn code: %s",err.returncode) + logging.error("\tOut: %s",err.stdout) + logging.error("\tErr: %s",err.stderr) except: logging.error("ERROR while calling subprocess: %s", sys.exc_info()[0]) @@ -358,7 +358,7 @@ if __name__=="__main__": parser.add_argument("-w", "--no-overwrite", action="store_true", help="Do not overwrite snapshots created at the same time, but append a number to their name.") - parser.add_argument("-x", "--alt-ext", metavar="EXTENSION" default='', + parser.add_argument("-x", "--alt-ext", metavar="EXTENSION", default='', help="Alternate extension for the timestamped snapshot (do not forget the dot).") parser.add_argument("-v","--verbose", choices=['DEBUG','INFO','WARNING','ERROR'], default='INFO', @@ -390,6 +390,19 @@ if __name__=="__main__": ["Send a notification (on the system's D-Bus).", None] + if shutil.which("zenity") and os.environ.get('DISPLAY'): + HAS_ZENITY = True + existing["zenity"] = ["Pop-up a dialog boz each time a file is touched.", None] + else: + HAS_ZENITY = False + has_zen = "" + if not shutil.which("zenity"): + has_zen = "`zenity` command not found, " + has_X = "" + if not os.environ.get('DISPLAY'): + has_X = "No graphical display found, " + logging.warning(has_X + has_zen + "the --zenity action is disabled.") + def help(name): return existing[name][0] @@ -410,6 +423,9 @@ if __name__=="__main__": available["log"][1] = Log() available["cmd"] = ["", Command(asked.cmd, asked.directory, asked.separator, asked.template, asked.alt_ext, asked.no_overwrite)] + if HAS_ZENITY: + available["zenity"][1] = Command("zenity --info --text 'File {target} was {event}'") + if HAS_DBUS: available["dbus"][1] = DBus()