dialogs.py 23 KB

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