Skip to content

Commit ea98d66

Browse files
committed
Improved handling of "tkinter not awailable"
1 parent d86910c commit ea98d66

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tools/postbuild.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ def CreateFs( fsName, mkFsName ):
8888
raise ProcessError( "CreateFs: data dir is not a directory: %s" % dataDir )
8989
FilesInDir = CountFilesInDir( dataDir )
9090
if FilesInDir == 0:
91-
if not ConfirmDialog( "%s Create" % fsName, "No files have been found in your data folder!\nAre you sure you want to create an empty %s image?" % fsName ):
91+
answer = ConfirmDialog( "%s Create" % fsName, "No files have been found in your data folder!\nAre you sure you want to create an empty %s image?" % fsName )
92+
if answer < 0:
93+
raise ProcessError( "tkinter not available.\nCan't ask 'Are you sure you want to create an empty ... image?'\nPlease install it with:\npip3 install tkinter\n" )
94+
elif:
9295
raise ProcessError( "Canceled by user" )
9396
os.makedirs( DstDir, exist_ok = True )
9497
imageName = "%s.%s" % ( Args.name, fsName )

tools/utillities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ def RemoveIno( path ):
7777
return path
7878

7979
def ConfirmDialog( title, text ):
80+
""" return -1 if tkinter not installed, 0 if aswer was no, 1 if answer was yes """
8081
try:
8182
import tkinter
8283
from tkinter import messagebox
8384
except:
84-
raise ProcessError( "tkinter not available.\nPlease install it with:\npip3 install tkinter\n" )
85+
return -1
8586
rootWin = tkinter.Tk() # Create the object
8687
rootWin.overrideredirect( 1 ) # Avoid it appearing and then disappearing quickly
8788
#rootWin.iconbitmap("PythonIcon.ico") # Set an icon (this is optional - must be in a .ico format)
8889
rootWin.withdraw() # Hide the window as we do not want to see this one
89-
return messagebox.askyesno( title, text, parent = rootWin )
90+
return 1 if messagebox.askyesno( title, text, parent = rootWin ) else 0
9091

0 commit comments

Comments
 (0)