Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Added .isEvent() to NeutralinoExtension.py
  • Loading branch information
hschneider committed Nov 27, 2023
1 parent da5aaf9 commit 94906c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def ping(d):

ext.sendMessage('pingResult', f'Python says PONG, in reply to "{d}"')

def processAppEvent(data):
def processAppEvent(d):
"""
Handle Neutralino app events.
:param data: data package as JSON dict.
:param d: data package as JSON dict.
:return: ---
"""

if 'event' in data and data['event'] == 'runPython':
(f, d) = ext.parseFunctionCall(data)
if ext.isEvent(d, 'runPython'):
(f, d) = ext.parseFunctionCall(d)

# Process incoming function calls:
# f: function name, d: data as JSON or string
Expand Down Expand Up @@ -181,6 +181,7 @@ Below this link, you see
|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| NeutralinoExtension(debug=false) | Extension class. debug: Print data flow to the terminal. |
| debugLog(msg, tag="info") | Write a message to the terminal. msg: Message, tag: The message type, "in" for incoming, "out" for outgoing, "info" for others. |
| isEvent(data, eventName) | Checks if the incoming data package contains a particular event. |
| parseFunctionCall(d) | Extracts function-name (f) and parameter-data (p) from a message data package. Returns (f, p). |
| async run(onReceiveMessage) | Starts the sockethandler main loop. onReceiveMessage: Callback function for incoming messages. |
| sendMessage(event, data=None) | Send a message to Neutralino. event: Event-name, data: Data package as string or JSON dict. |
Expand Down
13 changes: 12 additions & 1 deletion extensions/python/NeutralinoExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class NeutralinoExtension:
def __init__(self, debug=False):

self.version = "1.1.8"
self.version = "1.1.9"

parser = ArgumentParser()
parser.add_argument('--nl-port')
Expand Down Expand Up @@ -134,6 +134,17 @@ def parseFunctionCall(self, d):

return f, p

def isEvent(self, e, eventName):
"""
Check if e contains a particular event.
:param e: Event data package as dict.
:param eventName: Event name as string
:return: Boolean
"""
if 'event' in e and e['event'] == eventName:
return True
return False

def debugLog(self, msg, tag="info"):
"""
Log messages to terminal.
Expand Down
10 changes: 5 additions & 5 deletions extensions/python/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# main.py 1.0.1
# main.py 1.0.2
#
# Neutralino PythonExtension.
#
Expand All @@ -14,15 +14,15 @@ def ping(d):

ext.sendMessage('pingResult', f'Python says PONG, in reply to "{d}"')

def processAppEvent(data):
def processAppEvent(d):
"""
Handle Neutralino app events.
:param data: data package as JSON dict.
:param d: data package as JSON dict.
:return: ---
"""

if 'event' in data and data['event'] == 'runPython':
(f, d) = ext.parseFunctionCall(data)
if ext.isEvent(d, 'runPython'):
(f, d) = ext.parseFunctionCall(d)

# Process incoming function calls:
# f: function-name, d: data as JSON or string
Expand Down

0 comments on commit 94906c3

Please sign in to comment.