toolbars.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. (
  65. ("addAnimation", icons["addAnimation"].label),
  66. icons["addAnimation"],
  67. self.parent.OnAddAnimation,
  68. ),
  69. (
  70. ("editAnimation", icons["editAnimation"].label),
  71. icons["editAnimation"],
  72. self.parent.OnEditAnimation,
  73. ),
  74. (
  75. ("reload", BaseIcons["render"].label),
  76. BaseIcons["render"],
  77. self.parent.Reload,
  78. ),
  79. (
  80. ("exportAnimation", icons["exportAnimation"].label),
  81. icons["exportAnimation"],
  82. self.parent.OnExportAnimation,
  83. ),
  84. )
  85. )
  86. class AnimationToolbar(BaseToolbar):
  87. """Animation toolbar (to control animation)"""
  88. def __init__(self, parent):
  89. """Animation toolbar constructor"""
  90. BaseToolbar.__init__(self, parent)
  91. self.InitToolbar(self._toolbarData())
  92. # realize the toolbar
  93. self.Realize()
  94. self.isPlayingForward = True
  95. self.EnableAnimTools(False)
  96. def _toolbarData(self):
  97. """Returns toolbar data (name, icon, handler)"""
  98. # BaseIcons are a set of often used icons. It is possible
  99. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  100. icons = ganimIcons
  101. return self._getToolbarData(
  102. (
  103. (
  104. ("playBack", icons["playBack"].label),
  105. icons["playBack"],
  106. self.OnPlayBack,
  107. ),
  108. (
  109. ("playForward", icons["playForward"].label),
  110. icons["playForward"],
  111. self.OnPlayForward,
  112. ),
  113. (
  114. ("pause", icons["pause"].label),
  115. icons["pause"],
  116. self.OnPause,
  117. wx.ITEM_CHECK,
  118. ),
  119. (
  120. ("stop", icons["stop"].label),
  121. icons["stop"],
  122. self.OnStop,
  123. ),
  124. (None,),
  125. (
  126. (
  127. "oneDirectionReplay",
  128. icons["oneDirectionReplay"].label,
  129. ),
  130. icons["oneDirectionReplay"],
  131. self.OnOneDirectionReplay,
  132. wx.ITEM_CHECK,
  133. ),
  134. (
  135. (
  136. "bothDirectionReplay",
  137. icons["bothDirectionReplay"].label,
  138. ),
  139. icons["bothDirectionReplay"],
  140. self.OnBothDirectionReplay,
  141. wx.ITEM_CHECK,
  142. ),
  143. (None,),
  144. (
  145. ("adjustSpeed", icons["speed"].label),
  146. icons["speed"],
  147. self.parent.OnAdjustSpeed,
  148. ),
  149. )
  150. )
  151. def OnPlayForward(self, event):
  152. self.PlayForward()
  153. self.parent.OnPlayForward(event)
  154. def PlayForward(self):
  155. self.EnableTool(self.playForward, False)
  156. self.EnableTool(self.playBack, True)
  157. self.EnableTool(self.pause, True)
  158. self.EnableTool(self.stop, True)
  159. self.ToggleTool(self.pause, False)
  160. self.isPlayingForward = True
  161. def OnPlayBack(self, event):
  162. self.PlayBack()
  163. self.parent.OnPlayBack(event)
  164. def PlayBack(self):
  165. self.EnableTool(self.playForward, True)
  166. self.EnableTool(self.playBack, False)
  167. self.EnableTool(self.pause, True)
  168. self.EnableTool(self.stop, True)
  169. self.ToggleTool(self.pause, False)
  170. self.isPlayingForward = False
  171. def OnPause(self, event):
  172. self.Pause()
  173. self.parent.OnPause(event)
  174. def Pause(self):
  175. if self.GetToolState(self.pause):
  176. self.EnableTool(self.playForward, True)
  177. self.EnableTool(self.playBack, True)
  178. else:
  179. self.EnableTool(self.playForward, not self.isPlayingForward)
  180. self.EnableTool(self.playBack, self.isPlayingForward)
  181. def OnStop(self, event):
  182. self.Stop()
  183. self.parent.OnStop(event)
  184. def Stop(self):
  185. self.EnableTool(self.playForward, True)
  186. self.EnableTool(self.playBack, True)
  187. self.EnableTool(self.pause, False)
  188. self.EnableTool(self.stop, False)
  189. self.ToggleTool(self.pause, False)
  190. # if not self.GetToolState(self.oneDirectionReplay) and \
  191. # not self.GetToolState(self.bothDirectionReplay):
  192. # self.EnableTool(self.playBack, False) # assuming that stop rewinds to
  193. # the beginning
  194. def OnOneDirectionReplay(self, event):
  195. if event.IsChecked():
  196. self.ToggleTool(self.bothDirectionReplay, False)
  197. self.parent.OnOneDirectionReplay(event)
  198. def OnBothDirectionReplay(self, event):
  199. if event.IsChecked():
  200. self.ToggleTool(self.oneDirectionReplay, False)
  201. self.parent.OnBothDirectionReplay(event)
  202. def SetReplayMode(self, mode):
  203. one, both = False, False
  204. if mode == ReplayMode.REPEAT:
  205. one = True
  206. elif mode == ReplayMode.REVERSE:
  207. both = True
  208. self.ToggleTool(self.oneDirectionReplay, one)
  209. self.ToggleTool(self.bothDirectionReplay, both)
  210. def EnableAnimTools(self, enable):
  211. """Enable or diable animation tools"""
  212. self.EnableTool(self.playForward, enable)
  213. self.EnableTool(self.playBack, enable)
  214. self.EnableTool(self.pause, enable)
  215. self.EnableTool(self.stop, enable)
  216. class MiscToolbar(BaseToolbar):
  217. """Toolbar with miscellaneous tools related to app"""
  218. def __init__(self, parent):
  219. """Toolbar constructor"""
  220. BaseToolbar.__init__(self, parent)
  221. self.InitToolbar(self._toolbarData())
  222. # realize the toolbar
  223. self.Realize()
  224. def _toolbarData(self):
  225. """Toolbar data"""
  226. return self._getToolbarData(
  227. (
  228. (
  229. ("settings", BaseIcons["settings"].label),
  230. BaseIcons["settings"],
  231. self.parent.OnPreferences,
  232. ),
  233. (
  234. ("help", BaseIcons["help"].label),
  235. BaseIcons["help"],
  236. self.parent.OnHelp,
  237. ),
  238. (
  239. ("quit", BaseIcons["quit"].label),
  240. BaseIcons["quit"],
  241. self.parent.OnCloseWindow,
  242. ),
  243. )
  244. )
  245. class AnimSimpleLmgrToolbar(SimpleLmgrToolbar):
  246. """Simple layer manager toolbar for animation tool.
  247. Allows adding space-time dataset or series of maps.
  248. """
  249. def __init__(self, parent, lmgrStyle):
  250. SimpleLmgrToolbar.__init__(self, parent, lmgrStyle)
  251. def _toolbarData(self):
  252. data = SimpleLmgrToolbar._toolbarData(self)
  253. if self._style & SIMPLE_LMGR_STDS:
  254. data.insert(
  255. 0,
  256. (
  257. ("addSeries", simpleLmgrIcons["addSeries"].label),
  258. simpleLmgrIcons["addSeries"],
  259. self.parent.OnAddStds,
  260. ),
  261. )
  262. return data
  263. def EnableTools(self, tools, enable=True):
  264. for tool in tools:
  265. self.EnableTool(getattr(self, tool), enable)