Commit 72b509e5 authored by Antoine Lima's avatar Antoine Lima

Fixed profile pictures not displaying!!

parent efbf04ba
......@@ -46,9 +46,13 @@ class Downloader(Thread, QObject):
if nAttemps==None:
nAttemps = Downloader.N_ATTEMPS
print('Adding "{}". {} before it'.format(url_in, len(self._request_stack)))
self._request_stack.append((url_in, uri_out, nAttemps))
# Add if not already queued
req = (url_in, uri_out, nAttemps)
if req not in self._request_stack:
logging.debug('Adding "{}". {} before it'.format(url_in, len(self._request_stack)))
self._request_stack.append(req)
else:
logging.debug('"{}" is already queued, ignoring.'.format(url_in))
def run(self):
while not self._close:
......
......@@ -4,6 +4,7 @@
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""
import os
import logging
from enum import Enum
from http import HTTPStatus
......@@ -13,6 +14,7 @@ from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QDialog, QApplication
from Babyfut.babyfut import getMainWin, IMG_PATH
from Babyfut.core.downloader import Downloader
from Babyfut.core.ginger import Ginger
from Babyfut.core.database import Database, DatabaseError
from Babyfut.ui.consent_dialog_ui import Ui_Dialog as ConsentDialogUI
......@@ -62,6 +64,7 @@ class Player(QObject):
__query_victories = 'SELECT COUNT(*) AS victories FROM Players INNER JOIN Teams ON (Players.id==Teams.player1 OR Players.id==Teams.player2) INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam) WHERE Players.id==?'
_placeholder_pic_path = ':ui/img/placeholder_head.jpg'
_utcPictureURL = 'https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username={}'
def __init__(self, id, rfid, login, fname, lname, stats=None):
QObject.__init__(self)
......@@ -98,7 +101,6 @@ class Player(QObject):
return player
def displayImg(self, container_widget):
@staticmethod
def _loadFromDB(rfid):
db = Database.instance()
......@@ -128,7 +130,7 @@ class Player(QObject):
'''
response = Ginger.call('badge/{}'.format(rfid))
if isinstance(response, HTTPStatus):
logging.debug('Request to Ginger failed ({}): returning Guest'.format(response.value))
logging.warn('Request to Ginger failed ({}): returning Guest'.format(response.value))
return PlayerGuest
else:
infos = json.loads(response)
......@@ -136,24 +138,28 @@ class Player(QObject):
return Player._loadFromDB(rfid)
def displayImg(self, container_widget, *args):
self.pic_container = container_widget
if self.pic_path.startswith('http'):
# Download from the internet
# Download from the internet but display a temporary image between
self.pic_container.setStyleSheet('border-image: url({});'.format(Player._placeholder_pic_path))
Downloader.instance().request(self.pic_path, os.path.join(IMG_PATH, '{}.jpg'.format(self.id)))
Downloader.instance().finished.connect(self._downloader_callback)
else:
# Already downloaded and stored locally
self.pic_container.setStyleSheet('border-image: url({});'.format(self.pic_path))
self._forceWidgetUpdate()
QApplication.processEvents()
@pyqtSlot(str)
def _downloader_callback(self, path):
self.pic_path = path
Downloader.instance().finished.disconnect(self._downloader_callback)
self.displayImg(self.pic_container)
# Take the callback if not already done and we are the targer
if IMG_PATH in path and str(self.id) in path and IMG_PATH not in self.pic_path:
self.pic_path = path
Downloader.instance().finished.disconnect(self._downloader_callback)
if self.pic_container!=None:
self.displayImg(self.pic_container)
def forgetPicture(self):
self.pic_path = Player._placeholder_pic_path
......
......@@ -46,12 +46,12 @@
<translation>Form</translation>
</message>
<message>
<location filename="../ui/authquick_ui.py" line="231"/>
<location filename="../ui/authquick_ui.py" line="222"/>
<source>Identify yourselves! </source>
<translation>Identifiez vous ! </translation>
</message>
<message>
<location filename="../ui/authquick_ui.py" line="232"/>
<location filename="../ui/authquick_ui.py" line="223"/>
<source>Use the table&apos;s RFID reader with your card.</source>
<translation>Utilisez les lecteurs RFID de la table avec votre carte étu.</translation>
</message>
......@@ -61,7 +61,7 @@
<translation>Nom</translation>
</message>
<message>
<location filename="../ui/authleague_ui.py" line="147"/>
<location filename="../ui/authleague_ui.py" line="138"/>
<source>Stat</source>
<translation>Stat</translation>
</message>
......@@ -76,17 +76,17 @@
<translation>Joueur 2</translation>
</message>
<message>
<location filename="../ui/authquick_ui.py" line="235"/>
<location filename="../ui/authquick_ui.py" line="226"/>
<source>vs.</source>
<translation>vs .</translation>
</message>
<message>
<location filename="../ui/authquick_ui.py" line="236"/>
<location filename="../ui/authquick_ui.py" line="227"/>
<source>Player 3</source>
<translation>Joueur 3</translation>
</message>
<message>
<location filename="../ui/authquick_ui.py" line="237"/>
<location filename="../ui/authquick_ui.py" line="228"/>
<source>Player 4</source>
<translation>Joueur 4</translation>
</message>
......
......@@ -97,36 +97,15 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="img">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="img" native="true">
<property name="minimumSize">
<size>
<width>300</width>
<height>300</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......
......@@ -107,9 +107,9 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="imgP1">
<widget class="QWidget" name="imgP1" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -126,17 +126,8 @@
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......@@ -185,9 +176,9 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="imgP2">
<widget class="QWidget" name="imgP2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -204,14 +195,8 @@
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......@@ -337,9 +322,9 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="imgP3">
<widget class="QWidget" name="imgP3" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -356,14 +341,8 @@
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......@@ -412,9 +391,9 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="imgP4">
<widget class="QWidget" name="imgP4" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -431,14 +410,8 @@
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......
......@@ -69,13 +69,7 @@
<widget class="QWidget" name="widgetLayoutP1" native="true">
<layout class="QVBoxLayout" name="layoutP1">
<item>
<widget class="QLabel" name="imgP1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="imgP1" native="true">
<property name="minimumSize">
<size>
<width>400</width>
......@@ -84,18 +78,18 @@
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>300</height>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
<property name="baseSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......@@ -159,13 +153,7 @@
<widget class="QWidget" name="widgetLayoutP2" native="true">
<layout class="QVBoxLayout" name="layoutP2">
<item>
<widget class="QLabel" name="imgP2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="ImgP2" native="true">
<property name="minimumSize">
<size>
<width>400</width>
......@@ -174,18 +162,18 @@
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>300</height>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
<property name="baseSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="styleSheet">
<string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
</widget>
</item>
......
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