# HG changeset patch # User souliane # Date 1382983489 -3600 # Node ID af0d08a84cc6da832ab93bfe4b8dc256cb12ae95 # Parent ae95b032741290e3d52ade05ffdcb52f4e54a7da 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. diff -r ae95b0327412 -r af0d08a84cc6 frontends/src/primitivus/card_game.py --- a/frontends/src/primitivus/card_game.py Mon Oct 28 18:49:01 2013 +0100 +++ b/frontends/src/primitivus/card_game.py Mon Oct 28 19:04:49 2013 +0100 @@ -109,9 +109,12 @@ def update(self, hand): """Update the hand displayed in this widget @param hand: list of Card""" - del self.columns.widget_list[:] - del self.columns.column_types[:] - self.columns.contents.append((urwid.Text(''),('weight',1, False))) + try: + del self.columns.widget_list[:] + del self.columns.column_types[:] + except IndexError: + pass + self.columns.contents.append((urwid.Text(''), ('weight', 1, False))) for card in hand: widget = CardDisplayer(card) self.columns.widget_list.append(widget) @@ -260,7 +263,7 @@ @param xml_data: SàT xml representation of the form""" misc = {'callback': self.contratSelected} form = XMLUI(self.parent.host, xml_data, title=_('Please choose your contrat'), options=['NO_CANCEL'], misc=misc) - form.show() + form.show(valign='top') def showCards(self, game_stage, cards, data): """Display cards in the middle of the game (to show for e.g. chien ou poignée)""" diff -r ae95b0327412 -r af0d08a84cc6 frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Mon Oct 28 18:49:01 2013 +0100 +++ b/frontends/src/primitivus/primitivus Mon Oct 28 19:04:49 2013 +0100 @@ -321,10 +321,10 @@ #we still have popup to show, we display it self.showPopUp(next_popup) - def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40): + def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, valign='middle'): "Show a pop-up window if possible, else put it in queue" - if not isinstance(self.loop.widget,urwid.Overlay): - display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), 'middle', ('relative', perc_height)) + if not isinstance(self.loop.widget, urwid.Overlay): + display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), valign, ('relative', perc_height)) self.loop.widget = display_widget self.redraw() else: diff -r ae95b0327412 -r af0d08a84cc6 frontends/src/primitivus/xmlui.py --- a/frontends/src/primitivus/xmlui.py Mon Oct 28 18:49:01 2013 +0100 +++ b/frontends/src/primitivus/xmlui.py Mon Oct 28 19:04:49 2013 +0100 @@ -105,7 +105,7 @@ self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) elif type_=="list": style=[] if elem.getAttribute("multi")=='yes' else ['single'] - ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange) + ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange if self.type == "param" else None) ctrl.selectValue(elem.getAttribute("value")) self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) elif type_=="button": @@ -210,15 +210,18 @@ ret_wid.addFooter(grid_wid) return ret_wid - def show(self,show_type = 'popup'): + def show(self, show_type='popup', valign='middle'): """Show the constructed UI @param show_type: how to show the UI: - popup - - window""" + - window + @param valign: vertical alignment when show_type is 'popup'. + Ignored when show_type is 'window'. + """ self.__dest = "popup" decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or '')) if show_type == 'popup': - self.host.showPopUp(decorated) + self.host.showPopUp(decorated, valign=valign) elif show_type == 'window': self.host.addWindow(decorated) else: