[ID_OPTIONSWIZARDDIALOG,ID_ONCHANGE,ID_OPTIONSTYPECHOICE,ID_SUBGROUPTEXT,ID_UNITTEXT,ID_VALUECHECKBOX,ID_MINSPIN,ID_MAXSPIN,ID_PRECISIONSPIN,ID_SCADACHECKBOX,ID_OTHERTEXT,ID_DESCRIPTION,ID_STATIC] = [wx.NewId() for _init_ctrls in range(13)]
VARIABLETYPE = ["", "Static", "Session", "Alarm"]
class WampOptionsEditor(wx.Dialog):
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
self.OptionsSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=10, vgap=10)
self.OptionsSizer.AddWindow(wx.StaticText(self,wx.ID_ANY,"Type of variable"))
self.OptionsSizer.AddWindow(self.OptionsTypeChoice)
self.OptionsSizer.AddWindow(self.OnChangeCheckbox)
self.OptionsSizer.AddWindow(wx.StaticText(self, wx.ID_ANY, "On Change"))
self.OptionsSizer.AddWindow(self.ScadaCheckbox)
self.OptionsSizer.AddWindow(wx.StaticText(self, wx.ID_ANY, "Scada"))
self.OptionsSizer.AddWindow(self.StaticCheckbox)
self.OptionsSizer.AddWindow(wx.StaticText(self, wx.ID_ANY, "Static"))
self.OptionsSizer.AddWindow(wx.StaticText(self,wx.ID_ANY,"Subgroup:"))
self.OptionsSizer.AddWindow(self.SubgroupText)
self.OptionsSizer.AddWindow(wx.StaticText(self,wx.ID_ANY,"Unit:"))
self.OptionsSizer.AddWindow(self.UnitText)
self.OptionsSizer.AddWindow(self.ValueCheckbox)
self.OptionsSizer.AddWindow(wx.StaticText(self,wx.ID_ANY,"Enable min/max value"))
self.minValue=wx.StaticText(self, wx.ID_ANY, "Min value:")
self.maxValue=wx.StaticText(self, wx.ID_ANY, "Max value:")
self.PrecisionValue = wx.StaticText(self, wx.ID_ANY, "Precision:")
self.OptionsSizer.AddWindow(self.minValue)
self.OptionsSizer.AddWindow(self.MinSpin)
self.OptionsSizer.AddWindow(self.maxValue)
self.OptionsSizer.AddWindow(self.MaxSpin)
self.OptionsSizer.AddWindow(self.PrecisionValue)
self.OptionsSizer.AddWindow(self.PrecisionSpin)
self.OptionsSizer.AddWindow(wx.StaticText(self, wx.ID_ANY, "Other:"))
self.OptionsSizer.AddWindow(self.OtherText)
self.OptionsSizer.AddWindow(wx.StaticText(self, wx.ID_ANY, "Description:"))
self.OptionsSizer.AddWindow(self.DescriptionText)
self.ButtonSizer.AddWindow(self.ClearButton)
self.MainSizer.AddSizer(self.OptionsSizer, 0, border=20, flag=wx.ALL)
self.MainSizer.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_CENTER_HORIZONTAL)
self.SetSizer(self.MainSizer)
def _init_ctrls(self, prnt):
wx.Dialog.__init__(self, id=ID_OPTIONSWIZARDDIALOG,
name='OptionsWizard', parent=prnt,
size=wx.Size(255, 515), style=wx.DEFAULT_DIALOG_STYLE,
self.OptionsTypeChoice = wx.Choice(parent=self, id=ID_OPTIONSWIZARDDIALOG,
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.OptionsTypeChoice)
self.OnChangeCheckbox = wx.CheckBox(parent=self, id=ID_ONCHANGE)
self.SubgroupText = wx.TextCtrl(parent=self, id=ID_SUBGROUPTEXT)
self.UnitText = wx.TextCtrl(parent=self, id=ID_UNITTEXT)
self.ValueCheckbox = wx.CheckBox(parent=self, id=ID_VALUECHECKBOX)
self.MinSpin = wx.SpinCtrl(parent=self, id=ID_MINSPIN, style=wx.SP_VERTICAL)
self.MaxSpin = wx.SpinCtrl(parent=self, id=ID_MAXSPIN, style=wx.SP_VERTICAL)
self.PrecisionSpin = wx.SpinCtrl(parent=self, id=ID_PRECISIONSPIN, style=wx.SP_VERTICAL)
self.MinSpin.SetRange(-sys.maxsize, sys.maxsize)
self.MaxSpin.SetRange(-sys.maxsize, sys.maxsize)
self.ScadaCheckbox = wx.CheckBox(parent=self, id=ID_SCADACHECKBOX)
self.StaticCheckbox = wx.CheckBox(parent=self, id=ID_SCADACHECKBOX)
self.OtherText = wx.TextCtrl(parent=self, id=ID_OTHERTEXT)
self.DescriptionText = wx.TextCtrl(parent=self, id=ID_DESCRIPTION, size=(-1, 100), style=wx.TE_MULTILINE | wx.SUNKEN_BORDER)
self.ClearButton = wx.Button(self, wx.ID_CLEAR, "Clear")
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
self.ValueCheckbox.Bind(wx.EVT_CHECKBOX, self.EnableValue)
self.MinSpin.Enable(False)
self.MaxSpin.Enable(False)
self.OnChangeCheckbox.Enable(False)
self.StaticCheckbox.Enable(False)
self.Bind(wx.EVT_CHOICE, self.Enabler, self.OptionsTypeChoice)
self.Bind(wx.EVT_BUTTON, self.clearOptions, self.ClearButton)
self.Bind(wx.EVT_CHECKBOX, self.Enabler, self.ScadaCheckbox)
def __init__(self, parent, opt, desc):
self.SetOptions(opt, desc)
def Enabler(self, event):
if self.OptionsTypeChoice.GetSelection() in [1,3]:
self.OnChangeCheckbox.Enable(True)
self.OnChangeCheckbox.Enable(False)
if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue():
self.StaticCheckbox.Enable(True)
self.StaticCheckbox.Enable(False)
def clearOptions(self, event):
self.OptionsTypeChoice.SetSelection(0)
self.SubgroupText.SetLabel("")
self.UnitText.SetLabel("")
self.ValueCheckbox.SetValue(False)
self.ScadaCheckbox.SetValue(False)
self.StaticCheckbox.SetValue(False)
self.OtherText.SetLabel("")
self.MinSpin.Enable(False)
self.MaxSpin.Enable(False)
self.StaticCheckbox.Enable(False)
self.PrecisionSpin.SetValue(0)
self.OnChangeCheckbox.SetValue(False)
self.DescriptionText.SetLabel("")
def OnTypeChoice(self, event):
self.selected = event.GetSelection()
def EnableValue(self, event):
self.MinSpin.Enable(self.ValueCheckbox.GetValue())
self.MaxSpin.Enable(self.ValueCheckbox.GetValue())
# def MinChange(self,event):
# self.minValue.SetLabel("Min value: " + str(self.MinSpin.GetValue()))
# def MaxChange(self,event):
# self.maxValue.SetLabel("Max value: " + str(self.MaxSpin.GetValue()))
def SetOptions(self, opt, desc):
optionsTemp = opt1.split(" ")
options.append(el.split("="))
self.OptionsTypeChoice.SetSelection(0)
self.OptionsTypeChoice.SetSelection(1)
self.OptionsTypeChoice.SetSelection(2)
self.OptionsTypeChoice.SetSelection(3)
self.ScadaCheckbox.SetValue(True)
self.StaticCheckbox.Enable(True)
self.StaticCheckbox.SetValue(True)
self.SubgroupText.SetLabel(el[1])
self.UnitText.SetLabel(el[1])
self.ValueCheckbox.SetValue(True)
self.MinSpin.SetValue(int(el[1]))
self.MinSpin.Enable(True)
self.ValueCheckbox.SetValue(True)
self.MaxSpin.SetValue(int(el[1]))
self.MaxSpin.Enable(True)
self.OtherText.SetLabel(el[1])
elif el[0] == "precision":
self.PrecisionSpin.SetValue(int(el[1]))
self.OnChangeCheckbox.Enable(True)
self.OnChangeCheckbox.SetValue(True)
if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue():
self.StaticCheckbox.Enable(True)
self.DescriptionText.SetLabel(desc)
self.TypeSelected = self.OptionsTypeChoice.GetSelection()
options = VARIABLETYPE[self.TypeSelected]
if self.ScadaCheckbox.GetValue():
if self.StaticCheckbox.GetValue():
if self.SubgroupText.GetLineText(0) != "":
options += " subgroup=" + self.SubgroupText.GetLineText(0)
if self.UnitText.GetLineText(0) != "":
options += " unit=" + self.UnitText.GetLineText(0)
if self.MinSpin.IsEnabled():
options += " min=" + str(self.MinSpin.GetValue())
options += " max=" + str(self.MaxSpin.GetValue())
if self.PrecisionSpin.GetValue() != 0:
options += " precision=" + str(self.PrecisionSpin.GetValue())
if self.OtherText.GetLineText(0) != "":
options += " other=" + self.OtherText.GetLineText(0)
if self.OnChangeCheckbox.GetValue():
if VARIABLETYPE[self.TypeSelected] == "Alarm":
elif VARIABLETYPE[self.TypeSelected] == "Static":
self.value = "StoredValue"
self.Description = self.DescriptionText.GetValue()
return options, self.OnChange,self.value, self.Description