dialogs.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. """!
  2. @package iclass.dialogs
  3. @brief wxIClass dialogs
  4. Classes:
  5. - dialogs::IClassGroupDialog
  6. - dialogs::IClassMapDialog
  7. - dialogs::IClassCategoryManagerDialog
  8. - dialogs::CategoryListCtrl
  9. - dialogs::IClassSignatureFileDialog
  10. (C) 2006-2011 by the GRASS Development Team
  11. This program is free software under the GNU General Public
  12. License (>=v2). Read the file COPYING that comes with GRASS
  13. for details.
  14. @author Vaclav Petras <wenzeslaus gmail.com>
  15. @author Anna Kratochvilova <kratochanna gmail.com>
  16. """
  17. import os
  18. import wx
  19. import wx.lib.mixins.listctrl as listmix
  20. import wx.lib.scrolledpanel as scrolled
  21. from core import globalvar
  22. from core.settings import UserSettings
  23. from gui_core.dialogs import ElementDialog, GroupDialog
  24. from gui_core import gselect
  25. from iclass.statistics import Statistics, BandStatistics
  26. import grass.script as grass
  27. class IClassGroupDialog(ElementDialog):
  28. """!Dialog for imagery group selection"""
  29. def __init__(self, parent, group = None, title = _("Select imagery group"), id = wx.ID_ANY):
  30. """!
  31. Does post init and layout.
  32. @param gui parent
  33. @param title dialog window title
  34. @param id wx id
  35. """
  36. ElementDialog.__init__(self, parent, title, label = _("Name of imagery group:"))
  37. self.element = gselect.Select(parent = self.panel, type = 'group',
  38. mapsets = [grass.gisenv()['MAPSET']],
  39. size = globalvar.DIALOG_GSELECT_SIZE)
  40. if group:
  41. self.element.SetValue(group)
  42. self.editGroup = wx.Button(parent = self.panel, id = wx.ID_ANY,
  43. label = _("Create/edit group..."))
  44. self.editGroup.Bind(wx.EVT_BUTTON, self.OnEditGroup)
  45. self.PostInit()
  46. self.__Layout()
  47. self.SetMinSize(self.GetSize())
  48. def __Layout(self):
  49. """!Do layout"""
  50. self.dataSizer.Add(self.element, proportion = 0,
  51. flag = wx.EXPAND | wx.ALL, border = 5)
  52. self.dataSizer.Add(self.editGroup, proportion = 0,
  53. flag = wx.ALL, border = 5)
  54. self.panel.SetSizer(self.sizer)
  55. self.sizer.Fit(self)
  56. def GetGroup(self):
  57. """!Returns selected group"""
  58. return self.GetElement()
  59. def OnEditGroup(self, event):
  60. """!Launch edit group dialog"""
  61. dlg = GroupDialog(parent = self, defaultGroup = self.element.GetValue())
  62. dlg.ShowModal()
  63. gr = dlg.GetSelectedGroup()
  64. if gr in dlg.GetExistGroups():
  65. self.element.SetValue(gr)
  66. dlg.Destroy()
  67. class IClassMapDialog(ElementDialog):
  68. """!Dialog for adding raster/vector map"""
  69. def __init__(self, parent, title, element):
  70. """!
  71. Does post init and layout.
  72. @param gui parent
  73. @param element element type ('raster', 'vector')
  74. """
  75. if element == 'raster':
  76. label = _("Name of raster map:")
  77. elif element == 'vector':
  78. label = _("Name of vector map:")
  79. ElementDialog.__init__(self, parent, title = title, label = label)
  80. self.element = gselect.Select(parent = self.panel, type = element,
  81. size = globalvar.DIALOG_GSELECT_SIZE)
  82. self.PostInit()
  83. self.__Layout()
  84. self.SetMinSize(self.GetSize())
  85. def __Layout(self):
  86. """!Do layout"""
  87. self.dataSizer.Add(self.element, proportion = 0,
  88. flag = wx.EXPAND | wx.ALL, border = 5)
  89. self.panel.SetSizer(self.sizer)
  90. self.sizer.Fit(self)
  91. def GetMap(self):
  92. """!Returns selected raster/vector map"""
  93. return self.GetElement()
  94. class IClassCategoryManagerDialog(wx.Dialog):
  95. """!Dialog for managing categories (classes).
  96. Alows adding, deleting class and changing its name and color.
  97. """
  98. def __init__(self, parent, title = _("Class manager"), id = wx.ID_ANY):
  99. """!
  100. Does post init and layout.
  101. @param gui parent
  102. @param title dialog window title
  103. @param id wx id
  104. """
  105. wx.Dialog.__init__(self, parent = parent, title = title, id = id)
  106. self.parent = parent
  107. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  108. mainSizer = wx.BoxSizer(wx.VERTICAL)
  109. box = wx.StaticBox(panel, id = wx.ID_ANY,
  110. label = " %s " % _("Classes"))
  111. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  112. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  113. gridSizer.AddGrowableCol(0)
  114. gridSizer.AddGrowableRow(2)
  115. self.catList = CategoryListCtrl(panel, mapwindow = parent, statistics = parent.statisticsDict,
  116. statisticsList = parent.statisticsList)
  117. addButton = wx.Button(panel, id = wx.ID_ADD)
  118. deleteButton = wx.Button(panel, id = wx.ID_DELETE)
  119. gridSizer.Add(item = self.catList, pos = (0, 0), span = (3, 1), flag = wx.EXPAND)
  120. gridSizer.Add(item = addButton, pos = (0, 1), flag = wx.EXPAND)
  121. gridSizer.Add(item = deleteButton, pos = (1, 1), flag = wx.EXPAND)
  122. sizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  123. mainSizer.Add(item = sizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  124. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  125. closeButton = wx.Button(panel, id = wx.ID_CLOSE)
  126. btnSizer.Add(item = wx.Size(-1, -1), proportion = 1, flag = wx.EXPAND)
  127. btnSizer.Add(item = closeButton, proportion = 0, flag = wx.ALIGN_RIGHT)
  128. mainSizer.Add(item = btnSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
  129. addButton.Bind(wx.EVT_BUTTON, self.OnAddCategory)
  130. deleteButton.Bind(wx.EVT_BUTTON, self.OnDeleteCategory)
  131. closeButton.Bind(wx.EVT_BUTTON, self.OnClose)
  132. self.Bind(wx.EVT_CLOSE, self.OnClose)
  133. panel.SetSizer(mainSizer)
  134. mainSizer.Fit(panel)
  135. self.SetSize((-1, 250))
  136. self.Layout()
  137. def OnAddCategory(self, event):
  138. if self.parent.statisticsList:
  139. cat = max(self.parent.statisticsList) + 1
  140. else:
  141. cat = 1
  142. defaultName = 'class' + '_' + str(cat) # intentionally not translatable
  143. defaultColor = '0:0:0'
  144. self.catList.AddCategory(cat = cat, name = defaultName, color = defaultColor)
  145. def OnDeleteCategory(self, event):
  146. self.catList.DeleteCategory()
  147. def OnClose(self, event):
  148. self.catList.DeselectAll()
  149. self.catList.UpdateChoice()
  150. self.Hide()
  151. #if not isinstance(event, wx.CloseEvent):
  152. #self.Destroy()
  153. #event.Skip()
  154. def GetListCtrl(self):
  155. """!Returns list widget"""
  156. return self.catList
  157. class CategoryListCtrl(wx.ListCtrl,
  158. listmix.ListCtrlAutoWidthMixin,
  159. listmix.TextEditMixin):
  160. """! Widget for controling list of classes (categories).
  161. CategoryListCtrl updates choice in mapwindow and removes raster map
  162. when deleting class (category).
  163. It uses virtual data in the terms of @c wx.ListCtrl.
  164. @todo statistics and categories are managed here directly,
  165. it could be better to use some interface
  166. @todo delete vector features after deleting class
  167. """
  168. def __init__(self, parent, mapwindow, statistics, statisticsList, id = wx.ID_ANY):
  169. """!
  170. @param parent gui parent
  171. @param mapwindow mapwindow instance with iclass toolbar and remove raster method
  172. @param statistics dictionary of statistics (defined in statistics.py)
  173. @param statisticsList list of statistics
  174. @param id wx id
  175. """
  176. wx.ListCtrl.__init__(self, parent, id,
  177. style = wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
  178. self.columns = ((_('Class name'), 'name'),
  179. (_('Color'), 'color'))
  180. self.Populate(columns = self.columns)
  181. self.mapWindow = mapwindow
  182. self.statisticsDict = statistics
  183. self.statisticsList = statisticsList
  184. self.SetItemCount(len(statisticsList))
  185. self.rightClickedItemIdx = wx.NOT_FOUND
  186. listmix.ListCtrlAutoWidthMixin.__init__(self)
  187. listmix.TextEditMixin.__init__(self)
  188. self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnEdit)
  189. self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCategorySelected)
  190. self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnClassRightUp) #wxMSW
  191. self.Bind(wx.EVT_RIGHT_UP, self.OnClassRightUp) #wxGTK
  192. def SetVirtualData(self, row, column, text):
  193. attr = self.columns[column][1]
  194. setattr(self.statisticsDict[self.statisticsList[row]], attr, text)
  195. self.UpdateChoice()
  196. toolbar = self.mapWindow.toolbars['iClass']
  197. toolbar.choice.SetSelection(row)
  198. self.Select(row)
  199. if attr == 'name':
  200. self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
  201. self.mapWindow.UpdateChangeState(changes = True)
  202. def Populate(self, columns):
  203. for i, col in enumerate(columns):
  204. self.InsertColumn(i, col[0])#wx.LIST_FORMAT_RIGHT
  205. self.SetColumnWidth(0, 100)
  206. self.SetColumnWidth(1, 100)
  207. def AddCategory(self, cat, name, color):
  208. """!Add category record (used when importing areas)"""
  209. st = Statistics()
  210. st.SetBaseStatistics(cat = cat, name = name, color = color)
  211. self.statisticsDict[cat] = st
  212. self.statisticsList.append(cat)
  213. self.SetItemCount(len(self.statisticsList))
  214. self.UpdateChoice()
  215. self.mapWindow.UpdateChangeState(changes = True)
  216. def DeleteCategory(self):
  217. indexList = sorted(self.GetSelectedIndices(), reverse = True)
  218. cats = []
  219. for i in indexList:
  220. # remove temporary raster
  221. name = self.statisticsDict[self.statisticsList[i]].rasterName
  222. self.mapWindow.RemoveTempRaster(name)
  223. cats.append(self.statisticsList[i])
  224. del self.statisticsDict[self.statisticsList[i]]
  225. del self.statisticsList[i]
  226. self.SetItemCount(len(self.statisticsList))
  227. self.UpdateChoice()
  228. self.mapWindow.UpdateChangeState(changes = True)
  229. self.mapWindow.DeleteAreas(cats = cats)
  230. def UpdateChoice(self):
  231. toolbar = self.mapWindow.toolbars['iClass']
  232. name = toolbar.GetSelectedCategoryName()
  233. catNames = []
  234. for cat in self.statisticsList:
  235. catNames.append(self.statisticsDict[cat].name)
  236. toolbar.SetCategories(catNames = catNames, catIdx = self.statisticsList)
  237. if name in catNames:
  238. toolbar.choice.SetStringSelection(name)
  239. elif catNames:
  240. toolbar.choice.SetSelection(0)
  241. if toolbar.choice.IsEmpty():
  242. toolbar.EnableControls(False)
  243. else:
  244. toolbar.EnableControls(True)
  245. # don't forget to update maps, histo, ...
  246. def GetSelectedIndices(self, state = wx.LIST_STATE_SELECTED):
  247. indices = []
  248. lastFound = -1
  249. while True:
  250. index = self.GetNextItem(lastFound, wx.LIST_NEXT_ALL, state)
  251. if index == -1:
  252. break
  253. else:
  254. lastFound = index
  255. indices.append(index)
  256. return indices
  257. def OnEdit(self, event):
  258. currentItem = event.m_itemIndex
  259. currentCol = event.m_col
  260. if currentCol == 1:
  261. dlg = wx.ColourDialog(self)
  262. dlg.GetColourData().SetChooseFull(True)
  263. if dlg.ShowModal() == wx.ID_OK:
  264. color = dlg.GetColourData().GetColour().Get()
  265. color = ':'.join(map(str, color))
  266. self.SetVirtualData(currentItem, currentCol, color)
  267. dlg.Destroy()
  268. event.Skip()
  269. def OnCategorySelected(self, event):
  270. """!Highlight selected areas"""
  271. indexList = self.GetSelectedIndices()
  272. cats = []
  273. for i in indexList:
  274. cats.append(self.statisticsList[i])
  275. self.mapWindow.HighlightCategory(cats)
  276. if event:
  277. event.Skip()
  278. def OnClassRightUp(self, event):
  279. """!Show context menu on right click"""
  280. item, flags = self.HitTest((event.GetX(), event.GetY()))
  281. if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM:
  282. self.rightClickedItemIdx = item
  283. if not hasattr(self, "popupZoomtoAreas"):
  284. self.popupZoomtoAreas = wx.NewId()
  285. self.Bind(wx.EVT_MENU, self.OnZoomToAreasByCat, id = self.popupZoomtoAreas)
  286. # generate popup-menu
  287. menu = wx.Menu()
  288. menu.Append(self.popupZoomtoAreas, _("Zoom to training areas of selected class"))
  289. self.PopupMenu(menu)
  290. menu.Destroy()
  291. def OnZoomToAreasByCat(self, event):
  292. """!Zoom to areas of given category"""
  293. cat = self.statisticsList[self.rightClickedItemIdx]
  294. self.mapWindow.ZoomToAreasByCat(cat)
  295. def DeselectAll(self):
  296. """!Deselect all items"""
  297. indexList = self.GetSelectedIndices()
  298. for i in indexList:
  299. self.Select(i, on = 0)
  300. # no highlight
  301. self.OnCategorySelected(None)
  302. def OnGetItemText(self, item, col):
  303. cat = self.statisticsList[item]
  304. return getattr(self.statisticsDict[cat], self.columns[col][1])
  305. def OnGetItemImage(self, item):
  306. return -1
  307. def OnGetItemAttr(self, item):
  308. return None
  309. class IClassSignatureFileDialog(wx.Dialog):
  310. def __init__(self, parent, group, file = None, title = _("Save signature file"), id = wx.ID_ANY,
  311. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  312. **kwargs):
  313. """!Dialog for saving signature file
  314. @param parent window
  315. @param group group name
  316. @param file signature file name
  317. @param title window title
  318. """
  319. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  320. self.fileName = file
  321. env = grass.gisenv()
  322. # inconsistent group and subgroup name
  323. # path: grassdata/nc_spm_08/landsat/group/test_group/subgroup/test_group@landsat/sig/sigFile
  324. self.baseFilePath = os.path.join(env['GISDBASE'],
  325. env['LOCATION_NAME'],
  326. env['MAPSET'],
  327. 'group', group.split('@')[0], # !
  328. 'subgroup', group,
  329. 'sig')
  330. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  331. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  332. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  333. self.btnOK.SetDefault()
  334. self.btnOK.Enable(False)
  335. self.__layout()
  336. self.fileNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
  337. self.OnTextChanged(None)
  338. def OnTextChanged(self, event):
  339. """!Name for signature file given"""
  340. file = self.fileNameCtrl.GetValue()
  341. if len(file) > 0:
  342. self.btnOK.Enable(True)
  343. else:
  344. self.btnOK.Enable(False)
  345. path = os.path.join(self.baseFilePath, file)
  346. self.filePathText.SetLabel(path)
  347. bestSize = self.pathPanel.GetBestVirtualSize()
  348. self.pathPanel.SetVirtualSize(bestSize)
  349. self.pathPanel.Scroll(*bestSize)
  350. def __layout(self):
  351. """!Do layout"""
  352. sizer = wx.BoxSizer(wx.VERTICAL)
  353. dataSizer = wx.BoxSizer(wx.VERTICAL)
  354. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  355. label = _("Enter name of signature file:")),
  356. proportion = 0, flag = wx.ALL, border = 3)
  357. self.fileNameCtrl = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size = (400, -1))
  358. if self.fileName:
  359. self.fileNameCtrl.SetValue(self.fileName)
  360. dataSizer.Add(item = self.fileNameCtrl,
  361. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  362. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  363. label = _("Signature file path:")),
  364. proportion = 0, flag = wx.ALL, border = 3)
  365. self.pathPanel = scrolled.ScrolledPanel(self.panel, size = (-1, 40))
  366. pathSizer = wx.BoxSizer()
  367. self.filePathText = wx.StaticText(parent = self.pathPanel, id = wx.ID_ANY,
  368. label = self.baseFilePath)
  369. pathSizer.Add(self.filePathText, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  370. self.pathPanel.SetupScrolling(scroll_x = True, scroll_y = False)
  371. self.pathPanel.SetSizer(pathSizer)
  372. dataSizer.Add(item = self.pathPanel,
  373. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  374. # buttons
  375. btnSizer = wx.StdDialogButtonSizer()
  376. btnSizer.AddButton(self.btnCancel)
  377. btnSizer.AddButton(self.btnOK)
  378. btnSizer.Realize()
  379. sizer.Add(item = dataSizer, proportion = 1,
  380. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  381. sizer.Add(item = btnSizer, proportion = 0,
  382. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  383. self.panel.SetSizer(sizer)
  384. sizer.Fit(self)
  385. self.SetMinSize(self.GetSize())
  386. def GetFileName(self, fullPath = False):
  387. """!Returns signature file name
  388. @param fullPath return full path of sig. file
  389. """
  390. if fullPath:
  391. return os.path.join(self.baseFilePath, self.fileNameCtrl.GetValue())
  392. return self.fileNameCtrl.GetValue()
  393. class IClassExportAreasDialog(wx.Dialog):
  394. def __init__(self, parent, vectorName = None, title = _("Export training areas"), id = wx.ID_ANY,
  395. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  396. **kwargs):
  397. """!Dialog for export of training areas to vector layer
  398. @param parent window
  399. @param vectorName name of vector layer for export
  400. @param title window title
  401. """
  402. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  403. self.vectorName = vectorName
  404. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  405. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  406. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  407. self.btnOK.SetDefault()
  408. self.btnOK.Enable(False)
  409. self.btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
  410. self.__layout()
  411. self.vectorNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
  412. self.OnTextChanged(None)
  413. def OnTextChanged(self, event):
  414. """!Name of new vector map given.
  415. Enable/diable OK button.
  416. """
  417. file = self.vectorNameCtrl.GetValue()
  418. if len(file) > 0:
  419. self.btnOK.Enable(True)
  420. else:
  421. self.btnOK.Enable(False)
  422. def __layout(self):
  423. """!Do layout"""
  424. sizer = wx.BoxSizer(wx.VERTICAL)
  425. dataSizer = wx.BoxSizer(wx.VERTICAL)
  426. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  427. label = _("Enter name of new vector map:")),
  428. proportion = 0, flag = wx.ALL, border = 3)
  429. self.vectorNameCtrl = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size = (400, -1))
  430. if self.vectorName:
  431. self.vectorNameCtrl.SetValue(self.vectorName)
  432. dataSizer.Add(item = self.vectorNameCtrl,
  433. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  434. self.withTableCtrl = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  435. label = _("Export attribute table"))
  436. self.withTableCtrl.SetValue(True)
  437. self.withTableCtrl.SetToolTipString(_("Export attribute table containing"
  438. " computed statistical data"))
  439. dataSizer.Add(item = self.withTableCtrl,
  440. proportion = 0, flag = wx.ALL, border = 3)
  441. # buttons
  442. btnSizer = wx.StdDialogButtonSizer()
  443. btnSizer.AddButton(self.btnCancel)
  444. btnSizer.AddButton(self.btnOK)
  445. btnSizer.Realize()
  446. sizer.Add(item = dataSizer, proportion = 1,
  447. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  448. sizer.Add(item = btnSizer, proportion = 0,
  449. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  450. self.panel.SetSizer(sizer)
  451. sizer.Fit(self)
  452. self.SetMinSize(self.GetSize())
  453. def GetVectorName(self):
  454. """!Returns vector name"""
  455. return self.vectorNameCtrl.GetValue()
  456. def WithTable(self):
  457. """!Returns true if attribute table should be exported too"""
  458. return self.withTableCtrl.IsChecked()
  459. def OnOK(self, event):
  460. """!Checks if map exists and can be overwritten."""
  461. overwrite = UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')
  462. vName = self.GetVectorName()
  463. res = grass.find_file(vName, element = 'vector')
  464. if res['fullname'] and overwrite is False:
  465. qdlg = wx.MessageDialog(parent = self,
  466. message = _("Vector map <%s> already exists."
  467. " Do you want to overwrite it?" % vName) ,
  468. caption = _("Vector <%s> exists" % vName),
  469. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
  470. if qdlg.ShowModal() == wx.ID_YES:
  471. event.Skip()
  472. qdlg.Destroy()
  473. else:
  474. event.Skip()