/
lb2_threading.py
117 lines (92 loc) · 3.52 KB
/
lb2_threading.py
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
import time
from PySide6 import QtCore
from PySide6.QtCore import Signal
from networking import mb_query
from networking.ms_query import get_server_list, ms_url, ms_kart_url
class QueryMessageBoard(QtCore.QThread):
# Emits a string describing the mod
mod_description_sig1 = Signal(object)
# Emits a list of mods
mod_list_sig1 = Signal(dict)
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.mod = None
self.get_mod_description = False
self.get_mods = False
self.mods_type = None
def on_request_mod_list(self, mods_type):
self.get_mods = True
self.mods_type = mods_type
def on_request_mod_desc(self, mod):
print("on_request_mod_desc")
self.mod = mod
def run(self):
self.running = True
while self.running:
if self.get_mods:
self.mods_list = {}
subforum_url = None
if self.mods_type == "Maps":
subforum_url = mb_query.maps_sublink
if self.mods_type == "Characters":
subforum_url = mb_query.characters_sublink
if self.mods_type == "Lua":
subforum_url = mb_query.lua_sublink
if self.mods_type == "Assets":
subforum_url = mb_query.assets_sublink
if self.mods_type == "Misc":
subforum_url = mb_query.misc_sublink
mods = mb_query.get_mods(subforum_url)
for mod in mods:
entry_text = mod.name
self.mods_list[entry_text] = mod
self.mod_list_sig1.emit(self.mods_list)
# Reset variables
self.mods_list = {}
self.get_mods = False
self.mods_type = None
if self.mod:
self.mod.get_description()
self.mod_description_sig1.emit(self.mod)
# Reset variables
self.mod = None
time.sleep(1)
class QueryMasterServer(QtCore.QThread):
server_list_sig1 = Signal(list)
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.query_ms = False
self.running = True
def on_refresh(self):
"""Refresh button clicked
"""
self.query_ms = True
def on_quit(self):
self.running = False
def run(self):
while self.running:
if self.query_ms:
server_list = get_server_list(ms_url)
self.server_list_sig1.emit(server_list)
self.query_ms = False
time.sleep(1)
class ModDownloader(QtCore.QThread):
mod_filepath_sig1 = Signal(list)
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.download_url = None
self.filepath = None
self.running = True
def on_download_button(self, download_url):
self.download_url = download_url
def on_filepath_emit(self, filepath):
self.filepath = filepath
def run(self):
while self.running:
if self.download_url and self.filepath:
filepath = mb_query.download_mod(self.filepath, self.download_url)
# Extract files, get wads/pk3/etc to add.
self.mod_filepath_sig1.emit([filepath])
self.download_url = None
self.filepath = None
time.sleep(1)