comparison frontends/src/primitivus/card_game.py @ 687:af0d08a84cc6

primitivus card_game: bug fix and improvement - changeset 56f8a9c99194 introduced a bug because it connected all the list widgets to the parameter change callback. This is not OK because the Tarot is using a list form that is not a parameter. - some list processing was raising an error when the data is not initialized - display the "choose contrat" dialog with valign='top' to allow the user see his hand while taking the decision.
author souliane <souliane@mailoo.org>
date Mon, 28 Oct 2013 19:04:49 +0100
parents ae95b0327412
children 56aa0e98c92e
comparison
equal deleted inserted replaced
686:ae95b0327412 687:af0d08a84cc6
107 return _selected 107 return _selected
108 108
109 def update(self, hand): 109 def update(self, hand):
110 """Update the hand displayed in this widget 110 """Update the hand displayed in this widget
111 @param hand: list of Card""" 111 @param hand: list of Card"""
112 del self.columns.widget_list[:] 112 try:
113 del self.columns.column_types[:] 113 del self.columns.widget_list[:]
114 self.columns.contents.append((urwid.Text(''),('weight',1, False))) 114 del self.columns.column_types[:]
115 except IndexError:
116 pass
117 self.columns.contents.append((urwid.Text(''), ('weight', 1, False)))
115 for card in hand: 118 for card in hand:
116 widget = CardDisplayer(card) 119 widget = CardDisplayer(card)
117 self.columns.widget_list.append(widget) 120 self.columns.widget_list.append(widget)
118 self.columns.column_types.append(('fixed', 3)) 121 self.columns.column_types.append(('fixed', 3))
119 urwid.connect_signal(widget, 'click', self.__onClick) 122 urwid.connect_signal(widget, 'click', self.__onClick)
258 def chooseContrat(self, xml_data): 261 def chooseContrat(self, xml_data):
259 """Called when the player as to select his contrat 262 """Called when the player as to select his contrat
260 @param xml_data: SàT xml representation of the form""" 263 @param xml_data: SàT xml representation of the form"""
261 misc = {'callback': self.contratSelected} 264 misc = {'callback': self.contratSelected}
262 form = XMLUI(self.parent.host, xml_data, title=_('Please choose your contrat'), options=['NO_CANCEL'], misc=misc) 265 form = XMLUI(self.parent.host, xml_data, title=_('Please choose your contrat'), options=['NO_CANCEL'], misc=misc)
263 form.show() 266 form.show(valign='top')
264 267
265 def showCards(self, game_stage, cards, data): 268 def showCards(self, game_stage, cards, data):
266 """Display cards in the middle of the game (to show for e.g. chien ou poignée)""" 269 """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
267 QuickCardGame.showCards(self, game_stage, cards, data) 270 QuickCardGame.showCards(self, game_stage, cards, data)
268 self.center.widget_list[1] = urwid.Filler(Hand(self.to_show)) 271 self.center.widget_list[1] = urwid.Filler(Hand(self.to_show))