2626from PyQt6 .QtWidgets import QApplication
2727from PyQt6 .QtCore import QCoreApplication
2828from PyQt6 .QtGui import QIcon
29+ import logging
2930
3031try :
3132 # Import for unit tests
4849class Application (QApplication ):
4950 """Generate the main app object"""
5051
51- def __init__ (self ):
52+ def __init__ (self , conf ):
5253 """Initialize the object"""
53-
5454 super ().__init__ (sys .argv ) # Initialize the Qapplication
55+ self .log = logging .getLogger ()
5556
5657 # To add an event :
5758 # 1 - In Notifier create the signal
@@ -71,6 +72,15 @@ def __init__(self):
7172 self .datasdir = os .path .join (self .rootdir , "datas" )
7273 self .viewsdir = os .path .join (self .rootdir , "views" )
7374
75+ if sys .platform .startswith ("win" ):
76+ pidfile = os .path .join ("C:\\ " , "windows" , "temp" , "kiosk.pid" )
77+ else :
78+ pidfile = os .path .join ("/" , "tmp" , "kiosk.pid" )
79+
80+ with open (pidfile , "w" ) as pidfb :
81+ pidfb .write ("%s" % os .getpid ())
82+ pidfb .close ()
83+
7484 # Notify the application when something is happening
7585 self .notifier = Notifier ()
7686 # Action launched when the kiosk emit a notification
@@ -85,13 +95,14 @@ def __init__(self):
8595 self .translate = QCoreApplication .translate
8696
8797 # Keep the config parameters in memory
88- self .parameters = ConfParameter ()
98+ self .parameters = conf
8999
90100 # Socket server. It is always running. This module listen and wait the
91101 # messages from AM
92102 self .receiver = MessengerFromAM (self )
93103
94104 self .logger ("info" , "Initialization" )
105+ self .log .info ("Kiosk initialization" )
95106 # The mechanics are launched here
96107 self .notifier .app_launched .emit ()
97108
@@ -111,12 +122,18 @@ def __init__(self):
111122
112123 def run (self ):
113124 """Launch the main loop"""
114- self .exec ()
125+ try :
126+ self .exec ()
127+ except Exception as err :
128+ self .log .error ("Error during execution: %s" % err )
115129
116130 # Associate a unique sender. This module send messages to AM
117131 def send (self , message ):
118132 messenger = MessengerToAM (self )
119- messenger .send (message )
133+ try :
134+ messenger .send (message )
135+ except Exception as err :
136+ self .log .error ("Error during sending %s : %s" % (message , err ))
120137
121138 def logger (self , type , msg ):
122139 """Send log message to Agent Machine.
@@ -144,6 +161,14 @@ def send_pong(self):
144161
145162
146163if __name__ == "__main__" :
147- app = Application ()
164+ conf = ConfParameter ()
165+ format = "%(asctime)s - %(levelname)s -(LAUNCHER)%(message)s"
166+ formatter = logging .Formatter (format )
167+ logdir = os .path .dirname (conf .logfilename ())
168+ if os .path .isdir (logdir ):
169+ os .makedirs (logdir , exist_ok = True )
170+ logging .basicConfig (level = conf .log_level , format = format , filename = conf .logfilename (), filemode = "a" )
171+
172+ app = Application (conf )
148173 app .send_ping ()
149174 app .run ()
0 commit comments