diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2ae923f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/images/ diff --git a/Rare.py b/Rare.py index e37e6a12..790ceefa 100644 --- a/Rare.py +++ b/Rare.py @@ -425,46 +425,48 @@ def startMainProcess(loggedIn=False): # Since some games have the background and logo split into two files, # we have to do some extra logic to combine those if not os.path.isfile('images/' + game["app_name"] + '/FinalArt.png'): - print('Scaling cover for ' + game["app_name"]) - # First off, check if the extra logo file is even there - if os.path.isfile('images/' + game["app_name"] + '/DieselGameBoxLogo.png'): - # Load in the two images that need to be combined - bg = Image.open('images/' + game["app_name"] + '/DieselGameBoxTall.png') - # To make sure the background is actually horizontal (3/4) (looking at you Celeste), resize the image - bg = bg.resize((int(bg.size[1] * 3 / 4), bg.size[1])) - # Since the logo is transparent, we have to convert it to RGBA - logo = Image.open('images/' + game["app_name"] + '/DieselGameBoxLogo.png').convert('RGBA') - # Resize the logo to be ~ 3/4 as wide as the background (EGL does something like this) - wpercent = ((bg.size[0] * (3 / 4)) / float(logo.size[0])) - hsize = int((float(logo.size[1]) * float(wpercent))) - logo = logo.resize((int(bg.size[0] * (3 / 4)), hsize), Image.ANTIALIAS) - # Calculate where the image has to be placed - pasteX = int((bg.size[0] - logo.size[0]) / 2) - pasteY = int((bg.size[1] - logo.size[1]) / 2) - # And finally copy the background and paste in the image - finalArt = bg.copy() - finalArt.paste(logo, (pasteX, pasteY), logo) - # Write out the file - finalArt.save('images/' + game["app_name"] + '/FinalArt.png') - - # And we have to do part of that again - # since the cover for an uninstalled game has the logo half-transparent - logoCopy = logo.copy() - logoCopy.putalpha(int(256 * 3 / 4)) - logo.paste(logoCopy, logo) - uninstalledArt = bg.copy() - uninstalledArt.paste(logo, (pasteX, pasteY), logo) - uninstalledArt = uninstalledArt.convert('L') - uninstalledArt.save('images/' + game["app_name"] + '/UninstalledArt.png') - # And if the logo and background aren't split - else: - # We just open up the background and save that as the final image - finalArt = Image.open('images/' + game["app_name"] + '/DieselGameBoxTall.png') - finalArt.save('images/' + game["app_name"] + '/FinalArt.png') - # And same with the grayscale one - uninstalledArt = finalArt.convert('L') - uninstalledArt.save('images/' + game["app_name"] + '/UninstalledArt.png') + try: + print('Scaling cover for ' + game["app_name"]) + # First off, check if the extra logo file is even there + if os.path.isfile('images/' + game["app_name"] + '/DieselGameBoxLogo.png'): + # Load in the two images that need to be combined + bg = Image.open('images/' + game["app_name"] + '/DieselGameBoxTall.png') + # To make sure the background is actually horizontal (3/4) (looking at you Celeste), resize the image + bg = bg.resize((int(bg.size[1] * 3 / 4), bg.size[1])) + # Since the logo is transparent, we have to convert it to RGBA + logo = Image.open('images/' + game["app_name"] + '/DieselGameBoxLogo.png').convert('RGBA') + # Resize the logo to be ~ 3/4 as wide as the background (EGL does something like this) + wpercent = ((bg.size[0] * (3 / 4)) / float(logo.size[0])) + hsize = int((float(logo.size[1]) * float(wpercent))) + logo = logo.resize((int(bg.size[0] * (3 / 4)), hsize), Image.ANTIALIAS) + # Calculate where the image has to be placed + pasteX = int((bg.size[0] - logo.size[0]) / 2) + pasteY = int((bg.size[1] - logo.size[1]) / 2) + # And finally copy the background and paste in the image + finalArt = bg.copy() + finalArt.paste(logo, (pasteX, pasteY), logo) + # Write out the file + finalArt.save('images/' + game["app_name"] + '/FinalArt.png') + # And we have to do part of that again + # since the cover for an uninstalled game has the logo half-transparent + logoCopy = logo.copy() + logoCopy.putalpha(int(256 * 3 / 4)) + logo.paste(logoCopy, logo) + uninstalledArt = bg.copy() + uninstalledArt.paste(logo, (pasteX, pasteY), logo) + uninstalledArt = uninstalledArt.convert('L') + uninstalledArt.save('images/' + game["app_name"] + '/UninstalledArt.png') + # And if the logo and background aren't split + else: + # We just open up the background and save that as the final image + finalArt = Image.open('images/' + game["app_name"] + '/DieselGameBoxTall.png') + finalArt.save('images/' + game["app_name"] + '/FinalArt.png') + # And same with the grayscale one + uninstalledArt = finalArt.convert('L') + uninstalledArt.save('images/' + game["app_name"] + '/UninstalledArt.png') + except: + pass #If the user had to login first, the QApplication will already be running, so we don't have to start it again if not loggedIn: # Start GUI stuff diff --git a/Rare/FlowLayout.py b/Rare/FlowLayout.py new file mode 100644 index 00000000..66441fce --- /dev/null +++ b/Rare/FlowLayout.py @@ -0,0 +1,92 @@ +from PyQt5 import Qt +from PyQt5.QtCore import QRect, QPoint, QSize +from PyQt5.QtWidgets import QSizePolicy, QLayout + + +class FlowLayout(QLayout): + def __init__(self, parent=None, margin=0, spacing=-1): + super(FlowLayout, self).__init__(parent) + + if parent is not None: + self.setContentsMargins(margin, margin, margin, margin) + + self.setSpacing(spacing) + + self.itemList = [] + + def __del__(self): + item = self.takeAt(0) + while item: + item = self.takeAt(0) + + def addItem(self, item): + self.itemList.append(item) + + def count(self): + return len(self.itemList) + + def itemAt(self, index): + if index >= 0 and index < len(self.itemList): + return self.itemList[index] + + return None + + def takeAt(self, index): + if index >= 0 and index < len(self.itemList): + return self.itemList.pop(index) + + return None + + def expandingDirections(self): + return Qt.Orientations(Qt.Orientation(0)) + + def hasHeightForWidth(self): + return True + + def heightForWidth(self, width): + height = self.doLayout(QRect(0, 0, width, 0), True) + return height + + def setGeometry(self, rect): + super(FlowLayout, self).setGeometry(rect) + self.doLayout(rect, False) + + def sizeHint(self): + return self.minimumSize() + + def minimumSize(self): + size = QSize() + + for item in self.itemList: + size = size.expandedTo(item.minimumSize()) + + margin, _, _, _ = self.getContentsMargins() + + size += QSize(2 * margin, 2 * margin) + return size + + def doLayout(self, rect, testOnly): + x = rect.x() + y = rect.y() + lineHeight = 0 + + for item in self.itemList: + wid = item.widget() + spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, + Qt.Horizontal) + spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, + Qt.Vertical) + nextX = x + item.sizeHint().width() + spaceX + if nextX - spaceX > rect.right() and lineHeight > 0: + x = rect.x() + y = y + lineHeight + spaceY + nextX = x + item.sizeHint().width() + spaceX + lineHeight = 0 + + if not testOnly: + item.setGeometry(QRect(QPoint(x, y), item.sizeHint())) + + x = nextX + lineHeight = max(lineHeight, item.sizeHint().height()) + + return y + lineHeight - rect.y() diff --git a/Rare/GameWidget.py b/Rare/GameWidget.py new file mode 100644 index 00000000..52b810a5 --- /dev/null +++ b/Rare/GameWidget.py @@ -0,0 +1,44 @@ +import qtawesome as qta +from PyQt5.QtGui import QPixmap +from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton + + +class GameWidget(QWidget): + def __init__(self, game): + super(GameWidget, self).__init__() + # self.setStyleSheet("border:1px solid rgb(0, 0, 0)") + + self.title = game.title + self.version = game.version + + self.layout = QHBoxLayout() + + + self.pixmap = QPixmap(f"../images/{game.app_name}/FinalArt.png") + self.pixmap = self.pixmap.scaled(240, 320) + self.image = QLabel() + self.image.setPixmap(self.pixmap) + self.layout.addWidget(self.image) + + ##Layout on the right + self.childLayout = QVBoxLayout() + + self.childLayout.addWidget(QLabel(f"