Skip to content

Commit

Permalink
Issue #45 open XML file menu entry
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricp committed Mar 29, 2018
1 parent 9f0f609 commit a57068a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
11 changes: 8 additions & 3 deletions ddt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,15 @@ def __init__(self, parent = None):
menu = self.menuBar()

diagmenu = menu.addMenu(_("File"))
xmlopenaction = diagmenu.addAction("Open XML")
newecuction = diagmenu.addAction(_("Create New ECU"))
saveecuaction = diagmenu.addAction(_("Save current ECU"))
diagmenu.addSeparator()
savevehicleaction = diagmenu.addAction(_("Save ECU list"))
savevehicleaction.triggered.connect(self.saveEcus)
saveecuaction.triggered.connect(self.saveEcu)
newecuction.triggered.connect(self.newEcu)
xmlopenaction.triggered.connect(self.openxml)
diagmenu.addSeparator()
zipdbaction = diagmenu.addAction(_("Zip database"))
zipdbaction.triggered.connect(self.zipdb)
Expand Down Expand Up @@ -719,11 +721,12 @@ def saveEcu(self):
self.eculistwidget.init()
self.eculistwidget.filterProject()

def openxml(self):
filename = unicode(gui.QFileDialog.getOpenFileName(self, "Open File", "./", "XML files (*.xml *.XML)"), encoding="UTF-8")
self.set_param_file(filename, "", "", True)

def loadEcu(self, name):
vehicle_file = "vehicles/" + name + ".ecu"
# self.ecu_scan.ecus = pickle.load(open(vehicle_file, "rb"))
#

jsonfile = open(vehicle_file, "r")
eculist = json.loads(jsonfile.read())
jsonfile.close()
Expand Down Expand Up @@ -817,7 +820,9 @@ def changeECU(self, index):
if self.paramview:
if ecu_file == self.paramview.ddtfile:
return
self.set_param_file(ecu_file, ecu_addr, ecu_name, isxml)

def set_param_file(self, ecu_file, ecu_addr, ecu_name, isxml):
self.diagaction.setEnabled(True)
self.hexinput.setEnabled(True)
self.treeview_params.clear()
Expand Down
23 changes: 11 additions & 12 deletions parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def tester_send(self):

def saveEcu(self, name=None):
if not name:
filename = gui.QFileDialog.getSaveFileName(self, _("Save ECU (keep '.json' extension)"), "./json/myecu.json", "*.json")
filename = unicode(gui.QFileDialog.getSaveFileName(self, _("Save ECU (keep '.json' extension)"), "./json/myecu.json", "*.json"), encoding='UTF8')
else:
filename = name

Expand Down Expand Up @@ -109,17 +109,16 @@ def saveEcu(self, name=None):
jsfile.write(js)
jsfile.close()
else:
ecu_ident = options.ecu_scanner.ecu_database.getTargets(self.ecu_name)
ecu_ident.name = os.path.basename(filename)

js_targets = []
for ecui in ecu_ident:
js_targets.append(ecui.dump())

js = json.dumps(js_targets, indent=1)
jsfile = open(target_name, "w")
jsfile.write(js)
jsfile.close()
ecu_idents = options.ecu_scanner.ecu_database.getTargetsByHref(os.path.basename(self.ddtfile))
if len(ecu_idents):
js_targets = []
for ecui in ecu_idents:
js_targets.append(ecui.dump())

js = json.dumps(js_targets, indent=1)
jsfile = open(target_name, "w")
jsfile.write(js)
jsfile.close()

def renameCategory(self, oldname, newname):
if oldname not in self.categories:
Expand Down

0 comments on commit a57068a

Please sign in to comment.