Commit 369493db authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] XML Parser; see more

- Proper way to access to the model via XML parser
- Now the parser sets the status of the model to not modified just after the load of the file
- Fix typos
parent 8fd5aa74
......@@ -683,6 +683,7 @@ class Charter(object):
return response
## Export/Import ###########################################################
## XML models
@check_curent_model
def export_to_xml(self, widget):
"""
......@@ -708,6 +709,7 @@ class Charter(object):
mfile.write(xml.return_xml())
mfile.close()
self.previously_written_folder = os.path.dirname(xml_file)
# Notify that the model is not modified anymore
model.modified = False
except Exception as e:
cancel_warn(e.message)
......@@ -726,28 +728,26 @@ class Charter(object):
"""
As it says
"""
self.import_from_xml(xml_file, ffile=True)
self.import_from_xml(xml_file, string_data=True)
self.previously_opened_folder = os.path.dirname(xml_file)
def import_from_xml(self, xml_file, ffile=False):
def import_from_xml(self, xml_data, string_data=False):
"""Open and parse an xml file or a text
:param xml_file: File of a model or a model in text form.
:param ffile: Boolean to force xml text parsing instead of file parsing.
:type xml_file: <str>
:type ffile: <boolean>
:param xml_data: File of a model or a model in text form.
:param string_data: Boolean to force xml text parsing instead of file parsing.
:type xml_data: <str>
:type string_data: <boolean>
"""
if ffile:
parsing = MakeModelFromXmlFile(xml_file)
if string_data:
parsing = MakeModelFromXmlFile(xml_data)
else:
parsing = MakeModelFromXmlString(xml_file)
parsing = MakeModelFromXmlString(xml_data)
# chart model
model = parsing.get_model()
model.modified = False
# Get chart model and add it to the current tab
model = parsing.model
self.add_edit_mvc(model.name, model)
def choose_cadlang_file(self, widget):
"""
open a window to search xml file
......
......@@ -469,8 +469,7 @@ class MakeModelFromXmlFile:
:type xml_file: <str>
:type model: <ChartModel>
"""
self.model = model
self.handler = MakeHandler(model=self.model)
self.handler = MakeHandler(model=model)
self.parser = make_parser()
self.parser.setContentHandler(self.handler)
......@@ -480,6 +479,17 @@ class MakeModelFromXmlFile:
print("ERROR while xml parsing")
raise
# The model is currently not modified in comparison to the file
self.handler.model.modified = False
@property
def model(self):
"""Return the model generated from the XML file
:rtype: <ChartModel>
"""
return self.handler.model
def get_model(self):
"""Return the model generated from the XML file
......@@ -503,6 +513,17 @@ class MakeModelFromXmlString:
print("ERROR while xml parsing")
print(exc)
# The model is currently not modified in comparison to the file
self.handler.model.modified = False
@property
def model(self):
"""Return the model generated from the XML string
:rtype: <ChartModel>
"""
return self.handler.model
def get_model(self):
"""Return the model generated from the XML string
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment