如何使用wxpython禁用OSX中的窗口关闭按钮?

时间:2009-06-28 11:03:52

标签: macos wxpython

我正在使用wxpython处理osx的应用程序。我想在用户点击窗口关闭按钮时最小化窗口到停靠栏,以便可以从停靠栏恢复它。我怎样才能做到这一点?目前我有恢复窗口的问题,因为它在用户点击关闭按钮时被破坏。我怎么能阻止它?

提前致谢

2 个答案:

答案 0 :(得分:5)

我这样做是这样的:

__init__方法中设置wx.EVT_CLOSE事件的处理程序和一个“真正”退出选项的菜单项。你需要这个,或者你永远不能关闭你的程序。

def OnClose(self,evt):
  #Turn closes into hides unless this is a quit application message / or OS shutting down
  if evt.CanVeto():
    self.Hide()
    evt.Veto()
  else:
      #if we don't veto it we allow the event to propogate
      evt.Skip() 

def OnMenuExit(self,evt):
  #Event handler for exit menu item
  self.Close(force=True)  #Stops the close handler vetoing it

您还应该确保在__init__中调用wx.App.SetMacExitMenuItemId( [ID OF YOUR EXIT MENU ITEM HERE] ),以便停靠上下文菜单中的退出项目路由到正确的菜单处理程序。

当窗口关闭时,这会给你一个很好的mac-ish隐藏。你需要知道应用程序仍在运行,并且可以调用其菜单,因为菜单栏仍然位于屏幕顶部。菜单事件处理程序中对self.Show()的战略调用是您的朋友。

当您的应用程序窗口被隐藏时,您还可以充分利用wx.TaskBarIcon与Dock进行良好的交互(例如,单击Dock以重新显示窗口)。

答案 1 :(得分:0)

你不能只绑定事件EVT_CLOSE并最小化,而不是使用EVT_ICONIZE的处理程序关闭

...
def __init__(self):
  ...
  self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
  ...
def onCloseWindow(self, event):
  ... do something else instead of closing ...
...
相关问题