From 0de53b97ef6cec57ab4bdfbb9a9e1b6503eecfab Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 2 Oct 2020 20:52:15 -0400 Subject: UIContext notifications (eg file open/save) --- python/examples/ui_notifications.py | 77 +++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 python/examples/ui_notifications.py (limited to 'python/examples/ui_notifications.py') diff --git a/python/examples/ui_notifications.py b/python/examples/ui_notifications.py new file mode 100644 index 00000000..8074a1c5 --- /dev/null +++ b/python/examples/ui_notifications.py @@ -0,0 +1,77 @@ +# Copyright (c) 2015-2020 Vector 35 Inc +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +from binaryninjaui import * + +class UINotification(UIContextNotification): + def __init__(self): + UIContextNotification.__init__(self) + UIContext.registerNotification(self) + print("py UIContext.registerNotification") + + def __del__(self): + UIContext.unregisterNotification(self) + print("py UIContext.unregisterNotification") + + def OnContextOpen(self, context): + print("py OnContextOpen") + + def OnContextClose(self, context): + print("py OnContextClose") + + def OnBeforeOpenDatabase(self, context, metadata): + print(f"py OnBeforeOpenDatabase {metadata.filename}") + return True + + def OnAfterOpenDatabase(self, context, metadata, data): + print(f"py OnAfterOpenDatabase {metadata.filename} {data.name}") + return True + + def OnBeforeOpenFile(self, context, file): + print(f"py OnBeforeOpenFile {file.getFilename()}") + return True + + def OnAfterOpenFile(self, context, file, frame): + print(f"py OnAfterOpenFile {file.getFilename()} {frame.getShortFileName()}") + + def OnBeforeSaveFile(self, context, file, frame): + print(f"py OnBeforeSaveFile {file.getFilename()} {frame.getShortFileName()}") + return True + + def OnAfterSaveFile(self, context, file, frame): + print(f"py OnAfterSaveFile {file.getFilename()} {frame.getShortFileName()}") + + def OnBeforeCloseFile(self, context, file, frame): + print(f"py OnBeforeCloseFile {file.getFilename()} {frame.getShortFileName()}") + return True + + def OnAfterCloseFile(self, context, file, frame): + print(f"py OnAfterCloseFile {file.getFilename()} {frame.getShortFileName()}") + + def OnViewChange(self, context, frame, type): + if frame: + print(f"py OnViewChange {frame.getShortFileName()} / {type}") + else: + print("py OnViewChange") + + +# Register as a global so it doesn't get destructed +notif = UINotification() + -- cgit v1.3.1