dialogs.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. """!
  2. @package gmodeler.dialogs
  3. @brief wxGUI Graphical Modeler - dialogs
  4. Classes:
  5. - dialogs::ModelDataDialog
  6. - dialogs::ModelSearchDialog
  7. - dialogs::ModelRelationDialog
  8. - dialogs::ModelParamDialog
  9. - dialogs::ModelItemDialog
  10. - dialogs::ModelLoopDialog
  11. - dialogs::ModelConditionDialog
  12. (C) 2010-2011 by the GRASS Development Team
  13. This program is free software under the GNU General Public License
  14. (>=v2). Read the file COPYING that comes with GRASS for details.
  15. @author Martin Landa <landa.martin gmail.com>
  16. """
  17. import os
  18. import wx
  19. from core import globalvar
  20. from core import utils
  21. from gui_core.widgets import GNotebook
  22. from core.gcmd import GError, EncodeString
  23. from gui_core.dialogs import ElementDialog, MapLayersDialog
  24. from gui_core.ghelp import SearchModuleWindow
  25. from gui_core.prompt import GPromptSTC
  26. from gui_core.forms import CmdPanel
  27. from grass.script import task as gtask
  28. class ModelDataDialog(ElementDialog):
  29. """!Data item properties dialog"""
  30. def __init__(self, parent, shape, id = wx.ID_ANY, title = _("Data properties"),
  31. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  32. self.parent = parent
  33. self.shape = shape
  34. label, etype = self._getLabel()
  35. ElementDialog.__init__(self, parent, title, label = label, etype = etype)
  36. self.element = gselect.Select(parent = self.panel,
  37. type = prompt)
  38. self.element.SetValue(shape.GetValue())
  39. self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
  40. self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel)
  41. self.PostInit()
  42. if shape.GetValue():
  43. self.btnOK.Enable()
  44. self._layout()
  45. self.SetMinSize(self.GetSize())
  46. def _getLabel(self):
  47. etype = False
  48. prompt = self.shape.GetPrompt()
  49. if prompt == 'raster':
  50. label = _('Name of raster map:')
  51. elif prompt == 'vector':
  52. label = _('Name of vector map:')
  53. else:
  54. etype = True
  55. label = _('Name of element:')
  56. return label, etype
  57. def _layout(self):
  58. """!Do layout"""
  59. self.dataSizer.Add(self.element, proportion=0,
  60. flag=wx.EXPAND | wx.ALL, border=1)
  61. self.panel.SetSizer(self.sizer)
  62. self.sizer.Fit(self)
  63. def OnOK(self, event):
  64. """!Ok pressed"""
  65. self.shape.SetValue(self.GetElement())
  66. if self.etype:
  67. elem = self.GetType()
  68. if elem == 'rast':
  69. self.shape.SetPrompt('raster')
  70. elif elem == 'vect':
  71. self.shape.SetPrompt('raster')
  72. self.parent.canvas.Refresh()
  73. self.parent.SetStatusText('', 0)
  74. self.shape.SetPropDialog(None)
  75. if self.IsModal():
  76. event.Skip()
  77. else:
  78. self.Destroy()
  79. def OnCancel(self, event):
  80. """!Cancel pressed"""
  81. self.shape.SetPropDialog(None)
  82. if self.IsModal():
  83. event.Skip()
  84. else:
  85. self.Destroy()
  86. class ModelSearchDialog(wx.Dialog):
  87. def __init__(self, parent, id = wx.ID_ANY, title = _("Add new GRASS module to the model"),
  88. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  89. """!Graphical modeler module search window
  90. @param parent parent window
  91. @param id window id
  92. @param title window title
  93. @param kwargs wx.Dialogs' arguments
  94. """
  95. self.parent = parent
  96. wx.Dialog.__init__(self, parent = parent, id = id, title = title, **kwargs)
  97. self.SetName("ModelerDialog")
  98. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  99. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  100. self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  101. label=" %s " % _("Command"))
  102. self.cmd_prompt = GPromptSTC(parent = self)
  103. self.search = SearchModuleWindow(parent = self.panel, cmdPrompt = self.cmd_prompt, showTip = True)
  104. wx.CallAfter(self.cmd_prompt.SetFocus)
  105. # get commands
  106. items = self.cmd_prompt.GetCommandItems()
  107. self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
  108. self.btnOk = wx.Button(self.panel, wx.ID_OK)
  109. self.btnOk.SetDefault()
  110. self.btnOk.Enable(False)
  111. self.cmd_prompt.Bind(wx.EVT_KEY_UP, self.OnText)
  112. self.search.searchChoice.Bind(wx.EVT_CHOICE, self.OnText)
  113. self.Bind(wx.EVT_BUTTON, self.OnOk, self.btnOk)
  114. self._layout()
  115. self.SetSize((500, 275))
  116. def _layout(self):
  117. cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
  118. cmdSizer.Add(item = self.cmd_prompt, proportion = 1,
  119. flag = wx.EXPAND)
  120. btnSizer = wx.StdDialogButtonSizer()
  121. btnSizer.AddButton(self.btnCancel)
  122. btnSizer.AddButton(self.btnOk)
  123. btnSizer.Realize()
  124. mainSizer = wx.BoxSizer(wx.VERTICAL)
  125. mainSizer.Add(item = self.search, proportion = 0,
  126. flag = wx.EXPAND | wx.ALL, border = 3)
  127. mainSizer.Add(item = cmdSizer, proportion = 1,
  128. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 3)
  129. mainSizer.Add(item = btnSizer, proportion = 0,
  130. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  131. self.panel.SetSizer(mainSizer)
  132. mainSizer.Fit(self.panel)
  133. self.Layout()
  134. def GetPanel(self):
  135. """!Get dialog panel"""
  136. return self.panel
  137. def GetCmd(self):
  138. """!Get command"""
  139. line = self.cmd_prompt.GetCurLine()[0].strip()
  140. if len(line) == 0:
  141. list()
  142. try:
  143. cmd = utils.split(str(line))
  144. except UnicodeError:
  145. cmd = utils.split(EncodeString((line)))
  146. return cmd
  147. def OnOk(self, event):
  148. """!Button 'OK' pressed"""
  149. self.btnOk.SetFocus()
  150. cmd = self.GetCmd()
  151. if len(cmd) < 1:
  152. GError(parent = self,
  153. message = _("Command not defined.\n\n"
  154. "Unable to add new action to the model."))
  155. return
  156. if cmd[0] not in globalvar.grassCmd['all']:
  157. GError(parent = self,
  158. message = _("'%s' is not a GRASS module.\n\n"
  159. "Unable to add new action to the model.") % cmd[0])
  160. return
  161. self.EndModal(wx.ID_OK)
  162. def OnText(self, event):
  163. """!Text in prompt changed"""
  164. if self.cmd_prompt.AutoCompActive():
  165. event.Skip()
  166. return
  167. if isinstance(event, wx.KeyEvent):
  168. entry = self.cmd_prompt.GetTextLeft()
  169. elif isinstance(event, wx.stc.StyledTextEvent):
  170. entry = event.GetText()
  171. else:
  172. entry = event.GetString()
  173. if entry:
  174. self.btnOk.Enable()
  175. else:
  176. self.btnOk.Enable(False)
  177. event.Skip()
  178. def Reset(self):
  179. """!Reset dialog"""
  180. self.search.Reset()
  181. self.cmd_prompt.OnCmdErase(None)
  182. self.btnOk.Enable(False)
  183. self.cmd_prompt.SetFocus()
  184. class ModelRelationDialog(wx.Dialog):
  185. """!Relation properties dialog"""
  186. def __init__(self, parent, shape, id = wx.ID_ANY, title = _("Relation properties"),
  187. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  188. self.parent = parent
  189. self.shape = shape
  190. options = self._getOptions()
  191. if not options:
  192. self.valid = False
  193. return
  194. self.valid = True
  195. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  196. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  197. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  198. self.fromBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  199. label = " %s " % _("From"))
  200. self.toBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  201. label = " %s " % _("To"))
  202. self.option = wx.ComboBox(parent = self.panel, id = wx.ID_ANY,
  203. style = wx.CB_READONLY,
  204. choices = options)
  205. self.option.Bind(wx.EVT_COMBOBOX, self.OnOption)
  206. self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
  207. self.btnOk = wx.Button(self.panel, wx.ID_OK)
  208. self.btnOk.Enable(False)
  209. self._layout()
  210. def _layout(self):
  211. mainSizer = wx.BoxSizer(wx.VERTICAL)
  212. fromSizer = wx.StaticBoxSizer(self.fromBox, wx.VERTICAL)
  213. self._layoutShape(shape = self.shape.GetFrom(), sizer = fromSizer)
  214. toSizer = wx.StaticBoxSizer(self.toBox, wx.VERTICAL)
  215. self._layoutShape(shape = self.shape.GetTo(), sizer = toSizer)
  216. btnSizer = wx.StdDialogButtonSizer()
  217. btnSizer.AddButton(self.btnCancel)
  218. btnSizer.AddButton(self.btnOk)
  219. btnSizer.Realize()
  220. mainSizer.Add(item = fromSizer, proportion = 0,
  221. flag = wx.EXPAND | wx.ALL, border = 5)
  222. mainSizer.Add(item = toSizer, proportion = 0,
  223. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  224. mainSizer.Add(item = btnSizer, proportion = 0,
  225. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  226. self.panel.SetSizer(mainSizer)
  227. mainSizer.Fit(self.panel)
  228. self.Layout()
  229. self.SetSize(self.GetBestSize())
  230. def _layoutShape(self, shape, sizer):
  231. if isinstance(shape, ModelData):
  232. sizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  233. label = _("Data: %s") % shape.GetLog()),
  234. proportion = 1, flag = wx.EXPAND | wx.ALL,
  235. border = 5)
  236. elif isinstance(shape, ModelAction):
  237. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  238. gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  239. label = _("Command:")),
  240. pos = (0, 0))
  241. gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  242. label = shape.GetName()),
  243. pos = (0, 1))
  244. gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  245. label = _("Option:")),
  246. flag = wx.ALIGN_CENTER_VERTICAL,
  247. pos = (1, 0))
  248. gridSizer.Add(item = self.option,
  249. pos = (1, 1))
  250. sizer.Add(item = gridSizer,
  251. proportion = 1, flag = wx.EXPAND | wx.ALL,
  252. border = 5)
  253. def _getOptions(self):
  254. """!Get relevant options"""
  255. items = []
  256. fromShape = self.shape.GetFrom()
  257. if not isinstance(fromShape, ModelData):
  258. GError(parent = self.parent,
  259. message = _("Relation doesn't start with data item.\n"
  260. "Unable to add relation."))
  261. return items
  262. toShape = self.shape.GetTo()
  263. if not isinstance(toShape, ModelAction):
  264. GError(parent = self.parent,
  265. message = _("Relation doesn't point to GRASS command.\n"
  266. "Unable to add relation."))
  267. return items
  268. prompt = fromShape.GetPrompt()
  269. task = toShape.GetTask()
  270. for p in task.get_options()['params']:
  271. if p.get('prompt', '') == prompt and \
  272. 'name' in p:
  273. items.append(p['name'])
  274. if not items:
  275. GError(parent = self.parent,
  276. message = _("No relevant option found.\n"
  277. "Unable to add relation."))
  278. return items
  279. def GetOption(self):
  280. """!Get selected option"""
  281. return self.option.GetStringSelection()
  282. def IsValid(self):
  283. """!Check if relation is valid"""
  284. return self.valid
  285. def OnOption(self, event):
  286. """!Set option"""
  287. if event.GetString():
  288. self.btnOk.Enable()
  289. else:
  290. self.btnOk.Enable(False)
  291. class ModelParamDialog(wx.Dialog):
  292. def __init__(self, parent, params, id = wx.ID_ANY, title = _("Model parameters"),
  293. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  294. """!Model parameters dialog
  295. """
  296. self.parent = parent
  297. self.params = params
  298. self.tasks = list() # list of tasks/pages
  299. wx.Dialog.__init__(self, parent = parent, id = id, title = title, style = style, **kwargs)
  300. self.notebook = GNotebook(parent = self,
  301. style = globalvar.FNPageDStyle)
  302. panel = self._createPages()
  303. wx.CallAfter(self.notebook.SetSelection, 0)
  304. self.btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
  305. self.btnRun = wx.Button(parent = self, id = wx.ID_OK,
  306. label = _("&Run"))
  307. self.btnRun.SetDefault()
  308. self._layout()
  309. size = self.GetBestSize()
  310. self.SetMinSize(size)
  311. self.SetSize((size.width, size.height +
  312. panel.constrained_size[1] -
  313. panel.panelMinHeight))
  314. def _layout(self):
  315. btnSizer = wx.StdDialogButtonSizer()
  316. btnSizer.AddButton(self.btnCancel)
  317. btnSizer.AddButton(self.btnRun)
  318. btnSizer.Realize()
  319. mainSizer = wx.BoxSizer(wx.VERTICAL)
  320. mainSizer.Add(item = self.notebook, proportion = 1,
  321. flag = wx.EXPAND)
  322. mainSizer.Add(item = btnSizer, proportion = 0,
  323. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  324. self.SetSizer(mainSizer)
  325. mainSizer.Fit(self)
  326. def _createPages(self):
  327. """!Create for each parameterized module its own page"""
  328. nameOrdered = [''] * len(self.params.keys())
  329. for name, params in self.params.iteritems():
  330. nameOrdered[params['idx']] = name
  331. for name in nameOrdered:
  332. params = self.params[name]
  333. panel = self._createPage(name, params)
  334. if name == 'variables':
  335. name = _('Variables')
  336. self.notebook.AddPage(page = panel, text = name)
  337. return panel
  338. def _createPage(self, name, params):
  339. """!Define notebook page"""
  340. if name in globalvar.grassCmd['all']:
  341. task = gtask.grassTask(name)
  342. else:
  343. task = gtask.grassTask()
  344. task.flags = params['flags']
  345. task.params = params['params']
  346. panel = CmdPanel(parent = self, id = wx.ID_ANY, task = task)
  347. self.tasks.append(task)
  348. return panel
  349. def GetErrors(self):
  350. """!Check for errors, get list of messages"""
  351. errList = list()
  352. for task in self.tasks:
  353. errList += task.get_cmd_error()
  354. return errList
  355. class ModelItemDialog(wx.Dialog):
  356. """!Abstract item properties dialog"""
  357. def __init__(self, parent, shape, title, id = wx.ID_ANY,
  358. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  359. self.parent = parent
  360. self.shape = shape
  361. wx.Dialog.__init__(self, parent, id, title = title, style = style, **kwargs)
  362. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  363. self.condBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  364. label=" %s " % _("Condition"))
  365. self.condText = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  366. value = shape.GetText())
  367. self.itemList = ItemCheckListCtrl(parent = self.panel,
  368. window = self,
  369. columns = [_("ID"), _("Name"),
  370. _("Command")],
  371. shape = shape)
  372. self.itemList.Populate(self.parent.GetModel().GetItems())
  373. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  374. self.btnOk = wx.Button(parent = self.panel, id = wx.ID_OK)
  375. self.btnOk.SetDefault()
  376. def _layout(self):
  377. """!Do layout (virtual method)"""
  378. pass
  379. def GetCondition(self):
  380. """!Get loop condition"""
  381. return self.condText.GetValue()
  382. class ModelLoopDialog(ModelItemDialog):
  383. """!Loop properties dialog"""
  384. def __init__(self, parent, shape, id = wx.ID_ANY, title = _("Loop properties"),
  385. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  386. ModelItemDialog.__init__(self, parent, shape, title,
  387. style = style, **kwargs)
  388. self.listBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  389. label=" %s " % _("List of items in loop"))
  390. self.btnSeries = wx.Button(parent = self.panel, id = wx.ID_ANY,
  391. label = _("Series"))
  392. self.btnSeries.SetToolTipString(_("Define map series as condition for the loop"))
  393. self.btnSeries.Bind(wx.EVT_BUTTON, self.OnSeries)
  394. self._layout()
  395. self.SetMinSize(self.GetSize())
  396. self.SetSize((500, 400))
  397. def _layout(self):
  398. """!Do layout"""
  399. sizer = wx.BoxSizer(wx.VERTICAL)
  400. condSizer = wx.StaticBoxSizer(self.condBox, wx.HORIZONTAL)
  401. condSizer.Add(item = self.condText, proportion = 1,
  402. flag = wx.ALL, border = 3)
  403. condSizer.Add(item = self.btnSeries, proportion = 0,
  404. flag = wx.EXPAND)
  405. listSizer = wx.StaticBoxSizer(self.listBox, wx.VERTICAL)
  406. listSizer.Add(item = self.itemList, proportion = 1,
  407. flag = wx.EXPAND | wx.ALL, border = 3)
  408. btnSizer = wx.StdDialogButtonSizer()
  409. btnSizer.AddButton(self.btnCancel)
  410. btnSizer.AddButton(self.btnOk)
  411. btnSizer.Realize()
  412. sizer.Add(item = condSizer, proportion = 0,
  413. flag = wx.EXPAND | wx.ALL, border = 3)
  414. sizer.Add(item = listSizer, proportion = 1,
  415. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 3)
  416. sizer.Add(item = btnSizer, proportion=0,
  417. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  418. self.panel.SetSizer(sizer)
  419. sizer.Fit(self.panel)
  420. self.Layout()
  421. def GetItems(self):
  422. """!Get list of selected actions"""
  423. return self.itemList.GetItems()
  424. def OnSeries(self, event):
  425. """!Define map series as condition"""
  426. dialog = MapLayersDialog(parent = self, title = _("Define series of maps"), modeler = True)
  427. if dialog.ShowModal() != wx.ID_OK:
  428. dialog.Destroy()
  429. return
  430. cond = dialog.GetDSeries()
  431. if not cond:
  432. cond = 'map in %s' % map(lambda x: str(x), dialog.GetMapLayers())
  433. self.condText.SetValue(cond)
  434. dialog.Destroy()
  435. class ModelConditionDialog(ModelItemDialog):
  436. """!Condition properties dialog"""
  437. def __init__(self, parent, shape, id = wx.ID_ANY, title = _("If-else properties"),
  438. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  439. ModelItemDialog.__init__(self, parent, shape, title,
  440. style = style, **kwargs)
  441. self.listBoxIf = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  442. label=" %s " % _("List of items in 'if' block"))
  443. self.itemListIf = self.itemList
  444. self.itemListIf.SetName('IfBlockList')
  445. self.listBoxElse = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  446. label=" %s " % _("List of items in 'else' block"))
  447. self.itemListElse = ItemCheckListCtrl(parent = self.panel,
  448. window = self,
  449. columns = [_("ID"), _("Name"),
  450. _("Command")],
  451. shape = shape)
  452. self.itemListElse.SetName('ElseBlockList')
  453. self.itemListElse.Populate(self.parent.GetModel().GetItems())
  454. self._layout()
  455. self.SetMinSize(self.GetSize())
  456. self.SetSize((500, 400))
  457. def _layout(self):
  458. """!Do layout"""
  459. sizer = wx.BoxSizer(wx.VERTICAL)
  460. condSizer = wx.StaticBoxSizer(self.condBox, wx.VERTICAL)
  461. condSizer.Add(item = self.condText, proportion = 1,
  462. flag = wx.EXPAND)
  463. listIfSizer = wx.StaticBoxSizer(self.listBoxIf, wx.VERTICAL)
  464. listIfSizer.Add(item = self.itemListIf, proportion = 1,
  465. flag = wx.EXPAND)
  466. listElseSizer = wx.StaticBoxSizer(self.listBoxElse, wx.VERTICAL)
  467. listElseSizer.Add(item = self.itemListElse, proportion = 1,
  468. flag = wx.EXPAND)
  469. btnSizer = wx.StdDialogButtonSizer()
  470. btnSizer.AddButton(self.btnCancel)
  471. btnSizer.AddButton(self.btnOk)
  472. btnSizer.Realize()
  473. sizer.Add(item = condSizer, proportion = 0,
  474. flag = wx.EXPAND | wx.ALL, border = 3)
  475. sizer.Add(item = listIfSizer, proportion = 1,
  476. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 3)
  477. sizer.Add(item = listElseSizer, proportion = 1,
  478. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 3)
  479. sizer.Add(item = btnSizer, proportion=0,
  480. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  481. self.panel.SetSizer(sizer)
  482. sizer.Fit(self.panel)
  483. self.Layout()
  484. def OnCheckItemIf(self, index, flag):
  485. """!Item in if-block checked/unchecked"""
  486. if flag is False:
  487. return
  488. aId = int(self.itemListIf.GetItem(index, 0).GetText())
  489. if aId in self.itemListElse.GetItems()['checked']:
  490. self.itemListElse.CheckItemById(aId, False)
  491. def OnCheckItemElse(self, index, flag):
  492. """!Item in else-block checked/unchecked"""
  493. if flag is False:
  494. return
  495. aId = int(self.itemListElse.GetItem(index, 0).GetText())
  496. if aId in self.itemListIf.GetItems()['checked']:
  497. self.itemListIf.CheckItemById(aId, False)
  498. def GetItems(self):
  499. """!Get items"""
  500. return { 'if' : self.itemListIf.GetItems(),
  501. 'else' : self.itemListElse.GetItems() }