-
Dear community, I created a simple widget which displays name of the highlighted function, however it looks that I am doing something wrong when I try to add it to the dock. The widget class is defined in from binaryninjaui import DockHandler, DockContextHandler, UIActionHandler
from PySide6 import QtCore
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QLabel, QWidget, QMainWindow
class HelloDockWidget(QWidget, DockContextHandler):
def __init__(self, parent, name):
QWidget.__init__(self, parent)
DockContextHandler.__init__(self, self, name)
self.actionHandler = UIActionHandler()
self.actionHandler.setupActionHandler(self)
self.label = QLabel(name, self)
layout = QVBoxLayout()
layout.addWidget(self.label)
self.setLayout(layout)
def notifyViewLocationChanged(self, view, view_location):
action_context = view.actionContext()
bv = action_context.binaryView
token_state = action_context.token
if token_state.valid:
token = token_state.token
fun = bv.get_function_at(token.value)
if fun:
self.label.setText(fun.name)
# second part follows here... Now in the second part I tried two approaches. Using # ... file continues
dock_handler = DockHandler.getActiveDockHandler()
widget = HelloDockWidget(dock_handler.parent(), "Test")
dock_handler.addDockWidget(widget, Qt.AllDockWidgetAreas, Qt.Horizontal, True)
Second approach is to use # ... file continues (working option)
window = [ w.window() for w in QApplication.allWidgets() if w.__class__ == QMainWindow ][0]
dock_handler = window.findChild(DockHandler, '__DockHandler')
widget = HelloDockWidget(dock_handler.parent(), "Test")
dock_handler.addDockWidget(widget, Qt.AllDockWidgetAreas, Qt.Horizontal, True) Although this works, it feels somewhat wrong. I think I am missing some detail about where or how to trigger widget addition to the dock. Search of existing plugins shows that they do indeed use Two relevant additional questions:
Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Update
# ... file continues (working dynamic option
def create_dockable_widget(name, parent, bv):
return HelloDockWidget(parent, name)
dock_handler = DockHandler.getActiveDockHandler()
dock_handler.addDockWidget("Test", create_dockable_widget, QtCore.Qt.RightDockWidgetArea, QtCore.Qt.Horizontal, False) Magically it also solves the issue with deleted parent. 🎉 So the only left open point is about how to receive events on each token change:
|
Beta Was this translation helpful? Give feedback.
Hey, so,
DockWidget
s are actually a pretty old construct of ours and they're not really actively maintained. We've basically moved to a pane system with a sidebar area instead. We'd recommend re-implementing this as aSidebarWidget
instead (which also has anotifyViewLocationChanged
, especially becauseDockWidget
s will - at some point - be deprecated and removed.It's entirely possible that this was a bug that is now fixed in the
SidebarWidget
's implementation of that API. But, if it doesn't work there either, it's probably a limitation we haven't documented well enough.If you do wind up reimplementing in terms of
SidebarWidget
and can let us know how it goes, that'd be great. 🙂