Edouard@2329: #!/usr/bin/env python
Edouard@2329: # -*- coding: utf-8 -*-
Edouard@2329: 
Edouard@2329: # See COPYING file for copyrights details.
Edouard@2329: 
kinsamanka@3750: 
Edouard@2329: 
Edouard@2334: from functools import partial
Edouard@2329: import wx
Edouard@2329: 
Edouard@2336: from controls.IDBrowser import IDBrowser
Edouard@2334: 
edouard@2492: 
Edouard@2329: class SchemeEditor(wx.Panel):
Edouard@2329:     def __init__(self, scheme, parent, *args, **kwargs):
edouard@2492:         self.txtctrls = {}
Edouard@2329:         wx.Panel.__init__(self, parent, *args, **kwargs)
Edouard@2329: 
Edouard@2334:         self.fieldsizer = wx.FlexGridSizer(cols=2, hgap=10, vgap=10)
Edouard@2334: 
Edouard@2334:         if self.EnableIDSelector:
Edouard@2334:             self.model = self.model + [("ID", _("ID:"))]
Edouard@2329: 
Edouard@2329:         for tag, label in self.model:
Edouard@2329:             txtctrl = wx.TextCtrl(parent=self, size=wx.Size(200, -1))
Edouard@2329:             self.txtctrls[tag] = txtctrl
Edouard@2329:             for win, flag in [
edouard@2492:                     (wx.StaticText(self, label=label),
andrej@2537:                      wx.ALIGN_CENTER_VERTICAL),
edouard@2492:                     (txtctrl, wx.GROW)]:
edouard@3303:                 self.fieldsizer.Add(win, flag=flag)
Edouard@2329: 
Edouard@2334:         self.fieldsizer.AddSpacer(20)
Edouard@2329: 
Edouard@2334:         if self.EnableIDSelector:
Edouard@2334:             self.mainsizer = wx.FlexGridSizer(cols=2, hgap=10, vgap=10)
edouard@3303:             self.mainsizer.Add(self.fieldsizer)
Edouard@2336:             self.idselector = IDBrowser(
Edouard@2334:                 self, parent.ctr,
Edouard@2335:                 # use a callafter, as editor can be deleted by calling SetURI
Edouard@2335:                 partial(wx.CallAfter, parent.SetURI),
andrej@2537:                 self.txtctrls["ID"].SetValue)
edouard@3303:             self.mainsizer.Add(self.idselector)
Edouard@2334:             self.SetSizer(self.mainsizer)
Edouard@2334:         else:
Edouard@2334:             self.SetSizer(self.fieldsizer)
Edouard@2329: 
Edouard@2329:     def SetFields(self, fields):
edouard@2492:         for tag, _label in self.model:
Edouard@2329:             self.txtctrls[tag].SetValue(fields[tag])
Edouard@2329: 
Edouard@2329:     def GetFields(self):
edouard@2492:         return {tag: self.txtctrls[tag].GetValue() for tag, _label in self.model}