toolbars.py 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. """
  2. MODULE: toolbar
  3. CLASSES:
  4. * AbstractToolbar
  5. * MapToolbar
  6. * GRToolbar
  7. * GCPToolbar
  8. * VDigitToolbar
  9. * ProfileToolbar
  10. * NvizToolbar
  11. PURPOSE: Toolbars for Map Display window
  12. AUTHORS: The GRASS Development Team
  13. Michael Barton, Martin Landa, Jachym Cepicky
  14. COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
  15. This program is free software under the GNU General Public
  16. License (>=v2). Read the file COPYING that comes with GRASS
  17. for details.
  18. """
  19. import wx
  20. import os, sys
  21. import globalvar
  22. import gcmd
  23. import grassenv
  24. import gdialogs
  25. import vdigit
  26. from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
  27. from debug import Debug as Debug
  28. from icon import Icons as Icons
  29. from preferences import globalSettings as UserSettings
  30. gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
  31. sys.path.append(gmpath)
  32. class AbstractToolbar(object):
  33. """Abstract toolbar class"""
  34. def __init__():
  35. pass
  36. def InitToolbar(self, parent, toolbar, toolData):
  37. """Initialize toolbar, i.e. add tools to the toolbar
  38. @return list of ids (of added tools)
  39. """
  40. for tool in toolData:
  41. self.CreateTool(parent, toolbar, *tool)
  42. self._toolbar = toolbar
  43. self._data = toolData
  44. def ToolbarData(self):
  45. """Toolbar data"""
  46. return None
  47. def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
  48. shortHelp, longHelp, handler):
  49. """Add tool to the toolbar
  50. @return id of tool
  51. """
  52. bmpDisabled=wx.NullBitmap
  53. if label:
  54. toolWin = toolbar.AddLabelTool(tool, label, bitmap,
  55. bmpDisabled, kind,
  56. shortHelp, longHelp)
  57. parent.Bind(wx.EVT_TOOL, handler, toolWin)
  58. else: # add separator
  59. toolbar.AddSeparator()
  60. return tool
  61. def GetToolbar(self):
  62. """Get toolbar widget reference"""
  63. return self._toolbar
  64. def EnableLongHelp(self, enable=True):
  65. """Enable/disable long help
  66. @param enable True for enable otherwise disable
  67. """
  68. for tool in self._data:
  69. if tool[0] == '': # separator
  70. continue
  71. if enable:
  72. self._toolbar.SetToolLongHelp(tool[0], tool[5])
  73. else:
  74. self._toolbar.SetToolLongHelp(tool[0], "")
  75. class MapToolbar(AbstractToolbar):
  76. """
  77. Main Map Display toolbar
  78. """
  79. def __init__(self, mapdisplay, map):
  80. self.mapcontent = map
  81. self.mapdisplay = mapdisplay
  82. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  83. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  84. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  85. # optional tools
  86. self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value='Tools',
  87. choices=['Digitize', 'Nviz'], style=wx.CB_READONLY, size=(90, -1))
  88. self.comboid = self.toolbar.AddControl(self.combo)
  89. self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  90. # realize the toolbar
  91. self.toolbar.Realize()
  92. def ToolbarData(self):
  93. """Toolbar data"""
  94. self.displaymap = wx.NewId()
  95. self.rendermap = wx.NewId()
  96. self.erase = wx.NewId()
  97. self.pointer = wx.NewId()
  98. self.query = wx.NewId()
  99. self.pan = wx.NewId()
  100. self.zoomin = wx.NewId()
  101. self.zoomout = wx.NewId()
  102. self.zoomback = wx.NewId()
  103. self.zoommenu = wx.NewId()
  104. self.analyze = wx.NewId()
  105. self.dec = wx.NewId()
  106. self.savefile = wx.NewId()
  107. self.printmap = wx.NewId()
  108. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  109. return (
  110. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  111. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  112. self.mapdisplay.OnDraw),
  113. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  114. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  115. self.mapdisplay.OnRender),
  116. (self.erase, "erase", Icons["erase"].GetBitmap(),
  117. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  118. self.mapdisplay.OnErase),
  119. ("", "", "", "", "", "", ""),
  120. (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
  121. wx.ITEM_RADIO, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
  122. self.mapdisplay.OnPointer),
  123. (self.query, "queryDisplay", Icons["queryDisplay"].GetBitmap(),
  124. wx.ITEM_RADIO, Icons["queryDisplay"].GetLabel(), Icons["queryDisplay"].GetDesc(),
  125. self.mapdisplay.OnQuery),
  126. (self.pan, "pan", Icons["pan"].GetBitmap(),
  127. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  128. self.mapdisplay.OnPan),
  129. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  130. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  131. self.mapdisplay.OnZoomIn),
  132. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  133. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  134. self.mapdisplay.OnZoomOut),
  135. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  136. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  137. self.mapdisplay.OnZoomBack),
  138. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  139. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  140. self.mapdisplay.OnZoomMenu),
  141. ("", "", "", "", "", "", ""),
  142. (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
  143. wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
  144. self.mapdisplay.OnAnalyze),
  145. ("", "", "", "", "", "", ""),
  146. (self.dec, "overlay", Icons["overlay"].GetBitmap(),
  147. wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
  148. self.mapdisplay.OnDecoration),
  149. ("", "", "", "", "", "", ""),
  150. (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
  151. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  152. self.mapdisplay.SaveToFile),
  153. (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
  154. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  155. self.mapdisplay.PrintMenu),
  156. ("", "", "", "", "", "", "")
  157. )
  158. def OnSelectTool(self, event):
  159. """
  160. Select / enable tool available in tools list
  161. """
  162. tool = event.GetString()
  163. if tool == "Digitize" and not self.mapdisplay.toolbars['vdigit']:
  164. self.mapdisplay.AddToolbar("vdigit")
  165. elif tool == "Nviz" and not self.mapdisplay.toolbars['nviz']:
  166. self.mapdisplay.AddToolbar("nviz")
  167. def Enable2D(self, enabled):
  168. """Enable/Disable 2D display mode specific tools"""
  169. for tool in (self.pointer,
  170. self.query,
  171. self.pan,
  172. self.zoomin,
  173. self.zoomout,
  174. self.zoomback,
  175. self.zoommenu,
  176. self.analyze,
  177. self.dec,
  178. self.savefile,
  179. self.printmap):
  180. self.toolbar.EnableTool(tool, enabled)
  181. class GRToolbar(AbstractToolbar):
  182. """
  183. Georectify Display toolbar
  184. """
  185. def __init__(self, mapdisplay, map):
  186. self.mapcontent = map
  187. self.mapdisplay = mapdisplay
  188. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  189. # self.SetToolBar(self.toolbar)
  190. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  191. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  192. # realize the toolbar
  193. self.toolbar.Realize()
  194. def ToolbarData(self):
  195. """Toolbar data"""
  196. self.displaymap = wx.NewId()
  197. self.rendermap = wx.NewId()
  198. self.erase = wx.NewId()
  199. self.gcpset = wx.NewId()
  200. self.pan = wx.NewId()
  201. self.zoomin = wx.NewId()
  202. self.zoomout = wx.NewId()
  203. self.zoomback = wx.NewId()
  204. self.zoommenu = wx.NewId()
  205. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  206. return (
  207. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  208. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  209. self.mapdisplay.OnDraw),
  210. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  211. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  212. self.mapdisplay.OnRender),
  213. (self.erase, "erase", Icons["erase"].GetBitmap(),
  214. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  215. self.mapdisplay.OnErase),
  216. ("", "", "", "", "", "", ""),
  217. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  218. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  219. self.mapdisplay.OnPointer),
  220. (self.pan, "pan", Icons["pan"].GetBitmap(),
  221. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  222. self.mapdisplay.OnPan),
  223. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  224. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  225. self.mapdisplay.OnZoomIn),
  226. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  227. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  228. self.mapdisplay.OnZoomOut),
  229. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  230. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  231. self.mapdisplay.OnZoomBack),
  232. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  233. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  234. self.mapdisplay.OnZoomMenu),
  235. )
  236. class GCPToolbar(AbstractToolbar):
  237. """
  238. Toolbar for digitization
  239. """
  240. def __init__(self, parent, mapdisplay, map):
  241. self.parent = parent # GCP
  242. self.mapcontent = map
  243. self.mapdisplay = mapdisplay
  244. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  245. # self.SetToolBar(self.toolbar)
  246. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  247. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  248. # realize the toolbar
  249. self.toolbar.Realize()
  250. def ToolbarData(self):
  251. self.gcpSave = wx.NewId()
  252. self.gcpAdd = wx.NewId()
  253. self.gcpDelete = wx.NewId()
  254. self.gcpClear = wx.NewId()
  255. self.gcpReload = wx.NewId()
  256. self.rms = wx.NewId()
  257. self.georect = wx.NewId()
  258. self.settings = wx.NewId()
  259. self.quit = wx.NewId()
  260. return (
  261. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  262. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  263. self.parent.SaveGCPs),
  264. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  265. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  266. self.parent.AddGCP),
  267. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  268. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  269. self.parent.DeleteGCP),
  270. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  271. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  272. self.parent.ClearGCP),
  273. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  274. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  275. self.parent.ReloadGCPs),
  276. ("", "", "", "", "", "", ""),
  277. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  278. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  279. self.parent.OnRMS),
  280. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  281. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  282. self.parent.OnGeorect),
  283. ("", "", "", "", "", "", ""),
  284. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  285. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  286. self.parent.OnSettings),
  287. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  288. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  289. self.parent.OnQuit)
  290. )
  291. class VDigitToolbar(AbstractToolbar):
  292. """
  293. Toolbar for digitization
  294. """
  295. def __init__(self, parent, map, layerTree=None):
  296. self.mapcontent = map # Map class instance
  297. self.parent = parent # MapFrame
  298. self.layerTree = layerTree # reference to layer tree associated to map display
  299. # selected map to digitize
  300. self.layerSelectedID = None
  301. self.layers = []
  302. # default action (digitize new point, line, etc.)
  303. self.action = "addLine"
  304. self.type = "point"
  305. self.addString = ""
  306. self.comboid = None
  307. # only one dialog can be open
  308. self.settingsDialog = None
  309. # create toolbars (two rows optionaly)
  310. self.toolbar = []
  311. self.numOfRows = 1 # number of rows for toolbar
  312. for row in range(0, self.numOfRows):
  313. self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
  314. self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
  315. self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
  316. # create toolbar
  317. if self.numOfRows == 1:
  318. rowdata=None
  319. else:
  320. rowdata = row
  321. self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
  322. # list of available vector maps
  323. self.UpdateListOfLayers(updateTool=True)
  324. # realize toolbar
  325. for row in range(0, self.numOfRows):
  326. self.toolbar[row].Realize()
  327. # disable undo/redo
  328. self.toolbar[0].EnableTool(self.undo, False)
  329. # toogle to pointer by default
  330. self.OnTool(None)
  331. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  332. self.toolbar[0].EnableTool(self.copyCats, False) # not implemented (TODO)
  333. self.toolbar[0].SetToolShortHelp(self.copyCats, _("Not implemented yet"))
  334. def ToolbarData(self, row=None):
  335. """
  336. Toolbar data
  337. """
  338. data = []
  339. if row is None or row == 0:
  340. self.addPoint = wx.NewId()
  341. self.addLine = wx.NewId()
  342. self.addBoundary = wx.NewId()
  343. self.addCentroid = wx.NewId()
  344. self.moveVertex = wx.NewId()
  345. self.addVertex = wx.NewId()
  346. self.removeVertex = wx.NewId()
  347. self.splitLine = wx.NewId()
  348. self.editLine = wx.NewId()
  349. self.moveLine = wx.NewId()
  350. self.deleteLine = wx.NewId()
  351. self.additionalTools = wx.NewId()
  352. self.displayCats = wx.NewId()
  353. self.displayAttr = wx.NewId()
  354. self.copyCats = wx.NewId()
  355. data = [("", "", "", "", "", "", ""),
  356. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  357. wx.ITEM_RADIO, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  358. self.OnAddPoint),
  359. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  360. wx.ITEM_RADIO, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  361. self.OnAddLine),
  362. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  363. wx.ITEM_RADIO, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  364. self.OnAddBoundary),
  365. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  366. wx.ITEM_RADIO, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  367. self.OnAddCentroid),
  368. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  369. wx.ITEM_RADIO, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  370. self.OnMoveVertex),
  371. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  372. wx.ITEM_RADIO, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  373. self.OnAddVertex),
  374. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  375. wx.ITEM_RADIO, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  376. self.OnRemoveVertex),
  377. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  378. wx.ITEM_RADIO, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  379. self.OnSplitLine),
  380. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  381. wx.ITEM_RADIO, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  382. self.OnEditLine),
  383. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  384. wx.ITEM_RADIO, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  385. self.OnMoveLine),
  386. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  387. wx.ITEM_RADIO, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  388. self.OnDeleteLine),
  389. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  390. wx.ITEM_RADIO, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  391. self.OnDisplayCats),
  392. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  393. wx.ITEM_RADIO, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  394. self.OnCopyCats),
  395. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  396. wx.ITEM_RADIO, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  397. self.OnDisplayAttr),
  398. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  399. wx.ITEM_RADIO, Icons["digAdditionalTools"].GetLabel(),
  400. Icons["digAdditionalTools"].GetDesc(),
  401. self.OnAdditionalToolMenu)]
  402. if row is None or row == 1:
  403. self.undo = wx.NewId()
  404. self.settings = wx.NewId()
  405. self.exit = wx.NewId()
  406. data.append(("", "", "", "", "", "", ""))
  407. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  408. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  409. self.OnUndo))
  410. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  411. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  412. # self.OnRedo))
  413. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  414. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  415. self.OnSettings))
  416. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  417. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  418. self.OnExit))
  419. return data
  420. def OnTool(self, event):
  421. """Tool selected -> toggle tool to pointer"""
  422. id = self.parent.toolbars['map'].pointer
  423. self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
  424. self.parent.toolbars['map'].mapdisplay.OnPointer(event)
  425. if event:
  426. event.Skip()
  427. def OnAddPoint(self, event):
  428. """Add point to the vector map Laier"""
  429. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  430. self.action = "addLine"
  431. self.type = "point"
  432. self.parent.MapWindow.mouse['box'] = 'point'
  433. def OnAddLine(self, event):
  434. """Add line to the vector map layer"""
  435. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  436. self.action = "addLine"
  437. self.type = "line"
  438. self.parent.MapWindow.mouse['box'] = 'line'
  439. self.parent.MapWindow.polycoords = [] # reset temp line
  440. def OnAddBoundary(self, event):
  441. """Add boundary to the vector map layer"""
  442. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  443. self.action = "addLine"
  444. self.type = "boundary"
  445. self.parent.MapWindow.mouse['box'] = 'line'
  446. self.parent.MapWindow.polycoords = [] # reset temp line
  447. def OnAddCentroid(self, event):
  448. """Add centroid to the vector map layer"""
  449. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  450. self.action = "addLine"
  451. self.type = "centroid"
  452. self.parent.MapWindow.mouse['box'] = 'point'
  453. def OnExit (self, event=None):
  454. """Quit digitization tool"""
  455. # stop editing of the currently selected map layer
  456. try:
  457. self.StopEditing(self.layers[self.layerSelectedID])
  458. except:
  459. pass
  460. # close dialogs if still open
  461. if self.settingsDialog:
  462. self.settingsDialog.OnCancel(None)
  463. if self.parent.dialogs['category']:
  464. self.parent.dialogs['category'].OnCancel(None)
  465. if self.parent.dialogs['attributes']:
  466. self.parent.dialogs['attributes'].OnCancel(None)
  467. # disable the toolbar
  468. self.parent.RemoveToolbar ("vdigit")
  469. def OnMoveVertex(self, event):
  470. """Move line vertex"""
  471. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  472. self.action = "moveVertex"
  473. self.parent.MapWindow.mouse['box'] = 'point'
  474. def OnAddVertex(self, event):
  475. """Add line vertex"""
  476. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  477. self.action = "addVertex"
  478. self.parent.MapWindow.mouse['box'] = 'point'
  479. def OnRemoveVertex(self, event):
  480. """Remove line vertex"""
  481. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  482. self.action = "removeVertex"
  483. self.parent.MapWindow.mouse['box'] = 'point'
  484. def OnSplitLine(self, event):
  485. """Split line"""
  486. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  487. self.action = "splitLine"
  488. self.parent.MapWindow.mouse['box'] = 'point'
  489. def OnEditLine(self, event):
  490. """Edit line"""
  491. Debug.msg(2, "Digittoolbar.OnEditLine():")
  492. self.action="editLine"
  493. self.parent.MapWindow.mouse['box'] = 'line'
  494. def OnMoveLine(self, event):
  495. """Move line"""
  496. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  497. self.action = "moveLine"
  498. self.parent.MapWindow.mouse['box'] = 'box'
  499. def OnDeleteLine(self, event):
  500. """Delete line"""
  501. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  502. self.action = "deleteLine"
  503. self.parent.MapWindow.mouse['box'] = 'box'
  504. def OnDisplayCats(self, event):
  505. """Display/update categories"""
  506. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  507. self.action="displayCats"
  508. self.parent.MapWindow.mouse['box'] = 'point'
  509. def OnDisplayAttr(self, event):
  510. """Display/update attributes"""
  511. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  512. self.action="displayAttrs"
  513. self.parent.MapWindow.mouse['box'] = 'point'
  514. def OnCopyCats(self, event):
  515. """Copy categories"""
  516. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  517. self.action="copyCats"
  518. self.parent.MapWindow.mouse['box'] = 'point'
  519. def OnUndo(self, event):
  520. """Undo previous changes"""
  521. self.parent.digit.Undo()
  522. event.Skip()
  523. def EnableUndo(self, enable=True):
  524. """Enable 'Undo' in toolbar
  525. @param enable False for disable
  526. """
  527. if enable:
  528. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  529. self.toolbar[0].EnableTool(self.undo, True)
  530. else:
  531. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  532. self.toolbar[0].EnableTool(self.undo, False)
  533. def OnSettings(self, event):
  534. """Show settings dialog"""
  535. if self.parent.digit is None:
  536. reload(vdigit)
  537. from vdigit import Digit as Digit
  538. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  539. if not self.settingsDialog:
  540. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  541. style=wx.DEFAULT_DIALOG_STYLE)
  542. self.settingsDialog.Show()
  543. def OnAdditionalToolMenu(self, event):
  544. """Menu for additional tools"""
  545. point = wx.GetMousePosition()
  546. toolMenu = wx.Menu()
  547. # Add items to the menu
  548. copy = wx.MenuItem(toolMenu, wx.ID_ANY, _('Copy features from (background) vector map'))
  549. toolMenu.AppendItem(copy)
  550. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  551. flip = wx.MenuItem(toolMenu, wx.ID_ANY, _('Flip selected lines/boundaries'))
  552. toolMenu.AppendItem(flip)
  553. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  554. merge = wx.MenuItem(toolMenu, wx.ID_ANY, _('Merge selected lines/boundaries'))
  555. toolMenu.AppendItem(merge)
  556. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  557. breakL = wx.MenuItem(toolMenu, wx.ID_ANY, _('Break selected lines/boundaries at intersection'))
  558. toolMenu.AppendItem(breakL)
  559. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  560. snap = wx.MenuItem(toolMenu, wx.ID_ANY, _('Snap selected lines/boundaries (only to nodes)'))
  561. toolMenu.AppendItem(snap)
  562. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  563. connect = wx.MenuItem(toolMenu, wx.ID_ANY, _('Connect two selected lines/boundaries'))
  564. toolMenu.AppendItem(connect)
  565. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  566. query = wx.MenuItem(toolMenu, wx.ID_ANY, _('Query tool'))
  567. toolMenu.AppendItem(query)
  568. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  569. zbulk = wx.MenuItem(toolMenu, wx.ID_ANY, _('Z bulk-labeling of 3D lines'))
  570. toolMenu.AppendItem(zbulk)
  571. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  572. typeconv = wx.MenuItem(toolMenu, wx.ID_ANY, _('Feature type conversion'))
  573. toolMenu.AppendItem(typeconv)
  574. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  575. # Popup the menu. If an item is selected then its handler
  576. # will be called before PopupMenu returns.
  577. self.parent.MapWindow.PopupMenu(toolMenu)
  578. toolMenu.Destroy()
  579. def OnCopy(self, event):
  580. """Copy selected features from (background) vector map"""
  581. Debug.msg(2, "Digittoolbar.OnCopy():")
  582. self.action="copyLine"
  583. self.parent.MapWindow.mouse['box'] = 'box'
  584. def OnFlip(self, event):
  585. """Flip selected lines/boundaries"""
  586. Debug.msg(2, "Digittoolbar.OnFlip():")
  587. self.action="flipLine"
  588. self.parent.MapWindow.mouse['box'] = 'box'
  589. def OnMerge(self, event):
  590. """Merge selected lines/boundaries"""
  591. Debug.msg(2, "Digittoolbar.OnMerge():")
  592. self.action="mergeLine"
  593. self.parent.MapWindow.mouse['box'] = 'box'
  594. def OnBreak(self, event):
  595. """Break selected lines/boundaries"""
  596. Debug.msg(2, "Digittoolbar.OnBreak():")
  597. self.action="breakLine"
  598. self.parent.MapWindow.mouse['box'] = 'box'
  599. def OnSnap(self, event):
  600. """Snap selected features"""
  601. Debug.msg(2, "Digittoolbar.OnSnap():")
  602. self.action="snapLine"
  603. self.parent.MapWindow.mouse['box'] = 'box'
  604. def OnConnect(self, event):
  605. """Connect selected lines/boundaries"""
  606. Debug.msg(2, "Digittoolbar.OnConnect():")
  607. self.action="connectLine"
  608. self.parent.MapWindow.mouse['box'] = 'point'
  609. def OnQuery(self, event):
  610. """Query selected lines/boundaries"""
  611. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  612. UserSettings.Get(group='vdigit', key='query', subkey='type'))
  613. self.action="queryLine"
  614. self.parent.MapWindow.mouse['box'] = 'box'
  615. def OnZBulk(self, event):
  616. """Z bulk-labeling selected lines/boundaries"""
  617. Debug.msg(2, "Digittoolbar.OnZBulk():")
  618. self.action="zbulkLine"
  619. self.parent.MapWindow.mouse['box'] = 'line'
  620. def OnTypeConversion(self, event):
  621. """Feature type conversion
  622. Supported conversions:
  623. - point <-> centroid
  624. - line <-> boundary
  625. """
  626. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  627. self.action="typeConv"
  628. self.parent.MapWindow.mouse['box'] = 'box'
  629. def OnSelectMap (self, event):
  630. """
  631. Select vector map layer for editing
  632. If there is a vector map layer already edited, this action is
  633. firstly terminated. The map layer is closed. After this the
  634. selected map layer activated for editing.
  635. """
  636. if event.GetSelection() == 0: # create new vector map layer
  637. if self.layerSelectedID is not None:
  638. openVectorMap = self.layers[self.layerSelectedID].name.split('@')[0]
  639. else:
  640. openVectorMap = None
  641. mapName = gdialogs.CreateNewVector(self.parent,
  642. exceptMap=openVectorMap)
  643. if mapName:
  644. # add layer to map layer tree
  645. if self.layerTree:
  646. self.layerTree.AddLayer(ltype='vector',
  647. lname=mapName,
  648. lchecked=True,
  649. lopacity=1.0,
  650. lcmd=['d.vect', 'map=%s' % mapName])
  651. vectLayers = self.UpdateListOfLayers(updateTool=True)
  652. selection = vectLayers.index(mapName)
  653. else:
  654. pass # TODO (no Layer Manager)
  655. else:
  656. self.combo.SetValue(_('Select vector map'))
  657. return
  658. else:
  659. selection = event.GetSelection() - 1 # first option is 'New vector map'
  660. if self.layerSelectedID == selection:
  661. return False
  662. if self.layerSelectedID != None: # deactive map layer for editing
  663. self.StopEditing(self.layers[self.layerSelectedID])
  664. # select the given map layer for editing
  665. self.layerSelectedID = selection
  666. self.StartEditing(self.layers[self.layerSelectedID])
  667. event.Skip()
  668. return True
  669. def StartEditing (self, layerSelected):
  670. """
  671. Start editing of selected vector map layer.
  672. @param layerSelectedId id of layer to be edited
  673. @return True on success
  674. @return False on error
  675. """
  676. reload(vdigit)
  677. from vdigit import Digit as Digit
  678. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  679. try:
  680. self.layerSelectedID = self.layers.index(layerSelected)
  681. mapLayer = self.layers[self.layerSelectedID]
  682. except:
  683. return False
  684. try:
  685. self.parent.digit.SetMapName(mapLayer.name)
  686. except gcmd.DigitError, e:
  687. self.layerSelectedID = None
  688. print >> sys.stderr, e # wxMessageBox
  689. return False
  690. # update toolbar
  691. self.combo.SetValue (layerSelected.name)
  692. self.parent.toolbars['map'].combo.SetValue ('Digitize')
  693. # set initial category number for new features (layer=1), etc.
  694. Debug.msg (4, "VDigitToolbar.StartEditing(): layerSelectedID=%d layer=%s" % \
  695. (self.layerSelectedID, mapLayer.name))
  696. # deactive layer
  697. self.mapcontent.ChangeLayerActive(mapLayer, False)
  698. # change cursor
  699. if self.parent.MapWindow.mouse['use'] == 'pointer':
  700. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  701. # create pseudoDC for drawing the map
  702. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  703. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  704. # self.parent.MapWindow.UpdateMap()
  705. if not self.parent.MapWindow.resize:
  706. self.parent.MapWindow.UpdateMap(render=True)
  707. return True
  708. def StopEditing (self, layerSelected):
  709. """
  710. Stop editing of selected vector map layer.
  711. """
  712. if self.layers[self.layerSelectedID] == layerSelected:
  713. self.layerSelectedID = None
  714. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % \
  715. (layerSelected.name))
  716. self.combo.SetValue (_('Select vector map'))
  717. # save changes (only for vdigit)
  718. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  719. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  720. if self.parent.digit.GetUndoLevel() > 0:
  721. dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
  722. "in vector map <%s>?") % layerSelected.name,
  723. caption=_("Save changes?"),
  724. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  725. if dlg.ShowModal() == wx.ID_NO:
  726. # revert changes
  727. self.parent.digit.Undo(0)
  728. dlg.Destroy()
  729. self.parent.digit.SetMapName(None) # -> close map
  730. # re-active layer
  731. item = self.parent.tree.FindItemByData('maplayer', layerSelected)
  732. if item and self.parent.tree.IsItemChecked(item):
  733. self.mapcontent.ChangeLayerActive(layerSelected, True)
  734. # change cursor
  735. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  736. # disable pseudodc for vector map layer
  737. self.parent.MapWindow.pdcVector = None
  738. self.parent.digit.driver.SetDevice(None)
  739. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  740. self.parent.digit = None
  741. return True
  742. return False
  743. def UpdateListOfLayers (self, updateTool=False):
  744. """
  745. Update list of available vector map layers.
  746. This list consists only editable layers (in the current mapset)
  747. Optionaly also update toolbar
  748. """
  749. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  750. updateTool)
  751. layerNameSelected = None
  752. if self.layerSelectedID != None: # name of currently selected layer
  753. layerNameSelected = self.layers[self.layerSelectedID].name
  754. # select vector map layer in the current mapset
  755. layerNameList = []
  756. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  757. l_mapset=grassenv.GetGRASSVariable('MAPSET'))
  758. for layer in self.layers:
  759. if not layer.name in layerNameList: # do not duplicate layer
  760. layerNameList.append (layer.name)
  761. if updateTool: # update toolbar
  762. if self.layerSelectedID == None:
  763. value = _('Select vector map')
  764. else:
  765. value = layerNameSelected
  766. if not self.comboid:
  767. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  768. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  769. style=wx.CB_READONLY)
  770. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  771. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  772. else:
  773. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  774. # update layer index
  775. try:
  776. self.layerSelectedID = layerNameList.index(value)
  777. except ValueError:
  778. self.layerSelectedID = None
  779. self.toolbar[self.numOfRows-1].Realize()
  780. return layerNameList
  781. class ProfileToolbar(AbstractToolbar):
  782. """
  783. Toolbar for digitization
  784. """
  785. def __init__(self, parent, mapdisplay, map):
  786. self.parent = parent
  787. self.mapcontent = map
  788. self.mapdisplay = mapdisplay
  789. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  790. # self.SetToolBar(self.toolbar)
  791. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  792. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  793. # realize the toolbar
  794. self.toolbar.Realize()
  795. def ToolbarData(self):
  796. """Toolbar data"""
  797. self.transect = wx.NewId()
  798. self.addraster = wx.NewId()
  799. self.draw = wx.NewId()
  800. self.options = wx.NewId()
  801. self.drag = wx.NewId()
  802. self.zoom = wx.NewId()
  803. self.unzoom = wx.NewId()
  804. self.erase = wx.NewId()
  805. self.save = wx.NewId()
  806. self.printer = wx.NewId()
  807. self.quit = wx.NewId()
  808. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  809. return (
  810. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  811. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  812. self.parent.OnDrawTransect),
  813. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  814. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  815. self.parent.OnSelectRaster),
  816. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  817. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  818. self.parent.OnCreateProfile),
  819. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  820. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  821. self.parent.ProfileOptionsMenu),
  822. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  823. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  824. self.parent.OnDrag),
  825. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  826. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  827. self.parent.OnZoom),
  828. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  829. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  830. self.parent.OnRedraw),
  831. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  832. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  833. self.parent.OnErase),
  834. ("", "", "", "", "", "", ""),
  835. (self.save, 'save', Icons["savefile"].GetBitmap(),
  836. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  837. self.parent.SaveToFile),
  838. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  839. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  840. self.parent.PrintMenu),
  841. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  842. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  843. self.parent.OnQuit),
  844. )
  845. class NvizToolbar(AbstractToolbar):
  846. """
  847. Nviz toolbar
  848. """
  849. def __init__(self, parent, map):
  850. self.parent = parent
  851. self.mapcontent = map
  852. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  853. # self.SetToolBar(self.toolbar)
  854. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  855. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  856. # realize the toolbar
  857. self.toolbar.Realize()
  858. def ToolbarData(self):
  859. """Toolbar data"""
  860. self.settings = wx.NewId()
  861. self.quit = wx.NewId()
  862. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  863. return (
  864. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  865. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  866. self.OnSettings),
  867. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  868. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  869. self.OnExit),
  870. )
  871. def OnSettings(self, event):
  872. win = self.parent.nvizToolWin
  873. if not win.IsShown():
  874. self.parent.nvizToolWin.Show()
  875. def OnExit (self, event=None):
  876. """Quit nviz tool (swith to 2D mode)"""
  877. # disable the toolbar
  878. self.parent.RemoveToolbar ("nviz")