lpcmanager

Parents 62db7571a572
Children 870e9d7ec9c0
Added Export option for Halton variables and made Options column in python files larger.
--- a/LPCManager.py Thu Mar 30 08:19:00 2017 +0200
+++ b/LPCManager.py Thu Mar 30 13:15:17 2017 +0200
@@ -137,27 +137,41 @@
from ConfigTreeNode import ConfigTreeNode
from editors.ProjectNodeEditor import ProjectNodeEditor
from editors.CodeFileEditor import VariablesTable
+from editors.CodeFileEditor import VariablesEditor
from WampOptionsEditor import WampOptionsEditor
+from VariableExporter import VariableWriter
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()
- dialog.Destroy()
- if answer == wx.ID_OK:
- self.grid.SetCellValue(event.GetRow(), event.GetCol(), str(opt))
- if OnChange:
- self.grid.SetCellValue(event.GetRow(), event.GetCol()-1, value)
- self.grid.SetCellValue(event.GetRow(), event.GetCol()-2, description)
- self.Parent.RefreshModel()
+ if event.GetCol() == self.grid.GetNumberCols()-1:
+ 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)
+ if hasattr(self, "dialog"):
+ self.dialog.SetOptions(options, desc)
+ answer = self.dialog.ShowModal()
+ #self.dialog.SetOptions(options, desc)
+ else:
+ self.dialog = WampOptionsEditor(self.Parent.Parent, options, desc)
+ answer = self.dialog.ShowModal()
+ opt,OnChange,value,description = self.dialog.GetOptions()
+ if answer == wx.ID_OK:
+ self.grid.SetCellValue(event.GetRow(), event.GetCol(), str(opt))
+ if OnChange:
+ self.grid.SetCellValue(event.GetRow(), event.GetCol()-1, value)
+ self.grid.SetCellValue(event.GetRow(), event.GetCol()-2, description)
+ self.Parent.RefreshModel()
- else:
- event.Skip()
+ else:
+ event.Skip()
+
VariablesTable.LeftClick = LeftClick
+def VariablesEditorSetCollSize(self):
+ ColSizes = [20, 150] + [130] * (len(self.VariablesDefaultValue) - 2) + [300]
+ for col in range(self.Table.GetNumberCols()):
+ self.VariablesGrid.SetColSize(col, ColSizes[col])
+
+VariablesEditor.VariablesEditorSetCollSize = VariablesEditorSetCollSize
+
def _updateColAttrs(self, grid):
"""
wxGrid -> update the column attributes to add the
@@ -188,8 +202,13 @@
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)
+
+ self.grid.SetRowMinimalHeight
+ # updated column width, with function VariablesEditorSetCollSize added in VariablesEditor class
+ self.Parent.VariablesEditorSetCollSize()
+ # added left click option on grid, with function LeftClick added in VariablesTable class
+ self.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.LeftClick)
+
VariablesTable._updateColAttrs = _updateColAttrs
from PLCControler import PLCControler, LOCATION_MODULE, LOCATION_GROUP, \
@@ -224,6 +243,7 @@
# havecanfestival = False
SCROLLBAR_UNIT = 10
+ID_EXPORT = 7500
WINDOW_COLOUR = wx.Colour(240, 240, 240)
TITLE_COLOUR = wx.Colour(200, 200, 220)
CHANGED_TITLE_COLOUR = wx.Colour(220, 200, 220)
@@ -1329,6 +1349,9 @@
AppendMenu(parent, help='', id=wx.ID_PRINT,
kind=wx.ITEM_NORMAL, text=_(u'Print'))
parent.AppendSeparator()
+ AppendMenu(parent, help='', id=ID_EXPORT,
+ kind=wx.ITEM_NORMAL, text=_(u'Export'))
+ parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_EXIT,
kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
@@ -1337,11 +1360,14 @@
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
+ self.Bind(wx.EVT_MENU, lambda event: VariableWriter(self, event, self.CTR.ProjectPath), id=ID_EXPORT)
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
self.AddToMenuToolBar([(wx.ID_SAVE, "save", _(u'Save'), None),
(wx.ID_PRINT, "print", _(u'Print'), None)])
+
+
def _init_ctrls(self, prnt):
Beremiz._init_ctrls(self, prnt)
@@ -1367,6 +1393,16 @@
self.CTR.KillDebugThread()
self.KillLocalRuntime()
+ # close wxGlade if running
+ config = wx.ConfigBase.Get()
+ wxGladePid = str(config.Read("BeremizRoot.wxGlade"))
+ if wxGladePid != 0:
+ import signal
+ os.kill(int(wxGladePid), signal.SIGTERM)
+ wxGladePid = 0
+ config.Write("BeremizRoot.wxGlade", str(wxGladePid))
+ config.Flush()
+
self.SaveLastState()
lpcberemiz_cmd.Log.write("Closed\n")
@@ -1859,6 +1895,12 @@
lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
lpcberemiz_cmd.cmdloop()
+ def ResetwxGlade():
+ # reset pid of running wxGlade
+ config = wx.ConfigBase.Get()
+ wxGladePid = 0
+ config.Write("BeremizRoot.wxGlade", str(wxGladePid))
+ config.Flush()
Log = StdoutPseudoFile(port)
@@ -1881,4 +1923,6 @@
frame = LPCBeremiz(None, ctr=CTR, debug=True)
+ ResetwxGlade()
+
app.MainLoop()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/VariableExporter.py Thu Mar 30 13:15:17 2017 +0200
@@ -0,0 +1,107 @@
+import wx
+import csv
+import os
+
+def VariableWriter(parent, event, path):
+ FileDialog = wx.FileDialog(parent, "Save CSV file", "", "", "CSV files (*.csv)|*.csv",
+ wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
+ if FileDialog.ShowModal() == wx.ID_OK:
+ if FileDialog.GetPath()[-4:] == ".csv":
+ export = FileDialog.GetPath()
+ else:
+ export = FileDialog.GetPath() + ".csv"
+ else:
+ return
+ parent.Controler.logger.write(_("Exporting...\n"))
+ modbus_list = []
+ modbus_dict = {}
+ program_name = ""
+ program_type = ""
+ with open(path + "\plc.xml") as infile:
+ for line in infile:
+ if "<pou" in line:
+ start_program = line.find("name")
+ program_name = ""
+ if start_program != -1:
+ end_program = line[start_program:].find(" ")
+ program_name = line[start_program + 6:start_program + end_program - 1]
+ start_type = line.find("pouType")
+ program_type = ""
+ if start_type != -1:
+ end_type = line[start_type:].find("\"")
+ program_type = line[start_type + 9:start_type + end_type + 8]
+ if ":= UINT_TO_WORD(" in line:
+ idx = line.find(":= UINT_TO_WORD(")
+ end = line[idx:].find(")")
+ name = line[idx + len(":= UINT_TO_WORD("):idx + end]
+ space = line.find(" ")
+ target = line[:space]
+ address = target.split("_")[-1]
+ modbus_list.append(name)
+ modbus_dict[name] = [target, address, program_name, program_type]
+
+ dir_list = [os.path.join(path, o) for o in os.listdir(path) if os.path.isdir(os.path.join(path, o))]
+
+ py_directories = []
+ for dir in dir_list:
+ if dir[-6:] == "py_ext":
+ py_directories.append(dir)
+
+ variables = [
+ ["NAME", "TYPE", "GROUP", "SUBGROUP", "TYPE OF VARIABLE", "MODBUS NAME", "MODBUS ADDRESS", "PROGRAM NAME",
+ "PROGRAM TYPE"]]
+ for dir in py_directories:
+ variable_list = []
+ with open(dir + "\pyfile.xml") as infile:
+ for line in infile:
+ curr_variable = []
+ idx_name = line.find("name")
+ name = ""
+ if idx_name != -1:
+ end_name = line[idx_name:].find(" ")
+ name = line[idx_name + 6:idx_name + end_name - 1]
+ curr_variable.append(name)
+ idx_type = line.find("type")
+ group = ""
+ type = ""
+ if idx_type != -1:
+ end_type = line[idx_type:].find(" ")
+ type = line[idx_type + 6:idx_type + end_type - 1]
+ group = dir.split("\\")[-1].split("@")[0]
+ if len(curr_variable) > 0:
+ curr_variable.append(type)
+ curr_variable.append(group)
+ idx_opts = line.find("opts")
+ options = []
+ if idx_opts != -1:
+ end_opts = line[idx_opts + 6:].find("\"")
+ opts = line[idx_opts + 6: idx_opts + end_opts + 6]
+ options = opts.split(" ")
+ o_type = ""
+ subgroup = ""
+ for o in options:
+ if o in ["Session", "Alarm", "Static"]:
+ o_type = o
+ if o == "scada":
+ o_type += " " + o
+ if o == "static":
+ o_type += " " + o
+ idx_subgroup = o.find("subgroup")
+ if idx_subgroup != -1:
+ subgroup = o[idx_subgroup + 9:]
+ if len(curr_variable) > 0:
+ curr_variable.append(subgroup)
+ curr_variable.append(o_type)
+ if len(curr_variable) > 0:
+ if name in modbus_list:
+ curr_variable += modbus_dict[name]
+ else:
+ curr_variable += ["", "", ""]
+
+ if curr_variable != []:
+ variables.append(curr_variable)
+
+ with open(export, "wb") as f:
+ writer = csv.writer(f)
+ writer.writerows(variables)
+ parent.Controler.logger.write(_("Export completed successfully.\n"))
\ No newline at end of file