Commit a09b255d authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fixed minor path issues when loading files

parent fb6db2bf
...@@ -3842,8 +3842,8 @@ def add_to_ast(ast, filename=None, string=None): ...@@ -3842,8 +3842,8 @@ def add_to_ast(ast, filename=None, string=None):
errors, warnings = [], [] errors, warnings = [], []
try: try:
parser = parser_init(filename=filename, string=string) parser = parser_init(filename=filename, string=string)
except IOError: except IOError as err:
LOG.error('parser_init failed') LOG.error('parser_init failed: ' + str(err))
raise raise
# Use Sam & Max output capturer to get errors from ANTLR parser # Use Sam & Max output capturer to get errors from ANTLR parser
with samnmax.capture_ouput() as (stdout, stderr): with samnmax.capture_ouput() as (stdout, stderr):
...@@ -3962,11 +3962,11 @@ def parser_init(filename=None, string=None): ...@@ -3962,11 +3962,11 @@ def parser_init(filename=None, string=None):
''' Initialize the parser (to be called first) ''' ''' Initialize the parser (to be called first) '''
try: try:
char_stream = antlr3.ANTLRFileStream(filename, encoding='utf-8') char_stream = antlr3.ANTLRFileStream(filename, encoding='utf-8')
except (IOError, TypeError): except (IOError, TypeError) as err:
try: try:
char_stream = antlr3.ANTLRStringStream(string) char_stream = antlr3.ANTLRStringStream(string)
except TypeError as err: except TypeError as err:
raise IOError('Could not parse input' + str(err)) raise IOError('Could not parse input: ' + str(err))
lex = lexer.sdl92Lexer(char_stream) lex = lexer.sdl92Lexer(char_stream)
tokens = antlr3.CommonTokenStream(lex) tokens = antlr3.CommonTokenStream(lex)
parser = sdl92Parser(tokens) parser = sdl92Parser(tokens)
......
...@@ -1048,6 +1048,7 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -1048,6 +1048,7 @@ class SDL_View(QtGui.QGraphicsView, object):
''' Main graphic view used to display the SDL scene and handle zoom ''' ''' Main graphic view used to display the SDL scene and handle zoom '''
# signal to ask the main application that a new scene is needed # signal to ask the main application that a new scene is needed
need_new_scene = QtCore.Signal() need_new_scene = QtCore.Signal()
update_asn1_dock = QtCore.Signal(ogAST.AST)
def __init__(self, scene): def __init__(self, scene):
''' Create the SDL view holding the scene ''' ''' Create the SDL view holding the scene '''
...@@ -1352,7 +1353,8 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -1352,7 +1353,8 @@ class SDL_View(QtGui.QGraphicsView, object):
LOG.warning('Files are spread in several directories - ' LOG.warning('Files are spread in several directories - '
'ASN.1 files may not be found') 'ASN.1 files may not be found')
else: else:
os.chdir(dir_pool.pop()) files = [os.path.abspath(each) for each in files]
os.chdir(dir_pool.pop() or '.')
try: try:
ast, warnings, errors = ogParser.parse_pr(files=files) ast, warnings, errors = ogParser.parse_pr(files=files)
except IOError: except IOError:
...@@ -1385,7 +1387,9 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -1385,7 +1387,9 @@ class SDL_View(QtGui.QGraphicsView, object):
self.refresh() self.refresh()
self.centerOn(self.sceneRect().topLeft()) self.centerOn(self.sceneRect().topLeft())
self.scene().undo_stack.clear() self.scene().undo_stack.clear()
return ast # Emit a signal for the application to update the ASN.1 scene
self.update_asn1_dock.emit(ast)
#return ast
def open_diagram(self): def open_diagram(self):
''' Load one or several .pr file and display the state machine ''' ''' Load one or several .pr file and display the state machine '''
...@@ -1689,6 +1693,7 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -1689,6 +1693,7 @@ class OG_MainWindow(QtGui.QMainWindow, object):
self.asn1_area = sdlSymbols.ASN1Viewer() self.asn1_area = sdlSymbols.ASN1Viewer()
self.asn1_area.text.setPlainText('-- ASN.1 Data Types') self.asn1_area.text.setPlainText('-- ASN.1 Data Types')
self.asn1_area.text.try_resize() self.asn1_area.text.try_resize()
self.view.update_asn1_dock.connect(self.set_asn1_view)
self.datatypes_scene.addItem(self.asn1_area) self.datatypes_scene.addItem(self.asn1_area)
...@@ -1709,24 +1714,46 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -1709,24 +1714,46 @@ class OG_MainWindow(QtGui.QMainWindow, object):
if file_name: if file_name:
types = [] types = []
ast = self.view.load_file(file_name) self.view.load_file(file_name)
# Update the dock widget with ASN.1 files content # # Update the dock widget with ASN.1 files content
try: # try:
for asn1file in ast.asn1_filenames: # for asn1file in ast.asn1_filenames:
with open(asn1file, 'r') as file_handler: # with open(asn1file, 'r') as file_handler:
types.append('-- ' + asn1file) # types.append('-- ' + asn1file)
types.append(file_handler.read()) # types.append(file_handler.read())
if types: # if types:
self.asn1_area.text.setPlainText('\n'.join(types)) # self.asn1_area.text.setPlainText('\n'.join(types))
# ASN.1 text area is read-only: # # ASN.1 text area is read-only:
self.asn1_area.text.setTextInteractionFlags( # self.asn1_area.text.setTextInteractionFlags(
QtCore.Qt.TextBrowserInteraction) # QtCore.Qt.TextBrowserInteraction)
self.asn1_area.text.try_resize() # self.asn1_area.text.try_resize()
#
except IOError as err: # except IOError as err:
LOG.warning('ASN.1 file(s) could not be loaded : ' + str(err)) # LOG.warning('ASN.1 file(s) could not be loaded : ' + str(err))
except AttributeError: # except AttributeError:
LOG.warning('No AST, check input files') # LOG.warning('No AST, check input files')
@QtCore.Slot(ogAST.AST)
def set_asn1_view(self, ast):
''' Display the ASN.1 types in the dedicated scene '''
# Update the dock widget with ASN.1 files content
types = []
try:
for each in ast.asn1_filenames:
with open(each, 'r') as file_handler:
types.append('-- ' + each)
types.append(file_handler.read())
if types:
self.asn1_area.text.setPlainText('\n'.join(types))
# ASN.1 text area is read-only:
self.asn1_area.text.setTextInteractionFlags(
QtCore.Qt.TextBrowserInteraction)
self.asn1_area.text.try_resize()
except IOError as err:
LOG.warning('ASN.1 file(s) could not be loaded : ' + str(err))
except AttributeError:
LOG.warning('No AST, check input files')
def vi_command(self): def vi_command(self):
''' '''
......
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