View Single Post
Old 05-27-2025, 12:16 PM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,914
Karma: 6120478
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by DiapDealer View Post
I'll be honest: at this point, I wouldn't blame anyone for not worrying about providing support for pre-2.0 PyQt5. Just leave a version that still works with pre-2.0 Sigil and make a new one that works with PySide6. With the AppImage and the ability to use virtual Python environments for plugins, there's very few people that can't get PySide6 available for Sigil plugins.

Of course anyone who wants to continue using plugin_utils as a compatibility layer between the old and the new will receive bonus points!
For my bonus points ...

Here is all it took to get FolderIn to ask for a folder to read in from in an inline manner (ie. no MainWindow needed)

Code:
from plugin_utils import QtWidgets

...

    # ask the user to select the source folder to load files from                                                       
    app = QtWidgets.QApplication(sys.argv)
    foldpath = QtWidgets.QFileDialog.getExistingDirectory(None, 'Select Folder to Input Into Sigil', basepath)
    app.quit()
And here is how to ask for a filepath and name to save a file into:

Code:
    # ask for name and location to save
    app = QtWidgets.QApplication(sys.argv)
    fpath, seleted_filter = QtWidgets.QFileDialog.getSaveFileName(None, 'Save ePub3 as ...', suggest, "ePubs (*.epub)")
    app.quit()
which replaced all of this tk required for MacOS

Code:
    import tkinter
    import tkinter.ttk as tkinter_ttk
    import tkinter.constants as tkinter_constants
    import tkinter.filedialog as tkinter_filedialog

...

    # ask the user to select the source folder to load files from
    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 on OSX 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()
    foldopt = {}
    foldopt['parent'] = localRoot
    foldopt['initialdir'] = basepath
    foldopt['title'] = 'Select Folder to Input into Sigil'
    foldopt['mustexist']= True
    foldpath = tkinter_filedialog.askdirectory(**foldopt)
    # localRoot.destroy()
    localRoot.quit()
Admittedly, a lot of the differences were only required on MacOS as Tk did not work reliably across platforms.

I am going to use the same approach for FolderOut, and ePub3-itizer. My Access-Aide plugin already moved to Qt because Tk does not work well with svg images and its fill in alt text dialog was really flakey.

And to restrict plugin code to run only on Sigil 2.0.0 or later:

Code:
    if bk.launcher_version() < 20230315:
        print("This plugin requires Sigil-2.0.0 or later")
        return -1
So if I keep the old k version for All pre-2.0 Sigil as one plugin, I can then release this as a new version of the plugin to run on Sigil 2.0.0 and later. And no one gets left behid so to speak.

Last edited by KevinH; 05-27-2025 at 03:30 PM. Reason: added saveFileName example
KevinH is online now   Reply With Quote