gpyshell.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Interactive Python Shell %s") % VERSION + "\n\n" + \
  24. _("Type %s for more GRASS scripting related information.") % "\"help(grass)\"" + "\n\n"
  25. self.shell = PyShell(parent = self, id = wx.ID_ANY,
  26. introText = self.intro, locals = {'grass' : grass})
  27. sys.displayhook = self._displayhook
  28. self.btnClear = wx.Button(self, wx.ID_CLEAR)
  29. self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
  30. self.btnClear.SetToolTipString(_("Delete all text from the shell"))
  31. self._layout()
  32. def _displayhook(self, value):
  33. print value # do not modify __builtin__._
  34. def _layout(self):
  35. sizer = wx.BoxSizer(wx.VERTICAL)
  36. sizer.Add(item = self.shell, proportion = 1,
  37. flag = wx.EXPAND)
  38. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  39. btnSizer.Add(item = self.btnClear, proportion = 0,
  40. flag = wx.EXPAND | wx.RIGHT, border = 5)
  41. sizer.Add(item = btnSizer, proportion = 0,
  42. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  43. sizer.Fit(self)
  44. sizer.SetSizeHints(self)
  45. self.SetSizer(sizer)
  46. self.Fit()
  47. self.SetAutoLayout(True)
  48. self.Layout()
  49. def OnClear(self, event):
  50. """!Delete all text from the shell
  51. """
  52. self.shell.clear()
  53. self.shell.showIntro(self.intro)
  54. self.shell.prompt()