toolbars.py 8.2 KB

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