toolbars.py 7.9 KB

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