PythonScript Toggleable Script?
-
So…all this is great, but I really don’t see an advantage to it (the whole concept), and this is why:
-
if you’re a dedicated keyboardist, you’d have to dive for the mouse in order to hit the toolbar button to change the mode, spoiling being dedicated to the keyboard (where you could just add Alt to your Shift+arrows movement to get a column block).
-
if you’re not in love with keyboard-only actions, use the mouse to select text via click and drag; if you start this as a stream selection, you can add a press of Alt to it while you are dragging (can even just tap-n-release Alt) in order to change the selection to a column block type.
But…people will want what they will want, and that’s ok. :-)
-
-
Okay, going back to what the this thread was originally about, my toggle function is not working as I thought it would. If I go to click it to toggle it off, I get the following messagebox text:
“Another script is currently running. Running two scripts at the same time could produce unpredictable results, and is therefore disabled.”
I’m wondering how I can make it so that the user can break the infinite loop in my script by clicking on the button for the script again, essentially making it toggleable. Anyone got an idea? It would be much appreciated.
-
@john-doe-1 said in PythonScript Toggleable Script?:
how I can make it so that the user can break the infinite loop in my script
Possible solution: Don’t put an infinite loop in the script in the first place?
-
@john-doe-1 said in PythonScript Toggleable Script?:
I’m wondering how I can make it so that the user can break the infinite loop in my script by clicking on the button for the script again
By writing it without an infinite loop. The three line script I supplied is all you need to be able to easily convert a normal selection to a rectangle/column selection after the selection is made. Or the ⇅ script I showed you will allow a toggle-on/toggle-off without requiring an infinite loop.
I cannot say it any more plainly.
-
@alan-kilborn @PeterJones The reason for the infinite loop is that I want to make the script act like a toggle that works for not only arrow keys but also clicking and dragging for selection. I have the following statement in my infinite loop (among others):
editor.setSelectionMode(SELECTIONMODE.RECTANGLE)
This is the only way to be able to click and drag rectangle select persistently, it works for arrow key selection as well, only thing is if it is not in an infinite loop then that functionality no longer works.
Edit: Is there a function that can check if another PythonScript is being launched? That would be a good way to break the loop.
-
Did you not try my scripts? Because both ⇅ and the “simplest” will work, whether you use the keyboard or clicking and dragging. With ⇅ , click where you want to start the selection, then run the script, then click-and-drag to the end of the selection, then run the script, and it will convert that click-and-drag-selection to rectangle. With the “simplest” script, just click-and-drag your selection, then run the script, and it will convert that click-and-drag-selection to rectangle.
The infinite loop will not work for you. Stop trying to make it work. It is the wrong design. Every one of the problems you have run across has proven that to everyone (except you, who seems unwilling to accept an alternate solution that works better).
I have already written multiple scripts, and shown you how it works, in words and in video. If you are unwilling to go this route, I cannot help you beyond this. I am sorry. Good luck.
-
In case you don’t know which I mean by simplest, here is the version I have saved as
SelectionToRectangle.py
in my instance. I am actually going to use that in my workflow occasionally, because I am sometimes on a linux box and remote-desktop-connecting into my windows laptop, and the ALT key doesn’t transmit properly, so previously I wasn’t able to column selection; now I have a simple way to easily switch a normal selection to column selection, without using the ALT key.# encoding=utf-8 """ Derived from 22890-simplest.py, in response to https://community.notepad-plus-plus.org/topic/22890/ This is the simplest paradigm for converting a stream (normal) selection to rectangular (column): 1) Click or arrow to where you want to start selecting 2) Shift+Click or Shift+arrow to get to the end of the selection (ie, do a normal selection) 3) Run this script to convert the selection from STREAM to rectangle and refresh the screen automatically to see it """ from Npp import notepad, editor, SELECTIONMODE, STATUSBARSECTION editor.setSelectionMode( SELECTIONMODE.RECTANGLE ) notepad.activateFile(notepad.getCurrentFilename()) # use the activateFile() command to refresh UI; otherwise, it doesn't _look_ like column/rectangle select)
-
-
@peterjones Thank you, I do very much appreciate all of your help. It has helped greatly, I can be very picky trying to get a program to behave exactly how I want, my apologies for that, I understand it can be too much of a time sink and sometimes impossible.
-
@john-doe-1 said in PythonScript Toggleable Script?:
I can be very picky trying to get a program to behave exactly how I want
Sure, I understand this; I have Notepad++ heavily customized with scripts to have it behave how I want. But…when you do something like this, you have to understand the limitations of the environment you are working within, in order to “not” overstep your bounds.
Using things which hold keys down, writing infinite loops, running multiple scripts before one is finished…all of these are bad ideas in the context of what PythonScript aims to provide to Notepad++ users.
I really don’t know how to provide advice on what to not do, though, until you do it and post here asking for advice on how to solve encountered problems. :-)
-
@alan-kilborn You’re exactly correct, this has been a great learning experience for me regarding Notepad++ plugin development. I plan to continue improving my current plugins and write new ones. Once again thank you @Alan-Kilborn and @PeterJones for pointing me in the right direction, you’ve been helped a great deal! : - )
-
-