dialogs.py 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. """
  2. @package animation.dialogs
  3. @brief Dialogs for animation management, changing speed of animation
  4. Classes:
  5. - dialogs::SpeedDialog
  6. - dialogs::InputDialog
  7. - dialogs::EditDialog
  8. - dialogs::ExportDialog
  9. - dialogs::AnimSimpleLayerManager
  10. - dialogs::AddTemporalLayerDialog
  11. (C) 2013 by the GRASS Development Team
  12. This program is free software under the GNU General Public License
  13. (>=v2). Read the file COPYING that comes with GRASS for details.
  14. @author Anna Petrasova <kratochanna gmail.com>
  15. """
  16. from __future__ import print_function
  17. import os
  18. import wx
  19. import copy
  20. import datetime
  21. import wx.lib.filebrowsebutton as filebrowse
  22. import wx.lib.scrolledpanel as SP
  23. import wx.lib.colourselect as csel
  24. try:
  25. from wx.adv import HyperlinkCtrl
  26. except ImportError:
  27. from wx import HyperlinkCtrl
  28. from core.gcmd import GMessage, GError, GException
  29. from core import globalvar
  30. from gui_core.dialogs import MapLayersDialog, GetImageHandlers
  31. from gui_core.preferences import PreferencesBaseDialog
  32. from gui_core.forms import GUI
  33. from core.settings import UserSettings
  34. from gui_core.gselect import Select
  35. from gui_core.widgets import FloatValidator
  36. from gui_core.wrap import SpinCtrl, CheckBox, TextCtrl, Button, \
  37. BitmapButton, StaticText, StaticBox, Choice, RadioButton
  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(wx.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.Bind(
  1011. wx.EVT_CHOICE,
  1012. lambda event: self.ChangeFormat(
  1013. event.GetSelection()))
  1014. hSizer.Add(
  1015. StaticText(
  1016. panel,
  1017. id=wx.ID_ANY,
  1018. label=_("Export to:")),
  1019. proportion=0,
  1020. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1021. border=2)
  1022. hSizer.Add(
  1023. self.formatChoice,
  1024. proportion=1,
  1025. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.ALL,
  1026. border=2)
  1027. borderSizer.Add(
  1028. hSizer,
  1029. proportion=0,
  1030. flag=wx.EXPAND | wx.ALL,
  1031. border=3)
  1032. helpSizer = wx.BoxSizer(wx.HORIZONTAL)
  1033. helpSizer.AddStretchSpacer(1)
  1034. self.formatPanelSizer = wx.BoxSizer(wx.VERTICAL)
  1035. helpSizer.Add(self.formatPanelSizer, proportion=5, flag=wx.EXPAND)
  1036. borderSizer.Add(helpSizer, proportion=1, flag=wx.EXPAND)
  1037. self.formatPanels = []
  1038. # panel for image sequence
  1039. imSeqPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1040. prefixLabel = StaticText(
  1041. imSeqPanel, id=wx.ID_ANY, label=_("File prefix:"))
  1042. self.prefixCtrl = TextCtrl(
  1043. imSeqPanel, id=wx.ID_ANY, value=_("animation_"))
  1044. formatLabel = StaticText(
  1045. imSeqPanel, id=wx.ID_ANY, label=_("File format:"))
  1046. imageTypes = ['PNG', 'JPEG', 'GIF', 'TIFF', 'PPM', 'BMP']
  1047. self.imSeqFormatChoice = wx.Choice(imSeqPanel, choices=imageTypes)
  1048. self.imSeqFormatChoice.SetSelection(0)
  1049. self.dirBrowse = filebrowse.DirBrowseButton(
  1050. parent=imSeqPanel, id=wx.ID_ANY, labelText=_("Directory:"),
  1051. dialogTitle=_("Choose directory for export"),
  1052. buttonText=_("Browse"),
  1053. startDirectory=os.getcwd())
  1054. dirGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1055. dirGridSizer.Add(
  1056. prefixLabel, pos=(0, 0),
  1057. flag=wx.ALIGN_CENTER_VERTICAL)
  1058. dirGridSizer.Add(self.prefixCtrl, pos=(0, 1), flag=wx.EXPAND)
  1059. dirGridSizer.Add(
  1060. formatLabel, pos=(1, 0),
  1061. flag=wx.ALIGN_CENTER_VERTICAL)
  1062. dirGridSizer.Add(self.imSeqFormatChoice, pos=(1, 1), flag=wx.EXPAND)
  1063. dirGridSizer.Add(
  1064. self.dirBrowse, pos=(
  1065. 2, 0), flag=wx.EXPAND, span=(
  1066. 1, 2))
  1067. dirGridSizer.AddGrowableCol(1)
  1068. imSeqPanel.SetSizer(dirGridSizer)
  1069. dirGridSizer.Fit(imSeqPanel)
  1070. self.formatPanelSizer.Add(
  1071. imSeqPanel,
  1072. proportion=1,
  1073. flag=wx.EXPAND | wx.ALL,
  1074. border=5)
  1075. self.formatPanels.append(imSeqPanel)
  1076. # panel for gif
  1077. gifPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1078. self.gifBrowse = filebrowse.FileBrowseButton(
  1079. parent=gifPanel,
  1080. id=wx.ID_ANY,
  1081. fileMask="GIF file (*.gif)|*.gif",
  1082. labelText=_("GIF file:"),
  1083. dialogTitle=_("Choose file to save animation"),
  1084. buttonText=_("Browse"),
  1085. startDirectory=os.getcwd(),
  1086. fileMode=wx.FD_SAVE)
  1087. gifGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1088. gifGridSizer.AddGrowableCol(0)
  1089. gifGridSizer.Add(self.gifBrowse, pos=(0, 0), flag=wx.EXPAND)
  1090. gifPanel.SetSizer(gifGridSizer)
  1091. gifGridSizer.Fit(gifPanel)
  1092. self.formatPanelSizer.Add(
  1093. gifPanel,
  1094. proportion=1,
  1095. flag=wx.EXPAND | wx.ALL,
  1096. border=5)
  1097. self.formatPanels.append(gifPanel)
  1098. # panel for swf
  1099. swfPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1100. self.swfBrowse = filebrowse.FileBrowseButton(
  1101. parent=swfPanel,
  1102. id=wx.ID_ANY,
  1103. fileMask="SWF file (*.swf)|*.swf",
  1104. labelText=_("SWF file:"),
  1105. dialogTitle=_("Choose file to save animation"),
  1106. buttonText=_("Browse"),
  1107. startDirectory=os.getcwd(),
  1108. fileMode=wx.FD_SAVE)
  1109. swfGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1110. swfGridSizer.AddGrowableCol(0)
  1111. swfGridSizer.Add(self.swfBrowse, pos=(0, 0), flag=wx.EXPAND)
  1112. swfPanel.SetSizer(swfGridSizer)
  1113. swfGridSizer.Fit(swfPanel)
  1114. self.formatPanelSizer.Add(
  1115. swfPanel,
  1116. proportion=1,
  1117. flag=wx.EXPAND | wx.ALL,
  1118. border=5)
  1119. self.formatPanels.append(swfPanel)
  1120. # panel for avi
  1121. aviPanel = wx.Panel(parent=panel, id=wx.ID_ANY)
  1122. ffmpeg = gcore.find_program('ffmpeg', '--help')
  1123. if not ffmpeg:
  1124. warning = _(
  1125. "Program 'ffmpeg' was not found.\nPlease install it first "
  1126. "and make sure\nit's in the PATH variable.")
  1127. warningLabel = StaticText(parent=aviPanel, label=warning)
  1128. warningLabel.SetForegroundColour(wx.RED)
  1129. self.aviBrowse = filebrowse.FileBrowseButton(
  1130. parent=aviPanel,
  1131. id=wx.ID_ANY,
  1132. fileMask="AVI file (*.avi)|*.avi",
  1133. labelText=_("AVI file:"),
  1134. dialogTitle=_("Choose file to save animation"),
  1135. buttonText=_("Browse"),
  1136. startDirectory=os.getcwd(),
  1137. fileMode=wx.FD_SAVE)
  1138. encodingLabel = StaticText(
  1139. parent=aviPanel,
  1140. id=wx.ID_ANY,
  1141. label=_("Video codec:"))
  1142. self.encodingText = TextCtrl(
  1143. parent=aviPanel, id=wx.ID_ANY, value='mpeg4')
  1144. optionsLabel = StaticText(
  1145. parent=aviPanel, label=_("Additional options:"))
  1146. self.optionsText = TextCtrl(parent=aviPanel)
  1147. self.optionsText.SetToolTip(
  1148. _(
  1149. "Consider adding '-sameq' or '-qscale 1' "
  1150. "if not satisfied with video quality. "
  1151. "Options depend on ffmpeg version."))
  1152. aviGridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1153. aviGridSizer.Add(
  1154. self.aviBrowse, pos=(
  1155. 0, 0), span=(
  1156. 1, 2), flag=wx.EXPAND)
  1157. aviGridSizer.Add(
  1158. encodingLabel, pos=(1, 0),
  1159. flag=wx.ALIGN_CENTER_VERTICAL)
  1160. aviGridSizer.Add(self.encodingText, pos=(1, 1), flag=wx.EXPAND)
  1161. aviGridSizer.Add(
  1162. optionsLabel, pos=(2, 0),
  1163. flag=wx.ALIGN_CENTER_VERTICAL)
  1164. aviGridSizer.Add(self.optionsText, pos=(2, 1), flag=wx.EXPAND)
  1165. if not ffmpeg:
  1166. aviGridSizer.Add(warningLabel, pos=(3, 0), span=(1, 2),
  1167. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  1168. aviGridSizer.AddGrowableCol(1)
  1169. aviPanel.SetSizer(aviGridSizer)
  1170. aviGridSizer.Fit(aviPanel)
  1171. self.formatPanelSizer.Add(
  1172. aviPanel,
  1173. proportion=1,
  1174. flag=wx.EXPAND | wx.ALL,
  1175. border=5)
  1176. self.formatPanels.append(aviPanel)
  1177. fpsSizer = wx.BoxSizer(wx.HORIZONTAL)
  1178. fps = 1000 / self.timeTick
  1179. fpsSizer.Add(
  1180. StaticText(
  1181. panel,
  1182. id=wx.ID_ANY,
  1183. label=_("Current frame rate: %.2f fps") %
  1184. fps),
  1185. proportion=1,
  1186. flag=wx.EXPAND)
  1187. borderSizer.Add(
  1188. fpsSizer,
  1189. proportion=0,
  1190. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1191. border=5)
  1192. panel.SetSizer(borderSizer)
  1193. borderSizer.Fit(panel)
  1194. self.ChangeFormat(index=0)
  1195. return panel
  1196. def ChangeFormat(self, index):
  1197. for i, panel in enumerate(self.formatPanels):
  1198. self.formatPanelSizer.Show(window=panel, show=(i == index))
  1199. self.formatPanelSizer.Layout()
  1200. def OnFont(self, event):
  1201. index = self.listbox.GetSelection()
  1202. # should not happen
  1203. if index == wx.NOT_FOUND:
  1204. return
  1205. cdata = self.listbox.GetClientData(index)
  1206. font = cdata['font']
  1207. fontdata = wx.FontData()
  1208. fontdata.EnableEffects(True)
  1209. fontdata.SetColour('black')
  1210. fontdata.SetInitialFont(font)
  1211. dlg = wx.FontDialog(self, fontdata)
  1212. dlg.CenterOnParent()
  1213. if dlg.ShowModal() == wx.ID_OK:
  1214. newfontdata = dlg.GetFontData()
  1215. font = newfontdata.GetChosenFont()
  1216. self.sampleLabel.SetFont(font)
  1217. cdata['font'] = font
  1218. self.Layout()
  1219. def OnPosition(self, event, coord):
  1220. index = self.listbox.GetSelection()
  1221. # should not happen
  1222. if index == wx.NOT_FOUND:
  1223. return
  1224. cdata = self.listbox.GetClientData(index)
  1225. cdata['pos'][coord == 'Y'] = event.GetInt()
  1226. def OnSetImage(self, event):
  1227. index = self.listbox.GetSelection()
  1228. # should not happen
  1229. if index == wx.NOT_FOUND:
  1230. return
  1231. cdata = self.listbox.GetClientData(index)
  1232. cdata['file'] = event.GetString()
  1233. def OnAddDecoration(self, event, name):
  1234. if name == 'time':
  1235. timeInfo = {'name': name, 'font': self.GetFont(), 'pos': [10, 10]}
  1236. self.decorations.append(timeInfo)
  1237. elif name == 'image':
  1238. imageInfo = {'name': name, 'file': '', 'pos': [10, 10]}
  1239. self.decorations.append(imageInfo)
  1240. elif name == 'text':
  1241. textInfo = {
  1242. 'name': name,
  1243. 'font': self.GetFont(),
  1244. 'text': '',
  1245. 'pos': [
  1246. 10,
  1247. 10]}
  1248. self.decorations.append(textInfo)
  1249. self._updateListBox()
  1250. self.listbox.SetSelection(self.listbox.GetCount() - 1)
  1251. self.OnSelectionChanged(event=None)
  1252. def OnSelectionChanged(self, event):
  1253. index = self.listbox.GetSelection()
  1254. if index == wx.NOT_FOUND:
  1255. self._hideAll()
  1256. return
  1257. cdata = self.listbox.GetClientData(index)
  1258. self.hidevbox.Show(self.fontBox, (cdata['name'] in ('time', 'text')))
  1259. self.hidevbox.Show(self.imageBox, (cdata['name'] == 'image'))
  1260. self.hidevbox.Show(self.textBox, (cdata['name'] == 'text'))
  1261. self.hidevbox.Show(self.posBox, True)
  1262. self.hidevbox.Show(self.informBox, False)
  1263. self.spinX.SetValue(cdata['pos'][0])
  1264. self.spinY.SetValue(cdata['pos'][1])
  1265. if cdata['name'] == 'image':
  1266. self.browse.SetValue(cdata['file'])
  1267. elif cdata['name'] in ('time', 'text'):
  1268. self.sampleLabel.SetFont(cdata['font'])
  1269. if cdata['name'] == 'text':
  1270. self.textCtrl.SetValue(cdata['text'])
  1271. self.hidevbox.Layout()
  1272. # self.Layout()
  1273. def OnText(self, event):
  1274. index = self.listbox.GetSelection()
  1275. # should not happen
  1276. if index == wx.NOT_FOUND:
  1277. return
  1278. cdata = self.listbox.GetClientData(index)
  1279. cdata['text'] = event.GetString()
  1280. def OnRemove(self, event):
  1281. index = self.listbox.GetSelection()
  1282. if index == wx.NOT_FOUND:
  1283. return
  1284. decData = self.listbox.GetClientData(index)
  1285. self.decorations.remove(decData)
  1286. self._updateListBox()
  1287. if self.listbox.GetCount():
  1288. self.listbox.SetSelection(0)
  1289. self.OnSelectionChanged(event=None)
  1290. def OnExport(self, event):
  1291. for decor in self.decorations:
  1292. if decor['name'] == 'image':
  1293. if not os.path.exists(decor['file']):
  1294. if decor['file']:
  1295. GError(
  1296. parent=self,
  1297. message=_("File %s not found.") %
  1298. decor['file'])
  1299. else:
  1300. GError(parent=self,
  1301. message=_("Decoration image file is missing."))
  1302. return
  1303. if self.formatChoice.GetSelection() == 0:
  1304. name = self.dirBrowse.GetValue()
  1305. if not os.path.exists(name):
  1306. if name:
  1307. GError(
  1308. parent=self,
  1309. message=_("Directory %s not found.") %
  1310. name)
  1311. else:
  1312. GError(parent=self, message=_(
  1313. "Export directory is missing."))
  1314. return
  1315. elif self.formatChoice.GetSelection() == 1:
  1316. if not self.gifBrowse.GetValue():
  1317. GError(parent=self, message=_("Export file is missing."))
  1318. return
  1319. elif self.formatChoice.GetSelection() == 2:
  1320. if not self.swfBrowse.GetValue():
  1321. GError(parent=self, message=_("Export file is missing."))
  1322. return
  1323. # hide only to keep previous values
  1324. self.Hide()
  1325. self.doExport.emit(exportInfo=self.GetExportInformation(),
  1326. decorations=self.GetDecorations())
  1327. def GetDecorations(self):
  1328. return self.decorations
  1329. def GetExportInformation(self):
  1330. info = {}
  1331. if self.formatChoice.GetSelection() == 0:
  1332. info['method'] = 'sequence'
  1333. info['directory'] = self.dirBrowse.GetValue()
  1334. info['prefix'] = self.prefixCtrl.GetValue()
  1335. info['format'] = self.imSeqFormatChoice.GetStringSelection()
  1336. elif self.formatChoice.GetSelection() == 1:
  1337. info['method'] = 'gif'
  1338. info['file'] = self.gifBrowse.GetValue()
  1339. elif self.formatChoice.GetSelection() == 2:
  1340. info['method'] = 'swf'
  1341. info['file'] = self.swfBrowse.GetValue()
  1342. elif self.formatChoice.GetSelection() == 3:
  1343. info['method'] = 'avi'
  1344. info['file'] = self.aviBrowse.GetValue()
  1345. info['encoding'] = self.encodingText.GetValue()
  1346. info['options'] = self.optionsText.GetValue()
  1347. return info
  1348. def _updateListBox(self):
  1349. self.listbox.Clear()
  1350. names = {
  1351. 'time': _("Time stamp"),
  1352. 'image': _("Image"),
  1353. 'text': _("Text")}
  1354. for decor in self.decorations:
  1355. self.listbox.Append(names[decor['name']], clientData=decor)
  1356. def _hideAll(self):
  1357. self.hidevbox.Show(self.fontBox, False)
  1358. self.hidevbox.Show(self.imageBox, False)
  1359. self.hidevbox.Show(self.textBox, False)
  1360. self.hidevbox.Show(self.posBox, False)
  1361. self.hidevbox.Show(self.informBox, True)
  1362. self.hidevbox.Layout()
  1363. class AnimSimpleLayerManager(SimpleLayerManager):
  1364. """Simple layer manager for animation tool.
  1365. Allows adding space-time dataset or series of maps.
  1366. """
  1367. def __init__(self, parent, layerList,
  1368. lmgrStyle=SIMPLE_LMGR_RASTER | SIMPLE_LMGR_VECTOR |
  1369. SIMPLE_LMGR_TB_TOP | SIMPLE_LMGR_STDS,
  1370. toolbarCls=AnimSimpleLmgrToolbar, modal=True):
  1371. SimpleLayerManager.__init__(
  1372. self, parent, layerList, lmgrStyle, toolbarCls, modal)
  1373. self._3dActivated = False
  1374. def OnAddStds(self, event):
  1375. """Opens dialog for specifying temporal dataset.
  1376. Dummy layer is added first."""
  1377. layer = AnimLayer()
  1378. layer.hidden = True
  1379. self._layerList.AddLayer(layer)
  1380. self.SetStdsProperties(layer)
  1381. event.Skip()
  1382. def SetStdsProperties(self, layer):
  1383. dlg = AddTemporalLayerDialog(
  1384. parent=self, layer=layer, volume=self._3dActivated)
  1385. # first get hidden property, it's altered afterwards
  1386. hidden = layer.hidden
  1387. dlg.CenterOnParent()
  1388. if dlg.ShowModal() == wx.ID_OK:
  1389. layer = dlg.GetLayer()
  1390. if hidden:
  1391. signal = self.layerAdded
  1392. else:
  1393. signal = self.cmdChanged
  1394. signal.emit(
  1395. index=self._layerList.GetLayerIndex(layer),
  1396. layer=layer)
  1397. else:
  1398. if hidden:
  1399. self._layerList.RemoveLayer(layer)
  1400. dlg.Destroy()
  1401. self._update()
  1402. self.anyChange.emit()
  1403. def _layerChangeProperties(self, layer):
  1404. """Opens new module dialog or recycles it."""
  1405. if not hasattr(layer, 'maps'):
  1406. GUI(parent=self, giface=None, modal=self._modal).ParseCommand(
  1407. cmd=layer.cmd, completed=(self.GetOptData, layer, ''))
  1408. else:
  1409. self.SetStdsProperties(layer)
  1410. def Activate3D(self, activate=True):
  1411. """Activates/deactivates certain tool depending on 2D/3D view."""
  1412. self._toolbar.EnableTools(['addRaster', 'addVector',
  1413. 'opacity', 'up', 'down'], not activate)
  1414. self._3dActivated = activate
  1415. class AddTemporalLayerDialog(wx.Dialog):
  1416. """Dialog for adding space-time dataset/ map series."""
  1417. def __init__(self, parent, layer, volume=False,
  1418. title=_("Add space-time dataset layer")):
  1419. wx.Dialog.__init__(self, parent=parent, title=title)
  1420. self.layer = layer
  1421. self._mapType = None
  1422. self._name = None
  1423. self._cmd = None
  1424. self.tselect = Select(parent=self, type='strds')
  1425. iconTheme = UserSettings.Get(
  1426. group='appearance',
  1427. key='iconTheme',
  1428. subkey='type')
  1429. bitmapPath = os.path.join(
  1430. globalvar.ICONDIR,
  1431. iconTheme,
  1432. 'layer-open.png')
  1433. if os.path.isfile(bitmapPath) and os.path.getsize(bitmapPath):
  1434. bitmap = wx.Bitmap(name=bitmapPath)
  1435. else:
  1436. bitmap = wx.ArtProvider.GetBitmap(
  1437. id=wx.ART_MISSING_IMAGE, client=wx.ART_TOOLBAR)
  1438. self.addManyMapsButton = BitmapButton(self, bitmap=bitmap)
  1439. self.addManyMapsButton.Bind(wx.EVT_BUTTON, self._onAddMaps)
  1440. types = [('raster', _("Multiple raster maps")),
  1441. ('vector', _("Multiple vector maps")),
  1442. ('raster_3d', _("Multiple 3D raster maps")),
  1443. ('strds', _("Space time raster dataset")),
  1444. ('stvds', _("Space time vector dataset")),
  1445. ('str3ds', _("Space time 3D raster dataset"))]
  1446. if not volume:
  1447. del types[5]
  1448. del types[2]
  1449. self._types = dict(types)
  1450. self.tchoice = wx.Choice(parent=self)
  1451. for type_, text in types:
  1452. self.tchoice.Append(text, clientData=type_)
  1453. self.editBtn = Button(parent=self, label='Set properties')
  1454. self.okBtn = Button(parent=self, id=wx.ID_OK)
  1455. self.cancelBtn = Button(parent=self, id=wx.ID_CANCEL)
  1456. self.okBtn.Bind(wx.EVT_BUTTON, self._onOK)
  1457. self.editBtn.Bind(wx.EVT_BUTTON, self._onProperties)
  1458. self.tchoice.Bind(wx.EVT_CHOICE,
  1459. lambda evt: self._setType())
  1460. self.tselect.Bind(wx.EVT_TEXT,
  1461. lambda evt: self._datasetChanged())
  1462. if self.layer.mapType:
  1463. self._setType(self.layer.mapType)
  1464. else:
  1465. self._setType('raster')
  1466. if self.layer.name:
  1467. self.tselect.SetValue(self.layer.name)
  1468. if self.layer.cmd:
  1469. self._cmd = self.layer.cmd
  1470. self._layout()
  1471. self.SetSize(self.GetBestSize())
  1472. def _layout(self):
  1473. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1474. bodySizer = wx.BoxSizer(wx.VERTICAL)
  1475. typeSizer = wx.BoxSizer(wx.HORIZONTAL)
  1476. selectSizer = wx.BoxSizer(wx.HORIZONTAL)
  1477. typeSizer.Add(StaticText(self, label=_("Input data type:")),
  1478. flag=wx.ALIGN_CENTER_VERTICAL)
  1479. typeSizer.AddStretchSpacer()
  1480. typeSizer.Add(self.tchoice)
  1481. bodySizer.Add(typeSizer, flag=wx.EXPAND | wx.BOTTOM, border=5)
  1482. selectSizer.Add(self.tselect, flag=wx.RIGHT |
  1483. wx.ALIGN_CENTER_VERTICAL, border=5)
  1484. selectSizer.Add(self.addManyMapsButton, flag=wx.EXPAND)
  1485. bodySizer.Add(selectSizer, flag=wx.BOTTOM, border=5)
  1486. bodySizer.Add(self.editBtn, flag=wx.BOTTOM, border=5)
  1487. mainSizer.Add(
  1488. bodySizer,
  1489. proportion=1,
  1490. flag=wx.EXPAND | wx.ALL,
  1491. border=10)
  1492. btnSizer = wx.StdDialogButtonSizer()
  1493. btnSizer.AddButton(self.okBtn)
  1494. btnSizer.AddButton(self.cancelBtn)
  1495. btnSizer.Realize()
  1496. mainSizer.Add(btnSizer, proportion=0,
  1497. flag=wx.EXPAND | wx.ALL, border=10)
  1498. self.SetSizer(mainSizer)
  1499. mainSizer.Fit(self)
  1500. def _datasetChanged(self):
  1501. if self._name != self.tselect.GetValue():
  1502. self._name = self.tselect.GetValue()
  1503. self._cmd = None
  1504. def _setType(self, typeName=None):
  1505. if typeName:
  1506. self.tchoice.SetStringSelection(self._types[typeName])
  1507. self.tselect.SetType(typeName)
  1508. if typeName in ('strds', 'stvds', 'str3ds'):
  1509. self.tselect.SetType(typeName, multiple=False)
  1510. self.addManyMapsButton.Disable()
  1511. else:
  1512. self.tselect.SetType(typeName, multiple=True)
  1513. self.addManyMapsButton.Enable()
  1514. self._mapType = typeName
  1515. self.tselect.SetValue('')
  1516. else:
  1517. typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
  1518. if typeName in ('strds', 'stvds', 'str3ds'):
  1519. self.tselect.SetType(typeName, multiple=False)
  1520. self.addManyMapsButton.Disable()
  1521. else:
  1522. self.tselect.SetType(typeName, multiple=True)
  1523. self.addManyMapsButton.Enable()
  1524. if typeName != self._mapType:
  1525. self._cmd = None
  1526. self._mapType = typeName
  1527. self.tselect.SetValue('')
  1528. def _createDefaultCommand(self):
  1529. cmd = []
  1530. if self._mapType in ('raster', 'strds'):
  1531. cmd.append('d.rast')
  1532. elif self._mapType in ('vector', 'stvds'):
  1533. cmd.append('d.vect')
  1534. elif self._mapType in ('raster_3d', 'str3ds'):
  1535. cmd.append('d.rast3d')
  1536. if self._name:
  1537. if self._mapType in ('raster', 'vector', 'raster_3d'):
  1538. cmd.append('map={name}'.format(name=self._name.split(',')[0]))
  1539. else:
  1540. try:
  1541. maps = getRegisteredMaps(self._name, etype=self._mapType)
  1542. if maps:
  1543. mapName, mapLayer = getNameAndLayer(maps[0])
  1544. cmd.append('map={name}'.format(name=mapName))
  1545. except gcore.ScriptError as e:
  1546. GError(parent=self, message=str(e), showTraceback=False)
  1547. return None
  1548. return cmd
  1549. def _onAddMaps(self, event):
  1550. dlg = MapLayersDialog(self, title=_("Select raster/vector maps."))
  1551. dlg.applyAddingMapLayers.connect(
  1552. lambda mapLayers: self.tselect.SetValue(
  1553. ','.join(mapLayers)))
  1554. if self._mapType == 'raster':
  1555. index = 0
  1556. elif self._mapType == 'vector':
  1557. index = 2
  1558. else: # rast3d
  1559. index = 1
  1560. dlg.layerType.SetSelection(index)
  1561. dlg.LoadMapLayers(dlg.GetLayerType(cmd=True),
  1562. dlg.mapset.GetStringSelection())
  1563. dlg.CenterOnParent()
  1564. if dlg.ShowModal() == wx.ID_OK:
  1565. self.tselect.SetValue(','.join(dlg.GetMapLayers()))
  1566. dlg.Destroy()
  1567. def _onProperties(self, event):
  1568. self._checkInput()
  1569. if self._cmd:
  1570. GUI(parent=self, show=True, modal=True).ParseCommand(
  1571. cmd=self._cmd, completed=(self._getOptData, '', ''))
  1572. def _checkInput(self):
  1573. if not self.tselect.GetValue():
  1574. GMessage(parent=self, message=_(
  1575. "Please select maps or dataset first."))
  1576. return
  1577. if not self._cmd:
  1578. self._cmd = self._createDefaultCommand()
  1579. def _getOptData(self, dcmd, layer, params, propwin):
  1580. if dcmd:
  1581. self._cmd = dcmd
  1582. def _onOK(self, event):
  1583. self._checkInput()
  1584. if self._cmd:
  1585. try:
  1586. self.layer.hidden = False
  1587. self.layer.mapType = self._mapType
  1588. self.layer.name = self._name
  1589. self.layer.cmd = self._cmd
  1590. event.Skip()
  1591. except (GException, gcore.ScriptError) as e:
  1592. GError(parent=self, message=str(e))
  1593. def GetLayer(self):
  1594. return self.layer
  1595. class PreferencesDialog(PreferencesBaseDialog):
  1596. """Animation preferences dialog"""
  1597. def __init__(self, parent, giface, title=_("Animation Tool settings"),
  1598. settings=UserSettings):
  1599. PreferencesBaseDialog.__init__(
  1600. self, parent=parent, giface=giface, title=title, settings=settings,
  1601. size=(-1, 270))
  1602. self.formatChanged = Signal('PreferencesDialog.formatChanged')
  1603. self._timeFormats = ['%Y-%m-%d %H:%M:%S', # 2013-12-29 11:16:26
  1604. '%Y-%m-%d', # 2013-12-29
  1605. '%c',
  1606. # Sun Dec 29 11:16:26 2013 (locale-dependent)
  1607. '%x', # 12/29/13 (locale-dependent)
  1608. '%X', # 11:16:26 (locale-dependent)
  1609. '%b %d, %Y', # Dec 29, 2013
  1610. '%B %d, %Y', # December 29, 2013
  1611. '%B, %Y', # December 2013
  1612. '%I:%M %p', # 11:16 AM
  1613. '%I %p', # 11 AM
  1614. ]
  1615. self._format = None
  1616. self._initFormat = self.settings.Get(group='animation', key='temporal',
  1617. subkey='format')
  1618. # create notebook pages
  1619. self._createGeneralPage(self.notebook)
  1620. self._createTemporalPage(self.notebook)
  1621. self.SetMinSize(self.GetBestSize())
  1622. self.SetSize(self.size)
  1623. def _createGeneralPage(self, notebook):
  1624. """Create notebook page for general settings"""
  1625. panel = SP.ScrolledPanel(parent=notebook)
  1626. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1627. notebook.AddPage(page=panel, text=_("General"))
  1628. border = wx.BoxSizer(wx.VERTICAL)
  1629. sizer = wx.BoxSizer(wx.VERTICAL)
  1630. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1631. row = 0
  1632. gridSizer.Add(
  1633. StaticText(
  1634. parent=panel,
  1635. label=_("Background color:")),
  1636. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1637. pos=(
  1638. row,
  1639. 0))
  1640. color = csel.ColourSelect(
  1641. parent=panel,
  1642. colour=UserSettings.Get(
  1643. group='animation',
  1644. key='bgcolor',
  1645. subkey='color'),
  1646. size=globalvar.DIALOG_COLOR_SIZE)
  1647. color.SetName('GetColour')
  1648. self.winId['animation:bgcolor:color'] = color.GetId()
  1649. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1650. row += 1
  1651. gridSizer.Add(
  1652. StaticText(
  1653. parent=panel,
  1654. label=_("Number of parallel processes:")),
  1655. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1656. pos=(
  1657. row,
  1658. 0))
  1659. # when running for the first time, set nprocs based on the number of
  1660. # processes
  1661. if UserSettings.Get(group='animation', key='nprocs',
  1662. subkey='value') == -1:
  1663. UserSettings.Set(
  1664. group='animation',
  1665. key='nprocs',
  1666. subkey='value',
  1667. value=getCpuCount())
  1668. nprocs = SpinCtrl(
  1669. parent=panel,
  1670. initial=UserSettings.Get(
  1671. group='animation',
  1672. key='nprocs',
  1673. subkey='value'))
  1674. nprocs.SetName('GetValue')
  1675. self.winId['animation:nprocs:value'] = nprocs.GetId()
  1676. gridSizer.Add(nprocs, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1677. row += 1
  1678. gridSizer.Add(
  1679. StaticText(
  1680. parent=panel,
  1681. label=_("Text foreground color:")),
  1682. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1683. pos=(
  1684. row,
  1685. 0))
  1686. color = csel.ColourSelect(
  1687. parent=panel,
  1688. colour=UserSettings.Get(
  1689. group='animation',
  1690. key='font',
  1691. subkey='fgcolor'),
  1692. size=globalvar.DIALOG_COLOR_SIZE)
  1693. color.SetName('GetColour')
  1694. self.winId['animation:font:fgcolor'] = color.GetId()
  1695. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1696. row += 1
  1697. gridSizer.Add(
  1698. StaticText(
  1699. parent=panel,
  1700. label=_("Text background color:")),
  1701. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1702. pos=(
  1703. row,
  1704. 0))
  1705. color = csel.ColourSelect(
  1706. parent=panel,
  1707. colour=UserSettings.Get(
  1708. group='animation',
  1709. key='font',
  1710. subkey='bgcolor'),
  1711. size=globalvar.DIALOG_COLOR_SIZE)
  1712. color.SetName('GetColour')
  1713. self.winId['animation:font:bgcolor'] = color.GetId()
  1714. gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1715. gridSizer.AddGrowableCol(1)
  1716. sizer.Add(
  1717. gridSizer,
  1718. proportion=1,
  1719. flag=wx.ALL | wx.EXPAND,
  1720. border=3)
  1721. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1722. panel.SetSizer(border)
  1723. return panel
  1724. def _createTemporalPage(self, notebook):
  1725. """Create notebook page for temporal settings"""
  1726. panel = SP.ScrolledPanel(parent=notebook)
  1727. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1728. notebook.AddPage(page=panel, text=_("Time"))
  1729. border = wx.BoxSizer(wx.VERTICAL)
  1730. sizer = wx.BoxSizer(wx.VERTICAL)
  1731. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1732. row = 0
  1733. gridSizer.Add(
  1734. StaticText(
  1735. parent=panel,
  1736. label=_("Absolute time format:")),
  1737. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  1738. pos=(
  1739. row,
  1740. 0))
  1741. self.tempFormat = wx.ComboBox(parent=panel, name='GetValue')
  1742. self.tempFormat.SetItems(self._timeFormats)
  1743. self.tempFormat.SetValue(self._initFormat)
  1744. self.winId['animation:temporal:format'] = self.tempFormat.GetId()
  1745. gridSizer.Add(self.tempFormat, pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1746. self.infoTimeLabel = StaticText(parent=panel)
  1747. self.tempFormat.Bind(
  1748. wx.EVT_COMBOBOX,
  1749. lambda evt: self._setTimeFormat(
  1750. self.tempFormat.GetValue()))
  1751. self.tempFormat.Bind(
  1752. wx.EVT_TEXT, lambda evt: self._setTimeFormat(
  1753. self.tempFormat.GetValue()))
  1754. self.tempFormat.SetToolTipString(
  1755. _(
  1756. "Click and then press key up or down to preview "
  1757. "different date and time formats. "
  1758. "Type custom format string."))
  1759. row += 1
  1760. gridSizer.Add(self.infoTimeLabel, pos=(row, 0), span=(1, 2),
  1761. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1762. self._setTimeFormat(self.tempFormat.GetValue())
  1763. row += 1
  1764. link = HyperlinkCtrl(
  1765. panel, id=wx.ID_ANY,
  1766. label=_("Learn more about formatting options"),
  1767. url="http://docs.python.org/2/library/datetime.html#"
  1768. "strftime-and-strptime-behavior")
  1769. link.SetNormalColour(
  1770. wx.SystemSettings.GetColour(
  1771. wx.SYS_COLOUR_GRAYTEXT))
  1772. link.SetVisitedColour(
  1773. wx.SystemSettings.GetColour(
  1774. wx.SYS_COLOUR_GRAYTEXT))
  1775. gridSizer.Add(link, pos=(row, 0), span=(1, 2),
  1776. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1777. row += 2
  1778. noDataCheck = CheckBox(
  1779. panel, label=_("Display instances with no data"))
  1780. noDataCheck.SetToolTip(
  1781. _(
  1782. "When animating instant-based data which have irregular timestamps "
  1783. "you can display 'no data frame' (checked option) or "
  1784. "keep last frame."))
  1785. noDataCheck.SetValue(
  1786. self.settings.Get(
  1787. group='animation',
  1788. key='temporal',
  1789. subkey=[
  1790. 'nodata',
  1791. 'enable']))
  1792. self.winId['animation:temporal:nodata:enable'] = noDataCheck.GetId()
  1793. gridSizer.Add(noDataCheck, pos=(row, 0), span=(1, 2),
  1794. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1795. gridSizer.AddGrowableCol(1)
  1796. sizer.Add(
  1797. gridSizer,
  1798. proportion=1,
  1799. flag=wx.ALL | wx.EXPAND,
  1800. border=3)
  1801. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1802. panel.SetSizer(border)
  1803. return panel
  1804. def _setTimeFormat(self, formatString):
  1805. now = datetime.datetime.now()
  1806. try:
  1807. label = datetime.datetime.strftime(now, formatString)
  1808. self._format = formatString
  1809. except ValueError:
  1810. label = _("Invalid")
  1811. self.infoTimeLabel.SetLabel(label)
  1812. self.infoTimeLabel.GetContainingSizer().Layout()
  1813. def _updateSettings(self):
  1814. self.tempFormat.SetValue(self._format)
  1815. PreferencesBaseDialog._updateSettings(self)
  1816. if self._format != self._initFormat:
  1817. self.formatChanged.emit()
  1818. return True
  1819. def test():
  1820. import wx.lib.inspection
  1821. app = wx.App()
  1822. # testTemporalLayer()
  1823. # testAnimLmgr()
  1824. testAnimInput()
  1825. # wx.lib.inspection.InspectionTool().Show()
  1826. app.MainLoop()
  1827. def testAnimInput():
  1828. anim = AnimationData()
  1829. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1830. dlg = InputDialog(parent=None, mode='add', animationData=anim)
  1831. dlg.Show()
  1832. def testAnimEdit():
  1833. anim = AnimationData()
  1834. anim.SetDefaultValues(animationIndex=0, windowIndex=0)
  1835. dlg = EditDialog(parent=None, animationData=[anim])
  1836. dlg.Show()
  1837. def testExport():
  1838. dlg = ExportDialog(parent=None, temporal=TemporalMode.TEMPORAL,
  1839. timeTick=200)
  1840. if dlg.ShowModal() == wx.ID_OK:
  1841. print(dlg.GetDecorations())
  1842. print(dlg.GetExportInformation())
  1843. dlg.Destroy()
  1844. else:
  1845. dlg.Destroy()
  1846. def testTemporalLayer():
  1847. frame = wx.Frame(None)
  1848. frame.Show()
  1849. layer = AnimLayer()
  1850. dlg = AddTemporalLayerDialog(parent=frame, layer=layer)
  1851. if dlg.ShowModal() == wx.ID_OK:
  1852. layer = dlg.GetLayer()
  1853. print(layer.name, layer.cmd, layer.mapType)
  1854. dlg.Destroy()
  1855. else:
  1856. dlg.Destroy()
  1857. def testAnimLmgr():
  1858. from core.layerlist import LayerList
  1859. frame = wx.Frame(None)
  1860. mgr = AnimSimpleLayerManager(parent=frame, layerList=LayerList())
  1861. frame.mgr = mgr
  1862. frame.Show()
  1863. if __name__ == '__main__':
  1864. gcore.set_raise_on_error(True)
  1865. test()