toolbars.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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. Georectification 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. )
  240. class GCPToolbar(AbstractToolbar):
  241. """
  242. Toolbar for managing ground control points during georectification
  243. """
  244. def __init__(self, parent, tbframe):
  245. self.parent = parent # GCP
  246. self.tbframe = tbframe
  247. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  248. # self.SetToolBar(self.toolbar)
  249. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  250. self.InitToolbar(self.tbframe, 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. # currently selected map layer for editing (reference to MapLayer instance)
  303. self.mapLayer = None
  304. # list of vector layers from Layer Manager (only in the current mapset)
  305. self.layers = []
  306. # default action (digitize new point, line, etc.)
  307. self.action = "addLine"
  308. self.type = "point"
  309. self.addString = ""
  310. self.comboid = None
  311. # only one dialog can be open
  312. self.settingsDialog = None
  313. # create toolbars (two rows optionaly)
  314. self.toolbar = []
  315. self.numOfRows = 1 # number of rows for toolbar
  316. for row in range(0, self.numOfRows):
  317. self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
  318. self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
  319. self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
  320. # create toolbar
  321. if self.numOfRows == 1:
  322. rowdata=None
  323. else:
  324. rowdata = row
  325. self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
  326. # list of available vector maps
  327. self.UpdateListOfLayers(updateTool=True)
  328. # realize toolbar
  329. for row in range(0, self.numOfRows):
  330. self.toolbar[row].Realize()
  331. # disable undo/redo
  332. self.toolbar[0].EnableTool(self.undo, False)
  333. # toogle to pointer by default
  334. self.OnTool(None)
  335. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  336. self.toolbar[0].EnableTool(self.copyCats, False) # not implemented (TODO)
  337. self.toolbar[0].SetToolShortHelp(self.copyCats, _("Not implemented yet"))
  338. def ToolbarData(self, row=None):
  339. """
  340. Toolbar data
  341. """
  342. data = []
  343. if row is None or row == 0:
  344. self.addPoint = wx.NewId()
  345. self.addLine = wx.NewId()
  346. self.addBoundary = wx.NewId()
  347. self.addCentroid = wx.NewId()
  348. self.moveVertex = wx.NewId()
  349. self.addVertex = wx.NewId()
  350. self.removeVertex = wx.NewId()
  351. self.splitLine = wx.NewId()
  352. self.editLine = wx.NewId()
  353. self.moveLine = wx.NewId()
  354. self.deleteLine = wx.NewId()
  355. self.additionalTools = wx.NewId()
  356. self.displayCats = wx.NewId()
  357. self.displayAttr = wx.NewId()
  358. self.copyCats = wx.NewId()
  359. data = [("", "", "", "", "", "", ""),
  360. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  361. wx.ITEM_RADIO, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  362. self.OnAddPoint),
  363. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  364. wx.ITEM_RADIO, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  365. self.OnAddLine),
  366. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  367. wx.ITEM_RADIO, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  368. self.OnAddBoundary),
  369. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  370. wx.ITEM_RADIO, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  371. self.OnAddCentroid),
  372. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  373. wx.ITEM_RADIO, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  374. self.OnMoveVertex),
  375. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  376. wx.ITEM_RADIO, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  377. self.OnAddVertex),
  378. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  379. wx.ITEM_RADIO, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  380. self.OnRemoveVertex),
  381. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  382. wx.ITEM_RADIO, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  383. self.OnSplitLine),
  384. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  385. wx.ITEM_RADIO, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  386. self.OnEditLine),
  387. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  388. wx.ITEM_RADIO, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  389. self.OnMoveLine),
  390. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  391. wx.ITEM_RADIO, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  392. self.OnDeleteLine),
  393. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  394. wx.ITEM_RADIO, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  395. self.OnDisplayCats),
  396. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  397. wx.ITEM_RADIO, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  398. self.OnCopyCats),
  399. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  400. wx.ITEM_RADIO, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  401. self.OnDisplayAttr),
  402. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  403. wx.ITEM_RADIO, Icons["digAdditionalTools"].GetLabel(),
  404. Icons["digAdditionalTools"].GetDesc(),
  405. self.OnAdditionalToolMenu)]
  406. if row is None or row == 1:
  407. self.undo = wx.NewId()
  408. self.settings = wx.NewId()
  409. self.exit = wx.NewId()
  410. data.append(("", "", "", "", "", "", ""))
  411. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  412. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  413. self.OnUndo))
  414. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  415. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  416. # self.OnRedo))
  417. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  418. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  419. self.OnSettings))
  420. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  421. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  422. self.OnExit))
  423. return data
  424. def OnTool(self, event):
  425. """Tool selected -> toggle tool to pointer"""
  426. id = self.parent.toolbars['map'].pointer
  427. self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
  428. self.parent.toolbars['map'].mapdisplay.OnPointer(event)
  429. if event:
  430. event.Skip()
  431. def OnAddPoint(self, event):
  432. """Add point to the vector map Laier"""
  433. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  434. self.action = "addLine"
  435. self.type = "point"
  436. self.parent.MapWindow.mouse['box'] = 'point'
  437. def OnAddLine(self, event):
  438. """Add line to the vector map layer"""
  439. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  440. self.action = "addLine"
  441. self.type = "line"
  442. self.parent.MapWindow.mouse['box'] = 'line'
  443. self.parent.MapWindow.polycoords = [] # reset temp line
  444. def OnAddBoundary(self, event):
  445. """Add boundary to the vector map layer"""
  446. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  447. self.action = "addLine"
  448. self.type = "boundary"
  449. self.parent.MapWindow.mouse['box'] = 'line'
  450. self.parent.MapWindow.polycoords = [] # reset temp line
  451. def OnAddCentroid(self, event):
  452. """Add centroid to the vector map layer"""
  453. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  454. self.action = "addLine"
  455. self.type = "centroid"
  456. self.parent.MapWindow.mouse['box'] = 'point'
  457. def OnExit (self, event=None):
  458. """Quit digitization tool"""
  459. # stop editing of the currently selected map layer
  460. if self.mapLayer:
  461. self.StopEditing()
  462. # close dialogs if still open
  463. if self.settingsDialog:
  464. self.settingsDialog.OnCancel(None)
  465. if self.parent.dialogs['category']:
  466. self.parent.dialogs['category'].OnCancel(None)
  467. if self.parent.dialogs['attributes']:
  468. self.parent.dialogs['attributes'].OnCancel(None)
  469. # disable the toolbar
  470. self.parent.RemoveToolbar ("vdigit")
  471. def OnMoveVertex(self, event):
  472. """Move line vertex"""
  473. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  474. self.action = "moveVertex"
  475. self.parent.MapWindow.mouse['box'] = 'point'
  476. def OnAddVertex(self, event):
  477. """Add line vertex"""
  478. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  479. self.action = "addVertex"
  480. self.parent.MapWindow.mouse['box'] = 'point'
  481. def OnRemoveVertex(self, event):
  482. """Remove line vertex"""
  483. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  484. self.action = "removeVertex"
  485. self.parent.MapWindow.mouse['box'] = 'point'
  486. def OnSplitLine(self, event):
  487. """Split line"""
  488. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  489. self.action = "splitLine"
  490. self.parent.MapWindow.mouse['box'] = 'point'
  491. def OnEditLine(self, event):
  492. """Edit line"""
  493. Debug.msg(2, "Digittoolbar.OnEditLine():")
  494. self.action="editLine"
  495. self.parent.MapWindow.mouse['box'] = 'line'
  496. def OnMoveLine(self, event):
  497. """Move line"""
  498. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  499. self.action = "moveLine"
  500. self.parent.MapWindow.mouse['box'] = 'box'
  501. def OnDeleteLine(self, event):
  502. """Delete line"""
  503. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  504. self.action = "deleteLine"
  505. self.parent.MapWindow.mouse['box'] = 'box'
  506. def OnDisplayCats(self, event):
  507. """Display/update categories"""
  508. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  509. self.action="displayCats"
  510. self.parent.MapWindow.mouse['box'] = 'point'
  511. def OnDisplayAttr(self, event):
  512. """Display/update attributes"""
  513. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  514. self.action="displayAttrs"
  515. self.parent.MapWindow.mouse['box'] = 'point'
  516. def OnCopyCats(self, event):
  517. """Copy categories"""
  518. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  519. self.action="copyCats"
  520. self.parent.MapWindow.mouse['box'] = 'point'
  521. def OnUndo(self, event):
  522. """Undo previous changes"""
  523. self.parent.digit.Undo()
  524. event.Skip()
  525. def EnableUndo(self, enable=True):
  526. """Enable 'Undo' in toolbar
  527. @param enable False for disable
  528. """
  529. ### fix undo first...
  530. # if enable:
  531. # if self.toolbar[0].GetToolEnabled(self.undo) is False:
  532. # self.toolbar[0].EnableTool(self.undo, True)
  533. # else:
  534. # if self.toolbar[0].GetToolEnabled(self.undo) is True:
  535. # self.toolbar[0].EnableTool(self.undo, False)
  536. pass
  537. def OnSettings(self, event):
  538. """Show settings dialog"""
  539. if self.parent.digit is None:
  540. reload(vdigit)
  541. from vdigit import Digit as Digit
  542. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  543. if not self.settingsDialog:
  544. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  545. style=wx.DEFAULT_DIALOG_STYLE)
  546. self.settingsDialog.Show()
  547. def OnAdditionalToolMenu(self, event):
  548. """Menu for additional tools"""
  549. point = wx.GetMousePosition()
  550. toolMenu = wx.Menu()
  551. # Add items to the menu
  552. copy = wx.MenuItem(toolMenu, wx.ID_ANY, _('Copy features from (background) vector map'))
  553. toolMenu.AppendItem(copy)
  554. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  555. flip = wx.MenuItem(toolMenu, wx.ID_ANY, _('Flip selected lines/boundaries'))
  556. toolMenu.AppendItem(flip)
  557. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  558. merge = wx.MenuItem(toolMenu, wx.ID_ANY, _('Merge selected lines/boundaries'))
  559. toolMenu.AppendItem(merge)
  560. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  561. breakL = wx.MenuItem(toolMenu, wx.ID_ANY, _('Break selected lines/boundaries at intersection'))
  562. toolMenu.AppendItem(breakL)
  563. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  564. snap = wx.MenuItem(toolMenu, wx.ID_ANY, _('Snap selected lines/boundaries (only to nodes)'))
  565. toolMenu.AppendItem(snap)
  566. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  567. connect = wx.MenuItem(toolMenu, wx.ID_ANY, _('Connect selected lines/boundaries'))
  568. toolMenu.AppendItem(connect)
  569. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  570. query = wx.MenuItem(toolMenu, wx.ID_ANY, _('Query tool'))
  571. toolMenu.AppendItem(query)
  572. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  573. zbulk = wx.MenuItem(toolMenu, wx.ID_ANY, _('Z bulk-labeling of 3D lines'))
  574. toolMenu.AppendItem(zbulk)
  575. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  576. typeconv = wx.MenuItem(toolMenu, wx.ID_ANY, _('Feature type conversion'))
  577. toolMenu.AppendItem(typeconv)
  578. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  579. # Popup the menu. If an item is selected then its handler
  580. # will be called before PopupMenu returns.
  581. self.parent.MapWindow.PopupMenu(toolMenu)
  582. toolMenu.Destroy()
  583. def OnCopy(self, event):
  584. """Copy selected features from (background) vector map"""
  585. Debug.msg(2, "Digittoolbar.OnCopy():")
  586. self.action="copyLine"
  587. self.parent.MapWindow.mouse['box'] = 'box'
  588. def OnFlip(self, event):
  589. """Flip selected lines/boundaries"""
  590. Debug.msg(2, "Digittoolbar.OnFlip():")
  591. self.action="flipLine"
  592. self.parent.MapWindow.mouse['box'] = 'box'
  593. def OnMerge(self, event):
  594. """Merge selected lines/boundaries"""
  595. Debug.msg(2, "Digittoolbar.OnMerge():")
  596. self.action="mergeLine"
  597. self.parent.MapWindow.mouse['box'] = 'box'
  598. def OnBreak(self, event):
  599. """Break selected lines/boundaries"""
  600. Debug.msg(2, "Digittoolbar.OnBreak():")
  601. self.action="breakLine"
  602. self.parent.MapWindow.mouse['box'] = 'box'
  603. def OnSnap(self, event):
  604. """Snap selected features"""
  605. Debug.msg(2, "Digittoolbar.OnSnap():")
  606. self.action="snapLine"
  607. self.parent.MapWindow.mouse['box'] = 'box'
  608. def OnConnect(self, event):
  609. """Connect selected lines/boundaries"""
  610. Debug.msg(2, "Digittoolbar.OnConnect():")
  611. self.action="connectLine"
  612. self.parent.MapWindow.mouse['box'] = 'box'
  613. def OnQuery(self, event):
  614. """Query selected lines/boundaries"""
  615. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  616. UserSettings.Get(group='vdigit', key='query', subkey='type'))
  617. self.action="queryLine"
  618. self.parent.MapWindow.mouse['box'] = 'box'
  619. def OnZBulk(self, event):
  620. """Z bulk-labeling selected lines/boundaries"""
  621. Debug.msg(2, "Digittoolbar.OnZBulk():")
  622. self.action="zbulkLine"
  623. self.parent.MapWindow.mouse['box'] = 'line'
  624. def OnTypeConversion(self, event):
  625. """Feature type conversion
  626. Supported conversions:
  627. - point <-> centroid
  628. - line <-> boundary
  629. """
  630. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  631. self.action="typeConv"
  632. self.parent.MapWindow.mouse['box'] = 'box'
  633. def OnSelectMap (self, event):
  634. """
  635. Select vector map layer for editing
  636. If there is a vector map layer already edited, this action is
  637. firstly terminated. The map layer is closed. After this the
  638. selected map layer activated for editing.
  639. """
  640. if event.GetSelection() == 0: # create new vector map layer
  641. if self.mapLayer:
  642. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  643. else:
  644. openVectorMap = None
  645. mapName = gdialogs.CreateNewVector(self.parent,
  646. exceptMap=openVectorMap)
  647. if mapName:
  648. # add layer to map layer tree
  649. if self.layerTree:
  650. self.layerTree.AddLayer(ltype='vector',
  651. lname=mapName,
  652. lchecked=True,
  653. lopacity=1.0,
  654. lcmd=['d.vect', 'map=%s' % mapName])
  655. vectLayers = self.UpdateListOfLayers(updateTool=True)
  656. selection = vectLayers.index(mapName)
  657. else:
  658. pass # TODO (no Layer Manager)
  659. else:
  660. self.combo.SetValue(_('Select vector map'))
  661. return
  662. else:
  663. selection = event.GetSelection() - 1 # first option is 'New vector map'
  664. # skip currently selected map
  665. if self.layers[selection] == self.mapLayer:
  666. return False
  667. if self.mapLayer:
  668. # deactive map layer for editing
  669. self.StopEditing()
  670. # select the given map layer for editing
  671. self.StartEditing(self.layers[selection])
  672. event.Skip()
  673. return True
  674. def StartEditing (self, mapLayer):
  675. """
  676. Start editing selected vector map layer.
  677. @param mapLayer reference to MapLayer instance
  678. """
  679. # reload vdigit module
  680. reload(vdigit)
  681. from vdigit import Digit as Digit
  682. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  683. self.mapLayer = mapLayer
  684. # open vector map
  685. try:
  686. self.parent.digit.SetMapName(mapLayer.GetName())
  687. except gcmd.DigitError, e:
  688. self.mapLayer = None
  689. print >> sys.stderr, e # wxMessageBox
  690. return False
  691. # update toolbar
  692. self.combo.SetValue(mapLayer.GetName())
  693. self.parent.toolbars['map'].combo.SetValue ('Digitize')
  694. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  695. # deactive layer
  696. self.mapcontent.ChangeLayerActive(mapLayer, False)
  697. # change cursor
  698. if self.parent.MapWindow.mouse['use'] == 'pointer':
  699. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  700. # create pseudoDC for drawing the map
  701. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  702. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  703. # self.parent.MapWindow.UpdateMap()
  704. if not self.parent.MapWindow.resize:
  705. self.parent.MapWindow.UpdateMap(render=True)
  706. return True
  707. def StopEditing (self):
  708. """Stop editing of selected vector map layer.
  709. @return True on success
  710. @return False on failure
  711. """
  712. if not self.mapLayer:
  713. return False
  714. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  715. self.combo.SetValue (_('Select vector map'))
  716. # save changes (only for vdigit)
  717. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  718. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  719. if self.parent.digit.GetUndoLevel() > 0:
  720. dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
  721. "in vector map <%s>?") % self.mapLayer.GetName(),
  722. caption=_("Save changes?"),
  723. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  724. if dlg.ShowModal() == wx.ID_NO:
  725. # revert changes
  726. self.parent.digit.Undo(0)
  727. dlg.Destroy()
  728. self.parent.digit.SetMapName(None) # -> close map
  729. # re-active layer
  730. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  731. if item and self.parent.tree.IsItemChecked(item):
  732. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  733. # change cursor
  734. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  735. # disable pseudodc for vector map layer
  736. self.parent.MapWindow.pdcVector = None
  737. self.parent.digit.driver.SetDevice(None)
  738. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  739. self.parent.digit = None
  740. self.mapLayer = None
  741. return True
  742. def UpdateListOfLayers (self, updateTool=False):
  743. """
  744. Update list of available vector map layers.
  745. This list consists only editable layers (in the current mapset)
  746. Optionaly also update toolbar
  747. """
  748. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  749. updateTool)
  750. layerNameSelected = None
  751. # name of currently selected layer
  752. if self.mapLayer:
  753. layerNameSelected = self.mapLayer.GetName()
  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.GetName())
  761. if updateTool: # update toolbar
  762. if not self.mapLayer:
  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. self.toolbar[self.numOfRows-1].Realize()
  775. return layerNameList
  776. def GetLayer(self):
  777. """Get selected layer for editing -- MapLayer instance"""
  778. return self.mapLayer
  779. class ProfileToolbar(AbstractToolbar):
  780. """
  781. Toolbar for profiling raster map
  782. """
  783. def __init__(self, parent, mapdisplay, map):
  784. self.parent = parent
  785. self.mapcontent = map
  786. self.mapdisplay = mapdisplay
  787. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  788. # self.SetToolBar(self.toolbar)
  789. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  790. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  791. # realize the toolbar
  792. self.toolbar.Realize()
  793. def ToolbarData(self):
  794. """Toolbar data"""
  795. self.transect = wx.NewId()
  796. self.addraster = wx.NewId()
  797. self.draw = wx.NewId()
  798. self.options = wx.NewId()
  799. self.drag = wx.NewId()
  800. self.zoom = wx.NewId()
  801. self.unzoom = wx.NewId()
  802. self.erase = wx.NewId()
  803. self.save = wx.NewId()
  804. self.printer = wx.NewId()
  805. self.quit = wx.NewId()
  806. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  807. return (
  808. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  809. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  810. self.parent.OnDrawTransect),
  811. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  812. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  813. self.parent.OnSelectRaster),
  814. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  815. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  816. self.parent.OnCreateProfile),
  817. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  818. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  819. self.parent.ProfileOptionsMenu),
  820. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  821. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  822. self.parent.OnDrag),
  823. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  824. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  825. self.parent.OnZoom),
  826. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  827. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  828. self.parent.OnRedraw),
  829. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  830. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  831. self.parent.OnErase),
  832. ("", "", "", "", "", "", ""),
  833. (self.save, 'save', Icons["savefile"].GetBitmap(),
  834. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  835. self.parent.SaveToFile),
  836. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  837. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  838. self.parent.PrintMenu),
  839. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  840. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  841. self.parent.OnQuit),
  842. )
  843. class NvizToolbar(AbstractToolbar):
  844. """
  845. Nviz toolbar
  846. """
  847. def __init__(self, parent, map):
  848. self.parent = parent
  849. self.mapcontent = map
  850. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  851. # self.SetToolBar(self.toolbar)
  852. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  853. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  854. # realize the toolbar
  855. self.toolbar.Realize()
  856. def ToolbarData(self):
  857. """Toolbar data"""
  858. self.settings = wx.NewId()
  859. self.quit = wx.NewId()
  860. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  861. return (
  862. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  863. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  864. self.OnSettings),
  865. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  866. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  867. self.OnExit),
  868. )
  869. def OnSettings(self, event):
  870. win = self.parent.nvizToolWin
  871. if not win.IsShown():
  872. self.parent.nvizToolWin.Show()
  873. else:
  874. self.parent.nvizToolWin.Hide()
  875. def OnExit (self, event=None):
  876. """Quit nviz tool (swith to 2D mode)"""
  877. # disable the toolbar
  878. self.parent.RemoveToolbar ("nviz")