Code Beautifier 1.0 (PythonScript)
-
@Khundian-Twitch ,
Sorry, not seeing your app working, as it appears from the pythonscript console, that you are calling a Tkinter module, which I never downloaded/installed and which your instructions are moot on. Here’s the readout I got in the console.Registered DotLogTimestamp.py callbacks Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] Initialisation took 94ms Ready. Traceback (most recent call last): File "C:\Users\<username>\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 19, in <module> import Tkinter as tk ImportError: No module named Tkinter Registered DotLogTimestamp.py callbacks Traceback (most recent call last): File "C:\Users\<username>\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 19, in <module> import Tkinter as tk ImportError: No module named Tkinter Traceback (most recent call last): File "C:\Users\<username>\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 19, in <module> import Tkinter as tk ImportError: No module named Tkinter
If you require a module to be loaded, either you need to include it, or at the least, state it is needed and where to get it.
:-( -
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
If you require a module to be loaded, either you need to include it, or at the least, state it is needed and where to get it.
Tkinter is part of PythonScript itself; for example, see the downloads from https://github.com/bruderstein/PythonScript/releases that have “Tk” in their names:
-
@Alan-Kilborn ,
Unfortunately, unless I’ve done something wrong, that doesn’t show up as part of the PythonScript libary modules. I checked. It’s in my standalone 3.10 Python, but it’s not installed as part of the Python27.dll or any of the files in the lib of that install in the PythonScript that is in NPP’sC:\Program Files\Notepad++\plugins\PythonScript\lib
.If I’ve messed something when installing the PythonScript plugin, I don’t know what it can be, because the PythonScript script files work, except for this one requiring the Tkinter module. ::shrug::
However, looking at your list of files, perhaps PythonScript has an upgrade that I haven’t installed, and since the Plugin manager hasn’t indicated an upgrade is available, I haven’t upgraded…so could that be the problem? And if so, what changes am I looking at having to make with regard scripts that are already usable in NPP, and what files/how to migrate to a newer version? Thanks in advance @Alan-Kilborn .
-
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
it’s not installed as part of the Python27.dll or any of the files in the lib of that install in the PythonScript that is in NPP’s C:\Program Files\Notepad++\plugins\PythonScript\lib.
Correct.
I don’t bother with installers when I don’t have to, so I’ve never installed PythonScript other than manually. So…I’m not 100% sure but I’d think that if you install it using an installer, you get the “Full” version (“full” meaning not everything but only what the PS maintainers consider “full”) from the list of files I presented in my last post. And “full” does NOT include Tkinter.
To get Tkinter, you MUST install that manually, by extracting a “TclTk” zip file into the appropriate folder of your existing PS plugin directory structure.
looking at your list of files, perhaps PythonScript has an upgrade that I haven’t installed
My intent was to just show how the files are distributed, not any specific version.
I showed version 3 of PS because that’s the one I use.
The only PS version currently available via Plugins Admin is PS2 (apparently that is the version its developer’s recommend for most users).And…note that if you’re using PS2, you (somewhat obviously) need the “TckTk” file appropriate to that version.
-
@Alan-Kilborn ,
Thanks, so that means I have to track down a 2.7 version Tkinter module file, since what I’ve read, 2.7 has been discontinued since 2002 for development. I was reading that every version is a pre release, and no mentions of any stable version since 2.7 so I’m guessing that’s why the developer decided to stay with it.
Thanks again. It helps, since I’m not a regular Python or PythonScript guy, I just need it to run other peoples work. :-) -
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
…that means I have to track down…
Is it really that hard to find? Try HERE.
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
2.7 has been discontinued
Very true.
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
I’m guessing that’s why the developer decided to stay with it (Python 2.7)
There are special reasons that PythonScript is in somewhat of a split personality state. PS2 is great for those that work with files with legacy encoding (called ANSI in Notepad++ terminology) and it is harder to work with modern (Unicode) files. PS3 is perfect for Unicode, but not compatible at all with ANSI files.
-
@Alan-Kilborn ,
Thanks. I did find it while this window was open, and did an install and followed the instructions to find out if the tkinter is installed correctly, but the installer has no specific option to install tkinter and the IDLE, even though I’ve checked them in the installer that is supposed to install them all. I then look and I see…_tkinter
in the lib directory, so I know it’s there, I’m guessing that the installer doesn’t install it per se, so I’m trying to figure out what to do next to get it just to work with a Python install, let alone the NPP PythonScript.Be back if I’m still having problems with it, but I think I’m about done for the night…can’t play anymore. :( But this is what I’m getting in the console now, so something has changed after I copied the lib directories of the package in to the plugin directory under the install directory. I have no idea what it means, but will play again tomorrow.
Registered DotLogTimestamp.py callbacks Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] Initialisation took 172ms Ready. Traceback (most recent call last): File "C:\Users\camilee\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 140, in <module> load_language_settings() File "C:\Users\camilee\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 98, in load_language_settings os.makedirs(folder_path) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 5] Access is denied: 'plugins/Config/PythonScript' Traceback (most recent call last): File "C:\Users\camilee\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 140, in <module> load_language_settings() File "C:\Users\camilee\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\code.beautifier.py", line 98, in load_language_settings os.makedirs(folder_path) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Program Files\Notepad++\plugins\PythonScript\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 5] Access is denied: 'plugins/Config/PythonScript'
-
@Lycan-Thrope @Alan-Kilborn
Hey everyone!I’m surprised that the script doesn’t work out of the box, I just downloaded a portable version of Notepad++ v8.6.4 and installed the PythonScript 2 plugin from the “Plugins Admin” menu. Created a new script file with the Code Beautifier code and ran it. Everything is working on my end without any external or manual downloads, normally the Tkinter module should be available in the standard PythonScript 2 plugin.
I haven’t tested the script with Python3 yet, keep in mind the “Tkinter” module is named different in both versions of Python.
Python2 = Tkinter
Python3 = tkinter -
@Khundian-Twitch said in Code Beautifier 1.0 (PythonScript):
…normally the Tkinter module should be available in the standard PythonScript 2 plugin.
This is not correct…or, at least, it’s not my experience.
I just tried installing the PythonScript plugin (v.2.0.0.0) via Plugins Admin into a fresh Notepad++.
Then I tried to import Tkinter (or even tkinter) in the PS console:It’s pretty clear that it isn’t there with a Plugins admin install.
-
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
did an install and followed the instructions to find out if the tkinter is installed correctly, but the installer has no specific option to install tkinter and the IDLE, even though I’ve checked them in the installer that is supposed to install them all. I then look and I see… _tkinter in the lib directory, so I know it’s there, I’m guessing that the installer doesn’t install it per se, so I’m trying to figure out what to do next to get it just to work with a Python install, let alone the NPP PythonScript.
To be clear, nothing I’m talking about is relating to getting Tkinter into a non-PythonScript situation (i.e., getting it into a standard/standalone Python). Discussion of that is really outside of the scope of this forum and should be discussed elsewhere, if needed.
So…if we’re talking only about PythonScript… (and we are):
First (and I thought this was totally clear from earlier posting where I said To get Tkinter, you MUST install that manually, by extracting a “TclTk” zip file into the appropriate folder of your existing PS plugin directory structure), there is no installer for Tkinter on PS. Period. End of story. Let’s stop talking about installers (ugh!).
What you want to do is to grab
PythonScript_TclTk_2.0.0.0_x64.zip
(if using 64-bit N++) and unzip that into your N++ folder (where you can see the existingplugins
folder in it).Restart Notepad++ and try an
import Tkinter
in the PS console window and it should not fail (i.e. no red error messages):At that point you should (obviously) be good to go from a Tkinter standpoint.
I don’t know what problems you’ll encounter (if any) with the Code Beautifier script, as I haven’t tried that myself. -
@Alan-Kilborn @Lycan-Thrope
Alan is right, I forgot I have the full Python 2.7.18 release installed on my workstation. Hence the reason why it worked out of the box for me. Apologies for the confusion.You can install/enable the Tkinter module as Alan described above or you can install the full Python 2.7.18 release version from here. Either of these options should enable you to use the Tkinter module.
-
@Khundian-Twitch A relative path of
settings_folder = "plugins/Config/PythonScript/scripts/Code Beautifier" # Folder containing language settings files
will operate in the current working directory (cwd). The cwd can be the root of where notepad.exe is located. This may work for portable, though Notepad++ installed in
C:\Program Files\Notepad++
can cause the errorWindowsError: [Error 5] Access is denied
as unable to create folders or files in that location.I suggest an absolute path to the plugin config directory to ensure a writable location:
settings_folder = os.path.join(notepad.getPluginConfigDir(), r"PythonScript\scripts\Code Beautifier") # Folder containing language settings files
The change suggested is with line 28 .
-
@Khundian-Twitch said in Code Beautifier 1.0 (PythonScript):
you can install the full Python 2.7.18 release version
But you neglected to say that you must change your PS Configuration in order to use this. I’m not on my PC right now, so I can’t give the exact name of the setting for this.
It is best, when possible, to NOT demand that users have a standalone Python on their system in order to use scripts with Notepad++ – users that don’t already do Python are probably 0% likely to do this anyway. In this case (for the script in this thread), it is possible, as Tkinter does have a PS way to be run (discussed ad nauseum in this thread already).
-
@mpheath said in Code Beautifier 1.0 (PythonScript):
@Khundian-Twitch A relative path of
settings_folder = "plugins/Config/PythonScript/scripts/Code Beautifier" # Folder containing language settings files
will operate in the current working directory (cwd). The cwd can be the root of where notepad.exe is located. This may work for portable, though Notepad++ installed in
C:\Program Files\Notepad++
can cause the errorWindowsError: [Error 5] Access is denied
as unable to create folders or files in that location.I suggest an absolute path to the plugin config directory to ensure a writable location:
settings_folder = os.path.join(notepad.getPluginConfigDir(), r"PythonScript\scripts\Code Beautifier") # Folder containing language settings files
The change suggested is with line 28 .
Thanks for the suggestion, when I have some time I’ll have a look at the script to ensure compatibility with the installer version of Notepad++. Probably over the weekend.
@Alan-Kilborn said in Code Beautifier 1.0 (PythonScript):
@Khundian-Twitch said in Code Beautifier 1.0 (PythonScript):
you can install the full Python 2.7.18 release version
But you neglected to say that you must change your PS Configuration in order to use this. I’m not on my PC right now, so I can’t give the exact name of the setting for this.
It is best, when possible, to NOT demand that users have a standalone Python on their system in order to use scripts with Notepad++ – users that don’t already do Python are probably 0% likely to do this anyway. In this case (for the script in this thread), it is possible, as Tkinter does have a PS way to be run (discussed ad nauseum in this thread already).
I agree that your method is preferred over installing a standalone version of Python, but I didn’t have to change any PythonScript configuration to be able to use Tkinter.
-
@Alan-Kilborn,
Thanks @Alan-Kilborn . I apparently went awry somewhere along the way, followed your instructions, and had to retrace the installation of the script’s placement in the NPP directory, rather than the user directory, and then I changed the path at line 28, restarted NPP, and although I still had a problem getting it to work, I finally put the “quotes” around the keyword and got it to finally show the UI aspects. I’ll play more later.This brings up, @Khundian-Twitch , that you have to write instructions for an idiot like me, so I don’t screw them up. Which means you need to (as I did for my own dBASEPlus installer) assume nothing and either make it so the install is brain dead simple, or the instructions are written to a neophyte understanding level. As @Alan-Kilborn points out, the more difficult and detailed and with missing details the process is, the less likely you’ll have users to use it.
I’m a programmer, but not a Python or PythonScript programmer. I only use it because the scripts you guys write, need them to work, otherwise I’d be fine not bothering with Python at all. I’m slowly looking to do some programming in Python/PythonScript eventually, but not today. :-) Write for the idiot in us. :-)
-
@Khundian-Twitch ,
Have an issue I’m not sure of if is your plug in issue. I have two dBASE UDL’s. One for DarkMode and one for non-DarkMode. Named differently and when I tried to trigger the Beautifier in the non-DarkMode, it ignores it as another UDL. It would be in the same Alphabetic lettering, but is named, dBASEPlus and the DarkMode is…of course Dark_dBASEPlus. Only the DarkMode version is showing up in your Alphabetic listing.
Just an FYI. -
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
@Khundian-Twitch ,
Have an issue I’m not sure of if is your plug in issue. I have two dBASE UDL’s. One for DarkMode and one for non-DarkMode. Named differently and when I tried to trigger the Beautifier in the non-DarkMode, it ignores it as another UDL. It would be in the same Alphabetic lettering, but is named, dBASEPlus and the DarkMode is…of course Dark_dBASEPlus. Only the DarkMode version is showing up in your Alphabetic listing.
Just an FYI.Thanks for reporting your issue.
The script doesn’t pick up the non-dark version because “D” doesn’t equal “d”, make sure your language name starts with a capital letter and it will work without an issue.
When I have some time off, I’ll have a look at the script to make it case insensitive.
-
@Khundian-Twitch said in Code Beautifier 1.0 (PythonScript):
The script doesn’t pick up the non-dark version because “D” doesn’t equal “d”, make sure your language name starts with a capital letter and it will work without an issue.
When I have some time off, I’ll have a look at the script to make it case insensitive.
Thanks for verifying that, and taking a look to possibly change it. It actually is the products proper name, “dBASE”, so it’s more recognizable to people that know about it. Dark_ was just added so they could know the difference and setup their color scheme differently depending on the option they chose.
They use the same functionList and overrideMap .xml files, but each version has it’s own autoComplete.xml file and UDL language .xml file for coloring accordingly. Still playing and finding things out as I go. :-)
-
@Khundian-Twitch ,
More bad news, I’m afraid. Even using the capitalized language, option in your beautifier, it is not working on my code. I tried it straight from the IDE that generates code, and then I wrote one in Notepad++, with no formatting at all (all text was flush left), initiated your script, chose my language and all the settings that I had in there last time I made the beautifier settings, it did not carry them over, apparently. So, I redid some of them and then saved the file…and nothing.So, I either have bad settings here, somehow, although your script is apparently working to call up the dialog box, but it’s not doing any beautifying at all. :-(
-
@Lycan-Thrope said in Code Beautifier 1.0 (PythonScript):
@Khundian-Twitch ,
More bad news, I’m afraid. Even using the capitalized language, option in your beautifier, it is not working on my code. I tried it straight from the IDE that generates code, and then I wrote one in Notepad++, with no formatting at all (all text was flush left), initiated your script, chose my language and all the settings that I had in there last time I made the beautifier settings, it did not carry them over, apparently. So, I redid some of them and then saved the file…and nothing.So, I either have bad settings here, somehow, although your script is apparently working to call up the dialog box, but it’s not doing any beautifying at all. :-(
Can you go in a bit more detail what exactly isn’t working? Each language should have its own button in the alphabetical language list and a settings file, no settings are “carried over” between languages.
Does each “version” of the language have a seperate button in the alphabetical language list? If this is not the case, most probably the language settings file with the lowercase starting letter is still in the settings folder “\plugins\Config\PythonScript\scripts\Code Beautifier”. Make sure the settings file starts wiith a capital letter, and that you have configured the settings for each language through the GUI. When this is done, the script should beautify your code in both “versions” of the language. Let me know if this fixes your issue.
I will get around to fixing this annoying case sensitive thing, but between work and family there isn’t any time left atm.