Skip to content

Commit bc5df1e

Browse files
committed
Fix GUI status for games
1 parent 45547a8 commit bc5df1e

5 files changed

Lines changed: 110 additions & 144 deletions

File tree

‎app.py‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ def fmtTime(ts):
5454
def loadPix(url):
5555
_pixmap = QPixmap()
5656
try:
57-
_pixmap.loadFromData(requests.get(url, verify = False, timeout = 10).content)
58-
except Exception:
59-
pass
57+
r = requests.get(url, verify = False, timeout = 10)
58+
ok = _pixmap.loadFromData(r.content)
59+
# log('Image: %s -> HTTP %s, %s bytes, %s' % (url, r.status_code, len(r.content), 'decoded' if ok else 'INVALID DATA'))
60+
except Exception as e:
61+
log('Image load error: %s -> %s' % (url, e))
6062
return _pixmap
6163

6264
def up(_label,image):
6365
_label.clear()
6466
if isinstance(image,str):
6567
image = loadPix(image)
68+
if not image.isNull():
69+
image = image.scaled(_label.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
6670
_label.setPixmap(image)
6771

6872
class GUI(Ui_MainWindow):
@@ -201,7 +205,7 @@ def updateProfile(self):
201205
if not console:
202206
return
203207
self.miiLabel.setScaledContents(True)
204-
self.gameIcon.setScaledContents(True)
208+
self.gameIcon.setScaledContents(False)
205209
self.setFontText(self.username, console.get('username', ''))
206210
if console.get('mii'):
207211
up(self.miiLabel, console['mii']['face'])
@@ -307,15 +311,20 @@ def update(self, data):
307311
self.updateProfile()
308312
self.updateDetails()
309313
if data:
310-
self.gamePlate.show()
314+
self.gameIcon.show()
315+
self.gameName.show()
311316
game = client.userData['consoles'][0]['Presence']['game']
312317
publisher = (game.get('publisher') or {}).get('name', '')
313-
self.gamePlate.mouseReleaseEvent = lambda a : self.openLink('https://www.google.com/search?q=%s' % '+'.join((game['name'] + ' ' + publisher).split(' ')))
314-
if data.get('large_image') and not client.local:
318+
self.gameIcon.mouseReleaseEvent = lambda a : self.openLink('https://www.google.com/search?q=%s' % '+'.join((game['name'] + ' ' + publisher).split(' ')))
319+
self.gameName.mouseReleaseEvent = lambda a : self.openLink('https://www.google.com/search?q=%s' % '+'.join((game['name'] + ' ' + publisher).split(' ')))
320+
if data.get('large_image'):
315321
up(self.gameIcon, data['large_image'])
322+
else:
323+
log('No game image shown: large_image=%r' % data.get('large_image'))
316324
self.setFontText(self.gameName, data['details'])
317325
else:
318-
self.gamePlate.hide()
326+
self.gameIcon.hide()
327+
self.gameName.hide()
319328
self.underLyingButton.click()
320329
except Exception as e:
321330
print('Update error: %s' % e)

‎client.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def loop(self):
197197

198198
presence = console['Presence']
199199
game = presence['game']
200+
img_url = game.get('banner_url') or game.get('icon_url')
201+
log('Game image URL: %r (banner=%r icon=%r)' % (img_url, game.get('banner_url'), game.get('icon_url')))
200202

201203
if self.currentGame != game:
202204
logger += ' [%s -> %s]' % (self.currentGame['@id'], game['@id'])
@@ -210,16 +212,16 @@ def loop(self):
210212
# Include View Profile setting?
211213
# Certainly something when presence['joinable'] == True
212214
}
213-
if game.get('icon_url'):
214-
kwargs['large_image'] = game['icon_url'].replace('/cdn/', self.host + '/cdn/')
215+
if img_url:
216+
kwargs['large_image'] = img_url.replace('/cdn/', self.host + '/cdn/')
215217
kwargs['large_text'] = game['name']
216218
if presence.get('gameDescription'):
217219
kwargs['state'] = presence['gameDescription']
218220
if self.showProfileButton and console.get('username'):
219221
kwargs['buttons'] = [{'label': 'Profile', 'url': self.host + '/user/' + console['friendCode'] + '?network=' + console.get('network', '')},]
220222
if self.showElapsed:
221223
kwargs['start'] = self.start
222-
if self.showSmallImage and console.get('username') and game.get('icon_url'):
224+
if self.showSmallImage and console.get('username') and img_url:
223225
kwargs['small_image'] = console['mii']['face']
224226
kwargs['small_text'] = '-'.join(console['friendCode'][i:i+4] for i in range(0, 12, 4))
225227
for key in list(kwargs): # Blatant rip from OpenEmuRPC (also made by me. Check it out if you want)

‎layout/__init__.py‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,47 +153,38 @@ def setupUi(self, MainWindow):
153153
self.refreshButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
154154
self.refreshButton.setObjectName("refreshButton")
155155
self.friendCard = QtWidgets.QGroupBox(self.main)
156-
self.friendCard.setGeometry(QtCore.QRect(80, 115, 451, 231))
156+
self.friendCard.setGeometry(QtCore.QRect(80, 115, 451, 260))
157157
self.friendCard.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
158158
self.friendCard.setTitle("")
159159
self.friendCard.setObjectName("friendCard")
160-
self.namePlate = QtWidgets.QGroupBox(self.friendCard)
161-
self.namePlate.setGeometry(QtCore.QRect(0, 170, 451, 81))
162-
self.namePlate.setTitle("")
163-
self.namePlate.setObjectName("namePlate")
164-
self.username = QtWidgets.QLabel(self.namePlate)
165-
self.username.setGeometry(QtCore.QRect(280, 10, 151, 41))
166-
self.username.setText("")
167-
self.username.setAlignment(QtCore.Qt.AlignCenter)
168-
self.username.setObjectName("username")
169160
self.status = QtWidgets.QLabel(self.friendCard)
170-
self.status.setGeometry(QtCore.QRect(10, 10, 101, 21))
161+
self.status.setGeometry(QtCore.QRect(12, 10, 101, 21))
171162
self.status.setText("")
172163
self.status.setObjectName("status")
173164
self.miiLabel = QtWidgets.QLabel(self.friendCard)
174-
self.miiLabel.setGeometry(QtCore.QRect(280, 20, 151, 151))
165+
self.miiLabel.setGeometry(QtCore.QRect(268, 45, 140, 140))
175166
self.miiLabel.setText("")
176167
self.miiLabel.setObjectName("miiLabel")
177-
self.closeButton = QtWidgets.QPushButton(self.main)
178-
self.closeButton.setGeometry(QtCore.QRect(70, 570, 461, 61))
179-
self.closeButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
180-
self.closeButton.setObjectName("closeButton")
181-
self.gamePlate = QtWidgets.QGroupBox(self.main)
182-
self.gamePlate.setGeometry(QtCore.QRect(30, 155, 321, 111))
183-
self.gamePlate.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
184-
self.gamePlate.setVisible(False)
185-
self.gamePlate.setTitle("")
186-
self.gamePlate.setObjectName("gamePlate")
187-
self.gameIcon = QtWidgets.QLabel(self.gamePlate)
188-
self.gameIcon.setGeometry(QtCore.QRect(20, 30, 51, 51))
168+
self.username = QtWidgets.QLabel(self.friendCard)
169+
self.username.setGeometry(QtCore.QRect(238, 195, 200, 35))
170+
self.username.setText("")
171+
self.username.setAlignment(QtCore.Qt.AlignCenter)
172+
self.username.setObjectName("username")
173+
self.gameIcon = QtWidgets.QLabel(self.friendCard)
174+
self.gameIcon.setGeometry(QtCore.QRect(38, 40, 150, 150))
189175
self.gameIcon.setText("")
190176
self.gameIcon.setObjectName("gameIcon")
191-
self.gameName = QtWidgets.QLabel(self.gamePlate)
192-
self.gameName.setGeometry(QtCore.QRect(80, 40, 231, 31))
177+
self.gameName = QtWidgets.QLabel(self.friendCard)
178+
self.gameName.setGeometry(QtCore.QRect(13, 200, 200, 35))
193179
self.gameName.setText("")
180+
self.gameName.setAlignment(QtCore.Qt.AlignCenter)
194181
self.gameName.setObjectName("gameName")
182+
self.closeButton = QtWidgets.QPushButton(self.main)
183+
self.closeButton.setGeometry(QtCore.QRect(70, 570, 461, 61))
184+
self.closeButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
185+
self.closeButton.setObjectName("closeButton")
195186
self.detailsCard = QtWidgets.QGroupBox(self.main)
196-
self.detailsCard.setGeometry(QtCore.QRect(80, 375, 451, 135))
187+
self.detailsCard.setGeometry(QtCore.QRect(80, 385, 451, 135))
197188
self.detailsCard.setTitle("")
198189
self.detailsCard.setObjectName("detailsCard")
199190
self.networkDetail = QtWidgets.QLabel(self.detailsCard)

0 commit comments

Comments
 (0)