dialogs.py 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  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. from __future__ import print_function
  17. import os
  18. import wx
  19. import copy
  20. import datetime
  21. import wx.lib.filebrowsebutton as filebrowse
  22. import wx.lib.scrolledpanel as SP
  23. import wx.lib.colourselect as csel
  24. try:
  25. from wx.adv import HyperlinkCtrl
  26. except ImportError:
  27. from wx import HyperlinkCtrl
  28. from core.gcmd import GMessage, GError, GException
  29. from core import globalvar
  30. from gui_core.dialogs import MapLayersDialog, GetImageHandlers
  31. from gui_core.preferences import PreferencesBaseDialog
  32. from gui_core.forms import GUI
  33. from core.settings import UserSettings
  34. from gui_core.gselect import Select
  35. from gui_core.widgets import FloatValidator
  36. from gui_core.wrap import SpinCtrl, CheckBox, TextCtrl, Button, \
  37. BitmapButton, StaticText, StaticBox, Choice, RadioButton, EmptyImage
  38. from animation.utils import TemporalMode, getRegisteredMaps, getNameAndLayer, getCpuCount
  39. from animation.data import AnimationData, AnimLayer
  40. from animation.toolbars import AnimSimpleLmgrToolbar, SIMPLE_LMGR_STDS
  41. from gui_core.simplelmgr import SimpleLayerManager, \
  42. SIMPLE_LMGR_RASTER, SIMPLE_LMGR_VECTOR, SIMPLE_LMGR_TB_TOP
  43. from grass.pydispatch.signal import Signal
  44. import grass.script.core as gcore
  45. class SpeedDialog(wx.Dialog):
  46. def __init__(self, parent, title=_("Adjust speed of animation"),
  47. temporalMode=None, minimumDuration=0, timeGranularity=None,
  48. initialSpeed=200):
  49. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
  50. style=wx.DEFAULT_DIALOG_STYLE)
  51. # signal emitted when speed has changed; has attribute 'ms'
  52. self.speedChanged = Signal('SpeedDialog.speedChanged')
  53. self.minimumDuration = minimumDuration
  54. # self.framesCount = framesCount
  55. self.defaultSpeed = initialSpeed
  56. self.lastAppliedValue = self.defaultSpeed
  57. self.lastAppliedValueTemp = self.defaultSpeed
  58. self._layout()
  59. self.temporalMode = temporalMode
  60. self.timeGranularity = timeGranularity
  61. self._fillUnitChoice(self.choiceUnits)
  62. self.InitTimeSpin(self.defaultSpeed)
  63. def SetTimeGranularity(self, gran):
  64. self._timeGranularity = gran
  65. def GetTimeGranularity(self):
  66. return self._timeGranularity
  67. timeGranularity = property(
  68. fset=SetTimeGranularity,
  69. fget=GetTimeGranularity)
  70. def SetTemporalMode(self, mode):
  71. self._temporalMode = mode
  72. self._setTemporalMode()
  73. def GetTemporalMode(self):
  74. return self._temporalMode
  75. temporalMode = property(fset=SetTemporalMode, fget=GetTemporalMode)
  76. def _layout(self):
  77. """Layout window"""
  78. mainSizer = wx.BoxSizer(wx.VERTICAL)
  79. #
  80. # simple mode
  81. #
  82. self.nontemporalBox = StaticBox(parent=self, id=wx.ID_ANY,
  83. label=' %s ' % _("Simple mode"))
  84. box = wx.StaticBoxSizer(self.nontemporalBox, wx.VERTICAL)
  85. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  86. labelDuration = StaticText(
  87. self, id=wx.ID_ANY, label=_("Frame duration:"))
  88. labelUnits = StaticText(self, id=wx.ID_ANY, label=_("ms"))
  89. self.spinDuration = SpinCtrl(
  90. self,
  91. id=wx.ID_ANY,
  92. min=self.minimumDuration,
  93. max=10000,
  94. initial=self.defaultSpeed)
  95. # TODO total time
  96. gridSizer.Add(
  97. labelDuration, pos=(0, 0),
  98. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  99. gridSizer.Add(self.spinDuration, pos=(0, 1), flag=wx.ALIGN_CENTER)
  100. gridSizer.Add(
  101. labelUnits, pos=(0, 2),
  102. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  103. gridSizer.AddGrowableCol(0)
  104. box.Add(
  105. gridSizer,
  106. proportion=1,
  107. border=5,
  108. flag=wx.ALL | wx.EXPAND)
  109. self.nontemporalSizer = gridSizer
  110. mainSizer.Add(
  111. box,
  112. proportion=0,
  113. flag=wx.EXPAND | wx.ALL,
  114. border=5)
  115. #
  116. # temporal mode
  117. #
  118. self.temporalBox = StaticBox(parent=self, id=wx.ID_ANY,
  119. label=' %s ' % _("Temporal mode"))
  120. box = wx.StaticBoxSizer(self.temporalBox, wx.VERTICAL)
  121. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  122. labelTimeUnit = StaticText(
  123. self, id=wx.ID_ANY, label=_("Time unit:"))
  124. labelDuration = StaticText(
  125. self, id=wx.ID_ANY, label=_("Duration of time unit:"))
  126. labelUnits = StaticText(self, id=wx.ID_ANY, label=_("ms"))
  127. self.spinDurationTemp = SpinCtrl(
  128. self, id=wx.ID_ANY, min=self.minimumDuration, max=10000,
  129. initial=self.defaultSpeed)
  130. self.choiceUnits = wx.Choice(self, id=wx.ID_ANY)
  131. # TODO total time
  132. gridSizer.Add(
  133. labelTimeUnit, pos=(0, 0),
  134. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  135. gridSizer.Add(self.choiceUnits, pos=(0, 1),
  136. flag=wx.ALIGN_CENTER | wx.EXPAND)
  137. gridSizer.Add(
  138. labelDuration, pos=(1, 0),
  139. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  140. gridSizer.Add(
  141. self.spinDurationTemp, pos=(
  142. 1, 1), flag=wx.ALIGN_CENTER | wx.EXPAND)
  143. gridSizer.Add(
  144. labelUnits, pos=(1, 2),
  145. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  146. gridSizer.AddGrowableCol(1)
  147. self.temporalSizer = gridSizer
  148. box.Add(
  149. gridSizer,
  150. proportion=1,
  151. border=5,
  152. flag=wx.ALL | wx.EXPAND)
  153. mainSizer.Add(
  154. box,
  155. proportion=0,
  156. flag=wx.EXPAND | wx.ALL,
  157. border=5)
  158. self.btnOk = Button(self, wx.ID_OK)
  159. self.btnApply = Button(self, wx.ID_APPLY)
  160. self.btnCancel = Button(self, wx.ID_CANCEL)
  161. self.btnOk.SetDefault()
  162. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  163. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  164. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  165. self.Bind(wx.EVT_CLOSE, self.OnCancel)
  166. # button sizer
  167. btnStdSizer = wx.StdDialogButtonSizer()
  168. btnStdSizer.AddButton(self.btnOk)
  169. btnStdSizer.AddButton(self.btnApply)
  170. btnStdSizer.AddButton(self.btnCancel)
  171. btnStdSizer.Realize()
  172. mainSizer.Add(btnStdSizer, proportion=0,
  173. flag=wx.EXPAND | wx.ALL, border=5)
  174. self.SetSizer(mainSizer)
  175. mainSizer.Fit(self)
  176. def _setTemporalMode(self):
  177. self.nontemporalBox.Enable(
  178. self.temporalMode == TemporalMode.NONTEMPORAL)
  179. self.temporalBox.Enable(self.temporalMode == TemporalMode.TEMPORAL)
  180. for child in self.temporalSizer.GetChildren():
  181. child.GetWindow().Enable(self.temporalMode == TemporalMode.TEMPORAL)
  182. for child in self.nontemporalSizer.GetChildren():
  183. child.GetWindow().Enable(self.temporalMode == TemporalMode.NONTEMPORAL)
  184. self.Layout()
  185. def _fillUnitChoice(self, choiceWidget):
  186. timeUnitsChoice = [
  187. _("year"),
  188. _("month"),
  189. _("day"),
  190. _("hour"),
  191. _("minute"),
  192. _("second")]
  193. timeUnits = ["years", "months", "days", "hours", "minutes", "seconds"]
  194. for item, cdata in zip(timeUnitsChoice, timeUnits):
  195. choiceWidget.Append(item, cdata)
  196. if self.temporalMode == TemporalMode.TEMPORAL:
  197. unit = self.timeGranularity[1]
  198. index = 0
  199. for i, timeUnit in enumerate(timeUnits):
  200. if timeUnit.startswith(unit):
  201. index = i
  202. break
  203. choiceWidget.SetSelection(index)
  204. else:
  205. choiceWidget.SetSelection(0)
  206. def OnOk(self, event):
  207. self._apply()
  208. self.OnCancel(None)
  209. def OnApply(self, event):
  210. self._apply()
  211. def OnCancel(self, event):
  212. self.spinDuration.SetValue(self.lastAppliedValue)
  213. self.spinDurationTemp.SetValue(self.lastAppliedValueTemp)
  214. self.Hide()
  215. def InitTimeSpin(self, timeTick):
  216. if self.temporalMode == TemporalMode.TEMPORAL:
  217. index = self.choiceUnits.GetSelection()
  218. unit = self.choiceUnits.GetClientData(index)
  219. delta = self._timedelta(unit=unit, number=1)
  220. seconds1 = self._total_seconds(delta)
  221. number, unit = self.timeGranularity
  222. number = float(number)
  223. delta = self._timedelta(unit=unit, number=number)
  224. seconds2 = self._total_seconds(delta)
  225. value = timeTick
  226. ms = value * seconds1 / float(seconds2)
  227. self.spinDurationTemp.SetValue(ms)
  228. else:
  229. self.spinDuration.SetValue(timeTick)
  230. def _apply(self):
  231. if self.temporalMode == TemporalMode.NONTEMPORAL:
  232. ms = self.spinDuration.GetValue()
  233. self.lastAppliedValue = self.spinDuration.GetValue()
  234. elif self.temporalMode == TemporalMode.TEMPORAL:
  235. index = self.choiceUnits.GetSelection()
  236. unit = self.choiceUnits.GetClientData(index)
  237. delta = self._timedelta(unit=unit, number=1)
  238. seconds1 = self._total_seconds(delta)
  239. number, unit = self.timeGranularity
  240. number = float(number)
  241. delta = self._timedelta(unit=unit, number=number)
  242. seconds2 = self._total_seconds(delta)
  243. value = self.spinDurationTemp.GetValue()
  244. ms = value * seconds2 / float(seconds1)
  245. # minimumDuration set to 0, too restrictive
  246. if ms < self.minimumDuration:
  247. GMessage(parent=self, message=_(
  248. "Animation speed is too high."))
  249. return
  250. self.lastAppliedValueTemp = self.spinDurationTemp.GetValue()
  251. else:
  252. return
  253. self.speedChanged.emit(ms=ms)
  254. def _timedelta(self, unit, number):
  255. if unit in "years":
  256. delta = datetime.timedelta(days=365.25 * number)
  257. elif unit in "months":
  258. delta = datetime.timedelta(days=30.4375 * number) # 365.25/12
  259. elif unit in "days":
  260. delta = datetime.timedelta(days=1 * number)
  261. elif unit in "hours":
  262. delta = datetime.timedelta(hours=1 * number)
  263. elif unit in "minutes":
  264. delta = datetime.timedelta(minutes=1 * number)
  265. elif unit in "seconds":
  266. delta = datetime.timedelta(seconds=1 * number)
  267. return delta
  268. def _total_seconds(self, delta):
  269. """timedelta.total_seconds is new in version 2.7.
  270. """
  271. return delta.seconds + delta.days * 24 * 3600
  272. class InputDialog(wx.Dialog):
  273. def __init__(self, parent, mode, animationData):
  274. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  275. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
  276. if mode == 'add':
  277. self.SetTitle(_("Add new animation"))
  278. elif mode == 'edit':
  279. self.SetTitle(_("Edit animation"))
  280. self.animationData = animationData
  281. self._tmpLegendCmd = None
  282. self._layout()
  283. self.OnViewMode(event=None)
  284. def _layout(self):
  285. self.notebook = wx.Notebook(parent=self, style=wx.BK_DEFAULT)
  286. sizer = wx.BoxSizer(wx.VERTICAL)
  287. self.notebook.AddPage(
  288. self._createGeneralPage(
  289. self.notebook),
  290. _("General"))
  291. self.notebook.AddPage(
  292. self._createAdvancedPage(
  293. self.notebook),
  294. _("Advanced"))
  295. sizer.Add(
  296. self.notebook,
  297. proportion=1,
  298. flag=wx.ALL | wx.EXPAND,
  299. border=3)
  300. # buttons
  301. self.btnOk = Button(self, wx.ID_OK)
  302. self.btnCancel = Button(self, wx.ID_CANCEL)
  303. self.btnOk.SetDefault()
  304. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  305. # button sizer
  306. btnStdSizer = wx.StdDialogButtonSizer()
  307. btnStdSizer.AddButton(self.btnOk)
  308. btnStdSizer.AddButton(self.btnCancel)
  309. btnStdSizer.Realize()
  310. sizer.Add(btnStdSizer, proportion=0,
  311. flag=wx.EXPAND | wx.ALL, border=5)
  312. self.SetSizer(sizer)
  313. sizer.Fit(self)
  314. def _createGeneralPage(self, parent):
  315. panel = wx.Panel(parent=parent)
  316. mainSizer = wx.BoxSizer(wx.VERTICAL)
  317. self.windowChoice = wx.Choice(
  318. panel,
  319. id=wx.ID_ANY,
  320. choices=[
  321. _("top left"),
  322. _("top right"),
  323. _("bottom left"),
  324. _("bottom right")])
  325. self.windowChoice.SetSelection(self.animationData.windowIndex)
  326. self.nameCtrl = TextCtrl(
  327. panel, id=wx.ID_ANY, value=self.animationData.name)
  328. self.nDChoice = Choice(panel, id=wx.ID_ANY)
  329. mode = self.animationData.viewMode
  330. index = 0
  331. for i, (viewMode, viewModeName) in enumerate(
  332. self.animationData.viewModes):
  333. self.nDChoice.Append(viewModeName, clientData=viewMode)
  334. if mode == viewMode:
  335. index = i
  336. self.nDChoice.SetSelection(index)
  337. self.nDChoice.SetToolTip(_("Select 2D or 3D view"))
  338. self.nDChoice.Bind(wx.EVT_CHOICE, self.OnViewMode)
  339. gridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  340. gridSizer.Add(
  341. StaticText(
  342. panel,
  343. id=wx.ID_ANY,
  344. label=_("Name:")),
  345. flag=wx.ALIGN_CENTER_VERTICAL)
  346. gridSizer.Add(self.nameCtrl, proportion=1, flag=wx.EXPAND)
  347. gridSizer.Add(
  348. StaticText(
  349. panel,
  350. id=wx.ID_ANY,
  351. label=_("Window position:")),
  352. flag=wx.ALIGN_CENTER_VERTICAL)
  353. gridSizer.Add(
  354. self.windowChoice,
  355. proportion=1,
  356. flag=wx.ALIGN_RIGHT)
  357. gridSizer.Add(
  358. StaticText(
  359. panel,
  360. id=wx.ID_ANY,
  361. label=_("View mode:")),
  362. flag=wx.ALIGN_CENTER_VERTICAL)
  363. gridSizer.Add(self.nDChoice, proportion=1, flag=wx.ALIGN_RIGHT)
  364. gridSizer.AddGrowableCol(0, 1)
  365. gridSizer.AddGrowableCol(1, 1)
  366. mainSizer.Add(
  367. gridSizer,
  368. proportion=0,
  369. flag=wx.ALL | wx.EXPAND,
  370. border=5)
  371. label = _(
  372. "For 3D animation, please select only one space-time dataset\n"
  373. "or one series of map layers.")
  374. self.warning3DLayers = StaticText(panel, label=label)
  375. self.warning3DLayers.SetForegroundColour(
  376. wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
  377. mainSizer.Add(
  378. self.warning3DLayers,
  379. proportion=0,
  380. flag=wx.EXPAND | wx.LEFT,
  381. border=5)
  382. self.dataPanel = self._createDataPanel(panel)
  383. self.threeDPanel = self._create3DPanel(panel)
  384. mainSizer.Add(
  385. self.dataPanel,
  386. proportion=1,
  387. flag=wx.EXPAND | wx.ALL,
  388. border=3)
  389. mainSizer.Add(
  390. self.threeDPanel,
  391. proportion=0,
  392. flag=wx.EXPAND | wx.ALL,
  393. border=3)
  394. panel.SetSizer(mainSizer)
  395. mainSizer.Fit(panel)
  396. return panel
  397. def _createDataPanel(self, parent):
  398. panel = wx.Panel(parent)
  399. slmgrSizer = wx.BoxSizer(wx.VERTICAL)
  400. self._layerList = copy.deepcopy(self.animationData.layerList)
  401. self.simpleLmgr = AnimSimpleLayerManager(parent=panel,
  402. layerList=self._layerList,
  403. modal=True)
  404. self.simpleLmgr.SetMinSize((globalvar.DIALOG_GSELECT_SIZE[0], 80))
  405. slmgrSizer.Add(
  406. self.simpleLmgr,
  407. proportion=1,
  408. flag=wx.EXPAND | wx.ALL,
  409. border=5)
  410. self.legend = wx.CheckBox(panel, label=_("Show raster legend"))
  411. self.legend.SetValue(bool(self.animationData.legendCmd))
  412. self.legendBtn = Button(panel, label=_("Set options"))
  413. self.legend.Bind(wx.EVT_CHECKBOX, self.OnLegend)
  414. self.legendBtn.Bind(wx.EVT_BUTTON, self.OnLegendProperties)
  415. hbox = wx.BoxSizer(wx.HORIZONTAL)
  416. hbox.Add(self.legend, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
  417. hbox.Add(self.legendBtn, proportion=0, flag=wx.LEFT, border=5)
  418. slmgrSizer.Add(
  419. hbox,
  420. proportion=0,
  421. flag=wx.EXPAND | wx.ALL,
  422. border=3)
  423. panel.SetSizerAndFit(slmgrSizer)
  424. panel.SetAutoLayout(True)
  425. return panel
  426. def _create3DPanel(self, parent):
  427. panel = wx.Panel(parent, id=wx.ID_ANY)
  428. dataStBox = StaticBox(parent=panel, id=wx.ID_ANY,
  429. label=' %s ' % _("3D view parameters"))
  430. dataBoxSizer = wx.StaticBoxSizer(dataStBox, wx.VERTICAL)
  431. # workspace file
  432. self.fileSelector = filebrowse.FileBrowseButton(
  433. parent=panel,
  434. id=wx.ID_ANY,
  435. size=globalvar.DIALOG_GSELECT_SIZE,
  436. labelText=_("Workspace file:"),
  437. dialogTitle=_(
  438. "Choose workspace file to "
  439. "import 3D view parameters"),
  440. buttonText=_('Browse'),
  441. startDirectory=os.getcwd(),
  442. fileMode=0,
  443. fileMask="GRASS Workspace File (*.gxw)|*.gxw")
  444. if self.animationData.workspaceFile:
  445. self.fileSelector.SetValue(self.animationData.workspaceFile)
  446. self.paramLabel = StaticText(
  447. panel, wx.ID_ANY, label=_("Parameter for animation:"))
  448. self.paramChoice = wx.Choice(
  449. panel, id=wx.ID_ANY, choices=self.animationData.nvizParameters)
  450. self.paramChoice.SetStringSelection(self.animationData.nvizParameter)
  451. hbox = wx.BoxSizer(wx.HORIZONTAL)
  452. hbox.Add(
  453. self.fileSelector,
  454. proportion=1,
  455. flag=wx.EXPAND)
  456. dataBoxSizer.Add(
  457. hbox,
  458. proportion=0,
  459. flag=wx.EXPAND | wx.ALL,
  460. border=3)
  461. hbox = wx.BoxSizer(wx.HORIZONTAL)
  462. hbox.Add(
  463. self.paramLabel,
  464. proportion=1,
  465. flag=wx.ALIGN_CENTER_VERTICAL)
  466. hbox.Add(self.paramChoice, proportion=1, flag=wx.EXPAND)
  467. dataBoxSizer.Add(
  468. hbox,
  469. proportion=0,
  470. flag=wx.EXPAND | wx.ALL,
  471. border=3)
  472. panel.SetSizerAndFit(dataBoxSizer)
  473. panel.SetAutoLayout(True)
  474. return panel
  475. def _createAdvancedPage(self, parent):
  476. panel = wx.Panel(parent=parent)
  477. mainSizer = wx.BoxSizer(wx.VERTICAL)
  478. box = StaticBox(
  479. parent=panel, label=" %s " %
  480. _("Set spatial extent in 2D view"))
  481. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  482. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  483. self.stRegionLabel = StaticText(panel, label=_("Use saved region:"))
  484. gridSizer.Add(self.stRegionLabel,
  485. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  486. self.stRegion = Select(parent=panel, type='region', size=(200, -1))
  487. if self.animationData.startRegion:
  488. self.stRegion.SetValue(self.animationData.startRegion)
  489. gridSizer.Add(
  490. self.stRegion, pos=(0, 1),
  491. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  492. self.animateRegionCheckbox = CheckBox(panel, label=_("Animate region change"))
  493. self.animateRegionCheckbox.SetValue(False)
  494. gridSizer.Add(self.animateRegionCheckbox, pos=(1, 0), span=(1, 2), flag=wx.EXPAND)
  495. self.animateRegionCheckbox.Bind(wx.EVT_CHECKBOX, lambda evt: self._onAnimateExtent())
  496. self.endRegRadio = RadioButton(
  497. panel, label=_("End region:"), style=wx.RB_GROUP)
  498. gridSizer.Add(self.endRegRadio, pos=(2, 0), border=10, flag=wx.EXPAND | wx.LEFT)
  499. self.endRegion = Select(parent=panel, type='region', size=(200, -1))
  500. gridSizer.Add(
  501. self.endRegion, pos=(2, 1),
  502. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  503. self.zoomRadio = RadioButton(panel, label=_("Zoom value:"))
  504. self.zoomRadio.SetToolTip(_("N-S/E-W distances in map units used to "
  505. "gradually reduce region."))
  506. gridSizer.Add(self.zoomRadio, pos=(3, 0), border=10, flag=wx.EXPAND | wx.LEFT)
  507. zoomSizer = wx.BoxSizer(wx.HORIZONTAL)
  508. self.zoomNS = TextCtrl(panel, validator=FloatValidator())
  509. self.zoomEW = TextCtrl(panel, validator=FloatValidator())
  510. zoomSizer.Add(StaticText(panel, label=_("N-S:")), proportion=0,
  511. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  512. zoomSizer.Add(self.zoomNS, proportion=1, flag=wx.LEFT, border=3)
  513. zoomSizer.Add(StaticText(panel, label=_("E-W:")), proportion=0,
  514. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  515. zoomSizer.Add(self.zoomEW, proportion=1, flag=wx.LEFT, border=3)
  516. gridSizer.Add(
  517. zoomSizer, pos=(3, 1),
  518. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  519. if self.animationData.endRegion:
  520. self.animateRegionCheckbox.SetValue(True)
  521. self.endRegRadio.SetValue(True)
  522. self.zoomRadio.SetValue(False)
  523. self.endRegion.SetValue(self.animationData.endRegion)
  524. if self.animationData.zoomRegionValue:
  525. self.animateRegionCheckbox.SetValue(True)
  526. self.endRegRadio.SetValue(False)
  527. self.zoomRadio.SetValue(True)
  528. zoom = self.animationData.zoomRegionValue
  529. self.zoomNS.SetValue(str(zoom[0]))
  530. self.zoomEW.SetValue(str(zoom[1]))
  531. self.endRegRadio.Bind(
  532. wx.EVT_RADIOBUTTON,
  533. lambda evt: self._enableRegionWidgets())
  534. self.zoomRadio.Bind(
  535. wx.EVT_RADIOBUTTON,
  536. lambda evt: self._enableRegionWidgets())
  537. self._onAnimateExtent()
  538. gridSizer.AddGrowableCol(1)
  539. sizer.Add(gridSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  540. mainSizer.Add(sizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  541. panel.SetSizer(mainSizer)
  542. mainSizer.Fit(panel)
  543. return panel
  544. def _onAnimateExtent(self):
  545. checked = self.animateRegionCheckbox.IsChecked()
  546. self.endRegion.Enable(checked)
  547. self.zoomNS.Enable(checked)
  548. self.zoomEW.Enable(checked)
  549. self.zoomRadio.Enable(checked)
  550. self.endRegRadio.Enable(checked)
  551. if checked:
  552. self._enableRegionWidgets()
  553. def _enableRegionWidgets(self):
  554. """Enables/disables region widgets
  555. according to which radiobutton is active."""
  556. endReg = self.endRegRadio.GetValue()
  557. self.endRegion.Enable(endReg)
  558. self.zoomNS.Enable(not endReg)
  559. self.zoomEW.Enable(not endReg)
  560. def OnViewMode(self, event):
  561. mode = self.nDChoice.GetSelection()
  562. self.Freeze()
  563. self.simpleLmgr.Activate3D(mode == 1)
  564. self.warning3DLayers.Show(mode == 1)
  565. # disable region widgets for 3d
  566. regSizer = self.stRegion.GetContainingSizer()
  567. for child in regSizer.GetChildren():
  568. if child.IsSizer():
  569. for child_ in child.GetSizer().GetChildren():
  570. child_.GetWindow().Enable(mode != 1)
  571. elif child.IsWindow():
  572. child.GetWindow().Enable(mode != 1)
  573. if mode == 0:
  574. self._onAnimateExtent()
  575. # update layout
  576. sizer = self.threeDPanel.GetContainingSizer()
  577. sizer.Show(self.threeDPanel, mode == 1, True)
  578. sizer.Layout()
  579. self.Thaw()
  580. def OnLegend(self, event):
  581. if not self.legend.IsChecked():
  582. return
  583. if self._tmpLegendCmd or self.animationData.legendCmd:
  584. return
  585. cmd = ['d.legend', 'at=5,50,2,5']
  586. GUI(parent=self, modal=True).ParseCommand(
  587. cmd=cmd, completed=(self.GetOptData, '', ''))
  588. def OnLegendProperties(self, event):
  589. """Set options for legend"""
  590. if self._tmpLegendCmd:
  591. cmd = self._tmpLegendCmd
  592. elif self.animationData.legendCmd:
  593. cmd = self.animationData.legendCmd
  594. else:
  595. cmd = ['d.legend', 'at=5,50,2,5']
  596. GUI(parent=self, modal=True).ParseCommand(
  597. cmd=cmd, completed=(self.GetOptData, '', ''))
  598. def GetOptData(self, dcmd, layer, params, propwin):
  599. """Process decoration layer data"""
  600. if dcmd:
  601. self._tmpLegendCmd = dcmd
  602. if not self.legend.IsChecked():
  603. self.legend.SetValue(True)
  604. else:
  605. if not self._tmpLegendCmd and not self.animationData.legendCmd:
  606. self.legend.SetValue(False)
  607. def _update(self):
  608. if self.nDChoice.GetSelection() == 1 and len(self._layerList) > 1:
  609. raise GException(_("Only one series or space-time "
  610. "dataset is accepted for 3D mode."))
  611. hasSeries = False
  612. for layer in self._layerList:
  613. if layer.active and hasattr(layer, 'maps'):
  614. hasSeries = True
  615. break
  616. if not hasSeries:
  617. raise GException(_("No map series or space-time dataset added."))
  618. self.animationData.layerList = self._layerList
  619. self.animationData.name = self.nameCtrl.GetValue()
  620. self.animationData.windowIndex = self.windowChoice.GetSelection()
  621. sel = self.nDChoice.GetSelection()
  622. self.animationData.viewMode = self.nDChoice.GetClientData(sel)
  623. self.animationData.legendCmd = None
  624. if self._tmpLegendCmd:
  625. if self.legend.IsChecked():
  626. self.animationData.legendCmd = self._tmpLegendCmd
  627. if self.threeDPanel.IsShown():
  628. self.animationData.workspaceFile = self.fileSelector.GetValue()
  629. if self.threeDPanel.IsShown():
  630. self.animationData.nvizParameter = self.paramChoice.GetStringSelection()
  631. # region (2d only)
  632. if self.animationData.viewMode == '3d':
  633. self.animationData.startRegion = None
  634. self.animationData.endRegion = None
  635. self.animationData.zoomRegionValue = None
  636. return
  637. isEnd = self.endRegRadio.GetValue() and self.endRegion.GetValue()
  638. isZoom = self.zoomRadio.GetValue() and self.zoomNS.GetValue() and self.zoomEW.GetValue()
  639. isStart = self.stRegion.GetValue()
  640. useAnim = self.animateRegionCheckbox.GetValue()
  641. self.animationData.startRegion = None
  642. self.animationData.endRegion = None
  643. self.animationData.zoomRegionValue = None
  644. if not useAnim:
  645. if isStart:
  646. self.animationData.startRegion = isStart
  647. else:
  648. if isStart:
  649. self.animationData.startRegion = isStart
  650. else:
  651. raise GException(_("Region information is not complete"))
  652. if isEnd:
  653. self.animationData.endRegion = self.endRegion.GetValue()
  654. self.animationData.zoomRegionValue = None
  655. elif isZoom:
  656. self.animationData.zoomRegionValue = (
  657. float(self.zoomNS.GetValue()),
  658. float(self.zoomEW.GetValue()))
  659. self.animationData.endRegion = None
  660. else:
  661. raise GException(_("Region information is not complete"))
  662. def UnInit(self):
  663. self.simpleLmgr.UnInit()
  664. def OnOk(self, event):
  665. try:
  666. self._update()
  667. self.UnInit()
  668. self.EndModal(wx.ID_OK)
  669. except (GException, ValueError, IOError) as e:
  670. GError(
  671. message=str(e),
  672. showTraceback=False,
  673. caption=_("Invalid input"))
  674. class EditDialog(wx.Dialog):
  675. def __init__(self, parent, evalFunction, animationData, maxAnimations):
  676. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  677. style=wx.DEFAULT_DIALOG_STYLE)
  678. self.animationData = copy.deepcopy(animationData)
  679. self.eval = evalFunction
  680. self.SetTitle(_("Add, edit or remove animations"))
  681. self._layout()
  682. self.SetSize((300, -1))
  683. self.maxAnimations = maxAnimations
  684. self.result = None
  685. def _layout(self):
  686. mainSizer = wx.BoxSizer(wx.VERTICAL)
  687. box = StaticBox(
  688. parent=self,
  689. id=wx.ID_ANY,
  690. label=" %s " %
  691. _("List of animations"))
  692. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  693. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  694. gridBagSizer.AddGrowableCol(0)
  695. # gridBagSizer.AddGrowableCol(1,1)
  696. self.listbox = wx.ListBox(
  697. self, id=wx.ID_ANY, choices=[],
  698. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  699. self.listbox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnEdit)
  700. self.addButton = Button(self, id=wx.ID_ANY, label=_("Add"))
  701. self.addButton.Bind(wx.EVT_BUTTON, self.OnAdd)
  702. self.editButton = Button(self, id=wx.ID_ANY, label=_("Edit"))
  703. self.editButton.Bind(wx.EVT_BUTTON, self.OnEdit)
  704. self.removeButton = Button(self, id=wx.ID_ANY, label=_("Remove"))
  705. self.removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  706. self._updateListBox()
  707. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(3, 1),
  708. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  709. gridBagSizer.Add(self.addButton, pos=(0, 1),
  710. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  711. gridBagSizer.Add(self.editButton, pos=(1, 1),
  712. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  713. gridBagSizer.Add(self.removeButton, pos=(2, 1),
  714. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  715. sizer.Add(
  716. gridBagSizer,
  717. proportion=0,
  718. flag=wx.ALL | wx.EXPAND,
  719. border=5)
  720. mainSizer.Add(sizer, proportion=0,
  721. flag=wx.EXPAND | wx.ALL, border=5)
  722. # buttons
  723. self.btnOk = Button(self, wx.ID_OK)
  724. self.btnCancel = Button(self, wx.ID_CANCEL)
  725. self.btnOk.SetDefault()
  726. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  727. # button sizer
  728. btnStdSizer = wx.StdDialogButtonSizer()
  729. btnStdSizer.AddButton(self.btnOk)
  730. btnStdSizer.AddButton(self.btnCancel)
  731. btnStdSizer.Realize()
  732. mainSizer.Add(btnStdSizer, proportion=0,
  733. flag=wx.EXPAND | wx.ALL, border=5)
  734. self.SetSizer(mainSizer)
  735. mainSizer.Fit(self)
  736. def _updateListBox(self):
  737. self.listbox.Clear()
  738. for anim in self.animationData:
  739. self.listbox.Append(anim.name, clientData=anim)
  740. if self.animationData:
  741. self.listbox.SetSelection(0)
  742. def _getNextIndex(self):
  743. indices = [anim.windowIndex for anim in self.animationData]
  744. for i in range(self.maxAnimations):
  745. if i not in indices:
  746. return i
  747. return None
  748. def OnAdd(self, event):
  749. windowIndex = self._getNextIndex()
  750. if windowIndex is None:
  751. GMessage(
  752. self,
  753. message=_("Maximum number of animations is %d.") %
  754. self.maxAnimations)
  755. return
  756. animData = AnimationData()
  757. # number of active animations
  758. animationIndex = len(self.animationData)
  759. animData.SetDefaultValues(windowIndex, animationIndex)
  760. dlg = InputDialog(parent=self, mode='add', animationData=animData)
  761. dlg.CenterOnParent()
  762. if dlg.ShowModal() == wx.ID_CANCEL:
  763. dlg.UnInit()
  764. dlg.Destroy()
  765. return
  766. dlg.Destroy()
  767. self.animationData.append(animData)
  768. self._updateListBox()
  769. def OnEdit(self, event):
  770. index = self.listbox.GetSelection()
  771. if index == wx.NOT_FOUND:
  772. return
  773. animData = self.listbox.GetClientData(index)
  774. dlg = InputDialog(parent=self, mode='edit', animationData=animData)
  775. dlg.CenterOnParent()
  776. if dlg.ShowModal() == wx.ID_CANCEL:
  777. dlg.UnInit()
  778. dlg.Destroy()
  779. return
  780. dlg.Destroy()
  781. self._updateListBox()
  782. def OnRemove(self, event):
  783. index = self.listbox.GetSelection()
  784. if index == wx.NOT_FOUND:
  785. return
  786. animData = self.listbox.GetClientData(index)
  787. self.animationData.remove(animData)
  788. self._updateListBox()
  789. def GetResult(self):
  790. return self.result
  791. def OnOk(self, event):
  792. indices = set([anim.windowIndex for anim in self.animationData])
  793. if len(indices) != len(self.animationData):
  794. GError(
  795. parent=self, message=_(
  796. "More animations are using one window."
  797. " Please select different window for each animation."))
  798. return
  799. try:
  800. temporalMode, tempManager = self.eval(self.animationData)
  801. except GException as e:
  802. GError(parent=self, message=e.value, showTraceback=False)
  803. return
  804. self.result = (self.animationData, temporalMode, tempManager)
  805. self.EndModal(wx.ID_OK)
  806. class ExportDialog(wx.Dialog):
  807. def __init__(self, parent, temporal, timeTick):
  808. wx.Dialog.__init__(
  809. self,
  810. parent=parent,
  811. id=wx.ID_ANY,
  812. title=_("Export animation"),
  813. style=wx.DEFAULT_DIALOG_STYLE)
  814. self.decorations = []
  815. self.temporal = temporal
  816. self.timeTick = timeTick
  817. self._layout()
  818. # export animation
  819. self.doExport = Signal('ExportDialog::doExport')
  820. wx.CallAfter(self._hideAll)
  821. def _layout(self):
  822. notebook = wx.Notebook(self, id=wx.ID_ANY)
  823. mainSizer = wx.BoxSizer(wx.VERTICAL)
  824. notebook.AddPage(
  825. page=self._createExportFormatPanel(notebook),
  826. text=_("Format"))
  827. notebook.AddPage(
  828. page=self._createDecorationsPanel(notebook),
  829. text=_("Decorations"))
  830. mainSizer.Add(notebook, proportion=0,
  831. flag=wx.EXPAND | wx.ALL, border=5)
  832. self.btnExport = Button(self, wx.ID_OK)
  833. self.btnExport.SetLabel(_("Export"))
  834. self.btnCancel = Button(self, wx.ID_CANCEL)
  835. self.btnExport.SetDefault()
  836. self.btnExport.Bind(wx.EVT_BUTTON, self.OnExport)
  837. # button sizer
  838. btnStdSizer = wx.StdDialogButtonSizer()
  839. btnStdSizer.AddButton(self.btnExport)
  840. btnStdSizer.AddButton(self.btnCancel)
  841. btnStdSizer.Realize()
  842. mainSizer.Add(btnStdSizer, proportion=0,
  843. flag=wx.EXPAND | wx.ALL, border=5)
  844. self.SetSizer(mainSizer)
  845. # set the longest option to fit
  846. self.hidevbox.Show(self.fontBox, True)
  847. self.hidevbox.Show(self.imageBox, False)
  848. self.hidevbox.Show(self.textBox, True)
  849. self.hidevbox.Show(self.posBox, True)
  850. self.hidevbox.Show(self.informBox, False)
  851. mainSizer.Fit(self)
  852. def _createDecorationsPanel(self, notebook):
  853. panel = wx.Panel(notebook, id=wx.ID_ANY)
  854. sizer = wx.BoxSizer(wx.VERTICAL)
  855. sizer.Add(
  856. self._createDecorationsList(panel),
  857. proportion=0,
  858. flag=wx.ALL | wx.EXPAND,
  859. border=10)
  860. sizer.Add(
  861. self._createDecorationsProperties(panel),
  862. proportion=0,
  863. flag=wx.ALL | wx.EXPAND,
  864. border=10)
  865. panel.SetSizer(sizer)
  866. sizer.Fit(panel)
  867. return panel
  868. def _createDecorationsList(self, panel):
  869. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  870. gridBagSizer.AddGrowableCol(0)
  871. self.listbox = wx.ListBox(panel, id=wx.ID_ANY, choices=[],
  872. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  873. self.listbox.Bind(wx.EVT_LISTBOX, self.OnSelectionChanged)
  874. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(4, 1),
  875. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  876. buttonNames = ['time', 'image', 'text']
  877. buttonLabels = [_("Add time stamp"), _("Add image"), _("Add text")]
  878. i = 0
  879. for buttonName, buttonLabel in zip(buttonNames, buttonLabels):
  880. if buttonName == 'time' and self.temporal == TemporalMode.NONTEMPORAL:
  881. continue
  882. btn = Button(
  883. panel,
  884. id=wx.ID_ANY,
  885. name=buttonName,
  886. label=buttonLabel)
  887. btn.Bind(
  888. wx.EVT_BUTTON,
  889. lambda evt,
  890. temp=buttonName: self.OnAddDecoration(
  891. evt,
  892. temp))
  893. gridBagSizer.Add(
  894. btn,
  895. pos=(
  896. i,
  897. 1),
  898. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  899. border=0)
  900. i += 1
  901. removeButton = Button(panel, id=wx.ID_ANY, label=_("Remove"))
  902. removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  903. gridBagSizer.Add(
  904. removeButton,
  905. pos=(
  906. i,
  907. 1),
  908. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  909. border=0)
  910. return gridBagSizer
  911. def _createDecorationsProperties(self, panel):
  912. self.hidevbox = wx.BoxSizer(wx.VERTICAL)
  913. # inform label
  914. self.informBox = wx.BoxSizer(wx.HORIZONTAL)
  915. if self.temporal == TemporalMode.TEMPORAL:
  916. label = _(
  917. "Add time stamp, image or text decoration by one of the buttons above.")
  918. else:
  919. label = _("Add image or text decoration by one of the buttons above.")
  920. label = StaticText(panel, id=wx.ID_ANY, label=label)
  921. label.Wrap(400)
  922. self.informBox.Add(
  923. label,
  924. proportion=1,
  925. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  926. border=5)
  927. self.hidevbox.Add(
  928. self.informBox,
  929. proportion=0,
  930. flag=wx.EXPAND | wx.BOTTOM,
  931. border=5)
  932. # font
  933. self.fontBox = wx.BoxSizer(wx.HORIZONTAL)
  934. self.fontBox.Add(
  935. StaticText(
  936. panel,
  937. id=wx.ID_ANY,
  938. label=_("Font settings:")),
  939. proportion=0,
  940. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  941. border=5)
  942. self.sampleLabel = StaticText(
  943. panel, id=wx.ID_ANY, label=_("Sample text"))
  944. self.fontBox.Add(self.sampleLabel, proportion=1,
  945. flag=wx.ALIGN_CENTER | wx.RIGHT | wx.LEFT, border=5)
  946. fontButton = Button(panel, id=wx.ID_ANY, label=_("Set font"))
  947. fontButton.Bind(wx.EVT_BUTTON, self.OnFont)
  948. self.fontBox.Add(
  949. fontButton,
  950. proportion=0,
  951. flag=wx.ALIGN_CENTER_VERTICAL)
  952. self.hidevbox.Add(
  953. self.fontBox,
  954. proportion=0,
  955. flag=wx.EXPAND | wx.BOTTOM,
  956. border=5)
  957. # image
  958. self.imageBox = wx.BoxSizer(wx.HORIZONTAL)
  959. filetype, ltype = GetImageHandlers(EmptyImage(10, 10))
  960. self.browse = filebrowse.FileBrowseButton(
  961. parent=panel, id=wx.ID_ANY, fileMask=filetype,
  962. labelText=_("Image file:"),
  963. dialogTitle=_('Choose image file'),
  964. buttonText=_('Browse'),
  965. startDirectory=os.getcwd(),
  966. fileMode=wx.FD_OPEN, changeCallback=self.OnSetImage)
  967. self.imageBox.Add(self.browse, proportion=1, flag=wx.EXPAND)
  968. self.hidevbox.Add(
  969. self.imageBox,
  970. proportion=0,
  971. flag=wx.EXPAND | wx.BOTTOM,
  972. border=5)
  973. # text
  974. self.textBox = wx.BoxSizer(wx.HORIZONTAL)
  975. self.textBox.Add(
  976. StaticText(
  977. panel,
  978. id=wx.ID_ANY,
  979. label=_("Text:")),
  980. proportion=0,
  981. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  982. border=5)
  983. self.textCtrl = TextCtrl(panel, id=wx.ID_ANY)
  984. self.textCtrl.Bind(wx.EVT_TEXT, self.OnText)
  985. self.textBox.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
  986. self.hidevbox.Add(self.textBox, proportion=0, flag=wx.EXPAND)
  987. self.posBox = self._positionWidget(panel)
  988. self.hidevbox.Add(
  989. self.posBox,
  990. proportion=0,
  991. flag=wx.EXPAND | wx.TOP,
  992. border=5)
  993. return self.hidevbox
  994. def _positionWidget(self, panel):
  995. grid = wx.GridBagSizer(vgap=5, hgap=5)
  996. label = StaticText(
  997. panel, id=wx.ID_ANY, label=_(
  998. "Placement as percentage of"
  999. " screen coordinates (X: 0, Y: 0 is top left):"))
  1000. label.Wrap(400)
  1001. self.spinX = SpinCtrl(
  1002. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  1003. self.spinY = SpinCtrl(
  1004. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  1005. self.spinX.Bind(
  1006. wx.EVT_SPINCTRL,
  1007. lambda evt,
  1008. temp='X': self.OnPosition(
  1009. evt,
  1010. temp))
  1011. self.spinY.Bind(
  1012. wx.EVT_SPINCTRL,
  1013. lambda evt,
  1014. temp='Y': self.OnPosition(
  1015. evt,
  1016. temp))
  1017. grid.Add(label, pos=(0, 0), span=(1, 4), flag=wx.EXPAND)
  1018. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("X:")), pos=(1, 0),
  1019. flag=wx.ALIGN_CENTER_VERTICAL)
  1020. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("Y:")), pos=(1, 2),
  1021. flag=wx.ALIGN_CENTER_VERTICAL)
  1022. grid.Add(self.spinX, pos=(1, 1))
  1023. grid.Add(self.spinY, pos=(1, 3))
  1024. return grid
  1025. def _createExportFormatPanel(self, notebook):
  1026. panel = wx.Panel(notebook, id=wx.ID_ANY)
  1027. borderSizer = wx.BoxSizer(wx.VERTICAL)
  1028. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1029. choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
  1030. self.formatChoice = wx.Choice(parent=panel, id=wx.ID_ANY,
  1031. choices=choices)
  1032. self.formatChoice.Bind(
  1033. wx.EVT_CHOICE,
  1034. lambda event: self.ChangeFormat(
  1035. event.GetSelection()))
  1036. hSizer.Add(
  1037. StaticText(
  1038. panel,
  1039. id=wx.ID_ANY,
  1040. label=_("Export to:")),
  1041. proportion=0,
  1042. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1043. border=2)
  1044. hSizer.Add(
  1045. self.formatChoice,
  1046. proportion=1,
  1047. flag=wx.EXPAND | wx.ALL,
  1048. border=2)
  1049. borderSizer.Add(
  1050. hSizer,
  1051. proportion=0,
  1052. flag=wx.EXPAND | wx.ALL,
  1053. border=3)
  1054. helpSizer = wx.BoxSizer(wx.HORIZONTAL)
  1055. helpSizer.AddStretchSpacer(1)
  1056. self.formatPanelSizer = wx.BoxSizer(wx.VERTICAL)
  1057. helpSizer.Add(self.formatPanelSizer, proportion=5, flag=wx.EXPAND)
  1058. borderSizer.Add(helpSizer, proportion=1, flag=wx.EXPAND)
  1059. self.formatPanels = []
  1060. # panel for image sequence
  1061. imSeqPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1062. prefixLabel = StaticText(
  1063. imSeqPanel, id=wx.ID_ANY, label=_("File prefix:"))
  1064. self.prefixCtrl = TextCtrl(
  1065. imSeqPanel, id=wx.ID_ANY, value=_("animation_"))
  1066. formatLabel = StaticText(
  1067. imSeqPanel, id=wx.ID_ANY, label=_("File format:"))
  1068. imageTypes = ['PNG', 'JPEG', 'GIF', 'TIFF', 'PPM', 'BMP']
  1069. self.imSeqFormatChoice = wx.Choice(imSeqPanel, choices=imageTypes)
  1070. self.imSeqFormatChoice.SetSelection(0)
  1071. self.dirBrowse = filebrowse.DirBrowseButton(
  1072. parent=imSeqPanel, id=wx.ID_ANY, labelText=_("Directory:"),
  1073. dialogTitle=_("Choose directory for export"),
  1074. buttonText=_("Browse"),
  1075. startDirectory=os.getcwd())
  1076. dirGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1077. dirGridSizer.Add(
  1078. prefixLabel, pos=(0, 0),
  1079. flag=wx.ALIGN_CENTER_VERTICAL)
  1080. dirGridSizer.Add(self.prefixCtrl, pos=(0, 1), flag=wx.EXPAND)
  1081. dirGridSizer.Add(
  1082. formatLabel, pos=(1, 0),
  1083. flag=wx.ALIGN_CENTER_VERTICAL)
  1084. dirGridSizer.Add(self.imSeqFormatChoice, pos=(1, 1), flag=wx.EXPAND)
  1085. dirGridSizer.Add(
  1086. self.dirBrowse, pos=(
  1087. 2, 0), flag=wx.EXPAND, span=(
  1088. 1, 2))
  1089. dirGridSizer.AddGrowableCol(1)
  1090. imSeqPanel.SetSizer(dirGridSizer)
  1091. dirGridSizer.Fit(imSeqPanel)
  1092. self.formatPanelSizer.Add(
  1093. imSeqPanel,
  1094. proportion=1,
  1095. flag=wx.EXPAND | wx.ALL,
  1096. border=5)
  1097. self.formatPanels.append(imSeqPanel)
  1098. # panel for gif
  1099. gifPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1100. self.gifBrowse = filebrowse.FileBrowseButton(
  1101. parent=gifPanel,
  1102. id=wx.ID_ANY,
  1103. fileMask="GIF file (*.gif)|*.gif",
  1104. labelText=_("GIF file:"),
  1105. dialogTitle=_("Choose file to save animation"),
  1106. buttonText=_("Browse"),
  1107. startDirectory=os.getcwd(),
  1108. fileMode=wx.FD_SAVE)
  1109. gifGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1110. gifGridSizer.AddGrowableCol(0)
  1111. gifGridSizer.Add(self.gifBrowse, pos=(0, 0), flag=wx.EXPAND)
  1112. gifPanel.SetSizer(gifGridSizer)
  1113. gifGridSizer.Fit(gifPanel)
  1114. self.formatPanelSizer.Add(
  1115. gifPanel,
  1116. proportion=1,
  1117. flag=wx.EXPAND | wx.ALL,
  1118. border=5)
  1119. self.formatPanels.append(gifPanel)
  1120. # panel for swf
  1121. swfPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1122. self.swfBrowse = filebrowse.FileBrowseButton(
  1123. parent=swfPanel,
  1124. id=wx.ID_ANY,
  1125. fileMask="SWF file (*.swf)|*.swf",
  1126. labelText=_("SWF file:"),
  1127. dialogTitle=_("Choose file to save animation"),
  1128. buttonText=_("Browse"),
  1129. startDirectory=os.getcwd(),
  1130. fileMode=wx.FD_SAVE)
  1131. swfGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1132. swfGridSizer.AddGrowableCol(0)
  1133. swfGridSizer.Add(self.swfBrowse, pos=(0, 0), flag=wx.EXPAND)
  1134. swfPanel.SetSizer(swfGridSizer)
  1135. swfGridSizer.Fit(swfPanel)
  1136. self.formatPanelSizer.Add(
  1137. swfPanel,
  1138. proportion=1,
  1139. flag=wx.EXPAND | wx.ALL,
  1140. border=5)
  1141. self.formatPanels.append(swfPanel)
  1142. # panel for avi
  1143. aviPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1144. ffmpeg = gcore.find_program('ffmpeg', '--help')
  1145. if not ffmpeg:
  1146. warning = _(
  1147. "Program 'ffmpeg' was not found.\nPlease install it first "
  1148. "and make sure\nit's in the PATH variable.")
  1149. warningLabel = StaticText(parent=aviPanel, label=warning)
  1150. warningLabel.SetForegroundColour(wx.RED)
  1151. self.aviBrowse = filebrowse.FileBrowseButton(
  1152. parent=aviPanel,
  1153. id=wx.ID_ANY,
  1154. fileMask="AVI file (*.avi)|*.avi",
  1155. labelText=_("AVI file:"),
  1156. dialogTitle=_("Choose file to save animation"),
  1157. buttonText=_("Browse"),
  1158. startDirectory=os.getcwd(),
  1159. fileMode=wx.FD_SAVE)
  1160. encodingLabel = StaticText(
  1161. parent=aviPanel,
  1162. id=wx.ID_ANY,
  1163. label=_("Video codec:"))
  1164. self.encodingText = TextCtrl(
  1165. parent=aviPanel, id=wx.ID_ANY, value='mpeg4')
  1166. optionsLabel = StaticText(
  1167. parent=aviPanel, label=_("Additional options:"))
  1168. self.optionsText = TextCtrl(parent=aviPanel)
  1169. self.optionsText.SetToolTip(
  1170. _(
  1171. "Consider adding '-sameq' or '-qscale 1' "
  1172. "if not satisfied with video quality. "
  1173. "Options depend on ffmpeg version."))
  1174. aviGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1175. aviGridSizer.Add(
  1176. self.aviBrowse, pos=(
  1177. 0, 0), span=(
  1178. 1, 2), flag=wx.EXPAND)
  1179. aviGridSizer.Add(
  1180. encodingLabel, pos=(1, 0),
  1181. flag=wx.ALIGN_CENTER_VERTICAL)
  1182. aviGridSizer.Add(self.encodingText, pos=(1, 1), flag=wx.EXPAND)
  1183. aviGridSizer.Add(
  1184. optionsLabel, pos=(2, 0),
  1185. flag=wx.ALIGN_CENTER_VERTICAL)
  1186. aviGridSizer.Add(self.optionsText, pos=(2, 1), flag=wx.EXPAND)
  1187. if not ffmpeg:
  1188. aviGridSizer.Add(warningLabel, pos=(3, 0), span=(1, 2),
  1189. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1190. aviGridSizer.AddGrowableCol(1)
  1191. aviPanel.SetSizer(aviGridSizer)
  1192. aviGridSizer.Fit(aviPanel)
  1193. self.formatPanelSizer.Add(
  1194. aviPanel,
  1195. proportion=1,
  1196. flag=wx.EXPAND | wx.ALL,
  1197. border=5)
  1198. self.formatPanels.append(aviPanel)
  1199. fpsSizer = wx.BoxSizer(wx.HORIZONTAL)
  1200. fps = 1000 / self.timeTick
  1201. fpsSizer.Add(
  1202. StaticText(
  1203. panel,
  1204. id=wx.ID_ANY,
  1205. label=_("Current frame rate: %.2f fps") %
  1206. fps),
  1207. proportion=1,
  1208. flag=wx.EXPAND)
  1209. borderSizer.Add(
  1210. fpsSizer,
  1211. proportion=0,
  1212. flag=wx.ALL,
  1213. border=5)
  1214. panel.SetSizer(borderSizer)
  1215. borderSizer.Fit(panel)
  1216. self.ChangeFormat(index=0)
  1217. return panel
  1218. def ChangeFormat(self, index):
  1219. for i, panel in enumerate(self.formatPanels):
  1220. self.formatPanelSizer.Show(window=panel, show=(i == index))
  1221. self.formatPanelSizer.Layout()
  1222. def OnFont(self, event):
  1223. index = self.listbox.GetSelection()
  1224. # should not happen
  1225. if index == wx.NOT_FOUND:
  1226. return
  1227. cdata = self.listbox.GetClientData(index)
  1228. font = cdata['font']
  1229. fontdata = wx.FontData()
  1230. fontdata.EnableEffects(True)
  1231. fontdata.SetColour('black')
  1232. fontdata.SetInitialFont(font)
  1233. dlg = wx.FontDialog(self, fontdata)
  1234. dlg.CenterOnParent()
  1235. if dlg.ShowModal() == wx.ID_OK:
  1236. newfontdata = dlg.GetFontData()
  1237. font = newfontdata.GetChosenFont()
  1238. self.sampleLabel.SetFont(font)
  1239. cdata['font'] = font
  1240. self.Layout()
  1241. def OnPosition(self, event, coord):
  1242. index = self.listbox.GetSelection()
  1243. # should not happen
  1244. if index == wx.NOT_FOUND:
  1245. return
  1246. cdata = self.listbox.GetClientData(index)
  1247. cdata['pos'][coord == 'Y'] = event.GetInt()
  1248. def OnSetImage(self, event):
  1249. index = self.listbox.GetSelection()
  1250. # should not happen
  1251. if index == wx.NOT_FOUND:
  1252. return
  1253. cdata = self.listbox.GetClientData(index)
  1254. cdata['file'] = event.GetString()
  1255. def OnAddDecoration(self, event, name):
  1256. if name == 'time':
  1257. timeInfo = {'name': name, 'font': self.GetFont(), 'pos': [10, 10]}
  1258. self.decorations.append(timeInfo)
  1259. elif name == 'image':
  1260. imageInfo = {'name': name, 'file': '', 'pos': [10, 10]}
  1261. self.decorations.append(imageInfo)
  1262. elif name == 'text':
  1263. textInfo = {
  1264. 'name': name,
  1265. 'font': self.GetFont(),
  1266. 'text': '',
  1267. 'pos': [
  1268. 10,
  1269. 10]}
  1270. self.decorations.append(textInfo)
  1271. self._updateListBox()
  1272. self.listbox.SetSelection(self.listbox.GetCount() - 1)
  1273. self.OnSelectionChanged(event=None)
  1274. def OnSelectionChanged(self, event):
  1275. index = self.listbox.GetSelection()
  1276. if index == wx.NOT_FOUND:
  1277. self._hideAll()
  1278. return
  1279. cdata = self.listbox.GetClientData(index)
  1280. self.hidevbox.Show(self.fontBox, (cdata['name'] in ('time', 'text')))
  1281. self.hidevbox.Show(self.imageBox, (cdata['name'] == 'image'))
  1282. self.hidevbox.Show(self.textBox, (cdata['name'] == 'text'))
  1283. self.hidevbox.Show(self.posBox, True)
  1284. self.hidevbox.Show(self.informBox, False)
  1285. self.spinX.SetValue(cdata['pos'][0])
  1286. self.spinY.SetValue(cdata['pos'][1])
  1287. if cdata['name'] == 'image':
  1288. self.browse.SetValue(cdata['file'])
  1289. elif cdata['name'] in ('time', 'text'):
  1290. self.sampleLabel.SetFont(cdata['font'])
  1291. if cdata['name'] == 'text':
  1292. self.textCtrl.SetValue(cdata['text'])
  1293. self.hidevbox.Layout()
  1294. # self.Layout()
  1295. def OnText(self, event):
  1296. index = self.listbox.GetSelection()
  1297. # should not happen
  1298. if index == wx.NOT_FOUND:
  1299. return
  1300. cdata = self.listbox.GetClientData(index)
  1301. cdata['text'] = event.GetString()
  1302. def OnRemove(self, event):
  1303. index = self.listbox.GetSelection()
  1304. if index == wx.NOT_FOUND:
  1305. return
  1306. decData = self.listbox.GetClientData(index)
  1307. self.decorations.remove(decData)
  1308. self._updateListBox()
  1309. if self.listbox.GetCount():
  1310. self.listbox.SetSelection(0)
  1311. self.OnSelectionChanged(event=None)
  1312. def OnExport(self, event):
  1313. for decor in self.decorations:
  1314. if decor['name'] == 'image':
  1315. if not os.path.exists(decor['file']):
  1316. if decor['file']:
  1317. GError(
  1318. parent=self,
  1319. message=_("File %s not found.") %
  1320. decor['file'])
  1321. else:
  1322. GError(parent=self,
  1323. message=_("Decoration image file is missing."))
  1324. return
  1325. if self.formatChoice.GetSelection() == 0:
  1326. name = self.dirBrowse.GetValue()
  1327. if not os.path.exists(name):
  1328. if name:
  1329. GError(
  1330. parent=self,
  1331. message=_("Directory %s not found.") %
  1332. name)
  1333. else:
  1334. GError(parent=self, message=_(
  1335. "Export directory is missing."))
  1336. return
  1337. elif self.formatChoice.GetSelection() == 1:
  1338. if not self.gifBrowse.GetValue():
  1339. GError(parent=self, message=_("Export file is missing."))
  1340. return
  1341. elif self.formatChoice.GetSelection() == 2:
  1342. if not self.swfBrowse.GetValue():
  1343. GError(parent=self, message=_("Export file is missing."))
  1344. return
  1345. # hide only to keep previous values
  1346. self.Hide()
  1347. self.doExport.emit(exportInfo=self.GetExportInformation(),
  1348. decorations=self.GetDecorations())
  1349. def GetDecorations(self):
  1350. return self.decorations
  1351. def GetExportInformation(self):
  1352. info = {}
  1353. if self.formatChoice.GetSelection() == 0:
  1354. info['method'] = 'sequence'
  1355. info['directory'] = self.dirBrowse.GetValue()
  1356. info['prefix'] = self.prefixCtrl.GetValue()
  1357. info['format'] = self.imSeqFormatChoice.GetStringSelection()
  1358. elif self.formatChoice.GetSelection() == 1:
  1359. info['method'] = 'gif'
  1360. info['file'] = self.gifBrowse.GetValue()
  1361. elif self.formatChoice.GetSelection() == 2:
  1362. info['method'] = 'swf'
  1363. info['file'] = self.swfBrowse.GetValue()
  1364. elif self.formatChoice.GetSelection() == 3:
  1365. info['method'] = 'avi'
  1366. info['file'] = self.aviBrowse.GetValue()
  1367. info['encoding'] = self.encodingText.GetValue()
  1368. info['options'] = self.optionsText.GetValue()
  1369. return info
  1370. def _updateListBox(self):
  1371. self.listbox.Clear()
  1372. names = {
  1373. 'time': _("Time stamp"),
  1374. 'image': _("Image"),
  1375. 'text': _("Text")}
  1376. for decor in self.decorations:
  1377. self.listbox.Append(names[decor['name']], clientData=decor)
  1378. def _hideAll(self):
  1379. self.hidevbox.Show(self.fontBox, False)
  1380. self.hidevbox.Show(self.imageBox, False)
  1381. self.hidevbox.Show(self.textBox, False)
  1382. self.hidevbox.Show(self.posBox, False)
  1383. self.hidevbox.Show(self.informBox, True)
  1384. self.hidevbox.Layout()
  1385. class AnimSimpleLayerManager(SimpleLayerManager):
  1386. """Simple layer manager for animation tool.
  1387. Allows adding space-time dataset or series of maps.
  1388. """
  1389. def __init__(self, parent, layerList,
  1390. lmgrStyle=SIMPLE_LMGR_RASTER | SIMPLE_LMGR_VECTOR |
  1391. SIMPLE_LMGR_TB_TOP | SIMPLE_LMGR_STDS,
  1392. toolbarCls=AnimSimpleLmgrToolbar, modal=True):
  1393. SimpleLayerManager.__init__(
  1394. self, parent, layerList, lmgrStyle, toolbarCls, modal)
  1395. self._3dActivated = False
  1396. def OnAddStds(self, event):
  1397. """Opens dialog for specifying temporal dataset.
  1398. Dummy layer is added first."""
  1399. layer = AnimLayer()
  1400. layer.hidden = True
  1401. self._layerList.AddLayer(layer)
  1402. self.SetStdsProperties(layer)
  1403. event.Skip()
  1404. def SetStdsProperties(self, layer):
  1405. dlg = AddTemporalLayerDialog(
  1406. parent=self, layer=layer, volume=self._3dActivated)
  1407. # first get hidden property, it's altered afterwards
  1408. hidden = layer.hidden
  1409. dlg.CenterOnParent()
  1410. if dlg.ShowModal() == wx.ID_OK:
  1411. layer = dlg.GetLayer()
  1412. if hidden:
  1413. signal = self.layerAdded
  1414. else:
  1415. signal = self.cmdChanged
  1416. signal.emit(
  1417. index=self._layerList.GetLayerIndex(layer),
  1418. layer=layer)
  1419. else:
  1420. if hidden:
  1421. self._layerList.RemoveLayer(layer)
  1422. dlg.Destroy()
  1423. self._update()
  1424. self.anyChange.emit()
  1425. def _layerChangeProperties(self, layer):
  1426. """Opens new module dialog or recycles it."""
  1427. if not hasattr(layer, 'maps'):
  1428. GUI(parent=self, giface=None, modal=self._modal).ParseCommand(
  1429. cmd=layer.cmd, completed=(self.GetOptData, layer, ''))
  1430. else:
  1431. self.SetStdsProperties(layer)
  1432. def Activate3D(self, activate=True):
  1433. """Activates/deactivates certain tool depending on 2D/3D view."""
  1434. self._toolbar.EnableTools(['addRaster', 'addVector',
  1435. 'opacity', 'up', 'down'], not activate)
  1436. self._3dActivated = activate
  1437. class AddTemporalLayerDialog(wx.Dialog):
  1438. """Dialog for adding space-time dataset/ map series."""
  1439. def __init__(self, parent, layer, volume=False,
  1440. title=_("Add space-time dataset layer")):
  1441. wx.Dialog.__init__(self, parent=parent, title=title)
  1442. self.layer = layer
  1443. self._mapType = None
  1444. self._name = None
  1445. self._cmd = None
  1446. self.tselect = Select(parent=self, type='strds')
  1447. iconTheme = UserSettings.Get(
  1448. group='appearance',
  1449. key='iconTheme',
  1450. subkey='type')
  1451. bitmapPath = os.path.join(
  1452. globalvar.ICONDIR,
  1453. iconTheme,
  1454. 'layer-open.png')
  1455. if os.path.isfile(bitmapPath) and os.path.getsize(bitmapPath):
  1456. bitmap = wx.Bitmap(name=bitmapPath)
  1457. else:
  1458. bitmap = wx.ArtProvider.GetBitmap(
  1459. id=wx.ART_MISSING_IMAGE, client=wx.ART_TOOLBAR)
  1460. self.addManyMapsButton = BitmapButton(self, bitmap=bitmap)
  1461. self.addManyMapsButton.Bind(wx.EVT_BUTTON, self._onAddMaps)
  1462. types = [('raster', _("Multiple raster maps")),
  1463. ('vector', _("Multiple vector maps")),
  1464. ('raster_3d', _("Multiple 3D raster maps")),
  1465. ('strds', _("Space time raster dataset")),
  1466. ('stvds', _("Space time vector dataset")),
  1467. ('str3ds', _("Space time 3D raster dataset"))]
  1468. if not volume:
  1469. del types[5]
  1470. del types[2]
  1471. self._types = dict(types)
  1472. self.tchoice = wx.Choice(parent=self)
  1473. for type_, text in types:
  1474. self.tchoice.Append(text, clientData=type_)
  1475. self.editBtn = Button(parent=self, label='Set properties')
  1476. self.okBtn = Button(parent=self, id=wx.ID_OK)
  1477. self.cancelBtn = Button(parent=self, id=wx.ID_CANCEL)
  1478. self.okBtn.Bind(wx.EVT_BUTTON, self._onOK)
  1479. self.editBtn.Bind(wx.EVT_BUTTON, self._onProperties)
  1480. self.tchoice.Bind(wx.EVT_CHOICE,
  1481. lambda evt: self._setType())
  1482. self.tselect.Bind(wx.EVT_TEXT,
  1483. lambda evt: self._datasetChanged())
  1484. if self.layer.mapType:
  1485. self._setType(self.layer.mapType)
  1486. else:
  1487. self._setType('raster')
  1488. if self.layer.name:
  1489. self.tselect.SetValue(self.layer.name)
  1490. if self.layer.cmd:
  1491. self._cmd = self.layer.cmd
  1492. self._layout()
  1493. self.SetSize(self.GetBestSize())
  1494. def _layout(self):
  1495. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1496. bodySizer = wx.BoxSizer(wx.VERTICAL)
  1497. typeSizer = wx.BoxSizer(wx.HORIZONTAL)
  1498. selectSizer = wx.BoxSizer(wx.HORIZONTAL)
  1499. typeSizer.Add(StaticText(self, label=_("Input data type:")),
  1500. flag=wx.ALIGN_CENTER_VERTICAL)
  1501. typeSizer.AddStretchSpacer()
  1502. typeSizer.Add(self.tchoice)
  1503. bodySizer.Add(typeSizer, flag=wx.EXPAND | wx.BOTTOM, border=5)
  1504. selectSizer.Add(self.tselect, flag=wx.RIGHT |
  1505. wx.ALIGN_CENTER_VERTICAL, border=5)
  1506. selectSizer.Add(self.addManyMapsButton, flag=wx.EXPAND)
  1507. bodySizer.Add(selectSizer, flag=wx.BOTTOM, border=5)
  1508. bodySizer.Add(self.editBtn, flag=wx.BOTTOM, border=5)
  1509. mainSizer.Add(
  1510. bodySizer,
  1511. proportion=1,
  1512. flag=wx.EXPAND | wx.ALL,
  1513. border=10)
  1514. btnSizer = wx.StdDialogButtonSizer()
  1515. btnSizer.AddButton(self.okBtn)
  1516. btnSizer.AddButton(self.cancelBtn)
  1517. btnSizer.Realize()
  1518. mainSizer.Add(btnSizer, proportion=0,
  1519. flag=wx.EXPAND | wx.ALL, border=10)
  1520. self.SetSizer(mainSizer)
  1521. mainSizer.Fit(self)
  1522. def _datasetChanged(self):
  1523. if self._name != self.tselect.GetValue():
  1524. self._name = self.tselect.GetValue()
  1525. self._cmd = None
  1526. def _setType(self, typeName=None):
  1527. if typeName:
  1528. self.tchoice.SetStringSelection(self._types[typeName])
  1529. self.tselect.SetType(typeName)
  1530. if typeName in ('strds', 'stvds', 'str3ds'):
  1531. self.tselect.SetType(typeName, multiple=False)
  1532. self.addManyMapsButton.Disable()
  1533. else:
  1534. self.tselect.SetType(typeName, multiple=True)
  1535. self.addManyMapsButton.Enable()
  1536. self._mapType = typeName
  1537. self.tselect.SetValue('')
  1538. else:
  1539. typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
  1540. if typeName in ('strds', 'stvds', 'str3ds'):
  1541. self.tselect.SetType(typeName, multiple=False)
  1542. self.addManyMapsButton.Disable()
  1543. else:
  1544. self.tselect.SetType(typeName, multiple=True)
  1545. self.addManyMapsButton.Enable()
  1546. if typeName != self._mapType:
  1547. self._cmd = None
  1548. self._mapType = typeName
  1549. self.tselect.SetValue('')
  1550. def _createDefaultCommand(self):
  1551. cmd = []
  1552. if self._mapType in ('raster', 'strds'):
  1553. cmd.append('d.rast')
  1554. elif self._mapType in ('vector', 'stvds'):
  1555. cmd.append('d.vect')
  1556. elif self._mapType in ('raster_3d', 'str3ds'):
  1557. cmd.append('d.rast3d')
  1558. if self._name:
  1559. if self._mapType in ('raster', 'vector', 'raster_3d'):
  1560. cmd.append('map={name}'.format(name=self._name.split(',')[0]))
  1561. else:
  1562. try:
  1563. maps = getRegisteredMaps(self._name, etype=self._mapType)
  1564. if maps:
  1565. mapName, mapLayer = getNameAndLayer(maps[0])
  1566. cmd.append('map={name}'.format(name=mapName))
  1567. except gcore.ScriptError as e:
  1568. GError(parent=self, message=str(e), showTraceback=False)
  1569. return None
  1570. return cmd
  1571. def _onAddMaps(self, event):
  1572. dlg = MapLayersDialog(self, title=_("Select raster/vector maps."))
  1573. dlg.applyAddingMapLayers.connect(
  1574. lambda mapLayers: self.tselect.SetValue(
  1575. ','.join(mapLayers)))
  1576. if self._mapType == 'raster':
  1577. index = 0
  1578. elif self._mapType == 'vector':
  1579. index = 2
  1580. else: # rast3d
  1581. index = 1
  1582. dlg.layerType.SetSelection(index)
  1583. dlg.LoadMapLayers(dlg.GetLayerType(cmd=True),
  1584. dlg.mapset.GetStringSelection())
  1585. dlg.CenterOnParent()
  1586. if dlg.ShowModal() == wx.ID_OK:
  1587. self.tselect.SetValue(','.join(dlg.GetMapLayers()))
  1588. dlg.Destroy()
  1589. def _onProperties(self, event):
  1590. self._checkInput()
  1591. if self._cmd:
  1592. GUI(parent=self, show=True, modal=True).ParseCommand(
  1593. cmd=self._cmd, completed=(self._getOptData, '', ''))
  1594. def _checkInput(self):
  1595. if not self.tselect.GetValue():
  1596. GMessage(parent=self, message=_(
  1597. "Please select maps or dataset first."))
  1598. return
  1599. if not self._cmd:
  1600. self._cmd = self._createDefaultCommand()
  1601. def _getOptData(self, dcmd, layer, params, propwin):
  1602. if dcmd:
  1603. self._cmd = dcmd
  1604. def _onOK(self, event):
  1605. self._checkInput()
  1606. if self._cmd:
  1607. try:
  1608. self.layer.hidden = False
  1609. self.layer.mapType = self._mapType
  1610. self.layer.name = self._name
  1611. self.layer.cmd = self._cmd
  1612. event.Skip()
  1613. except (GException, gcore.ScriptError) as e:
  1614. GError(parent=self, message=str(e))
  1615. def GetLayer(self):
  1616. return self.layer
  1617. class PreferencesDialog(PreferencesBaseDialog):
  1618. """Animation preferences dialog"""
  1619. def __init__(self, parent, giface, title=_("Animation Tool settings"),
  1620. settings=UserSettings):
  1621. PreferencesBaseDialog.__init__(
  1622. self, parent=parent, giface=giface, title=title, settings=settings,
  1623. size=(-1, 270))
  1624. self.formatChanged = Signal('PreferencesDialog.formatChanged')
  1625. self._timeFormats = ['%Y-%m-%d %H:%M:%S', # 2013-12-29 11:16:26
  1626. '%Y-%m-%d', # 2013-12-29
  1627. '%c',
  1628. # Sun Dec 29 11:16:26 2013 (locale-dependent)
  1629. '%x', # 12/29/13 (locale-dependent)
  1630. '%X', # 11:16:26 (locale-dependent)
  1631. '%b %d, %Y', # Dec 29, 2013
  1632. '%B %d, %Y', # December 29, 2013
  1633. '%B, %Y', # December 2013
  1634. '%I:%M %p', # 11:16 AM
  1635. '%I %p', # 11 AM
  1636. ]
  1637. self._format = None
  1638. self._initFormat = self.settings.Get(group='animation', key='temporal',
  1639. subkey='format')
  1640. # create notebook pages
  1641. self._createGeneralPage(self.notebook)
  1642. self._createTemporalPage(self.notebook)
  1643. self.SetMinSize(self.GetBestSize())
  1644. self.SetSize(self.size)
  1645. def _createGeneralPage(self, notebook):
  1646. """Create notebook page for general settings"""
  1647. panel = SP.ScrolledPanel(parent=notebook)
  1648. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1649. notebook.AddPage(page=panel, text=_("General"))
  1650. border = wx.BoxSizer(wx.VERTICAL)
  1651. sizer = wx.BoxSizer(wx.VERTICAL)
  1652. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1653. row = 0
  1654. gridSizer.Add(
  1655. StaticText(
  1656. parent=panel,
  1657. label=_("Background color:")),
  1658. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1659. pos=(
  1660. row,
  1661. 0))
  1662. color = csel.ColourSelect(
  1663. parent=panel,
  1664. colour=UserSettings.Get(
  1665. group='animation',
  1666. key='bgcolor',
  1667. subkey='color'),
  1668. size=globalvar.DIALOG_COLOR_SIZE)
  1669. color.SetName('GetColour')
  1670. self.winId['animation:bgcolor:color'] = color.GetId()
  1671. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1672. row += 1
  1673. gridSizer.Add(
  1674. StaticText(
  1675. parent=panel,
  1676. label=_("Number of parallel processes:")),
  1677. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1678. pos=(
  1679. row,
  1680. 0))
  1681. # when running for the first time, set nprocs based on the number of
  1682. # processes
  1683. if UserSettings.Get(group='animation', key='nprocs',
  1684. subkey='value') == -1:
  1685. UserSettings.Set(
  1686. group='animation',
  1687. key='nprocs',
  1688. subkey='value',
  1689. value=getCpuCount())
  1690. nprocs = SpinCtrl(
  1691. parent=panel,
  1692. initial=UserSettings.Get(
  1693. group='animation',
  1694. key='nprocs',
  1695. subkey='value'))
  1696. nprocs.SetName('GetValue')
  1697. self.winId['animation:nprocs:value'] = nprocs.GetId()
  1698. gridSizer.Add(nprocs, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1699. row += 1
  1700. gridSizer.Add(
  1701. StaticText(
  1702. parent=panel,
  1703. label=_("Text foreground color:")),
  1704. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1705. pos=(
  1706. row,
  1707. 0))
  1708. color = csel.ColourSelect(
  1709. parent=panel,
  1710. colour=UserSettings.Get(
  1711. group='animation',
  1712. key='font',
  1713. subkey='fgcolor'),
  1714. size=globalvar.DIALOG_COLOR_SIZE)
  1715. color.SetName('GetColour')
  1716. self.winId['animation:font:fgcolor'] = color.GetId()
  1717. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1718. row += 1
  1719. gridSizer.Add(
  1720. StaticText(
  1721. parent=panel,
  1722. label=_("Text background color:")),
  1723. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1724. pos=(
  1725. row,
  1726. 0))
  1727. color = csel.ColourSelect(
  1728. parent=panel,
  1729. colour=UserSettings.Get(
  1730. group='animation',
  1731. key='font',
  1732. subkey='bgcolor'),
  1733. size=globalvar.DIALOG_COLOR_SIZE)
  1734. color.SetName('GetColour')
  1735. self.winId['animation:font:bgcolor'] = color.GetId()
  1736. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1737. gridSizer.AddGrowableCol(1)
  1738. sizer.Add(
  1739. gridSizer,
  1740. proportion=1,
  1741. flag=wx.ALL | wx.EXPAND,
  1742. border=3)
  1743. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1744. panel.SetSizer(border)
  1745. return panel
  1746. def _createTemporalPage(self, notebook):
  1747. """Create notebook page for temporal settings"""
  1748. panel = SP.ScrolledPanel(parent=notebook)
  1749. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1750. notebook.AddPage(page=panel, text=_("Time"))
  1751. border = wx.BoxSizer(wx.VERTICAL)
  1752. sizer = wx.BoxSizer(wx.VERTICAL)
  1753. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1754. row = 0
  1755. gridSizer.Add(
  1756. StaticText(
  1757. parent=panel,
  1758. label=_("Absolute time format:")),
  1759. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1760. pos=(
  1761. row,
  1762. 0))
  1763. self.tempFormat = wx.ComboBox(parent=panel, name='GetValue')
  1764. self.tempFormat.SetItems(self._timeFormats)
  1765. self.tempFormat.SetValue(self._initFormat)
  1766. self.winId['animation:temporal:format'] = self.tempFormat.GetId()
  1767. gridSizer.Add(self.tempFormat, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1768. self.infoTimeLabel = StaticText(parent=panel)
  1769. self.tempFormat.Bind(
  1770. wx.EVT_COMBOBOX,
  1771. lambda evt: self._setTimeFormat(
  1772. self.tempFormat.GetValue()))
  1773. self.tempFormat.Bind(
  1774. wx.EVT_TEXT, lambda evt: self._setTimeFormat(
  1775. self.tempFormat.GetValue()))
  1776. self.tempFormat.SetToolTipString(
  1777. _(
  1778. "Click and then press key up or down to preview "
  1779. "different date and time formats. "
  1780. "Type custom format string."))
  1781. row += 1
  1782. gridSizer.Add(self.infoTimeLabel, pos=(row, 0), span=(1, 2),
  1783. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1784. self._setTimeFormat(self.tempFormat.GetValue())
  1785. row += 1
  1786. link = HyperlinkCtrl(
  1787. panel, id=wx.ID_ANY,
  1788. label=_("Learn more about formatting options"),
  1789. url="http://docs.python.org/2/library/datetime.html#"
  1790. "strftime-and-strptime-behavior")
  1791. link.SetNormalColour(
  1792. wx.SystemSettings.GetColour(
  1793. wx.SYS_COLOUR_GRAYTEXT))
  1794. link.SetVisitedColour(
  1795. wx.SystemSettings.GetColour(
  1796. wx.SYS_COLOUR_GRAYTEXT))
  1797. gridSizer.Add(link, pos=(row, 0), span=(1, 2),
  1798. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1799. row += 2
  1800. noDataCheck = CheckBox(
  1801. panel, label=_("Display instances with no data"))
  1802. noDataCheck.SetToolTip(
  1803. _(
  1804. "When animating instant-based data which have irregular timestamps "
  1805. "you can display 'no data frame' (checked option) or "
  1806. "keep last frame."))
  1807. noDataCheck.SetValue(
  1808. self.settings.Get(
  1809. group='animation',
  1810. key='temporal',
  1811. subkey=[
  1812. 'nodata',
  1813. 'enable']))
  1814. self.winId['animation:temporal:nodata:enable'] = noDataCheck.GetId()
  1815. gridSizer.Add(noDataCheck, pos=(row, 0), span=(1, 2),
  1816. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1817. gridSizer.AddGrowableCol(1)
  1818. sizer.Add(
  1819. gridSizer,
  1820. proportion=1,
  1821. flag=wx.ALL | wx.EXPAND,
  1822. border=3)
  1823. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1824. panel.SetSizer(border)
  1825. return panel
  1826. def _setTimeFormat(self, formatString):
  1827. now = datetime.datetime.now()
  1828. try:
  1829. label = datetime.datetime.strftime(now, formatString)
  1830. self._format = formatString
  1831. except ValueError:
  1832. label = _("Invalid")
  1833. self.infoTimeLabel.SetLabel(label)
  1834. self.infoTimeLabel.GetContainingSizer().Layout()
  1835. def _updateSettings(self):
  1836. self.tempFormat.SetValue(self._format)
  1837. PreferencesBaseDialog._updateSettings(self)
  1838. if self._format != self._initFormat:
  1839. self.formatChanged.emit()
  1840. return True
  1841. def test():
  1842. import wx.lib.inspection
  1843. app = wx.App()
  1844. # testTemporalLayer()
  1845. # testAnimLmgr()
  1846. testAnimInput()
  1847. # wx.lib.inspection.InspectionTool().Show()
  1848. app.MainLoop()
  1849. def testAnimInput():
  1850. anim = AnimationData()
  1851. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1852. dlg = InputDialog(parent=None, mode='add', animationData=anim)
  1853. dlg.Show()
  1854. def testAnimEdit():
  1855. anim = AnimationData()
  1856. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1857. dlg = EditDialog(parent=None, animationData=[anim])
  1858. dlg.Show()
  1859. def testExport():
  1860. dlg = ExportDialog(parent=None, temporal=TemporalMode.TEMPORAL,
  1861. timeTick=200)
  1862. if dlg.ShowModal() == wx.ID_OK:
  1863. print(dlg.GetDecorations())
  1864. print(dlg.GetExportInformation())
  1865. dlg.Destroy()
  1866. else:
  1867. dlg.Destroy()
  1868. def testTemporalLayer():
  1869. frame = wx.Frame(None)
  1870. frame.Show()
  1871. layer = AnimLayer()
  1872. dlg = AddTemporalLayerDialog(parent=frame, layer=layer)
  1873. if dlg.ShowModal() == wx.ID_OK:
  1874. layer = dlg.GetLayer()
  1875. print(layer.name, layer.cmd, layer.mapType)
  1876. dlg.Destroy()
  1877. else:
  1878. dlg.Destroy()
  1879. def testAnimLmgr():
  1880. from core.layerlist import LayerList
  1881. frame = wx.Frame(None)
  1882. mgr = AnimSimpleLayerManager(parent=frame, layerList=LayerList())
  1883. frame.mgr = mgr
  1884. frame.Show()
  1885. if __name__ == '__main__':
  1886. gcore.set_raise_on_error(True)
  1887. test()