简体   繁体   中英

How do I get close event to work in wxPython using AUIManager?

How would I add another event to the pane created in our GUI manager class (below). I want to detect when the x button closes the pane. I've tried using the same format as wx.EVT_MENU for wx.EVT_CLOSE but it didn't work.

    def popup_panel(self, p):
    """
    Add a panel object to the AUI manager

    :param p: panel object to add to the AUI manager

    :return: ID of the event associated with the new panel [int]

    """
    ID = wx.NewId()
    self.panels[str(ID)] = p
    self.graph_num += 1
    if p.window_caption.split()[0] in NOT_SO_GRAPH_LIST:
        windowcaption = p.window_caption
    else:
        windowcaption = 'Graph'#p.window_caption
    windowname = p.window_name

    # Append nummber
    captions = self._get_plotpanel_captions()
    while (1):
        caption = windowcaption + '%s'% str(self.graph_num)
        if caption not in captions:
            break
        self.graph_num += 1
        # protection from forever-loop: max num = 1000
        if self.graph_num > 1000:
            break
    if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST:
        p.window_caption = caption 
    #p.window_caption = windowcaption+ str(self.graph_num)
    p.window_name = windowname + str(self.graph_num)

    style1 = self.__gui_style & GUIFRAME.FIXED_PANEL
    style2 = self.__gui_style & GUIFRAME.FLOATING_PANEL
    if style1 == GUIFRAME.FIXED_PANEL:
        self._mgr.AddPane(p, wx.aui.AuiPaneInfo().
                          Name(p.window_name).
                          Caption(p.window_caption).
                          Position(10).
                          Floatable().
                          Right().
                          Dock().
                          MinimizeButton().
                          Resizable(True).
                          # Use a large best size to make sure the AUI 
                          # manager takes all the available space
                          BestSize(wx.Size(PLOPANEL_WIDTH, 
                                           PLOPANEL_HEIGTH)))

        self._popup_fixed_panel(p)

    elif style2 == GUIFRAME.FLOATING_PANEL:
        self._mgr.AddPane(p, wx.aui.AuiPaneInfo().
                          Name(p.window_name).Caption(p.window_caption).
                          MinimizeButton().
                          Resizable(True).
                          # Use a large best size to make sure the AUI
                          #  manager takes all the available space
                          BestSize(wx.Size(PLOPANEL_WIDTH, 
                                           PLOPANEL_HEIGTH)))

        self._popup_floating_panel(p)

    # Register for showing/hiding the panel
    wx.EVT_MENU(self, ID, self.on_view)
    if p not in self.plot_panels.values() and p.group_id != None:
        self.plot_panels[ID] = p
        if len(self.plot_panels) == 1:
            self.panel_on_focus = p
            self.set_panel_on_focus(None)
        if self._data_panel is not None and \
            self._plotting_plugin is not None:
            ind = self._data_panel.cb_plotpanel.FindString('None')
            if ind != wx.NOT_FOUND:
                self._data_panel.cb_plotpanel.Delete(ind)
            if caption not in self._data_panel.cb_plotpanel.GetItems():
                self._data_panel.cb_plotpanel.Append(str(caption), p)
    return ID

I want to be able to pick up the event in the plotting child class.

def create_panel_helper(self, new_panel, data, group_id, title=None):
    """
    """
    ## Set group ID if available
    ## Assign data properties to the new create panel
    new_panel.set_manager(self)
    new_panel.group_id = group_id
    if group_id not in data.list_group_id:
        data.list_group_id.append(group_id)
    if title is None:
        title = data.title
    new_panel.window_caption = title
    new_panel.window_name = data.title
    event_id = self.parent.popup_panel(new_panel)
    #remove the default item in the menu
    if len(self.plot_panels) == 0:
        pos = self.menu.FindItem(DEFAULT_MENU_ITEM_LABEL)
        if pos != -1:
            self.menu.Delete(DEFAULT_MENU_ITEM_ID)
    # Set UID to allow us to reference the panel later
    new_panel.uid = event_id
    # Ship the plottable to its panel
    wx.CallAfter(new_panel.plot_data, data) 
    self.plot_panels[new_panel.group_id] = new_panel

    # Set Graph menu and help string        
    helpString = 'Show/Hide Graph: '
    for plot in  new_panel.plots.itervalues():
        helpString += (' ' + plot.label + ';')
    self.menu.AppendCheckItem(event_id, new_panel.window_caption, 
                              helpString)
    self.menu.Check(event_id, IS_WIN)
    wx.EVT_MENU(self.parent, event_id, self._on_check_menu)
    wx.EVT_CLOSE(self.parent, event_id, self._on_close_panel)
    wx.EVT_SHOW(new_panel, self._on_show_panel)

Did you try catching wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE or wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED? I would think that would do what you want. I am assuming you're using wx.aui rather than wx.agw.aui. I suspect the latter is similar though.

EDIT: Oops. I read this wrong. I thought the OP wanted to know about AUINotebook. The event you're probably looking for is wx.aui.EVT_AUI_PANE_CLOSE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM