comparison frontends/src/primitivus/card_game.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children c123dddaea6b
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
46 def mouse_event(self, size, event, button, x, y, focus): 46 def mouse_event(self, size, event, button, x, y, focus):
47 if urwid.is_mouse_press(event) and button == 1: 47 if urwid.is_mouse_press(event) and button == 1:
48 self.select(not self.__selected) 48 self.select(not self.__selected)
49 self._emit('click') 49 self._emit('click')
50 return True 50 return True
51 51
52 return False 52 return False
53 53
54 def select(self, state=True): 54 def select(self, state=True):
55 self.__selected = state 55 self.__selected = state
56 attr,txt = self.card.getAttrText() 56 attr,txt = self.card.getAttrText()
57 if self.__selected: 57 if self.__selected:
58 attr+='_selected' 58 attr+='_selected'
181 if [getattr(self, place) for place in ['top','left','bottom','right']].count(None) == 0: 181 if [getattr(self, place) for place in ['top','left','bottom','right']].count(None) == 0:
182 #If the table is full of card, we remove them 182 #If the table is full of card, we remove them
183 self.top = self.left = self.bottom = self.right = None 183 self.top = self.left = self.bottom = self.right = None
184 setattr(self, location, card) 184 setattr(self, location, card)
185 self._invalidate() 185 self._invalidate()
186 186
187 def rows(self,size,focus=False): 187 def rows(self,size,focus=False):
188 return self.display_widget(size, focus).rows(size, focus) 188 return self.display_widget(size, focus).rows(size, focus)
189 189
190 def render(self, size, focus=False): 190 def render(self, size, focus=False):
191 return self.display_widget(size, focus).render(size, focus) 191 return self.display_widget(size, focus).render(size, focus)
201 cards[location] = card.getAttrText() if card else Card.SIZE * ' ' 201 cards[location] = card.getAttrText() if card else Card.SIZE * ' '
202 render_wid = [urwid.Text([margin,cards['top']]), 202 render_wid = [urwid.Text([margin,cards['top']]),
203 urwid.Text([margin_center,cards['left'],separator,cards['right']]), 203 urwid.Text([margin_center,cards['left'],separator,cards['right']]),
204 urwid.Text([margin,cards['bottom']])] 204 urwid.Text([margin,cards['bottom']])]
205 return urwid.Pile(render_wid) 205 return urwid.Pile(render_wid)
206 206
207 207
208 class CardGame(QuickCardGame,urwid.WidgetWrap): 208 class CardGame(QuickCardGame,urwid.WidgetWrap):
209 """Widget for card games""" 209 """Widget for card games"""
210 210
211 def __init__(self, parent, referee, players, player_nick): 211 def __init__(self, parent, referee, players, player_nick):
212 QuickCardGame.__init__(self, parent, referee, players, player_nick) 212 QuickCardGame.__init__(self, parent, referee, players, player_nick)
213 self.loadCards() 213 self.loadCards()
214 self.top = urwid.Pile([urwid.Padding(urwid.Text(self.top_nick), 'center')]) 214 self.top = urwid.Pile([urwid.Padding(urwid.Text(self.top_nick), 'center')])
215 #self.parent.host.debug() 215 #self.parent.host.debug()
246 def newGame(self, hand): 246 def newGame(self, hand):
247 """Start a new game, with given hand""" 247 """Start a new game, with given hand"""
248 QuickCardGame.newGame(self, hand) 248 QuickCardGame.newGame(self, hand)
249 self.hand_wid.update(self.hand) 249 self.hand_wid.update(self.hand)
250 self.parent.host.redraw() 250 self.parent.host.redraw()
251 251
252 def contratSelected(self, data): 252 def contratSelected(self, data):
253 """Called when the contrat has been choosed 253 """Called when the contrat has been choosed
254 @param data: form result""" 254 @param data: form result"""
255 contrat = data[0][1] 255 contrat = data[0][1]
256 QuickCardGame.contratSelected(self, contrat) 256 QuickCardGame.contratSelected(self, contrat)
257 257
258 def chooseContrat(self, xml_data): 258 def chooseContrat(self, xml_data):
259 """Called when the player as to select his contrat 259 """Called when the player as to select his contrat
260 @param xml_data: SàT xml representation of the form""" 260 @param xml_data: SàT xml representation of the form"""
261 misc = {'callback': self.contratSelected} 261 misc = {'callback': self.contratSelected}
262 form = XMLUI(self.parent.host, xml_data, title = _('Please choose your contrat'), options = ['NO_CANCEL'], misc = misc) 262 form = XMLUI(self.parent.host, xml_data, title = _('Please choose your contrat'), options = ['NO_CANCEL'], misc = misc)
295 QuickCardGame.invalidCards(self, phase, played_cards, invalid_cards) 295 QuickCardGame.invalidCards(self, phase, played_cards, invalid_cards)
296 self.hand_wid.update(self.hand) 296 self.hand_wid.update(self.hand)
297 if self._autoplay==None: #No dialog if there is autoplay 297 if self._autoplay==None: #No dialog if there is autoplay
298 self.parent.host.notify(_('Cards played are invalid !')) 298 self.parent.host.notify(_('Cards played are invalid !'))
299 self.parent.host.redraw() 299 self.parent.host.redraw()
300 300
301 def cardsPlayed(self, player, cards): 301 def cardsPlayed(self, player, cards):
302 """A card has been played by player""" 302 """A card has been played by player"""
303 QuickCardGame.cardsPlayed(self, player, cards) 303 QuickCardGame.cardsPlayed(self, player, cards)
304 self.table.putCard(self.getPlayerLocation(player),self.played[player]) 304 self.table.putCard(self.getPlayerLocation(player),self.played[player])
305 self._checkState() 305 self._checkState()
306 self.parent.host.redraw() 306 self.parent.host.redraw()
307 307
308 def _checkState(self): 308 def _checkState(self):
309 if isinstance(self.center.widget_list[1].original_widget, Hand): #if we have a hand displayed 309 if isinstance(self.center.widget_list[1].original_widget, Hand): #if we have a hand displayed
310 self.center.widget_list[1] = urwid.Filler(self.table) #we show again the table 310 self.center.widget_list[1] = urwid.Filler(self.table) #we show again the table
311 if self.state == "chien": 311 if self.state == "chien":
312 self.to_show = [] 312 self.to_show = []
315 self.state = "ecart" 315 self.state = "ecart"
316 self.hand.extend(self.to_show) 316 self.hand.extend(self.to_show)
317 self.hand.sort() 317 self.hand.sort()
318 self.to_show = [] 318 self.to_show = []
319 self.hand_wid.update(self.hand) 319 self.hand_wid.update(self.hand)
320 320
321 321
322 ##EVENTS## 322 ##EVENTS##
323 def onClick(self, hand, card_wid): 323 def onClick(self, hand, card_wid):
324 """Called when user do an action on the hand""" 324 """Called when user do an action on the hand"""
325 if not self.state in ['play','ecart','wait_for_ecart']: 325 if not self.state in ['play','ecart','wait_for_ecart']: