Beremiz.py
changeset 13 f1f0edbeb313
parent 12 a1f9e514f708
child 17 ee8cb104dbe0
equal deleted inserted replaced
12:a1f9e514f708 13:f1f0edbeb313
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
       
    25 __version__ = "$Revision$"
       
    26 
    25 import wx
    27 import wx
    26 
    28 
    27 from time import localtime
    29 from time import localtime
    28 from datetime import datetime
    30 from datetime import datetime
    29 
    31 
    38 
    40 
    39 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
    41 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
    40 from TextViewer import TextViewer
    42 from TextViewer import TextViewer
    41 from plcopen.structures import IEC_KEYWORDS#, AddPlugin
    43 from plcopen.structures import IEC_KEYWORDS#, AddPlugin
    42 from PLCControler import PLCControler
    44 from PLCControler import PLCControler
    43 
       
    44 import plugins
       
    45 
       
    46 __version__ = "$Revision$"
       
    47 
       
    48 def create(parent):
       
    49     return Beremiz(parent)
       
    50 
       
    51 def usage():
       
    52     print "\nUsage of Beremiz.py :"
       
    53     print "\n   %s [Projectpath]\n"%sys.argv[0]
       
    54 
       
    55 try:
       
    56     opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
       
    57 except getopt.GetoptError:
       
    58     # print help information and exit:
       
    59     usage()
       
    60     sys.exit(2)
       
    61 
       
    62 for o, a in opts:
       
    63     if o in ("-h", "--help"):
       
    64         usage()
       
    65         sys.exit()
       
    66 
       
    67 projectOpen = None
       
    68 if len(args) > 1:
       
    69     usage()
       
    70     sys.exit()
       
    71 elif len(args) == 1:
       
    72     projectOpen = args[0]
       
    73 CWD = sys.path[0]
       
    74 
       
    75 re_texts = {}
       
    76 re_texts["letter"] = "[A-Za-z]"
       
    77 re_texts["digit"] = "[0-9]"
       
    78 LOCATED_MODEL = re.compile("__LOCATED_VAR\(([A-Z]*),([_A-Za-z0-9]*)\)")
       
    79 
       
    80 
    45 
    81 class LogPseudoFile:
    46 class LogPseudoFile:
    82     """ Base class for file like objects to facilitate StdOut for the Shell."""
    47     """ Base class for file like objects to facilitate StdOut for the Shell."""
    83     def __init__(self, output = None):
    48     def __init__(self, output = None):
    84         self.red_white = wx.TextAttr("RED", "WHITE")
    49         self.red_white = wx.TextAttr("RED", "WHITE")
   326               size=wx.Size(48, 48), style=0)
   291               size=wx.Size(48, 48), style=0)
   327         self.DeleteBusButton.Bind(wx.EVT_BUTTON, self.OnDeleteBusButton,
   292         self.DeleteBusButton.Bind(wx.EVT_BUTTON, self.OnDeleteBusButton,
   328               id=ID_BEREMIZDELETEBUSBUTTON)
   293               id=ID_BEREMIZDELETEBUSBUTTON)
   329         
   294         
   330         self._init_sizers()
   295         self._init_sizers()
   331     
   296 
   332     def __init__(self, parent):
   297     def __init__(self, parent, projectOpen):
   333         self._init_ctrls(parent)
   298         self._init_ctrls(parent)
   334         
   299         
   335         for name in plugins.__all__:
   300         for name in plugins.__all__:
   336             module = getattr(plugins, name)
   301             module = getattr(plugins, name)
   337             
   302             
   678                 break
   643                 break
   679         err = child.wait()
   644         err = child.wait()
   680         return (err, outdata, errdata)
   645         return (err, outdata, errdata)
   681 
   646 
   682     def BuildAutom(self):
   647     def BuildAutom(self):
       
   648         LOCATED_MODEL = re.compile("__LOCATED_VAR\(([A-Z]*),([_A-Za-z0-9]*)\)")
       
   649 
   683         if self.PLCManager:
   650         if self.PLCManager:
   684             self.TargetDir = os.path.join(self.CurrentProjectPath, "build")
   651             self.TargetDir = os.path.join(self.CurrentProjectPath, "build")
   685             if not os.path.exists(self.TargetDir):
   652             if not os.path.exists(self.TargetDir):
   686                 os.mkdir(self.TargetDir)
   653                 os.mkdir(self.TargetDir)
   687             self.Log.flush()
   654             self.Log.flush()
   708                 self.Log.write("Extracting Located Variables...\n")
   675                 self.Log.write("Extracting Located Variables...\n")
   709                 location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h"))
   676                 location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h"))
   710                 locations = []
   677                 locations = []
   711                 lines = [line.strip() for line in location_file.readlines()]
   678                 lines = [line.strip() for line in location_file.readlines()]
   712                 for line in lines:
   679                 for line in lines:
   713                     result = LOCATED_MODEL.match(line)
   680                     result = self.LOCATED_MODEL.match(line)
   714                     if result:
   681                     if result:
   715                         locations.append(result.groups())
   682                         locations.append(result.groups())
   716                 self.Log.write("Generating Network Configurations...\n")
   683                 self.Log.write("Generating Network Configurations...\n")
   717                 for bus_id, bus_infos in self.BusManagers.items():
   684                 for bus_id, bus_infos in self.BusManagers.items():
   718                    if bus_infos["Manager"]:
   685                    if bus_infos["Manager"]:
   977 
   944 
   978     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
   945     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
   979     sys.excepthook = handle_exception
   946     sys.excepthook = handle_exception
   980 
   947 
   981 if __name__ == '__main__':
   948 if __name__ == '__main__':
       
   949     def usage():
       
   950         print "\nUsage of Beremiz.py :"
       
   951         print "\n   %s [Projectpath]\n"%sys.argv[0]
       
   952     
       
   953     try:
       
   954         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
       
   955     except getopt.GetoptError:
       
   956         # print help information and exit:
       
   957         usage()
       
   958         sys.exit(2)
       
   959     
       
   960     for o, a in opts:
       
   961         if o in ("-h", "--help"):
       
   962             usage()
       
   963             sys.exit()
       
   964     
       
   965     if len(args) > 1:
       
   966         usage()
       
   967         sys.exit()
       
   968     elif len(args) == 1:
       
   969         projectOpen = args[0]
       
   970     else:
       
   971         projectOpen = None
       
   972     
   982     app = wx.PySimpleApp()
   973     app = wx.PySimpleApp()
   983     wx.InitAllImageHandlers()
   974     wx.InitAllImageHandlers()
   984     
   975     
   985     # Install a exception handle for bug reports
   976     # Install a exception handle for bug reports
   986     AddExceptHook(os.getcwd(),__version__)
   977     AddExceptHook(os.getcwd(),__version__)
   987     
   978     
   988     frame = Beremiz(None)
   979     frame = Beremiz(None, projectOpen)
   989 
   980 
   990     frame.Show()
   981     frame.Show()
   991     app.MainLoop()
   982     app.MainLoop()