menu.py 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import logging

11 12 13 14
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont

15 16 17 18 19 20 21 22 23
from module import Module
import modules
from ui.menu_ui import Ui_Form as MenuWidget

class MenuModule(Module):
	def __init__(self, parent):
		super().__init__(parent, MenuWidget())

		# Button connections
Antoine Lima's avatar
Antoine Lima committed
24 25 26 27 28
		self.ui.btnStart2p.clicked.connect    (lambda: self.switchModule(modules.AuthModule))
		self.ui.btnStartParty.clicked.connect (lambda: self.switchModule(modules.GameModule))
		self.ui.btnStartLeague.clicked.connect(lambda: self.switchModule(modules.GameModule))
		self.ui.btnLeaderboard.clicked.connect(lambda: self.switchModule(modules.LeaderboardModule))
		self.ui.btnOptions.clicked.connect    (lambda: self.switchModule(modules.OptionsModule))
29 30 31

	def load(self):
		logging.debug('Loading MenuModule')
32
		self.ui.btnStart2p.setFocus()
33 34 35 36 37 38 39

	def unload(self):
		logging.debug('Unloading MenuModule')
	
	def other(self, **kwargs):
		logging.debug('Other MenuModule')

40 41
	def keyPressEvent(self, e):
		if e.key() == Qt.Key_Escape:
42
			self.handleExit()
43 44 45 46 47
		elif e.key() == Qt.Key_Up:
			self.parent().focusPreviousChild()
		elif e.key() == Qt.Key_Down:
			self.parent().focusNextChild()
		elif e.key() == Qt.Key_Return:
Antoine Lima's avatar
Antoine Lima committed
48 49 50 51
			if QApplication.focusWidget()==None:
				logging.error('No focused widget to activate')
			else:
				QApplication.focusWidget().animateClick()
52

53
	def handleExit(self):
Antoine Lima's avatar
Antoine Lima committed
54
		logging.info('Closing..')
Antoine Lima's avatar
Antoine Lima committed
55
		self.mainwin.close()