Remove idle arg, make it default

This commit is contained in:
DevilXD committed 2022-02-13 21:48:38 +01:00
1 parent 423e51bc27
commit f6453dafaf
4 files changed
+33 -24

No files matched your search

+3 -3
View File
@@ -16,7 +16,7 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "main.py", "program": "main.py",
"args": ["--no-run-check", "--idle", "-vv"], "args": ["--no-run-check", "-vv"],
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": false "justMyCode": false
}, },
@@ -25,7 +25,7 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "main.py", "program": "main.py",
"args": ["--no-run-check", "--idle", "-vvv"], "args": ["--no-run-check", "-vvv"],
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": false "justMyCode": false
}, },
@@ -34,7 +34,7 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "main.py", "program": "main.py",
"args": ["--no-run-check", "--idle", "-vvv", "--debug-ws"], "args": ["--no-run-check", "-vvv", "--debug-ws"],
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": false "justMyCode": false
}, },
+13 -9
View File
@@ -289,6 +289,7 @@ class GameSelector:
def _on_select(self, event): def _on_select(self, event):
current = self._list.curselection() current = self._list.curselection()
print(current)
if not current: if not current:
# can happen when the user clicks on an empty list # can happen when the user clicks on an empty list
new_selection = None new_selection = None
@@ -298,18 +299,21 @@ class GameSelector:
self._selection = new_selection self._selection = new_selection
self._manager._twitch.change_state(State.GAME_SELECT) self._manager._twitch.change_state(State.GAME_SELECT)
def get_selection(self) -> Game: def get_selection(self) -> Optional[Game]:
if self._selection is None: if self._selection is None:
if not self._games: return None
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] return self._games[self._selection]
def set_first(self) -> Game:
# select and return the first game from the list
self._list.selection_clear(0, "end")
self._list.selection_set(0)
for game_name, first_game in self._games.items():
# just one iteration to get, set and return the first game
self._selection = game_name
return first_game
raise RuntimeError("No games to select from")
class _BaseVars(TypedDict): class _BaseVars(TypedDict):
progress: DoubleVar progress: DoubleVar
-2
View File
@@ -20,7 +20,6 @@ class ParsedArgs(argparse.Namespace):
_debug_ws: bool _debug_ws: bool
_debug_gql: bool _debug_gql: bool
log: bool log: bool
idle: bool
tray: bool tray: bool
no_run_check: bool no_run_check: bool
game: Optional[str] game: Optional[str]
@@ -69,7 +68,6 @@ parser.add_argument("--no-run-check", dest="no_run_check", action="store_true")
parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true") parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true")
parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true") parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true")
parser.add_argument("-g", "--game", default=None) parser.add_argument("-g", "--game", default=None)
parser.add_argument("--idle", action="store_true")
parser.add_argument("--tray", action="store_true") parser.add_argument("--tray", action="store_true")
parser.add_argument("--log", action="store_true") parser.add_argument("--log", action="store_true")
options: ParsedArgs = parser.parse_args(namespace=ParsedArgs()) options: ParsedArgs = parser.parse_args(namespace=ParsedArgs())
+17 -10
View File
@@ -179,6 +179,7 @@ class Twitch:
WebsocketTopic("User", "Drops", self._user_id, self.process_drops), WebsocketTopic("User", "Drops", self._user_id, self.process_drops),
WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points), WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points),
]) ])
first_select: bool = True
games: List[Game] = [] games: List[Game] = []
full_cleanup: bool = False full_cleanup: bool = False
channels: Final[OrderedDict[int, Channel]] = self.channels channels: Final[OrderedDict[int, Channel]] = self.channels
@@ -215,18 +216,24 @@ class Twitch:
# only start the websocket after we confirm there are drops to mine # only start the websocket after we confirm there are drops to mine
await self.websocket.start() await self.websocket.start()
self.gui.games.set_games(games) self.gui.games.set_games(games)
if self.options.idle: self.change_state(State.GAME_SELECT)
self.options.idle = False
self.change_state(State.IDLE)
else:
self.change_state(State.GAME_SELECT)
elif self._state is State.GAME_SELECT: elif self._state is State.GAME_SELECT:
self.game = self.gui.games.get_selection() self.game = self.gui.games.get_selection()
# restart the watch loop if needed if self.game is None:
self.restart_watching() if first_select:
# signal channel cleanup that we're removing everything # on first select, let the user make the choice
full_cleanup = True first_select = False
self.change_state(State.CHANNELS_CLEANUP) else:
self.game = self.gui.games.set_first()
if self.game is not None:
# restart the watch loop if needed
self.restart_watching()
# signal channel cleanup that we're removing everything
full_cleanup = True
self.change_state(State.CHANNELS_CLEANUP)
else:
# with no game selected, we switch to IDLE
self.change_state(State.IDLE)
elif self._state is State.CHANNELS_CLEANUP: elif self._state is State.CHANNELS_CLEANUP:
if self.game is None or full_cleanup: if self.game is None or full_cleanup:
# no game selected or we're doing full cleanup: remove everything # no game selected or we're doing full cleanup: remove everything