Prevent the absence of PyQt5 to stop lauching cgt.

* Change: In CRL/helpers.io, the ErrorWidget requires PyQt5 to execute but
    is not mandatory to run Coriolis/cgt. In order to be more portable,
    if it is not availble just evert to text display on the console.
      This widget will be directly supplied by Coriolis in the future
    completely removing the need for PyQt.
*Change: In cumulus/plugins/aboutwindow, same as above.
This commit is contained in:
Jean-Paul Chaput 2022-10-26 16:37:16 +02:00
parent 60c8bfe75e
commit 118b28b5a7
2 changed files with 235 additions and 204 deletions

View File

@ -19,6 +19,7 @@ import os
import os.path import os.path
import re import re
import traceback import traceback
pyQtIsEnabled = True
try: try:
from PyQt4.QtCore import Qt from PyQt4.QtCore import Qt
from PyQt4.QtGui import QSizePolicy from PyQt4.QtGui import QSizePolicy
@ -57,8 +58,8 @@ except Exception as e:
from PyQt5.QtWidgets import QAction from PyQt5.QtWidgets import QAction
from PyQt5.QtGui import QKeySequence from PyQt5.QtGui import QKeySequence
except Exception: except Exception:
print( '[ERROR] helpers.io, neither PyQt4 nor PyQt5 is available.' ) print( '[WARNING] helpers.io, neither PyQt4 nor PyQt5 is available, disabling ErrorWidget.' )
sys.exit( 1 ) pyQtIsEnabled = False
import Cfg import Cfg
import helpers import helpers
from Hurricane import UpdateSession from Hurricane import UpdateSession
@ -68,9 +69,14 @@ import Viewer
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# Class : "ErrorWidget". # Class : "ErrorWidget".
class ErrorWidget ( QDialog ): def getErrorWidget ():
if pyQtIsEnabled:
class ErrorWidget ( QDialog ):
def __init__ ( self, e ): def __init__ ( self, e ):
QWidget.__init__ ( self, None ) QWidget.__init__ ( self, None )
self.setWindowTitle( 'Error' ) self.setWindowTitle( 'Error' )
@ -152,10 +158,17 @@ class ErrorWidget ( QDialog ):
return return
def closeEvent ( self, event ): def closeEvent ( self, event ):
if not pyQtIsEnabled: return
self.setResult( QDialog.Rejected ) self.setResult( QDialog.Rejected )
event.accept() event.accept()
return return
else:
ErrorWidget = None
return ErrorWidget
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# Class : "ErrorMessage". # Class : "ErrorMessage".
@ -232,11 +245,13 @@ class ErrorMessage ( Exception ):
@staticmethod @staticmethod
def show ( code, *arguments ): def show ( code, *arguments ):
e = ErrorMessage( code, *arguments ) e = ErrorMessage( code, *arguments )
if Viewer.Graphics.get().isEnabled(): if not Viewer.Graphics.get().isEnabled():
raise e
classErrorWidget = getErrorWidget()
if not classErrorWidget:
raise e
tryCont = ErrorWidget( e ).exec_() tryCont = ErrorWidget( e ).exec_()
if not tryCont: raise e if not tryCont: raise e
else:
raise e
return return
@ -256,7 +271,9 @@ def catch ( errorObject ):
print( em ) print( em )
print( helpers.textStackTrace( em.trace, True, em.scriptPath ) ) print( helpers.textStackTrace( em.trace, True, em.scriptPath ) )
if Viewer.Graphics.get().isEnabled(): if Viewer.Graphics.get().isEnabled():
tryCont = ErrorWidget( em ).exec_() classErrorWidget = getErrorWidget()
if classErrorWidget:
tryCont = classErrorWidget( em ).exec_()
if UpdateSession.getStackSize() > 0: UpdateSession.close() if UpdateSession.getStackSize() > 0: UpdateSession.close()
return return

View File

@ -13,10 +13,10 @@
# +-----------------------------------------------------------------+ # +-----------------------------------------------------------------+
import sys
import traceback
pyQtIsEnabled = True
try: try:
import sys
import traceback
try:
from PyQt4.QtCore import Qt from PyQt4.QtCore import Qt
from PyQt4.QtCore import QEventLoop from PyQt4.QtCore import QEventLoop
from PyQt4.QtGui import QDialog from PyQt4.QtGui import QDialog
@ -30,7 +30,7 @@ try:
from PyQt4.QtGui import QAction from PyQt4.QtGui import QAction
from PyQt4.QtGui import QKeySequence from PyQt4.QtGui import QKeySequence
from PyQt4.QtGui import QApplication from PyQt4.QtGui import QApplication
except: except:
try: try:
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtCore import QEventLoop from PyQt5.QtCore import QEventLoop
@ -46,23 +46,33 @@ try:
from PyQt5.QtGui import QKeySequence from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
except: except:
print( '[ERROR] AboutWindow: Neither PyQt4 nor PyQt5 is available.' ) print( '[WARNING] AboutWindow: Neither PyQt4 nor PyQt5 is available, disabling AboutWidget.' )
sys.exit( 1 ) pyQtIsEnabled = False
import Viewer import Viewer
import helpers import helpers
from helpers.io import ErrorMessage from helpers.io import ErrorMessage
from helpers.io import WarningMessage from helpers.io import WarningMessage
import plugins import plugins
except Exception as e:
helpers.io.catch( e )
sys.exit(2)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Class : "AboutWidget". # Class : "AboutWidget".
class AboutWidget ( QDialog ): def getAboutWidget ():
aboutText = 'Coriolis CAD System 1.0 . . . . . . . . . . . . . . ccb 1.0\n' \
'Copyright (c) 2008-2022 . . . . . . . . Sorbonne Université\n' \
'Authors . . . . . . . . . . . . . . . . Christophe Alexandre\n' \
' . . . . . . . . . . . . . . . . . . Sophie Belloeil\n' \
' . . . . . . . . . . . . . . . . . . Jean-Paul Chaput\n' \
' . . . . . . . . . . . . . . . . . . . Damien Dupuis\n' \
' . . . . . . . . . . . . . . . . . . . Remy Escassut\n' \
' . . . . . . . . . . . . . . . . . . Christian Masson\n' \
'E-Mail . . . . . . . . . . . . . . Jean-Paul.Chaput@lip6.fr'
if pyQtIsEnabled:
class AboutWidget ( QDialog ):
def __init__ ( self, parent=None ): def __init__ ( self, parent=None ):
QWidget.__init__ ( self, parent ) QWidget.__init__ ( self, parent )
@ -76,23 +86,18 @@ class AboutWidget ( QDialog ):
botLine.setFrameShape( QFrame.HLine ) botLine.setFrameShape( QFrame.HLine )
botLine.setLineWidth ( 2 ) botLine.setLineWidth ( 2 )
title = QLabel( 'CCB' ) title = QLabel( 'CGT' )
title.setAlignment( Qt.AlignCenter ) title.setAlignment( Qt.AlignCenter )
font = title.font() font = title.font()
font.setPointSize( 72 ) font.setPointSize( 72 )
font.setWeight ( QFont.Bold ) font.setWeight ( QFont.Bold )
title.setFont( font ) title.setFont( font )
subTitle = QLabel( 'Coriolis & Chams Builder for the Dummies' ) subTitle = QLabel( 'Coriolis Graphical Interface' )
subTitle.setAlignment( Qt.AlignCenter ) subTitle.setAlignment( Qt.AlignCenter )
subTitle.setFont( QFont('Courier',10,QFont.Bold) ) subTitle.setFont( QFont('Courier',10,QFont.Bold) )
authors = QLabel( 'Coriolis CAD System 1.0 . . . . . . . . ccb 1.0\n' authors = QLabel( aboutText )
'Copyright (c) 2008-2016 . . . . . . . . . . UPMC\n'
'Authors . . . . . . . . . . . . . Damien Dupuis\n'
' . . . . . . . . . . . . Jean-Paul Chaput\n'
'E-Mail . . . . . . . . Jean-Paul.Chaput@lip6.fr'
)
authors.setAlignment( Qt.AlignCenter ) authors.setAlignment( Qt.AlignCenter )
authors.setFont( QFont('Courier',10,QFont.Bold) ) authors.setFont( QFont('Courier',10,QFont.Bold) )
@ -132,7 +137,14 @@ class AboutWidget ( QDialog ):
self._closeAction.triggered.connect( self.accept ) self._closeAction.triggered.connect( self.accept )
self.addAction( self._closeAction ) self.addAction( self._closeAction )
return else:
class AboutWidget ( object ):
def __init__ ( self ):
self.aboutText = aboutText
return AboutWidget
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -149,10 +161,12 @@ def unicornHook ( **kw ):
def scriptMain ( **kw ): def scriptMain ( **kw ):
rvalue = True
try: try:
#helpers.setTraceLevel( 550 ) #helpers.setTraceLevel( 550 )
aboutWidget = AboutWidget() aboutWidget = getAboutWidget()()
if not pyQtIsEnabled:
print( aboutWidget.aboutText )
return True
answer = aboutWidget.exec_() answer = aboutWidget.exec_()
print( 'answer:', answer ) print( 'answer:', answer )
if not answer: return True if not answer: return True
@ -160,4 +174,4 @@ def scriptMain ( **kw ):
helpers.io.catch( e ) helpers.io.catch( e )
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
return rvalue return True