wxglade_hmi/wxglade_hmi.py
changeset 1061 02f371f3e063
parent 1014 e2f7d6c95db0
child 1062 fd7c9a7cf882
equal deleted inserted replaced
1060:ac9896336b90 1061:02f371f3e063
     1 import wx
     1 import wx
     2 import os, sys
     2 import os, sys, shutil
     3 from xml.dom import minidom
     3 from xml.dom import minidom
     4 
     4 
     5 from py_ext import PythonFileCTNMixin
     5 from py_ext import PythonFileCTNMixin
     6 
     6 
     7 class WxGladeHMI(PythonFileCTNMixin):
     7 class WxGladeHMI(PythonFileCTNMixin):
    14     ]
    14     ]
    15 
    15 
    16     def ConfNodePath(self):
    16     def ConfNodePath(self):
    17         return os.path.join(os.path.dirname(__file__))
    17         return os.path.join(os.path.dirname(__file__))
    18 
    18 
    19     def _getWXGLADEpath(self):
    19     def _getWXGLADEpath(self, project_path=None):
    20         # define name for IEC raw code file
    20         if project_path is None:
    21         return os.path.join(self.CTNPath(), "hmi.wxg")
    21             project_path = self.CTNPath()
       
    22         # define name for wxGlade gui file
       
    23         return os.path.join(project_path, "hmi.wxg")
    22 
    24 
    23     def launch_wxglade(self, options, wait=False):
    25     def launch_wxglade(self, options, wait=False):
    24         from wxglade import __file__ as fileName
    26         from wxglade import __file__ as fileName
    25         path = os.path.dirname(fileName)
    27         path = os.path.dirname(fileName)
    26         glade = os.path.join(path, 'wxglade.py')
    28         glade = os.path.join(path, 'wxglade.py')
    27         if wx.Platform == '__WXMSW__':
    29         if wx.Platform == '__WXMSW__':
    28             glade = "\"%s\""%glade
    30             glade = "\"%s\""%glade
    29         mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
    31         mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
    30         os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options)
    32         os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options)
    31 
    33 
       
    34     def OnCTNSave(self, from_project_path=None):
       
    35         if from_project_path is not None:
       
    36             shutil.copyfile(self._getWXGLADEpath(from_project_path),
       
    37                             self._getWXGLADEpath())
       
    38         return PythonFileCTNMixin.OnCTNSave(self, from_project_path)
    32 
    39 
    33     def CTNGenerate_C(self, buildpath, locations):
    40     def CTNGenerate_C(self, buildpath, locations):
    34         """
    41         """
    35         Return C code generated by iec2c compiler 
    42         Return C code generated by iec2c compiler 
    36         when _generate_softPLC have been called
    43         when _generate_softPLC have been called
   126     </application>
   133     </application>
   127     """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
   134     """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
   128             if wx.Platform == '__WXMSW__':
   135             if wx.Platform == '__WXMSW__':
   129                 wxg_filename = "\"%s\""%wxg_filename
   136                 wxg_filename = "\"%s\""%wxg_filename
   130             self.launch_wxglade([wxg_filename])
   137             self.launch_wxglade([wxg_filename])
       
   138