dialogs.py 24 KB

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