0

我如何将另一个事件添加到我们的 GUI 管理器类(下)中创建的窗格中。我想检测 x 按钮何时关闭窗格。我已经尝试对 wx.EVT_CLOSE 使用与 wx.EVT_MENU 相同的格式,但它没有用。

    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

我希望能够在绘图子类中获取事件。

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)
4

1 回答 1

2

您是否尝试捕获 wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 或 wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED?我认为那会做你想要的。我假设您使用的是 wx.aui 而不是 wx.agw.aui。我怀疑后者是相似的。

编辑:哎呀。我读错了。我以为 OP 想了解 AUINotebook。您可能正在寻找的事件是 wx.aui.EVT_AUI_PANE_CLOSE

于 2012-04-23T17:35:07.920 回答