babyfut.py 1.46 KB
Newer Older
Antoine Lima's avatar
Base UI  
Antoine Lima committed
1
2
3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Antoine Lima's avatar
UI v0.3    
Antoine Lima committed
4
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
Antoine Lima's avatar
Base UI  
Antoine Lima committed
5
6
"""

7
8
9
import os
OnRasp = os.uname()[1] == 'raspberrypi'

Antoine Lima's avatar
UI v0.3    
Antoine Lima committed
10
11
import sys
import logging
Antoine Lima's avatar
Antoine Lima committed
12
from os.path import dirname, abspath, join
Antoine Lima's avatar
Base UI  
Antoine Lima committed
13

Antoine Lima's avatar
Antoine Lima committed
14
from PyQt5 import QtWidgets, QtCore
Antoine Lima's avatar
Base UI  
Antoine Lima committed
15

Antoine Lima's avatar
Cleanup    
Antoine Lima committed
16
17
18
def getContent(path):
	contentFolder = join(dirname(dirname(abspath(__file__))), 'content')
	return join(contentFolder, path)
19
	
Antoine Lima's avatar
Base UI  
Antoine Lima committed
20
if __name__=='__main__':
Antoine Lima's avatar
Cleanup    
Antoine Lima committed
21
22
23
	from ui.mainwin import MainWin
	from modules import GameModule
	from player import Side
Antoine Lima's avatar
Antoine Lima committed
24
	from settings import Settings
Antoine Lima's avatar
Cleanup    
Antoine Lima committed
25
	
26
27
	from input import GPIOThread
	from database import Database
28
	from replay import Replay as ReplayThread
Antoine Lima's avatar
Antoine Lima committed
29
	
30
31
32
33
34
	try:
		#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
		logging.basicConfig(level=logging.DEBUG)
		
		app = QtWidgets.QApplication(sys.argv)
Antoine Lima's avatar
Antoine Lima committed
35
36
37
38
39
		lang = Settings['ui.language']
		qtTranslator = QtCore.QTranslator()
		if lang!='en' and qtTranslator.load("translations/babyfut_{}.qm".format(lang)):
			app.installTranslator(qtTranslator)
    
40
41
		myapp = MainWin()
		
42
43
44
45
		if ReplayThread.isCamAvailable():
			threadReplay = ReplayThread(Side.Left)
			threadReplay.start()
			myapp.dispatchMessage({'replayThread': threadReplay}, toType=GameModule)
46
47
48
49
50
51
52
53
54
		
		threadGPIO = GPIOThread(myapp)
		threadGPIO.start()
		
		myapp.show()
		app.exec_()
		
		threadGPIO.stop()
		
55
56
57
		if ReplayThread.isCamAvailable():
			threadReplay.stop()
			threadReplay.join()
58
59
60
61
62
		
		threadGPIO.join()
		
	finally:
		GPIOThread.clean()
Antoine Lima's avatar
Antoine Lima committed
63
		Database.instance().close()