toolbars.py 8.3 KB

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