Commit 9ab100f3 authored by Antoine Lima's avatar Antoine Lima

New package structure (Babyfut as root)

Many changes but mainly changing things like `from ui import ..`
to `from Babyfut.ui import ..`
parent fd0e6b96
......@@ -13,7 +13,7 @@ The UI is done with PyQt5.
* Make sure to have Python>3.5 installed (`sudo apt-get install python3` otherwise)
* Make sure to have PyQt5 installed (`sudo pip install pyqt5` otherwise)
* Compile the .ui and .rc files: `./devtools.sh ui`
* Execute main.py: `python3 babyfut.py`
* Execute the software: `./devtools.sh exec`
## Edit the UI
The UI is mostly created using Qt-Designer:
......
......@@ -19,7 +19,7 @@ def getContent(path):
return join(contentFolder, path)
def getMainWin():
from ui.mainwin import MainWin
from Babyfut.ui.mainwin import MainWin
# Global function to find the (open) QMainWindow in application
for widget in QApplication.instance().topLevelWidgets():
......@@ -28,14 +28,14 @@ def getMainWin():
return None
if __name__=='__main__':
from ui.mainwin import MainWin
from modules import GameModule
from player import Side
from settings import Settings
from input import GPIOThread
from database import Database
from replay import Replay as ReplayThread
print(__package__)
from Babyfut.ui.mainwin import MainWin
from Babyfut.modules import GameModule
from Babyfut.core.player import Side
from Babyfut.core.settings import Settings
from Babyfut.core.input import GPIOThread
from Babyfut.core.database import Database
from Babyfut.core.replay import Replay as ReplayThread
try:
#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
......
......@@ -14,7 +14,7 @@ class Database():
def __init__(self):
if not Database.__db:
from babyfut import getContent
from Babyfut.babyfut import getContent
db_path = getContent('babyfut.sqlite')
self._connection = sqlite3.connect(db_path)
......@@ -56,7 +56,7 @@ class Database():
self._connection.commit()
def select_all_rfid(self, debug=False):
from settings import Settings
from Babyfut.core.settings import Settings
if Settings['app.mode']=='prod':
return self._cursor.execute('SELECT rfid FROM Players WHERE rfid>0').fetchall()
else:
......
......@@ -8,13 +8,12 @@ import logging
import pyautogui # PyPi library
from threading import Thread
from babyfut import OnRasp
from Babyfut.babyfut import OnRasp
from Babyfut.core.player import Side
if OnRasp:
import RPi.GPIO as GPIO
from player import Side
class GPIOThread(Thread):
_keyButtonBindings = {
26: 'up',
......
......@@ -8,12 +8,13 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from enum import Enum
from database import Database, DatabaseError
from PyQt5.QtCore import Qt, QCoreApplication
from PyQt5.QtWidgets import QDialog
from ui.consent_dialog_ui import Ui_Dialog as ConsentDialogUI
from Babyfut.babyfut import getMainWin
from Babyfut.core.database import Database, DatabaseError
from Babyfut.ui.consent_dialog_ui import Ui_Dialog as ConsentDialogUI
class Side(Enum):
'''
......@@ -81,8 +82,7 @@ class Player():
# Ask for consent
if rfid==-2 and Player._first_time:
import babyfut
consentDialog = ConsentDialog(babyfut.getMainWin())
consentDialog = ConsentDialog(getMainWin())
consentDialog.exec()
if not consentDialog.result()==QDialog.Accepted:
......@@ -104,13 +104,22 @@ class Player():
logging.warn('DB Error: {}'.format(e))
return PlayerGuest
def displayImg(self, containerWidget):
containerWidget.setStyleSheet('border-image: url({});'.format(self.pic_path))
def displayImg(self, container_widget):
self.pic_container = container_widget
if self.pic_path.startswith('http'):
# Download from the internet
container_widget.setStyleSheet('border-image: url({});'.format(Player._placeholder_pic_path))
else:
# Already downloaded and stored locally
container_widget.setStyleSheet('border-image: url({});'.format(self.pic_path))
def save(self):
'''
Update or create the player in database
'''
pass
# DONT SAVE PIC PATH, IT IS CHANGED FOR THE LOCAL PATH
@property
def name(self):
......
......@@ -6,8 +6,8 @@
from threading import Thread, Event
from babyfut import getContent, OnRasp
from settings import Settings
from Babyfut.babyfut import getContent, OnRasp
from Babyfut.core.settings import Settings
if OnRasp:
import picamera
......
......@@ -117,5 +117,5 @@ class SettingsHolder(object):
self.settingsPath = settingsPath
from babyfut import getContent
from Babyfut.babyfut import getContent
Settings = SettingsHolder(getContent('settings.json'))
......@@ -9,23 +9,23 @@ case "$1" in
echo "Building UI..."
echo " Modules"
pyuic5 --import-from=ui ui/main.ui -o ui/main_ui.py
pyuic5 --import-from=ui ui/menu.ui -o ui/menu_ui.py
pyuic5 --import-from=ui ui/game.ui -o ui/game_ui.py
pyuic5 --import-from=ui ui/endgame.ui -o ui/endgame_ui.py
pyuic5 --import-from=ui ui/options.ui -o ui/options_ui.py
pyuic5 --import-from=ui ui/authquick.ui -o ui/authquick_ui.py
pyuic5 --import-from=ui ui/authleague.ui -o ui/authleague_ui.py
pyuic5 --import-from=ui ui/leaderboard.ui -o ui/leaderboard_ui.py
pyuic5 --import-from=ui ui/privacy.ui -o ui/privacy_ui.py
pyuic5 --import-from=Babyfut.ui ui/main.ui -o ui/main_ui.py
pyuic5 --import-from=Babyfut.ui ui/menu.ui -o ui/menu_ui.py
pyuic5 --import-from=Babyfut.ui ui/game.ui -o ui/game_ui.py
pyuic5 --import-from=Babyfut.ui ui/endgame.ui -o ui/endgame_ui.py
pyuic5 --import-from=Babyfut.ui ui/options.ui -o ui/options_ui.py
pyuic5 --import-from=Babyfut.ui ui/authquick.ui -o ui/authquick_ui.py
pyuic5 --import-from=Babyfut.ui ui/authleague.ui -o ui/authleague_ui.py
pyuic5 --import-from=Babyfut.ui ui/leaderboard.ui -o ui/leaderboard_ui.py
pyuic5 --import-from=Babyfut.ui ui/privacy.ui -o ui/privacy_ui.py
echo " Custom Widgets"
pyuic5 --import-from=ui ui/playerlist.ui -o ui/playerlist_ui.py
pyuic5 --import-from=ui ui/delete_dialog.ui -o ui/delete_dialog_ui.py
pyuic5 --import-from=ui ui/consent_dialog.ui -o ui/consent_dialog_ui.py
pyuic5 --import-from=Babyfut.ui ui/playerlist.ui -o ui/playerlist_ui.py
pyuic5 --import-from=Babyfut.ui ui/delete_dialog.ui -o ui/delete_dialog_ui.py
pyuic5 --import-from=Babyfut.ui ui/consent_dialog.ui -o ui/consent_dialog_ui.py
echo " Resources"
pyrcc5 -root /ui ui/assets.qrc -o ui/assets_rc.py
pyrcc5 -root /Babyfut/ui ui/assets.qrc -o ui/assets_rc.py
echo "Done."
;;
"clean"|"clear")
......@@ -36,6 +36,7 @@ case "$1" in
rm -rf __pycache__
rm -rf ui/__pycache__
rm -rf core/__pycache__
rm -rf modules/__pycache__
echo "Done."
;;
......@@ -58,6 +59,10 @@ case "$1" in
bash ./devtools.sh "clean"
bash ./devtools.sh "all"
;;
"exec")
cd ..
python -m Babyfut.babyfut
;;
*)
echo "Unknown command \"$1\". See content of script for available commands."
;;
......
from modules.authquick import AuthQuickModule
from modules.authleague import AuthLeagueModule
from modules.game import GameModule
from modules.endgame import EndGameModule
from modules.menu import MenuModule
from modules.options import OptionsModule
from modules.leaderboard import LeaderboardModule
from modules.privacy import PrivacyModule
from Babyfut.modules.authquick import AuthQuickModule
from Babyfut.modules.authleague import AuthLeagueModule
from Babyfut.modules.game import GameModule
from Babyfut.modules.endgame import EndGameModule
from Babyfut.modules.menu import MenuModule
from Babyfut.modules.options import OptionsModule
from Babyfut.modules.leaderboard import LeaderboardModule
from Babyfut.modules.privacy import PrivacyModule
......@@ -8,9 +8,9 @@ import logging
from PyQt5.QtCore import Qt
import modules
from module import Module
from player import Side, Player
from Babyfut import modules
from Babyfut.core.module import Module
from Babyfut.core.player import Side, Player
class AuthModuleBase(Module):
def __init__(self, parent, widget):
......
......@@ -7,12 +7,11 @@
import logging
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QAbstractItemView
from modules.auth import AuthModuleBase
from ui.authleague_ui import Ui_Form as AuthLeagueWidget
from player import Side, PlayerEmpty
from Babyfut.modules.auth import AuthModuleBase
from Babyfut.ui.authleague_ui import Ui_Form as AuthLeagueWidget
from Babyfut.core.player import Side, PlayerEmpty
class AuthLeagueModule(AuthModuleBase):
def __init__(self, parent):
......@@ -49,9 +48,9 @@ class AuthLeagueModule(AuthModuleBase):
# Update the left side description
player.displayImg(self.ui.img)
self.ui.lblName.setText(player.name)
self.ui.lblStat1.setText(_translate('{} Victories').format(player.stats['victories']))
self.ui.lblStat2.setText(_translate('{} Games Played').format(player.stats['games_played']))
self.ui.lblStat3.setText(_translate('{} Goals Scored').format(player.stats['goals_scored']))
self.ui.lblStat1.setText(_translate('Form', '{} Victories').format(player.stats['victories']))
self.ui.lblStat2.setText(_translate('Form', '{} Games Played').format(player.stats['games_played']))
self.ui.lblStat3.setText(_translate('Form', '{} Goals Scored').format(player.stats['goals_scored']))
if player!=PlayerEmpty:
# Update the right side list, making sure that the added player is showed
......
......@@ -8,9 +8,9 @@ import logging
from PyQt5.QtWidgets import QSizePolicy
from modules.auth import AuthModuleBase
from player import Side, PlayerGuest
from ui.authquick_ui import Ui_Form as AuthQuickWidget
from Babyfut.modules.auth import AuthModuleBase
from Babyfut.core.player import Side, PlayerGuest
from Babyfut.ui.authquick_ui import Ui_Form as AuthQuickWidget
class AuthQuickModule(AuthModuleBase):
def __init__(self, parent):
......
......@@ -9,11 +9,11 @@ import logging
from PyQt5 import QtWidgets
from PyQt5.QtCore import QTimer, Qt
from database import Database
from player import Side, PlayerGuest
from module import Module
import modules
from ui.endgame_ui import Ui_Form as EndGameWidget
from Babyfut import modules
from Babyfut.core.database import Database
from Babyfut.core.player import Side, PlayerGuest
from Babyfut.core.module import Module
from Babyfut.ui.endgame_ui import Ui_Form as EndGameWidget
class EndGameModule(Module):
def __init__(self, parent=None):
......
......@@ -14,12 +14,12 @@ from PyQt5.QtCore import QDateTime, QDate, QTime, QTimer, QRect, Qt, QUrl
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from player import Side, PlayerGuest
from replay import Replay
from module import Module
from settings import Settings
import modules
from ui.game_ui import Ui_Form as GameWidget
from Babyfut import modules
from Babyfut.core.player import Side, PlayerGuest
from Babyfut.core.replay import Replay
from Babyfut.core.module import Module
from Babyfut.core.settings import Settings
from Babyfut.ui.game_ui import Ui_Form as GameWidget
class GameOverChecker():
def __init__(self, conditionType, limit):
......
......@@ -11,14 +11,13 @@ from operator import attrgetter
from PyQt5.QtWidgets import QWidget, QDialog, QListWidgetItem
from PyQt5.QtCore import Qt, QItemSelectionModel
import modules
from module import Module
from player import Player, Side
from database import Database
from ui.leaderboard_ui import Ui_Form as LeaderboardWidget
from ui.playerlist_ui import Ui_Form as PlayerListWidget
from ui.delete_dialog_ui import Ui_Dialog as PlayerDeleteDialog
from Babyfut import modules
from Babyfut.core.module import Module
from Babyfut.core.player import Player, Side
from Babyfut.core.database import Database
from Babyfut.ui.leaderboard_ui import Ui_Form as LeaderboardWidget
from Babyfut.ui.playerlist_ui import Ui_Form as PlayerListWidget
from Babyfut.ui.delete_dialog_ui import Ui_Dialog as PlayerDeleteDialog
class LeaderboardItemWidget(QWidget):
def __init__(self, parent, player):
......@@ -98,6 +97,7 @@ class LeaderboardModule(Module):
def unload(self):
logging.debug('Unloading LeaderboardModule')
self.players = []
self.ui.listWidget.clear()
def other(self, **kwargs):
logging.debug('Other LeaderboardModule')
......
......@@ -9,11 +9,11 @@ import logging
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
import modules
from module import Module
from settings import Settings
from ui.menu_ui import Ui_Form as MenuWidget
from player import Side
from Babyfut import modules
from Babyfut.core.module import Module
from Babyfut.core.settings import Settings
from Babyfut.ui.menu_ui import Ui_Form as MenuWidget
from Babyfut.core.player import Side
class MenuModule(Module):
def __init__(self, parent):
......
......@@ -9,10 +9,10 @@ import logging
from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtWidgets import QRadioButton, QSlider
from settings import Settings
from module import Module
import modules
from ui.options_ui import Ui_Form as OptionsWidget
from Babyfut import modules
from Babyfut.core.settings import Settings
from Babyfut.core.module import Module
from Babyfut.ui.options_ui import Ui_Form as OptionsWidget
class OptionsModule(Module):
def __init__(self, parent):
......
......@@ -8,9 +8,9 @@ import logging
from PyQt5.QtCore import Qt, QCoreApplication
from module import Module
import modules
from ui.privacy_ui import Ui_Form as PrivacyWidget
from Babyfut import modules
from Babyfut.core.module import Module
from Babyfut.ui.privacy_ui import Ui_Form as PrivacyWidget
class PrivacyModule(Module):
def __init__(self, parent):
......
......@@ -276,24 +276,6 @@
</context>
<context>
<name>consent</name>
<message>
<location filename="../player.py" line="36"/>
<source>&lt;p&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>You are about to connect yourself for the first time. We will need to access:
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;ul&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;Your Name and Surname&lt;/li&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;Your Picture (if public)&lt;/li&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;...&lt;/li&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;/ul&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;/p&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;p&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>It is possible to play withtout connecting yourslef, but this will allow you to keep track of your score and to provide a better experience for you and the ones you play with!
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;br/&gt;&lt;br/&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>Do you agree with this?
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../modules/privacy.py" line="18"/>
<source>&lt;p&gt;
......
......@@ -11,8 +11,8 @@ from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication
from PyQt5.QtCore import QTime, Qt
from ui.main_ui import Ui_MainWindow
import modules
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut import modules
class MainWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
......@@ -73,7 +73,7 @@ class MainWin(QtWidgets.QMainWindow):
self.modules[modIdx].other(**msg)
def _loadSettings(self):
from settings import Settings
from Babyfut.core.settings import Settings
if Settings['ui.fullscreen']:
self.showFullScreen()
......
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