toolbars.py 7.9 KB

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