dialogs.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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,
  129. stats_data = parent.stats_data)
  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.stats_data.GetCategories():
  154. cat = max(self.parent.stats_data.GetCategories()) + 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 delete vector features after deleting class
  180. """
  181. def __init__(self, parent, mapwindow, stats_data, id = wx.ID_ANY):
  182. """!
  183. @param parent gui parent
  184. @param mapwindow mapwindow instance with iclass toolbar and remove raster method
  185. @param stats_data StatisticsData instance (defined in statistics.py)
  186. @param id wx id
  187. """
  188. wx.ListCtrl.__init__(self, parent, id,
  189. style = wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
  190. self.columns = ((_('Class name'), 'name'),
  191. (_('Color'), 'color'))
  192. self.Populate(columns = self.columns)
  193. self.mapWindow = mapwindow
  194. self.stats_data = stats_data
  195. self.SetItemCount(len(self.stats_data.GetCategories()))
  196. self.rightClickedItemIdx = wx.NOT_FOUND
  197. listmix.ListCtrlAutoWidthMixin.__init__(self)
  198. listmix.TextEditMixin.__init__(self)
  199. self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnEdit)
  200. self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCategorySelected)
  201. self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnClassRightUp) #wxMSW
  202. self.Bind(wx.EVT_RIGHT_UP, self.OnClassRightUp) #wxGTK
  203. self.stats_data.statisticsAdded.connect(self.Update)
  204. self.stats_data.statisticsDeleted.connect(self.Update)
  205. self.stats_data.allStatisticsDeleted.connect(self.Update)
  206. self.stats_data.statisticsSet.connect(self.Update)
  207. def Update(self):
  208. self.SetItemCount(len(self.stats_data.GetCategories()))
  209. def SetVirtualData(self, row, column, text):
  210. attr = self.columns[column][1]
  211. if attr == 'name':
  212. try:
  213. text.encode('ascii')
  214. except UnicodeEncodeError:
  215. GMessage(parent = self, message = _("Please use only ASCII characters."))
  216. return
  217. cat = self.stats_data.GetCategories()[row]
  218. self.stats_data.GetStatistics(cat).SetStatistics(stats = {attr : text})
  219. self.UpdateChoice()
  220. toolbar = self.mapWindow.toolbars['iClass']
  221. toolbar.choice.SetSelection(row)
  222. self.Select(row)
  223. if attr == 'name':
  224. self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
  225. self.mapWindow.UpdateChangeState(changes = True)
  226. def Populate(self, columns):
  227. for i, col in enumerate(columns):
  228. self.InsertColumn(i, col[0])#wx.LIST_FORMAT_RIGHT
  229. self.SetColumnWidth(0, 100)
  230. self.SetColumnWidth(1, 100)
  231. def AddCategory(self, cat, name, color):
  232. """!Add category record (used when importing areas)"""
  233. self.stats_data.AddStatistics(cat, name, color)
  234. self.SetItemCount(len(self.stats_data.GetCategories()))
  235. self.UpdateChoice()
  236. self.mapWindow.UpdateChangeState(changes = True)
  237. def DeleteCategory(self):
  238. indexList = sorted(self.GetSelectedIndices(), reverse = True)
  239. del_cats = []
  240. cats = self.stats_data.GetCategories()
  241. for i in indexList:
  242. # remove temporary raster
  243. cat = cats[i]
  244. stat = self.stats_data.GetStatistics(cat)
  245. name = stat.rasterName
  246. self.mapWindow.RemoveTempRaster(name)
  247. del_cats.append(cat)
  248. self.stats_data.DeleteStatistics(cat)
  249. self.SetItemCount(len(self.stats_data.GetCategories()))
  250. self.UpdateChoice()
  251. self.mapWindow.UpdateChangeState(changes = True)
  252. self.mapWindow.DeleteAreas(cats = del_cats)
  253. def UpdateChoice(self):
  254. toolbar = self.mapWindow.toolbars['iClass']
  255. name = toolbar.GetSelectedCategoryName()
  256. catNames = []
  257. cats = self.stats_data.GetCategories()
  258. for cat in cats:
  259. stat = self.stats_data.GetStatistics(cat)
  260. catNames.append(stat.name)
  261. toolbar.SetCategories(catNames = catNames, catIdx = cats)
  262. if name in catNames:
  263. toolbar.choice.SetStringSelection(name)
  264. elif catNames:
  265. toolbar.choice.SetSelection(0)
  266. if toolbar.choice.IsEmpty():
  267. toolbar.EnableControls(False)
  268. else:
  269. toolbar.EnableControls(True)
  270. # don't forget to update maps, histo, ...
  271. def GetSelectedIndices(self, state = wx.LIST_STATE_SELECTED):
  272. indices = []
  273. lastFound = -1
  274. while True:
  275. index = self.GetNextItem(lastFound, wx.LIST_NEXT_ALL, state)
  276. if index == -1:
  277. break
  278. else:
  279. lastFound = index
  280. indices.append(index)
  281. return indices
  282. def OnEdit(self, event):
  283. currentItem = event.m_itemIndex
  284. currentCol = event.m_col
  285. if currentCol == 1:
  286. dlg = wx.ColourDialog(self)
  287. dlg.GetColourData().SetChooseFull(True)
  288. if dlg.ShowModal() == wx.ID_OK:
  289. color = dlg.GetColourData().GetColour().Get()
  290. color = ':'.join(map(str, color))
  291. self.SetVirtualData(currentItem, currentCol, color)
  292. dlg.Destroy()
  293. wx.CallAfter(self.SetFocus)
  294. event.Skip()
  295. def OnCategorySelected(self, event):
  296. """!Highlight selected areas"""
  297. indexList = self.GetSelectedIndices()
  298. sel_cats = []
  299. cats = self.stats_data.GetCategories()
  300. for i in indexList:
  301. sel_cats.append(cats[i])
  302. self.mapWindow.HighlightCategory(sel_cats)
  303. if event:
  304. event.Skip()
  305. def OnClassRightUp(self, event):
  306. """!Show context menu on right click"""
  307. item, flags = self.HitTest((event.GetX(), event.GetY()))
  308. if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM:
  309. self.rightClickedItemIdx = item
  310. if not hasattr(self, "popupZoomtoAreas"):
  311. self.popupZoomtoAreas = wx.NewId()
  312. self.Bind(wx.EVT_MENU, self.OnZoomToAreasByCat, id = self.popupZoomtoAreas)
  313. # generate popup-menu
  314. menu = wx.Menu()
  315. menu.Append(self.popupZoomtoAreas, _("Zoom to training areas of selected class"))
  316. self.PopupMenu(menu)
  317. menu.Destroy()
  318. def OnZoomToAreasByCat(self, event):
  319. """!Zoom to areas of given category"""
  320. cat = self.stats_data.GetCategories()[self.rightClickedItemIdx]
  321. self.mapWindow.ZoomToAreasByCat(cat)
  322. def DeselectAll(self):
  323. """!Deselect all items"""
  324. indexList = self.GetSelectedIndices()
  325. for i in indexList:
  326. self.Select(i, on = 0)
  327. # no highlight
  328. self.OnCategorySelected(None)
  329. def OnGetItemText(self, item, col):
  330. cat = self.stats_data.GetCategories()[item]
  331. stat = self.stats_data.GetStatistics(cat)
  332. return getattr(stat, self.columns[col][1])
  333. def OnGetItemImage(self, item):
  334. return -1
  335. def OnGetItemAttr(self, item):
  336. return None
  337. class IClassSignatureFileDialog(wx.Dialog):
  338. def __init__(self, parent, group, file = None, title = _("Save signature file"), id = wx.ID_ANY,
  339. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  340. **kwargs):
  341. """!Dialog for saving signature file
  342. @param parent window
  343. @param group group name
  344. @param file signature file name
  345. @param title window title
  346. """
  347. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  348. self.fileName = file
  349. env = grass.gisenv()
  350. # inconsistent group and subgroup name
  351. # path: grassdata/nc_spm_08/landsat/group/test_group/subgroup/test_group/sig/sigFile
  352. self.baseFilePath = os.path.join(env['GISDBASE'],
  353. env['LOCATION_NAME'],
  354. env['MAPSET'],
  355. 'group', group,
  356. 'subgroup', group,
  357. 'sig')
  358. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  359. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  360. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  361. self.btnOK.SetDefault()
  362. self.btnOK.Enable(False)
  363. self.__layout()
  364. self.fileNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
  365. self.OnTextChanged(None)
  366. def OnTextChanged(self, event):
  367. """!Name for signature file given"""
  368. file = self.fileNameCtrl.GetValue()
  369. if len(file) > 0:
  370. self.btnOK.Enable(True)
  371. else:
  372. self.btnOK.Enable(False)
  373. path = os.path.join(self.baseFilePath, file)
  374. self.filePathText.SetLabel(path)
  375. bestSize = self.pathPanel.GetBestVirtualSize()
  376. self.pathPanel.SetVirtualSize(bestSize)
  377. self.pathPanel.Scroll(*bestSize)
  378. def __layout(self):
  379. """!Do layout"""
  380. sizer = wx.BoxSizer(wx.VERTICAL)
  381. dataSizer = wx.BoxSizer(wx.VERTICAL)
  382. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  383. label = _("Enter name of signature file:")),
  384. proportion = 0, flag = wx.ALL, border = 3)
  385. self.fileNameCtrl = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size = (400, -1))
  386. if self.fileName:
  387. self.fileNameCtrl.SetValue(self.fileName)
  388. dataSizer.Add(item = self.fileNameCtrl,
  389. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  390. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  391. label = _("Signature file path:")),
  392. proportion = 0, flag = wx.ALL, border = 3)
  393. self.pathPanel = scrolled.ScrolledPanel(self.panel, size = (-1, 40))
  394. pathSizer = wx.BoxSizer()
  395. self.filePathText = wx.StaticText(parent = self.pathPanel, id = wx.ID_ANY,
  396. label = self.baseFilePath)
  397. pathSizer.Add(self.filePathText, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  398. self.pathPanel.SetupScrolling(scroll_x = True, scroll_y = False)
  399. self.pathPanel.SetSizer(pathSizer)
  400. dataSizer.Add(item = self.pathPanel,
  401. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  402. # buttons
  403. btnSizer = wx.StdDialogButtonSizer()
  404. btnSizer.AddButton(self.btnCancel)
  405. btnSizer.AddButton(self.btnOK)
  406. btnSizer.Realize()
  407. sizer.Add(item = dataSizer, proportion = 1,
  408. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  409. sizer.Add(item = btnSizer, proportion = 0,
  410. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  411. self.panel.SetSizer(sizer)
  412. sizer.Fit(self)
  413. self.SetMinSize(self.GetSize())
  414. def GetFileName(self, fullPath = False):
  415. """!Returns signature file name
  416. @param fullPath return full path of sig. file
  417. """
  418. if fullPath:
  419. return os.path.join(self.baseFilePath, self.fileNameCtrl.GetValue())
  420. return self.fileNameCtrl.GetValue()
  421. class IClassExportAreasDialog(wx.Dialog):
  422. def __init__(self, parent, vectorName = None, title = _("Export training areas"), id = wx.ID_ANY,
  423. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  424. **kwargs):
  425. """!Dialog for export of training areas to vector layer
  426. @param parent window
  427. @param vectorName name of vector layer for export
  428. @param title window title
  429. """
  430. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  431. self.vectorName = vectorName
  432. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  433. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  434. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  435. self.btnOK.SetDefault()
  436. self.btnOK.Enable(False)
  437. self.btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
  438. self.__layout()
  439. self.vectorNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
  440. self.OnTextChanged(None)
  441. wx.CallAfter(self.vectorNameCtrl.SetFocus)
  442. def OnTextChanged(self, event):
  443. """!Name of new vector map given.
  444. Enable/diable OK button.
  445. """
  446. file = self.vectorNameCtrl.GetValue()
  447. if len(file) > 0:
  448. self.btnOK.Enable(True)
  449. else:
  450. self.btnOK.Enable(False)
  451. def __layout(self):
  452. """!Do layout"""
  453. sizer = wx.BoxSizer(wx.VERTICAL)
  454. dataSizer = wx.BoxSizer(wx.VERTICAL)
  455. dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  456. label = _("Enter name of new vector map:")),
  457. proportion = 0, flag = wx.ALL, border = 3)
  458. self.vectorNameCtrl = gselect.Select(parent = self.panel, type = 'vector',
  459. mapsets = [grass.gisenv()['MAPSET']],
  460. size = globalvar.DIALOG_GSELECT_SIZE)
  461. if self.vectorName:
  462. self.vectorNameCtrl.SetValue(self.vectorName)
  463. dataSizer.Add(item = self.vectorNameCtrl,
  464. proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  465. self.withTableCtrl = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  466. label = _("Export attribute table"))
  467. self.withTableCtrl.SetValue(True)
  468. self.withTableCtrl.SetToolTipString(_("Export attribute table containing"
  469. " computed statistical data"))
  470. dataSizer.Add(item = self.withTableCtrl,
  471. proportion = 0, flag = wx.ALL, border = 3)
  472. # buttons
  473. btnSizer = wx.StdDialogButtonSizer()
  474. btnSizer.AddButton(self.btnCancel)
  475. btnSizer.AddButton(self.btnOK)
  476. btnSizer.Realize()
  477. sizer.Add(item = dataSizer, proportion = 1,
  478. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  479. sizer.Add(item = btnSizer, proportion = 0,
  480. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  481. self.panel.SetSizer(sizer)
  482. sizer.Fit(self)
  483. self.SetMinSize(self.GetSize())
  484. def GetVectorName(self):
  485. """!Returns vector name"""
  486. return self.vectorNameCtrl.GetValue()
  487. def WithTable(self):
  488. """!Returns true if attribute table should be exported too"""
  489. return self.withTableCtrl.IsChecked()
  490. def OnOK(self, event):
  491. """!Checks if map exists and can be overwritten."""
  492. overwrite = UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')
  493. vName = self.GetVectorName()
  494. res = grass.find_file(vName, element = 'vector')
  495. if res['fullname'] and overwrite is False:
  496. qdlg = wx.MessageDialog(parent = self,
  497. message = _("Vector map <%s> already exists."
  498. " Do you want to overwrite it?" % vName) ,
  499. caption = _("Vector <%s> exists" % vName),
  500. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
  501. if qdlg.ShowModal() == wx.ID_YES:
  502. event.Skip()
  503. qdlg.Destroy()
  504. else:
  505. event.Skip()