dialogs.py 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  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 BitmapButton, Button, CheckBox, Choice, \
  37. ComboBox, EmptyImage, RadioButton, SpinCtrl, StaticBox, StaticText, TextCtrl
  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 | wx.ALIGN_RIGHT, 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 | wx.ALIGN_RIGHT, 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 | wx.ALIGN_CENTER)
  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. _("Animate region change (2D view only)"))
  481. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  482. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  483. gridSizer.Add(StaticText(panel, label=_("Start region:")),
  484. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  485. self.stRegion = Select(parent=panel, type='region', size=(200, -1))
  486. if self.animationData.startRegion:
  487. self.stRegion.SetValue(self.animationData.startRegion)
  488. gridSizer.Add(
  489. self.stRegion, pos=(0, 1),
  490. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  491. self.endRegRadio = RadioButton(
  492. panel, label=_("End region:"), style=wx.RB_GROUP)
  493. gridSizer.Add(self.endRegRadio, pos=(1, 0), flag=wx.EXPAND)
  494. self.endRegion = Select(parent=panel, type='region', size=(200, -1))
  495. gridSizer.Add(
  496. self.endRegion, pos=(1, 1),
  497. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  498. self.zoomRadio = RadioButton(panel, label=_("Zoom value:"))
  499. self.zoomRadio.SetToolTip(_("N-S/E-W distances in map units used to "
  500. "gradually reduce region."))
  501. gridSizer.Add(self.zoomRadio, pos=(2, 0), flag=wx.EXPAND)
  502. zoomSizer = wx.BoxSizer(wx.HORIZONTAL)
  503. self.zoomNS = TextCtrl(panel, validator=FloatValidator())
  504. self.zoomEW = TextCtrl(panel, validator=FloatValidator())
  505. zoomSizer.Add(StaticText(panel, label=_("N-S:")), proportion=0,
  506. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  507. zoomSizer.Add(self.zoomNS, proportion=1, flag=wx.LEFT, border=3)
  508. zoomSizer.Add(StaticText(panel, label=_("E-W:")), proportion=0,
  509. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  510. zoomSizer.Add(self.zoomEW, proportion=1, flag=wx.LEFT, border=3)
  511. gridSizer.Add(
  512. zoomSizer, pos=(2, 1),
  513. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  514. if self.animationData.endRegion:
  515. self.endRegRadio.SetValue(True)
  516. self.zoomRadio.SetValue(False)
  517. self.endRegion.SetValue(self.animationData.endRegion)
  518. if self.animationData.zoomRegionValue:
  519. self.endRegRadio.SetValue(False)
  520. self.zoomRadio.SetValue(True)
  521. zoom = self.animationData.zoomRegionValue
  522. self.zoomNS.SetValue(str(zoom[0]))
  523. self.zoomEW.SetValue(str(zoom[1]))
  524. self.endRegRadio.Bind(
  525. wx.EVT_RADIOBUTTON,
  526. lambda evt: self._enableRegionWidgets())
  527. self.zoomRadio.Bind(
  528. wx.EVT_RADIOBUTTON,
  529. lambda evt: self._enableRegionWidgets())
  530. self._enableRegionWidgets()
  531. gridSizer.AddGrowableCol(1)
  532. sizer.Add(gridSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  533. mainSizer.Add(sizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  534. panel.SetSizer(mainSizer)
  535. mainSizer.Fit(panel)
  536. return panel
  537. def _enableRegionWidgets(self):
  538. """Enables/disables region widgets
  539. according to which radiobutton is active."""
  540. endReg = self.endRegRadio.GetValue()
  541. self.endRegion.Enable(endReg)
  542. self.zoomNS.Enable(not endReg)
  543. self.zoomEW.Enable(not endReg)
  544. def OnViewMode(self, event):
  545. mode = self.nDChoice.GetSelection()
  546. self.Freeze()
  547. self.simpleLmgr.Activate3D(mode == 1)
  548. self.warning3DLayers.Show(mode == 1)
  549. # disable region widgets for 3d
  550. regSizer = self.stRegion.GetContainingSizer()
  551. for child in regSizer.GetChildren():
  552. if child.IsSizer():
  553. for child_ in child.GetSizer().GetChildren():
  554. child_.GetWindow().Enable(mode != 1)
  555. elif child.IsWindow():
  556. child.GetWindow().Enable(mode != 1)
  557. self._enableRegionWidgets()
  558. # update layout
  559. sizer = self.threeDPanel.GetContainingSizer()
  560. sizer.Show(self.threeDPanel, mode == 1, True)
  561. sizer.Layout()
  562. self.Thaw()
  563. def OnLegend(self, event):
  564. if not self.legend.IsChecked():
  565. return
  566. if self._tmpLegendCmd or self.animationData.legendCmd:
  567. return
  568. cmd = ['d.legend', 'at=5,50,2,5']
  569. GUI(parent=self, modal=True).ParseCommand(
  570. cmd=cmd, completed=(self.GetOptData, '', ''))
  571. def OnLegendProperties(self, event):
  572. """Set options for legend"""
  573. if self._tmpLegendCmd:
  574. cmd = self._tmpLegendCmd
  575. elif self.animationData.legendCmd:
  576. cmd = self.animationData.legendCmd
  577. else:
  578. cmd = ['d.legend', 'at=5,50,2,5']
  579. GUI(parent=self, modal=True).ParseCommand(
  580. cmd=cmd, completed=(self.GetOptData, '', ''))
  581. def GetOptData(self, dcmd, layer, params, propwin):
  582. """Process decoration layer data"""
  583. if dcmd:
  584. self._tmpLegendCmd = dcmd
  585. if not self.legend.IsChecked():
  586. self.legend.SetValue(True)
  587. else:
  588. if not self._tmpLegendCmd and not self.animationData.legendCmd:
  589. self.legend.SetValue(False)
  590. def _update(self):
  591. if self.nDChoice.GetSelection() == 1 and len(self._layerList) > 1:
  592. raise GException(_("Only one series or space-time "
  593. "dataset is accepted for 3D mode."))
  594. hasSeries = False
  595. for layer in self._layerList:
  596. if layer.active and hasattr(layer, 'maps'):
  597. hasSeries = True
  598. break
  599. if not hasSeries:
  600. raise GException(_("No map series or space-time dataset added."))
  601. self.animationData.layerList = self._layerList
  602. self.animationData.name = self.nameCtrl.GetValue()
  603. self.animationData.windowIndex = self.windowChoice.GetSelection()
  604. sel = self.nDChoice.GetSelection()
  605. self.animationData.viewMode = self.nDChoice.GetClientData(sel)
  606. self.animationData.legendCmd = None
  607. if self._tmpLegendCmd:
  608. if self.legend.IsChecked():
  609. self.animationData.legendCmd = self._tmpLegendCmd
  610. if self.threeDPanel.IsShown():
  611. self.animationData.workspaceFile = self.fileSelector.GetValue()
  612. if self.threeDPanel.IsShown():
  613. self.animationData.nvizParameter = self.paramChoice.GetStringSelection()
  614. # region (2d only)
  615. if self.animationData.viewMode == '3d':
  616. self.animationData.startRegion = None
  617. self.animationData.endRegion = None
  618. self.animationData.zoomRegionValue = None
  619. return
  620. isEnd = self.endRegRadio.GetValue() and self.endRegion.GetValue()
  621. isZoom = self.zoomRadio.GetValue() and self.zoomNS.GetValue() and self.zoomEW.GetValue()
  622. isStart = self.stRegion.GetValue()
  623. condition = bool(isStart) + bool(isZoom) + bool(isEnd)
  624. if condition == 1:
  625. raise GException(_("Region information is not complete"))
  626. elif condition == 2:
  627. self.animationData.startRegion = isStart
  628. if isEnd:
  629. self.animationData.endRegion = self.endRegion.GetValue()
  630. self.animationData.zoomRegionValue = None
  631. else:
  632. self.animationData.zoomRegionValue = (
  633. float(self.zoomNS.GetValue()),
  634. float(self.zoomEW.GetValue()))
  635. self.animationData.endRegion = None
  636. else:
  637. self.animationData.startRegion = None
  638. self.animationData.endRegion = None
  639. self.animationData.zoomRegionValue = None
  640. def UnInit(self):
  641. self.simpleLmgr.UnInit()
  642. def OnOk(self, event):
  643. try:
  644. self._update()
  645. self.UnInit()
  646. self.EndModal(wx.ID_OK)
  647. except (GException, ValueError, IOError) as e:
  648. GError(
  649. message=str(e),
  650. showTraceback=False,
  651. caption=_("Invalid input"))
  652. class EditDialog(wx.Dialog):
  653. def __init__(self, parent, evalFunction, animationData, maxAnimations):
  654. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  655. style=wx.DEFAULT_DIALOG_STYLE)
  656. self.animationData = copy.deepcopy(animationData)
  657. self.eval = evalFunction
  658. self.SetTitle(_("Add, edit or remove animations"))
  659. self._layout()
  660. self.SetSize((300, -1))
  661. self.maxAnimations = maxAnimations
  662. self.result = None
  663. def _layout(self):
  664. mainSizer = wx.BoxSizer(wx.VERTICAL)
  665. box = StaticBox(
  666. parent=self,
  667. id=wx.ID_ANY,
  668. label=" %s " %
  669. _("List of animations"))
  670. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  671. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  672. gridBagSizer.AddGrowableCol(0)
  673. # gridBagSizer.AddGrowableCol(1,1)
  674. self.listbox = wx.ListBox(
  675. self, id=wx.ID_ANY, choices=[],
  676. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  677. self.listbox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnEdit)
  678. self.addButton = Button(self, id=wx.ID_ANY, label=_("Add"))
  679. self.addButton.Bind(wx.EVT_BUTTON, self.OnAdd)
  680. self.editButton = Button(self, id=wx.ID_ANY, label=_("Edit"))
  681. self.editButton.Bind(wx.EVT_BUTTON, self.OnEdit)
  682. self.removeButton = Button(self, id=wx.ID_ANY, label=_("Remove"))
  683. self.removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  684. self._updateListBox()
  685. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(3, 1),
  686. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  687. gridBagSizer.Add(self.addButton, pos=(0, 1),
  688. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  689. gridBagSizer.Add(self.editButton, pos=(1, 1),
  690. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  691. gridBagSizer.Add(self.removeButton, pos=(2, 1),
  692. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  693. sizer.Add(
  694. gridBagSizer,
  695. proportion=0,
  696. flag=wx.ALL | wx.EXPAND,
  697. border=5)
  698. mainSizer.Add(sizer, proportion=0,
  699. flag=wx.EXPAND | wx.ALL, border=5)
  700. # buttons
  701. self.btnOk = Button(self, wx.ID_OK)
  702. self.btnCancel = Button(self, wx.ID_CANCEL)
  703. self.btnOk.SetDefault()
  704. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  705. # button sizer
  706. btnStdSizer = wx.StdDialogButtonSizer()
  707. btnStdSizer.AddButton(self.btnOk)
  708. btnStdSizer.AddButton(self.btnCancel)
  709. btnStdSizer.Realize()
  710. mainSizer.Add(btnStdSizer, proportion=0,
  711. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  712. self.SetSizer(mainSizer)
  713. mainSizer.Fit(self)
  714. def _updateListBox(self):
  715. self.listbox.Clear()
  716. for anim in self.animationData:
  717. self.listbox.Append(anim.name, clientData=anim)
  718. if self.animationData:
  719. self.listbox.SetSelection(0)
  720. def _getNextIndex(self):
  721. indices = [anim.windowIndex for anim in self.animationData]
  722. for i in range(self.maxAnimations):
  723. if i not in indices:
  724. return i
  725. return None
  726. def OnAdd(self, event):
  727. windowIndex = self._getNextIndex()
  728. if windowIndex is None:
  729. GMessage(
  730. self,
  731. message=_("Maximum number of animations is %d.") %
  732. self.maxAnimations)
  733. return
  734. animData = AnimationData()
  735. # number of active animations
  736. animationIndex = len(self.animationData)
  737. animData.SetDefaultValues(windowIndex, animationIndex)
  738. dlg = InputDialog(parent=self, mode='add', animationData=animData)
  739. dlg.CenterOnParent()
  740. if dlg.ShowModal() == wx.ID_CANCEL:
  741. dlg.UnInit()
  742. dlg.Destroy()
  743. return
  744. dlg.Destroy()
  745. self.animationData.append(animData)
  746. self._updateListBox()
  747. def OnEdit(self, event):
  748. index = self.listbox.GetSelection()
  749. if index == wx.NOT_FOUND:
  750. return
  751. animData = self.listbox.GetClientData(index)
  752. dlg = InputDialog(parent=self, mode='edit', animationData=animData)
  753. dlg.CenterOnParent()
  754. if dlg.ShowModal() == wx.ID_CANCEL:
  755. dlg.UnInit()
  756. dlg.Destroy()
  757. return
  758. dlg.Destroy()
  759. self._updateListBox()
  760. def OnRemove(self, event):
  761. index = self.listbox.GetSelection()
  762. if index == wx.NOT_FOUND:
  763. return
  764. animData = self.listbox.GetClientData(index)
  765. self.animationData.remove(animData)
  766. self._updateListBox()
  767. def GetResult(self):
  768. return self.result
  769. def OnOk(self, event):
  770. indices = set([anim.windowIndex for anim in self.animationData])
  771. if len(indices) != len(self.animationData):
  772. GError(
  773. parent=self, message=_(
  774. "More animations are using one window."
  775. " Please select different window for each animation."))
  776. return
  777. try:
  778. temporalMode, tempManager = self.eval(self.animationData)
  779. except GException as e:
  780. GError(parent=self, message=e.value, showTraceback=False)
  781. return
  782. self.result = (self.animationData, temporalMode, tempManager)
  783. self.EndModal(wx.ID_OK)
  784. class ExportDialog(wx.Dialog):
  785. def __init__(self, parent, temporal, timeTick):
  786. wx.Dialog.__init__(
  787. self,
  788. parent=parent,
  789. id=wx.ID_ANY,
  790. title=_("Export animation"),
  791. style=wx.DEFAULT_DIALOG_STYLE)
  792. self.decorations = []
  793. self.temporal = temporal
  794. self.timeTick = timeTick
  795. self._layout()
  796. # export animation
  797. self.doExport = Signal('ExportDialog::doExport')
  798. wx.CallAfter(self._hideAll)
  799. def _layout(self):
  800. notebook = wx.Notebook(self, id=wx.ID_ANY)
  801. mainSizer = wx.BoxSizer(wx.VERTICAL)
  802. notebook.AddPage(
  803. page=self._createExportFormatPanel(notebook),
  804. text=_("Format"))
  805. notebook.AddPage(
  806. page=self._createDecorationsPanel(notebook),
  807. text=_("Decorations"))
  808. mainSizer.Add(notebook, proportion=0,
  809. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  810. self.btnExport = Button(self, wx.ID_OK)
  811. self.btnExport.SetLabel(_("Export"))
  812. self.btnCancel = Button(self, wx.ID_CANCEL)
  813. self.btnExport.SetDefault()
  814. self.btnExport.Bind(wx.EVT_BUTTON, self.OnExport)
  815. # button sizer
  816. btnStdSizer = wx.StdDialogButtonSizer()
  817. btnStdSizer.AddButton(self.btnExport)
  818. btnStdSizer.AddButton(self.btnCancel)
  819. btnStdSizer.Realize()
  820. mainSizer.Add(btnStdSizer, proportion=0,
  821. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  822. self.SetSizer(mainSizer)
  823. # set the longest option to fit
  824. self.hidevbox.Show(self.fontBox, True)
  825. self.hidevbox.Show(self.imageBox, False)
  826. self.hidevbox.Show(self.textBox, True)
  827. self.hidevbox.Show(self.posBox, True)
  828. self.hidevbox.Show(self.informBox, False)
  829. mainSizer.Fit(self)
  830. def _createDecorationsPanel(self, notebook):
  831. panel = wx.Panel(notebook, id=wx.ID_ANY)
  832. sizer = wx.BoxSizer(wx.VERTICAL)
  833. sizer.Add(
  834. self._createDecorationsList(panel),
  835. proportion=0,
  836. flag=wx.ALL | wx.EXPAND,
  837. border=10)
  838. sizer.Add(
  839. self._createDecorationsProperties(panel),
  840. proportion=0,
  841. flag=wx.ALL | wx.EXPAND,
  842. border=10)
  843. panel.SetSizer(sizer)
  844. sizer.Fit(panel)
  845. return panel
  846. def _createDecorationsList(self, panel):
  847. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  848. gridBagSizer.AddGrowableCol(0)
  849. self.listbox = wx.ListBox(panel, id=wx.ID_ANY, choices=[],
  850. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  851. self.listbox.Bind(wx.EVT_LISTBOX, self.OnSelectionChanged)
  852. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(4, 1),
  853. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  854. buttonNames = ['time', 'image', 'text']
  855. buttonLabels = [_("Add time stamp"), _("Add image"), _("Add text")]
  856. i = 0
  857. for buttonName, buttonLabel in zip(buttonNames, buttonLabels):
  858. if buttonName == 'time' and self.temporal == TemporalMode.NONTEMPORAL:
  859. continue
  860. btn = Button(
  861. panel,
  862. id=wx.ID_ANY,
  863. name=buttonName,
  864. label=buttonLabel)
  865. btn.Bind(
  866. wx.EVT_BUTTON,
  867. lambda evt,
  868. temp=buttonName: self.OnAddDecoration(
  869. evt,
  870. temp))
  871. gridBagSizer.Add(
  872. btn,
  873. pos=(
  874. i,
  875. 1),
  876. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  877. border=0)
  878. i += 1
  879. removeButton = Button(panel, id=wx.ID_ANY, label=_("Remove"))
  880. removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  881. gridBagSizer.Add(
  882. removeButton,
  883. pos=(
  884. i,
  885. 1),
  886. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  887. border=0)
  888. return gridBagSizer
  889. def _createDecorationsProperties(self, panel):
  890. self.hidevbox = wx.BoxSizer(wx.VERTICAL)
  891. # inform label
  892. self.informBox = wx.BoxSizer(wx.HORIZONTAL)
  893. if self.temporal == TemporalMode.TEMPORAL:
  894. label = _(
  895. "Add time stamp, image or text decoration by one of the buttons above.")
  896. else:
  897. label = _("Add image or text decoration by one of the buttons above.")
  898. label = StaticText(panel, id=wx.ID_ANY, label=label)
  899. label.Wrap(400)
  900. self.informBox.Add(
  901. label,
  902. proportion=1,
  903. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  904. border=5)
  905. self.hidevbox.Add(
  906. self.informBox,
  907. proportion=0,
  908. flag=wx.EXPAND | wx.BOTTOM,
  909. border=5)
  910. # font
  911. self.fontBox = wx.BoxSizer(wx.HORIZONTAL)
  912. self.fontBox.Add(
  913. StaticText(
  914. panel,
  915. id=wx.ID_ANY,
  916. label=_("Font settings:")),
  917. proportion=0,
  918. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  919. border=5)
  920. self.sampleLabel = StaticText(
  921. panel, id=wx.ID_ANY, label=_("Sample text"))
  922. self.fontBox.Add(self.sampleLabel, proportion=1,
  923. flag=wx.ALIGN_CENTER | wx.RIGHT | wx.LEFT, border=5)
  924. fontButton = Button(panel, id=wx.ID_ANY, label=_("Set font"))
  925. fontButton.Bind(wx.EVT_BUTTON, self.OnFont)
  926. self.fontBox.Add(
  927. fontButton,
  928. proportion=0,
  929. flag=wx.ALIGN_CENTER_VERTICAL)
  930. self.hidevbox.Add(
  931. self.fontBox,
  932. proportion=0,
  933. flag=wx.EXPAND | wx.BOTTOM,
  934. border=5)
  935. # image
  936. self.imageBox = wx.BoxSizer(wx.HORIZONTAL)
  937. filetype, ltype = GetImageHandlers(EmptyImage(10, 10))
  938. self.browse = filebrowse.FileBrowseButton(
  939. parent=panel, id=wx.ID_ANY, fileMask=filetype,
  940. labelText=_("Image file:"),
  941. dialogTitle=_('Choose image file'),
  942. buttonText=_('Browse'),
  943. startDirectory=os.getcwd(),
  944. fileMode=wx.FD_OPEN, changeCallback=self.OnSetImage)
  945. self.imageBox.Add(self.browse, proportion=1, flag=wx.EXPAND)
  946. self.hidevbox.Add(
  947. self.imageBox,
  948. proportion=0,
  949. flag=wx.EXPAND | wx.BOTTOM,
  950. border=5)
  951. # text
  952. self.textBox = wx.BoxSizer(wx.HORIZONTAL)
  953. self.textBox.Add(
  954. StaticText(
  955. panel,
  956. id=wx.ID_ANY,
  957. label=_("Text:")),
  958. proportion=0,
  959. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  960. border=5)
  961. self.textCtrl = TextCtrl(panel, id=wx.ID_ANY)
  962. self.textCtrl.Bind(wx.EVT_TEXT, self.OnText)
  963. self.textBox.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
  964. self.hidevbox.Add(self.textBox, proportion=0, flag=wx.EXPAND)
  965. self.posBox = self._positionWidget(panel)
  966. self.hidevbox.Add(
  967. self.posBox,
  968. proportion=0,
  969. flag=wx.EXPAND | wx.TOP,
  970. border=5)
  971. return self.hidevbox
  972. def _positionWidget(self, panel):
  973. grid = wx.GridBagSizer(vgap=5, hgap=5)
  974. label = StaticText(
  975. panel, id=wx.ID_ANY, label=_(
  976. "Placement as percentage of"
  977. " screen coordinates (X: 0, Y: 0 is top left):"))
  978. label.Wrap(400)
  979. self.spinX = SpinCtrl(
  980. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  981. self.spinY = SpinCtrl(
  982. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  983. self.spinX.Bind(
  984. wx.EVT_SPINCTRL,
  985. lambda evt,
  986. temp='X': self.OnPosition(
  987. evt,
  988. temp))
  989. self.spinY.Bind(
  990. wx.EVT_SPINCTRL,
  991. lambda evt,
  992. temp='Y': self.OnPosition(
  993. evt,
  994. temp))
  995. grid.Add(label, pos=(0, 0), span=(1, 4), flag=wx.EXPAND)
  996. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("X:")), pos=(1, 0),
  997. flag=wx.ALIGN_CENTER_VERTICAL)
  998. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("Y:")), pos=(1, 2),
  999. flag=wx.ALIGN_CENTER_VERTICAL)
  1000. grid.Add(self.spinX, pos=(1, 1))
  1001. grid.Add(self.spinY, pos=(1, 3))
  1002. return grid
  1003. def _createExportFormatPanel(self, notebook):
  1004. panel = wx.Panel(notebook, id=wx.ID_ANY)
  1005. borderSizer = wx.BoxSizer(wx.VERTICAL)
  1006. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1007. choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
  1008. self.formatChoice = wx.Choice(parent=panel, id=wx.ID_ANY,
  1009. choices=choices)
  1010. self.formatChoice.SetSelection(0)
  1011. self.formatChoice.Bind(
  1012. wx.EVT_CHOICE,
  1013. lambda event: self.ChangeFormat(
  1014. event.GetSelection()))
  1015. hSizer.Add(
  1016. StaticText(
  1017. panel,
  1018. id=wx.ID_ANY,
  1019. label=_("Export to:")),
  1020. proportion=0,
  1021. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1022. border=2)
  1023. hSizer.Add(
  1024. self.formatChoice,
  1025. proportion=1,
  1026. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.ALL,
  1027. border=2)
  1028. borderSizer.Add(
  1029. hSizer,
  1030. proportion=0,
  1031. flag=wx.EXPAND | wx.ALL,
  1032. border=3)
  1033. helpSizer = wx.BoxSizer(wx.HORIZONTAL)
  1034. helpSizer.AddStretchSpacer(1)
  1035. self.formatPanelSizer = wx.BoxSizer(wx.VERTICAL)
  1036. helpSizer.Add(self.formatPanelSizer, proportion=5, flag=wx.EXPAND)
  1037. borderSizer.Add(helpSizer, proportion=1, flag=wx.EXPAND)
  1038. self.formatPanels = []
  1039. # panel for image sequence
  1040. imSeqPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1041. prefixLabel = StaticText(
  1042. imSeqPanel, id=wx.ID_ANY, label=_("File prefix:"))
  1043. self.prefixCtrl = TextCtrl(
  1044. imSeqPanel, id=wx.ID_ANY, value=_("animation_"))
  1045. formatLabel = StaticText(
  1046. imSeqPanel, id=wx.ID_ANY, label=_("File format:"))
  1047. imageTypes = ['PNG', 'JPEG', 'GIF', 'TIFF', 'PPM', 'BMP']
  1048. self.imSeqFormatChoice = wx.Choice(imSeqPanel, choices=imageTypes)
  1049. self.imSeqFormatChoice.SetSelection(0)
  1050. self.dirBrowse = filebrowse.DirBrowseButton(
  1051. parent=imSeqPanel, id=wx.ID_ANY, labelText=_("Directory:"),
  1052. dialogTitle=_("Choose directory for export"),
  1053. buttonText=_("Browse"),
  1054. startDirectory=os.getcwd())
  1055. dirGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1056. dirGridSizer.Add(
  1057. prefixLabel, pos=(0, 0),
  1058. flag=wx.ALIGN_CENTER_VERTICAL)
  1059. dirGridSizer.Add(self.prefixCtrl, pos=(0, 1), flag=wx.EXPAND)
  1060. dirGridSizer.Add(
  1061. formatLabel, pos=(1, 0),
  1062. flag=wx.ALIGN_CENTER_VERTICAL)
  1063. dirGridSizer.Add(self.imSeqFormatChoice, pos=(1, 1), flag=wx.EXPAND)
  1064. dirGridSizer.Add(
  1065. self.dirBrowse, pos=(
  1066. 2, 0), flag=wx.EXPAND, span=(
  1067. 1, 2))
  1068. dirGridSizer.AddGrowableCol(1)
  1069. imSeqPanel.SetSizer(dirGridSizer)
  1070. dirGridSizer.Fit(imSeqPanel)
  1071. self.formatPanelSizer.Add(
  1072. imSeqPanel,
  1073. proportion=1,
  1074. flag=wx.EXPAND | wx.ALL,
  1075. border=5)
  1076. self.formatPanels.append(imSeqPanel)
  1077. # panel for gif
  1078. gifPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1079. self.gifBrowse = filebrowse.FileBrowseButton(
  1080. parent=gifPanel,
  1081. id=wx.ID_ANY,
  1082. fileMask="GIF file (*.gif)|*.gif",
  1083. labelText=_("GIF file:"),
  1084. dialogTitle=_("Choose file to save animation"),
  1085. buttonText=_("Browse"),
  1086. startDirectory=os.getcwd(),
  1087. fileMode=wx.FD_SAVE)
  1088. gifGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1089. gifGridSizer.AddGrowableCol(0)
  1090. gifGridSizer.Add(self.gifBrowse, pos=(0, 0), flag=wx.EXPAND)
  1091. gifPanel.SetSizer(gifGridSizer)
  1092. gifGridSizer.Fit(gifPanel)
  1093. self.formatPanelSizer.Add(
  1094. gifPanel,
  1095. proportion=1,
  1096. flag=wx.EXPAND | wx.ALL,
  1097. border=5)
  1098. self.formatPanels.append(gifPanel)
  1099. # panel for swf
  1100. swfPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1101. self.swfBrowse = filebrowse.FileBrowseButton(
  1102. parent=swfPanel,
  1103. id=wx.ID_ANY,
  1104. fileMask="SWF file (*.swf)|*.swf",
  1105. labelText=_("SWF file:"),
  1106. dialogTitle=_("Choose file to save animation"),
  1107. buttonText=_("Browse"),
  1108. startDirectory=os.getcwd(),
  1109. fileMode=wx.FD_SAVE)
  1110. swfGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1111. swfGridSizer.AddGrowableCol(0)
  1112. swfGridSizer.Add(self.swfBrowse, pos=(0, 0), flag=wx.EXPAND)
  1113. swfPanel.SetSizer(swfGridSizer)
  1114. swfGridSizer.Fit(swfPanel)
  1115. self.formatPanelSizer.Add(
  1116. swfPanel,
  1117. proportion=1,
  1118. flag=wx.EXPAND | wx.ALL,
  1119. border=5)
  1120. self.formatPanels.append(swfPanel)
  1121. # panel for avi
  1122. aviPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1123. ffmpeg = gcore.find_program('ffmpeg', '--help')
  1124. if not ffmpeg:
  1125. warning = _(
  1126. "Program 'ffmpeg' was not found.\nPlease install it first "
  1127. "and make sure\nit's in the PATH variable.")
  1128. warningLabel = StaticText(parent=aviPanel, label=warning)
  1129. warningLabel.SetForegroundColour(wx.RED)
  1130. self.aviBrowse = filebrowse.FileBrowseButton(
  1131. parent=aviPanel,
  1132. id=wx.ID_ANY,
  1133. fileMask="AVI file (*.avi)|*.avi",
  1134. labelText=_("AVI file:"),
  1135. dialogTitle=_("Choose file to save animation"),
  1136. buttonText=_("Browse"),
  1137. startDirectory=os.getcwd(),
  1138. fileMode=wx.FD_SAVE)
  1139. encodingLabel = StaticText(
  1140. parent=aviPanel,
  1141. id=wx.ID_ANY,
  1142. label=_("Video codec:"))
  1143. self.encodingText = TextCtrl(
  1144. parent=aviPanel, id=wx.ID_ANY, value='mpeg4')
  1145. optionsLabel = StaticText(
  1146. parent=aviPanel, label=_("Additional options:"))
  1147. self.optionsText = TextCtrl(parent=aviPanel)
  1148. self.optionsText.SetToolTip(
  1149. _(
  1150. "Consider adding '-sameq' or '-qscale 1' "
  1151. "if not satisfied with video quality. "
  1152. "Options depend on ffmpeg version."))
  1153. aviGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1154. aviGridSizer.Add(
  1155. self.aviBrowse, pos=(
  1156. 0, 0), span=(
  1157. 1, 2), flag=wx.EXPAND)
  1158. aviGridSizer.Add(
  1159. encodingLabel, pos=(1, 0),
  1160. flag=wx.ALIGN_CENTER_VERTICAL)
  1161. aviGridSizer.Add(self.encodingText, pos=(1, 1), flag=wx.EXPAND)
  1162. aviGridSizer.Add(
  1163. optionsLabel, pos=(2, 0),
  1164. flag=wx.ALIGN_CENTER_VERTICAL)
  1165. aviGridSizer.Add(self.optionsText, pos=(2, 1), flag=wx.EXPAND)
  1166. if not ffmpeg:
  1167. aviGridSizer.Add(warningLabel, pos=(3, 0), span=(1, 2),
  1168. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1169. aviGridSizer.AddGrowableCol(1)
  1170. aviPanel.SetSizer(aviGridSizer)
  1171. aviGridSizer.Fit(aviPanel)
  1172. self.formatPanelSizer.Add(
  1173. aviPanel,
  1174. proportion=1,
  1175. flag=wx.EXPAND | wx.ALL,
  1176. border=5)
  1177. self.formatPanels.append(aviPanel)
  1178. fpsSizer = wx.BoxSizer(wx.HORIZONTAL)
  1179. fps = 1000 / self.timeTick
  1180. fpsSizer.Add(
  1181. StaticText(
  1182. panel,
  1183. id=wx.ID_ANY,
  1184. label=_("Current frame rate: %.2f fps") %
  1185. fps),
  1186. proportion=1,
  1187. flag=wx.EXPAND)
  1188. borderSizer.Add(
  1189. fpsSizer,
  1190. proportion=0,
  1191. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1192. border=5)
  1193. panel.SetSizer(borderSizer)
  1194. borderSizer.Fit(panel)
  1195. self.ChangeFormat(index=0)
  1196. return panel
  1197. def ChangeFormat(self, index):
  1198. for i, panel in enumerate(self.formatPanels):
  1199. self.formatPanelSizer.Show(window=panel, show=(i == index))
  1200. self.formatPanelSizer.Layout()
  1201. def OnFont(self, event):
  1202. index = self.listbox.GetSelection()
  1203. # should not happen
  1204. if index == wx.NOT_FOUND:
  1205. return
  1206. cdata = self.listbox.GetClientData(index)
  1207. font = cdata['font']
  1208. fontdata = wx.FontData()
  1209. fontdata.EnableEffects(True)
  1210. fontdata.SetColour('black')
  1211. fontdata.SetInitialFont(font)
  1212. dlg = wx.FontDialog(self, fontdata)
  1213. dlg.CenterOnParent()
  1214. if dlg.ShowModal() == wx.ID_OK:
  1215. newfontdata = dlg.GetFontData()
  1216. font = newfontdata.GetChosenFont()
  1217. self.sampleLabel.SetFont(font)
  1218. cdata['font'] = font
  1219. self.Layout()
  1220. def OnPosition(self, event, coord):
  1221. index = self.listbox.GetSelection()
  1222. # should not happen
  1223. if index == wx.NOT_FOUND:
  1224. return
  1225. cdata = self.listbox.GetClientData(index)
  1226. cdata['pos'][coord == 'Y'] = event.GetInt()
  1227. def OnSetImage(self, event):
  1228. index = self.listbox.GetSelection()
  1229. # should not happen
  1230. if index == wx.NOT_FOUND:
  1231. return
  1232. cdata = self.listbox.GetClientData(index)
  1233. cdata['file'] = event.GetString()
  1234. def OnAddDecoration(self, event, name):
  1235. if name == 'time':
  1236. timeInfo = {'name': name, 'font': self.GetFont(), 'pos': [10, 10]}
  1237. self.decorations.append(timeInfo)
  1238. elif name == 'image':
  1239. imageInfo = {'name': name, 'file': '', 'pos': [10, 10]}
  1240. self.decorations.append(imageInfo)
  1241. elif name == 'text':
  1242. textInfo = {
  1243. 'name': name,
  1244. 'font': self.GetFont(),
  1245. 'text': '',
  1246. 'pos': [
  1247. 10,
  1248. 10]}
  1249. self.decorations.append(textInfo)
  1250. self._updateListBox()
  1251. self.listbox.SetSelection(self.listbox.GetCount() - 1)
  1252. self.OnSelectionChanged(event=None)
  1253. def OnSelectionChanged(self, event):
  1254. index = self.listbox.GetSelection()
  1255. if index == wx.NOT_FOUND:
  1256. self._hideAll()
  1257. return
  1258. cdata = self.listbox.GetClientData(index)
  1259. self.hidevbox.Show(self.fontBox, (cdata['name'] in ('time', 'text')))
  1260. self.hidevbox.Show(self.imageBox, (cdata['name'] == 'image'))
  1261. self.hidevbox.Show(self.textBox, (cdata['name'] == 'text'))
  1262. self.hidevbox.Show(self.posBox, True)
  1263. self.hidevbox.Show(self.informBox, False)
  1264. self.spinX.SetValue(cdata['pos'][0])
  1265. self.spinY.SetValue(cdata['pos'][1])
  1266. if cdata['name'] == 'image':
  1267. self.browse.SetValue(cdata['file'])
  1268. elif cdata['name'] in ('time', 'text'):
  1269. self.sampleLabel.SetFont(cdata['font'])
  1270. if cdata['name'] == 'text':
  1271. self.textCtrl.SetValue(cdata['text'])
  1272. self.hidevbox.Layout()
  1273. # self.Layout()
  1274. def OnText(self, event):
  1275. index = self.listbox.GetSelection()
  1276. # should not happen
  1277. if index == wx.NOT_FOUND:
  1278. return
  1279. cdata = self.listbox.GetClientData(index)
  1280. cdata['text'] = event.GetString()
  1281. def OnRemove(self, event):
  1282. index = self.listbox.GetSelection()
  1283. if index == wx.NOT_FOUND:
  1284. return
  1285. decData = self.listbox.GetClientData(index)
  1286. self.decorations.remove(decData)
  1287. self._updateListBox()
  1288. if self.listbox.GetCount():
  1289. self.listbox.SetSelection(0)
  1290. self.OnSelectionChanged(event=None)
  1291. def OnExport(self, event):
  1292. for decor in self.decorations:
  1293. if decor['name'] == 'image':
  1294. if not os.path.exists(decor['file']):
  1295. if decor['file']:
  1296. GError(
  1297. parent=self,
  1298. message=_("File %s not found.") %
  1299. decor['file'])
  1300. else:
  1301. GError(parent=self,
  1302. message=_("Decoration image file is missing."))
  1303. return
  1304. if self.formatChoice.GetSelection() == 0:
  1305. name = self.dirBrowse.GetValue()
  1306. if not os.path.exists(name):
  1307. if name:
  1308. GError(
  1309. parent=self,
  1310. message=_("Directory %s not found.") %
  1311. name)
  1312. else:
  1313. GError(parent=self, message=_(
  1314. "Export directory is missing."))
  1315. return
  1316. elif self.formatChoice.GetSelection() == 1:
  1317. if not self.gifBrowse.GetValue():
  1318. GError(parent=self, message=_("Export file is missing."))
  1319. return
  1320. elif self.formatChoice.GetSelection() == 2:
  1321. if not self.swfBrowse.GetValue():
  1322. GError(parent=self, message=_("Export file is missing."))
  1323. return
  1324. # hide only to keep previous values
  1325. self.Hide()
  1326. self.doExport.emit(exportInfo=self.GetExportInformation(),
  1327. decorations=self.GetDecorations())
  1328. def GetDecorations(self):
  1329. return self.decorations
  1330. def GetExportInformation(self):
  1331. info = {}
  1332. if self.formatChoice.GetSelection() == 0:
  1333. info['method'] = 'sequence'
  1334. info['directory'] = self.dirBrowse.GetValue()
  1335. info['prefix'] = self.prefixCtrl.GetValue()
  1336. info['format'] = self.imSeqFormatChoice.GetStringSelection()
  1337. elif self.formatChoice.GetSelection() == 1:
  1338. info['method'] = 'gif'
  1339. info['file'] = self.gifBrowse.GetValue()
  1340. elif self.formatChoice.GetSelection() == 2:
  1341. info['method'] = 'swf'
  1342. info['file'] = self.swfBrowse.GetValue()
  1343. elif self.formatChoice.GetSelection() == 3:
  1344. info['method'] = 'avi'
  1345. info['file'] = self.aviBrowse.GetValue()
  1346. info['encoding'] = self.encodingText.GetValue()
  1347. info['options'] = self.optionsText.GetValue()
  1348. return info
  1349. def _updateListBox(self):
  1350. self.listbox.Clear()
  1351. names = {
  1352. 'time': _("Time stamp"),
  1353. 'image': _("Image"),
  1354. 'text': _("Text")}
  1355. for decor in self.decorations:
  1356. self.listbox.Append(names[decor['name']], clientData=decor)
  1357. def _hideAll(self):
  1358. self.hidevbox.Show(self.fontBox, False)
  1359. self.hidevbox.Show(self.imageBox, False)
  1360. self.hidevbox.Show(self.textBox, False)
  1361. self.hidevbox.Show(self.posBox, False)
  1362. self.hidevbox.Show(self.informBox, True)
  1363. self.hidevbox.Layout()
  1364. class AnimSimpleLayerManager(SimpleLayerManager):
  1365. """Simple layer manager for animation tool.
  1366. Allows adding space-time dataset or series of maps.
  1367. """
  1368. def __init__(self, parent, layerList,
  1369. lmgrStyle=SIMPLE_LMGR_RASTER | SIMPLE_LMGR_VECTOR |
  1370. SIMPLE_LMGR_TB_TOP | SIMPLE_LMGR_STDS,
  1371. toolbarCls=AnimSimpleLmgrToolbar, modal=True):
  1372. SimpleLayerManager.__init__(
  1373. self, parent, layerList, lmgrStyle, toolbarCls, modal)
  1374. self._3dActivated = False
  1375. def OnAddStds(self, event):
  1376. """Opens dialog for specifying temporal dataset.
  1377. Dummy layer is added first."""
  1378. layer = AnimLayer()
  1379. layer.hidden = True
  1380. self._layerList.AddLayer(layer)
  1381. self.SetStdsProperties(layer)
  1382. event.Skip()
  1383. def SetStdsProperties(self, layer):
  1384. dlg = AddTemporalLayerDialog(
  1385. parent=self, layer=layer, volume=self._3dActivated)
  1386. # first get hidden property, it's altered afterwards
  1387. hidden = layer.hidden
  1388. dlg.CenterOnParent()
  1389. if dlg.ShowModal() == wx.ID_OK:
  1390. layer = dlg.GetLayer()
  1391. if hidden:
  1392. signal = self.layerAdded
  1393. else:
  1394. signal = self.cmdChanged
  1395. signal.emit(
  1396. index=self._layerList.GetLayerIndex(layer),
  1397. layer=layer)
  1398. else:
  1399. if hidden:
  1400. self._layerList.RemoveLayer(layer)
  1401. dlg.Destroy()
  1402. self._update()
  1403. self.anyChange.emit()
  1404. def _layerChangeProperties(self, layer):
  1405. """Opens new module dialog or recycles it."""
  1406. if not hasattr(layer, 'maps'):
  1407. GUI(parent=self, giface=None, modal=self._modal).ParseCommand(
  1408. cmd=layer.cmd, completed=(self.GetOptData, layer, ''))
  1409. else:
  1410. self.SetStdsProperties(layer)
  1411. def Activate3D(self, activate=True):
  1412. """Activates/deactivates certain tool depending on 2D/3D view."""
  1413. self._toolbar.EnableTools(['addRaster', 'addVector',
  1414. 'opacity', 'up', 'down'], not activate)
  1415. self._3dActivated = activate
  1416. class AddTemporalLayerDialog(wx.Dialog):
  1417. """Dialog for adding space-time dataset/ map series."""
  1418. def __init__(self, parent, layer, volume=False,
  1419. title=_("Add space-time dataset layer")):
  1420. wx.Dialog.__init__(self, parent=parent, title=title)
  1421. self.layer = layer
  1422. self._mapType = None
  1423. self._name = None
  1424. self._cmd = None
  1425. self.tselect = Select(parent=self, type='strds')
  1426. iconTheme = UserSettings.Get(
  1427. group='appearance',
  1428. key='iconTheme',
  1429. subkey='type')
  1430. bitmapPath = os.path.join(
  1431. globalvar.ICONDIR,
  1432. iconTheme,
  1433. 'layer-open.png')
  1434. if os.path.isfile(bitmapPath) and os.path.getsize(bitmapPath):
  1435. bitmap = wx.Bitmap(name=bitmapPath)
  1436. else:
  1437. bitmap = wx.ArtProvider.GetBitmap(
  1438. id=wx.ART_MISSING_IMAGE, client=wx.ART_TOOLBAR)
  1439. self.addManyMapsButton = BitmapButton(self, bitmap=bitmap)
  1440. self.addManyMapsButton.Bind(wx.EVT_BUTTON, self._onAddMaps)
  1441. types = [('raster', _("Multiple raster maps")),
  1442. ('vector', _("Multiple vector maps")),
  1443. ('raster_3d', _("Multiple 3D raster maps")),
  1444. ('strds', _("Space time raster dataset")),
  1445. ('stvds', _("Space time vector dataset")),
  1446. ('str3ds', _("Space time 3D raster dataset"))]
  1447. if not volume:
  1448. del types[5]
  1449. del types[2]
  1450. self._types = dict(types)
  1451. self.tchoice = wx.Choice(parent=self)
  1452. for type_, text in types:
  1453. self.tchoice.Append(text, clientData=type_)
  1454. self.editBtn = Button(parent=self, label='Set properties')
  1455. self.okBtn = Button(parent=self, id=wx.ID_OK)
  1456. self.cancelBtn = Button(parent=self, id=wx.ID_CANCEL)
  1457. self.okBtn.Bind(wx.EVT_BUTTON, self._onOK)
  1458. self.editBtn.Bind(wx.EVT_BUTTON, self._onProperties)
  1459. self.tchoice.Bind(wx.EVT_CHOICE,
  1460. lambda evt: self._setType())
  1461. self.tselect.Bind(wx.EVT_TEXT,
  1462. lambda evt: self._datasetChanged())
  1463. if self.layer.mapType:
  1464. self._setType(self.layer.mapType)
  1465. else:
  1466. self._setType('raster')
  1467. if self.layer.name:
  1468. self.tselect.SetValue(self.layer.name)
  1469. if self.layer.cmd:
  1470. self._cmd = self.layer.cmd
  1471. self._layout()
  1472. self.SetSize(self.GetBestSize())
  1473. def _layout(self):
  1474. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1475. bodySizer = wx.BoxSizer(wx.VERTICAL)
  1476. typeSizer = wx.BoxSizer(wx.HORIZONTAL)
  1477. selectSizer = wx.BoxSizer(wx.HORIZONTAL)
  1478. typeSizer.Add(StaticText(self, label=_("Input data type:")),
  1479. flag=wx.ALIGN_CENTER_VERTICAL)
  1480. typeSizer.AddStretchSpacer()
  1481. typeSizer.Add(self.tchoice)
  1482. bodySizer.Add(typeSizer, flag=wx.EXPAND | wx.BOTTOM, border=5)
  1483. selectSizer.Add(self.tselect, flag=wx.RIGHT |
  1484. wx.ALIGN_CENTER_VERTICAL, border=5)
  1485. selectSizer.Add(self.addManyMapsButton, flag=wx.EXPAND)
  1486. bodySizer.Add(selectSizer, flag=wx.BOTTOM, border=5)
  1487. bodySizer.Add(self.editBtn, flag=wx.BOTTOM, border=5)
  1488. mainSizer.Add(
  1489. bodySizer,
  1490. proportion=1,
  1491. flag=wx.EXPAND | wx.ALL,
  1492. border=10)
  1493. btnSizer = wx.StdDialogButtonSizer()
  1494. btnSizer.AddButton(self.okBtn)
  1495. btnSizer.AddButton(self.cancelBtn)
  1496. btnSizer.Realize()
  1497. mainSizer.Add(btnSizer, proportion=0,
  1498. flag=wx.EXPAND | wx.ALL, border=10)
  1499. self.SetSizer(mainSizer)
  1500. mainSizer.Fit(self)
  1501. def _datasetChanged(self):
  1502. if self._name != self.tselect.GetValue():
  1503. self._name = self.tselect.GetValue()
  1504. self._cmd = None
  1505. def _setType(self, typeName=None):
  1506. if typeName:
  1507. self.tchoice.SetStringSelection(self._types[typeName])
  1508. self.tselect.SetType(typeName)
  1509. if typeName in ('strds', 'stvds', 'str3ds'):
  1510. self.tselect.SetType(typeName, multiple=False)
  1511. self.addManyMapsButton.Disable()
  1512. else:
  1513. self.tselect.SetType(typeName, multiple=True)
  1514. self.addManyMapsButton.Enable()
  1515. self._mapType = typeName
  1516. self.tselect.SetValue('')
  1517. else:
  1518. typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
  1519. if typeName in ('strds', 'stvds', 'str3ds'):
  1520. self.tselect.SetType(typeName, multiple=False)
  1521. self.addManyMapsButton.Disable()
  1522. else:
  1523. self.tselect.SetType(typeName, multiple=True)
  1524. self.addManyMapsButton.Enable()
  1525. if typeName != self._mapType:
  1526. self._cmd = None
  1527. self._mapType = typeName
  1528. self.tselect.SetValue('')
  1529. def _createDefaultCommand(self):
  1530. cmd = []
  1531. if self._mapType in ('raster', 'strds'):
  1532. cmd.append('d.rast')
  1533. elif self._mapType in ('vector', 'stvds'):
  1534. cmd.append('d.vect')
  1535. elif self._mapType in ('raster_3d', 'str3ds'):
  1536. cmd.append('d.rast3d')
  1537. if self._name:
  1538. if self._mapType in ('raster', 'vector', 'raster_3d'):
  1539. cmd.append('map={name}'.format(name=self._name.split(',')[0]))
  1540. else:
  1541. try:
  1542. maps = getRegisteredMaps(self._name, etype=self._mapType)
  1543. if maps:
  1544. mapName, mapLayer = getNameAndLayer(maps[0])
  1545. cmd.append('map={name}'.format(name=mapName))
  1546. except gcore.ScriptError as e:
  1547. GError(parent=self, message=str(e), showTraceback=False)
  1548. return None
  1549. return cmd
  1550. def _onAddMaps(self, event):
  1551. dlg = MapLayersDialog(self, title=_("Select raster/vector maps."))
  1552. dlg.applyAddingMapLayers.connect(
  1553. lambda mapLayers: self.tselect.SetValue(
  1554. ','.join(mapLayers)))
  1555. if self._mapType == 'raster':
  1556. index = 0
  1557. elif self._mapType == 'vector':
  1558. index = 2
  1559. else: # rast3d
  1560. index = 1
  1561. dlg.layerType.SetSelection(index)
  1562. dlg.LoadMapLayers(dlg.GetLayerType(cmd=True),
  1563. dlg.mapset.GetStringSelection())
  1564. dlg.CenterOnParent()
  1565. if dlg.ShowModal() == wx.ID_OK:
  1566. self.tselect.SetValue(','.join(dlg.GetMapLayers()))
  1567. dlg.Destroy()
  1568. def _onProperties(self, event):
  1569. self._checkInput()
  1570. if self._cmd:
  1571. GUI(parent=self, show=True, modal=True).ParseCommand(
  1572. cmd=self._cmd, completed=(self._getOptData, '', ''))
  1573. def _checkInput(self):
  1574. if not self.tselect.GetValue():
  1575. GMessage(parent=self, message=_(
  1576. "Please select maps or dataset first."))
  1577. return
  1578. if not self._cmd:
  1579. self._cmd = self._createDefaultCommand()
  1580. def _getOptData(self, dcmd, layer, params, propwin):
  1581. if dcmd:
  1582. self._cmd = dcmd
  1583. def _onOK(self, event):
  1584. self._checkInput()
  1585. if self._cmd:
  1586. try:
  1587. self.layer.hidden = False
  1588. self.layer.mapType = self._mapType
  1589. self.layer.name = self._name
  1590. self.layer.cmd = self._cmd
  1591. event.Skip()
  1592. except (GException, gcore.ScriptError) as e:
  1593. GError(parent=self, message=str(e))
  1594. def GetLayer(self):
  1595. return self.layer
  1596. class PreferencesDialog(PreferencesBaseDialog):
  1597. """Animation preferences dialog"""
  1598. def __init__(self, parent, giface, title=_("Animation Tool settings"),
  1599. settings=UserSettings):
  1600. PreferencesBaseDialog.__init__(
  1601. self, parent=parent, giface=giface, title=title, settings=settings,
  1602. size=(-1, 270))
  1603. self.formatChanged = Signal('PreferencesDialog.formatChanged')
  1604. self._timeFormats = ['%Y-%m-%d %H:%M:%S', # 2013-12-29 11:16:26
  1605. '%Y-%m-%d', # 2013-12-29
  1606. '%c',
  1607. # Sun Dec 29 11:16:26 2013 (locale-dependent)
  1608. '%x', # 12/29/13 (locale-dependent)
  1609. '%X', # 11:16:26 (locale-dependent)
  1610. '%b %d, %Y', # Dec 29, 2013
  1611. '%B %d, %Y', # December 29, 2013
  1612. '%B, %Y', # December 2013
  1613. '%I:%M %p', # 11:16 AM
  1614. '%I %p', # 11 AM
  1615. ]
  1616. self._format = None
  1617. self._initFormat = self.settings.Get(group='animation', key='temporal',
  1618. subkey='format')
  1619. # create notebook pages
  1620. self._createGeneralPage(self.notebook)
  1621. self._createTemporalPage(self.notebook)
  1622. self.SetMinSize(self.GetBestSize())
  1623. self.SetSize(self.size)
  1624. def _createGeneralPage(self, notebook):
  1625. """Create notebook page for general settings"""
  1626. panel = SP.ScrolledPanel(parent=notebook)
  1627. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1628. notebook.AddPage(page=panel, text=_("General"))
  1629. border = wx.BoxSizer(wx.VERTICAL)
  1630. sizer = wx.BoxSizer(wx.VERTICAL)
  1631. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1632. row = 0
  1633. gridSizer.Add(
  1634. StaticText(
  1635. parent=panel,
  1636. label=_("Background color:")),
  1637. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1638. pos=(
  1639. row,
  1640. 0))
  1641. color = csel.ColourSelect(
  1642. parent=panel,
  1643. colour=UserSettings.Get(
  1644. group='animation',
  1645. key='bgcolor',
  1646. subkey='color'),
  1647. size=globalvar.DIALOG_COLOR_SIZE)
  1648. color.SetName('GetColour')
  1649. self.winId['animation:bgcolor:color'] = color.GetId()
  1650. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1651. row += 1
  1652. gridSizer.Add(
  1653. StaticText(
  1654. parent=panel,
  1655. label=_("Number of parallel processes:")),
  1656. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1657. pos=(
  1658. row,
  1659. 0))
  1660. # when running for the first time, set nprocs based on the number of
  1661. # processes
  1662. if UserSettings.Get(group='animation', key='nprocs',
  1663. subkey='value') == -1:
  1664. UserSettings.Set(
  1665. group='animation',
  1666. key='nprocs',
  1667. subkey='value',
  1668. value=getCpuCount())
  1669. nprocs = SpinCtrl(
  1670. parent=panel,
  1671. initial=UserSettings.Get(
  1672. group='animation',
  1673. key='nprocs',
  1674. subkey='value'))
  1675. nprocs.SetName('GetValue')
  1676. self.winId['animation:nprocs:value'] = nprocs.GetId()
  1677. gridSizer.Add(nprocs, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1678. row += 1
  1679. gridSizer.Add(
  1680. StaticText(
  1681. parent=panel,
  1682. label=_("Text foreground color:")),
  1683. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1684. pos=(
  1685. row,
  1686. 0))
  1687. color = csel.ColourSelect(
  1688. parent=panel,
  1689. colour=UserSettings.Get(
  1690. group='animation',
  1691. key='font',
  1692. subkey='fgcolor'),
  1693. size=globalvar.DIALOG_COLOR_SIZE)
  1694. color.SetName('GetColour')
  1695. self.winId['animation:font:fgcolor'] = color.GetId()
  1696. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1697. row += 1
  1698. gridSizer.Add(
  1699. StaticText(
  1700. parent=panel,
  1701. label=_("Text background color:")),
  1702. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1703. pos=(
  1704. row,
  1705. 0))
  1706. color = csel.ColourSelect(
  1707. parent=panel,
  1708. colour=UserSettings.Get(
  1709. group='animation',
  1710. key='font',
  1711. subkey='bgcolor'),
  1712. size=globalvar.DIALOG_COLOR_SIZE)
  1713. color.SetName('GetColour')
  1714. self.winId['animation:font:bgcolor'] = color.GetId()
  1715. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1716. gridSizer.AddGrowableCol(1)
  1717. sizer.Add(
  1718. gridSizer,
  1719. proportion=1,
  1720. flag=wx.ALL | wx.EXPAND,
  1721. border=3)
  1722. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1723. panel.SetSizer(border)
  1724. return panel
  1725. def _createTemporalPage(self, notebook):
  1726. """Create notebook page for temporal settings"""
  1727. panel = SP.ScrolledPanel(parent=notebook)
  1728. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1729. notebook.AddPage(page=panel, text=_("Time"))
  1730. border = wx.BoxSizer(wx.VERTICAL)
  1731. sizer = wx.BoxSizer(wx.VERTICAL)
  1732. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1733. row = 0
  1734. gridSizer.Add(
  1735. StaticText(
  1736. parent=panel,
  1737. label=_("Absolute time format:")),
  1738. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1739. pos=(
  1740. row,
  1741. 0))
  1742. self.tempFormat = ComboBox(parent=panel, name='GetValue')
  1743. self.tempFormat.SetItems(self._timeFormats)
  1744. self.tempFormat.SetValue(self._initFormat)
  1745. self.winId['animation:temporal:format'] = self.tempFormat.GetId()
  1746. gridSizer.Add(self.tempFormat, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1747. self.infoTimeLabel = StaticText(parent=panel)
  1748. self.tempFormat.Bind(
  1749. wx.EVT_COMBOBOX,
  1750. lambda evt: self._setTimeFormat(
  1751. self.tempFormat.GetValue()))
  1752. self.tempFormat.Bind(
  1753. wx.EVT_TEXT, lambda evt: self._setTimeFormat(
  1754. self.tempFormat.GetValue()))
  1755. self.tempFormat.SetToolTip(
  1756. _(
  1757. "Click and then press key up or down to preview "
  1758. "different date and time formats. "
  1759. "Type custom format string."))
  1760. row += 1
  1761. gridSizer.Add(self.infoTimeLabel, pos=(row, 0), span=(1, 2),
  1762. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1763. self._setTimeFormat(self.tempFormat.GetValue())
  1764. row += 1
  1765. link = HyperlinkCtrl(
  1766. panel, id=wx.ID_ANY,
  1767. label=_("Learn more about formatting options"),
  1768. url="http://docs.python.org/2/library/datetime.html#"
  1769. "strftime-and-strptime-behavior")
  1770. link.SetNormalColour(
  1771. wx.SystemSettings.GetColour(
  1772. wx.SYS_COLOUR_GRAYTEXT))
  1773. link.SetVisitedColour(
  1774. wx.SystemSettings.GetColour(
  1775. wx.SYS_COLOUR_GRAYTEXT))
  1776. gridSizer.Add(link, pos=(row, 0), span=(1, 2),
  1777. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1778. row += 2
  1779. noDataCheck = CheckBox(
  1780. panel, label=_("Display instances with no data"))
  1781. noDataCheck.SetToolTip(
  1782. _(
  1783. "When animating instant-based data which have irregular timestamps "
  1784. "you can display 'no data frame' (checked option) or "
  1785. "keep last frame."))
  1786. noDataCheck.SetValue(
  1787. self.settings.Get(
  1788. group='animation',
  1789. key='temporal',
  1790. subkey=[
  1791. 'nodata',
  1792. 'enable']))
  1793. self.winId['animation:temporal:nodata:enable'] = noDataCheck.GetId()
  1794. gridSizer.Add(noDataCheck, pos=(row, 0), span=(1, 2),
  1795. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1796. gridSizer.AddGrowableCol(1)
  1797. sizer.Add(
  1798. gridSizer,
  1799. proportion=1,
  1800. flag=wx.ALL | wx.EXPAND,
  1801. border=3)
  1802. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1803. panel.SetSizer(border)
  1804. return panel
  1805. def _setTimeFormat(self, formatString):
  1806. now = datetime.datetime.now()
  1807. try:
  1808. label = datetime.datetime.strftime(now, formatString)
  1809. self._format = formatString
  1810. except ValueError:
  1811. label = _("Invalid")
  1812. self.infoTimeLabel.SetLabel(label)
  1813. self.infoTimeLabel.GetContainingSizer().Layout()
  1814. def _updateSettings(self):
  1815. self.tempFormat.SetValue(self._format)
  1816. PreferencesBaseDialog._updateSettings(self)
  1817. if self._format != self._initFormat:
  1818. self.formatChanged.emit()
  1819. return True
  1820. def test():
  1821. import wx.lib.inspection
  1822. app = wx.App()
  1823. # testTemporalLayer()
  1824. # testAnimLmgr()
  1825. testAnimInput()
  1826. # wx.lib.inspection.InspectionTool().Show()
  1827. app.MainLoop()
  1828. def testAnimInput():
  1829. anim = AnimationData()
  1830. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1831. dlg = InputDialog(parent=None, mode='add', animationData=anim)
  1832. dlg.Show()
  1833. def testAnimEdit():
  1834. anim = AnimationData()
  1835. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1836. dlg = EditDialog(parent=None, animationData=[anim])
  1837. dlg.Show()
  1838. def testExport():
  1839. dlg = ExportDialog(parent=None, temporal=TemporalMode.TEMPORAL,
  1840. timeTick=200)
  1841. if dlg.ShowModal() == wx.ID_OK:
  1842. print(dlg.GetDecorations())
  1843. print(dlg.GetExportInformation())
  1844. dlg.Destroy()
  1845. else:
  1846. dlg.Destroy()
  1847. def testTemporalLayer():
  1848. frame = wx.Frame(None)
  1849. frame.Show()
  1850. layer = AnimLayer()
  1851. dlg = AddTemporalLayerDialog(parent=frame, layer=layer)
  1852. if dlg.ShowModal() == wx.ID_OK:
  1853. layer = dlg.GetLayer()
  1854. print(layer.name, layer.cmd, layer.mapType)
  1855. dlg.Destroy()
  1856. else:
  1857. dlg.Destroy()
  1858. def testAnimLmgr():
  1859. from core.layerlist import LayerList
  1860. frame = wx.Frame(None)
  1861. mgr = AnimSimpleLayerManager(parent=frame, layerList=LayerList())
  1862. frame.mgr = mgr
  1863. frame.Show()
  1864. if __name__ == '__main__':
  1865. gcore.set_raise_on_error(True)
  1866. test()