Last active
May 23, 2021 20:46
-
-
Save luluco250/a50d2c54096f9c88fcc236561595d9fe to your computer and use it in GitHub Desktop.
Remove the "You can drop dockable dialogs here" text from GIMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
VERSION = "1.0.3" | |
TARGET_TEXT = b"You can drop dockable dialogs here" | |
HELP_TEXT = ( | |
"""Description: | |
This script replaces the "You can drop dockable dialogs here" text in GIMP with an empty one, disabling it. | |
Usage: nodroptext [<file_path>] [...] | |
Arguments: | |
file_path: Path to the GIMP executable file. | |
-b, --backup: Create a backup copy of the specified file. (default) | |
-nb, --no-backup: Don't create a backup copy of the specified file. | |
-h, --help: Display usage text. | |
-v, --version: Display version number.""" | |
) | |
ARGS = [ | |
"-b", "--backup", | |
"-nb", "--no-backup", | |
"-h", "--help", | |
"-v", "--version" | |
] | |
if __name__ == "__main__": | |
from shutil import copyfile | |
from os.path import abspath, exists, isfile | |
from sys import argv as args | |
from sys import stderr, exit | |
if len(args) == 1 or "-h" in args or "--help" in args: | |
print(HELP_TEXT) | |
exit(0) | |
if "-v" in args or "--version" in args: | |
print(VERSION) | |
exit(0) | |
if args[1] in ARGS: | |
print("Error: Expected file path!", file=stderr) | |
exit(1) | |
fpath = abspath(args[1]) | |
if not exists(fpath): | |
print("Error: The specified file doesn't exist!", file=stderr) | |
exit(1) | |
if not isfile(fpath): | |
print("Error: The specified path is not a file!", file=stderr) | |
exit(1) | |
if "-b" in args or "--backup" in args or "-nb" not in args and "--no-backup" not in args: | |
bpath = fpath + ".bak" | |
# Create an incrementing ".bak#" extension if one already exists | |
if isfile(bpath): | |
i = 1 | |
while isfile(bpath + str(i)): | |
i += 1 | |
bpath += str(i) | |
copyfile(fpath, bpath) | |
print('Backup: "{}" -> "{}"'.format(fpath, bpath)) | |
try: | |
with open(fpath, "rb+") as file: | |
s = file.read() | |
file.seek(0) | |
file.write(s.replace(TARGET_TEXT, bytearray(len(TARGET_TEXT)))) | |
file.truncate() | |
print("Operation completed.") | |
except (OSError, IOError) as e: | |
print("Error:", e, file=stderr) | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment