diff sat_frontends/primitivus/game_tarot.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children 4b842c1fb686
line wrap: on
line diff
--- a/sat_frontends/primitivus/game_tarot.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat_frontends/primitivus/game_tarot.py	Sat Apr 08 13:54:42 2023 +0200
@@ -34,7 +34,7 @@
     def __init__(self, card):
         self.__selected = False
         self.card = card
-        urwid.Text.__init__(self, card.getAttrText())
+        urwid.Text.__init__(self, card.get_attr_text())
 
     def selectable(self):
         return True
@@ -55,16 +55,16 @@
 
     def select(self, state=True):
         self.__selected = state
-        attr, txt = self.card.getAttrText()
+        attr, txt = self.card.get_attr_text()
         if self.__selected:
             attr += "_selected"
         self.set_text((attr, txt))
         self._invalidate()
 
-    def isSelected(self):
+    def is_selected(self):
         return self.__selected
 
-    def getCard(self):
+    def get_card(self):
         return self.card
 
     def render(self, size, focus=False):
@@ -102,12 +102,12 @@
                 self._emit("click", None)
             return key
 
-    def getSelected(self):
+    def get_selected(self):
         """Return a list of selected cards"""
         _selected = []
         for wid in self.columns.widget_list:
-            if isinstance(wid, CardDisplayer) and wid.isSelected():
-                _selected.append(wid.getCard())
+            if isinstance(wid, CardDisplayer) and wid.is_selected():
+                _selected.append(wid.get_card())
         return _selected
 
     def update(self, hand):
@@ -123,11 +123,11 @@
             widget = CardDisplayer(card)
             self.columns.widget_list.append(widget)
             self.columns.column_types.append(("fixed", 3))
-            urwid.connect_signal(widget, "click", self.__onClick)
+            urwid.connect_signal(widget, "click", self.__on_click)
         self.columns.contents.append((urwid.Text(""), ("weight", 1, False)))
         self.columns.focus_position = 1
 
-    def __onClick(self, card_wid):
+    def __on_click(self, card_wid):
         self._emit("click", card_wid)
 
 
@@ -141,7 +141,7 @@
         """@param file: path of the PNG file"""
         TarotCard.__init__(self, (suit, value))
 
-    def getAttrText(self):
+    def get_attr_text(self):
         """return text representation of the card with attributes"""
         try:
             value = "%02i" % int(self.value)
@@ -169,7 +169,7 @@
             color = "special"
         return ("card_%s" % color, "%s%s" % (value, suit))
 
-    def getWidget(self):
+    def get_widget(self):
         """Return a widget representing the card"""
         return CardDisplayer(self)
 
@@ -180,7 +180,7 @@
     def __init__(self):
         self.top = self.left = self.bottom = self.right = None
 
-    def putCard(self, location, card):
+    def put_card(self, location, card):
         """Put a card on the table
         @param location: where to put the card (top, left, bottom or right)
         @param card: Card to play or None"""
@@ -208,7 +208,7 @@
         margin_center = max((max_col - Card.SIZE * 2 - len(separator)) / 2, 0) * " "
         for location in ["top", "left", "bottom", "right"]:
             card = getattr(self, location)
-            cards[location] = card.getAttrText() if card else Card.SIZE * " "
+            cards[location] = card.get_attr_text() if card else Card.SIZE * " "
         render_wid = [
             urwid.Text([margin, cards["top"]]),
             urwid.Text([margin_center, cards["left"], separator, cards["right"]]),
@@ -222,7 +222,7 @@
 
     def __init__(self, parent, referee, players):
         QuickTarotGame.__init__(self, parent, referee, players)
-        self.loadCards()
+        self.load_cards()
         self.top = urwid.Pile([urwid.Padding(urwid.Text(self.top_nick), "center")])
         # self.parent.host.debug()
         self.table = Table()
@@ -244,18 +244,18 @@
                                            ]),
                              urwid.Padding(self.bottom_card_wid,'center')
                              ])"""
-        self.hand_wid = Hand(selectable=True, on_click=self.onClick)
+        self.hand_wid = Hand(selectable=True, on_click=self.on_click)
         self.main_frame = urwid.Frame(
             self.center, header=self.top, footer=self.hand_wid, focus_part="footer"
         )
         urwid.WidgetWrap.__init__(self, self.main_frame)
-        self.parent.host.bridge.tarotGameReady(
+        self.parent.host.bridge.tarot_game_ready(
             self.player_nick, referee, self.parent.profile
         )
 
-    def loadCards(self):
+    def load_cards(self):
         """Load all the cards in memory"""
-        QuickTarotGame.loadCards(self)
+        QuickTarotGame.load_cards(self)
         for value in list(map(str, list(range(1, 22)))) + ["excuse"]:
             card = Card("atout", value)
             self.cards[card.suit, card.value] = card
@@ -266,22 +266,22 @@
                 self.cards[card.suit, card.value] = card
                 self.deck.append(card)
 
-    def tarotGameNewHandler(self, hand):
+    def tarot_game_new_handler(self, hand):
         """Start a new game, with given hand"""
         if hand is []:  # reset the display after the scores have been showed
-            self.resetRound()
+            self.reset_round()
             for location in ["top", "left", "bottom", "right"]:
-                self.table.putCard(location, None)
+                self.table.put_card(location, None)
             self.parent.host.redraw()
-            self.parent.host.bridge.tarotGameReady(
+            self.parent.host.bridge.tarot_game_ready(
                 self.player_nick, self.referee, self.parent.profile
             )
             return
-        QuickTarotGame.tarotGameNewHandler(self, hand)
+        QuickTarotGame.tarot_game_new_handler(self, hand)
         self.hand_wid.update(self.hand)
         self.parent.host.redraw()
 
-    def tarotGameChooseContratHandler(self, xml_data):
+    def tarot_game_choose_contrat_handler(self, xml_data):
         """Called when the player has to select his contrat
         @param xml_data: SàT xml representation of the form"""
         form = xmlui.create(
@@ -293,16 +293,16 @@
         )
         form.show(valign="top")
 
-    def tarotGameShowCardsHandler(self, game_stage, cards, data):
+    def tarot_game_show_cards_handler(self, game_stage, cards, data):
         """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
-        QuickTarotGame.tarotGameShowCardsHandler(self, game_stage, cards, data)
+        QuickTarotGame.tarot_game_show_cards_handler(self, game_stage, cards, data)
         self.center.widget_list[1] = urwid.Filler(Hand(self.to_show))
         self.parent.host.redraw()
 
-    def tarotGameYourTurnHandler(self):
-        QuickTarotGame.tarotGameYourTurnHandler(self)
+    def tarot_game_your_turn_handler(self):
+        QuickTarotGame.tarot_game_your_turn_handler(self)
 
-    def tarotGameScoreHandler(self, xml_data, winners, loosers):
+    def tarot_game_score_handler(self, xml_data, winners, loosers):
         """Called when the round is over, display the scores
         @param xml_data: SàT xml representation of the form"""
         if not winners and not loosers:
@@ -318,23 +318,23 @@
         )
         form.show()
 
-    def tarotGameInvalidCardsHandler(self, phase, played_cards, invalid_cards):
+    def tarot_game_invalid_cards_handler(self, phase, played_cards, invalid_cards):
         """Invalid cards have been played
         @param phase: phase of the game
         @param played_cards: all the cards played
         @param invalid_cards: cards which are invalid"""
-        QuickTarotGame.tarotGameInvalidCardsHandler(
+        QuickTarotGame.tarot_game_invalid_cards_handler(
             self, phase, played_cards, invalid_cards
         )
         self.hand_wid.update(self.hand)
         if self._autoplay == None:  # No dialog if there is autoplay
-            self.parent.host.barNotify(_("Cards played are invalid !"))
+            self.parent.host.bar_notify(_("Cards played are invalid !"))
         self.parent.host.redraw()
 
-    def tarotGameCardsPlayedHandler(self, player, cards):
+    def tarot_game_cards_played_handler(self, player, cards):
         """A card has been played by player"""
-        QuickTarotGame.tarotGameCardsPlayedHandler(self, player, cards)
-        self.table.putCard(self.getPlayerLocation(player), self.played[player])
+        QuickTarotGame.tarot_game_cards_played_handler(self, player, cards)
+        self.table.put_card(self.get_player_location(player), self.played[player])
         self._checkState()
         self.parent.host.redraw()
 
@@ -356,7 +356,7 @@
                 self.hand_wid.update(self.hand)
 
     ##EVENTS##
-    def onClick(self, hand, card_wid):
+    def on_click(self, hand, card_wid):
         """Called when user do an action on the hand"""
         if not self.state in ["play", "ecart", "wait_for_ecart"]:
             # it's not our turn, we ignore the click
@@ -364,16 +364,16 @@
             return
         self._checkState()
         if self.state == "ecart":
-            if len(self.hand_wid.getSelected()) == 6:
+            if len(self.hand_wid.get_selected()) == 6:
                 pop_up_widget = sat_widgets.ConfirmDialog(
                     _("Do you put these cards in chien ?"),
-                    yes_cb=self.onEcartDone,
-                    no_cb=self.parent.host.removePopUp,
+                    yes_cb=self.on_ecart_done,
+                    no_cb=self.parent.host.remove_pop_up,
                 )
-                self.parent.host.showPopUp(pop_up_widget)
+                self.parent.host.show_pop_up(pop_up_widget)
         elif self.state == "play":
-            card = card_wid.getCard()
-            self.parent.host.bridge.tarotGamePlayCards(
+            card = card_wid.get_card()
+            self.parent.host.bridge.tarot_game_play_cards(
                 self.player_nick,
                 self.referee,
                 [(card.suit, card.value)],
@@ -383,15 +383,15 @@
             self.hand_wid.update(self.hand)
             self.state = "wait"
 
-    def onEcartDone(self, button):
+    def on_ecart_done(self, button):
         """Called when player has finished his écart"""
         ecart = []
-        for card in self.hand_wid.getSelected():
+        for card in self.hand_wid.get_selected():
             ecart.append((card.suit, card.value))
             self.hand.remove(card)
         self.hand_wid.update(self.hand)
-        self.parent.host.bridge.tarotGamePlayCards(
+        self.parent.host.bridge.tarot_game_play_cards(
             self.player_nick, self.referee, ecart, self.parent.profile
         )
         self.state = "wait"
-        self.parent.host.removePopUp()
+        self.parent.host.remove_pop_up()