Small GUI internals cleanup
This commit is contained in:
1 parent
5b04907d33
commit
2bddd68af2
2 files changed
+15
-14
No files matched your search
@@ -1,7 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
@@ -16,6 +14,7 @@ try:
|
|||||||
except ModuleNotFoundError as exc:
|
except ModuleNotFoundError as exc:
|
||||||
raise ImportError("You have to run 'pip install pystray' first") from exc
|
raise ImportError("You have to run 'pip install pystray' first") from exc
|
||||||
|
|
||||||
|
from utils import resource_path
|
||||||
from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State
|
from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -29,13 +28,7 @@ digits = ceil(log10(WS_TOPICS_LIMIT))
|
|||||||
WS_FONT = ("Courier New", 10)
|
WS_FONT = ("Courier New", 10)
|
||||||
|
|
||||||
|
|
||||||
def resource_path(relative_path):
|
class _ICOImage:
|
||||||
"""Get absolute path to resource, works for dev and for PyInstaller"""
|
|
||||||
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
return os.path.join(base_path, relative_path)
|
|
||||||
|
|
||||||
|
|
||||||
class ICOImage:
|
|
||||||
def __init__(self, path: str):
|
def __init__(self, path: str):
|
||||||
with open(path, 'rb') as file:
|
with open(path, 'rb') as file:
|
||||||
self._data = file.read()
|
self._data = file.read()
|
||||||
@@ -44,7 +37,7 @@ class ICOImage:
|
|||||||
file.write(self._data)
|
file.write(self._data)
|
||||||
|
|
||||||
|
|
||||||
class TKOutputHandler(logging.Handler):
|
class _TKOutputHandler(logging.Handler):
|
||||||
def __init__(self, output: GUIManager):
|
def __init__(self, output: GUIManager):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._output = output
|
self._output = output
|
||||||
@@ -516,7 +509,7 @@ class ConsoleOutput:
|
|||||||
self._text.config(state="disabled")
|
self._text.config(state="disabled")
|
||||||
|
|
||||||
|
|
||||||
class Buttons(TypedDict):
|
class _Buttons(TypedDict):
|
||||||
frame: ttk.Frame
|
frame: ttk.Frame
|
||||||
switch: ttk.Button
|
switch: ttk.Button
|
||||||
load_points: ttk.Button
|
load_points: ttk.Button
|
||||||
@@ -532,7 +525,7 @@ class ChannelList:
|
|||||||
# tell master frame that the containing column can expand
|
# tell master frame that the containing column can expand
|
||||||
master.columnconfigure(2, weight=1)
|
master.columnconfigure(2, weight=1)
|
||||||
buttons_frame = ttk.Frame(frame)
|
buttons_frame = ttk.Frame(frame)
|
||||||
self._buttons: Buttons = {
|
self._buttons: _Buttons = {
|
||||||
"frame": buttons_frame,
|
"frame": buttons_frame,
|
||||||
"switch": ttk.Button(
|
"switch": ttk.Button(
|
||||||
buttons_frame,
|
buttons_frame,
|
||||||
@@ -788,7 +781,7 @@ class TrayIcon:
|
|||||||
)
|
)
|
||||||
self.icon = pystray.Icon(
|
self.icon = pystray.Icon(
|
||||||
"twitch_miner",
|
"twitch_miner",
|
||||||
ICOImage(resource_path("pickaxe.ico")),
|
_ICOImage(resource_path("pickaxe.ico")),
|
||||||
self.get_title(drop),
|
self.get_title(drop),
|
||||||
menu,
|
menu,
|
||||||
)
|
)
|
||||||
@@ -910,7 +903,7 @@ class GUIManager:
|
|||||||
root.update_idletasks()
|
root.update_idletasks()
|
||||||
root.minsize(width=0, height=root.winfo_reqheight())
|
root.minsize(width=0, height=root.winfo_reqheight())
|
||||||
# register logging handler
|
# register logging handler
|
||||||
self._handler = TKOutputHandler(self)
|
self._handler = _TKOutputHandler(self)
|
||||||
self._handler.setFormatter(FORMATTER)
|
self._handler.setFormatter(FORMATTER)
|
||||||
logging.getLogger("TwitchDrops").addHandler(self._handler)
|
logging.getLogger("TwitchDrops").addHandler(self._handler)
|
||||||
# show the window when ready
|
# show the window when ready
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -28,6 +30,12 @@ logger = logging.getLogger("TwitchDrops")
|
|||||||
NONCE_CHARS = string.ascii_letters + string.digits
|
NONCE_CHARS = string.ascii_letters + string.digits
|
||||||
|
|
||||||
|
|
||||||
|
def resource_path(relative_path):
|
||||||
|
"""Get absolute path to resource, works for dev and for PyInstaller"""
|
||||||
|
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
return os.path.join(base_path, relative_path)
|
||||||
|
|
||||||
|
|
||||||
def timestamp(string: str) -> datetime:
|
def timestamp(string: str) -> datetime:
|
||||||
return datetime.strptime(string, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
|
return datetime.strptime(string, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user