ida_kernwin.Choose window closing during debug start/exit

I created a plugin that uses a ida_kernwin.Choose window as the main interface. When this window is open and I enter a debug session, it automatically gets closed. When it’s opened after entering a debug session and the session ends, it gets closed again. How do I keep it open upon debug start/exit?

The chooser is closed because the debugging desktop has its own set of tabs and windows. One option could be to save the debugger desktop with your chooser open, but you could also try to hook the ui_desktop_applied event and reopen it yourself.

Please also check auto_instantiate_widget_plugin.py sample

So from some experimentation this is how I understand it. The widget is removed from view when the desktop changes (assuming the object isn’t destroyed since I can call .Show on the same widget later). When the desktop is redrawn create_desktop_widget is called for each window widget. If my plugin widget isn’t open when entering debug mode create_desktop_widget isn’t called for it when exiting debug mode. However, if it was open and debug mode exits, create_desktop_widget is called for it even if the desktop mode was not specifically saved to include it (confirmed by printing out the titles for all widgets in create_desktop_widget).

Now, my plugin creates the widget in .init, and opens it in .run (chooser.Show), and I’m able to view the widget after exiting debug mode repeatedly by just reselecting the plugin from the plugins menu, ie, the widget object isn’t created again, just reused. Now here’s the part I don’t get. when I call .Show (when ttl is set to my widget title, it returns 0) from create_desktop_widget my widget isn’t displayed, and opening the plugin from the plugin menu again doesn’t show the widget either (now returns -3, even though the widget isn’t visible).

Trying to create a new widget instead of displaying the old one does the same thing. It seems that within create_desktop_widget the widget is marked as being visible. But never actually drawn, and since it’s marked as visible I can’t call .Show again.

I can’t see anything specific in the demo code to try and account for this, thought I guess there could be some subtle problem with my solution. Any feedback would be appreciated, for reference, code excluding the demo create_desktop_widget code here.

class UIHooks(ida_kernwin.UI_Hooks):

    def create_desktop_widget(self, ttl, cfg):
        print(f"[Code Filter] Creating desktop widget with title {ttl}")
        #if ttl == "Code Filter":
        #    self.code_filter.cf_chooser.Show()
        #    return self.code_filter.cf_chooser.GetWidget()

EDIT:

I see now I should be returning the widget, not displaying it myself, however, returning my inherited chooser doesn’t work, and using mychooser.GetWidget() returns none, so still stuck.