From 8434ca1d227cb30b9d674335444361a17ddcf73b Mon Sep 17 00:00:00 2001 From: Piotr Idzik <65706193+vil02@users.noreply.github.com> Date: Sun, 20 Apr 2025 00:37:00 +0200 Subject: [PATCH] Simplify loops (#448) --- pysollib/game/__init__.py | 7 +++---- pysollib/kivy/menubar.py | 3 +-- pysollib/stack.py | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index f78fc5b6..a35cc28d 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -885,7 +885,7 @@ class Game(object): assert len(self.allstacks) == len(game.loadinfo.stacks) old_state = game.moves.state game.moves.state = self.S_RESTORE - for i in range(len(self.allstacks)): + for i, cur_stack in enumerate(self.allstacks): for t in game.loadinfo.stacks[i]: card_id, face_up = t card = self.cards[card_id] @@ -893,7 +893,7 @@ class Game(object): card.showFace() else: card.showBack() - self.allstacks[i].addCard(card) + cur_stack.addCard(card) game.moves.state = old_state # 4) update settings for stack_id, cap in self.saveinfo.stack_caps: @@ -1106,9 +1106,8 @@ class Game(object): x, y = int(round((init_coord[0] + cw) * xf)), \ int(round((init_coord[1] + ch) * yf)) self.canvas.coords(item, x, y) - for i in range(len(self.texts.list)): + for i, item in enumerate(self.texts.list): init_coord = self.init_texts.list[i] - item = self.texts.list[i] x, y = int(round((init_coord[0] + cw) * xf)), \ int(round((init_coord[1] + ch) * yf)) self.canvas.coords(item, x, y) diff --git a/pysollib/kivy/menubar.py b/pysollib/kivy/menubar.py index 6138ecc5..4941d489 100644 --- a/pysollib/kivy/menubar.py +++ b/pysollib/kivy/menubar.py @@ -1880,8 +1880,7 @@ class PysolMenubarTk: short_name=False): # cb = self.__cb_max - for i in range(len(games)): - gi = games[i] + for gi in games: # columnbreak = i > 0 and (i % cb) == 0 if short_name: label = gi.short_name diff --git a/pysollib/stack.py b/pysollib/stack.py index d7b1ecfd..49c8b57f 100644 --- a/pysollib/stack.py +++ b/pysollib/stack.py @@ -493,8 +493,7 @@ class Stack: images = self.game.app.images cw, ch = images.getSize() index = -1 - for i in range(len(cards)): - c = cards[i] + for i, c in enumerate(cards): r = (c.x, c.y, c.x + cw, c.y + ch) if r[0] <= x < r[2] and r[1] <= y < r[3]: index = i