# HG changeset patch # User laurent # Date 1249662470 -7200 # Node ID a76ee5307bb75a189c309aaebc1e1c2da639f602 # Parent cd90e4c1026125c5804dd79369c2c3a500c655cf Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade Updating linux wxglade example according to this new plugin design diff -r cd90e4c10261 -r a76ee5307bb7 plugins/python/modules/wxglade_hmi/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/python/modules/wxglade_hmi/README Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,1 @@ +WxGlade HMI \ No newline at end of file diff -r cd90e4c10261 -r a76ee5307bb7 plugins/python/modules/wxglade_hmi/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/python/modules/wxglade_hmi/__init__.py Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,1 @@ +from wxglade_hmi import * diff -r cd90e4c10261 -r a76ee5307bb7 plugins/python/modules/wxglade_hmi/wxglade_hmi.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/python/modules/wxglade_hmi/wxglade_hmi.py Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,113 @@ +import wx +import os, sys +from xml.dom import minidom + +from plugger import opjimg +from plugins.python import PythonCodeTemplate + +class RootClass(PythonCodeTemplate): + + PluginMethods = [ + {"bitmap" : opjimg("editWXGLADE"), + "name" : _("WXGLADE GUI"), + "tooltip" : _("Edit a WxWidgets GUI with WXGlade"), + "method" : "_editWXGLADE"}, + ] + + def _getWXGLADEpath(self): + # define name for IEC raw code file + return os.path.join(self.PlugPath(), "hmi.wxg") + + def launch_wxglade(self, options, wait=False): + from wxglade import __file__ as fileName + path = os.path.dirname(fileName) + glade = os.path.join(path, 'wxglade.py') + if wx.Platform == '__WXMSW__': + glade = "\"%s\""%glade + mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait] + os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options) + + + def PlugGenerate_C(self, buildpath, locations): + """ + Return C code generated by iec2c compiler + when _generate_softPLC have been called + @param locations: ignored + @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND + """ + + current_location = self.GetCurrentLocation() + # define a unique name for the generated C file + location_str = "_".join(map(lambda x:str(x), current_location)) + + runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) + runtimefile = open(runtimefile_path, 'w') + + hmi_frames = {} + + wxgfile_path=self._getWXGLADEpath() + if os.path.exists(wxgfile_path): + wxgfile = open(wxgfile_path, 'r') + wxgtree = minidom.parse(wxgfile) + wxgfile.close() + + for node in wxgtree.childNodes[1].childNodes: + if node.nodeType == wxgtree.ELEMENT_NODE: + hmi_frames[node._attrs["name"].value] = node._attrs["class"].value + + hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py") + if wx.Platform == '__WXMSW__': + wxgfile_path = "\"%s\""%wxgfile_path + hmipyfile_path = "\"%s\""%hmipyfile_path + self.launch_wxglade(['-o', hmipyfile_path, '-g', 'python', wxgfile_path], wait=True) + + hmipyfile = open(hmipyfile_path, 'r') + runtimefile.write(hmipyfile.read()) + hmipyfile.close() + + runtimefile.write(self.GetPythonCode()) + runtimefile.write(""" +%(declare)s + +def _runtime_%(location)s_begin(): + global %(global)s + + def OnCloseFrame(evt): + wx.MessageBox(_("Please stop PLC to close")) + + %(init)s + +def _runtime_%(location)s_cleanup(): + global %(global)s + + %(cleanup)s + +""" % {"location": location_str, + "declare": "\n".join(map(lambda x:"%s = None" % x, hmi_frames.keys())), + "global": ",".join(hmi_frames.keys()), + "init": "\n".join(map(lambda x: """ + %(name)s = %(class)s(None) + %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) + %(name)s.Show() +""" % {"name": x[0], "class": x[1]}, + hmi_frames.items())), + "cleanup": "\n ".join(map(lambda x:"%s.Destroy()" % x, hmi_frames.keys()))}) + runtimefile.close() + + return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) + + def _editWXGLADE(self): + wxg_filename = self._getWXGLADEpath() + if not os.path.exists(wxg_filename): + hmi_name = self.BaseParams.getName() + open(wxg_filename,"w").write(""" + + + + frame_1 + + +""" % {"name": hmi_name, "class": "Class_%s" % hmi_name}) + if wx.Platform == '__WXMSW__': + wxg_filename = "\"%s\""%wxg_filename + self.launch_wxglade([wxg_filename]) diff -r cd90e4c10261 -r a76ee5307bb7 plugins/python/python.py --- a/plugins/python/python.py Wed Jul 29 15:17:10 2009 +0200 +++ b/plugins/python/python.py Fri Aug 07 18:27:50 2009 +0200 @@ -244,7 +244,7 @@ plc_python_code = plc_python_file.read() plc_python_file.close() python_eval_fb_list = [] - for v in plugin_root._VariablesList : + for v in plugin_root._VariablesList: if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL","PYTHON_POLL"]: python_eval_fb_list.append(v) python_eval_fb_count = max(1, len(python_eval_fb_list)) @@ -262,14 +262,6 @@ runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) runtimefile = open(runtimefile_path, 'w') runtimefile.write(self.GetPythonCode()) - runtimefile.write(""" -def _runtime_%(location)s_begin(): - print "runtime_begin" - -def _runtime_%(location)s_cleanup(): - print "runtime_cleanup" - -""" % {"location": location_str}) runtimefile.close() if wx.Platform == '__WXMSW__': diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/plc.xml --- a/tests/linux/wxGlade/plc.xml Wed Jul 29 15:17:10 2009 +0200 +++ b/tests/linux/wxGlade/plc.xml Fri Aug 07 18:27:50 2009 +0200 @@ -6,9 +6,9 @@ + creationDateTime="2008-12-14T16:21:19"/> + modificationDateTime="2009-08-07T18:17:20"> @@ -104,10 +104,10 @@ ')' - + - + 'HMIFrame.spin_ctrl_1.SetValue(' @@ -221,9 +221,9 @@ - - - + + + @@ -421,8 +421,8 @@ - - + + diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/baseplugin.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/baseplugin.xml Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,2 @@ + + diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/hmi.wxg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/hmi.wxg Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,34 @@ + + + + + + + HMIFrame + + wxVERTICAL + + 0 + + + 0, 10000 + + + + 0 + + + + + + + 0 + + + 1 + + + + + + diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/python.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/linux/wxGlade/python@python/HMIFrame@wxglade_hmi/python.xml Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,4 @@ + + + + diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/python@python/baseplugin.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/linux/wxGlade/python@python/baseplugin.xml Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,2 @@ + + diff -r cd90e4c10261 -r a76ee5307bb7 tests/linux/wxGlade/python@python/python.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/linux/wxGlade/python@python/python.xml Fri Aug 07 18:27:50 2009 +0200 @@ -0,0 +1,8 @@ + + + +