def on_touch_down(self, touch): if self.replaceable and self.collide_point(*touch.pos): chooser = GridLayout(rows=4, cols=4, size_hint=(1, 1)) dummy = type("dummy", (object, ), dict(operation=None)) popup = Popup( title='Replace gate', content=chooser, #auto_dismiss=False, size_hint=(0.4, 0.4), center=(self.center)) for op in range(16): dummy.operation = op widget = get_visualization_of_bgate(dummy) button = Button(size_hint=(1, 1), text=boolean.get_name_of_bgate(op)) layout = FloatLayout() layout.add_widget(widget) widget.pos_hint = {"center_x": 0.5, "center_y": 0.5} button.add_widget(layout) chooser.add_widget(button) # def update(*largs, **kwargs): # print "Updating size/pos of operation %d" % op # widget.size = button.size # widget.center = button.center # button.on_pos = button.on_size = update def choose_op(op=op, *largs): self.op._update_table(op) self.remove_widget(self.gate) self.gate = get_visualization_of_bgate(self.op) self.gate.size_hint = (1, 0.55) self.add_widget(self.gate) popup.dismiss(force=True) button.on_press = choose_op popup.attach_to = self popup.open() return super(BGate, self).on_touch_down(touch)