# HG changeset patch # User lbessard # Date 1187881622 -7200 # Node ID 8f7725451453af75d5fcbae8954405386713c905 # Parent 4f3364846782a1f72def1cc0a552c417ce21620d Some bugs fixed: - Using __file__ instead of sys.path[0] for extracting CWD - EDS generation errors (reported by Robert McCullough) diff -r 4f3364846782 -r 8f7725451453 objdictgen/commondialogs.py --- a/objdictgen/commondialogs.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/commondialogs.py Thu Aug 23 17:07:02 2007 +0200 @@ -25,6 +25,8 @@ import os +ScriptDirectory = os.path.split(__file__)[0] + #------------------------------------------------------------------------------- # Editing Communication Dialog #------------------------------------------------------------------------------- @@ -979,7 +981,7 @@ self._init_sizers() - def __init__(self, parent, cwd): + def __init__(self, parent): self._init_ctrls(parent) self.NodeID.SetValue("0x00") @@ -989,7 +991,7 @@ self.Description.SetValue("") self.ListProfile = {"None" : ""} self.Profile.Append("None") - self.Directory = os.path.join(cwd, "config") + self.Directory = os.path.join(ScriptDirectory, "config") listfiles = os.listdir(self.Directory) listfiles.sort() for item in listfiles: diff -r 4f3364846782 -r 8f7725451453 objdictgen/eds_utils.py --- a/objdictgen/eds_utils.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/eds_utils.py Thu Aug 23 17:07:02 2007 +0200 @@ -420,7 +420,10 @@ # Generate FileInfo section fileContent = "[FileInfo]\n" - fileContent += "CreatedBy=CANFestival\n" + fileContent += "FileName=%s\n"%os.path.split(filepath)[-1] + fileContent += "FileVersion=1\n" + fileContent += "FileRevision=1\n" + fileContent += "EDSVersion=4.0\n" fileContent += "Description=%s\n"%description fileContent += "CreationTime=%s"%strftime("%I:%M", current_time) # %p option of strftime seems not working, then generate AM/PM by hands @@ -429,10 +432,15 @@ else: fileContent += "PM\n" fileContent += "CreationDate=%s\n"%strftime("%m-%d-%Y", current_time) - fileContent += "FileName=%s\n"%os.path.split(filepath)[-1] - fileContent += "FileVersion=1\n" - fileContent += "FileRevision=1\n" - fileContent += "EDSVersion=3.0\n" + fileContent += "CreatedBy=CANFestival\n" + fileContent += "ModificationTime=%s"%strftime("%I:%M", current_time) + # %p option of strftime seems not working, then generate AM/PM by hands + if strftime("%I", current_time) == strftime("%H", current_time): + fileContent += "AM\n" + else: + fileContent += "PM\n" + fileContent += "ModificationDate=%s\n"%strftime("%m-%d-%Y", current_time) + fileContent += "ModifiedBy=CANFestival\n" # Generate DeviceInfo section fileContent += "\n[DeviceInfo]\n" @@ -556,7 +564,7 @@ fileContent += "\n[MandatoryObjects]\n" fileContent += "SupportedObjects=%d\n"%len(mandatories) for idx, entry in enumerate(mandatories): - fileContent += "%d=0x%4.4X\n"%(idx, entry) + fileContent += "%d=0x%4.4X\n"%(idx + 1, entry) # Write mandatory entries for entry in mandatories: fileContent += indexContents[entry] @@ -565,7 +573,7 @@ fileContent += "\n[OptionalObjects]\n" fileContent += "SupportedObjects=%d\n"%len(optionals) for idx, entry in enumerate(optionals): - fileContent += "%d=0x%4.4X\n"%(idx, entry) + fileContent += "%d=0x%4.4X\n"%(idx + 1, entry) # Write optional entries for entry in optionals: fileContent += indexContents[entry] @@ -574,7 +582,7 @@ fileContent += "\n[ManufacturerObjects]\n" fileContent += "SupportedObjects=%d\n"%len(manufacturers) for idx, entry in enumerate(manufacturers): - fileContent += "%d=0x%4.4X\n"%(idx, entry) + fileContent += "%d=0x%4.4X\n"%(idx + 1, entry) # Write manufacturer entries for entry in manufacturers: fileContent += indexContents[entry] @@ -614,7 +622,7 @@ return fileContent # Function that generates Node from an EDS file -def GenerateNode(filepath, cwd, nodeID = 0): +def GenerateNode(filepath, nodeID = 0): global Node # Create a new node Node = node.Node(id = nodeID) @@ -627,7 +635,7 @@ if ProfileNb not in [301, 302]: # Compile Profile name and path to .prf file ProfileName = "DS-%d"%ProfileNb - ProfilePath = os.path.join(cwd, "config/%s.prf"%ProfileName) + ProfilePath = os.path.join(os.path.split(__file__)[0], "config/%s.prf"%ProfileName) # Verify that profile is available if os.path.isfile(ProfilePath): try: diff -r 4f3364846782 -r 8f7725451453 objdictgen/networkedit.py --- a/objdictgen/networkedit.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/networkedit.py Thu Aug 23 17:07:02 2007 +0200 @@ -61,10 +61,7 @@ else: usage() sys.exit(2) -ScriptDirectory = "" -for path in sys.path: - if os.path.isfile(os.path.join(path, "networkedit.py")): - ScriptDirectory = path +ScriptDirectory = os.path.split(__file__)[0] try: import wx.html @@ -169,8 +166,6 @@ class networkedit(wx.Frame): def _init_coll_menuBar1_Menus(self, parent): - # generated method, don't edit - if self.ModeSolo: parent.Append(menu=self.FileMenu, title='File') parent.Append(menu=self.NetworkMenu, title='Network') @@ -179,8 +174,6 @@ parent.Append(menu=self.HelpMenu, title='Help') def _init_coll_EditMenu_Items(self, parent): - # generated method, don't edit - parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS4, kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') parent.AppendSeparator() @@ -213,8 +206,6 @@ id=ID_NETWORKEDITEDITMENUITEMS8) def _init_coll_HelpMenu_Items(self, parent): - # generated method, don't edit - parent.Append(help='', id=ID_NETWORKEDITHELPMENUITEMS0, kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, @@ -230,8 +221,6 @@ id=ID_NETWORKEDITHELPMENUITEMS2) def _init_coll_FileMenu_Items(self, parent): - # generated method, don't edit - parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS5, kind=wx.ITEM_NORMAL, text='New\tCTRL+N') parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS0, @@ -255,8 +244,6 @@ id=ID_NETWORKEDITFILEMENUITEMS5) def _init_coll_NetworkMenu_Items(self, parent): - # generated method, don't edit - parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUITEMS0, kind=wx.ITEM_NORMAL, text='Add Slave Node') parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUITEMS1, @@ -272,8 +259,6 @@ ## id=ID_NETWORKEDITNETWORKMENUITEMS3) def _init_coll_AddMenu_Items(self, parent): - # generated method, don't edit - parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS0, kind=wx.ITEM_NORMAL, text='SDO Server') parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS1, @@ -300,7 +285,6 @@ id=ID_NETWORKEDITADDMENUITEMS5) def _init_coll_HelpBar_Fields(self, parent): - # generated method, don't edit parent.SetFieldsCount(3) parent.SetStatusText(number=0, text='') @@ -310,7 +294,6 @@ parent.SetStatusWidths([100, 110, -1]) def _init_utils(self): - # generated method, don't edit self.menuBar1 = wx.MenuBar() self.menuBar1.SetEvtHandlerEnabled(True) @@ -330,7 +313,6 @@ self._init_coll_HelpMenu_Items(self.HelpMenu) def _init_ctrls(self, prnt): - # generated method, don't edit wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit', parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), style=wx.DEFAULT_FRAME_STYLE, title='Networkedit') @@ -358,7 +340,7 @@ self.BusId = None if self.ModeSolo: - self.Manager = NodeManager(ScriptDirectory) + self.Manager = NodeManager() if projectOpen: self.NodeList = NodeList(self.Manager) result = self.NodeList.LoadProject(projectOpen) @@ -460,7 +442,7 @@ projectpath = dialog.GetPath() if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: os.mkdir(os.path.join(projectpath, "eds")) - manager = NodeManager(ScriptDirectory) + manager = NodeManager() nodelist = NodeList(manager) result = nodelist.LoadProject(projectpath) if not result: @@ -488,7 +470,7 @@ if dialog.ShowModal() == wx.ID_OK: projectpath = dialog.GetPath() if os.path.isdir(projectpath): - manager = NodeManager(ScriptDirectory) + manager = NodeManager() nodelist = NodeList(manager) result = nodelist.LoadProject(projectpath) if not result: diff -r 4f3364846782 -r 8f7725451453 objdictgen/node.py --- a/objdictgen/node.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/node.py Thu Aug 23 17:07:02 2007 +0200 @@ -107,7 +107,7 @@ 0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "values" : [{"name" : "Number of Errors", "type" : 0x05, "access" : 'rw', "pdo" : False}, {"name" : "Standard Error Field", "type" : 0x07, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]}, - 0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : True, "callback" : True, "values" : + 0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : False, "callback" : True, "values" : [{"name" : "SYNC COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, 0x1006 : {"name" : "Communication / Cycle Period", "struct" : var, "need" : False, "callback" : True, "values" : [{"name" : "Communication Cycle Period", "type" : 0x07, "access" : 'rw', "pdo" : False}]}, diff -r 4f3364846782 -r 8f7725451453 objdictgen/nodelist.py --- a/objdictgen/nodelist.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/nodelist.py Thu Aug 23 17:07:02 2007 +0200 @@ -37,6 +37,7 @@ def __init__(self, manager, netname = ""): self.Root = "" + self.EDSFolder = "" self.Manager = manager self.NetworkName = netname self.SlaveNodes = {} @@ -131,7 +132,7 @@ def LoadEDS(self, eds): edspath = os.path.join(self.EDSFolder, eds) - node = eds_utils.GenerateNode(edspath, self.Manager.ScriptDirectory) + node = eds_utils.GenerateNode(edspath) if isinstance(node, Node): self.EDSNodes[eds] = node return None diff -r 4f3364846782 -r 8f7725451453 objdictgen/nodemanager.py --- a/objdictgen/nodemanager.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/nodemanager.py Thu Aug 23 17:07:02 2007 +0200 @@ -150,13 +150,12 @@ """ Constructor """ - def __init__(self, cwd): + def __init__(self): self.LastNewIndex = 0 self.FilePaths = {} self.FileNames = {} self.NodeIndex = None self.CurrentNode = None - self.ScriptDirectory = cwd self.UndoBuffers = {} #------------------------------------------------------------------------------- @@ -207,7 +206,7 @@ AddIndexList.append(0x1017) for option in options: if option == "DS302": - DS302Path = os.path.join(self.ScriptDirectory, "config/DS-302.prf") + DS302Path = os.path.join(os.path.split(__file__)[0], "config/DS-302.prf") # Charging DS-302 profile if choosen by user if os.path.isfile(DS302Path): try: @@ -303,7 +302,7 @@ """ def ImportCurrentFromEDSFile(self, filepath): # Generate node from definition in a xml file - result = eds_utils.GenerateNode(filepath, self.ScriptDirectory) + result = eds_utils.GenerateNode(filepath) if isinstance(result, Node): self.CurrentNode = result index = self.AddNodeBuffer(self.CurrentNode.Copy(), False) diff -r 4f3364846782 -r 8f7725451453 objdictgen/objdictedit.py --- a/objdictgen/objdictedit.py Wed Aug 08 18:40:47 2007 +0200 +++ b/objdictgen/objdictedit.py Thu Aug 23 17:07:02 2007 +0200 @@ -125,7 +125,7 @@ sys.exit() filesOpen = args -ScriptDirectory = sys.path[0] +ScriptDirectory = os.path.split(__file__)[0] [ID_OBJDICTEDIT, ID_OBJDICTEDITFILEOPENED, @@ -323,7 +323,7 @@ self.HtmlFrameOpened = [] self.ModeSolo = True - self.Manager = NodeManager(ScriptDirectory) + self.Manager = NodeManager() for filepath in filesOpen: result = self.Manager.OpenFileInCurrent(filepath) if type(result) == IntType: @@ -334,7 +334,7 @@ if window: self.Manager.ChangeCurrentNode(window.GetIndex()) self.FileOpened.SetSelection(0) - if self.Manager.CurrentDS302Defined(): + if self.Manager.CurrentDS302Defined(): self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) else: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) @@ -522,7 +522,7 @@ self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, True) self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, True) else: - self.menuBar1.EnableTop(1, False) + self.menuBar1.EnableTop(1, False) self.menuBar1.EnableTop(2, False) self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, False) self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, False) @@ -592,7 +592,7 @@ def OnNewMenu(self, event): self.FilePath = "" - dialog = CreateNodeDialog(self, ScriptDirectory) + dialog = CreateNodeDialog(self) if dialog.ShowModal() == wx.ID_OK: name, id, nodetype, description = dialog.GetValues() profile, filepath = dialog.GetProfile()