Add an experimental shutdown handler
This commit is contained in:
1 parent
6d5191e148
commit
0431a2d98e
3 files changed
+4
-11
No files matched your search
@@ -1629,6 +1629,7 @@ class GUIManager:
|
|||||||
root.iconbitmap(resource_path("pickaxe.ico")) # window icon
|
root.iconbitmap(resource_path("pickaxe.ico")) # window icon
|
||||||
root.title(WINDOW_TITLE) # window title
|
root.title(WINDOW_TITLE) # window title
|
||||||
root.protocol("WM_DELETE_WINDOW", self.close) # hook the X window closing button
|
root.protocol("WM_DELETE_WINDOW", self.close) # hook the X window closing button
|
||||||
|
root.protocol("WM_ENDSESSION", self.close) # hook the Windows shutdown signal
|
||||||
root.bind_all("<KeyPress-Escape>", self.unfocus) # pressing ESC unfocuses selection
|
root.bind_all("<KeyPress-Escape>", self.unfocus) # pressing ESC unfocuses selection
|
||||||
# Image cache for displaying images
|
# Image cache for displaying images
|
||||||
self._cache = ImageCache(self)
|
self._cache = ImageCache(self)
|
||||||
@@ -1781,7 +1782,7 @@ class GUIManager:
|
|||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
self._poll_task = None
|
self._poll_task = None
|
||||||
|
|
||||||
def close(self):
|
def close(self, *args):
|
||||||
"""
|
"""
|
||||||
Requests the GUI application to close.
|
Requests the GUI application to close.
|
||||||
The window itself will be closed in the closing sequence later.
|
The window itself will be closed in the closing sequence later.
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ exit_status = 0
|
|||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
client = Twitch(settings)
|
client = Twitch(settings)
|
||||||
signal.signal(signal.SIGINT, lambda *_: client.signal_close())
|
signal.signal(signal.SIGINT, lambda *_: client.gui.close())
|
||||||
signal.signal(signal.SIGTERM, lambda *_: client.signal_close())
|
signal.signal(signal.SIGTERM, lambda *_: client.gui.close())
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(client.run())
|
loop.run_until_complete(client.run())
|
||||||
except CaptchaRequired:
|
except CaptchaRequired:
|
||||||
|
|||||||
@@ -121,14 +121,6 @@ class Twitch:
|
|||||||
# perfect for GUI usage
|
# perfect for GUI usage
|
||||||
return partial(self.change_state, state)
|
return partial(self.change_state, state)
|
||||||
|
|
||||||
def signal_close(self):
|
|
||||||
"""
|
|
||||||
Called when the application is requested to close by the operating system,
|
|
||||||
usually by receiving a SIGINT or SIGTERM.
|
|
||||||
"""
|
|
||||||
# delegate this to the same action as the user clicking on the X in the GUI window
|
|
||||||
self.gui.close()
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Called when the application is requested to close by the user,
|
Called when the application is requested to close by the user,
|
||||||
|
|||||||
Reference in new issue
Block a user