mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-06-05 03:49:37 +00:00
Redesign root icon setting system
This commit is contained in:
7
gui.py
7
gui.py
@@ -29,7 +29,7 @@ if sys.platform == "win32":
|
||||
from translate import _
|
||||
from cache import ImageCache
|
||||
from exceptions import ExitRequest
|
||||
from utils import resource_path, get_photo_image, Game, _T
|
||||
from utils import resource_path, set_root_icon, Game, _T
|
||||
from constants import (
|
||||
SELF_PATH, OUTPUT_FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State
|
||||
)
|
||||
@@ -1778,10 +1778,7 @@ class GUIManager:
|
||||
# withdraw immediately to prevent the window from flashing
|
||||
self._root.withdraw()
|
||||
# root.resizable(False, True)
|
||||
icon_photo = get_photo_image(root, resource_path("pickaxe.ico"))
|
||||
root.iconphoto(True, icon_photo) # window icon
|
||||
# keep a reference to the PhotoImage to avoid the ResourceWarning
|
||||
root._icon_image = icon_photo # type: ignore[attr-defined]
|
||||
set_root_icon(root, resource_path("pickaxe.ico"))
|
||||
root.title(WINDOW_TITLE) # window title
|
||||
root.bind_all("<KeyPress-Escape>", self.unfocus) # pressing ESC unfocuses selection
|
||||
# Image cache for displaying images
|
||||
|
||||
7
main.py
7
main.py
@@ -26,7 +26,7 @@ if __name__ == "__main__":
|
||||
from settings import Settings
|
||||
from version import __version__
|
||||
from exceptions import CaptchaRequired
|
||||
from utils import resource_path, get_photo_image
|
||||
from utils import resource_path, set_root_icon
|
||||
from constants import CALL, SELF_PATH, FILE_FORMATTER, LOG_PATH, WINDOW_TITLE
|
||||
|
||||
warnings.simplefilter("default", ResourceWarning)
|
||||
@@ -92,10 +92,7 @@ if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
root.overrideredirect(True)
|
||||
root.withdraw()
|
||||
icon_photo = get_photo_image(root, resource_path("pickaxe.ico"))
|
||||
root.iconphoto(True, icon_photo)
|
||||
# keep a reference to the PhotoImage to avoid the ResourceWarning
|
||||
root._icon_image = icon_photo # type: ignore[attr-defined]
|
||||
set_root_icon(root, resource_path("pickaxe.ico"))
|
||||
root.update()
|
||||
parser = Parser(
|
||||
SELF_PATH.name,
|
||||
|
||||
11
utils.py
11
utils.py
@@ -41,11 +41,12 @@ _JSON_T = TypeVar("_JSON_T", bound=Mapping[Any, Any])
|
||||
logger = logging.getLogger("TwitchDrops")
|
||||
|
||||
|
||||
def get_photo_image(master: tk.Misc, path: Path | str) -> PhotoImage:
|
||||
image = Image_module.open(path)
|
||||
photo = PhotoImage(master=master, image=image)
|
||||
image.close()
|
||||
return photo
|
||||
def set_root_icon(root: tk.Tk, image_path: Path | str) -> None:
|
||||
with Image_module.open(image_path) as image:
|
||||
icon_photo = PhotoImage(master=root, image=image)
|
||||
root.iconphoto(True, icon_photo)
|
||||
# keep a reference to the PhotoImage to avoid the ResourceWarning
|
||||
root._icon_image = icon_photo # type: ignore[attr-defined]
|
||||
|
||||
|
||||
async def first_to_complete(coros: abc.Iterable[abc.Coroutine[Any, Any, _T]]) -> _T:
|
||||
|
||||
Reference in New Issue
Block a user