def OnMenuOpen(self, event: wx.MenuEvent) -> None: if event.GetMenu() is not self: # We may be just opening one of the submenus but we only # want to do this when opening the main menu. event.Skip() return main_window = wx.GetApp().GetTopWindow() all_windows = { w for w in wx.GetTopLevelWindows() if w is not main_window } for window in all_windows.difference(self._id_to_window.values()): if not window.Title: # We have bogus top-level windows because of the use # of AuiManager on the logging window (see issue #617) # so skip windows without a title. continue menu_item = wx.MenuItem(self, wx.ID_ANY, window.Title) self.Bind(wx.EVT_MENU, self.OnWindowTitle, menu_item) self._id_to_window[menu_item.Id] = window # Place this menu item after the "Reset window positions" # but before the log viewer and debug window. position = len(self._id_to_window) self.Insert(position, menu_item)
def OnMenuOpen(self, event: wx.MenuEvent) -> None: if event.GetMenu() is not self: # We may be just opening one of the submenus but we only # want to do this when opening the main menu. event.Skip() return main_window = wx.GetApp().GetTopWindow() all_windows = { w for w in wx.GetTopLevelWindows() if w is not main_window } for window in all_windows.difference(self._id_to_window.values()): if not window.Title: # We have bogus top-level windows because of the use # of AuiManager on the logging window (see issue #617) # so skip windows without a title. continue sub_menu = wx.Menu() for label, method in [ ('Show/Hide', self.OnShowOrHide), ('Raise to top', self.OnRaiseToTop), ('Move to mouse', self.OnMoveToMouse), ]: menu_item = sub_menu.Append(wx.ID_ANY, label) sub_menu.Bind(wx.EVT_MENU, method, menu_item) self._id_to_window[menu_item.Id] = window # Place this submenu after the "Reset window positions" # but before the log viewer and debug window. position = len(self._id_to_window) / 3 self.Insert(position, wx.ID_ANY, window.Title, sub_menu)