toolbars.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. """
  2. @package animation.toolbars
  3. @brief Animation toolbars
  4. Classes:
  5. - toolbars::MainToolbar(BaseToolbar)
  6. - toolbars::AnimationToolbar(BaseToolbar)
  7. - toolbars::MiscToolbar(BaseToolbar)
  8. - toolbars::AnimSimpleLmgrToolbar
  9. (C) 2013 by the GRASS Development Team
  10. This program is free software under the GNU General Public License
  11. (>=v2). Read the file COPYING that comes with GRASS for details.
  12. @author Anna Petrasova <kratochanna gmail.com>
  13. """
  14. import wx
  15. from gui_core.toolbars import BaseToolbar, BaseIcons
  16. from icons.icon import MetaIcon
  17. from core.utils import _
  18. from gui_core.simplelmgr import SimpleLmgrToolbar
  19. from animation.anim import ReplayMode
  20. ganimIcons = {
  21. 'speed': MetaIcon(img='move', label=_("Change animation speed")),
  22. 'playForward': MetaIcon(img='execute', label=_("Play forward")),
  23. 'playBack': MetaIcon(img='player-back', label=_("Play back")),
  24. 'stop': MetaIcon(img='player-stop', label=_("Stop")),
  25. 'pause': MetaIcon(img='player-pause', label=_("Pause")),
  26. 'oneDirectionReplay': MetaIcon(img='redraw', label=_("Repeat")),
  27. 'bothDirectionReplay': MetaIcon(img='player-repeat-back-forward',
  28. label=_("Play back and forward")),
  29. 'addAnimation': MetaIcon(img='layer-add', label=_("Add new animation"),
  30. desc=_("Add new animation")),
  31. 'editAnimation': MetaIcon(img='layer-more', label=_("Add, edit or remove animation"),
  32. desc=_("Add, edit or remove animation")),
  33. 'exportAnimation': MetaIcon(img='layer-export', label=_("Export animation"),
  34. desc=_("Export animation"))
  35. }
  36. SIMPLE_LMGR_STDS = 256
  37. simpleLmgrIcons = {
  38. 'addSeries': MetaIcon(img='mapset-add',
  39. label=_("Add space-time dataset or series of map layers"),
  40. desc=_("Add space-time dataset or series of map layers for animation")),
  41. }
  42. class MainToolbar(BaseToolbar):
  43. """Main toolbar (data management)
  44. """
  45. def __init__(self, parent):
  46. """Main toolbar constructor
  47. """
  48. BaseToolbar.__init__(self, parent)
  49. self.InitToolbar(self._toolbarData())
  50. # realize the toolbar
  51. self.Realize()
  52. def _toolbarData(self):
  53. """Returns toolbar data (name, icon, handler)"""
  54. # BaseIcons are a set of often used icons. It is possible
  55. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  56. icons = ganimIcons
  57. return self._getToolbarData((("addAnimation", icons["addAnimation"],
  58. self.parent.OnAddAnimation),
  59. ("editAnimation", icons["editAnimation"],
  60. self.parent.OnEditAnimation),
  61. ("reload", BaseIcons["render"],
  62. self.parent.Reload),
  63. ("exportAnimation", icons["exportAnimation"],
  64. self.parent.OnExportAnimation)
  65. ))
  66. class AnimationToolbar(BaseToolbar):
  67. """Animation toolbar (to control animation)
  68. """
  69. def __init__(self, parent):
  70. """Animation toolbar constructor
  71. """
  72. BaseToolbar.__init__(self, parent)
  73. self.InitToolbar(self._toolbarData())
  74. # realize the toolbar
  75. self.Realize()
  76. self.isPlayingForward = True
  77. self.EnableAnimTools(False)
  78. def _toolbarData(self):
  79. """Returns toolbar data (name, icon, handler)"""
  80. # BaseIcons are a set of often used icons. It is possible
  81. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  82. icons = ganimIcons
  83. return self._getToolbarData((("playBack", icons["playBack"],
  84. self.OnPlayBack),
  85. ("playForward", icons["playForward"],
  86. self.OnPlayForward),
  87. ("pause", icons["pause"],
  88. self.OnPause,
  89. wx.ITEM_CHECK),
  90. ("stop", icons["stop"],
  91. self.OnStop),
  92. (None, ),
  93. ("oneDirectionReplay", icons["oneDirectionReplay"],
  94. self.OnOneDirectionReplay,
  95. wx.ITEM_CHECK),
  96. ("bothDirectionReplay", icons["bothDirectionReplay"],
  97. self.OnBothDirectionReplay,
  98. wx.ITEM_CHECK),
  99. (None, ),
  100. ("adjustSpeed", icons['speed'],
  101. self.parent.OnAdjustSpeed)
  102. ))
  103. def OnPlayForward(self, event):
  104. self.PlayForward()
  105. self.parent.OnPlayForward(event)
  106. def PlayForward(self):
  107. self.EnableTool(self.playForward, False)
  108. self.EnableTool(self.playBack, True)
  109. self.EnableTool(self.pause, True)
  110. self.EnableTool(self.stop, True)
  111. self.ToggleTool(self.pause, False)
  112. self.isPlayingForward = True
  113. def OnPlayBack(self, event):
  114. self.PlayBack()
  115. self.parent.OnPlayBack(event)
  116. def PlayBack(self):
  117. self.EnableTool(self.playForward, True)
  118. self.EnableTool(self.playBack, False)
  119. self.EnableTool(self.pause, True)
  120. self.EnableTool(self.stop, True)
  121. self.ToggleTool(self.pause, False)
  122. self.isPlayingForward = False
  123. def OnPause(self, event):
  124. self.Pause()
  125. self.parent.OnPause(event)
  126. def Pause(self):
  127. if self.GetToolState(self.pause):
  128. self.EnableTool(self.playForward, True)
  129. self.EnableTool(self.playBack, True)
  130. else:
  131. self.EnableTool(self.playForward, not self.isPlayingForward)
  132. self.EnableTool(self.playBack, self.isPlayingForward)
  133. def OnStop(self, event):
  134. self.Stop()
  135. self.parent.OnStop(event)
  136. def Stop(self):
  137. self.EnableTool(self.playForward, True)
  138. self.EnableTool(self.playBack, True)
  139. self.EnableTool(self.pause, False)
  140. self.EnableTool(self.stop, False)
  141. self.ToggleTool(self.pause, False)
  142. # if not self.GetToolState(self.oneDirectionReplay) and \
  143. # not self.GetToolState(self.bothDirectionReplay):
  144. # self.EnableTool(self.playBack, False) # assuming that stop rewinds to the beginning
  145. def OnOneDirectionReplay(self, event):
  146. if event.IsChecked():
  147. self.ToggleTool(self.bothDirectionReplay, False)
  148. self.parent.OnOneDirectionReplay(event)
  149. def OnBothDirectionReplay(self, event):
  150. if event.IsChecked():
  151. self.ToggleTool(self.oneDirectionReplay, False)
  152. self.parent.OnBothDirectionReplay(event)
  153. def SetReplayMode(self, mode):
  154. one, both = False, False
  155. if mode == ReplayMode.REPEAT:
  156. one = True
  157. elif mode == ReplayMode.REVERSE:
  158. both = True
  159. self.ToggleTool(self.oneDirectionReplay, one)
  160. self.ToggleTool(self.bothDirectionReplay, both)
  161. def EnableAnimTools(self, enable):
  162. """Enable or diable animation tools"""
  163. self.EnableTool(self.playForward, enable)
  164. self.EnableTool(self.playBack, enable)
  165. self.EnableTool(self.pause, enable)
  166. self.EnableTool(self.stop, enable)
  167. class MiscToolbar(BaseToolbar):
  168. """Toolbar with miscellaneous tools related to app
  169. """
  170. def __init__(self, parent):
  171. """Toolbar constructor
  172. """
  173. BaseToolbar.__init__(self, parent)
  174. self.InitToolbar(self._toolbarData())
  175. # realize the toolbar
  176. self.Realize()
  177. def _toolbarData(self):
  178. """Toolbar data"""
  179. return self._getToolbarData((("settings", BaseIcons['settings'],
  180. self.parent.OnPreferences),
  181. ("help", BaseIcons['help'],
  182. self.parent.OnHelp),
  183. ("quit", BaseIcons['quit'],
  184. self.parent.OnCloseWindow),
  185. ))
  186. class AnimSimpleLmgrToolbar(SimpleLmgrToolbar):
  187. """Simple layer manager toolbar for animation tool.
  188. Allows to add space-time dataset or series of maps.
  189. """
  190. def __init__(self, parent, lmgrStyle):
  191. SimpleLmgrToolbar.__init__(self, parent, lmgrStyle)
  192. def _toolbarData(self):
  193. data = SimpleLmgrToolbar._toolbarData(self)
  194. if self._style & SIMPLE_LMGR_STDS:
  195. data.insert(0, ('addSeries', simpleLmgrIcons['addSeries'],
  196. self.parent.OnAddStds))
  197. return data
  198. def EnableTools(self, tools, enable=True):
  199. for tool in tools:
  200. self.EnableTool(getattr(self, tool), enable)