toolbars.py 42 KB

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