Commit 4cfbe44c authored by Antoine Lima's avatar Antoine Lima

Auto-translating software

parent 9ab100f3
......@@ -11,7 +11,7 @@ import sys
import logging
from os.path import dirname, abspath, join
from PyQt5 import QtWidgets, QtCore
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication
def getContent(path):
......@@ -28,11 +28,10 @@ def getMainWin():
return None
if __name__=='__main__':
print(__package__)
__package__ = 'Babyfut'
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
......@@ -41,12 +40,7 @@ if __name__=='__main__':
#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)
app = QtWidgets.QApplication(sys.argv)
lang = Settings['ui.language']
qtTranslator = QtCore.QTranslator()
if lang!='en' and qtTranslator.load("translations/babyfut_{}.qm".format(lang)):
app.installTranslator(qtTranslator)
app = QApplication(sys.argv)
myapp = MainWin()
if ReplayThread.isCamAvailable():
......
......@@ -15,11 +15,11 @@ class Module(QWidget):
self.mainwin = parent
self.ui = widget
self.ui.setupUi(self)
def switchModule(self, new_type):
curmod_idx = self.mainwin.findMod(type(self))
newmod_idx = self.mainwin.findMod(new_type)
if curmod_idx<0:
logging.error('Unknown panel {}'.format(type(self)))
elif newmod_idx<0:
......@@ -28,26 +28,27 @@ class Module(QWidget):
# Unfocus the current module
if QApplication.focusWidget() != None:
QApplication.focusWidget().clearFocus()
# Swap modules by unloading, changing the ui then loading
self.mainwin.modules[curmod_idx].unload()
self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx])
self.mainwin.modules[newmod_idx].setFocus()
# Select first element of the Module
self.mainwin.modules[newmod_idx].focusNextChild()
self.mainwin.modules[newmod_idx].focusPreviousChild()
self.mainwin.modules[newmod_idx].ui.retranslateUi(self.mainwin)
self.mainwin.modules[newmod_idx].load()
def send(self, to, **kwargs):
mod_idx = self.mainwin.findMod(to)
if mod_idx<0:
logging.error('Unknown panel {}'.format(to))
else:
self.mainwin.modules[mod_idx].other(**kwargs)
def load(self):
logging.warning('Unimplemented method "load" for {}'.format(self.__class__))
......
......@@ -245,6 +245,21 @@
<source>Privacy</source>
<translation>Vie Privée</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="51"/>
<source>{} Victories</source>
<translation>{} Victoires</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="52"/>
<source>{} Games Played</source>
<translation>{} Parties Jouées</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="53"/>
<source>{} Goals Scored</source>
<translation>{} Buts Marqués</translation>
</message>
<message encoding="UTF-8">
<location filename="../ui/options_ui.py" line="229"/>
<source>Français</source>
......@@ -285,7 +300,7 @@
<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"/>&lt;li&gt;...&lt;/li&gt;
<byte value="x9"/><byte value="x9"/>&lt;/ul&gt;
<byte value="x9"/><byte value="x9"/>&lt;/p&gt;
<byte value="x9"/><byte value="x9"/>&lt;/p&gt;
<byte value="x9"/><byte value="x9"/>&lt;p&gt;
<byte value="x9"/><byte value="x9"/>That way players can keep track of their score and compare it with others.
......
......@@ -5,20 +5,28 @@
"""
import os
from os.path import join, dirname, abspath
import logging
OnRasp = os.uname()[1] == 'raspberrypi'
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication
from PyQt5.QtCore import QTime, Qt
from PyQt5.QtCore import Qt, QTime, QTranslator
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut import modules
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut.core.settings import Settings
class MainWin(QtWidgets.QMainWindow):
DEFAULT_LANG = 'en'
TR_PATH = join(dirname(dirname(abspath(__file__))), 'translations/')
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.lang = MainWin.DEFAULT_LANG
self._retranslateUI()
#Background blur
bgBlur = QGraphicsBlurEffect()
......@@ -73,11 +81,34 @@ class MainWin(QtWidgets.QMainWindow):
self.modules[modIdx].other(**msg)
def _loadSettings(self):
from Babyfut.core.settings import Settings
if Settings['ui.fullscreen']:
self.showFullScreen()
QApplication.setOverrideCursor(Qt.BlankCursor);
else:
self.showNormal()
QApplication.setOverrideCursor(Qt.ArrowCursor);
self._retranslateUI()
def _retranslateUI(self):
app = QApplication.instance()
oldlang = self.lang
newlang = Settings['ui.language']
if newlang==oldlang:
pass # Nothing to do
elif newlang!=MainWin.DEFAULT_LANG:
self.translator = QTranslator()
if self.translator.load("babyfut_{}".format(newlang), MainWin.TR_PATH):
logging.info('Installing \'{}\''.format(newlang))
app.installTranslator(self.translator)
else:
logging.warn('Could not open translation file for \'{}\' in path "{}"'.format(newlang, MainWin.TR_PATH))
elif newlang==MainWin.DEFAULT_LANG:
logging.info('Installing language \'{}\''.format(newlang))
app.removeTranslator(self.translator)
self.translator = None
self.lang = newlang
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