Commit 7b83de26 authored by Antoine Lima's avatar Antoine Lima

Base UI v0.1

parent a70a8a47
# source-rasp
Code source de la Raspberry PI contenue dans le babyfoot connecté.
\ No newline at end of file
Source code for the foosball embedded Raspberry PI. It runs the UI and manages games.
The UI is done with PyQt.
## Edit the UI
* Download qt4-designer (`sudo apt-get install qt4-designer`)
* Edit .ui files with qt4-designer
* Convert the .ui files to python sources (`pyuic5 file.ui -o file_ui.py`)
* Done!
......@@ -14,22 +14,18 @@ from math import ceil
from PyQt5.QtCore import QTime
from PyQt5 import QtWidgets
from main_ui import Ui_MainWindow
from menu_ui import Ui_Form as Menu_Form
from options_ui import Ui_Form as Options_Form
class MainWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
# UI Setup
self.ui.setupUi(self)
self.displaySystemTime()
self.startTimer(1000)
# Button connections
self.ui.btnStart.clicked.connect(self.ui_handleClick_btnStart)
self.ui.btnOptions.clicked.connect(self.ui_handleClick_btnOptions)
self.ui.btnExit.clicked.connect(self.ui_handleClick_btnExit)
self.switchPanel(MenuPanel(self))
def timerEvent(self, e):
self.displaySystemTime()
......@@ -37,15 +33,54 @@ class MainWin(QtWidgets.QMainWindow):
def displaySystemTime(self):
self.ui.lcdNumber.display(QTime.currentTime().toString("hh:mm:ss"))
def switchPanel(self, panel):
print("switching from {} to {} (size {})".format(self.ui.stackedWidget.currentWidget(), panel, self.ui.stackedWidget.count()))
#self.ui.panel = panel
self.ui.stackedWidget.removeWidget(self.ui.stackedWidget.currentWidget())
self.ui.stackedWidget.addWidget(panel)
self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.count()-1)
class MenuPanel(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
# UI Setup
self.ui = Menu_Form()
self.ui.setupUi(self)
#self.displaySystemTime()
#self.startTimer(1000)
# Button connections
self.ui.btn0Start.clicked.connect(self.ui_handleClick_btnStart)
self.ui.btn1Options.clicked.connect(self.ui_handleClick_btnOptions)
self.ui.btn2Exit.clicked.connect(self.ui_handleClick_btnExit)
def ui_handleClick_btnStart(self):
print('start')
self.parent().parent().parent().showFullScreen()
def ui_handleClick_btnOptions(self):
print('options')
print('options', self.parent(), self.parent().parent(), self.parent().parent().parent())
self.parent().parent().parent().switchPanel(OptionsPanel(self.parent().parent().parent()))
def ui_handleClick_btnExit(self):
print('exit')
self.close()
self.parent().parent().parent().close()
class OptionsPanel(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
# UI Setup
self.ui = Options_Form()
self.ui.setupUi(self)
# Button connections
self.ui.btnBack.clicked.connect(self.ui_handleClick_btnBack)
def ui_handleClick_btnBack(self):
print('back', self.parent(), self.parent().parent(), self.parent().parent().parent())
self.parent().parent().parent().switchPanel(MenuPanel(self.parent().parent().parent()))
if __name__=='__main__':
app = QtWidgets.QApplication(sys.argv)
......
......@@ -44,9 +44,12 @@
<string>Babyfoot</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
......@@ -87,117 +90,12 @@
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<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>
<spacer name="verticalSpacer_6">
<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>
<spacer name="verticalSpacer_5">
<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>
<widget class="QPushButton" name="btnStart">
<property name="text">
<string>Start</string>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<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>
<widget class="QPushButton" name="btnOptions">
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnExit">
<property name="text">
<string>Exit</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
<spacer name="verticalSpacer_7">
<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>
<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>
</layout>
</widget>
</widget>
......
......@@ -23,9 +23,10 @@ class Ui_MainWindow(object):
MainWindow.setBaseSize(QtCore.QSize(640, 360))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
......@@ -43,39 +44,17 @@ class Ui_MainWindow(object):
self.lcdNumber.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.lcdNumber.setObjectName("lcdNumber")
self.horizontalLayout.addWidget(self.lcdNumber)
self.verticalLayout_2.addLayout(self.horizontalLayout)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem1)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem2)
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem3)
self.btnStart = QtWidgets.QPushButton(self.centralwidget)
self.btnStart.setObjectName("btnStart")
self.verticalLayout_2.addWidget(self.btnStart)
spacerItem4 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem4)
self.btnOptions = QtWidgets.QPushButton(self.centralwidget)
self.btnOptions.setObjectName("btnOptions")
self.verticalLayout_2.addWidget(self.btnOptions)
self.btnExit = QtWidgets.QPushButton(self.centralwidget)
self.btnExit.setObjectName("btnExit")
self.verticalLayout_2.addWidget(self.btnExit)
spacerItem5 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem5)
spacerItem6 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem6)
spacerItem7 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem7)
self.verticalLayout.addLayout(self.horizontalLayout)
self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.stackedWidget.setObjectName("stackedWidget")
self.verticalLayout.addWidget(self.stackedWidget)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(-1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Babyfoot"))
self.btnStart.setText(_translate("MainWindow", "Start"))
self.btnOptions.setText(_translate("MainWindow", "Options"))
self.btnExit.setText(_translate("MainWindow", "Exit"))
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>813</width>
<height>463</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>36</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>37</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>36</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn0Start">
<property name="text">
<string>Start</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>37</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn1Options">
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn2Exit">
<property name="text">
<string>Exit</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>36</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>37</height>
</size>
</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>36</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'menu.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(813, 463)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
spacerItem = QtWidgets.QSpacerItem(20, 36, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
spacerItem1 = QtWidgets.QSpacerItem(20, 37, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem1)
spacerItem2 = QtWidgets.QSpacerItem(20, 36, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
self.btn0Start = QtWidgets.QPushButton(Form)
self.btn0Start.setAutoDefault(True)
self.btn0Start.setDefault(True)
self.btn0Start.setObjectName("btn0Start")
self.verticalLayout.addWidget(self.btn0Start)
spacerItem3 = QtWidgets.QSpacerItem(20, 37, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem3)
self.btn1Options = QtWidgets.QPushButton(Form)
self.btn1Options.setObjectName("btn1Options")
self.verticalLayout.addWidget(self.btn1Options)
self.btn2Exit = QtWidgets.QPushButton(Form)
self.btn2Exit.setObjectName("btn2Exit")
self.verticalLayout.addWidget(self.btn2Exit)
spacerItem4 = QtWidgets.QSpacerItem(20, 36, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem4)
spacerItem5 = QtWidgets.QSpacerItem(20, 37, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem5)
spacerItem6 = QtWidgets.QSpacerItem(20, 36, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem6)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.btn0Start.setText(_translate("Form", "Start"))
self.btn1Options.setText(_translate("Form", "Options"))
self.btn2Exit.setText(_translate("Form", "Exit"))
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>540</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="btnBack">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'options.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(728, 540)
self.gridLayout = QtWidgets.QGridLayout(Form)
self.gridLayout.setObjectName("gridLayout")
self.btnBack = QtWidgets.QPushButton(Form)
self.btnBack.setObjectName("btnBack")
self.gridLayout.addWidget(self.btnBack, 0, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.btnBack.setText(_translate("Form", "Back"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment