Commit b2caf55c authored by Antoine Lima's avatar Antoine Lima

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

parent 7b29a21e
......@@ -10,26 +10,42 @@ import sys
import logging
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 modules import *
#acceptedKeys = [Qt.Key_Escape, Qt.Key_Enter, Qt.Key_Return, Qt.UpArrow, Qt.DownArrow, Qt.LeftArrow, Qt.RightArrow]
class MainWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
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]
for mod in self.modules:
self.ui.panels.addWidget(mod(self))
self.ui.panels.setCurrentIndex(0)
self.ui.panels.currentWidget().setFocus()
self.ui.panels.currentWidget().grabKeyboard()
self.ui.panels.currentWidget().load()
self.displaySystemTime()
self.startTimer(1000)
#def eventFilter(target, event):
# return event.type()==QEvent.KeyPress and event.key() not in acceptedKeys
def timerEvent(self, e):
self.displaySystemTime()
......
......@@ -9,9 +9,8 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5 import QtWidgets
from PyQt5.QtGui import QRegion
from PyQt5.QtCore import QTime, QTimer
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox
from PyQt5.QtCore import QTime, QTimer, Qt
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
from modules import *
......@@ -29,9 +28,18 @@ class Module(QtWidgets.QWidget):
if panel_idx<0:
logging.error('Error: unknown panel {}'.format(new_type))
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.setCurrentIndex(panel_idx)
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):
logging.warning('Unimplemented method "load" for {}'.format(self.__class__))
......
......@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtCore import QTime
from PyQt5.QtCore import QTime, Qt
from module import Module
import modules
......@@ -18,9 +18,6 @@ class AuthModule(Module):
def __init__(self, parent):
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):
logging.debug('Loading AuthModule')
......@@ -30,6 +27,12 @@ class AuthModule(Module):
def other(self, **kwargs):
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):
self.switchModule(modules.MenuModule)
......
......@@ -8,7 +8,9 @@ Created on Wed Apr 18 18:34:40 2018
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
import modules
......@@ -32,16 +34,17 @@ class GameModule(Module):
# Button connections
self.ui.btnScore1.clicked.connect(self.ui_handleClick_btnScore1)
self.ui.btnScore2.clicked.connect(self.ui_handleClick_btnScore2)
self.ui.btnCancel.clicked.connect(self.ui_handleClick_btnCancel)
def load(self):
logging.debug('Loading GameModule')
self.gameStartTime = QTime.currentTime()
self.timerUpdateChrono.start(1000)
self.ui.lcdChrono.display(QTime(0,0).toString("hh:mm:ss"))
self.score1 = 0
self.score2 = 0
self.updateScores()
def unload(self):
logging.debug('Unloading GameModule')
......@@ -51,6 +54,25 @@ class GameModule(Module):
def other(self, **kwargs):
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):
# Updated each second
elapsedSec = self.gameStartTime.secsTo(QTime.currentTime())
......
......@@ -8,7 +8,7 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtCore import QTime
from PyQt5.QtCore import QTime, Qt
from module import Module
import modules
......@@ -18,8 +18,6 @@ class LeaderboardModule(Module):
def __init__(self, parent):
super().__init__(parent, LeaderboardWidget())
self.ui.btnExit.clicked.connect(self.ui_handleClick_btnExit)
def load(self):
logging.debug('Loading LeaderboardModule')
......@@ -29,5 +27,9 @@ class LeaderboardModule(Module):
def other(self, **kwargs):
logging.debug('Other LeaderboardModule')
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.ui_handleClick_btnExit()
def ui_handleClick_btnExit(self):
self.switchModule(modules.MenuModule)
......@@ -8,6 +8,10 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from module import Module
import modules
from ui.menu_ui import Ui_Form as MenuWidget
......@@ -22,10 +26,10 @@ class MenuModule(Module):
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))
self.ui.btnExit.clicked.connect (self.ui_handleClick_btnExit)
def load(self):
logging.debug('Loading MenuModule')
self.ui.btnStart2p.setFocus()
def unload(self):
logging.debug('Unloading MenuModule')
......@@ -33,6 +37,16 @@ class MenuModule(Module):
def other(self, **kwargs):
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):
logging.info('Closing..')
self.parent_win.close()
......@@ -8,7 +8,8 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
from module import Module
import modules
......@@ -39,11 +40,20 @@ class OptionsModule(Module):
def other(self, **kwargs):
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):
if self.ui.options.cellWidget(0, 1).currentText().lower() == 'true':
self.parent_win.showFullScreen()
#QWSServer::setCursorVisible(False);
QApplication.setOverrideCursor(Qt.BlankCursor);
else:
self.parent_win.showNormal()
#QWSServer.setCursorVisible(True);
self.switchModule(modules.MenuModule)
......
<RCC>
<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/placeholder_head.jpg</file>
</qresource>
<qresource prefix="font">
<file>KaushanScript-Regular.ttf</file>
</qresource>
</RCC>
......@@ -106,8 +106,8 @@
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>300</height>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="maximumSize">
......@@ -213,8 +213,8 @@
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>300</height>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="maximumSize">
......@@ -239,6 +239,9 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
......@@ -311,81 +314,6 @@
</property>
</spacer>
</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>
</widget>
<resources>
......
......@@ -13,21 +13,6 @@
<property name="windowTitle">
<string>Form</string>
</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">
<item>
<spacer name="verticalSpacer">
......@@ -45,19 +30,6 @@ color: black;
</property>
</spacer>
</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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -75,11 +47,41 @@ color: black;
</item>
<item>
<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">
<string>0</string>
</property>
</widget>
</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>
<spacer name="horizontalSpacer_3">
<property name="orientation">
......@@ -95,6 +97,23 @@ color: black;
</item>
<item>
<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">
<string>0</string>
</property>
......@@ -121,7 +140,7 @@ color: black;
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
......@@ -142,15 +161,12 @@ color: black;
<property name="minimumSize">
<size>
<width>200</width>
<height>100</height>
<height>80</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="smallDecimalPoint">
<bool>false</bool>
</property>
<property name="digitCount">
<number>8</number>
</property>
......@@ -161,83 +177,17 @@ color: black;
<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>
<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 name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
......
ui/img/bg/bg0.jpg

29.3 KB | W: | H:

ui/img/bg/bg0.jpg

41.7 KB | W: | H:

ui/img/bg/bg0.jpg
ui/img/bg/bg0.jpg
ui/img/bg/bg0.jpg
ui/img/bg/bg0.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -22,7 +22,7 @@
</font>
</property>
<property name="text">
<string>Leadderboard</string>
<string>Leaderboard</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
......@@ -215,7 +215,7 @@
<x>0</x>
<y>0</y>
<width>1260</width>
<height>464</height>
<height>521</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -226,80 +226,6 @@
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_9">
<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_12">
<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="btnExit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>Exit</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_11">
<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_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
......
......@@ -45,16 +45,25 @@
</property>
<widget class="QWidget" name="centralwidget">
<property name="styleSheet">
<string notr="true">#panels {
border-image: url(:/ui/img/bg/bg0.jpg) 0 0 0 0 stretch stretch;
<string notr="true">#centralwidget {
border-image: url(:/ui/img/bg/bg1.jpg) 0 0 0 0 stretch stretch;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>1</number>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="layoutMenuBar">
......@@ -82,6 +91,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>30</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(231, 231, 231);</string>