55from queue import Queue , Empty
66from threading import Thread , Lock
77from time import sleep
8- from typing import List , Any , Dict , Literal , Union
8+ from typing import List , Any , Dict , Literal , Union , Tuple
99
1010from PIL import Image , ImageTk
11+ from PIL .ImageTk import PhotoImage
1112
1213from Libs import Vars
1314
1415ServerPinger : Any = None
1516Address : Any = None
1617TCPSocketConnection : Any = None
18+ _MaxUnknown = str
1719
1820
1921def import_mcstatus ():
@@ -221,6 +223,7 @@ def __init__(self, info: dict) -> None:
221223 self .player_max , self .player_online , self .players = self .parse_player_info ()
222224
223225 # 服务器图标信息
226+ self .favicon = None
224227 self .favicon_data , self .favicon_photo , self .has_favicon = self .parse_icon_info ()
225228
226229 # 服务器标题
@@ -261,15 +264,15 @@ def __call__(self) -> dict:
261264 def __str__ (self ) -> str :
262265 return self .text
263266
264- def load_favicon_photo (self , has_favicon : bool = True , favicon_data = None , load_from_self = True ) -> Union [
265- ImageTk .PhotoImage , None ]:
267+ def load_favicon_photo (self , has_favicon : bool = True , favicon_data = None , load_from_self = True ) -> \
268+ Union [ ImageTk .PhotoImage , None ]:
266269 if not load_from_self :
267270 if has_favicon :
268- favicon = Image .open (BytesIO (favicon_data ), formats = ["PNG" ])
269- return ImageTk .PhotoImage (favicon )
271+ self . favicon = Image .open (BytesIO (favicon_data ), formats = ["PNG" ])
272+ return ImageTk .PhotoImage (self . favicon )
270273 elif self .has_favicon :
271- favicon = Image .open (BytesIO (self .favicon_data ), formats = ["PNG" ])
272- self .favicon_photo = ImageTk .PhotoImage (favicon )
274+ self . favicon = Image .open (BytesIO (self .favicon_data ), formats = ["PNG" ])
275+ self .favicon_photo = ImageTk .PhotoImage (self . favicon )
273276 return None
274277
275278 def parse_version_info (self ):
@@ -291,9 +294,7 @@ def parse_version_info(self):
291294 return version_name , protocol_version , protocol_info , protocol_name , protocol_major_name , version_type
292295
293296 def parse_player_info (self ):
294- # 如果你的 IDE 提示我的类型注释不对, 那就是 IDE 的问题
295- # 类型注释是正确的, 一层套一层导致 IDE 爆炸了 ( 其实是因为 self.parsed_data 没有做也很难做类型注释 )
296- player_max : Union [int , Literal ["未知" ]] = self .parsed_data .get ("players" , {"max" : "未知" })["max" ]
297+ player_max : Union [int , _MaxUnknown ] = self .parsed_data .get ("players" , {"max" : "未知" })["max" ]
297298 player_number = self .parsed_data .get ("players" , {"online" : "未知" })["online" ]
298299 if self .parsed_data .get ("players" , {}).get ("sample" ):
299300 player_list : List = self .parsed_data ["players" ]["sample" ]
0 commit comments