|
3 | 3 |
|
4 | 4 | from .flipping_aztecdiamond import *
|
5 | 5 | from sage_widget_adapters.graphs.graph_grid_view_adapter import GraphGridViewAdapter
|
6 |
| -from sage_combinat_widgets.grid_view_widget import GridViewWidget, ButtonCell, BlankButton, styled_button_cell |
| 6 | +from sage_combinat_widgets.grid_view_widget import GridViewWidget, ButtonCell, BlankButton, StyledButtonCell |
7 | 7 | from ipywidgets import Layout
|
8 | 8 | from traitlets import dlink, HasTraits, Bool, observe, All
|
9 | 9 | from contextlib import contextmanager
|
@@ -143,6 +143,32 @@ def unlink(self):
|
143 | 143 | source[0].unobserve(self._update, names=source[1])
|
144 | 144 | self.double_source, self.target = None, None
|
145 | 145 |
|
| 146 | + |
| 147 | +class MyStyledButtonCell(StyledButtonCell): |
| 148 | + def _handle_msg(self, msg): |
| 149 | + r""" |
| 150 | + Override needed to prevent propagation |
| 151 | + when a domino is pressed, in some cases. |
| 152 | + """ |
| 153 | + data = msg['content']['data'] |
| 154 | + if data['method'] != 'update' or not 'state' in data or ('buffer_paths' in data and data['buffer_paths']): |
| 155 | + super(FlippinDominosWidget)._handle_msg(msg) |
| 156 | + state = data['state'] |
| 157 | + try: |
| 158 | + self.set_state(state) |
| 159 | + except: |
| 160 | + pass |
| 161 | + |
| 162 | + |
| 163 | +def my_styled_button_cell(disabled=False, style_name='', addable=False): |
| 164 | + class_name = "{}Button".format(style_name.capitalize()) |
| 165 | + if disabled: |
| 166 | + class_name = "Disabled" + class_name |
| 167 | + elif addable: |
| 168 | + class_name = "Addable" + class_name |
| 169 | + return type(class_name, (MyStyledButtonCell,), {'disable': disabled, 'css_class': style_name, 'addable': addable}) |
| 170 | + |
| 171 | + |
146 | 172 | class Domino(HasTraits):
|
147 | 173 | r"""Objet non représenté en lui-même, les 2
|
148 | 174 | boutons qu'il contient étant, eux, des widgets"""
|
@@ -250,19 +276,16 @@ def __init__(self, g, css_classes=['b0', 'b1', 'b2', 'b3', 'b4']):
|
250 | 276 | with flipping aztec diamond graph `g`
|
251 | 277 | """
|
252 | 278 | self.css_classes = css_classes
|
253 |
| - #self.resetting = None |
254 |
| - #self.resetting = True |
255 | 279 | super(FlippingDominosWidget, self).__init__(g, adapter = FlippingDominosAdapter(),
|
256 | 280 | cell_layout = smallblyt,
|
257 |
| - cell_widget_classes=[styled_button_cell(), |
258 |
| - styled_button_cell(style_name='b1'), |
259 |
| - styled_button_cell(style_name='b2'), |
260 |
| - styled_button_cell(style_name='b3'), |
261 |
| - styled_button_cell(style_name='b4'), |
| 281 | + cell_widget_classes=[my_styled_button_cell(), |
| 282 | + my_styled_button_cell(style_name='b1'), |
| 283 | + my_styled_button_cell(style_name='b2'), |
| 284 | + my_styled_button_cell(style_name='b3'), |
| 285 | + my_styled_button_cell(style_name='b4'), |
262 | 286 | ],
|
263 | 287 | cell_widget_class_index=make_cell_widget_class_index(g),
|
264 | 288 | blank_widget_class = BlankButton)
|
265 |
| - self.resetting_cells = [] |
266 | 289 |
|
267 | 290 | def draw(self):
|
268 | 291 | self.dominos = {}
|
@@ -312,7 +335,6 @@ def set_cell(self, change):
|
312 | 335 | print("set_cell()", change.name, change.old, change.new)
|
313 | 336 | else:
|
314 | 337 | print("set_cell()", change.name)
|
315 |
| - # Try to reset everything right now to avoid unwanted propagations |
316 | 338 | click_pos = extract_coordinates(change.name)
|
317 | 339 | domino = self.domino_for_position(click_pos)
|
318 | 340 | if not domino: # or domino.donottrack:
|
|
0 commit comments