Quote:
Originally Posted by KevinH
It still will sometimes not appear as anything other than an icon even with the latest tk.
I spent some time searching the web and found the following potential solution:
Code:
localRoot = tkinter.Tk()
localRoot.withdraw()
# localRoot is is an empty topmost root window that is hidden by withdrawing it
# but localRoot needs to be centred, and lifted and focus_force used
# so that its child dialog will inherit focus upon launch
localRoot.overrideredirect(True)
# center on screen but make size 0 to hide the empty localRoot
w = localRoot.winfo_screenwidth()
h = localRoot.winfo_screenheight()
x = int(w/2)
y = int(h/2)
localRoot.geometry('%dx%d+%d+%d' % (0, 0, x, y))
localRoot.deiconify()
localRoot.lift()
localRoot.focus_force()
fpath = tkinter_filedialog.asksaveasfilename(
parent=localRoot,
title="Save ePub3 as ...",
initialfile=fname,
initialdir=_USER_HOME,
defaultextension=".epub"
)
# localRoot.destroy()
localRoot.quit()
If this added code will not hurt anything on Windows or Linux I can add it to the plugin to prevent this type of issue from happening to others.
KevinH
|
Sorry I'm late to this, but the new code doesn't work for me on Linux (Sigil HEAD/Python 3.6). The file dialog launches behind Sigil's window, and nothing new opens on the taskbar to even indicate anything was launched. Until I happened to minimize Sigil, I thought the plugin was hung up.
The problem on Linux seems to be the line:
Code:
localRoot.overrideredirect(True)
When I comment that out, the file dialog pops in front of Sigil and a new item appears on the taskbar.
If that line is absolutely needed on Macs, you may want to limit using it on that platform with an "if sys.platform.startswith('darwin')"
EDIT: indeed, changing the code to the following makes everything work "normally" on Linux/Windows for me. I assume it would fix the Mac issue as well.
Code:
localRoot = tkinter.Tk()
localRoot.withdraw()
if sys.platform.startswith('darwin'):
# localRoot is is an empty topmost root window that is hidden by withdrawing it
# but localRoot needs to be centred, and lifted and focus_force used
# so that its child dialog will inherit focus upon launch
localRoot.overrideredirect(True)
# center on screen but make size 0 to hide the empty localRoot
w = localRoot.winfo_screenwidth()
h = localRoot.winfo_screenheight()
x = int(w/2)
y = int(h/2)
localRoot.geometry('%dx%d+%d+%d' % (0, 0, x, y))
localRoot.deiconify()
localRoot.lift()
localRoot.focus_force()
fpath = tkinter_filedialog.asksaveasfilename(
parent=localRoot,
title="Save ePub3 as ...",
initialfile=fname,
initialdir=_USER_HOME,
defaultextension=".epub"
)
# localRoot.destroy()
localRoot.quit()