gpyshell.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """!
  2. @package gpyshell.py
  3. @brief wxGUI Interactive Python Shell
  4. Classes:
  5. - PyShellWindow
  6. (C) 2011 by the GRASS Development Team
  7. This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import os
  13. import sys
  14. import wx
  15. from wx.py.shell import Shell as PyShell
  16. from wx.py.version import VERSION
  17. import grass.script as grass
  18. class PyShellWindow(wx.Panel):
  19. """!Python Shell Window"""
  20. def __init__(self, parent, id = wx.ID_ANY, **kwargs):
  21. self.parent = parent
  22. wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
  23. self.intro = _("Welcome to wxGUI Python Shell %s") % VERSION
  24. self.shell = PyShell(parent = self, id = wx.ID_ANY,
  25. introText = self.intro, locals = {'grass' : grass})
  26. sys.displayhook = self._displayhook
  27. self.btnClear = wx.Button(self, wx.ID_CLEAR)
  28. self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
  29. self.btnClear.SetToolTipString(_("Delete all text from the shell"))
  30. self._layout()
  31. def _displayhook(self, value):
  32. print value # do not modify __builtin__._
  33. def _layout(self):
  34. sizer = wx.BoxSizer(wx.VERTICAL)
  35. sizer.Add(item = self.shell, proportion = 1,
  36. flag = wx.EXPAND)
  37. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  38. btnSizer.Add(item = self.btnClear, proportion = 0,
  39. flag = wx.EXPAND | wx.RIGHT, border = 5)
  40. sizer.Add(item = btnSizer, proportion = 0,
  41. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  42. sizer.Fit(self)
  43. sizer.SetSizeHints(self)
  44. self.SetSizer(sizer)
  45. self.Fit()
  46. self.SetAutoLayout(True)
  47. self.Layout()
  48. def OnClear(self, event):
  49. """!Delete all text from the shell
  50. """
  51. self.shell.clear()
  52. self.shell.showIntro(self.intro)
  53. self.shell.prompt()