gmodeler.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. """!
  2. @package gmodeler.py
  3. @brief Graphical modeler to create edit, and manage models
  4. Classes:
  5. - ModelFrame
  6. - ModelCanvas
  7. (C) 2010 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import os
  13. import globalvar
  14. if not os.getenv("GRASS_WXBUNDLED"):
  15. globalvar.CheckForWx()
  16. import wx
  17. import wx.lib.ogl as ogl
  18. import menu
  19. import menudata
  20. import toolbars
  21. from grass.script import core as grass
  22. class ModelFrame(wx.Frame):
  23. def __init__(self, parent, id = wx.ID_ANY, title = _("Graphical modeler (under development)"), **kwargs):
  24. """!Graphical modeler main window
  25. @param parent parent window
  26. @param id window id
  27. @param title window title
  28. @param kwargs wx.Frames' arguments
  29. """
  30. self.parent = parent
  31. wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
  32. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  33. self.menubar = menu.Menu(parent = self, data = menudata.ModelerData())
  34. self.SetMenuBar(self.menubar)
  35. self.toolbar = toolbars.ModelToolbar(parent = self)
  36. self.SetToolBar(self.toolbar)
  37. self.statusbar = self.CreateStatusBar(number = 1)
  38. self.canvas = ModelCanvas(self)
  39. self.canvas.SetBackgroundColour(wx.WHITE)
  40. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  41. self._layout()
  42. self.SetMinSize((400, 300))
  43. def _layout(self):
  44. """!Do layout"""
  45. sizer = wx.BoxSizer(wx.VERTICAL)
  46. sizer.Add(item = self.canvas, proportion = 1,
  47. flag = wx.EXPAND)
  48. self.SetAutoLayout(True)
  49. self.SetSizer(sizer)
  50. sizer.Fit(self)
  51. self.Layout()
  52. def OnCloseWindow(self, event):
  53. """!Close window"""
  54. self.Destroy()
  55. def OnModelNew(self, event):
  56. """!Create new model"""
  57. pass
  58. def OnModelOpen(self, event):
  59. """!Load model from file"""
  60. pass
  61. def OnModelSave(self, event):
  62. """!Save model to file"""
  63. pass
  64. def OnModelSaveAs(self, event):
  65. """!Create model to file as"""
  66. pass
  67. def OnAddAction(self, event):
  68. """!Add action to model"""
  69. pass
  70. def OnHelp(self, event):
  71. """!Display manual page"""
  72. grass.run_command('g.manual',
  73. entry = 'wxGUI.Modeler')
  74. class ModelCanvas(ogl.ShapeCanvas):
  75. """!Canvas where model is drawn"""
  76. def __init__(self, parent):
  77. ogl.OGLInitialize()
  78. ogl.ShapeCanvas.__init__(self, parent)
  79. self.diagram = ogl.Diagram()
  80. self.SetDiagram(self.diagram)
  81. self.diagram.SetCanvas(self)
  82. def main():
  83. app = wx.PySimpleApp()
  84. frame = ModelFrame(parent = None)
  85. frame.CenterOnScreen()
  86. frame.Show()
  87. app.MainLoop()
  88. if __name__ == "__main__":
  89. main()