dialogs.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. if newvalue:
  176. try:
  177. if ctype == int:
  178. newvalue = int(newvalue)
  179. elif ctype == float:
  180. newvalue = float(newvalue)
  181. except ValueError:
  182. GError(parent = self,
  183. message = _("Column <%(col)s>: Value '%(value)s' needs to be entered as %(type)s.") % \
  184. {'col' : name,
  185. 'value' : str(newvalue),
  186. 'type' : columns[name]['type'].lower()},
  187. showTraceback = False)
  188. sqlCommands.append(None)
  189. continue
  190. else:
  191. if self.action == 'add':
  192. continue
  193. if newvalue != value:
  194. updatedColumns.append(name)
  195. if not newvalue:
  196. updatedValues.append('NULL')
  197. else:
  198. if ctype != str:
  199. updatedValues.append(str(newvalue))
  200. else:
  201. updatedValues.append("'" + str(newvalue) + "'")
  202. columns[name]['values'][idx] = newvalue
  203. if self.action != "add" and len(updatedValues) == 0:
  204. continue
  205. if self.action == "add":
  206. sqlString = "INSERT INTO %s (%s," % (table, key)
  207. else:
  208. sqlString = "UPDATE %s SET " % table
  209. for idx in range(len(updatedColumns)):
  210. name = updatedColumns[idx]
  211. if self.action == "add":
  212. sqlString += name + ","
  213. else:
  214. sqlString += name + "=" + updatedValues[idx] + ","
  215. sqlString = sqlString[:-1] # remove last comma
  216. if self.action == "add":
  217. sqlString += ") VALUES (%s," % cat
  218. for value in updatedValues:
  219. sqlString += str(value) + ","
  220. sqlString = sqlString[:-1] # remove last comma
  221. sqlString += ")"
  222. else:
  223. sqlString += " WHERE %s=%s" % (key, cat)
  224. sqlCommands.append(sqlString)
  225. # for each category
  226. # for each layer END
  227. Debug.msg(3, "DisplayAttributesDialog.GetSQLString(): %s" % sqlCommands)
  228. return sqlCommands
  229. def OnReset(self, event = None):
  230. """!Reset form"""
  231. for layer in self.mapDBInfo.layers.keys():
  232. table = self.mapDBInfo.layers[layer]["table"]
  233. key = self.mapDBInfo.layers[layer]["key"]
  234. columns = self.mapDBInfo.tables[table]
  235. for idx in range(len(columns[key]['values'])):
  236. for name in columns.keys():
  237. type = columns[name]['type']
  238. value = columns[name]['values'][idx]
  239. if value is None:
  240. value = ''
  241. try:
  242. id = columns[name]['ids'][idx]
  243. except IndexError:
  244. id = wx.NOT_FOUND
  245. if name != key and id != wx.NOT_FOUND:
  246. self.FindWindowById(id).SetValue(str(value))
  247. def OnCancel(self, event):
  248. """!Cancel button pressed
  249. """
  250. self.parent.parent.dialogs['attributes'] = None
  251. if hasattr(self, "digit"):
  252. self.parent.digit.GetDisplay().SetSelected([])
  253. self.parent.UpdateMap(render = False)
  254. else:
  255. self.parent.parent.OnRender(None)
  256. self.Close()
  257. def OnSubmit(self, event):
  258. """!Submit records"""
  259. layer = 1
  260. close = True
  261. enc = UserSettings.Get(group = 'atm', key = 'encoding', subkey = 'value')
  262. if not enc and 'GRASS_DB_ENCODING' in os.environ:
  263. enc = os.environ['GRASS_DB_ENCODING']
  264. for sql in self.GetSQLString(updateValues = True):
  265. if not sql:
  266. close = False
  267. continue
  268. if enc:
  269. sql = sql.encode(enc)
  270. driver, database = self.mapDBInfo.GetDbSettings(layer)
  271. Debug.msg(1, "SQL: %s" % sql)
  272. RunCommand('db.execute',
  273. parent = self,
  274. quiet = True,
  275. input = '-',
  276. stdin = sql,
  277. driver = driver,
  278. database = database)
  279. layer += 1
  280. if close and self.closeDialog.IsChecked():
  281. self.OnCancel(event)
  282. def OnFeature(self, event):
  283. self.fid = int(event.GetString())
  284. self.UpdateDialog(cats = self.cats, fid = self.fid)
  285. def GetCats(self):
  286. """!Get id of selected vector object or 'None' if nothing selected
  287. @param id if true return ids otherwise cats
  288. """
  289. if self.fid < 0:
  290. return None
  291. return self.cats[self.fid]
  292. def GetFid(self):
  293. """!Get selected feature id"""
  294. return self.fid
  295. def UpdateDialog(self, map = None, query = None, cats = None, fid = -1,
  296. action = None):
  297. """!Update dialog
  298. @param map name of vector map
  299. @param query
  300. @param cats
  301. @param fid feature id
  302. @param action add, update, display or None
  303. @return True if updated
  304. @return False
  305. """
  306. if action:
  307. self.action = action
  308. if action == 'display':
  309. enabled = False
  310. else:
  311. enabled = True
  312. self.closeDialog.Enable(enabled)
  313. self.FindWindowById(wx.ID_OK).Enable(enabled)
  314. if map:
  315. self.map = map
  316. # get layer/table/column information
  317. self.mapDBInfo = VectorDBInfo(self.map)
  318. if not self.mapDBInfo:
  319. return False
  320. self.mapDBInfo.Reset()
  321. layers = self.mapDBInfo.layers.keys() # get available layers
  322. # id of selected line
  323. if query: # select by position
  324. data = self.mapDBInfo.SelectByPoint(query[0],
  325. query[1])
  326. self.cats = {}
  327. if data and 'Layer' in data:
  328. idx = 0
  329. for layer in data['Layer']:
  330. layer = int(layer)
  331. if 'Id' in data:
  332. tfid = int(data['Id'][idx])
  333. else:
  334. tfid = 0 # Area / Volume
  335. if not tfid in self.cats:
  336. self.cats[tfid] = {}
  337. if not layer in self.cats[tfid]:
  338. self.cats[tfid][layer] = []
  339. cat = int(data['Category'][idx])
  340. self.cats[tfid][layer].append(cat)
  341. idx += 1
  342. else:
  343. self.cats = cats
  344. if fid > 0:
  345. self.fid = fid
  346. elif len(self.cats.keys()) > 0:
  347. self.fid = self.cats.keys()[0]
  348. else:
  349. self.fid = -1
  350. if len(self.cats.keys()) == 1:
  351. self.fidMulti.Show(False)
  352. self.fidText.Show(True)
  353. if self.fid > 0:
  354. self.fidText.SetLabel("%d" % self.fid)
  355. else:
  356. self.fidText.SetLabel(_("Unknown"))
  357. else:
  358. self.fidMulti.Show(True)
  359. self.fidText.Show(False)
  360. choices = []
  361. for tfid in self.cats.keys():
  362. choices.append(str(tfid))
  363. self.fidMulti.SetItems(choices)
  364. self.fidMulti.SetStringSelection(str(self.fid))
  365. # reset notebook
  366. self.notebook.DeleteAllPages()
  367. for layer in layers: # for each layer
  368. if not query: # select by layer/cat
  369. if self.fid > 0 and layer in self.cats[self.fid]:
  370. for cat in self.cats[self.fid][layer]:
  371. nselected = self.mapDBInfo.SelectFromTable(layer,
  372. where = "%s=%d" % \
  373. (self.mapDBInfo.layers[layer]['key'],
  374. cat))
  375. else:
  376. nselected = 0
  377. # if nselected <= 0 and self.action != "add":
  378. # continue # nothing selected ...
  379. if self.action == "add":
  380. if nselected <= 0:
  381. if layer in self.cats[self.fid]:
  382. table = self.mapDBInfo.layers[layer]["table"]
  383. key = self.mapDBInfo.layers[layer]["key"]
  384. columns = self.mapDBInfo.tables[table]
  385. for name in columns.keys():
  386. if name == key:
  387. for cat in self.cats[self.fid][layer]:
  388. self.mapDBInfo.tables[table][name]['values'].append(cat)
  389. else:
  390. self.mapDBInfo.tables[table][name]['values'].append(None)
  391. else: # change status 'add' -> 'update'
  392. self.action = "update"
  393. table = self.mapDBInfo.layers[layer]["table"]
  394. key = self.mapDBInfo.layers[layer]["key"]
  395. columns = self.mapDBInfo.tables[table]
  396. for idx in range(len(columns[key]['values'])):
  397. for name in columns.keys():
  398. if name == key:
  399. cat = int(columns[name]['values'][idx])
  400. break
  401. # use scrolled panel instead (and fix initial max height of the window to 480px)
  402. panel = scrolled.ScrolledPanel(parent = self.notebook, id = wx.ID_ANY,
  403. size = (-1, 150))
  404. panel.SetupScrolling(scroll_x = False)
  405. self.notebook.AddPage(page = panel, text = " %s %d / %s %d" % (_("Layer"), layer,
  406. _("Category"), cat))
  407. # notebook body
  408. border = wx.BoxSizer(wx.VERTICAL)
  409. flexSizer = wx.FlexGridSizer (cols = 3, hgap = 3, vgap = 3)
  410. flexSizer.AddGrowableCol(2)
  411. # columns (sorted by index)
  412. names = [''] * len(columns.keys())
  413. for name in columns.keys():
  414. names[columns[name]['index']] = name
  415. for name in names:
  416. if name == key: # skip key column (category)
  417. continue
  418. vtype = columns[name]['type'].lower()
  419. ctype = columns[name]['ctype']
  420. if columns[name]['values'][idx] is not None:
  421. if columns[name]['ctype'] != types.StringType:
  422. value = str(columns[name]['values'][idx])
  423. else:
  424. value = columns[name]['values'][idx]
  425. else:
  426. value = ''
  427. colName = wx.StaticText(parent = panel, id = wx.ID_ANY,
  428. label = name)
  429. colType = wx.StaticText(parent = panel, id = wx.ID_ANY,
  430. label = "[%s]:" % vtype)
  431. colValue = wx.TextCtrl(parent = panel, id = wx.ID_ANY, value = value)
  432. colValue.SetName(name)
  433. if ctype == int:
  434. colValue.SetValidator(IntegerValidator())
  435. elif ctype == float:
  436. colValue.SetValidator(FloatValidator())
  437. self.Bind(wx.EVT_TEXT, self.OnSQLStatement, colValue)
  438. if self.action == 'display':
  439. colValue.SetWindowStyle(wx.TE_READONLY)
  440. flexSizer.Add(colName, proportion = 0,
  441. flag = wx.ALIGN_CENTER_VERTICAL)
  442. flexSizer.Add(colType, proportion = 0,
  443. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  444. flexSizer.Add(colValue, proportion = 1,
  445. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
  446. # add widget reference to self.columns
  447. columns[name]['ids'].append(colValue.GetId()) # name, type, values, id
  448. # for each attribute (including category) END
  449. border.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  450. panel.SetSizer(border)
  451. # for each category END
  452. # for each layer END
  453. if self.notebook.GetPageCount() == 0:
  454. self.noFoundMsg.Show(True)
  455. else:
  456. self.noFoundMsg.Show(False)
  457. self.Layout()
  458. return True
  459. def SetColumnValue(self, layer, column, value):
  460. """!Set attrbute value
  461. @param column column name
  462. @param value value
  463. """
  464. table = self.mapDBInfo.GetTable(layer)
  465. columns = self.mapDBInfo.GetTableDesc(table)
  466. for key, col in columns.iteritems():
  467. if key == column:
  468. col['values'] = [col['ctype'](value),]
  469. break
  470. class ModifyTableRecord(wx.Dialog):
  471. def __init__(self, parent, title, data, keyEditable = (-1, True),
  472. id = wx.ID_ANY, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  473. """!Dialog for inserting/updating table record
  474. @param data a list: [(column, value)]
  475. @param KeyEditable (id, editable?) indicates if textarea for key column
  476. is editable(True) or not
  477. """
  478. # parent -> VDigitWindow
  479. wx.Dialog.__init__(self, parent, id, title, style = style)
  480. self.CenterOnParent()
  481. self.keyId = keyEditable[0]
  482. box = wx.StaticBox(parent = self, id = wx.ID_ANY)
  483. box.Hide()
  484. self.dataPanel = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY,
  485. style = wx.TAB_TRAVERSAL)
  486. self.dataPanel.SetupScrolling(scroll_x = False)
  487. # buttons
  488. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  489. self.btnSubmit = wx.Button(self, wx.ID_OK, _("&Submit"))
  490. self.btnSubmit.SetDefault()
  491. # data area
  492. self.widgets = []
  493. cId = 0
  494. self.usebox = False
  495. self.cat = None
  496. winFocus = False
  497. for column, ctype, ctypeStr, value in data:
  498. if self.keyId == cId:
  499. self.cat = int(value)
  500. if not keyEditable[1]:
  501. self.usebox = True
  502. box.SetLabel(" %s %d " % (_("Category"), self.cat))
  503. box.Show()
  504. self.boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  505. cId += 1
  506. continue
  507. else:
  508. valueWin = wx.SpinCtrl(parent = self.dataPanel, id = wx.ID_ANY,
  509. value = value, min = -1e9, max = 1e9, size = (250, -1))
  510. else:
  511. valueWin = wx.TextCtrl(parent = self.dataPanel, id = wx.ID_ANY,
  512. value = value, size = (250, -1))
  513. if ctype == int:
  514. valueWin.SetValidator(IntegerValidator())
  515. elif ctype == float:
  516. valueWin.SetValidator(FloatValidator())
  517. if not winFocus:
  518. wx.CallAfter(valueWin.SetFocus)
  519. winFocus = True
  520. label = wx.StaticText(parent = self.dataPanel, id = wx.ID_ANY,
  521. label = column)
  522. ctype = wx.StaticText(parent = self.dataPanel, id = wx.ID_ANY,
  523. label = "[%s]:" % ctypeStr.lower())
  524. self.widgets.append((label.GetId(), ctype.GetId(), valueWin.GetId()))
  525. cId += 1
  526. self._layout()
  527. def _layout(self):
  528. """!Do layout"""
  529. sizer = wx.BoxSizer(wx.VERTICAL)
  530. # data area
  531. dataSizer = wx.FlexGridSizer(cols = 3, hgap = 3, vgap = 3)
  532. dataSizer.AddGrowableCol(2)
  533. for labelId, ctypeId, valueId in self.widgets:
  534. label = self.FindWindowById(labelId)
  535. ctype = self.FindWindowById(ctypeId)
  536. value = self.FindWindowById(valueId)
  537. dataSizer.Add(label, proportion = 0,
  538. flag = wx.ALIGN_CENTER_VERTICAL)
  539. dataSizer.Add(ctype, proportion = 0,
  540. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  541. dataSizer.Add(value, proportion = 0,
  542. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
  543. self.dataPanel.SetAutoLayout(True)
  544. self.dataPanel.SetSizer(dataSizer)
  545. dataSizer.Fit(self.dataPanel)
  546. if self.usebox:
  547. self.boxSizer.Add(item = self.dataPanel, proportion = 1,
  548. flag = wx.EXPAND | wx.ALL, border = 5)
  549. # buttons
  550. btnSizer = wx.StdDialogButtonSizer()
  551. btnSizer.AddButton(self.btnCancel)
  552. btnSizer.AddButton(self.btnSubmit)
  553. btnSizer.Realize()
  554. if not self.usebox:
  555. sizer.Add(item = self.dataPanel, proportion = 1,
  556. flag = wx.EXPAND | wx.ALL, border = 5)
  557. else:
  558. sizer.Add(item = self.boxSizer, proportion = 1,
  559. flag = wx.EXPAND | wx.ALL, border = 5)
  560. sizer.Add(item = btnSizer, proportion = 0,
  561. flag = wx.EXPAND | wx.ALL, border = 5)
  562. framewidth = self.GetBestSize()[0] + 25
  563. self.SetMinSize((framewidth, 250))
  564. self.SetAutoLayout(True)
  565. self.SetSizer(sizer)
  566. sizer.Fit(self)
  567. self.Layout()
  568. def GetValues(self, columns = None):
  569. """!Return list of values (casted to string).
  570. If columns is given (list), return only values of given columns.
  571. """
  572. valueList = []
  573. for labelId, ctypeId, valueId in self.widgets:
  574. column = self.FindWindowById(labelId).GetLabel().replace(':', '')
  575. if columns is None or column in columns:
  576. value = str(self.FindWindowById(valueId).GetValue())
  577. valueList.append(value)
  578. # add key value
  579. if self.usebox:
  580. valueList.insert(self.keyId, str(self.cat))
  581. return valueList