Stop automatic switching between games;

IDLE state + listbox selection clear fix
This commit is contained in:
DevilXD committed 2022-01-16 22:50:09 +01:00
1 parent 1d65fddfa1
commit cf1830cce9
4 files changed
+9 -24

No files matched your search

-1
View File
@@ -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. - 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. - 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. - 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. - Mining is stopped automatically when the last available drop has been mined.
**Not managed / TODO / manual:** **Not managed / TODO / manual:**
+1
View File
@@ -47,6 +47,7 @@ FORMATTER = logging.Formatter(
class State(Enum): class State(Enum):
IDLE = auto()
INVENTORY_FETCH = auto() INVENTORY_FETCH = auto()
GAMES_UPDATE = auto() GAMES_UPDATE = auto()
GAME_SELECT = auto() GAME_SELECT = auto()
+2 -16
View File
@@ -281,6 +281,7 @@ class GameSelector:
) )
if selected_index is not None: if selected_index is not None:
# reselect the currently selected item # reselect the currently selected item
self._list.selection_clear(0, "end")
self._list.selection_set(selected_index) self._list.selection_set(selected_index)
else: else:
# the game we've had selected isn't there anymore - clear selection # the game we've had selected isn't there anymore - clear selection
@@ -302,25 +303,13 @@ class GameSelector:
if not self._games: if not self._games:
raise RuntimeError("No games to select from") raise RuntimeError("No games to select from")
# select and return the first game from the list # select and return the first game from the list
self._list.selection_clear(0, "end")
self._list.selection_set(0) self._list.selection_set(0)
first_game = next(iter(self._games.values())) first_game = next(iter(self._games.values()))
self._selection = str(first_game) self._selection = str(first_game)
return first_game return first_game
return self._games[self._selection] 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): class _BaseVars(TypedDict):
progress: DoubleVar progress: DoubleVar
@@ -978,9 +967,6 @@ if __name__ == "__main__":
create_game(491115, "Paladins"), create_game(491115, "Paladins"),
# create_game(460630, "Tom Clancy's Rainbow Six Siege"), # create_game(460630, "Tom Clancy's Rainbow Six Siege"),
]) ])
gui.games.select_next()
gui.games.select_next()
gui.games.select_next()
# Channel list # Channel list
gui.channels.display(create_channel("PaladinsGame", 0, None, 0, 0)) gui.channels.display(create_channel("PaladinsGame", 0, None, 0, 0))
channel = create_channel("Traitus", 1, None, 0, 0) channel = create_channel("Traitus", 1, None, 0, 0)
+6 -7
View File
@@ -205,7 +205,10 @@ class Twitch:
selected_game: Optional[Game] = None selected_game: Optional[Game] = None
self.change_state(State.INVENTORY_FETCH) self.change_state(State.INVENTORY_FETCH)
while True: 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() await self.fetch_inventory()
self.change_state(State.GAMES_UPDATE) self.change_state(State.GAMES_UPDATE)
elif self._state is State.GAMES_UPDATE: elif self._state is State.GAMES_UPDATE:
@@ -308,12 +311,8 @@ class Twitch:
break break
else: else:
self.stop_watching() self.stop_watching()
selected_game = self.gui.games.select_next() self.gui.print(f"No suitable channel to watch for game: {selected_game}")
if selected_game is None: self.change_state(State.IDLE)
self.gui.print("No suitable channel to watch.")
# TODO: Figure out what to do here.
return
self.change_state(State.CHANNELS_CLEANUP)
await self._state_change.wait() await self._state_change.wait()
@task_wrapper @task_wrapper