dialogs.py 27 KB

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