dialogs.py 23 KB

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