dbm_dialogs.py 25 KB

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