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

Fixes for Python3

parent 2e49b361
......@@ -159,8 +159,8 @@ def parse_asn1(*files, **options):
stg_qrc.open(1)
content = stg_qrc.readAll()
stgfile = outdir + os.sep + 'pretty_print_asn1.stg'
with open(stgfile, 'w') as tmpfile:
tmpfile.write(content.data().encode('utf-8'))
with open(stgfile, 'wb') as tmpfile:
tmpfile.write(content.data())
html = ['-customIcdUper', stgfile + '::' + html_filepath]
else:
html = []
......
......@@ -366,7 +366,7 @@ class Signalroute(Connection):
def update_completion_list(self, pr_text):
''' Called after text has been edited '''
from sdlSymbols import CONTEXT
from .sdlSymbols import CONTEXT
ast, _, _, _, _ = self.parser.parseSingleElement('signalroute',
pr_text)
# ast is a dict:
......
......@@ -51,6 +51,7 @@
__all__ = ['Symbol', 'VerticalSymbol', 'HorizontalSymbol', 'Comment']
import os
import logging
import traceback
from PySide2.QtCore import *
from PySide2.QtGui import *
......@@ -325,7 +326,9 @@ class Symbol(QObject, QGraphicsPathItem):
# in addition to the error from ANTLR, in order to be very clear
# about the line number and character position to fix the error
# => TODO
except (AssertionError, AttributeError):
except (AssertionError, AttributeError) as err:
LOG.debug(self.common_name + " - error parsing - " + str(err))
LOG.debug(str(traceback.format_exc()))
LOG.error('Checker failed - no parser for this construct?')
else:
return syntax_errors
......@@ -492,11 +495,23 @@ class Symbol(QObject, QGraphicsPathItem):
def resize_item(self, rect):
''' resize item, e.g. when editing text - move children accordingly '''
# Call stack:
# scene_refresh() => Text_Interaction.try_resize() => resize_item()
LOG.debug("resize item")
#LOG.debug(traceback.print_stack())
if not self.resizeable:
return
delta_x = (self.boundingRect().width() - rect.width()) / 2.0
delta_y = self.boundingRect().height() - rect.height()
self.set_shape(rect.width(), rect.height())
# Qt5 behaves differently from Qt4 (most likely a bug in Qt5)
# when setting the shape, the bounnding rect of the parent is not set
# to the same value as the bounding rect of the shape! The value
# is increased by 1 for some reason.. To compensate we have to
# decrease by 1 the width and height here.
# It is likely that if this bug is fixed at some point (in Qt5 or
# PySide2), the effect will be that the symbols will SHRINK in size
# when user clicks on the scene or edits the text...
self.set_shape(rect.width()-1, rect.height()-1)
# Align children properly when resizing
try:
self.text.set_textbox_position()
......@@ -531,7 +546,8 @@ class Symbol(QObject, QGraphicsPathItem):
def set_shape(self, width, height):
''' to be implemented per symbol in subclasses '''
_, ___ = width, height
#LOG.debug("generic set_shape")
_, _ = width, height
self.prepareGeometryChange()
self.updateConnectionPoints()
# Update grabber size to fit the new shape size
......
......@@ -727,7 +727,7 @@ def check_call(name, params, context):
# unsigned .. A cast is necessary if the parameter of abs is negative
Min = float(param_btys[0].Min)
Max = float(param_btys[0].Max)
if p.exprType.kind != 'ReferenceType' and Min == Max:
if params[0].exprType.kind != 'ReferenceType' and Min == Max:
# if param is a raw number, return a positive range
# otherwise return the same type as the variable
return type('Universal_Integer', (param_btys[0],), {
......@@ -2065,7 +2065,7 @@ def call_expression(root, context, pos="right"):
ident = variable.children[0].text.lower()
proc_list = [proc.inputString.lower()
for proc in context.procedures]
if ident in (SPECIAL_OPERATORS.keys() + proc_list):
if ident in (list(SPECIAL_OPERATORS.keys()) + proc_list):
return primary_call(root, context)
# not a call to a special operator or procedure
......@@ -5338,6 +5338,9 @@ def parser_init(filename=None, string=None):
lex = lexer.sdl92Lexer(char_stream)
tokens = antlr3.CommonTokenStream(lex)
parser = sdl92Parser(tokens)
# bug in the antlr3.5 runtime for python3 - attribute "error_list"
# is missing - we have to add it manually here
parser.error_list=[]
return parser
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0302
......
......@@ -1077,6 +1077,7 @@ class Process(HorizontalSymbol):
def set_shape(self, width, height):
''' Compute the polygon to fit in width, height '''
#LOG.debug ("process set_shape " + str(width) + " " + str(height))
path = QPainterPath()
path.moveTo(7, 0)
path.lineTo(0, 7)
......
Markdown is supported
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