From cf1830cce9060b49579524600dd264334dcde29b Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 16 Jan 2022 22:50:09 +0100 Subject: [PATCH] Stop automatic switching between games; IDLE state + listbox selection clear fix --- README.md | 1 - constants.py | 1 + gui.py | 18 ++---------------- twitch.py | 13 ++++++------- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2c1c3d4..4c1c296 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ This application allows you to AFK mine timed Twitch drops, without having to wo - Stream tags and drop campaign validation, so you don't end up watching a stream that can't earn you the drop. - Channel stream switching, when the one you were currently watching goes offline. - Cookie saving between sessions, so you don't need to login every time. -- Game switching once there's no more drops available for the selected game. - Mining is stopped automatically when the last available drop has been mined. **Not managed / TODO / manual:** diff --git a/constants.py b/constants.py index a099154..d2e730c 100644 --- a/constants.py +++ b/constants.py @@ -47,6 +47,7 @@ FORMATTER = logging.Formatter( class State(Enum): + IDLE = auto() INVENTORY_FETCH = auto() GAMES_UPDATE = auto() GAME_SELECT = auto() diff --git a/gui.py b/gui.py index 9837796..5ab83ee 100644 --- a/gui.py +++ b/gui.py @@ -281,6 +281,7 @@ class GameSelector: ) if selected_index is not None: # reselect the currently selected item + self._list.selection_clear(0, "end") self._list.selection_set(selected_index) else: # the game we've had selected isn't there anymore - clear selection @@ -302,25 +303,13 @@ class GameSelector: if not self._games: raise RuntimeError("No games to select from") # select and return the first game from the list + self._list.selection_clear(0, "end") self._list.selection_set(0) first_game = next(iter(self._games.values())) self._selection = str(first_game) return first_game return self._games[self._selection] - def select_next(self) -> Optional[Game]: - current = self._list.curselection() - if not current: - return self.get_selection() - next_idx = current[0]+1 - game_name = self._list.get(next_idx) - if not game_name: - # this was the last game on the list - return None - self._list.selection_set(next_idx) - self._selection = game_name - return self._games[game_name] - class _BaseVars(TypedDict): progress: DoubleVar @@ -978,9 +967,6 @@ if __name__ == "__main__": create_game(491115, "Paladins"), # create_game(460630, "Tom Clancy's Rainbow Six Siege"), ]) - gui.games.select_next() - gui.games.select_next() - gui.games.select_next() # Channel list gui.channels.display(create_channel("PaladinsGame", 0, None, 0, 0)) channel = create_channel("Traitus", 1, None, 0, 0) diff --git a/twitch.py b/twitch.py index 259c051..d263009 100644 --- a/twitch.py +++ b/twitch.py @@ -205,7 +205,10 @@ class Twitch: selected_game: Optional[Game] = None self.change_state(State.INVENTORY_FETCH) while True: - if self._state is State.INVENTORY_FETCH: + if self._state is State.IDLE: + # clear the flag and wait until it's set again + self._state_change.clear() + elif self._state is State.INVENTORY_FETCH: await self.fetch_inventory() self.change_state(State.GAMES_UPDATE) elif self._state is State.GAMES_UPDATE: @@ -308,12 +311,8 @@ class Twitch: break else: self.stop_watching() - selected_game = self.gui.games.select_next() - if selected_game is None: - self.gui.print("No suitable channel to watch.") - # TODO: Figure out what to do here. - return - self.change_state(State.CHANNELS_CLEANUP) + self.gui.print(f"No suitable channel to watch for game: {selected_game}") + self.change_state(State.IDLE) await self._state_change.wait() @task_wrapper