dialogs.py 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. """!
  2. @package animation.dialogs
  3. @brief Dialogs for animation management, changing speed of animation
  4. Classes:
  5. - dialogs::SpeedDialog
  6. - dialogs::InputDialog
  7. - dialogs::EditDialog
  8. - dialogs::ExportDialog
  9. - dialogs::AnimSimpleLayerManager
  10. - dialogs::AddTemporalLayerDialog
  11. (C) 2013 by the GRASS Development Team
  12. This program is free software under the GNU General Public License
  13. (>=v2). Read the file COPYING that comes with GRASS for details.
  14. @author Anna Petrasova <kratochanna gmail.com>
  15. """
  16. import os
  17. import sys
  18. import wx
  19. import copy
  20. import datetime
  21. import wx.lib.filebrowsebutton as filebrowse
  22. if __name__ == '__main__':
  23. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  24. from core.gcmd import GMessage, GError, GException
  25. from core import globalvar
  26. from gui_core.dialogs import MapLayersDialog, GetImageHandlers
  27. from gui_core.forms import GUI
  28. from core.settings import UserSettings
  29. from core.utils import _
  30. from gui_core.gselect import Select
  31. from animation.utils import TemporalMode, getRegisteredMaps
  32. from animation.data import AnimationData, AnimLayer
  33. from animation.toolbars import AnimSimpleLmgrToolbar, SIMPLE_LMGR_STDS
  34. from gui_core.simplelmgr import SimpleLayerManager, \
  35. SIMPLE_LMGR_RASTER, SIMPLE_LMGR_VECTOR, SIMPLE_LMGR_TB_TOP
  36. from grass.pydispatch.signal import Signal
  37. import grass.script.core as gcore
  38. class SpeedDialog(wx.Dialog):
  39. def __init__(self, parent, title=_("Adjust speed of animation"),
  40. temporalMode=None, minimumDuration=20, timeGranularity=None,
  41. initialSpeed=200):
  42. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
  43. style=wx.DEFAULT_DIALOG_STYLE)
  44. # signal emitted when speed has changed; has attribute 'ms'
  45. self.speedChanged = Signal('SpeedDialog.speedChanged')
  46. self.minimumDuration = minimumDuration
  47. # self.framesCount = framesCount
  48. self.defaultSpeed = initialSpeed
  49. self.lastAppliedValue = self.defaultSpeed
  50. self.lastAppliedValueTemp = self.defaultSpeed
  51. self._layout()
  52. self.temporalMode = temporalMode
  53. self.timeGranularity = timeGranularity
  54. self._fillUnitChoice(self.choiceUnits)
  55. self.InitTimeSpin(self.defaultSpeed)
  56. def SetTimeGranularity(self, gran):
  57. self._timeGranularity = gran
  58. def GetTimeGranularity(self):
  59. return self._timeGranularity
  60. timeGranularity = property(fset=SetTimeGranularity, fget=GetTimeGranularity)
  61. def SetTemporalMode(self, mode):
  62. self._temporalMode = mode
  63. self._setTemporalMode()
  64. def GetTemporalMode(self):
  65. return self._temporalMode
  66. temporalMode = property(fset=SetTemporalMode, fget=GetTemporalMode)
  67. def _layout(self):
  68. """!Layout window"""
  69. mainSizer = wx.BoxSizer(wx.VERTICAL)
  70. #
  71. # simple mode
  72. #
  73. self.nontemporalBox = wx.StaticBox(parent=self, id=wx.ID_ANY,
  74. label=' %s ' % _("Simple mode"))
  75. box = wx.StaticBoxSizer(self.nontemporalBox, wx.VERTICAL)
  76. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  77. labelDuration = wx.StaticText(self, id=wx.ID_ANY, label=_("Frame duration:"))
  78. labelUnits = wx.StaticText(self, id=wx.ID_ANY, label=_("ms"))
  79. self.spinDuration = wx.SpinCtrl(self, id=wx.ID_ANY, min=self.minimumDuration,
  80. max=10000, initial=self.defaultSpeed)
  81. # TODO total time
  82. gridSizer.Add(item=labelDuration, pos=(0, 0), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  83. gridSizer.Add(item=self.spinDuration, pos=(0, 1), flag = wx.ALIGN_CENTER)
  84. gridSizer.Add(item=labelUnits, pos=(0, 2), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  85. gridSizer.AddGrowableCol(0)
  86. box.Add(item=gridSizer, proportion=1, border=5, flag=wx.ALL | wx.EXPAND)
  87. self.nontemporalSizer = gridSizer
  88. mainSizer.Add(item=box, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
  89. #
  90. # temporal mode
  91. #
  92. self.temporalBox = wx.StaticBox(parent=self, id=wx.ID_ANY,
  93. label=' %s ' % _("Temporal mode"))
  94. box = wx.StaticBoxSizer(self.temporalBox, wx.VERTICAL)
  95. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  96. labelTimeUnit = wx.StaticText(self, id=wx.ID_ANY, label=_("Time unit:"))
  97. labelDuration = wx.StaticText(self, id=wx.ID_ANY, label=_("Duration of time unit:"))
  98. labelUnits = wx.StaticText(self, id=wx.ID_ANY, label=_("ms"))
  99. self.spinDurationTemp = wx.SpinCtrl(self, id=wx.ID_ANY, min=self.minimumDuration,
  100. max=10000, initial=self.defaultSpeed)
  101. self.choiceUnits = wx.Choice(self, id=wx.ID_ANY)
  102. # TODO total time
  103. gridSizer.Add(item=labelTimeUnit, pos=(0, 0), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  104. gridSizer.Add(item=self.choiceUnits, pos=(0, 1), flag = wx.ALIGN_CENTER | wx.EXPAND)
  105. gridSizer.Add(item=labelDuration, pos=(1, 0), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  106. gridSizer.Add(item=self.spinDurationTemp, pos=(1, 1), flag = wx.ALIGN_CENTER | wx.EXPAND)
  107. gridSizer.Add(item=labelUnits, pos=(1, 2), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  108. gridSizer.AddGrowableCol(1)
  109. self.temporalSizer = gridSizer
  110. box.Add(item=gridSizer, proportion=1, border=5, flag=wx.ALL | wx.EXPAND)
  111. mainSizer.Add(item=box, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
  112. self.btnOk = wx.Button(self, wx.ID_OK)
  113. self.btnApply = wx.Button(self, wx.ID_APPLY)
  114. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  115. self.btnOk.SetDefault()
  116. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  117. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  118. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  119. self.Bind(wx.EVT_CLOSE, self.OnCancel)
  120. # button sizer
  121. btnStdSizer = wx.StdDialogButtonSizer()
  122. btnStdSizer.AddButton(self.btnOk)
  123. btnStdSizer.AddButton(self.btnApply)
  124. btnStdSizer.AddButton(self.btnCancel)
  125. btnStdSizer.Realize()
  126. mainSizer.Add(item=btnStdSizer, proportion=0,
  127. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  128. self.SetSizer(mainSizer)
  129. mainSizer.Fit(self)
  130. def _setTemporalMode(self):
  131. self.nontemporalBox.Enable(self.temporalMode == TemporalMode.NONTEMPORAL)
  132. self.temporalBox.Enable(self.temporalMode == TemporalMode.TEMPORAL)
  133. for child in self.temporalSizer.GetChildren():
  134. child.GetWindow().Enable(self.temporalMode == TemporalMode.TEMPORAL)
  135. for child in self.nontemporalSizer.GetChildren():
  136. child.GetWindow().Enable(self.temporalMode == TemporalMode.NONTEMPORAL)
  137. self.Layout()
  138. def _fillUnitChoice(self, choiceWidget):
  139. timeUnitsChoice = [_("year"), _("month"), _("day"), _("hour"), _("minute"), _("second")]
  140. timeUnits = ["years", "months", "days", "hours", "minutes", "seconds"]
  141. for item, cdata in zip(timeUnitsChoice, timeUnits):
  142. choiceWidget.Append(item, cdata)
  143. if self.temporalMode == TemporalMode.TEMPORAL:
  144. unit = self.timeGranularity[1]
  145. try:
  146. index = timeUnits.index(unit)
  147. except ValueError:
  148. index = 0
  149. choiceWidget.SetSelection(index)
  150. else:
  151. choiceWidget.SetSelection(0)
  152. def OnOk(self, event):
  153. self._apply()
  154. self.OnCancel(None)
  155. def OnApply(self, event):
  156. self._apply()
  157. def OnCancel(self, event):
  158. self.spinDuration.SetValue(self.lastAppliedValue)
  159. self.spinDurationTemp.SetValue(self.lastAppliedValueTemp)
  160. self.Hide()
  161. def InitTimeSpin(self, timeTick):
  162. if self.temporalMode == TemporalMode.TEMPORAL:
  163. index = self.choiceUnits.GetSelection()
  164. unit = self.choiceUnits.GetClientData(index)
  165. delta = self._timedelta(unit=unit, number=1)
  166. seconds1 = self._total_seconds(delta)
  167. number, unit = self.timeGranularity
  168. number = float(number)
  169. delta = self._timedelta(unit=unit, number=number)
  170. seconds2 = self._total_seconds(delta)
  171. value = timeTick
  172. ms = value * seconds1 / float(seconds2)
  173. self.spinDurationTemp.SetValue(ms)
  174. else:
  175. self.spinDuration.SetValue(timeTick)
  176. def _apply(self):
  177. if self.temporalMode == TemporalMode.NONTEMPORAL:
  178. ms = self.spinDuration.GetValue()
  179. self.lastAppliedValue = self.spinDuration.GetValue()
  180. elif self.temporalMode == TemporalMode.TEMPORAL:
  181. index = self.choiceUnits.GetSelection()
  182. unit = self.choiceUnits.GetClientData(index)
  183. delta = self._timedelta(unit=unit, number=1)
  184. seconds1 = self._total_seconds(delta)
  185. number, unit = self.timeGranularity
  186. number = float(number)
  187. delta = self._timedelta(unit=unit, number=number)
  188. seconds2 = self._total_seconds(delta)
  189. value = self.spinDurationTemp.GetValue()
  190. ms = value * seconds2 / float(seconds1)
  191. if ms < self.minimumDuration:
  192. GMessage(parent=self, message=_("Animation speed is too high."))
  193. return
  194. self.lastAppliedValueTemp = self.spinDurationTemp.GetValue()
  195. else:
  196. return
  197. self.speedChanged.emit(ms=ms)
  198. def _timedelta(self, unit, number):
  199. if unit in "years":
  200. delta = datetime.timedelta(days=365.25 * number)
  201. elif unit in "months":
  202. delta = datetime.timedelta(days=30.4375 * number) # 365.25/12
  203. elif unit in "days":
  204. delta = datetime.timedelta(days=1 * number)
  205. elif unit in "hours":
  206. delta = datetime.timedelta(hours=1 * number)
  207. elif unit in "minutes":
  208. delta = datetime.timedelta(minutes=1 * number)
  209. elif unit in "seconds":
  210. delta = datetime.timedelta(seconds=1 * number)
  211. return delta
  212. def _total_seconds(self, delta):
  213. """!timedelta.total_seconds is new in version 2.7.
  214. """
  215. return delta.seconds + delta.days * 24 * 3600
  216. class InputDialog(wx.Dialog):
  217. def __init__(self, parent, mode, animationData):
  218. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  219. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
  220. if mode == 'add':
  221. self.SetTitle(_("Add new animation"))
  222. elif mode == 'edit':
  223. self.SetTitle(_("Edit animation"))
  224. self.animationData = animationData
  225. self._tmpLegendCmd = None
  226. self._layout()
  227. self.OnViewMode(event=None)
  228. def _layout(self):
  229. mainSizer = wx.BoxSizer(wx.VERTICAL)
  230. self.windowChoice = wx.Choice(self, id=wx.ID_ANY,
  231. choices=[_("top left"), _("top right"),
  232. _("bottom left"), _("bottom right")])
  233. self.windowChoice.SetSelection(self.animationData.windowIndex)
  234. self.nameCtrl = wx.TextCtrl(self, id=wx.ID_ANY, value=self.animationData.name)
  235. self.nDChoice = wx.Choice(self, id=wx.ID_ANY)
  236. mode = self.animationData.viewMode
  237. index = 0
  238. for i, (viewMode, viewModeName) in enumerate(self.animationData.viewModes):
  239. self.nDChoice.Append(viewModeName, clientData=viewMode)
  240. if mode == viewMode:
  241. index = i
  242. self.nDChoice.SetSelection(index)
  243. self.nDChoice.SetToolTipString(_("Select 2D or 3D view"))
  244. self.nDChoice.Bind(wx.EVT_CHOICE, self.OnViewMode)
  245. gridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  246. gridSizer.Add(item=wx.StaticText(self, id=wx.ID_ANY, label=_("Name:")),
  247. flag=wx.ALIGN_CENTER_VERTICAL)
  248. gridSizer.Add(item=self.nameCtrl, proportion=1, flag=wx.EXPAND)
  249. gridSizer.Add(item=wx.StaticText(self, id=wx.ID_ANY, label=_("Window position:")),
  250. flag=wx.ALIGN_CENTER_VERTICAL)
  251. gridSizer.Add(item=self.windowChoice, proportion=1, flag=wx.ALIGN_RIGHT)
  252. gridSizer.Add(item=wx.StaticText(self, id=wx.ID_ANY, label=_("View mode:")),
  253. flag=wx.ALIGN_CENTER_VERTICAL)
  254. gridSizer.Add(item=self.nDChoice, proportion=1, flag=wx.ALIGN_RIGHT)
  255. gridSizer.AddGrowableCol(0, 1)
  256. gridSizer.AddGrowableCol(1, 1)
  257. mainSizer.Add(item=gridSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  258. label = _("For 3D animation, please select only one space-time dataset\n"
  259. "or one series of map layers.")
  260. self.warning3DLayers = wx.StaticText(self, label=label)
  261. self.warning3DLayers.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT))
  262. mainSizer.Add(item=self.warning3DLayers, proportion=0, flag=wx.EXPAND | wx.LEFT, border=5)
  263. self.dataPanel = self._createDataPanel()
  264. self.threeDPanel = self._create3DPanel()
  265. mainSizer.Add(item=self.dataPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  266. mainSizer.Add(item=self.threeDPanel, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  267. # buttons
  268. self.btnOk = wx.Button(self, wx.ID_OK)
  269. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  270. self.btnOk.SetDefault()
  271. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  272. # button sizer
  273. btnStdSizer = wx.StdDialogButtonSizer()
  274. btnStdSizer.AddButton(self.btnOk)
  275. btnStdSizer.AddButton(self.btnCancel)
  276. btnStdSizer.Realize()
  277. mainSizer.Add(item=btnStdSizer, proportion=0,
  278. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  279. self.SetSizer(mainSizer)
  280. mainSizer.Fit(self)
  281. def _createDataPanel(self):
  282. panel = wx.Panel(self)
  283. slmgrSizer = wx.BoxSizer(wx.VERTICAL)
  284. self._layerList = copy.deepcopy(self.animationData.layerList)
  285. self.simpleLmgr = AnimSimpleLayerManager(parent=panel,
  286. layerList=self._layerList,
  287. modal=True)
  288. self.simpleLmgr.SetMinSize((globalvar.DIALOG_GSELECT_SIZE[0], 120))
  289. slmgrSizer.Add(self.simpleLmgr, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  290. self.legend = wx.CheckBox(panel, label=_("Show raster legend"))
  291. self.legend.SetValue(bool(self.animationData.legendCmd))
  292. self.legendBtn = wx.Button(panel, label=_("Set options"))
  293. self.legend.Bind(wx.EVT_CHECKBOX, self.OnLegend)
  294. self.legendBtn.Bind(wx.EVT_BUTTON, self.OnLegendProperties)
  295. hbox = wx.BoxSizer(wx.HORIZONTAL)
  296. hbox.Add(item=self.legend, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
  297. hbox.Add(item=self.legendBtn, proportion=0, flag=wx.LEFT, border=5)
  298. slmgrSizer.Add(item=hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  299. panel.SetSizerAndFit(slmgrSizer)
  300. panel.SetAutoLayout(True)
  301. return panel
  302. def _create3DPanel(self):
  303. panel = wx.Panel(self, id=wx.ID_ANY)
  304. dataStBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  305. label=' %s ' % _("3D view parameters"))
  306. dataBoxSizer = wx.StaticBoxSizer(dataStBox, wx.VERTICAL)
  307. # workspace file
  308. self.fileSelector = \
  309. filebrowse.FileBrowseButton(parent=panel, id=wx.ID_ANY,
  310. size=globalvar.DIALOG_GSELECT_SIZE,
  311. labelText=_("Workspace file:"),
  312. dialogTitle=_("Choose workspace file to "
  313. "import 3D view parameters"),
  314. buttonText=_('Browse'),
  315. startDirectory=os.getcwd(), fileMode=0,
  316. fileMask="GRASS Workspace File (*.gxw)|*.gxw")
  317. if self.animationData.workspaceFile:
  318. self.fileSelector.SetValue(self.animationData.workspaceFile)
  319. self.paramLabel = wx.StaticText(panel, wx.ID_ANY, label=_("Parameter for animation:"))
  320. self.paramChoice = wx.Choice(panel, id=wx.ID_ANY, choices=self.animationData.nvizParameters)
  321. self.paramChoice.SetStringSelection(self.animationData.nvizParameter)
  322. hbox = wx.BoxSizer(wx.HORIZONTAL)
  323. hbox.Add(item=self.fileSelector, proportion=1, flag=wx.EXPAND | wx.ALIGN_CENTER)
  324. dataBoxSizer.Add(item=hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  325. hbox = wx.BoxSizer(wx.HORIZONTAL)
  326. hbox.Add(item=self.paramLabel, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
  327. hbox.Add(item=self.paramChoice, proportion=1, flag=wx.EXPAND)
  328. dataBoxSizer.Add(item=hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  329. panel.SetSizerAndFit(dataBoxSizer)
  330. panel.SetAutoLayout(True)
  331. return panel
  332. def OnViewMode(self, event):
  333. mode = self.nDChoice.GetSelection()
  334. self.Freeze()
  335. self.simpleLmgr.Activate3D(mode == 1)
  336. self.warning3DLayers.Show(mode == 1)
  337. sizer = self.threeDPanel.GetContainingSizer()
  338. sizer.Show(self.threeDPanel, mode == 1, True)
  339. sizer.Layout()
  340. self.Layout()
  341. self.Fit()
  342. self.Thaw()
  343. def OnLegend(self, event):
  344. if not self.legend.IsChecked():
  345. return
  346. if self._tmpLegendCmd or self.animationData.legendCmd:
  347. return
  348. cmd = ['d.legend', 'at=5,50,2,5']
  349. GUI(parent=self, modal=True).ParseCommand(cmd=cmd,
  350. completed=(self.GetOptData, '', ''))
  351. def OnLegendProperties(self, event):
  352. """!Set options for legend"""
  353. if self._tmpLegendCmd:
  354. cmd = self._tmpLegendCmd
  355. elif self.animationData.legendCmd:
  356. cmd = self.animationData.legendCmd
  357. else:
  358. cmd = ['d.legend', 'at=5,50,2,5']
  359. mapName = self._getLegendMapHint()
  360. if mapName:
  361. cmd.append("map=%s" % mapName)
  362. GUI(parent=self, modal=True).ParseCommand(cmd=cmd,
  363. completed=(self.GetOptData, '', ''))
  364. def GetOptData(self, dcmd, layer, params, propwin):
  365. """!Process decoration layer data"""
  366. if dcmd:
  367. self._tmpLegendCmd = dcmd
  368. if not self.legend.IsChecked():
  369. self.legend.SetValue(True)
  370. else:
  371. if not self._tmpLegendCmd and not self.animationData.legendCmd:
  372. self.legend.SetValue(False)
  373. def _update(self):
  374. if self.nDChoice.GetSelection() == 1 and len(self._layerList) > 1:
  375. raise GException(_("Only one series or space-time "
  376. "dataset is accepted for 3D mode."))
  377. hasSeries = False
  378. for layer in self._layerList:
  379. if layer.active and hasattr(layer, 'maps'):
  380. hasSeries = True
  381. break
  382. if not hasSeries:
  383. raise GException(_("No map series or space-time dataset added."))
  384. self.animationData.layerList = self._layerList
  385. self.animationData.name = self.nameCtrl.GetValue()
  386. self.animationData.windowIndex = self.windowChoice.GetSelection()
  387. sel = self.nDChoice.GetSelection()
  388. self.animationData.viewMode = self.nDChoice.GetClientData(sel)
  389. self.animationData.legendCmd = None
  390. if self._tmpLegendCmd:
  391. if self.legend.IsChecked():
  392. self.animationData.legendCmd = self._tmpLegendCmd
  393. if self.threeDPanel.IsShown():
  394. self.animationData.workspaceFile = self.fileSelector.GetValue()
  395. if self.threeDPanel.IsShown():
  396. self.animationData.nvizParameter = self.paramChoice.GetStringSelection()
  397. def OnOk(self, event):
  398. try:
  399. self._update()
  400. self.EndModal(wx.ID_OK)
  401. except (GException, ValueError, IOError) as e:
  402. GError(message=str(e), showTraceback=False, caption=_("Invalid input"))
  403. class EditDialog(wx.Dialog):
  404. def __init__(self, parent, evalFunction, animationData, maxAnimations):
  405. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  406. style=wx.DEFAULT_DIALOG_STYLE)
  407. self.animationData = copy.deepcopy(animationData)
  408. self.eval = evalFunction
  409. self.SetTitle(_("Add, edit or remove animations"))
  410. self._layout()
  411. self.SetSize((300, -1))
  412. self.maxAnimations = maxAnimations
  413. self.result = None
  414. def _layout(self):
  415. mainSizer = wx.BoxSizer(wx.VERTICAL)
  416. box = wx.StaticBox (parent=self, id=wx.ID_ANY, label=" %s " % _("List of animations"))
  417. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  418. gridBagSizer = wx.GridBagSizer (hgap=5, vgap=5)
  419. gridBagSizer.AddGrowableCol(0)
  420. # gridBagSizer.AddGrowableCol(1,1)
  421. self.listbox = wx.ListBox(self, id=wx.ID_ANY, choices=[], style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  422. self.listbox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnEdit)
  423. self.addButton = wx.Button(self, id=wx.ID_ANY, label=_("Add"))
  424. self.addButton.Bind(wx.EVT_BUTTON, self.OnAdd)
  425. self.editButton = wx.Button(self, id=wx.ID_ANY, label=_("Edit"))
  426. self.editButton.Bind(wx.EVT_BUTTON, self.OnEdit)
  427. self.removeButton = wx.Button(self, id=wx.ID_ANY, label=_("Remove"))
  428. self.removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  429. self._updateListBox()
  430. gridBagSizer.Add(self.listbox, pos=(0, 0), span = (3, 1),
  431. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  432. gridBagSizer.Add(self.addButton, pos=(0, 1),
  433. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  434. gridBagSizer.Add(self.editButton, pos=(1, 1),
  435. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  436. gridBagSizer.Add(self.removeButton, pos=(2, 1),
  437. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  438. sizer.Add(gridBagSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  439. mainSizer.Add(item=sizer, proportion=0,
  440. flag=wx.EXPAND | wx.ALL, border=5)
  441. # buttons
  442. self.btnOk = wx.Button(self, wx.ID_OK)
  443. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  444. self.btnOk.SetDefault()
  445. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  446. # button sizer
  447. btnStdSizer = wx.StdDialogButtonSizer()
  448. btnStdSizer.AddButton(self.btnOk)
  449. btnStdSizer.AddButton(self.btnCancel)
  450. btnStdSizer.Realize()
  451. mainSizer.Add(item=btnStdSizer, proportion=0,
  452. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  453. self.SetSizer(mainSizer)
  454. mainSizer.Fit(self)
  455. def _updateListBox(self):
  456. self.listbox.Clear()
  457. for anim in self.animationData:
  458. self.listbox.Append(anim.name, clientData=anim)
  459. if self.animationData:
  460. self.listbox.SetSelection(0)
  461. def _getNextIndex(self):
  462. indices = [anim.windowIndex for anim in self.animationData]
  463. for i in range(self.maxAnimations):
  464. if i not in indices:
  465. return i
  466. return None
  467. def OnAdd(self, event):
  468. windowIndex = self._getNextIndex()
  469. if windowIndex is None:
  470. GMessage(self, message=_("Maximum number of animations is %d.") % self.maxAnimations)
  471. return
  472. animData = AnimationData()
  473. # number of active animations
  474. animationIndex = len(self.animationData)
  475. animData.SetDefaultValues(windowIndex, animationIndex)
  476. dlg = InputDialog(parent=self, mode='add', animationData=animData)
  477. if dlg.ShowModal() == wx.ID_CANCEL:
  478. dlg.Destroy()
  479. return
  480. dlg.Destroy()
  481. self.animationData.append(animData)
  482. self._updateListBox()
  483. def OnEdit(self, event):
  484. index = self.listbox.GetSelection()
  485. if index == wx.NOT_FOUND:
  486. return
  487. animData = self.listbox.GetClientData(index)
  488. dlg = InputDialog(parent=self, mode='edit', animationData=animData)
  489. if dlg.ShowModal() == wx.ID_CANCEL:
  490. dlg.Destroy()
  491. return
  492. dlg.Destroy()
  493. self._updateListBox()
  494. def OnRemove(self, event):
  495. index = self.listbox.GetSelection()
  496. if index == wx.NOT_FOUND:
  497. return
  498. animData = self.listbox.GetClientData(index)
  499. self.animationData.remove(animData)
  500. self._updateListBox()
  501. def GetResult(self):
  502. return self.result
  503. def OnOk(self, event):
  504. indices = set([anim.windowIndex for anim in self.animationData])
  505. if len(indices) != len(self.animationData):
  506. GError(parent=self, message=_("More animations are using one window."
  507. " Please select different window for each animation."))
  508. return
  509. try:
  510. temporalMode, tempManager = self.eval(self.animationData)
  511. except GException, e:
  512. GError(parent=self, message=e.value, showTraceback=False)
  513. return
  514. self.result = (self.animationData, temporalMode, tempManager)
  515. self.EndModal(wx.ID_OK)
  516. class ExportDialog(wx.Dialog):
  517. def __init__(self, parent, temporal, timeTick):
  518. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=_("Export animation"),
  519. style=wx.DEFAULT_DIALOG_STYLE)
  520. self.decorations = []
  521. self.temporal = temporal
  522. self.timeTick = timeTick
  523. self._layout()
  524. # export animation
  525. self.doExport = Signal('ExportDialog::doExport')
  526. wx.CallAfter(self._hideAll)
  527. def _layout(self):
  528. notebook = wx.Notebook(self, id=wx.ID_ANY)
  529. mainSizer = wx.BoxSizer(wx.VERTICAL)
  530. notebook.AddPage(page=self._createExportFormatPanel(notebook), text=_("Format"))
  531. notebook.AddPage(page=self._createDecorationsPanel(notebook), text=_("Decorations"))
  532. mainSizer.Add(item=notebook, proportion=0,
  533. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  534. self.btnExport = wx.Button(self, wx.ID_OK)
  535. self.btnExport.SetLabel(_("Export"))
  536. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  537. self.btnExport.SetDefault()
  538. self.btnExport.Bind(wx.EVT_BUTTON, self.OnExport)
  539. # button sizer
  540. btnStdSizer = wx.StdDialogButtonSizer()
  541. btnStdSizer.AddButton(self.btnExport)
  542. btnStdSizer.AddButton(self.btnCancel)
  543. btnStdSizer.Realize()
  544. mainSizer.Add(item=btnStdSizer, proportion=0,
  545. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  546. self.SetSizer(mainSizer)
  547. # set the longest option to fit
  548. self.hidevbox.Show(self.fontBox, True)
  549. self.hidevbox.Show(self.imageBox, False)
  550. self.hidevbox.Show(self.textBox, True)
  551. self.hidevbox.Show(self.posBox, True)
  552. self.hidevbox.Show(self.informBox, False)
  553. mainSizer.Fit(self)
  554. def _createDecorationsPanel(self, notebook):
  555. panel = wx.Panel(notebook, id=wx.ID_ANY)
  556. sizer = wx.BoxSizer(wx.VERTICAL)
  557. sizer.Add(self._createDecorationsList(panel), proportion=0, flag=wx.ALL | wx.EXPAND, border=10)
  558. sizer.Add(self._createDecorationsProperties(panel), proportion=0, flag=wx.ALL | wx.EXPAND, border=10)
  559. panel.SetSizer(sizer)
  560. sizer.Fit(panel)
  561. return panel
  562. def _createDecorationsList(self, panel):
  563. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  564. gridBagSizer.AddGrowableCol(0)
  565. self.listbox = wx.ListBox(panel, id=wx.ID_ANY, choices=[],
  566. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  567. self.listbox.Bind(wx.EVT_LISTBOX, self.OnSelectionChanged)
  568. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(4, 1),
  569. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  570. buttonNames = ['time', 'image', 'text']
  571. buttonLabels = [_("Add time stamp"), _("Add image"), _("Add text")]
  572. i = 0
  573. for buttonName, buttonLabel in zip(buttonNames, buttonLabels):
  574. if buttonName == 'time' and self.temporal == TemporalMode.NONTEMPORAL:
  575. continue
  576. btn = wx.Button(panel, id=wx.ID_ANY, name=buttonName, label=buttonLabel)
  577. btn.Bind(wx.EVT_BUTTON, lambda evt, temp=buttonName: self.OnAddDecoration(evt, temp))
  578. gridBagSizer.Add(btn, pos=(i, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  579. i += 1
  580. removeButton = wx.Button(panel, id=wx.ID_ANY, label=_("Remove"))
  581. removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  582. gridBagSizer.Add(removeButton, pos=(i, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  583. return gridBagSizer
  584. def _createDecorationsProperties(self, panel):
  585. self.hidevbox = wx.BoxSizer(wx.VERTICAL)
  586. # inform label
  587. self.informBox = wx.BoxSizer(wx.HORIZONTAL)
  588. if self.temporal == TemporalMode.TEMPORAL:
  589. label = _("Add time stamp, image or text decoration by one of the buttons above.")
  590. else:
  591. label = _("Add image or text decoration by one of the buttons above.")
  592. label = wx.StaticText(panel, id=wx.ID_ANY, label=label)
  593. label.Wrap(400)
  594. self.informBox.Add(label, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=5)
  595. self.hidevbox.Add(self.informBox, proportion=0, flag=wx.EXPAND | wx.BOTTOM, border=5)
  596. # font
  597. self.fontBox = wx.BoxSizer(wx.HORIZONTAL)
  598. self.fontBox.Add(wx.StaticText(panel, id=wx.ID_ANY, label=_("Font settings:")),
  599. proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=5)
  600. self.sampleLabel = wx.StaticText(panel, id=wx.ID_ANY, label=_("Sample text"))
  601. self.fontBox.Add(self.sampleLabel, proportion=1,
  602. flag=wx.ALIGN_CENTER | wx.RIGHT | wx.LEFT, border=5)
  603. fontButton = wx.Button(panel, id=wx.ID_ANY, label=_("Set font"))
  604. fontButton.Bind(wx.EVT_BUTTON, self.OnFont)
  605. self.fontBox.Add(fontButton, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  606. self.hidevbox.Add(self.fontBox, proportion=0, flag=wx.EXPAND | wx.BOTTOM, border=5)
  607. # image
  608. self.imageBox = wx.BoxSizer(wx.HORIZONTAL)
  609. filetype, ltype = GetImageHandlers(wx.EmptyImage(10, 10))
  610. self.browse = filebrowse.FileBrowseButton(parent=panel, id=wx.ID_ANY, fileMask=filetype,
  611. labelText=_("Image file:"),
  612. dialogTitle=_('Choose image file'),
  613. buttonText=_('Browse'),
  614. startDirectory=os.getcwd(), fileMode=wx.OPEN,
  615. changeCallback=self.OnSetImage)
  616. self.imageBox.Add(self.browse, proportion=1, flag=wx.EXPAND)
  617. self.hidevbox.Add(self.imageBox, proportion=0, flag=wx.EXPAND | wx.BOTTOM, border=5)
  618. # text
  619. self.textBox = wx.BoxSizer(wx.HORIZONTAL)
  620. self.textBox.Add(wx.StaticText(panel, id=wx.ID_ANY, label=_("Text:")),
  621. proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=5)
  622. self.textCtrl = wx.TextCtrl(panel, id=wx.ID_ANY)
  623. self.textCtrl.Bind(wx.EVT_TEXT, self.OnText)
  624. self.textBox.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
  625. self.hidevbox.Add(self.textBox, proportion=0, flag=wx.EXPAND)
  626. self.posBox = self._positionWidget(panel)
  627. self.hidevbox.Add(self.posBox, proportion=0, flag=wx.EXPAND | wx.TOP, border=5)
  628. return self.hidevbox
  629. def _positionWidget(self, panel):
  630. grid = wx.GridBagSizer(vgap=5, hgap=5)
  631. label = wx.StaticText(panel, id=wx.ID_ANY, label=_("Placement as percentage of"
  632. " screen coordinates (X: 0, Y: 0 is top left):"))
  633. label.Wrap(400)
  634. self.spinX = wx.SpinCtrl(panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  635. self.spinY = wx.SpinCtrl(panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  636. self.spinX.Bind(wx.EVT_SPINCTRL, lambda evt, temp='X': self.OnPosition(evt, temp))
  637. self.spinY.Bind(wx.EVT_SPINCTRL, lambda evt, temp='Y': self.OnPosition(evt, temp))
  638. grid.Add(label, pos=(0, 0), span = (1, 4), flag = wx.EXPAND)
  639. grid.Add(wx.StaticText(panel, id=wx.ID_ANY, label=_("X:")), pos=(1, 0),
  640. flag = wx.ALIGN_CENTER_VERTICAL)
  641. grid.Add(wx.StaticText(panel, id=wx.ID_ANY, label=_("Y:")), pos=(1, 2),
  642. flag = wx.ALIGN_CENTER_VERTICAL)
  643. grid.Add(self.spinX, pos=(1, 1))
  644. grid.Add(self.spinY, pos=(1, 3))
  645. return grid
  646. def _createExportFormatPanel(self, notebook):
  647. panel = wx.Panel(notebook, id=wx.ID_ANY)
  648. borderSizer = wx.BoxSizer(wx.VERTICAL)
  649. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  650. choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
  651. self.formatChoice = wx.Choice(parent=panel, id=wx.ID_ANY,
  652. choices=choices)
  653. self.formatChoice.Bind(wx.EVT_CHOICE, lambda event: self.ChangeFormat(event.GetSelection()))
  654. hSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("Export to:")),
  655. proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=2)
  656. hSizer.Add(item=self.formatChoice, proportion=1,
  657. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.ALL, border=2)
  658. borderSizer.Add(item=hSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  659. helpSizer = wx.BoxSizer(wx.HORIZONTAL)
  660. helpSizer.AddStretchSpacer(1)
  661. self.formatPanelSizer = wx.BoxSizer(wx.VERTICAL)
  662. helpSizer.Add(self.formatPanelSizer, proportion=5, flag=wx.EXPAND)
  663. borderSizer.Add(helpSizer, proportion=1, flag=wx.EXPAND)
  664. self.formatPanels = []
  665. # panel for image sequence
  666. imSeqPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  667. prefixLabel = wx.StaticText(imSeqPanel, id=wx.ID_ANY, label=_("File prefix:"))
  668. self.prefixCtrl = wx.TextCtrl(imSeqPanel, id=wx.ID_ANY, value=_("animation_"))
  669. formatLabel = wx.StaticText(imSeqPanel, id=wx.ID_ANY, label=_("File format:"))
  670. imageTypes = ['PNG', 'JPEG', 'GIF', 'TIFF', 'PPM', 'BMP']
  671. self.imSeqFormatChoice = wx.Choice(imSeqPanel, choices=imageTypes)
  672. self.imSeqFormatChoice.SetSelection(0)
  673. self.dirBrowse = filebrowse.DirBrowseButton(parent=imSeqPanel, id=wx.ID_ANY,
  674. labelText=_("Directory:"),
  675. dialogTitle=_("Choose directory for export"),
  676. buttonText=_("Browse"),
  677. startDirectory=os.getcwd())
  678. dirGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  679. dirGridSizer.AddGrowableCol(1)
  680. dirGridSizer.Add(prefixLabel, pos=(0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  681. dirGridSizer.Add(self.prefixCtrl, pos=(0, 1), flag = wx.EXPAND)
  682. dirGridSizer.Add(formatLabel, pos=(1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  683. dirGridSizer.Add(self.imSeqFormatChoice, pos=(1, 1), flag = wx.EXPAND)
  684. dirGridSizer.Add(self.dirBrowse, pos=(2, 0), flag = wx.EXPAND, span = (1, 2))
  685. imSeqPanel.SetSizer(dirGridSizer)
  686. dirGridSizer.Fit(imSeqPanel)
  687. self.formatPanelSizer.Add(item=imSeqPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  688. self.formatPanels.append(imSeqPanel)
  689. # panel for gif
  690. gifPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  691. self.gifBrowse = filebrowse.FileBrowseButton(parent=gifPanel, id=wx.ID_ANY,
  692. fileMask="GIF file (*.gif)|*.gif",
  693. labelText=_("GIF file:"),
  694. dialogTitle=_("Choose file to save animation"),
  695. buttonText=_("Browse"),
  696. startDirectory=os.getcwd(), fileMode=wx.SAVE)
  697. gifGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  698. gifGridSizer.AddGrowableCol(0)
  699. gifGridSizer.Add(self.gifBrowse, pos=(0, 0), flag = wx.EXPAND)
  700. gifPanel.SetSizer(gifGridSizer)
  701. gifGridSizer.Fit(gifPanel)
  702. self.formatPanelSizer.Add(item=gifPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  703. self.formatPanels.append(gifPanel)
  704. # panel for swf
  705. swfPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  706. self.swfBrowse = filebrowse.FileBrowseButton(parent=swfPanel, id=wx.ID_ANY,
  707. fileMask="SWF file (*.swf)|*.swf",
  708. labelText=_("SWF file:"),
  709. dialogTitle=_("Choose file to save animation"),
  710. buttonText=_("Browse"),
  711. startDirectory=os.getcwd(), fileMode=wx.SAVE)
  712. swfGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  713. swfGridSizer.AddGrowableCol(0)
  714. swfGridSizer.Add(self.swfBrowse, pos=(0, 0), flag = wx.EXPAND)
  715. swfPanel.SetSizer(swfGridSizer)
  716. swfGridSizer.Fit(swfPanel)
  717. self.formatPanelSizer.Add(item=swfPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  718. self.formatPanels.append(swfPanel)
  719. # panel for avi
  720. aviPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  721. ffmpeg = gcore.find_program('ffmpeg', '--help')
  722. if not ffmpeg:
  723. warning = _("Program 'ffmpeg' was not found.\nPlease install it first "
  724. "and make sure\nit's in the PATH variable.")
  725. warningLabel = wx.StaticText(parent=aviPanel, label=warning)
  726. warningLabel.SetForegroundColour(wx.RED)
  727. self.aviBrowse = filebrowse.FileBrowseButton(parent=aviPanel, id=wx.ID_ANY,
  728. fileMask="AVI file (*.avi)|*.avi",
  729. labelText=_("AVI file:"),
  730. dialogTitle=_("Choose file to save animation"),
  731. buttonText=_("Browse"),
  732. startDirectory=os.getcwd(), fileMode=wx.SAVE)
  733. encodingLabel = wx.StaticText(parent=aviPanel, id=wx.ID_ANY, label=_("Video codec:"))
  734. self.encodingText = wx.TextCtrl(parent=aviPanel, id=wx.ID_ANY, value='mpeg4')
  735. optionsLabel = wx.StaticText(parent=aviPanel, label=_("Additional options:"))
  736. self.optionsText = wx.TextCtrl(parent=aviPanel)
  737. self.optionsText.SetToolTipString(_("Consider adding '-sameq' or '-qscale 1' "
  738. "if not satisfied with video quality. "
  739. "Options depend on ffmpeg version."))
  740. aviGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  741. aviGridSizer.AddGrowableCol(1)
  742. aviGridSizer.Add(self.aviBrowse, pos=(0, 0), span = (1, 2), flag = wx.EXPAND)
  743. aviGridSizer.Add(encodingLabel, pos=(1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  744. aviGridSizer.Add(self.encodingText, pos=(1, 1), flag = wx.EXPAND)
  745. aviGridSizer.Add(optionsLabel, pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  746. aviGridSizer.Add(self.optionsText, pos=(2, 1), flag=wx.EXPAND)
  747. if not ffmpeg:
  748. aviGridSizer.Add(warningLabel, pos=(3, 0), span=(1, 2),
  749. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  750. aviPanel.SetSizer(aviGridSizer)
  751. aviGridSizer.Fit(aviPanel)
  752. self.formatPanelSizer.Add(item=aviPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  753. self.formatPanels.append(aviPanel)
  754. fpsSizer = wx.BoxSizer(wx.HORIZONTAL)
  755. fps = 1000 / self.timeTick
  756. fpsSizer.Add(wx.StaticText(panel, id=wx.ID_ANY, label=_("Current frame rate: %.2f fps") % fps),
  757. proportion=1, flag=wx.EXPAND)
  758. borderSizer.Add(fpsSizer, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  759. panel.SetSizer(borderSizer)
  760. borderSizer.Fit(panel)
  761. self.ChangeFormat(index=0)
  762. return panel
  763. def ChangeFormat(self, index):
  764. for i, panel in enumerate(self.formatPanels):
  765. self.formatPanelSizer.Show(item=panel, show=(i == index))
  766. self.formatPanelSizer.Layout()
  767. def OnFont(self, event):
  768. index = self.listbox.GetSelection()
  769. # should not happen
  770. if index == wx.NOT_FOUND:
  771. return
  772. cdata = self.listbox.GetClientData(index)
  773. font = cdata['font']
  774. fontdata = wx.FontData()
  775. fontdata.EnableEffects(True)
  776. fontdata.SetColour('black')
  777. fontdata.SetInitialFont(font)
  778. dlg = wx.FontDialog(self, fontdata)
  779. if dlg.ShowModal() == wx.ID_OK:
  780. newfontdata = dlg.GetFontData()
  781. font = newfontdata.GetChosenFont()
  782. self.sampleLabel.SetFont(font)
  783. cdata['font'] = font
  784. self.Layout()
  785. def OnPosition(self, event, coord):
  786. index = self.listbox.GetSelection()
  787. # should not happen
  788. if index == wx.NOT_FOUND:
  789. return
  790. cdata = self.listbox.GetClientData(index)
  791. cdata['pos'][coord == 'Y'] = event.GetInt()
  792. def OnSetImage(self, event):
  793. index = self.listbox.GetSelection()
  794. # should not happen
  795. if index == wx.NOT_FOUND:
  796. return
  797. cdata = self.listbox.GetClientData(index)
  798. cdata['file'] = event.GetString()
  799. def OnAddDecoration(self, event, name):
  800. if name == 'time':
  801. timeInfo = {'name': name, 'font': self.GetFont(), 'pos': [10, 10]}
  802. self.decorations.append(timeInfo)
  803. elif name == 'image':
  804. imageInfo = {'name': name, 'file': '', 'pos': [10, 10]}
  805. self.decorations.append(imageInfo)
  806. elif name == 'text':
  807. textInfo = {'name': name, 'font': self.GetFont(), 'text': '', 'pos': [10, 10]}
  808. self.decorations.append(textInfo)
  809. self._updateListBox()
  810. self.listbox.SetSelection(self.listbox.GetCount() - 1)
  811. self.OnSelectionChanged(event=None)
  812. def OnSelectionChanged(self, event):
  813. index = self.listbox.GetSelection()
  814. if index == wx.NOT_FOUND:
  815. self._hideAll()
  816. return
  817. cdata = self.listbox.GetClientData(index)
  818. self.hidevbox.Show(self.fontBox, (cdata['name'] in ('time', 'text')))
  819. self.hidevbox.Show(self.imageBox, (cdata['name'] == 'image'))
  820. self.hidevbox.Show(self.textBox, (cdata['name'] == 'text'))
  821. self.hidevbox.Show(self.posBox, True)
  822. self.hidevbox.Show(self.informBox, False)
  823. self.spinX.SetValue(cdata['pos'][0])
  824. self.spinY.SetValue(cdata['pos'][1])
  825. if cdata['name'] == 'image':
  826. self.browse.SetValue(cdata['file'])
  827. elif cdata['name'] in ('time', 'text'):
  828. self.sampleLabel.SetFont(cdata['font'])
  829. if cdata['name'] == 'text':
  830. self.textCtrl.SetValue(cdata['text'])
  831. self.hidevbox.Layout()
  832. # self.Layout()
  833. def OnText(self, event):
  834. index = self.listbox.GetSelection()
  835. # should not happen
  836. if index == wx.NOT_FOUND:
  837. return
  838. cdata = self.listbox.GetClientData(index)
  839. cdata['text'] = event.GetString()
  840. def OnRemove(self, event):
  841. index = self.listbox.GetSelection()
  842. if index == wx.NOT_FOUND:
  843. return
  844. decData = self.listbox.GetClientData(index)
  845. self.decorations.remove(decData)
  846. self._updateListBox()
  847. if self.listbox.GetCount():
  848. self.listbox.SetSelection(0)
  849. self.OnSelectionChanged(event=None)
  850. def OnExport(self, event):
  851. for decor in self.decorations:
  852. if decor['name'] == 'image':
  853. if not os.path.exists(decor['file']):
  854. if decor['file']:
  855. GError(parent=self, message=_("File %s not found.") % decor['file'])
  856. else:
  857. GError(parent=self, message=_("Decoration image file is missing."))
  858. return
  859. if self.formatChoice.GetSelection() == 0:
  860. name = self.dirBrowse.GetValue()
  861. if not os.path.exists(name):
  862. if name:
  863. GError(parent=self, message=_("Directory %s not found.") % name)
  864. else:
  865. GError(parent=self, message=_("Export directory is missing."))
  866. return
  867. elif self.formatChoice.GetSelection() == 1:
  868. if not self.gifBrowse.GetValue():
  869. GError(parent=self, message=_("Export file is missing."))
  870. return
  871. elif self.formatChoice.GetSelection() == 2:
  872. if not self.swfBrowse.GetValue():
  873. GError(parent=self, message=_("Export file is missing."))
  874. return
  875. # hide only to keep previous values
  876. self.Hide()
  877. self.doExport.emit(exportInfo=self.GetExportInformation(),
  878. decorations=self.GetDecorations())
  879. def GetDecorations(self):
  880. return self.decorations
  881. def GetExportInformation(self):
  882. info = {}
  883. if self.formatChoice.GetSelection() == 0:
  884. info['method'] = 'sequence'
  885. info['directory'] = self.dirBrowse.GetValue()
  886. info['prefix'] = self.prefixCtrl.GetValue()
  887. info['format'] = self.imSeqFormatChoice.GetStringSelection()
  888. elif self.formatChoice.GetSelection() == 1:
  889. info['method'] = 'gif'
  890. info['file'] = self.gifBrowse.GetValue()
  891. elif self.formatChoice.GetSelection() == 2:
  892. info['method'] = 'swf'
  893. info['file'] = self.swfBrowse.GetValue()
  894. elif self.formatChoice.GetSelection() == 3:
  895. info['method'] = 'avi'
  896. info['file'] = self.aviBrowse.GetValue()
  897. info['encoding'] = self.encodingText.GetValue()
  898. info['options'] = self.optionsText.GetValue()
  899. return info
  900. def _updateListBox(self):
  901. self.listbox.Clear()
  902. names = {'time': _("Time stamp"), 'image': _("Image"), 'text': _("Text")}
  903. for decor in self.decorations:
  904. self.listbox.Append(names[decor['name']], clientData=decor)
  905. def _hideAll(self):
  906. self.hidevbox.Show(self.fontBox, False)
  907. self.hidevbox.Show(self.imageBox, False)
  908. self.hidevbox.Show(self.textBox, False)
  909. self.hidevbox.Show(self.posBox, False)
  910. self.hidevbox.Show(self.informBox, True)
  911. self.hidevbox.Layout()
  912. class AnimSimpleLayerManager(SimpleLayerManager):
  913. """!Simple layer manager for animation tool.
  914. Allows to add space-time dataset or series of maps.
  915. """
  916. def __init__(self, parent, layerList,
  917. lmgrStyle=SIMPLE_LMGR_RASTER | SIMPLE_LMGR_VECTOR |
  918. SIMPLE_LMGR_TB_TOP | SIMPLE_LMGR_STDS,
  919. toolbarCls=AnimSimpleLmgrToolbar, modal=True):
  920. SimpleLayerManager.__init__(self, parent, layerList, lmgrStyle, toolbarCls, modal)
  921. def OnAddStds(self, event):
  922. """!Opens dialog for specifying temporal dataset.
  923. Dummy layer is added first."""
  924. layer = AnimLayer()
  925. layer.hidden = True
  926. self._layerList.AddLayer(layer)
  927. self.SetStdsProperties(layer)
  928. event.Skip()
  929. def SetStdsProperties(self, layer):
  930. dlg = AddTemporalLayerDialog(parent=self, layer=layer)
  931. # first get hidden property, it's altered afterwards
  932. hidden = layer.hidden
  933. if dlg.ShowModal() == wx.ID_OK:
  934. layer = dlg.GetLayer()
  935. if hidden:
  936. signal = self.layerAdded
  937. else:
  938. signal = self.cmdChanged
  939. signal.emit(index=self._layerList.GetLayerIndex(layer), layer=layer)
  940. else:
  941. if hidden:
  942. self._layerList.RemoveLayer(layer)
  943. dlg.Destroy()
  944. self._update()
  945. self.anyChange.emit()
  946. def _layerChangeProperties(self, layer):
  947. """!Opens new module dialog or recycles it."""
  948. if not hasattr(layer, 'maps'):
  949. GUI(parent=self, giface=None,
  950. modal=self._modal).ParseCommand(cmd=layer.cmd,
  951. completed=(self.GetOptData, layer, ''))
  952. else:
  953. self.SetStdsProperties(layer)
  954. def Activate3D(self, activate=True):
  955. """!Activates/deactivates certain tool depending on 2D/3D view."""
  956. self._toolbar.EnableTools(['addRaster', 'addVector',
  957. 'opacity', 'up', 'down'], not activate)
  958. class AddTemporalLayerDialog(wx.Dialog):
  959. """!Dialog for adding space-time dataset/ map series."""
  960. def __init__(self, parent, layer, title=_("Add space-time dataset layer")):
  961. wx.Dialog.__init__(self, parent=parent, title=title)
  962. self.layer = layer
  963. self._mapType = None
  964. self._name = None
  965. self._cmd = None
  966. self.tselect = Select(parent=self, type='strds')
  967. iconTheme = UserSettings.Get(group='appearance', key='iconTheme', subkey='type')
  968. bitmapPath = os.path.join(globalvar.ETCICONDIR, iconTheme, 'layer-open.png')
  969. if os.path.isfile(bitmapPath) and os.path.getsize(bitmapPath):
  970. bitmap = wx.Bitmap(name=bitmapPath)
  971. else:
  972. bitmap = wx.ArtProvider.GetBitmap(id=wx.ART_MISSING_IMAGE, client=wx.ART_TOOLBAR)
  973. self.addManyMapsButton = wx.BitmapButton(self, bitmap=bitmap)
  974. self.addManyMapsButton.Bind(wx.EVT_BUTTON, self._onAddMaps)
  975. types = [('rast', _("Multiple raster maps")),
  976. ('vect', _("Multiple vector maps")),
  977. ('strds', _("Space time raster dataset")),
  978. ('stvds', _("Space time vector dataset"))]
  979. self._types = dict(types)
  980. self.tchoice = wx.Choice(parent=self)
  981. for type_, text in types:
  982. self.tchoice.Append(text, clientData=type_)
  983. self.editBtn = wx.Button(parent=self, label='Set properties')
  984. self.okBtn = wx.Button(parent=self, id=wx.ID_OK)
  985. self.cancelBtn = wx.Button(parent=self, id=wx.ID_CANCEL)
  986. self.okBtn.Bind(wx.EVT_BUTTON, self._onOK)
  987. self.editBtn.Bind(wx.EVT_BUTTON, self._onProperties)
  988. self.tchoice.Bind(wx.EVT_CHOICE,
  989. lambda evt: self._setType())
  990. self.tselect.Bind(wx.EVT_TEXT,
  991. lambda evt: self._datasetChanged())
  992. if self.layer.mapType:
  993. self._setType(self.layer.mapType)
  994. else:
  995. self._setType('rast')
  996. if self.layer.name:
  997. self.tselect.SetValue(self.layer.name)
  998. if self.layer.cmd:
  999. self._cmd = self.layer.cmd
  1000. self._layout()
  1001. self.SetSize(self.GetBestSize())
  1002. def _layout(self):
  1003. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1004. bodySizer = wx.BoxSizer(wx.VERTICAL)
  1005. typeSizer = wx.BoxSizer(wx.HORIZONTAL)
  1006. selectSizer = wx.BoxSizer(wx.HORIZONTAL)
  1007. typeSizer.Add(wx.StaticText(self, label=_("Input data type:")),
  1008. flag=wx.ALIGN_CENTER_VERTICAL)
  1009. typeSizer.AddStretchSpacer()
  1010. typeSizer.Add(self.tchoice)
  1011. bodySizer.Add(typeSizer, flag=wx.EXPAND | wx.BOTTOM, border=5)
  1012. selectSizer.Add(self.tselect, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=5)
  1013. selectSizer.Add(self.addManyMapsButton, flag=wx.EXPAND)
  1014. bodySizer.Add(selectSizer, flag=wx.BOTTOM, border=5)
  1015. bodySizer.Add(self.editBtn, flag=wx.BOTTOM, border=5)
  1016. mainSizer.Add(bodySizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
  1017. btnSizer = wx.StdDialogButtonSizer()
  1018. btnSizer.AddButton(self.okBtn)
  1019. btnSizer.AddButton(self.cancelBtn)
  1020. btnSizer.Realize()
  1021. mainSizer.Add(btnSizer, proportion=0,
  1022. flag=wx.EXPAND | wx.ALL, border=10)
  1023. self.SetSizer(mainSizer)
  1024. mainSizer.Fit(self)
  1025. def _datasetChanged(self):
  1026. if self._name != self.tselect.GetValue():
  1027. self._name = self.tselect.GetValue()
  1028. self._cmd = None
  1029. def _setType(self, typeName=None):
  1030. if typeName:
  1031. self.tchoice.SetStringSelection(self._types[typeName])
  1032. self.tselect.SetType(typeName)
  1033. if typeName in ('strds', 'stvds'):
  1034. self.tselect.SetType(typeName, multiple=False)
  1035. self.addManyMapsButton.Disable()
  1036. else:
  1037. self.tselect.SetType(typeName, multiple=True)
  1038. self.addManyMapsButton.Enable()
  1039. self._mapType = typeName
  1040. self.tselect.SetValue('')
  1041. else:
  1042. typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
  1043. if typeName in ('strds', 'stvds'):
  1044. self.tselect.SetType(typeName, multiple=False)
  1045. self.addManyMapsButton.Disable()
  1046. else:
  1047. self.tselect.SetType(typeName, multiple=True)
  1048. self.addManyMapsButton.Enable()
  1049. if typeName != self._mapType:
  1050. self._cmd = None
  1051. self._mapType = typeName
  1052. self.tselect.SetValue('')
  1053. def _createDefaultCommand(self):
  1054. cmd = []
  1055. if self._mapType in ('rast', 'strds'):
  1056. cmd.append('d.rast')
  1057. elif self._mapType in ('vect', 'stvds'):
  1058. cmd.append('d.vect')
  1059. if self._name:
  1060. if self._mapType in ('rast', 'vect'):
  1061. cmd.append('map={}'.format(self._name.split(',')[0]))
  1062. else:
  1063. try:
  1064. maps = getRegisteredMaps(self._name, etype=self._mapType)
  1065. if maps:
  1066. cmd.append('map={}'.format(maps[0]))
  1067. except gcore.ScriptError, e:
  1068. GError(parent=self, message=str(e), showTraceback=False)
  1069. return None
  1070. return cmd
  1071. def _onAddMaps(self, event):
  1072. dlg = MapLayersDialog(self, title=_("Select raster/vector maps."))
  1073. dlg.applyAddingMapLayers.connect(lambda mapLayers:
  1074. self.tselect.SetValue(','.join(mapLayers)))
  1075. index = 0 if self._mapType == 'rast' else 1
  1076. dlg.layerType.SetSelection(index)
  1077. dlg.LoadMapLayers(dlg.GetLayerType(cmd=True),
  1078. dlg.mapset.GetStringSelection())
  1079. if dlg.ShowModal() == wx.ID_OK:
  1080. self.tselect.SetValue(','.join(dlg.GetMapLayers()))
  1081. dlg.Destroy()
  1082. def _onProperties(self, event):
  1083. self._checkInput()
  1084. if self._cmd:
  1085. GUI(parent=self, show=True, modal=True).ParseCommand(cmd=self._cmd,
  1086. completed=(self._getOptData, '', ''))
  1087. def _checkInput(self):
  1088. if not self.tselect.GetValue():
  1089. GMessage(parent=self, message=_("Please select maps or dataset first."))
  1090. return
  1091. if not self._cmd:
  1092. self._cmd = self._createDefaultCommand()
  1093. def _getOptData(self, dcmd, layer, params, propwin):
  1094. if dcmd:
  1095. self._cmd = dcmd
  1096. def _onOK(self, event):
  1097. self._checkInput()
  1098. if self._cmd:
  1099. try:
  1100. self.layer.hidden = False
  1101. self.layer.mapType = self._mapType
  1102. self.layer.name = self._name
  1103. self.layer.cmd = self._cmd
  1104. event.Skip()
  1105. except (GException, gcore.ScriptError), e:
  1106. GError(parent=self, message=str(e))
  1107. def GetLayer(self):
  1108. return self.layer
  1109. def test():
  1110. import wx.lib.inspection
  1111. app = wx.PySimpleApp()
  1112. # testTemporalLayer()
  1113. # testAnimLmgr()
  1114. testAnimInput()
  1115. # wx.lib.inspection.InspectionTool().Show()
  1116. app.MainLoop()
  1117. def testAnimInput():
  1118. anim = AnimationData()
  1119. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1120. dlg = InputDialog(parent=None, mode='add', animationData=anim)
  1121. dlg.Show()
  1122. def testAnimEdit():
  1123. anim = AnimationData()
  1124. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1125. dlg = EditDialog(parent=None, animationData=[anim])
  1126. dlg.Show()
  1127. def testExport():
  1128. dlg = ExportDialog(parent=None, temporal=TemporalMode.TEMPORAL,
  1129. timeTick=200)
  1130. if dlg.ShowModal() == wx.ID_OK:
  1131. print dlg.GetDecorations()
  1132. print dlg.GetExportInformation()
  1133. dlg.Destroy()
  1134. else:
  1135. dlg.Destroy()
  1136. def testTemporalLayer():
  1137. frame = wx.Frame(None)
  1138. frame.Show()
  1139. layer = AnimLayer()
  1140. dlg = AddTemporalLayerDialog(parent=frame, layer=layer)
  1141. if dlg.ShowModal() == wx.ID_OK:
  1142. layer = dlg.GetLayer()
  1143. print layer.name, layer.cmd, layer.mapType
  1144. dlg.Destroy()
  1145. else:
  1146. dlg.Destroy()
  1147. def testAnimLmgr():
  1148. from core.layerlist import LayerList
  1149. frame = wx.Frame(None)
  1150. mgr = AnimSimpleLayerManager(parent=frame, layerList=LayerList())
  1151. frame.mgr = mgr
  1152. frame.Show()
  1153. if __name__ == '__main__':
  1154. gcore.set_raise_on_error(True)
  1155. test()