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 core.utils import _
  35. from gui_core.gselect import Select
  36. from gui_core.widgets import FloatValidator
  37. from gui_core.wrap import SpinCtrl, CheckBox, TextCtrl, Button, \
  38. BitmapButton, StaticText, StaticBox, Choice, RadioButton
  39. from animation.utils import TemporalMode, getRegisteredMaps, getNameAndLayer, getCpuCount
  40. from animation.data import AnimationData, AnimLayer
  41. from animation.toolbars import AnimSimpleLmgrToolbar, SIMPLE_LMGR_STDS
  42. from gui_core.simplelmgr import SimpleLayerManager, \
  43. SIMPLE_LMGR_RASTER, SIMPLE_LMGR_VECTOR, SIMPLE_LMGR_TB_TOP
  44. from grass.pydispatch.signal import Signal
  45. import grass.script.core as gcore
  46. class SpeedDialog(wx.Dialog):
  47. def __init__(self, parent, title=_("Adjust speed of animation"),
  48. temporalMode=None, minimumDuration=0, timeGranularity=None,
  49. initialSpeed=200):
  50. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
  51. style=wx.DEFAULT_DIALOG_STYLE)
  52. # signal emitted when speed has changed; has attribute 'ms'
  53. self.speedChanged = Signal('SpeedDialog.speedChanged')
  54. self.minimumDuration = minimumDuration
  55. # self.framesCount = framesCount
  56. self.defaultSpeed = initialSpeed
  57. self.lastAppliedValue = self.defaultSpeed
  58. self.lastAppliedValueTemp = self.defaultSpeed
  59. self._layout()
  60. self.temporalMode = temporalMode
  61. self.timeGranularity = timeGranularity
  62. self._fillUnitChoice(self.choiceUnits)
  63. self.InitTimeSpin(self.defaultSpeed)
  64. def SetTimeGranularity(self, gran):
  65. self._timeGranularity = gran
  66. def GetTimeGranularity(self):
  67. return self._timeGranularity
  68. timeGranularity = property(
  69. fset=SetTimeGranularity,
  70. fget=GetTimeGranularity)
  71. def SetTemporalMode(self, mode):
  72. self._temporalMode = mode
  73. self._setTemporalMode()
  74. def GetTemporalMode(self):
  75. return self._temporalMode
  76. temporalMode = property(fset=SetTemporalMode, fget=GetTemporalMode)
  77. def _layout(self):
  78. """Layout window"""
  79. mainSizer = wx.BoxSizer(wx.VERTICAL)
  80. #
  81. # simple mode
  82. #
  83. self.nontemporalBox = StaticBox(parent=self, id=wx.ID_ANY,
  84. label=' %s ' % _("Simple mode"))
  85. box = wx.StaticBoxSizer(self.nontemporalBox, wx.VERTICAL)
  86. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  87. labelDuration = StaticText(
  88. self, id=wx.ID_ANY, label=_("Frame duration:"))
  89. labelUnits = StaticText(self, id=wx.ID_ANY, label=_("ms"))
  90. self.spinDuration = SpinCtrl(
  91. self,
  92. id=wx.ID_ANY,
  93. min=self.minimumDuration,
  94. max=10000,
  95. initial=self.defaultSpeed)
  96. # TODO total time
  97. gridSizer.Add(
  98. labelDuration, pos=(0, 0),
  99. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  100. gridSizer.Add(self.spinDuration, pos=(0, 1), flag=wx.ALIGN_CENTER)
  101. gridSizer.Add(
  102. labelUnits, pos=(0, 2),
  103. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  104. gridSizer.AddGrowableCol(0)
  105. box.Add(
  106. gridSizer,
  107. proportion=1,
  108. border=5,
  109. flag=wx.ALL | wx.EXPAND)
  110. self.nontemporalSizer = gridSizer
  111. mainSizer.Add(
  112. box,
  113. proportion=0,
  114. flag=wx.EXPAND | wx.ALL,
  115. border=5)
  116. #
  117. # temporal mode
  118. #
  119. self.temporalBox = StaticBox(parent=self, id=wx.ID_ANY,
  120. label=' %s ' % _("Temporal mode"))
  121. box = wx.StaticBoxSizer(self.temporalBox, wx.VERTICAL)
  122. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  123. labelTimeUnit = StaticText(
  124. self, id=wx.ID_ANY, label=_("Time unit:"))
  125. labelDuration = StaticText(
  126. self, id=wx.ID_ANY, label=_("Duration of time unit:"))
  127. labelUnits = StaticText(self, id=wx.ID_ANY, label=_("ms"))
  128. self.spinDurationTemp = SpinCtrl(
  129. self, id=wx.ID_ANY, min=self.minimumDuration, max=10000,
  130. initial=self.defaultSpeed)
  131. self.choiceUnits = wx.Choice(self, id=wx.ID_ANY)
  132. # TODO total time
  133. gridSizer.Add(
  134. labelTimeUnit, pos=(0, 0),
  135. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  136. gridSizer.Add(self.choiceUnits, pos=(0, 1),
  137. flag=wx.ALIGN_CENTER | wx.EXPAND)
  138. gridSizer.Add(
  139. labelDuration, pos=(1, 0),
  140. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  141. gridSizer.Add(
  142. self.spinDurationTemp, pos=(
  143. 1, 1), flag=wx.ALIGN_CENTER | wx.EXPAND)
  144. gridSizer.Add(
  145. labelUnits, pos=(1, 2),
  146. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  147. gridSizer.AddGrowableCol(1)
  148. self.temporalSizer = gridSizer
  149. box.Add(
  150. gridSizer,
  151. proportion=1,
  152. border=5,
  153. flag=wx.ALL | wx.EXPAND)
  154. mainSizer.Add(
  155. box,
  156. proportion=0,
  157. flag=wx.EXPAND | wx.ALL,
  158. border=5)
  159. self.btnOk = Button(self, wx.ID_OK)
  160. self.btnApply = Button(self, wx.ID_APPLY)
  161. self.btnCancel = Button(self, wx.ID_CANCEL)
  162. self.btnOk.SetDefault()
  163. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  164. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  165. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  166. self.Bind(wx.EVT_CLOSE, self.OnCancel)
  167. # button sizer
  168. btnStdSizer = wx.StdDialogButtonSizer()
  169. btnStdSizer.AddButton(self.btnOk)
  170. btnStdSizer.AddButton(self.btnApply)
  171. btnStdSizer.AddButton(self.btnCancel)
  172. btnStdSizer.Realize()
  173. mainSizer.Add(btnStdSizer, proportion=0,
  174. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  175. self.SetSizer(mainSizer)
  176. mainSizer.Fit(self)
  177. def _setTemporalMode(self):
  178. self.nontemporalBox.Enable(
  179. self.temporalMode == TemporalMode.NONTEMPORAL)
  180. self.temporalBox.Enable(self.temporalMode == TemporalMode.TEMPORAL)
  181. for child in self.temporalSizer.GetChildren():
  182. child.GetWindow().Enable(self.temporalMode == TemporalMode.TEMPORAL)
  183. for child in self.nontemporalSizer.GetChildren():
  184. child.GetWindow().Enable(self.temporalMode == TemporalMode.NONTEMPORAL)
  185. self.Layout()
  186. def _fillUnitChoice(self, choiceWidget):
  187. timeUnitsChoice = [
  188. _("year"),
  189. _("month"),
  190. _("day"),
  191. _("hour"),
  192. _("minute"),
  193. _("second")]
  194. timeUnits = ["years", "months", "days", "hours", "minutes", "seconds"]
  195. for item, cdata in zip(timeUnitsChoice, timeUnits):
  196. choiceWidget.Append(item, cdata)
  197. if self.temporalMode == TemporalMode.TEMPORAL:
  198. unit = self.timeGranularity[1]
  199. index = 0
  200. for i, timeUnit in enumerate(timeUnits):
  201. if timeUnit.startswith(unit):
  202. index = i
  203. break
  204. choiceWidget.SetSelection(index)
  205. else:
  206. choiceWidget.SetSelection(0)
  207. def OnOk(self, event):
  208. self._apply()
  209. self.OnCancel(None)
  210. def OnApply(self, event):
  211. self._apply()
  212. def OnCancel(self, event):
  213. self.spinDuration.SetValue(self.lastAppliedValue)
  214. self.spinDurationTemp.SetValue(self.lastAppliedValueTemp)
  215. self.Hide()
  216. def InitTimeSpin(self, timeTick):
  217. if self.temporalMode == TemporalMode.TEMPORAL:
  218. index = self.choiceUnits.GetSelection()
  219. unit = self.choiceUnits.GetClientData(index)
  220. delta = self._timedelta(unit=unit, number=1)
  221. seconds1 = self._total_seconds(delta)
  222. number, unit = self.timeGranularity
  223. number = float(number)
  224. delta = self._timedelta(unit=unit, number=number)
  225. seconds2 = self._total_seconds(delta)
  226. value = timeTick
  227. ms = value * seconds1 / float(seconds2)
  228. self.spinDurationTemp.SetValue(ms)
  229. else:
  230. self.spinDuration.SetValue(timeTick)
  231. def _apply(self):
  232. if self.temporalMode == TemporalMode.NONTEMPORAL:
  233. ms = self.spinDuration.GetValue()
  234. self.lastAppliedValue = self.spinDuration.GetValue()
  235. elif self.temporalMode == TemporalMode.TEMPORAL:
  236. index = self.choiceUnits.GetSelection()
  237. unit = self.choiceUnits.GetClientData(index)
  238. delta = self._timedelta(unit=unit, number=1)
  239. seconds1 = self._total_seconds(delta)
  240. number, unit = self.timeGranularity
  241. number = float(number)
  242. delta = self._timedelta(unit=unit, number=number)
  243. seconds2 = self._total_seconds(delta)
  244. value = self.spinDurationTemp.GetValue()
  245. ms = value * seconds2 / float(seconds1)
  246. # minimumDuration set to 0, too restrictive
  247. if ms < self.minimumDuration:
  248. GMessage(parent=self, message=_(
  249. "Animation speed is too high."))
  250. return
  251. self.lastAppliedValueTemp = self.spinDurationTemp.GetValue()
  252. else:
  253. return
  254. self.speedChanged.emit(ms=ms)
  255. def _timedelta(self, unit, number):
  256. if unit in "years":
  257. delta = datetime.timedelta(days=365.25 * number)
  258. elif unit in "months":
  259. delta = datetime.timedelta(days=30.4375 * number) # 365.25/12
  260. elif unit in "days":
  261. delta = datetime.timedelta(days=1 * number)
  262. elif unit in "hours":
  263. delta = datetime.timedelta(hours=1 * number)
  264. elif unit in "minutes":
  265. delta = datetime.timedelta(minutes=1 * number)
  266. elif unit in "seconds":
  267. delta = datetime.timedelta(seconds=1 * number)
  268. return delta
  269. def _total_seconds(self, delta):
  270. """timedelta.total_seconds is new in version 2.7.
  271. """
  272. return delta.seconds + delta.days * 24 * 3600
  273. class InputDialog(wx.Dialog):
  274. def __init__(self, parent, mode, animationData):
  275. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  276. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
  277. if mode == 'add':
  278. self.SetTitle(_("Add new animation"))
  279. elif mode == 'edit':
  280. self.SetTitle(_("Edit animation"))
  281. self.animationData = animationData
  282. self._tmpLegendCmd = None
  283. self._layout()
  284. self.OnViewMode(event=None)
  285. def _layout(self):
  286. self.notebook = wx.Notebook(parent=self, style=wx.BK_DEFAULT)
  287. sizer = wx.BoxSizer(wx.VERTICAL)
  288. self.notebook.AddPage(
  289. self._createGeneralPage(
  290. self.notebook),
  291. _("General"))
  292. self.notebook.AddPage(
  293. self._createAdvancedPage(
  294. self.notebook),
  295. _("Advanced"))
  296. sizer.Add(
  297. self.notebook,
  298. proportion=1,
  299. flag=wx.ALL | wx.EXPAND,
  300. border=3)
  301. # buttons
  302. self.btnOk = Button(self, wx.ID_OK)
  303. self.btnCancel = Button(self, wx.ID_CANCEL)
  304. self.btnOk.SetDefault()
  305. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  306. # button sizer
  307. btnStdSizer = wx.StdDialogButtonSizer()
  308. btnStdSizer.AddButton(self.btnOk)
  309. btnStdSizer.AddButton(self.btnCancel)
  310. btnStdSizer.Realize()
  311. sizer.Add(btnStdSizer, proportion=0,
  312. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  313. self.SetSizer(sizer)
  314. sizer.Fit(self)
  315. def _createGeneralPage(self, parent):
  316. panel = wx.Panel(parent=parent)
  317. mainSizer = wx.BoxSizer(wx.VERTICAL)
  318. self.windowChoice = wx.Choice(
  319. panel,
  320. id=wx.ID_ANY,
  321. choices=[
  322. _("top left"),
  323. _("top right"),
  324. _("bottom left"),
  325. _("bottom right")])
  326. self.windowChoice.SetSelection(self.animationData.windowIndex)
  327. self.nameCtrl = TextCtrl(
  328. panel, id=wx.ID_ANY, value=self.animationData.name)
  329. self.nDChoice = Choice(panel, id=wx.ID_ANY)
  330. mode = self.animationData.viewMode
  331. index = 0
  332. for i, (viewMode, viewModeName) in enumerate(
  333. self.animationData.viewModes):
  334. self.nDChoice.Append(viewModeName, clientData=viewMode)
  335. if mode == viewMode:
  336. index = i
  337. self.nDChoice.SetSelection(index)
  338. self.nDChoice.SetToolTip(_("Select 2D or 3D view"))
  339. self.nDChoice.Bind(wx.EVT_CHOICE, self.OnViewMode)
  340. gridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  341. gridSizer.Add(
  342. StaticText(
  343. panel,
  344. id=wx.ID_ANY,
  345. label=_("Name:")),
  346. flag=wx.ALIGN_CENTER_VERTICAL)
  347. gridSizer.Add(self.nameCtrl, proportion=1, flag=wx.EXPAND)
  348. gridSizer.Add(
  349. StaticText(
  350. panel,
  351. id=wx.ID_ANY,
  352. label=_("Window position:")),
  353. flag=wx.ALIGN_CENTER_VERTICAL)
  354. gridSizer.Add(
  355. self.windowChoice,
  356. proportion=1,
  357. flag=wx.ALIGN_RIGHT)
  358. gridSizer.Add(
  359. StaticText(
  360. panel,
  361. id=wx.ID_ANY,
  362. label=_("View mode:")),
  363. flag=wx.ALIGN_CENTER_VERTICAL)
  364. gridSizer.Add(self.nDChoice, proportion=1, flag=wx.ALIGN_RIGHT)
  365. gridSizer.AddGrowableCol(0, 1)
  366. gridSizer.AddGrowableCol(1, 1)
  367. mainSizer.Add(
  368. gridSizer,
  369. proportion=0,
  370. flag=wx.ALL | wx.EXPAND,
  371. border=5)
  372. label = _(
  373. "For 3D animation, please select only one space-time dataset\n"
  374. "or one series of map layers.")
  375. self.warning3DLayers = StaticText(panel, label=label)
  376. self.warning3DLayers.SetForegroundColour(
  377. wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
  378. mainSizer.Add(
  379. self.warning3DLayers,
  380. proportion=0,
  381. flag=wx.EXPAND | wx.LEFT,
  382. border=5)
  383. self.dataPanel = self._createDataPanel(panel)
  384. self.threeDPanel = self._create3DPanel(panel)
  385. mainSizer.Add(
  386. self.dataPanel,
  387. proportion=1,
  388. flag=wx.EXPAND | wx.ALL,
  389. border=3)
  390. mainSizer.Add(
  391. self.threeDPanel,
  392. proportion=0,
  393. flag=wx.EXPAND | wx.ALL,
  394. border=3)
  395. panel.SetSizer(mainSizer)
  396. mainSizer.Fit(panel)
  397. return panel
  398. def _createDataPanel(self, parent):
  399. panel = wx.Panel(parent)
  400. slmgrSizer = wx.BoxSizer(wx.VERTICAL)
  401. self._layerList = copy.deepcopy(self.animationData.layerList)
  402. self.simpleLmgr = AnimSimpleLayerManager(parent=panel,
  403. layerList=self._layerList,
  404. modal=True)
  405. self.simpleLmgr.SetMinSize((globalvar.DIALOG_GSELECT_SIZE[0], 80))
  406. slmgrSizer.Add(
  407. self.simpleLmgr,
  408. proportion=1,
  409. flag=wx.EXPAND | wx.ALL,
  410. border=5)
  411. self.legend = wx.CheckBox(panel, label=_("Show raster legend"))
  412. self.legend.SetValue(bool(self.animationData.legendCmd))
  413. self.legendBtn = Button(panel, label=_("Set options"))
  414. self.legend.Bind(wx.EVT_CHECKBOX, self.OnLegend)
  415. self.legendBtn.Bind(wx.EVT_BUTTON, self.OnLegendProperties)
  416. hbox = wx.BoxSizer(wx.HORIZONTAL)
  417. hbox.Add(self.legend, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
  418. hbox.Add(self.legendBtn, proportion=0, flag=wx.LEFT, border=5)
  419. slmgrSizer.Add(
  420. hbox,
  421. proportion=0,
  422. flag=wx.EXPAND | wx.ALL,
  423. border=3)
  424. panel.SetSizerAndFit(slmgrSizer)
  425. panel.SetAutoLayout(True)
  426. return panel
  427. def _create3DPanel(self, parent):
  428. panel = wx.Panel(parent, id=wx.ID_ANY)
  429. dataStBox = StaticBox(parent=panel, id=wx.ID_ANY,
  430. label=' %s ' % _("3D view parameters"))
  431. dataBoxSizer = wx.StaticBoxSizer(dataStBox, wx.VERTICAL)
  432. # workspace file
  433. self.fileSelector = filebrowse.FileBrowseButton(
  434. parent=panel,
  435. id=wx.ID_ANY,
  436. size=globalvar.DIALOG_GSELECT_SIZE,
  437. labelText=_("Workspace file:"),
  438. dialogTitle=_(
  439. "Choose workspace file to "
  440. "import 3D view parameters"),
  441. buttonText=_('Browse'),
  442. startDirectory=os.getcwd(),
  443. fileMode=0,
  444. fileMask="GRASS Workspace File (*.gxw)|*.gxw")
  445. if self.animationData.workspaceFile:
  446. self.fileSelector.SetValue(self.animationData.workspaceFile)
  447. self.paramLabel = StaticText(
  448. panel, wx.ID_ANY, label=_("Parameter for animation:"))
  449. self.paramChoice = wx.Choice(
  450. panel, id=wx.ID_ANY, choices=self.animationData.nvizParameters)
  451. self.paramChoice.SetStringSelection(self.animationData.nvizParameter)
  452. hbox = wx.BoxSizer(wx.HORIZONTAL)
  453. hbox.Add(
  454. self.fileSelector,
  455. proportion=1,
  456. flag=wx.EXPAND | wx.ALIGN_CENTER)
  457. dataBoxSizer.Add(
  458. hbox,
  459. proportion=0,
  460. flag=wx.EXPAND | wx.ALL,
  461. border=3)
  462. hbox = wx.BoxSizer(wx.HORIZONTAL)
  463. hbox.Add(
  464. self.paramLabel,
  465. proportion=1,
  466. flag=wx.ALIGN_CENTER_VERTICAL)
  467. hbox.Add(self.paramChoice, proportion=1, flag=wx.EXPAND)
  468. dataBoxSizer.Add(
  469. hbox,
  470. proportion=0,
  471. flag=wx.EXPAND | wx.ALL,
  472. border=3)
  473. panel.SetSizerAndFit(dataBoxSizer)
  474. panel.SetAutoLayout(True)
  475. return panel
  476. def _createAdvancedPage(self, parent):
  477. panel = wx.Panel(parent=parent)
  478. mainSizer = wx.BoxSizer(wx.VERTICAL)
  479. box = StaticBox(
  480. parent=panel, label=" %s " %
  481. _("Animate region change (2D view only)"))
  482. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  483. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  484. gridSizer.Add(StaticText(panel, label=_("Start region:")),
  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.endRegRadio = RadioButton(
  493. panel, label=_("End region:"), style=wx.RB_GROUP)
  494. gridSizer.Add(self.endRegRadio, pos=(1, 0), flag=wx.EXPAND)
  495. self.endRegion = Select(parent=panel, type='region', size=(200, -1))
  496. gridSizer.Add(
  497. self.endRegion, pos=(1, 1),
  498. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  499. self.zoomRadio = RadioButton(panel, label=_("Zoom value:"))
  500. self.zoomRadio.SetToolTip(_("N-S/E-W distances in map units used to "
  501. "gradually reduce region."))
  502. gridSizer.Add(self.zoomRadio, pos=(2, 0), flag=wx.EXPAND)
  503. zoomSizer = wx.BoxSizer(wx.HORIZONTAL)
  504. self.zoomNS = TextCtrl(panel, validator=FloatValidator())
  505. self.zoomEW = TextCtrl(panel, validator=FloatValidator())
  506. zoomSizer.Add(StaticText(panel, label=_("N-S:")), proportion=0,
  507. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  508. zoomSizer.Add(self.zoomNS, proportion=1, flag=wx.LEFT, border=3)
  509. zoomSizer.Add(StaticText(panel, label=_("E-W:")), proportion=0,
  510. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3)
  511. zoomSizer.Add(self.zoomEW, proportion=1, flag=wx.LEFT, border=3)
  512. gridSizer.Add(
  513. zoomSizer, pos=(2, 1),
  514. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  515. if self.animationData.endRegion:
  516. self.endRegRadio.SetValue(True)
  517. self.zoomRadio.SetValue(False)
  518. self.endRegion.SetValue(self.animationData.endRegion)
  519. if self.animationData.zoomRegionValue:
  520. self.endRegRadio.SetValue(False)
  521. self.zoomRadio.SetValue(True)
  522. zoom = self.animationData.zoomRegionValue
  523. self.zoomNS.SetValue(str(zoom[0]))
  524. self.zoomEW.SetValue(str(zoom[1]))
  525. self.endRegRadio.Bind(
  526. wx.EVT_RADIOBUTTON,
  527. lambda evt: self._enableRegionWidgets())
  528. self.zoomRadio.Bind(
  529. wx.EVT_RADIOBUTTON,
  530. lambda evt: self._enableRegionWidgets())
  531. self._enableRegionWidgets()
  532. gridSizer.AddGrowableCol(1)
  533. sizer.Add(gridSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  534. mainSizer.Add(sizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
  535. panel.SetSizer(mainSizer)
  536. mainSizer.Fit(panel)
  537. return panel
  538. def _enableRegionWidgets(self):
  539. """Enables/disables region widgets
  540. according to which radiobutton is active."""
  541. endReg = self.endRegRadio.GetValue()
  542. self.endRegion.Enable(endReg)
  543. self.zoomNS.Enable(not endReg)
  544. self.zoomEW.Enable(not endReg)
  545. def OnViewMode(self, event):
  546. mode = self.nDChoice.GetSelection()
  547. self.Freeze()
  548. self.simpleLmgr.Activate3D(mode == 1)
  549. self.warning3DLayers.Show(mode == 1)
  550. # disable region widgets for 3d
  551. regSizer = self.stRegion.GetContainingSizer()
  552. for child in regSizer.GetChildren():
  553. if child.IsSizer():
  554. for child_ in child.GetSizer().GetChildren():
  555. child_.GetWindow().Enable(mode != 1)
  556. elif child.IsWindow():
  557. child.GetWindow().Enable(mode != 1)
  558. self._enableRegionWidgets()
  559. # update layout
  560. sizer = self.threeDPanel.GetContainingSizer()
  561. sizer.Show(self.threeDPanel, mode == 1, True)
  562. sizer.Layout()
  563. self.Thaw()
  564. def OnLegend(self, event):
  565. if not self.legend.IsChecked():
  566. return
  567. if self._tmpLegendCmd or self.animationData.legendCmd:
  568. return
  569. cmd = ['d.legend', 'at=5,50,2,5']
  570. GUI(parent=self, modal=True).ParseCommand(
  571. cmd=cmd, completed=(self.GetOptData, '', ''))
  572. def OnLegendProperties(self, event):
  573. """Set options for legend"""
  574. if self._tmpLegendCmd:
  575. cmd = self._tmpLegendCmd
  576. elif self.animationData.legendCmd:
  577. cmd = self.animationData.legendCmd
  578. else:
  579. cmd = ['d.legend', 'at=5,50,2,5']
  580. GUI(parent=self, modal=True).ParseCommand(
  581. cmd=cmd, completed=(self.GetOptData, '', ''))
  582. def GetOptData(self, dcmd, layer, params, propwin):
  583. """Process decoration layer data"""
  584. if dcmd:
  585. self._tmpLegendCmd = dcmd
  586. if not self.legend.IsChecked():
  587. self.legend.SetValue(True)
  588. else:
  589. if not self._tmpLegendCmd and not self.animationData.legendCmd:
  590. self.legend.SetValue(False)
  591. def _update(self):
  592. if self.nDChoice.GetSelection() == 1 and len(self._layerList) > 1:
  593. raise GException(_("Only one series or space-time "
  594. "dataset is accepted for 3D mode."))
  595. hasSeries = False
  596. for layer in self._layerList:
  597. if layer.active and hasattr(layer, 'maps'):
  598. hasSeries = True
  599. break
  600. if not hasSeries:
  601. raise GException(_("No map series or space-time dataset added."))
  602. self.animationData.layerList = self._layerList
  603. self.animationData.name = self.nameCtrl.GetValue()
  604. self.animationData.windowIndex = self.windowChoice.GetSelection()
  605. sel = self.nDChoice.GetSelection()
  606. self.animationData.viewMode = self.nDChoice.GetClientData(sel)
  607. self.animationData.legendCmd = None
  608. if self._tmpLegendCmd:
  609. if self.legend.IsChecked():
  610. self.animationData.legendCmd = self._tmpLegendCmd
  611. if self.threeDPanel.IsShown():
  612. self.animationData.workspaceFile = self.fileSelector.GetValue()
  613. if self.threeDPanel.IsShown():
  614. self.animationData.nvizParameter = self.paramChoice.GetStringSelection()
  615. # region (2d only)
  616. if self.animationData.viewMode == '3d':
  617. self.animationData.startRegion = None
  618. self.animationData.endRegion = None
  619. self.animationData.zoomRegionValue = None
  620. return
  621. isEnd = self.endRegRadio.GetValue() and self.endRegion.GetValue()
  622. isZoom = self.zoomRadio.GetValue() and self.zoomNS.GetValue() and self.zoomEW.GetValue()
  623. isStart = self.stRegion.GetValue()
  624. condition = bool(isStart) + bool(isZoom) + bool(isEnd)
  625. if condition == 1:
  626. raise GException(_("Region information is not complete"))
  627. elif condition == 2:
  628. self.animationData.startRegion = isStart
  629. if isEnd:
  630. self.animationData.endRegion = self.endRegion.GetValue()
  631. self.animationData.zoomRegionValue = None
  632. else:
  633. self.animationData.zoomRegionValue = (
  634. float(self.zoomNS.GetValue()),
  635. float(self.zoomEW.GetValue()))
  636. self.animationData.endRegion = None
  637. else:
  638. self.animationData.startRegion = None
  639. self.animationData.endRegion = None
  640. self.animationData.zoomRegionValue = None
  641. def UnInit(self):
  642. self.simpleLmgr.UnInit()
  643. def OnOk(self, event):
  644. try:
  645. self._update()
  646. self.UnInit()
  647. self.EndModal(wx.ID_OK)
  648. except (GException, ValueError, IOError) as e:
  649. GError(
  650. message=str(e),
  651. showTraceback=False,
  652. caption=_("Invalid input"))
  653. class EditDialog(wx.Dialog):
  654. def __init__(self, parent, evalFunction, animationData, maxAnimations):
  655. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  656. style=wx.DEFAULT_DIALOG_STYLE)
  657. self.animationData = copy.deepcopy(animationData)
  658. self.eval = evalFunction
  659. self.SetTitle(_("Add, edit or remove animations"))
  660. self._layout()
  661. self.SetSize((300, -1))
  662. self.maxAnimations = maxAnimations
  663. self.result = None
  664. def _layout(self):
  665. mainSizer = wx.BoxSizer(wx.VERTICAL)
  666. box = StaticBox(
  667. parent=self,
  668. id=wx.ID_ANY,
  669. label=" %s " %
  670. _("List of animations"))
  671. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  672. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  673. gridBagSizer.AddGrowableCol(0)
  674. # gridBagSizer.AddGrowableCol(1,1)
  675. self.listbox = wx.ListBox(
  676. self, id=wx.ID_ANY, choices=[],
  677. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  678. self.listbox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnEdit)
  679. self.addButton = Button(self, id=wx.ID_ANY, label=_("Add"))
  680. self.addButton.Bind(wx.EVT_BUTTON, self.OnAdd)
  681. self.editButton = Button(self, id=wx.ID_ANY, label=_("Edit"))
  682. self.editButton.Bind(wx.EVT_BUTTON, self.OnEdit)
  683. self.removeButton = Button(self, id=wx.ID_ANY, label=_("Remove"))
  684. self.removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  685. self._updateListBox()
  686. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(3, 1),
  687. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  688. gridBagSizer.Add(self.addButton, pos=(0, 1),
  689. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  690. gridBagSizer.Add(self.editButton, pos=(1, 1),
  691. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  692. gridBagSizer.Add(self.removeButton, pos=(2, 1),
  693. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  694. sizer.Add(
  695. gridBagSizer,
  696. proportion=0,
  697. flag=wx.ALL | wx.EXPAND,
  698. border=5)
  699. mainSizer.Add(sizer, proportion=0,
  700. flag=wx.EXPAND | wx.ALL, border=5)
  701. # buttons
  702. self.btnOk = Button(self, wx.ID_OK)
  703. self.btnCancel = Button(self, wx.ID_CANCEL)
  704. self.btnOk.SetDefault()
  705. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  706. # button sizer
  707. btnStdSizer = wx.StdDialogButtonSizer()
  708. btnStdSizer.AddButton(self.btnOk)
  709. btnStdSizer.AddButton(self.btnCancel)
  710. btnStdSizer.Realize()
  711. mainSizer.Add(btnStdSizer, proportion=0,
  712. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  713. self.SetSizer(mainSizer)
  714. mainSizer.Fit(self)
  715. def _updateListBox(self):
  716. self.listbox.Clear()
  717. for anim in self.animationData:
  718. self.listbox.Append(anim.name, clientData=anim)
  719. if self.animationData:
  720. self.listbox.SetSelection(0)
  721. def _getNextIndex(self):
  722. indices = [anim.windowIndex for anim in self.animationData]
  723. for i in range(self.maxAnimations):
  724. if i not in indices:
  725. return i
  726. return None
  727. def OnAdd(self, event):
  728. windowIndex = self._getNextIndex()
  729. if windowIndex is None:
  730. GMessage(
  731. self,
  732. message=_("Maximum number of animations is %d.") %
  733. self.maxAnimations)
  734. return
  735. animData = AnimationData()
  736. # number of active animations
  737. animationIndex = len(self.animationData)
  738. animData.SetDefaultValues(windowIndex, animationIndex)
  739. dlg = InputDialog(parent=self, mode='add', animationData=animData)
  740. dlg.CenterOnParent()
  741. if dlg.ShowModal() == wx.ID_CANCEL:
  742. dlg.UnInit()
  743. dlg.Destroy()
  744. return
  745. dlg.Destroy()
  746. self.animationData.append(animData)
  747. self._updateListBox()
  748. def OnEdit(self, event):
  749. index = self.listbox.GetSelection()
  750. if index == wx.NOT_FOUND:
  751. return
  752. animData = self.listbox.GetClientData(index)
  753. dlg = InputDialog(parent=self, mode='edit', animationData=animData)
  754. dlg.CenterOnParent()
  755. if dlg.ShowModal() == wx.ID_CANCEL:
  756. dlg.UnInit()
  757. dlg.Destroy()
  758. return
  759. dlg.Destroy()
  760. self._updateListBox()
  761. def OnRemove(self, event):
  762. index = self.listbox.GetSelection()
  763. if index == wx.NOT_FOUND:
  764. return
  765. animData = self.listbox.GetClientData(index)
  766. self.animationData.remove(animData)
  767. self._updateListBox()
  768. def GetResult(self):
  769. return self.result
  770. def OnOk(self, event):
  771. indices = set([anim.windowIndex for anim in self.animationData])
  772. if len(indices) != len(self.animationData):
  773. GError(
  774. parent=self, message=_(
  775. "More animations are using one window."
  776. " Please select different window for each animation."))
  777. return
  778. try:
  779. temporalMode, tempManager = self.eval(self.animationData)
  780. except GException as e:
  781. GError(parent=self, message=e.value, showTraceback=False)
  782. return
  783. self.result = (self.animationData, temporalMode, tempManager)
  784. self.EndModal(wx.ID_OK)
  785. class ExportDialog(wx.Dialog):
  786. def __init__(self, parent, temporal, timeTick):
  787. wx.Dialog.__init__(
  788. self,
  789. parent=parent,
  790. id=wx.ID_ANY,
  791. title=_("Export animation"),
  792. style=wx.DEFAULT_DIALOG_STYLE)
  793. self.decorations = []
  794. self.temporal = temporal
  795. self.timeTick = timeTick
  796. self._layout()
  797. # export animation
  798. self.doExport = Signal('ExportDialog::doExport')
  799. wx.CallAfter(self._hideAll)
  800. def _layout(self):
  801. notebook = wx.Notebook(self, id=wx.ID_ANY)
  802. mainSizer = wx.BoxSizer(wx.VERTICAL)
  803. notebook.AddPage(
  804. page=self._createExportFormatPanel(notebook),
  805. text=_("Format"))
  806. notebook.AddPage(
  807. page=self._createDecorationsPanel(notebook),
  808. text=_("Decorations"))
  809. mainSizer.Add(notebook, proportion=0,
  810. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  811. self.btnExport = Button(self, wx.ID_OK)
  812. self.btnExport.SetLabel(_("Export"))
  813. self.btnCancel = Button(self, wx.ID_CANCEL)
  814. self.btnExport.SetDefault()
  815. self.btnExport.Bind(wx.EVT_BUTTON, self.OnExport)
  816. # button sizer
  817. btnStdSizer = wx.StdDialogButtonSizer()
  818. btnStdSizer.AddButton(self.btnExport)
  819. btnStdSizer.AddButton(self.btnCancel)
  820. btnStdSizer.Realize()
  821. mainSizer.Add(btnStdSizer, proportion=0,
  822. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  823. self.SetSizer(mainSizer)
  824. # set the longest option to fit
  825. self.hidevbox.Show(self.fontBox, True)
  826. self.hidevbox.Show(self.imageBox, False)
  827. self.hidevbox.Show(self.textBox, True)
  828. self.hidevbox.Show(self.posBox, True)
  829. self.hidevbox.Show(self.informBox, False)
  830. mainSizer.Fit(self)
  831. def _createDecorationsPanel(self, notebook):
  832. panel = wx.Panel(notebook, id=wx.ID_ANY)
  833. sizer = wx.BoxSizer(wx.VERTICAL)
  834. sizer.Add(
  835. self._createDecorationsList(panel),
  836. proportion=0,
  837. flag=wx.ALL | wx.EXPAND,
  838. border=10)
  839. sizer.Add(
  840. self._createDecorationsProperties(panel),
  841. proportion=0,
  842. flag=wx.ALL | wx.EXPAND,
  843. border=10)
  844. panel.SetSizer(sizer)
  845. sizer.Fit(panel)
  846. return panel
  847. def _createDecorationsList(self, panel):
  848. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  849. gridBagSizer.AddGrowableCol(0)
  850. self.listbox = wx.ListBox(panel, id=wx.ID_ANY, choices=[],
  851. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  852. self.listbox.Bind(wx.EVT_LISTBOX, self.OnSelectionChanged)
  853. gridBagSizer.Add(self.listbox, pos=(0, 0), span=(4, 1),
  854. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  855. buttonNames = ['time', 'image', 'text']
  856. buttonLabels = [_("Add time stamp"), _("Add image"), _("Add text")]
  857. i = 0
  858. for buttonName, buttonLabel in zip(buttonNames, buttonLabels):
  859. if buttonName == 'time' and self.temporal == TemporalMode.NONTEMPORAL:
  860. continue
  861. btn = Button(
  862. panel,
  863. id=wx.ID_ANY,
  864. name=buttonName,
  865. label=buttonLabel)
  866. btn.Bind(
  867. wx.EVT_BUTTON,
  868. lambda evt,
  869. temp=buttonName: self.OnAddDecoration(
  870. evt,
  871. temp))
  872. gridBagSizer.Add(
  873. btn,
  874. pos=(
  875. i,
  876. 1),
  877. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  878. border=0)
  879. i += 1
  880. removeButton = Button(panel, id=wx.ID_ANY, label=_("Remove"))
  881. removeButton.Bind(wx.EVT_BUTTON, self.OnRemove)
  882. gridBagSizer.Add(
  883. removeButton,
  884. pos=(
  885. i,
  886. 1),
  887. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  888. border=0)
  889. return gridBagSizer
  890. def _createDecorationsProperties(self, panel):
  891. self.hidevbox = wx.BoxSizer(wx.VERTICAL)
  892. # inform label
  893. self.informBox = wx.BoxSizer(wx.HORIZONTAL)
  894. if self.temporal == TemporalMode.TEMPORAL:
  895. label = _(
  896. "Add time stamp, image or text decoration by one of the buttons above.")
  897. else:
  898. label = _("Add image or text decoration by one of the buttons above.")
  899. label = StaticText(panel, id=wx.ID_ANY, label=label)
  900. label.Wrap(400)
  901. self.informBox.Add(
  902. label,
  903. proportion=1,
  904. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  905. border=5)
  906. self.hidevbox.Add(
  907. self.informBox,
  908. proportion=0,
  909. flag=wx.EXPAND | wx.BOTTOM,
  910. border=5)
  911. # font
  912. self.fontBox = wx.BoxSizer(wx.HORIZONTAL)
  913. self.fontBox.Add(
  914. StaticText(
  915. panel,
  916. id=wx.ID_ANY,
  917. label=_("Font settings:")),
  918. proportion=0,
  919. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  920. border=5)
  921. self.sampleLabel = StaticText(
  922. panel, id=wx.ID_ANY, label=_("Sample text"))
  923. self.fontBox.Add(self.sampleLabel, proportion=1,
  924. flag=wx.ALIGN_CENTER | wx.RIGHT | wx.LEFT, border=5)
  925. fontButton = Button(panel, id=wx.ID_ANY, label=_("Set font"))
  926. fontButton.Bind(wx.EVT_BUTTON, self.OnFont)
  927. self.fontBox.Add(
  928. fontButton,
  929. proportion=0,
  930. flag=wx.ALIGN_CENTER_VERTICAL)
  931. self.hidevbox.Add(
  932. self.fontBox,
  933. proportion=0,
  934. flag=wx.EXPAND | wx.BOTTOM,
  935. border=5)
  936. # image
  937. self.imageBox = wx.BoxSizer(wx.HORIZONTAL)
  938. filetype, ltype = GetImageHandlers(wx.EmptyImage(10, 10))
  939. self.browse = filebrowse.FileBrowseButton(
  940. parent=panel, id=wx.ID_ANY, fileMask=filetype,
  941. labelText=_("Image file:"),
  942. dialogTitle=_('Choose image file'),
  943. buttonText=_('Browse'),
  944. startDirectory=os.getcwd(),
  945. fileMode=wx.FD_OPEN, changeCallback=self.OnSetImage)
  946. self.imageBox.Add(self.browse, proportion=1, flag=wx.EXPAND)
  947. self.hidevbox.Add(
  948. self.imageBox,
  949. proportion=0,
  950. flag=wx.EXPAND | wx.BOTTOM,
  951. border=5)
  952. # text
  953. self.textBox = wx.BoxSizer(wx.HORIZONTAL)
  954. self.textBox.Add(
  955. StaticText(
  956. panel,
  957. id=wx.ID_ANY,
  958. label=_("Text:")),
  959. proportion=0,
  960. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  961. border=5)
  962. self.textCtrl = TextCtrl(panel, id=wx.ID_ANY)
  963. self.textCtrl.Bind(wx.EVT_TEXT, self.OnText)
  964. self.textBox.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
  965. self.hidevbox.Add(self.textBox, proportion=0, flag=wx.EXPAND)
  966. self.posBox = self._positionWidget(panel)
  967. self.hidevbox.Add(
  968. self.posBox,
  969. proportion=0,
  970. flag=wx.EXPAND | wx.TOP,
  971. border=5)
  972. return self.hidevbox
  973. def _positionWidget(self, panel):
  974. grid = wx.GridBagSizer(vgap=5, hgap=5)
  975. label = StaticText(
  976. panel, id=wx.ID_ANY, label=_(
  977. "Placement as percentage of"
  978. " screen coordinates (X: 0, Y: 0 is top left):"))
  979. label.Wrap(400)
  980. self.spinX = SpinCtrl(
  981. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  982. self.spinY = SpinCtrl(
  983. panel, id=wx.ID_ANY, min=0, max=100, initial=10)
  984. self.spinX.Bind(
  985. wx.EVT_SPINCTRL,
  986. lambda evt,
  987. temp='X': self.OnPosition(
  988. evt,
  989. temp))
  990. self.spinY.Bind(
  991. wx.EVT_SPINCTRL,
  992. lambda evt,
  993. temp='Y': self.OnPosition(
  994. evt,
  995. temp))
  996. grid.Add(label, pos=(0, 0), span=(1, 4), flag=wx.EXPAND)
  997. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("X:")), pos=(1, 0),
  998. flag=wx.ALIGN_CENTER_VERTICAL)
  999. grid.Add(StaticText(panel, id=wx.ID_ANY, label=_("Y:")), pos=(1, 2),
  1000. flag=wx.ALIGN_CENTER_VERTICAL)
  1001. grid.Add(self.spinX, pos=(1, 1))
  1002. grid.Add(self.spinY, pos=(1, 3))
  1003. return grid
  1004. def _createExportFormatPanel(self, notebook):
  1005. panel = wx.Panel(notebook, id=wx.ID_ANY)
  1006. borderSizer = wx.BoxSizer(wx.VERTICAL)
  1007. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  1008. choices = [_("image sequence"), _("animated GIF"), _("SWF"), _("AVI")]
  1009. self.formatChoice = wx.Choice(parent=panel, id=wx.ID_ANY,
  1010. choices=choices)
  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(item=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 = wx.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.SetToolTipString(
  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()