如何使用AUIManager在wxPython中使用close事件?

时间:2012-04-20 10:14:26

标签: python events wxpython

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

    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)

1 个答案:

答案 0 :(得分: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