dialogs.py 24 KB

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