File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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 ()
Original file line number Diff line number Diff line change 79
79
#editor.setRepresentation(u'\u000A', u'\u240A')
80
80
#editor.setRepresentation(u'\u000D', u'\u240D')
81
81
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
+
82
106
######################
83
107
def CCB ():
84
108
notepad .clearCallbacks ()
You can’t perform that action at this time.
0 commit comments