-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgui.py
More file actions
250 lines (208 loc) · 8.63 KB
/
gui.py
File metadata and controls
250 lines (208 loc) · 8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import sys
import os
import webbrowser
from PyQt5.QtWidgets import (QApplication, QMainWindow, QListWidget, QVBoxLayout, QWidget, QLineEdit, QLabel, QPushButton,
QHBoxLayout, QMenu, QAction, QMessageBox, QListWidgetItem, QDialog, QDialogButtonBox, QProgressBar)
from PyQt5.QtCore import pyqtSignal, QThread, QObject, QTimer, Qt
import json
import requests
from download import Downloader # Ensure you have a Downloader class in download.py
class GameDetailDialog(QDialog):
def __init__(self, title, description, url, parent=None):
super().__init__(parent)
self.setWindowTitle("Game Details")
self.setModal(True)
self.url = url
self.setStyleSheet("""
QDialog {
background-color: #121212;
color: #FFFFFF;
}
QLabel {
color: #FFFFFF;
}
QPushButton {
background-color: #007bff;
color: #FFFFFF;
padding: 10px;
border: none;
border-radius: 5px;
}
QPushButton:hover {
background-color: #0056b3;
}
QProgressBar {
background-color: #1E1E1E;
border: 2px solid #555555;
border-radius: 5px;
color: #FFFFFF;
}
""")
self.downloader = None
self.download_thread = None
layout = QVBoxLayout()
title_label = QLabel(f"<b>{title}</b>")
title_label.setStyleSheet("font-size: 18px;")
layout.addWidget(title_label)
description_label = QLabel(description)
layout.addWidget(description_label)
self.progress_bar = QProgressBar()
self.progress_bar.setValue(0)
layout.addWidget(self.progress_bar)
button_box = QDialogButtonBox()
self.download_button = QPushButton("Download")
self.download_button.clicked.connect(self.on_download_clicked)
button_box.addButton(self.download_button, QDialogButtonBox.AcceptRole)
button_box.addButton(QPushButton("Close"), QDialogButtonBox.RejectRole)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
self.setLayout(layout)
def on_download_clicked(self):
self.download_button.setEnabled(False)
self.progress_bar.setValue(0)
# Ensure the file name is valid and create the save path
file_name = os.path.basename(self.url.split('/')[-1])
save_directory = os.path.join(os.path.expanduser("~"), "SteamUnlockedLibrary")
save_path = os.path.join(save_directory, file_name)
# Ensure the directory exists
os.makedirs(save_directory, exist_ok=True)
# Print the save_path for debugging
print(f"Save path: {save_path}")
# Initialize Downloader with the URL and save path
self.downloader = Downloader(self.url, save_path)
self.download_thread = QThread()
self.downloader.moveToThread(self.download_thread)
self.downloader.progress.connect(self.progress_bar.setValue)
self.downloader.finished.connect(self.on_download_finished)
self.download_thread.started.connect(self.downloader.download)
self.download_thread.start()
def on_download_finished(self):
self.download_thread.quit()
self.download_thread.wait()
self.download_button.setEnabled(True)
QMessageBox.information(self, "Download Complete", "The download has completed successfully.")
class ScraperWorker(QObject):
games_fetched = pyqtSignal(list)
def __init__(self, driver_path, url):
super().__init__()
self.driver_path = driver_path
self.url = url
def run(self):
import scraper
scraper.get_game_list(self.games_fetched.emit, self.driver_path, self.url)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Game Finder")
self.setGeometry(100, 100, 1280, 720)
self.driver_path = "chromedriver.exe"
self.url = "https://steamunlocked.net/all-games-2/"
self.setStyleSheet("""
QMainWindow {
background-color: #121212;
}
QLabel {
color: #FFFFFF;
}
QLineEdit {
padding: 10px;
border: 2px solid #555555;
border-radius: 5px;
color: #FFFFFF;
background-color: #1E1E1E;
}
QLineEdit:focus {
border-color: #007bff;
}
QListWidget {
border: 1px solid #333333;
border-radius: 5px;
color: #FFFFFF;
background-color: #1E1E1E;
}
QListWidget::item {
padding: 10px;
background-color: #1E1E1E;
color: #FFFFFF;
}
QListWidget::item:selected {
background-color: #007bff;
color: #FFFFFF;
}
""")
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QVBoxLayout(self.central_widget)
self.header_label = QLabel("SteamUnlocked Downloader")
self.header_label.setStyleSheet("font-size: 24px; font-weight: bold; margin-bottom: 20px;")
self.layout.addWidget(self.header_label)
self.search_bar = QLineEdit()
self.search_bar.setPlaceholderText("Search for a game...")
self.layout.addWidget(self.search_bar)
self.search_bar.textChanged.connect(self.apply_filter)
self.game_list_widget = QListWidget()
self.layout.addWidget(self.game_list_widget)
self.game_list_widget.setContextMenuPolicy(Qt.CustomContextMenu)
self.game_list_widget.customContextMenuRequested.connect(self.show_context_menu)
self.game_list_widget.itemDoubleClicked.connect(self.show_game_details)
self.all_games = []
self.displayed_games = []
self.game_descriptions = {}
self.timer = QTimer()
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.update_displayed_games)
self.search_text = ""
self.load_cached_games()
def load_cached_games(self):
cached_games = []
if os.path.exists("cached_games.json"):
with open("cached_games.json", "r", encoding="utf-8") as file:
cached_games = json.load(file)
self.add_games(cached_games)
def add_games(self, game_titles_with_urls):
self.all_games = [title for title, url in game_titles_with_urls]
self.game_descriptions = dict(game_titles_with_urls)
self.apply_filter()
def apply_filter(self):
self.search_text = self.search_bar.text().lower()
self.timer.start(300)
def update_displayed_games(self):
self.game_list_widget.clear()
filtered_games = [game for game in self.all_games if self.search_text in game.lower()]
self.displayed_games = filtered_games
self.game_list_widget.addItems(filtered_games)
def show_context_menu(self, pos):
item = self.game_list_widget.itemAt(pos)
if item:
game_title = item.text()
if game_title in self.game_descriptions:
url = self.game_descriptions[game_title]
menu = QMenu(self)
action = QAction(f"URL: {url}", self)
menu.addAction(action)
menu.exec_(self.game_list_widget.viewport().mapToGlobal(pos))
def show_game_details(self, item):
game_title = item.text()
url = self.game_descriptions.get(game_title, "")
description = "No description available"
dialog = GameDetailDialog(game_title, description, url, self)
dialog.exec_()
def check_and_add_new_games(self, new_games):
existing_titles = set(self.all_games)
for title, url in new_games:
if title not in existing_titles:
self.all_games.append(title)
self.game_descriptions[title] = url
self.game_list_widget.addItem(title)
existing_titles.add(title)
def run_gui():
app = QApplication(sys.argv)
main_window = MainWindow()
scraper_worker = ScraperWorker(main_window.driver_path, main_window.url)
scraper_thread = QThread()
scraper_worker.moveToThread(scraper_thread)
scraper_worker.games_fetched.connect(main_window.check_and_add_new_games)
scraper_thread.started.connect(scraper_worker.run)
scraper_thread.start()
main_window.show()
sys.exit(app.exec_())