Skip to content

Commit 9f3efef

Browse files
committed
Do PoC for -pluginMessage processing in PythonScript
1 parent ba79d7d commit 9f3efef

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# encoding=utf-8
2+
"""in response to https://community.notepad-plus-plus.org/topic/26689/
3+
4+
Example processing of NPPN_CMDLINEPLUGINMSG notification
5+
"""
6+
from Npp import notepad, console, NOTIFICATION
7+
import ctypes
8+
import sys
9+
10+
def usePluginMessageString(s):
11+
console.write(f"TODO: do something more interesting with -pluginMessage=\"{s}\"\n")
12+
13+
def getStringFromNotification(args):
14+
code = args['code'] if 'code' in args else None
15+
idFrom = args['idFrom'] if 'idFrom' in args else None
16+
hwndFrom = args['hwndFrom'] if 'hwndFrom' in args else None
17+
#console.write(f"notification(code:{code}, idFrom:{idFrom}, hwndFrom:{hwndFrom}) received\n")
18+
if idFrom is None: return
19+
s = ctypes.wstring_at(idFrom)
20+
#console.write(f"\tAdditional Info: str=\"{s}\"\n")
21+
usePluginMessageString(s)
22+
23+
def getStringFromCommandLine():
24+
for token in sys.argv:
25+
if len(token)>15 and token[0:15]=="-pluginMessage=":
26+
s = token[15:]
27+
#console.write(f"TODO: process {token} => \"{s}\"\n")
28+
usePluginMessageString(s)
29+
30+
notepad.callback(getStringFromNotification, [NOTIFICATION.CMDLINEPLUGINMSG])
31+
console.write("Registered getStringFromNotification callback for CMDLINEPLUGINMSG\n")
32+
getStringFromCommandLine()

pythonScripts/startup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@
7979
#editor.setRepresentation(u'\u000A', u'\u240A')
8080
#editor.setRepresentation(u'\u000D', u'\u240D')
8181

82+
######################
83+
##!!## The following can be uncommented to experiment with one or more notifications
84+
##!!def myFunction(args):
85+
##!! code = args['code'] if 'code' in args else None
86+
##!! idFrom = args['idFrom'] if 'idFrom' in args else None
87+
##!! hwndFrom = args['hwndFrom'] if 'hwndFrom' in args else None
88+
##!! console.write(f"notification(code:{code}, idFrom:{idFrom}, hwndFrom:{hwndFrom}) received\n")
89+
##!! if code==NOTIFICATION.CMDLINEPLUGINMSG:
90+
##!! if idFrom is None: return
91+
##!! str = ctypes.wstring_at(idFrom)
92+
##!! console.write(f"\tAdditional Info: str=\"{str}\"\n")
93+
##!!
94+
##!!notepad.callback(myFunction, [NOTIFICATION.CMDLINEPLUGINMSG])
95+
##!!#notepad.callback(myFunction, list(range(1001,1032))) # should be every notification
96+
##!!console.write("Registered myFunction callback for CMDLINEPLUGINMSG\n")
97+
##!!myFunction(dict(code=1, hwndFrom=2, idFrom=3))
98+
######################
99+
100+
######################
101+
# process -pluginMessage="" from the command-line
102+
#import pluginNotification26689
103+
######################
104+
105+
82106
######################
83107
def CCB():
84108
notepad.clearCallbacks()

0 commit comments

Comments
 (0)