feat: add --zenity

This commit is contained in:
Johann Dreo 2025-08-10 17:54:09 +02:00
commit 3dad35fbff
2 changed files with 25 additions and 7 deletions

View file

@ -26,7 +26,8 @@ Currently, FlickSave can perform the following actions:
- `--inkscape`, - `--inkscape`,
- `--git`, - `--git`,
- `--log`, - `--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]`. - `--cmd [COMMAND]`.
You can pass multiple actions. You can pass multiple actions.
@ -52,8 +53,9 @@ Actions:
* `--save`: Save a snapshot of the watched file. * `--save`: Save a snapshot of the watched file.
* `--inkscape`: Save a PNG snpashot of the watched SVG file. * `--inkscape`: Save a PNG snpashot of the watched SVG file.
* `--git`: Commit the watched file if it has been modified. * `--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. * `--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. * `--cmd [COMMAND]: Run the passed command for each watched file.
You can use tags, which will be replaced by actual data: You can use tags, which will be replaced by actual data:
- {target} (the current watched file), - {target} (the current watched file),

View file

@ -238,11 +238,11 @@ class Command(Save):
try: try:
# We want the shell because we may call shell command or need environment variables. # 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) 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("ERROR while calling command")
logging.error("\tReturn code: %s",proc.returncode) logging.error("\tReturn code: %s",err.returncode)
logging.error("\tOut: %s",proc.stdout) logging.error("\tOut: %s",err.stdout)
logging.error("\tErr: %s",proc.stderr) logging.error("\tErr: %s",err.stderr)
except: except:
logging.error("ERROR while calling subprocess: %s", sys.exc_info()[0]) 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", 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.") 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).") help="Alternate extension for the timestamped snapshot (do not forget the dot).")
parser.add_argument("-v","--verbose", choices=['DEBUG','INFO','WARNING','ERROR'], default='INFO', 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).", ["Send a notification (on the system's D-Bus).",
None] 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): def help(name):
return existing[name][0] return existing[name][0]
@ -410,6 +423,9 @@ if __name__=="__main__":
available["log"][1] = Log() available["log"][1] = Log()
available["cmd"] = ["", Command(asked.cmd, asked.directory, asked.separator, asked.template, asked.alt_ext, asked.no_overwrite)] 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: if HAS_DBUS:
available["dbus"][1] = DBus() available["dbus"][1] = DBus()