prompt.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. @package prompt.py
  3. @brief GRASS prompt
  4. Classes:
  5. - GPrompt
  6. (C) 2009 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 wx
  13. class GPrompt:
  14. """Interactive GRASS prompt"""
  15. def __init__(self, parent):
  16. self.parent = parent
  17. self.panel, self.input = self.__create()
  18. def __create(self):
  19. """Create widget"""
  20. cmdprompt = wx.Panel(self.parent)
  21. label = wx.Button(parent = cmdprompt, id = wx.ID_ANY,
  22. label = _("Cmd >"), size = (-1, 25))
  23. label.SetToolTipString(_("Click for erasing command prompt"))
  24. cmdinput = wx.TextCtrl(parent = cmdprompt, id = wx.ID_ANY,
  25. value = "",
  26. style = wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
  27. size = (-1, 25))
  28. cmdinput.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
  29. wx.CallAfter(cmdinput.SetInsertionPoint, 0)
  30. label.Bind(wx.EVT_BUTTON, self.OnCmdErase)
  31. cmdinput.Bind(wx.EVT_TEXT_ENTER, self.OnRunCmd)
  32. cmdinput.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
  33. # layout
  34. sizer = wx.BoxSizer(wx.HORIZONTAL)
  35. sizer.Add(item = label, proportion = 0,
  36. flag = wx.EXPAND | wx.LEFT | wx.RIGHT |
  37. wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
  38. border = 3)
  39. sizer.Add(item = cmdinput, proportion = 1,
  40. flag = wx.EXPAND | wx.ALL,
  41. border = 1)
  42. cmdprompt.SetSizer(sizer)
  43. sizer.Fit(cmdprompt)
  44. cmdprompt.Layout()
  45. return cmdprompt, cmdinput
  46. def GetPanel(self):
  47. """Get main widget panel"""
  48. return self.panel
  49. def OnCmdErase(self, event):
  50. """Erase command prompt"""
  51. self.input.SetValue('')
  52. def OnRunCmd(self, event):
  53. """Run command"""
  54. cmd = event.GetString()
  55. if self.parent.GetName() != "LayerManager":
  56. return
  57. if cmd[:2] == 'd.' and not self.parent.curr_page:
  58. self.parent.NewDisplay(show=True)
  59. if len(cmd.split(' ')) > 1:
  60. self.parent.goutput.RunCmd(cmd, switchPage = True)
  61. else:
  62. self.parent.goutput.RunCmd(cmd, switchPage = False)
  63. self.OnUpdateStatusBar(None)
  64. def OnUpdateStatusBar(self, event):
  65. """Update Layer Manager status bar"""
  66. if self.parent.GetName() != "LayerManager":
  67. return
  68. if event is None:
  69. self.parent.statusbar.SetStatusText("")
  70. else:
  71. self.parent.statusbar.SetStatusText(_("Type GRASS command and run by pressing ENTER"))