1
0
Fork 0
mirror of synced 2024-06-24 01:00:43 +12:00

Add socail links to game info

This commit is contained in:
Dummerle 2021-09-05 21:25:57 +02:00
parent 59cf52ec77
commit f8560b206f
4 changed files with 124 additions and 52 deletions

View file

@ -2,7 +2,8 @@ import logging
import webbrowser
from PyQt5.QtGui import QPixmap, QFont
from PyQt5.QtWidgets import QWidget, QLabel
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QHBoxLayout
from qtawesome import icon
from rare.components.tabs.shop.shop_models import ShopGame
from rare.ui.components.tabs.store.shop_game_info import Ui_shop_info
@ -124,7 +125,14 @@ class ShopGameInfo(QWidget, Ui_shop_info):
else:
self.req_group_box.layout().addWidget(QLabel(self.tr("Could not get requirements")))
self.image.update_image(self.game.image_urls.front_tall, self.game.title, (240, 320))
if self.game.image_urls.front_tall:
img = self.game.image_urls.front_tall
elif self.game.image_urls.offer_image_tall:
img = self.game.image_urls.offer_image_tall
else:
img = ""
self.image.update_image(img, self.game.title, (240, 320))
self.image_stack.setCurrentIndex(0)
try:
@ -136,6 +144,34 @@ class ShopGameInfo(QWidget, Ui_shop_info):
pass
self.tags.setText(", ".join(self.game.tags))
# clear Layout
QWidget().setLayout(self.social_link_gb.layout())
self.social_link_gb.setLayout(QHBoxLayout())
self.social_link_gb.layout().addStretch(1)
link_count = 0
for name, url in self.game.links:
if name.lower() == "homepage":
icn = icon("mdi.web", scale_factor=1.5)
else:
try:
icn = icon("mdi." + name.lower(), scale_factor=1.5)
except Exception as e:
logger.error(str(e))
continue
button = SocialButton(icn, url)
self.social_link_gb.layout().addWidget(button)
link_count += 1
self.social_link_gb.layout().addStretch(1)
if link_count == 0:
self.social_link_gb.setVisible(False)
else:
self.social_link_gb.setVisible(True)
self.social_link_gb.layout().addStretch(1)
def add_wishlist_items(self, wishlist):
wishlist = wishlist["data"]["Wishlist"]["wishlistItems"]["elements"]
for game in wishlist:
@ -143,3 +179,11 @@ class ShopGameInfo(QWidget, Ui_shop_info):
def button_clicked(self):
webbrowser.open("https://www.epicgames.com/store/de/p/" + self.slug)
class SocialButton(QPushButton):
def __init__(self, icn, url):
super(SocialButton, self).__init__(icn, "")
self.url = url
self.clicked.connect(lambda: webbrowser.open(url))
self.setToolTip(url)

View file

@ -64,7 +64,10 @@ class ShopGame:
api_data = product
break
if "pages" in api_data.keys():
api_data = api_data["pages"][0]
for page in api_data["pages"]:
if page["_slug"] == "home":
api_data = page
break
tmp = cls()
tmp.title = search_data.get("title", "Fail")
tmp.image_urls = ImageUrlModel.from_json(search_data["keyImages"])

View file

@ -23,6 +23,11 @@ class Ui_shop_info(object):
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.image_stack = QtWidgets.QStackedWidget(shop_info)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.image_stack.sizePolicy().hasHeightForWidth())
self.image_stack.setSizePolicy(sizePolicy)
self.image_stack.setObjectName("image_stack")
self.horizontalLayout.addWidget(self.image_stack)
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
@ -81,6 +86,11 @@ class Ui_shop_info(object):
self.gridLayout_2 = QtWidgets.QGridLayout(self.req_group_box)
self.gridLayout_2.setObjectName("gridLayout_2")
self.verticalLayout.addWidget(self.req_group_box)
self.social_link_gb = QtWidgets.QGroupBox(shop_info)
self.social_link_gb.setObjectName("social_link_gb")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.social_link_gb)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout.addWidget(self.social_link_gb)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
@ -101,6 +111,7 @@ class Ui_shop_info(object):
self.open_store_button.setText(_translate("shop_info", "Buy Game in Epic Games Store"))
self.wishlist_button.setText(_translate("shop_info", "Add to wishlist"))
self.req_group_box.setTitle(_translate("shop_info", "Requirements"))
self.social_link_gb.setTitle(_translate("shop_info", "Social Links"))
if __name__ == "__main__":

View file

@ -25,27 +25,33 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QStackedWidget" name="image_stack">
<property name="currentIndex">
<number>-1</number>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="title">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Error</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
<widget class="QLabel" name="title">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Error</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="dev">
@ -62,23 +68,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="owned_label">
<property name="text">
<string>You already own this game</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="price">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="owned_label">
<property name="text">
<string>You already own this game</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="price">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="discount_price">
<property name="text">
@ -149,22 +155,30 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="req_group_box">
<property name="title">
<string>Requirements</string>
</property>
<layout class="QGridLayout" name="gridLayout_2"/>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<item>
<widget class="QGroupBox" name="req_group_box">
<property name="title">
<string>Requirements</string>
</property>
<layout class="QGridLayout" name="gridLayout_2"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="social_link_gb">
<property name="title">
<string>Social Links</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</widget>
</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>