1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# -*- coding: utf-8 -*-
#
# AWL simulator - GUI utility functions
#
# Copyright 2012-2014 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.core.compat import *
import sys
from awlsim.core import *
from awlsim.coreserver import *
import awlsim.cython_helper
if isPyPy or isJython:
# PySide does not work on PyPy or Jython, yet.
printError("Running awlsimgui on the PyPy or Jython interpreter is not supported.")
printError("Please use CPython 2.7 or CPython 3.x")
sys.exit(1)
if awlsim.cython_helper.shouldUseCython():
print("*** Using accelerated CYTHON core "
"(AWLSIMCYTHON environment variable is set)")
try:
from PySide.QtCore import *
from PySide.QtGui import *
except ImportError as e:
printError("PLEASE INSTALL PySide (http://www.pyside.org/)")
input("Press enter to continue.")
sys.exit(1)
import os
import traceback
def handleFatalException(parentWidget=None):
QMessageBox.critical(parentWidget,
"A fatal exception occurred",
"A fatal exception occurred:\n\n"
"%s\n\n"
"Awlsim will be terminated." %\
(traceback.format_exc(),))
sys.exit(1)
class MessageBox(QMessageBox):
def __init__(self, parent, title, text, details=None):
QMessageBox.__init__(self, parent)
self.setWindowTitle(title)
self.setText(text)
self.setIcon(QMessageBox.Critical)
if details:
self.setDetailedText(details)
@classmethod
def error(cls, parent, text, details=None):
return cls(parent, "Awlsim - simulator error",
text, details).exec_()
@classmethod
def handleAwlSimError(cls, parent, description, exception):
cpu = exception.getCpu()
text = "A simulator exception occurred:"
if description:
text += "\n"
text += " " + description + "."
text += "\n\n"
text += " " + str(exception)
text += "\n\n"
insnStr = exception.getFailingInsnStr()
if insnStr:
text += " At statement:\n"
text += " AWL/STL line %s: %s" % (exception.getLineNrStr(),
insnStr)
else:
text += " At AWL/STL line %s" % exception.getLineNrStr()
details = None
if cpu:
details = str(exception) + "\n\n" + str(cpu)
return cls.error(parent, text, details)
@classmethod
def handleAwlParserError(cls, parent, exception):
return cls.handleAwlSimError(parent = parent,
description = None,
exception = exception)
|