main.py 2.89 KB
Newer Older
Antoine Lima's avatar
Antoine Lima committed
1 2 3 4 5
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

Antoine Lima's avatar
Antoine Lima committed
6
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
Antoine Lima's avatar
Antoine Lima committed
7 8
"""

Antoine Lima's avatar
Antoine Lima committed
9 10
import sys
import logging
Antoine Lima's avatar
Antoine Lima committed
11
import threading
Antoine Lima's avatar
Antoine Lima committed
12
from os.path import dirname, abspath, join
Antoine Lima's avatar
Antoine Lima committed
13 14

from PyQt5 import QtWidgets
15
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication
16
from PyQt5.QtCore import QTime, Qt
Antoine Lima's avatar
Antoine Lima committed
17

18 19
from ui.main_ui import Ui_MainWindow
from modules import *
Antoine Lima's avatar
Antoine Lima committed
20 21
from player import Side
from com import InputThread
Antoine Lima's avatar
Antoine Lima committed
22 23 24 25 26 27

class MainWin(QtWidgets.QMainWindow):
	def __init__(self, parent=None):
		QtWidgets.QWidget.__init__(self, parent)
		self.ui = Ui_MainWindow()
		self.ui.setupUi(self)
28
		
29 30 31 32 33 34 35
		#Background blur
		bgBlur = QGraphicsBlurEffect()
		bgBlur.setBlurHints(QGraphicsBlurEffect.QualityHint)
		#bgBlur.setBlurRadius(5)
		#self.ui.panels.setGraphicsEffect(bgBlur)
		
		# Module loading
Antoine Lima's avatar
Antoine Lima committed
36 37
		self.modules = [
			MenuModule(self),
38 39
			AuthQuickModule(self),
			AuthLeagueModule(self),
Antoine Lima's avatar
Antoine Lima committed
40 41 42 43 44
			GameModule(self),
			EndGameModule(self),
			LeaderboardModule(self),
			OptionsModule(self)
		]
45 46
		
		for mod in self.modules:
Antoine Lima's avatar
Antoine Lima committed
47
			self.ui.panels.addWidget(mod)
48
		
Antoine Lima's avatar
Antoine Lima committed
49
		self.ui.panels.setCurrentIndex(0)
50 51 52
		self.ui.panels.currentWidget().setFocus()
		self.ui.panels.currentWidget().grabKeyboard()
		self.ui.panels.currentWidget().load()
Antoine Lima's avatar
Antoine Lima committed
53 54
		self.displaySystemTime()
		self.startTimer(1000)
55 56 57
	
	#def eventFilter(target, event):
	#	return event.type()==QEvent.KeyPress and event.key() not in acceptedKeys
Antoine Lima's avatar
Antoine Lima committed
58

Antoine Lima's avatar
Antoine Lima committed
59 60
	def timerEvent(self, e):
		self.displaySystemTime()
Antoine Lima's avatar
Antoine Lima committed
61

Antoine Lima's avatar
Antoine Lima committed
62 63
	def displaySystemTime(self):
		self.ui.lcdTime.display(QTime.currentTime().toString("hh:mm:ss"))
Antoine Lima's avatar
Antoine Lima committed
64 65 66 67 68 69 70 71 72

	def findMod(self, type):
		mod_idx = [i for i, x in enumerate(self.modules) if isinstance(x, type)]
		return -1 if len(mod_idx)==0 else mod_idx[0]
	
	def dispatchMessage(self, msg, toAll=False):
		modulesIdx = self.modules if toAll else [self.findMod(type(self.ui.panels.currentWidget()))]			
		for modIdx in modulesIdx:
			self.modules[modIdx].other(**msg)
73 74 75 76 77
	
	@staticmethod
	def getContent(path):
		contentFolder = join(dirname(dirname(abspath(__file__))), 'content')
		return join(contentFolder, path)
Antoine Lima's avatar
Antoine Lima committed
78

79 80 81 82 83 84 85 86 87
	def _refreshAfterSettings(self):
		from settings import Settings
		
		if Settings.ui['fullscreen']:
			self.showFullScreen()
			QApplication.setOverrideCursor(Qt.BlankCursor);
		else:
			self.showNormal()
			QApplication.setOverrideCursor(Qt.ArrowCursor);
Antoine Lima's avatar
Antoine Lima committed
88

Antoine Lima's avatar
Antoine Lima committed
89
if __name__=='__main__':
Antoine Lima's avatar
Antoine Lima committed
90 91
	from settings import Settings
	
Antoine Lima's avatar
Antoine Lima committed
92 93
	#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
	logging.basicConfig(level=logging.DEBUG)
Antoine Lima's avatar
Antoine Lima committed
94 95
	
	app = QtWidgets.QApplication(sys.argv)
Antoine Lima's avatar
Antoine Lima committed
96
	myapp = MainWin()
Antoine Lima's avatar
Antoine Lima committed
97 98 99 100 101 102 103
	
	if Settings['app.mode']!='dev':
		threadArduinoLeft  = InputThread(myapp, Side.Left)
		#threadArduinoRight = InputThread(myapp, Side.Right)
		threadArduinoLeft.start()
		#threadArduinoRight.start()
	
Antoine Lima's avatar
Antoine Lima committed
104
	myapp.show()
105
	app.exec_()
Antoine Lima's avatar
Antoine Lima committed
106 107 108 109 110 111
	
	if Settings['app.mode']!='dev':
		threadArduinoLeft.stop()
		#threadArduinoRight.stop()
		threadArduinoLeft.join()
		#threadArduinoRight.join()