dialogs.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. """!
  2. @package dbmgr.dialogs
  3. @brief DBM-related dialogs
  4. List of classes:
  5. - dialogs::DisplayAttributesDialog
  6. - dialogs::ModifyTableRecord
  7. (C) 2007-2011 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import os
  13. from core import globalvar
  14. import wx
  15. import wx.lib.scrolledpanel as scrolled
  16. from core.gcmd import RunCommand
  17. from core.debug import Debug
  18. from core.settings import UserSettings
  19. from dbmgr.vinfo import VectorDBInfo
  20. class DisplayAttributesDialog(wx.Dialog):
  21. def __init__(self, parent, map,
  22. query = None, cats = None, line = None,
  23. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  24. pos = wx.DefaultPosition,
  25. action = "add", ignoreError = False):
  26. """!Standard dialog used to add/update/display attributes linked
  27. to the vector map.
  28. Attribute data can be selected based on layer and category number
  29. or coordinates.
  30. @param parent
  31. @param map vector map
  32. @param query query coordinates and distance (used for v.edit)
  33. @param cats {layer: cats}
  34. @param line feature id (requested for cats)
  35. @param style
  36. @param pos
  37. @param action (add, update, display)
  38. @param ignoreError True to ignore errors
  39. """
  40. self.parent = parent # mapdisplay.BufferedWindow
  41. self.map = map
  42. self.action = action
  43. # ids/cats of selected features
  44. # fid : {layer : cats}
  45. self.cats = {}
  46. self.fid = -1 # feature id
  47. # get layer/table/column information
  48. self.mapDBInfo = VectorDBInfo(self.map)
  49. layers = self.mapDBInfo.layers.keys() # get available layers
  50. # check if db connection / layer exists
  51. if len(layers) <= 0:
  52. if not ignoreError:
  53. dlg = wx.MessageDialog(parent = self.parent,
  54. message = _("No attribute table found.\n\n"
  55. "Do you want to create a new attribute table "
  56. "and defined a link to vector map <%s>?") % self.map,
  57. caption = _("Create table?"),
  58. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
  59. if dlg.ShowModal() == wx.ID_YES:
  60. lmgr = self.parent.lmgr
  61. lmgr.OnShowAttributeTable(event = None, selection = 'layers')
  62. dlg.Destroy()
  63. self.mapDBInfo = None
  64. wx.Dialog.__init__(self, parent = self.parent, id = wx.ID_ANY,
  65. title = "", style = style, pos = pos)
  66. # dialog body
  67. mainSizer = wx.BoxSizer(wx.VERTICAL)
  68. # notebook
  69. self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  70. self.closeDialog = wx.CheckBox(parent = self, id = wx.ID_ANY,
  71. label = _("Close dialog on submit"))
  72. self.closeDialog.SetValue(True)
  73. if self.action == 'display':
  74. self.closeDialog.Enable(False)
  75. # feature id (text/choice for duplicates)
  76. self.fidMulti = wx.Choice(parent = self, id = wx.ID_ANY,
  77. size = (150, -1))
  78. self.fidMulti.Bind(wx.EVT_CHOICE, self.OnFeature)
  79. self.fidText = wx.StaticText(parent = self, id = wx.ID_ANY)
  80. self.noFoundMsg = wx.StaticText(parent = self, id = wx.ID_ANY,
  81. label = _("No attributes found"))
  82. self.UpdateDialog(query = query, cats = cats)
  83. # set title
  84. if self.action == "update":
  85. self.SetTitle(_("Update attributes"))
  86. elif self.action == "add":
  87. self.SetTitle(_("Define attributes"))
  88. else:
  89. self.SetTitle(_("Display attributes"))
  90. # buttons
  91. btnCancel = wx.Button(self, wx.ID_CANCEL)
  92. btnReset = wx.Button(self, wx.ID_UNDO, _("&Reload"))
  93. btnSubmit = wx.Button(self, wx.ID_OK, _("&Submit"))
  94. if self.action == 'display':
  95. btnSubmit.Enable(False)
  96. btnSizer = wx.StdDialogButtonSizer()
  97. btnSizer.AddButton(btnCancel)
  98. btnSizer.AddButton(btnReset)
  99. btnSizer.SetNegativeButton(btnReset)
  100. btnSubmit.SetDefault()
  101. btnSizer.AddButton(btnSubmit)
  102. btnSizer.Realize()
  103. mainSizer.Add(item = self.noFoundMsg, proportion = 0,
  104. flag = wx.EXPAND | wx.ALL, border = 5)
  105. mainSizer.Add(item = self.notebook, proportion = 1,
  106. flag = wx.EXPAND | wx.ALL, border = 5)
  107. fidSizer = wx.BoxSizer(wx.HORIZONTAL)
  108. fidSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
  109. label = _("Feature id:")),
  110. proportion = 0, border = 5,
  111. flag = wx.ALIGN_CENTER_VERTICAL)
  112. fidSizer.Add(item = self.fidMulti, proportion = 0,
  113. flag = wx.EXPAND | wx.ALL, border = 5)
  114. fidSizer.Add(item = self.fidText, proportion = 0,
  115. flag = wx.EXPAND | wx.ALL, border = 5)
  116. mainSizer.Add(item = fidSizer, proportion = 0,
  117. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
  118. mainSizer.Add(item = self.closeDialog, proportion = 0, flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  119. border = 5)
  120. mainSizer.Add(item = btnSizer, proportion = 0,
  121. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  122. # bindigs
  123. btnReset.Bind(wx.EVT_BUTTON, self.OnReset)
  124. btnSubmit.Bind(wx.EVT_BUTTON, self.OnSubmit)
  125. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  126. self.SetSizer(mainSizer)
  127. mainSizer.Fit(self)
  128. # set min size for dialog
  129. w, h = self.GetBestSize()
  130. if h < 200:
  131. self.SetMinSize((w, 200))
  132. else:
  133. self.SetMinSize(self.GetBestSize())
  134. if self.notebook.GetPageCount() == 0:
  135. Debug.msg(2, "DisplayAttributesDialog(): Nothing found!")
  136. ### self.mapDBInfo = None
  137. def OnSQLStatement(self, event):
  138. """!Update SQL statement"""
  139. pass
  140. def IsFound(self):
  141. """!Check for status
  142. @return True on attributes found
  143. @return False attributes not found
  144. """
  145. return bool(self.mapDBInfo and self.notebook.GetPageCount() > 0)
  146. def GetSQLString(self, updateValues = False):
  147. """!Create SQL statement string based on self.sqlStatement
  148. If updateValues is True, update dataFrame according to values
  149. in textfields.
  150. """
  151. sqlCommands = []
  152. # find updated values for each layer/category
  153. for layer in self.mapDBInfo.layers.keys(): # for each layer
  154. table = self.mapDBInfo.GetTable(layer)
  155. key = self.mapDBInfo.GetKeyColumn(layer)
  156. columns = self.mapDBInfo.GetTableDesc(table)
  157. for idx in range(len(columns[key]['values'])): # for each category
  158. updatedColumns = []
  159. updatedValues = []
  160. for name in columns.keys():
  161. if name == key:
  162. cat = columns[name]['values'][idx]
  163. continue
  164. type = columns[name]['type']
  165. value = columns[name]['values'][idx]
  166. id = columns[name]['ids'][idx]
  167. try:
  168. newvalue = self.FindWindowById(id).GetValue()
  169. except:
  170. newvalue = self.FindWindowById(id).GetLabel()
  171. if newvalue == '':
  172. newvalue = None
  173. if newvalue != value:
  174. updatedColumns.append(name)
  175. if newvalue is None:
  176. updatedValues.append('NULL')
  177. else:
  178. if type != 'character':
  179. updatedValues.append(newvalue)
  180. else:
  181. updatedValues.append("'" + newvalue + "'")
  182. columns[name]['values'][idx] = newvalue
  183. if self.action != "add" and len(updatedValues) == 0:
  184. continue
  185. if self.action == "add":
  186. sqlString = "INSERT INTO %s (%s," % (table, key)
  187. else:
  188. sqlString = "UPDATE %s SET " % table
  189. for idx in range(len(updatedColumns)):
  190. name = updatedColumns[idx]
  191. if self.action == "add":
  192. sqlString += name + ","
  193. else:
  194. sqlString += name + "=" + updatedValues[idx] + ","
  195. sqlString = sqlString[:-1] # remove last comma
  196. if self.action == "add":
  197. sqlString += ") VALUES (%s," % cat
  198. for value in updatedValues:
  199. sqlString += str(value) + ","
  200. sqlString = sqlString[:-1] # remove last comma
  201. sqlString += ")"
  202. else:
  203. sqlString += " WHERE %s=%s" % (key, cat)
  204. sqlCommands.append(sqlString)
  205. # for each category
  206. # for each layer END
  207. Debug.msg(3, "DisplayAttributesDialog.GetSQLString(): %s" % sqlCommands)
  208. return sqlCommands
  209. def OnReset(self, event = None):
  210. """!Reset form"""
  211. for layer in self.mapDBInfo.layers.keys():
  212. table = self.mapDBInfo.layers[layer]["table"]
  213. key = self.mapDBInfo.layers[layer]["key"]
  214. columns = self.mapDBInfo.tables[table]
  215. for idx in range(len(columns[key]['values'])):
  216. for name in columns.keys():
  217. type = columns[name]['type']
  218. value = columns[name]['values'][idx]
  219. if value is None:
  220. value = ''
  221. try:
  222. id = columns[name]['ids'][idx]
  223. except IndexError:
  224. id = wx.NOT_FOUND
  225. if name != key and id != wx.NOT_FOUND:
  226. self.FindWindowById(id).SetValue(str(value))
  227. def OnCancel(self, event):
  228. """!Cancel button pressed
  229. """
  230. self.parent.parent.dialogs['attributes'] = None
  231. if hasattr(self, "digit"):
  232. self.parent.digit.GetDisplay().SetSelected([])
  233. self.parent.UpdateMap(render = False)
  234. else:
  235. self.parent.parent.OnRender(None)
  236. self.Close()
  237. def OnSubmit(self, event):
  238. """!Submit records"""
  239. layer = 1
  240. for sql in self.GetSQLString(updateValues = True):
  241. enc = UserSettings.Get(group = 'atm', key = 'encoding', subkey = 'value')
  242. if not enc and 'GRASS_DB_ENCODING' in os.environ:
  243. enc = os.environ['GRASS_DB_ENCODING']
  244. if enc:
  245. sql = sql.encode(enc)
  246. driver, database = self.mapDBInfo.GetDbSettings(layer)
  247. Debug.msg(1, "SQL: %s" % sql)
  248. RunCommand('db.execute',
  249. parent = self,
  250. quiet = True,
  251. input = '-',
  252. stdin = sql,
  253. driver = driver,
  254. database = database)
  255. layer += 1
  256. if self.closeDialog.IsChecked():
  257. self.OnCancel(event)
  258. def OnFeature(self, event):
  259. self.fid = int(event.GetString())
  260. self.UpdateDialog(cats = self.cats, fid = self.fid)
  261. def GetCats(self):
  262. """!Get id of selected vector object or 'None' if nothing selected
  263. @param id if true return ids otherwise cats
  264. """
  265. if self.fid < 0:
  266. return None
  267. return self.cats[self.fid]
  268. def GetFid(self):
  269. """!Get selected feature id"""
  270. return self.fid
  271. def UpdateDialog(self, map = None, query = None, cats = None, fid = -1,
  272. action = None):
  273. """!Update dialog
  274. @param map name of vector map
  275. @param query
  276. @param cats
  277. @param fid feature id
  278. @param action add, update, display or None
  279. @return True if updated
  280. @return False
  281. """
  282. if action:
  283. self.action = action
  284. if action == 'display':
  285. enabled = False
  286. else:
  287. enabled = True
  288. self.closeDialog.Enable(enabled)
  289. self.FindWindowById(wx.ID_OK).Enable(enabled)
  290. if map:
  291. self.map = map
  292. # get layer/table/column information
  293. self.mapDBInfo = VectorDBInfo(self.map)
  294. if not self.mapDBInfo:
  295. return False
  296. self.mapDBInfo.Reset()
  297. layers = self.mapDBInfo.layers.keys() # get available layers
  298. # id of selected line
  299. if query: # select by position
  300. data = self.mapDBInfo.SelectByPoint(query[0],
  301. query[1])
  302. self.cats = {}
  303. if data and 'Layer' in data:
  304. idx = 0
  305. for layer in data['Layer']:
  306. layer = int(layer)
  307. if 'Id' in data:
  308. tfid = int(data['Id'][idx])
  309. else:
  310. tfid = 0 # Area / Volume
  311. if not tfid in self.cats:
  312. self.cats[tfid] = {}
  313. if not layer in self.cats[tfid]:
  314. self.cats[tfid][layer] = []
  315. cat = int(data['Category'][idx])
  316. self.cats[tfid][layer].append(cat)
  317. idx += 1
  318. else:
  319. self.cats = cats
  320. if fid > 0:
  321. self.fid = fid
  322. elif len(self.cats.keys()) > 0:
  323. self.fid = self.cats.keys()[0]
  324. else:
  325. self.fid = -1
  326. if len(self.cats.keys()) == 1:
  327. self.fidMulti.Show(False)
  328. self.fidText.Show(True)
  329. if self.fid > 0:
  330. self.fidText.SetLabel("%d" % self.fid)
  331. else:
  332. self.fidText.SetLabel(_("Unknown"))
  333. else:
  334. self.fidMulti.Show(True)
  335. self.fidText.Show(False)
  336. choices = []
  337. for tfid in self.cats.keys():
  338. choices.append(str(tfid))
  339. self.fidMulti.SetItems(choices)
  340. self.fidMulti.SetStringSelection(str(self.fid))
  341. # reset notebook
  342. self.notebook.DeleteAllPages()
  343. for layer in layers: # for each layer
  344. if not query: # select by layer/cat
  345. if self.fid > 0 and layer in self.cats[self.fid]:
  346. for cat in self.cats[self.fid][layer]:
  347. nselected = self.mapDBInfo.SelectFromTable(layer,
  348. where = "%s=%d" % \
  349. (self.mapDBInfo.layers[layer]['key'],
  350. cat))
  351. else:
  352. nselected = 0
  353. # if nselected <= 0 and self.action != "add":
  354. # continue # nothing selected ...
  355. if self.action == "add":
  356. if nselected <= 0:
  357. if layer in self.cats[self.fid]:
  358. table = self.mapDBInfo.layers[layer]["table"]
  359. key = self.mapDBInfo.layers[layer]["key"]
  360. columns = self.mapDBInfo.tables[table]
  361. for name in columns.keys():
  362. if name == key:
  363. for cat in self.cats[self.fid][layer]:
  364. self.mapDBInfo.tables[table][name]['values'].append(cat)
  365. else:
  366. self.mapDBInfo.tables[table][name]['values'].append(None)
  367. else: # change status 'add' -> 'update'
  368. self.action = "update"
  369. table = self.mapDBInfo.layers[layer]["table"]
  370. key = self.mapDBInfo.layers[layer]["key"]
  371. columns = self.mapDBInfo.tables[table]
  372. for idx in range(len(columns[key]['values'])):
  373. for name in columns.keys():
  374. if name == key:
  375. cat = int(columns[name]['values'][idx])
  376. break
  377. # use scrolled panel instead (and fix initial max height of the window to 480px)
  378. panel = scrolled.ScrolledPanel(parent = self.notebook, id = wx.ID_ANY,
  379. size = (-1, 150))
  380. panel.SetupScrolling(scroll_x = False)
  381. self.notebook.AddPage(page = panel, text = " %s %d / %s %d" % (_("Layer"), layer,
  382. _("Category"), cat))
  383. # notebook body
  384. border = wx.BoxSizer(wx.VERTICAL)
  385. flexSizer = wx.FlexGridSizer (cols = 4, hgap = 3, vgap = 3)
  386. flexSizer.AddGrowableCol(3)
  387. # columns (sorted by index)
  388. names = [''] * len(columns.keys())
  389. for name in columns.keys():
  390. names[columns[name]['index']] = name
  391. for name in names:
  392. if name == key: # skip key column (category)
  393. continue
  394. vtype = columns[name]['type']
  395. if columns[name]['values'][idx] is not None:
  396. if columns[name]['ctype'] != type(''):
  397. value = str(columns[name]['values'][idx])
  398. else:
  399. value = columns[name]['values'][idx]
  400. else:
  401. value = ''
  402. colName = wx.StaticText(parent = panel, id = wx.ID_ANY,
  403. label = name)
  404. colType = wx.StaticText(parent = panel, id = wx.ID_ANY,
  405. label = "[" + vtype.lower() + "]")
  406. delimiter = wx.StaticText(parent = panel, id = wx.ID_ANY, label = ":")
  407. colValue = wx.TextCtrl(parent = panel, id = wx.ID_ANY, value = value)
  408. colValue.SetName(name)
  409. self.Bind(wx.EVT_TEXT, self.OnSQLStatement, colValue)
  410. if self.action == 'display':
  411. colValue.SetWindowStyle(wx.TE_READONLY)
  412. flexSizer.Add(colName, proportion = 0,
  413. flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  414. flexSizer.Add(colType, proportion = 0,
  415. flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  416. flexSizer.Add(delimiter, proportion = 0,
  417. flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  418. flexSizer.Add(colValue, proportion = 1,
  419. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
  420. # add widget reference to self.columns
  421. columns[name]['ids'].append(colValue.GetId()) # name, type, values, id
  422. # for each attribute (including category) END
  423. border.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  424. panel.SetSizer(border)
  425. # for each category END
  426. # for each layer END
  427. if self.notebook.GetPageCount() == 0:
  428. self.noFoundMsg.Show(True)
  429. else:
  430. self.noFoundMsg.Show(False)
  431. self.Layout()
  432. return True
  433. def SetColumnValue(self, layer, column, value):
  434. """!Set attrbute value
  435. @param column column name
  436. @param value value
  437. """
  438. table = self.mapDBInfo.GetTable(layer)
  439. columns = self.mapDBInfo.GetTableDesc(table)
  440. for key, col in columns.iteritems():
  441. if key == column:
  442. col['values'] = [col['ctype'](value),]
  443. break
  444. class ModifyTableRecord(wx.Dialog):
  445. def __init__(self, parent, title, data, keyEditable = (-1, True),
  446. id = wx.ID_ANY, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  447. """!Dialog for inserting/updating table record
  448. @param data a list: [(column, value)]
  449. @param KeyEditable (id, editable?) indicates if textarea for key column
  450. is editable(True) or not
  451. """
  452. # parent -> VDigitWindow
  453. wx.Dialog.__init__(self, parent, id, title, style = style)
  454. self.CenterOnParent()
  455. self.keyId = keyEditable[0]
  456. box = wx.StaticBox(parent = self, id = wx.ID_ANY)
  457. box.Hide()
  458. self.dataPanel = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY,
  459. style = wx.TAB_TRAVERSAL)
  460. self.dataPanel.SetupScrolling(scroll_x = False)
  461. # buttons
  462. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  463. self.btnSubmit = wx.Button(self, wx.ID_OK, _("&Submit"))
  464. self.btnSubmit.SetDefault()
  465. # data area
  466. self.widgets = []
  467. cId = 0
  468. self.usebox = False
  469. self.cat = None
  470. winFocus = False
  471. for column, value in data:
  472. if self.keyId == cId:
  473. self.cat = int(value)
  474. if not keyEditable[1]:
  475. self.usebox = True
  476. box.SetLabel(" %s %d " % (_("Category"), self.cat))
  477. box.Show()
  478. self.boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  479. cId += 1
  480. continue
  481. else:
  482. valueWin = wx.SpinCtrl(parent = self.dataPanel, id = wx.ID_ANY,
  483. value = value, min = -1e9, max = 1e9, size = (250, -1))
  484. else:
  485. valueWin = wx.TextCtrl(parent = self.dataPanel, id = wx.ID_ANY,
  486. value = value, size = (250, -1))
  487. if not winFocus:
  488. wx.CallAfter(valueWin.SetFocus)
  489. winFocus = True
  490. label = wx.StaticText(parent = self.dataPanel, id = wx.ID_ANY,
  491. label = column + ":")
  492. self.widgets.append((label.GetId(), valueWin.GetId()))
  493. cId += 1
  494. self._layout()
  495. def _layout(self):
  496. """!Do layout"""
  497. sizer = wx.BoxSizer(wx.VERTICAL)
  498. # data area
  499. dataSizer = wx.FlexGridSizer (cols = 2, hgap = 3, vgap = 3)
  500. dataSizer.AddGrowableCol(1)
  501. for labelId, valueId in self.widgets:
  502. label = self.FindWindowById(labelId)
  503. value = self.FindWindowById(valueId)
  504. dataSizer.Add(label, proportion = 0,
  505. flag = wx.ALIGN_CENTER_VERTICAL)
  506. dataSizer.Add(value, proportion = 0,
  507. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
  508. self.dataPanel.SetAutoLayout(True)
  509. self.dataPanel.SetSizer(dataSizer)
  510. dataSizer.Fit(self.dataPanel)
  511. if self.usebox:
  512. self.boxSizer.Add(item = self.dataPanel, proportion = 1,
  513. flag = wx.EXPAND | wx.ALL, border = 5)
  514. # buttons
  515. btnSizer = wx.StdDialogButtonSizer()
  516. btnSizer.AddButton(self.btnCancel)
  517. btnSizer.AddButton(self.btnSubmit)
  518. btnSizer.Realize()
  519. if not self.usebox:
  520. sizer.Add(item = self.dataPanel, proportion = 1,
  521. flag = wx.EXPAND | wx.ALL, border = 5)
  522. else:
  523. sizer.Add(item = self.boxSizer, proportion = 1,
  524. flag = wx.EXPAND | wx.ALL, border = 5)
  525. sizer.Add(item = btnSizer, proportion = 0,
  526. flag = wx.EXPAND | wx.ALL, border = 5)
  527. framewidth = self.GetSize()[0]
  528. self.SetMinSize((framewidth,250))
  529. self.SetAutoLayout(True)
  530. self.SetSizer(sizer)
  531. sizer.Fit(self)
  532. self.Layout()
  533. def GetValues(self, columns = None):
  534. """!Return list of values (casted to string).
  535. If columns is given (list), return only values of given columns.
  536. """
  537. valueList = []
  538. for labelId, valueId in self.widgets:
  539. column = self.FindWindowById(labelId).GetLabel().replace(':', '')
  540. if columns is None or column in columns:
  541. value = str(self.FindWindowById(valueId).GetValue())
  542. valueList.append(value)
  543. # add key value
  544. if self.usebox:
  545. valueList.insert(self.keyId, str(self.cat))
  546. return valueList