def setUp(self): self.TM = mvm.TableManager() self.HM = mvm.HistoryManager() self.GB = mvm.GraphBox(self.TM, self.HM, True) self.CB = mvm.ChangeBox(self.TM) self.SB = mvm.StatBox(self.TM) self.AB = mvm.AddBox(self.TM) self.IB = mvm.InfoBox(DummyParent())
class ChangeBox(GridLayout): '''displays current dice and allows to change. parent app is what's called for dice actions and info updates. all calls are self.parent_app.request_something(*args).''' view_model = ObjectProperty(mvm.ChangeBox(mvm.TableManager())) def __init__(self, **kwargs): super(ChangeBox, self).__init__(**kwargs) self.cols = 1 self.old_dice = [] def add_rm(self, btn): '''uses die stored in button and btn text to request add or rm''' self.view_model.add_rm(int(btn.text), btn.die) self.parent.parent.do_update() def reset(self, btn): '''resets current table back to empty and display instructions''' self.view_model.reset() self.parent.parent.do_update() self.clear_widgets() self.add_widget(Label(text=INTRO_TEXT, text_size=self.size, valign='top', halign='center')) def update(self): '''updates the current dice after add, rm or clear''' new_dice = [] button_list = self.view_model.display() self.clear_widgets() max_height = self.height/10 reset = Button(text='reset table', on_press=self.reset, size_hint=(1, None), height=0.75*max_height) self.add_widget(reset) if button_list: new_height = min((self.height - reset.height) / len(button_list), max_height) for labels, die_ in button_list: temp = labels[:] labels = [] for label in temp: if '50' not in label or 'D' in label: labels.append(label) box = BoxLayout(size_hint=(0.8, None), height=new_height, orientation='horizontal') self.add_widget(box) x_hint = round(1./(len(labels) + 2), 2) for label in labels: if label[0] == '-' or label[0] == '+': btn = FlashButton( text=label, size_hint=(x_hint, 1), die=die_, on_press=lambda btn: btn.delay(self.add_rm, btn) ) box.add_widget(btn) else: flash = FlashLabel(text=label, size_hint=(3 * x_hint, 1)) box.add_widget(flash) new_dice.append(label) if label not in self.old_dice: Clock.schedule_once(flash.flash_it, 0.01) self.old_dice = new_dice
def __init__(self, **kwargs): super(DicePlatform, self).__init__(**kwargs) table = mvm.TableManager() history = mvm.HistoryManager() self._read_hist_msg = history.read_history() change = mvm.ChangeBox(table) add = mvm.AddBox(table) stat = mvm.StatBox(table) graph = mvm.GraphBox(table, history, False) info = mvm.InfoBox(table) self.ids['change_box'].view_model = change self.ids['add_box'].view_model = add self.ids['stat_box'].view_model = stat self.ids['graph_box'].view_model = graph self.ids['info_box'].view_model = info self.initializer()