mirror of
https://github.com/novoid/filetags.git
synced 2026-06-14 03:21:19 +00:00
make Tkinter dependency optional
Tkinter is required only for the new --gui option but not for filetags core functionality, still it has to be installed in order to run filetags at the moment. This commit makes the import of Tkinter optional as long as the --gui option is not passed, thus allowing users that don't have Tkinter installed on their system to keep using filetags like before. In case the --gui option is passed and Tkinter can't be imported an error message is printed instructing the user to install the Python Tkinter module similar to the safe import of other modules.
This commit is contained in:
parent
b68a731c81
commit
7045c9a8e0
1 changed files with 10 additions and 2 deletions
|
|
@ -46,8 +46,12 @@ import argparse # for handling command line arguments
|
|||
import time
|
||||
import logging
|
||||
import errno # for throwing FileNotFoundError
|
||||
import tkinter as tk ## for --gui
|
||||
from tkinter import ttk ## for --gui
|
||||
try:
|
||||
import tkinter as tk ## for --gui
|
||||
from tkinter import ttk ## for --gui
|
||||
have_tkinter = True
|
||||
except ModuleNotFoundError:
|
||||
have_tkinter = False
|
||||
|
||||
safe_import('operator') # for sorting dicts
|
||||
safe_import('difflib') # for good enough matching words
|
||||
|
|
@ -2972,6 +2976,10 @@ def main():
|
|||
error_exit(3, "I found option \"--tag\" and option \"--interactive\". \n" +
|
||||
"Please choose either tag option OR interactive mode.")
|
||||
|
||||
if options.gui and not have_tkinter:
|
||||
error_exit(4, "Could not find Python module \"tkinter\", which is required for --gui option. \n"+
|
||||
"Please install it (e.g., \"apt install python3-tk\") or don't use this option.")
|
||||
|
||||
if not options.interactive and options.gui:
|
||||
logging.warning('Found option "--gui" without option "--interactive". Will ignore that.')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue