1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
"""
@package animation.toolbars
@brief Animation toolbars
Classes:
- toolbars::MainToolbar(BaseToolbar)
- toolbars::AnimationToolbar(BaseToolbar)
- toolbars::MiscToolbar(BaseToolbar)
- toolbars::AnimSimpleLmgrToolbar
(C) 2013 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Anna Petrasova <kratochanna gmail.com>
"""
import wx
from gui_core.toolbars import BaseToolbar, BaseIcons
from icons.icon import MetaIcon
from gui_core.simplelmgr import SimpleLmgrToolbar
from animation.anim import ReplayMode
ganimIcons = {
"speed": MetaIcon(img="move", label=_("Change animation speed")),
"playForward": MetaIcon(img="execute", label=_("Play forward")),
"playBack": MetaIcon(img="player-back", label=_("Play back")),
"stop": MetaIcon(img="player-stop", label=_("Stop")),
"pause": MetaIcon(img="player-pause", label=_("Pause")),
"oneDirectionReplay": MetaIcon(img="redraw", label=_("Repeat")),
"bothDirectionReplay": MetaIcon(
img="player-repeat-back-forward", label=_("Play back and forward")
),
"addAnimation": MetaIcon(
img="layer-add", label=_("Add new animation"), desc=_("Add new animation")
),
"editAnimation": MetaIcon(
img="layer-more",
label=_("Add, edit or remove animation"),
desc=_("Add, edit or remove animation"),
),
"exportAnimation": MetaIcon(
img="layer-export", label=_("Export animation"), desc=_("Export animation")
),
}
SIMPLE_LMGR_STDS = 256
simpleLmgrIcons = {
"addSeries": MetaIcon(
img="mapset-add",
label=_("Add space-time dataset or series of map layers"),
desc=_("Add space-time dataset or series of map layers for animation"),
),
}
class MainToolbar(BaseToolbar):
"""Main toolbar (data management)"""
def __init__(self, parent):
"""Main toolbar constructor"""
BaseToolbar.__init__(self, parent)
self.InitToolbar(self._toolbarData())
# realize the toolbar
self.Realize()
def _toolbarData(self):
"""Returns toolbar data (name, icon, handler)"""
# BaseIcons are a set of often used icons. It is possible
# to reuse icons in gui/icons/grass or add new ones there.
icons = ganimIcons
return self._getToolbarData(
(
(
("addAnimation", icons["addAnimation"].label),
icons["addAnimation"],
self.parent.OnAddAnimation,
),
(
("editAnimation", icons["editAnimation"].label),
icons["editAnimation"],
self.parent.OnEditAnimation,
),
(
("reload", BaseIcons["render"].label),
BaseIcons["render"],
self.parent.Reload,
),
(
("exportAnimation", icons["exportAnimation"].label),
icons["exportAnimation"],
self.parent.OnExportAnimation,
),
)
)
class AnimationToolbar(BaseToolbar):
"""Animation toolbar (to control animation)"""
def __init__(self, parent):
"""Animation toolbar constructor"""
BaseToolbar.__init__(self, parent)
self.InitToolbar(self._toolbarData())
# realize the toolbar
self.Realize()
self.isPlayingForward = True
self.EnableAnimTools(False)
def _toolbarData(self):
"""Returns toolbar data (name, icon, handler)"""
# BaseIcons are a set of often used icons. It is possible
# to reuse icons in gui/icons/grass or add new ones there.
icons = ganimIcons
return self._getToolbarData(
(
(
("playBack", icons["playBack"].label),
icons["playBack"],
self.OnPlayBack,
),
(
("playForward", icons["playForward"].label),
icons["playForward"],
self.OnPlayForward,
),
(
("pause", icons["pause"].label),
icons["pause"],
self.OnPause,
wx.ITEM_CHECK,
),
(
("stop", icons["stop"].label),
icons["stop"],
self.OnStop,
),
(None,),
(
(
"oneDirectionReplay",
icons["oneDirectionReplay"].label,
),
icons["oneDirectionReplay"],
self.OnOneDirectionReplay,
wx.ITEM_CHECK,
),
(
(
"bothDirectionReplay",
icons["bothDirectionReplay"].label,
),
icons["bothDirectionReplay"],
self.OnBothDirectionReplay,
wx.ITEM_CHECK,
),
(None,),
(
("adjustSpeed", icons["speed"].label),
icons["speed"],
self.parent.OnAdjustSpeed,
),
)
)
def OnPlayForward(self, event):
self.PlayForward()
self.parent.OnPlayForward(event)
def PlayForward(self):
self.EnableTool(self.playForward, False)
self.EnableTool(self.playBack, True)
self.EnableTool(self.pause, True)
self.EnableTool(self.stop, True)
self.ToggleTool(self.pause, False)
self.isPlayingForward = True
def OnPlayBack(self, event):
self.PlayBack()
self.parent.OnPlayBack(event)
def PlayBack(self):
self.EnableTool(self.playForward, True)
self.EnableTool(self.playBack, False)
self.EnableTool(self.pause, True)
self.EnableTool(self.stop, True)
self.ToggleTool(self.pause, False)
self.isPlayingForward = False
def OnPause(self, event):
self.Pause()
self.parent.OnPause(event)
def Pause(self):
if self.GetToolState(self.pause):
self.EnableTool(self.playForward, True)
self.EnableTool(self.playBack, True)
else:
self.EnableTool(self.playForward, not self.isPlayingForward)
self.EnableTool(self.playBack, self.isPlayingForward)
def OnStop(self, event):
self.Stop()
self.parent.OnStop(event)
def Stop(self):
self.EnableTool(self.playForward, True)
self.EnableTool(self.playBack, True)
self.EnableTool(self.pause, False)
self.EnableTool(self.stop, False)
self.ToggleTool(self.pause, False)
# if not self.GetToolState(self.oneDirectionReplay) and \
# not self.GetToolState(self.bothDirectionReplay):
# self.EnableTool(self.playBack, False) # assuming that stop rewinds to
# the beginning
def OnOneDirectionReplay(self, event):
if event.IsChecked():
self.ToggleTool(self.bothDirectionReplay, False)
self.parent.OnOneDirectionReplay(event)
def OnBothDirectionReplay(self, event):
if event.IsChecked():
self.ToggleTool(self.oneDirectionReplay, False)
self.parent.OnBothDirectionReplay(event)
def SetReplayMode(self, mode):
one, both = False, False
if mode == ReplayMode.REPEAT:
one = True
elif mode == ReplayMode.REVERSE:
both = True
self.ToggleTool(self.oneDirectionReplay, one)
self.ToggleTool(self.bothDirectionReplay, both)
def EnableAnimTools(self, enable):
"""Enable or disable animation tools"""
self.EnableTool(self.playForward, enable)
self.EnableTool(self.playBack, enable)
self.EnableTool(self.pause, enable)
self.EnableTool(self.stop, enable)
class MiscToolbar(BaseToolbar):
"""Toolbar with miscellaneous tools related to app"""
def __init__(self, parent):
"""Toolbar constructor"""
BaseToolbar.__init__(self, parent)
self.InitToolbar(self._toolbarData())
# realize the toolbar
self.Realize()
def _toolbarData(self):
"""Toolbar data"""
return self._getToolbarData(
(
(
("settings", BaseIcons["settings"].label),
BaseIcons["settings"],
self.parent.OnPreferences,
),
(
("help", BaseIcons["help"].label),
BaseIcons["help"],
self.parent.OnHelp,
),
(
("quit", BaseIcons["quit"].label),
BaseIcons["quit"],
self.parent.OnCloseWindow,
),
)
)
class AnimSimpleLmgrToolbar(SimpleLmgrToolbar):
"""Simple layer manager toolbar for animation tool.
Allows adding space-time dataset or series of maps.
"""
def __init__(self, parent, lmgrStyle):
SimpleLmgrToolbar.__init__(self, parent, lmgrStyle)
def _toolbarData(self):
data = SimpleLmgrToolbar._toolbarData(self)
if self._style & SIMPLE_LMGR_STDS:
data.insert(
0,
(
("addSeries", simpleLmgrIcons["addSeries"].label),
simpleLmgrIcons["addSeries"],
self.parent.OnAddStds,
),
)
return data
def EnableTools(self, tools, enable=True):
for tool in tools:
self.EnableTool(getattr(self, tool), enable)
|