toolbars.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. def _toolbarData(self):
  69. """!Returns toolbar data (name, icon, handler)"""
  70. # BaseIcons are a set of often used icons. It is possible
  71. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  72. icons = ganimIcons
  73. return self._getToolbarData((("playBack", icons["playBack"],
  74. self.OnPlayBack),
  75. ("playForward", icons["playForward"],
  76. self.OnPlayForward),
  77. ("pause", icons["pause"],
  78. self.OnPause,
  79. wx.ITEM_CHECK),
  80. ("stop", icons["stop"],
  81. self.OnStop),
  82. (None, ),
  83. ("oneDirectionReplay", icons["oneDirectionReplay"],
  84. self.OnOneDirectionReplay,
  85. wx.ITEM_CHECK),
  86. ("bothDirectionReplay", icons["bothDirectionReplay"],
  87. self.OnBothDirectionReplay,
  88. wx.ITEM_CHECK),
  89. (None, ),
  90. ("adjustSpeed", icons['speed'],
  91. self.parent.OnAdjustSpeed)
  92. ))
  93. def OnPlayForward(self, event):
  94. self.PlayForward()
  95. self.parent.OnPlayForward(event)
  96. def PlayForward(self):
  97. self.EnableTool(self.playForward, False)
  98. self.EnableTool(self.playBack, True)
  99. self.EnableTool(self.pause, True)
  100. self.EnableTool(self.stop, True)
  101. self.ToggleTool(self.pause, False)
  102. self.isPlayingForward = True
  103. def OnPlayBack(self, event):
  104. self.PlayBack()
  105. self.parent.OnPlayBack(event)
  106. def PlayBack(self):
  107. self.EnableTool(self.playForward, True)
  108. self.EnableTool(self.playBack, False)
  109. self.EnableTool(self.pause, True)
  110. self.EnableTool(self.stop, True)
  111. self.ToggleTool(self.pause, False)
  112. self.isPlayingForward = False
  113. def OnPause(self, event):
  114. self.Pause()
  115. self.parent.OnPause(event)
  116. def Pause(self):
  117. if self.GetToolState(self.pause):
  118. self.EnableTool(self.playForward, True)
  119. self.EnableTool(self.playBack, True)
  120. else:
  121. self.EnableTool(self.playForward, not self.isPlayingForward)
  122. self.EnableTool(self.playBack, self.isPlayingForward)
  123. def OnStop(self, event):
  124. self.Stop()
  125. self.parent.OnStop(event)
  126. def Stop(self):
  127. self.EnableTool(self.playForward, True)
  128. self.EnableTool(self.playBack, True)
  129. self.EnableTool(self.pause, False)
  130. self.EnableTool(self.stop, False)
  131. self.ToggleTool(self.pause, False)
  132. # if not self.GetToolState(self.oneDirectionReplay) and \
  133. # not self.GetToolState(self.bothDirectionReplay):
  134. # self.EnableTool(self.playBack, False) # assuming that stop rewinds to the beginning
  135. def OnOneDirectionReplay(self, event):
  136. if event.IsChecked():
  137. self.ToggleTool(self.bothDirectionReplay, False)
  138. self.parent.OnOneDirectionReplay(event)
  139. def OnBothDirectionReplay(self, event):
  140. if event.IsChecked():
  141. self.ToggleTool(self.oneDirectionReplay, False)
  142. self.parent.OnBothDirectionReplay(event)
  143. def SetReplayMode(self, mode):
  144. one, both = False, False
  145. if mode == ReplayMode.REPEAT:
  146. one = True
  147. elif mode == ReplayMode.REVERSE:
  148. both = True
  149. self.ToggleTool(self.oneDirectionReplay, one)
  150. self.ToggleTool(self.bothDirectionReplay, both)
  151. class MiscToolbar(BaseToolbar):
  152. """!Toolbar with miscellaneous tools related to app
  153. """
  154. def __init__(self, parent):
  155. """!Toolbar constructor
  156. """
  157. BaseToolbar.__init__(self, parent)
  158. self.InitToolbar(self._toolbarData())
  159. # realize the toolbar
  160. self.Realize()
  161. def _toolbarData(self):
  162. """!Toolbar data"""
  163. return self._getToolbarData((("help", BaseIcons['help'],
  164. self.parent.OnHelp),
  165. ("quit", BaseIcons['quit'],
  166. self.parent.OnCloseWindow),
  167. ))