WxAppShell.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """
  2. WxAppShell provides a GUI application framework using wxPython.
  3. This is an wxPython version of AppShell.py
  4. """
  5. import wx
  6. import sys
  7. class WxAppShell(wx.Frame):
  8. appversion = '1.0'
  9. appname = 'Generic Application Frame'
  10. copyright = ('Copyright 2008 Walt Disney Internet Group.' +
  11. '\nAll Rights Reserved.')
  12. contactname = 'Gyedo Jeon'
  13. contactemail = '[email protected]'
  14. frameWidth = 450
  15. frameHeight = 320
  16. padx = 5
  17. pady = 5
  18. usecommandarea = 0
  19. usestatusarea = 0
  20. balloonState = 'none'
  21. panelCount = 0
  22. def __init__(self, *args, **kw):
  23. # Initialize the base class
  24. if not kw.get(''):
  25. kw['title'] = self.appname
  26. if not kw.get('size'):
  27. kw['size'] = wx.Size(self.frameWidth, self.frameHeight)
  28. wx.Frame.__init__(self, None, -1, *args, **kw)
  29. self._logWin = None
  30. # Initialize the application
  31. self.appInit()
  32. self.__createInterface()
  33. self.Show()
  34. def __createInterface(self):
  35. self.__createLogWin()
  36. self.__createMenuBar()
  37. self.__createAboutBox()
  38. # Add binding for panel cleanup code
  39. self.Bind(wx.EVT_CLOSE, self.quit)
  40. #
  41. # Create the parts of the interface
  42. # which can be modified by subclasses
  43. #
  44. self.createMenuBar()
  45. self.createInterface()
  46. def __createLogWin(self, evt=None):
  47. # to bypass wx.Log
  48. if self._logWin:
  49. self._logWin.Destroy()
  50. self._logWin = wx.Frame(None)
  51. self._logWin.Bind(wx.EVT_CLOSE, self.__createLogWin)
  52. wx.Log.SetActiveTarget(wx.LogTextCtrl(wx.TextCtrl(self._logWin, style=wx.TE_MULTILINE)))
  53. def __createMenuBar(self):
  54. self.menuBar = wx.MenuBar()
  55. self.SetMenuBar(self.menuBar)
  56. def __createAboutBox(self):
  57. self.about = wx.MessageDialog(None,
  58. self.appname + "\n\n" +
  59. 'Version %s'%self.appversion + "\n\n" +
  60. self.copyright + "\n\n" +
  61. 'For more information, contact:\n%s\nEmail: %s' %\
  62. (self.contactname, self.contactemail),
  63. "About %s"%self.appname, wx.OK | wx.ICON_INFORMATION)
  64. def showAbout(self, event):
  65. # Create the dialog to display about and contact information.
  66. self.about.ShowModal()
  67. def quit(self, event=None):
  68. self.onDestroy(event)
  69. # to close Panda
  70. from direct.showbase import ShowBaseGlobal
  71. if hasattr(ShowBaseGlobal, 'base'):
  72. ShowBaseGlobal.base.userExit()
  73. else:
  74. sys.exit()
  75. ### USER METHODS ###
  76. # To be overridden
  77. def appInit(self):
  78. # Called before interface is created (should be overridden).
  79. pass
  80. def createInterface(self):
  81. # Override this method to create the interface for the app.
  82. pass
  83. def onDestroy(self, event):
  84. # Override this method with actions to be performed on panel shutdown
  85. pass
  86. def createMenuBar(self):
  87. # Creates default menus.
  88. # Override if you don't want to use default menus
  89. self.menuFile = wx.Menu()
  90. self.menuBar.Append(self.menuFile, "&File")
  91. self.menuHelp = wx.Menu()
  92. self.menuBar.Append(self.menuHelp, "&Help")
  93. menuItem = self.menuFile.Append(wx.ID_EXIT, "&Quit")
  94. self.Bind(wx.EVT_MENU, self.quit, menuItem)
  95. menuItem = self.menuHelp.Append(wx.ID_ABOUT, "&About...")
  96. self.Bind(wx.EVT_MENU, self.showAbout, menuItem)