Commit b2caf55c authored by Antoine Lima's avatar Antoine Lima

Nicer UI: background & transparency, moved controls to arrow keys + enter/escape

parent 7b29a21e
...@@ -10,25 +10,41 @@ import sys ...@@ -10,25 +10,41 @@ import sys
import logging import logging
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtCore import QTime from PyQt5.QtWidgets import QGraphicsBlurEffect
from PyQt5.QtCore import QTime, Qt
from ui.main_ui import Ui_MainWindow from ui.main_ui import Ui_MainWindow
from modules import * from modules import *
#acceptedKeys = [Qt.Key_Escape, Qt.Key_Enter, Qt.Key_Return, Qt.UpArrow, Qt.DownArrow, Qt.LeftArrow, Qt.RightArrow]
class MainWin(QtWidgets.QMainWindow): class MainWin(QtWidgets.QMainWindow):
def __init__(self, parent=None): def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent) QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
#Background blur
bgBlur = QGraphicsBlurEffect()
bgBlur.setBlurHints(QGraphicsBlurEffect.QualityHint)
#bgBlur.setBlurRadius(5)
#self.ui.panels.setGraphicsEffect(bgBlur)
# Module loading
self.modules = [MenuModule, GameModule, OptionsModule, AuthModule, LeaderboardModule] self.modules = [MenuModule, GameModule, OptionsModule, AuthModule, LeaderboardModule]
for mod in self.modules: for mod in self.modules:
self.ui.panels.addWidget(mod(self)) self.ui.panels.addWidget(mod(self))
self.ui.panels.setCurrentIndex(0) self.ui.panels.setCurrentIndex(0)
self.ui.panels.currentWidget().setFocus()
self.ui.panels.currentWidget().grabKeyboard()
self.ui.panels.currentWidget().load()
self.displaySystemTime() self.displaySystemTime()
self.startTimer(1000) self.startTimer(1000)
#def eventFilter(target, event):
# return event.type()==QEvent.KeyPress and event.key() not in acceptedKeys
def timerEvent(self, e): def timerEvent(self, e):
self.displaySystemTime() self.displaySystemTime()
......
...@@ -9,9 +9,8 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -9,9 +9,8 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtGui import QRegion from PyQt5.QtCore import QTime, QTimer, Qt
from PyQt5.QtCore import QTime, QTimer from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox
from modules import * from modules import *
...@@ -29,9 +28,18 @@ class Module(QtWidgets.QWidget): ...@@ -29,9 +28,18 @@ class Module(QtWidgets.QWidget):
if panel_idx<0: if panel_idx<0:
logging.error('Error: unknown panel {}'.format(new_type)) logging.error('Error: unknown panel {}'.format(new_type))
else: else:
self.parent_win.ui.panels.currentWidget().releaseKeyboard()
if QApplication.focusWidget() != None:
QApplication.focusWidget().clearFocus()
self.parent_win.ui.panels.currentWidget().unload() self.parent_win.ui.panels.currentWidget().unload()
self.parent_win.ui.panels.setCurrentIndex(panel_idx) self.parent_win.ui.panels.setCurrentIndex(panel_idx)
self.parent_win.ui.panels.currentWidget().load() self.parent_win.ui.panels.currentWidget().load()
# Select first element of the Module
self.parent_win.ui.panels.currentWidget().focusNextChild()
self.parent_win.ui.panels.currentWidget().focusPreviousChild()
self.parent_win.ui.panels.currentWidget().grabKeyboard()
def load(self): def load(self):
logging.warning('Unimplemented method "load" for {}'.format(self.__class__)) logging.warning('Unimplemented method "load" for {}'.format(self.__class__))
......
...@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtCore import QTime from PyQt5.QtCore import QTime, Qt
from module import Module from module import Module
import modules import modules
...@@ -17,9 +17,6 @@ from ui.auth2p_ui import Ui_Form as Auth2pWidget ...@@ -17,9 +17,6 @@ from ui.auth2p_ui import Ui_Form as Auth2pWidget
class AuthModule(Module): class AuthModule(Module):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent, Auth2pWidget()) super().__init__(parent, Auth2pWidget())
self.ui.btnDone.clicked.connect (self.ui_handleClick_btnDone)
self.ui.btnCancel.clicked.connect(self.ui_handleClick_btnCancel)
def load(self): def load(self):
logging.debug('Loading AuthModule') logging.debug('Loading AuthModule')
...@@ -30,6 +27,12 @@ class AuthModule(Module): ...@@ -30,6 +27,12 @@ class AuthModule(Module):
def other(self, **kwargs): def other(self, **kwargs):
logging.debug('Other AuthModule') logging.debug('Other AuthModule')
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnCancel()
elif e.key() == Qt.Key_Enter or e.key() == Qt.Key_Return:
self.ui_handleClick_btnDone()
def ui_handleClick_btnCancel(self): def ui_handleClick_btnCancel(self):
self.switchModule(modules.MenuModule) self.switchModule(modules.MenuModule)
......
...@@ -8,7 +8,9 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,7 +8,9 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtCore import QTime, QTimer from PyQt5 import QtWidgets
from PyQt5.QtGui import QRegion
from PyQt5.QtCore import QTime, QTimer, QRect, Qt
from module import Module from module import Module
import modules import modules
...@@ -32,16 +34,17 @@ class GameModule(Module): ...@@ -32,16 +34,17 @@ class GameModule(Module):
# Button connections # Button connections
self.ui.btnScore1.clicked.connect(self.ui_handleClick_btnScore1) self.ui.btnScore1.clicked.connect(self.ui_handleClick_btnScore1)
self.ui.btnScore2.clicked.connect(self.ui_handleClick_btnScore2) self.ui.btnScore2.clicked.connect(self.ui_handleClick_btnScore2)
self.ui.btnCancel.clicked.connect(self.ui_handleClick_btnCancel)
def load(self): def load(self):
logging.debug('Loading GameModule') logging.debug('Loading GameModule')
self.gameStartTime = QTime.currentTime() self.gameStartTime = QTime.currentTime()
self.timerUpdateChrono.start(1000) self.timerUpdateChrono.start(1000)
self.ui.lcdChrono.display(QTime(0,0).toString("hh:mm:ss"))
self.score1 = 0 self.score1 = 0
self.score2 = 0 self.score2 = 0
self.updateScores()
def unload(self): def unload(self):
logging.debug('Unloading GameModule') logging.debug('Unloading GameModule')
...@@ -50,6 +53,25 @@ class GameModule(Module): ...@@ -50,6 +53,25 @@ class GameModule(Module):
def other(self, **kwargs): def other(self, **kwargs):
logging.debug('Other GameModule') logging.debug('Other GameModule')
def resizeEvent(self, event):
# 40% of the window width to have (5% margin)-(40% circle)-(10% middle)-(40% circle)-(5% margin)
btnDiameter = self.parent_win.width()*0.4
region = QRegion(QRect(0, 0, btnDiameter, btnDiameter), QRegion.Ellipse)
self.ui.btnScore1.setMinimumSize(btnDiameter, btnDiameter)
self.ui.btnScore2.setMinimumSize(btnDiameter, btnDiameter)
self.ui.btnScore1.setMask(region)
self.ui.btnScore2.setMask(region)
QtWidgets.QWidget.resizeEvent(self, event)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnCancel()
elif e.key() == Qt.Key_Left:
self.ui_handleClick_btnScore1()
elif e.key() == Qt.Key_Right:
self.ui_handleClick_btnScore2()
def updateChrono(self): def updateChrono(self):
# Updated each second # Updated each second
......
...@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtCore import QTime from PyQt5.QtCore import QTime, Qt
from module import Module from module import Module
import modules import modules
...@@ -17,8 +17,6 @@ from ui.leaderboard_ui import Ui_Form as LeaderboardWidget ...@@ -17,8 +17,6 @@ from ui.leaderboard_ui import Ui_Form as LeaderboardWidget
class LeaderboardModule(Module): class LeaderboardModule(Module):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent, LeaderboardWidget()) super().__init__(parent, LeaderboardWidget())
self.ui.btnExit.clicked.connect(self.ui_handleClick_btnExit)
def load(self): def load(self):
logging.debug('Loading LeaderboardModule') logging.debug('Loading LeaderboardModule')
...@@ -29,5 +27,9 @@ class LeaderboardModule(Module): ...@@ -29,5 +27,9 @@ class LeaderboardModule(Module):
def other(self, **kwargs): def other(self, **kwargs):
logging.debug('Other LeaderboardModule') logging.debug('Other LeaderboardModule')
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnExit()
def ui_handleClick_btnExit(self): def ui_handleClick_btnExit(self):
self.switchModule(modules.MenuModule) self.switchModule(modules.MenuModule)
...@@ -8,6 +8,10 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,6 +8,10 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from module import Module from module import Module
import modules import modules
from ui.menu_ui import Ui_Form as MenuWidget from ui.menu_ui import Ui_Form as MenuWidget
...@@ -22,10 +26,10 @@ class MenuModule(Module): ...@@ -22,10 +26,10 @@ class MenuModule(Module):
self.ui.btnStartLeague.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.btnLeaderboard.clicked.connect(lambda: self.switchModule(modules.LeaderboardModule))
self.ui.btnOptions.clicked.connect (lambda: self.switchModule(modules.OptionsModule)) self.ui.btnOptions.clicked.connect (lambda: self.switchModule(modules.OptionsModule))
self.ui.btnExit.clicked.connect (self.ui_handleClick_btnExit)
def load(self): def load(self):
logging.debug('Loading MenuModule') logging.debug('Loading MenuModule')
self.ui.btnStart2p.setFocus()
def unload(self): def unload(self):
logging.debug('Unloading MenuModule') logging.debug('Unloading MenuModule')
...@@ -33,6 +37,16 @@ class MenuModule(Module): ...@@ -33,6 +37,16 @@ class MenuModule(Module):
def other(self, **kwargs): def other(self, **kwargs):
logging.debug('Other MenuModule') logging.debug('Other MenuModule')
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnExit()
elif e.key() == Qt.Key_Up:
self.parent().focusPreviousChild()
elif e.key() == Qt.Key_Down:
self.parent().focusNextChild()
elif e.key() == Qt.Key_Return:
QApplication.focusWidget().animateClick()
def ui_handleClick_btnExit(self): def ui_handleClick_btnExit(self):
logging.info('Closing..') logging.info('Closing..')
self.parent_win.close() self.parent_win.close()
...@@ -8,7 +8,8 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,7 +8,8 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
from module import Module from module import Module
import modules import modules
...@@ -39,11 +40,20 @@ class OptionsModule(Module): ...@@ -39,11 +40,20 @@ class OptionsModule(Module):
def other(self, **kwargs): def other(self, **kwargs):
logging.debug('Other OptionsModule') logging.debug('Other OptionsModule')
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnBack()
elif e.key() == Qt.Key_Return:
self.ui_handleClick_btnSave()
def ui_handleClick_btnSave(self): def ui_handleClick_btnSave(self):
if self.ui.options.cellWidget(0, 1).currentText().lower() == 'true': if self.ui.options.cellWidget(0, 1).currentText().lower() == 'true':
self.parent_win.showFullScreen() self.parent_win.showFullScreen()
#QWSServer::setCursorVisible(False);
QApplication.setOverrideCursor(Qt.BlankCursor);
else: else:
self.parent_win.showNormal() self.parent_win.showNormal()
#QWSServer.setCursorVisible(True);
self.switchModule(modules.MenuModule) self.switchModule(modules.MenuModule)
......
<RCC> <RCC>
<qresource prefix="ui"> <qresource prefix="ui">
<file>img/bg/bg1.jpg</file>
<file>img/bg/bg2.png</file>
<file>img/bg/bg3.jpg</file>
<file>img/bg/bg4.jpg</file>
<file>img/bg/bg0.jpg</file> <file>img/bg/bg0.jpg</file>
<file>img/placeholder_head.jpg</file> <file>img/placeholder_head.jpg</file>
</qresource> </qresource>
<qresource prefix="font">
<file>KaushanScript-Regular.ttf</file>
</qresource>
</RCC> </RCC>
...@@ -106,8 +106,8 @@ ...@@ -106,8 +106,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>300</width> <width>400</width>
<height>300</height> <height>400</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
...@@ -213,8 +213,8 @@ ...@@ -213,8 +213,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>300</width> <width>400</width>
<height>300</height> <height>400</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
...@@ -239,6 +239,9 @@ ...@@ -239,6 +239,9 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
...@@ -311,81 +314,6 @@ ...@@ -311,81 +314,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnDone">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources> <resources>
......
...@@ -13,21 +13,6 @@ ...@@ -13,21 +13,6 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<property name="styleSheet">
<string notr="true">#btnScore1, #btnScore2 {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 white, stop: 1 rgb(168, 170, 184));
color: black;
border-style: solid;
border-width:1px;
border-radius:14ex;
border-color: green;
max-width:200px;
max-height:200px;
min-width:200px;
min-height:200px;
}
</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
...@@ -45,19 +30,6 @@ color: black; ...@@ -45,19 +30,6 @@ color: black;
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
...@@ -75,11 +47,41 @@ color: black; ...@@ -75,11 +47,41 @@ color: black;
</item> </item>
<item> <item>
<widget class="QPushButton" name="btnScore1"> <widget class="QPushButton" name="btnScore1">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="font">
<font>
<pointsize>70</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>0</string> <string>0</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
...@@ -95,6 +97,23 @@ color: black; ...@@ -95,6 +97,23 @@ color: black;
</item> </item>
<item> <item>
<widget class="QPushButton" name="btnScore2"> <widget class="QPushButton" name="btnScore2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="font">
<font>
<pointsize>70</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>0</string> <string>0</string>
</property> </property>
...@@ -121,7 +140,7 @@ color: black; ...@@ -121,7 +140,7 @@ color: black;
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Preferred</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
...@@ -142,15 +161,12 @@ color: black; ...@@ -142,15 +161,12 @@ color: black;
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>200</width> <width>200</width>
<height>100</height> <height>80</height>
</size> </size>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="smallDecimalPoint">
<bool>false</bool>
</property>
<property name="digitCount"> <property name="digitCount">
<number>8</number> <number>8</number>
</property> </property>
...@@ -161,83 +177,17 @@ color: black; ...@@ -161,83 +177,17 @@ color: black;
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>40</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>