--- a/LPCManager.py Wed Jan 25 10:45:37 2017 +0100
+++ b/LPCManager.py Wed Jan 25 10:48:23 2017 +0100
@@ -128,6 +128,61 @@
from ProjectController import ProjectController
from ConfigTreeNode import ConfigTreeNode
from editors.ProjectNodeEditor import ProjectNodeEditor
+from editors.CodeFileEditor import VariablesTable +from WampOptionsEditor import WampOptionsEditor +def LeftClick(self, event): + if event.GetCol() == 6: + options = [self.grid.GetCellValue(event.GetRow(), event.GetCol()), self.grid.GetCellValue(event.GetRow(), event.GetCol()-1)] + desc = self.grid.GetCellValue(event.GetRow(), event.GetCol()-2) + dialog = WampOptionsEditor(self.Parent.Parent, options, desc) + answer = dialog.ShowModal() + opt,OnChange,value,description = dialog.GetOptions() + self.grid.SetCellValue(event.GetRow(), event.GetCol(), str(opt)) + self.grid.SetCellValue(event.GetRow(), event.GetCol()-1, value) + self.grid.SetCellValue(event.GetRow(), event.GetCol()-2, description) + self.Parent.RefreshModel() +VariablesTable.LeftClick = LeftClick +def _updateColAttrs(self, grid): + wxGrid -> update the column attributes to add the + appropriate renderer given the column name. + Otherwise default to the default renderer. + for row in range(self.GetNumberRows()): + for col in range(self.GetNumberCols()): + colname = self.GetColLabelValue(col, False) + if colname in ["Name", "Initial", "Description", "OnChange"]: + editor = wx.grid.GridCellTextEditor() + elif colname == "Class": + editor = wx.grid.GridCellChoiceEditor() + editor.SetParameters("input,memory,output") + elif colname == "Type": + grid.SetReadOnly(row, col, True) + grid.SetCellEditor(row, col, editor) + grid.SetCellRenderer(row, col, renderer) + grid.SetCellBackgroundColour(row, col, wx.WHITE) + self.ResizeRow(grid, row) + self.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.LeftClick) +VariablesTable._updateColAttrs = _updateColAttrs from PLCControler import PLCControler, LOCATION_MODULE, LOCATION_GROUP, \
LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WampOptionsEditor.py Wed Jan 25 10:48:23 2017 +0100
@@ -0,0 +1,213 @@
+[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): + def _init_sizers(self): + 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._init_ctrls(parent) + 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.MinSpin.SetValue(0) + self.MaxSpin.SetValue(0) + 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) + elif el[0] == "Static": + self.OptionsTypeChoice.SetSelection(1) + elif el[0] == "Session": + self.OptionsTypeChoice.SetSelection(2) + self.OptionsTypeChoice.SetSelection(3) + self.ScadaCheckbox.SetValue(True) + self.StaticCheckbox.Enable(True) + self.StaticCheckbox.SetValue(True) + if el[0] == "subgroup": + 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() + if self.TypeSelected<0: + 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 \ No newline at end of file