Add timestamps to output messages
This commit is contained in:
1 parent
57baa4fc1e
commit
51b2da3e42
2 files changed
+23
-19
No files matched your search
@@ -673,7 +673,7 @@ class CampaignProgress:
|
|||||||
class ConsoleOutput:
|
class ConsoleOutput:
|
||||||
def __init__(self, manager: GUIManager, master: ttk.Widget):
|
def __init__(self, manager: GUIManager, master: ttk.Widget):
|
||||||
frame = ttk.LabelFrame(master, text=_("gui", "output"), padding=(4, 0, 4, 4))
|
frame = ttk.LabelFrame(master, text=_("gui", "output"), padding=(4, 0, 4, 4))
|
||||||
frame.grid(column=0, row=3, columnspan=2, sticky="nsew", padx=2)
|
frame.grid(column=0, row=3, columnspan=3, sticky="nsew", padx=2)
|
||||||
# tell master frame that the containing row can expand
|
# tell master frame that the containing row can expand
|
||||||
master.rowconfigure(3, weight=1)
|
master.rowconfigure(3, weight=1)
|
||||||
frame.rowconfigure(0, weight=1) # let the frame expand
|
frame.rowconfigure(0, weight=1) # let the frame expand
|
||||||
@@ -696,9 +696,12 @@ class ConsoleOutput:
|
|||||||
xscroll.grid(column=0, row=1, sticky="ew")
|
xscroll.grid(column=0, row=1, sticky="ew")
|
||||||
yscroll.grid(column=1, row=0, sticky="ns")
|
yscroll.grid(column=1, row=0, sticky="ns")
|
||||||
|
|
||||||
def print(self, *values, sep: str = ' ', end: str = '\n'):
|
def print(self, message: str):
|
||||||
|
stamp = datetime.now().strftime("%X")
|
||||||
|
if '\n' in message:
|
||||||
|
message = message.replace('\n', f"\n{stamp}: ")
|
||||||
self._text.config(state="normal")
|
self._text.config(state="normal")
|
||||||
self._text.insert("end", f"{sep.join(values)}{end}")
|
self._text.insert("end", f"{stamp}: {message}\n")
|
||||||
self._text.see("end") # scroll to the newly added line
|
self._text.see("end") # scroll to the newly added line
|
||||||
self._text.config(state="disabled")
|
self._text.config(state="disabled")
|
||||||
|
|
||||||
@@ -713,7 +716,7 @@ class ChannelList:
|
|||||||
def __init__(self, manager: GUIManager, master: ttk.Widget):
|
def __init__(self, manager: GUIManager, master: ttk.Widget):
|
||||||
self._manager = manager
|
self._manager = manager
|
||||||
frame = ttk.LabelFrame(master, text=_("gui", "channels", "name"), padding=(4, 0, 4, 4))
|
frame = ttk.LabelFrame(master, text=_("gui", "channels", "name"), padding=(4, 0, 4, 4))
|
||||||
frame.grid(column=2, row=1, rowspan=3, sticky="nsew", padx=2)
|
frame.grid(column=2, row=1, rowspan=2, sticky="nsew", padx=2)
|
||||||
# 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)
|
||||||
frame.rowconfigure(1, weight=1)
|
frame.rowconfigure(1, weight=1)
|
||||||
@@ -1993,9 +1996,9 @@ class GUIManager:
|
|||||||
self.progress.display(None)
|
self.progress.display(None)
|
||||||
self.tray.update_title(None)
|
self.tray.update_title(None)
|
||||||
|
|
||||||
def print(self, *args, **kwargs):
|
def print(self, message: str):
|
||||||
# print to our custom output
|
# print to our custom output
|
||||||
self.output.print(*args, **kwargs)
|
self.output.print(message)
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
@@ -2193,6 +2196,11 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
campaign = drop.campaign
|
campaign = drop.campaign
|
||||||
await gui.inv.add_campaign(campaign)
|
await gui.inv.add_campaign(campaign)
|
||||||
|
|
||||||
|
gui.print("Single-line test message")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
gui.print("Multi-line\ntest\nmessage")
|
||||||
|
|
||||||
# Tray
|
# Tray
|
||||||
# gui.tray.minimize()
|
# gui.tray.minimize()
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|||||||
@@ -639,11 +639,11 @@ class Twitch:
|
|||||||
"""
|
"""
|
||||||
self.gui.prevent_close()
|
self.gui.prevent_close()
|
||||||
|
|
||||||
def print(self, *args, **kwargs):
|
def print(self, message: str):
|
||||||
"""
|
"""
|
||||||
Can be used to print messages within the GUI.
|
Can be used to print messages within the GUI.
|
||||||
"""
|
"""
|
||||||
self.gui.print(*args, **kwargs)
|
self.gui.print(message)
|
||||||
|
|
||||||
def save(self, *, force: bool = False) -> None:
|
def save(self, *, force: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -785,7 +785,7 @@ class Twitch:
|
|||||||
self.change_state(State.CHANNELS_FETCH)
|
self.change_state(State.CHANNELS_FETCH)
|
||||||
else:
|
else:
|
||||||
# with no games available, we switch to IDLE after cleanup
|
# with no games available, we switch to IDLE after cleanup
|
||||||
self.gui.print(_("status", "no_campaign"))
|
self.print(_("status", "no_campaign"))
|
||||||
self.change_state(State.IDLE)
|
self.change_state(State.IDLE)
|
||||||
elif self._state is State.CHANNELS_FETCH:
|
elif self._state is State.CHANNELS_FETCH:
|
||||||
self.gui.status.update(_("gui", "status", "gathering"))
|
self.gui.status.update(_("gui", "status", "gathering"))
|
||||||
@@ -908,7 +908,7 @@ class Twitch:
|
|||||||
self._state_change.clear()
|
self._state_change.clear()
|
||||||
else:
|
else:
|
||||||
# not watching anything and there isn't anything to watch either
|
# not watching anything and there isn't anything to watch either
|
||||||
self.gui.print(_("status", "no_channel"))
|
self.print(_("status", "no_channel"))
|
||||||
self.change_state(State.IDLE)
|
self.change_state(State.IDLE)
|
||||||
elif self._state is State.EXIT:
|
elif self._state is State.EXIT:
|
||||||
self.gui.status.update(_("gui", "status", "exiting"))
|
self.gui.status.update(_("gui", "status", "exiting"))
|
||||||
@@ -1095,7 +1095,7 @@ class Twitch:
|
|||||||
and self.should_switch(channel) # and we should!
|
and self.should_switch(channel) # and we should!
|
||||||
):
|
):
|
||||||
self.watch(channel)
|
self.watch(channel)
|
||||||
self.gui.print(_("status", "goes_online").format(channel=channel.name))
|
self.print(_("status", "goes_online").format(channel=channel.name))
|
||||||
self.gui.status.update(
|
self.gui.status.update(
|
||||||
_("gui", "status", "watching").format(channel=channel.name)
|
_("gui", "status", "watching").format(channel=channel.name)
|
||||||
)
|
)
|
||||||
@@ -1107,7 +1107,7 @@ class Twitch:
|
|||||||
# change the channel if we're currently watching it
|
# change the channel if we're currently watching it
|
||||||
watching_channel = self.watching_channel.get_with_default(None)
|
watching_channel = self.watching_channel.get_with_default(None)
|
||||||
if watching_channel is not None and watching_channel == channel:
|
if watching_channel is not None and watching_channel == channel:
|
||||||
self.gui.print(_("status", "goes_offline").format(channel=channel.name))
|
self.print(_("status", "goes_offline").format(channel=channel.name))
|
||||||
self.change_state(State.CHANNEL_SWITCH)
|
self.change_state(State.CHANNEL_SWITCH)
|
||||||
else:
|
else:
|
||||||
logger.debug(f"{channel.name} goes OFFLINE")
|
logger.debug(f"{channel.name} goes OFFLINE")
|
||||||
@@ -1140,9 +1140,7 @@ class Twitch:
|
|||||||
)
|
)
|
||||||
# two different claim texts, becase a new line after the game name
|
# two different claim texts, becase a new line after the game name
|
||||||
# looks ugly in the output window - replace it with a space
|
# looks ugly in the output window - replace it with a space
|
||||||
self.gui.print(
|
self.print(_("status", "claimed_drop").format(drop=claim_text.replace('\n', ' ')))
|
||||||
_("status", "claimed_drop").format(drop=claim_text.replace('\n', ' '))
|
|
||||||
)
|
|
||||||
self.gui.tray.notify(claim_text, _("gui", "tray", "notification_title"))
|
self.gui.tray.notify(claim_text, _("gui", "tray", "notification_title"))
|
||||||
else:
|
else:
|
||||||
logger.error(f"Drop claim failed! Drop ID: {drop_id}")
|
logger.error(f"Drop claim failed! Drop ID: {drop_id}")
|
||||||
@@ -1233,14 +1231,12 @@ class Twitch:
|
|||||||
if channel is not None:
|
if channel is not None:
|
||||||
channel.points = balance
|
channel.points = balance
|
||||||
channel.display()
|
channel.display()
|
||||||
self.gui.print(
|
self.print(_("status", "earned_points").format(points=f"{points:3}", balance=balance))
|
||||||
_("status", "earned_points").format(points=f"{points:3}", balance=balance)
|
|
||||||
)
|
|
||||||
elif msg_type == "claim-available":
|
elif msg_type == "claim-available":
|
||||||
claim_data = message["data"]["claim"]
|
claim_data = message["data"]["claim"]
|
||||||
points = claim_data["point_gain"]["total_points"]
|
points = claim_data["point_gain"]["total_points"]
|
||||||
await self.claim_points(claim_data["channel_id"], claim_data["id"])
|
await self.claim_points(claim_data["channel_id"], claim_data["id"])
|
||||||
self.gui.print(_("status", "claimed_points").format(points=points))
|
self.print(_("status", "claimed_points").format(points=points))
|
||||||
|
|
||||||
async def get_auth(self) -> _AuthState:
|
async def get_auth(self) -> _AuthState:
|
||||||
await self._auth_state.validate()
|
await self._auth_state.validate()
|
||||||
|
|||||||
Reference in new issue
Block a user