Add Loading Screen to Script?
-
Hello everyone! I am working on a Script and would like to know if it is possible to add some kind of loading screen functionality. My script manipulates large files and it takes a few seconds to see the changes after running it. Is there any way I can add in a loading screen that terminates when the script has completed running? That way the user has a clearer picture of when the script actually finished executing.
Any help would be greatly appreciated, thanks a bunch! -
Hello everyone!
I might not be everyone. However, I am one that is part of everyone
You don’t say what kind of “Script” you are writing. But since every one of your posts on this forum has been about PythonScript, I assume you are writing a PythonScript script to help automate Notepad++ (maybe related to your CSV manipulations, maybe not).
In general, you would want to open the “splash” or “busy” dialog or window when it starts, and close the window when the script is over.
The PythonScript library gives you access to the standard
notepad.messageBox()
interface, and the docs that come with PythonScript plugin explain the arguments to that method. But aside from that andnotepad.input()
, there aren’t any other dialog box formats that PythonScript gives you direct access to. And those I don’t think would work right for your desires: there isn’t an asynchronous access to open one of those standard dialogs with one command and close it with another command using the PythonScript’s Npp module.That said, the default python interpreter that comes with PythonScript has the
ctypes
module, and if you import that, you can access all thectypes.windll.user32
commands; here are docs for ctypes in 2.7.18 for PythonScript 2.0.0 and for Python 3.10 for PythonScript 3.0.13-alpha. But delving into the ctypes libraries for how to create a splash screen or progress bar is off topic here. (Note my helpful hints of possible search terms: “splash screen” or “progress bar”)However, if you aren’t married to the idea of a window (which is how I interpret “loading screen”), the
notepad.setStatusBar()
method allows you to change the text in the six different status bar sections. My WhatUniChar.py script shows an example of overriding the STATUSBARSECTION.DOCTYPE (where “Python file” or “CSV File” or similar usually goes). And with extractypes
manipulation (see other files in that same repo – search for “statusbar”; I think dev-statusbar.py has a working example of agetStatusBarText
implementation), you can read the current text of that status bar section, so your process could be: 1) read the current text from the desired section of the status bar and save it tokeepStatusBarText
variable; 2) at the start of your script, set the status bar text to your “CSV is being loaded” message; 3) wait for script to end; 4) either put a message that says “done loading CSV”, which will be overwritten the next time that Notepad++ updates the display, or you can just write the originalkeepStatusBarText
variable back into that field. -
“Loading screens” / “splash screen” / “progress windows” are insanely complicated things to get “right”. Of course, if you’ve never tried to implement one, then bah, easy?
What I would do in the OP’s case, if something takes a long time to execute, would be putting up a message box saying “About to do something that will likely take a while”, then do the long-running action, then put up another message box saying “Done with long-running operations”.
-
@PeterJones Thanks for your input and search advice, it is much appreciated. @Alan-Kilborn Yeah that is what I ended up doing, funny we had the same thought. The loading screen seems to be too much of a time sink for right now. Maybe later on in development.