toolbars.py 8.3 KB

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