diff options
Diffstat (limited to 'python/examples')
| -rw-r--r-- | python/examples/helloglobalarea.py | 6 | ||||
| -rw-r--r-- | python/examples/hellosidebar.py | 15 |
2 files changed, 20 insertions, 1 deletions
diff --git a/python/examples/helloglobalarea.py b/python/examples/helloglobalarea.py index ca288525..1b7332fc 100644 --- a/python/examples/helloglobalarea.py +++ b/python/examples/helloglobalarea.py @@ -30,6 +30,12 @@ from PySide6.QtGui import QImage, QPixmap, QPainter, QFont, QColor instance_id = 0 +# In Binary Ninja 4.0, global area widgets have been moved to the more flexible sidebar system. +# Plugins should use SidebarWidget instead of GlobalAreaWidget. To provide the same functionality, +# return `SidebarWidgetLocation.LeftBottom` from `SidebarWidgetType.defaultLocation` and return +# `SidebarWidgetContextSensitivity.GlobalSidebarContext` from `SidebarWidgetType.contextSensitivity`. +# See `hellosidebar.py` for an example of how to create a `SidebarWidget`. + # Global area widgets must derive from GlobalAreaWidget, not QWidget. GlobalAreaWidget is a QWidget but # provides callbacks for global area events, and must be created with a title. class HelloGlobalAreaWidget(GlobalAreaWidget): diff --git a/python/examples/hellosidebar.py b/python/examples/hellosidebar.py index 2fc0cbf7..5f798d09 100644 --- a/python/examples/hellosidebar.py +++ b/python/examples/hellosidebar.py @@ -21,7 +21,8 @@ # This is an example UI plugin which demonstrates how to add sidebar widgets to Binary Ninja. # See .../api/ui/sidebar.h for interface details. -from binaryninjaui import SidebarWidget, SidebarWidgetType, Sidebar, UIActionHandler +from binaryninjaui import SidebarWidget, SidebarWidgetType, Sidebar, UIActionHandler, SidebarWidgetLocation, \ + SidebarContextSensitivity from PySide6 import QtCore from PySide6.QtCore import Qt, QRectF from PySide6.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QLabel, QWidget @@ -104,6 +105,18 @@ class HelloSidebarWidgetType(SidebarWidgetType): # widget is visible and the BinaryView becomes active. return HelloSidebarWidget("Hello", frame, data) + def defaultLocation(self): + # Default location in the sidebar where this widget will appear + return SidebarWidgetLocation.RightContent + + def contextSensitivity(self): + # Context sensitivity controls which contexts have separate instances of the sidebar widget. + # Using `contextSensitivity` instead of the deprecated `viewSensitive` callback allows sidebar + # widget implementations to reduce resource usage. + + # This example widget uses a single instance and detects view changes. + return SidebarContextSensitivity.SelfManagedSidebarContext + # Register the sidebar widget type with Binary Ninja. This will make it appear as an icon in the # sidebar and the `createWidget` method will be called when a widget is required. |
