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())
def test_history_manager_read_history(self): self.TM.request_add(1, dt.Die(1)) obj = self.TM.request_plot_obj(True) self.HM.add_plot_obj(obj) self.HM.write_history() to_test = mvm.HistoryManager() msg = to_test.read_history() self.assertEqual(msg, 'ok') self.assertEqual(self.HM.get_labels(), [('1D1', [(1, 1)])])
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()
def test_graph_box_graph_it_retrieves_according_to_use_axes(self): self.TM.request_add(1, dt.Die(1)) axes_obj = self.TM.request_plot_obj(True) axes_data = (axes_obj['text'], axes_obj['pts']) pts_obj = self.TM.request_plot_obj(False) pts_data = (pts_obj['text'], pts_obj['pts']) pts_GB = mvm.GraphBox(self.TM, mvm.HistoryManager(), False) self.assertNotEqual(axes_obj, pts_obj) self.assertEqual( pts_GB.graph_it([('1D1', [(1, 1)])]), ((1, 1), (100.0, 100.0), [pts_data]) ) self.assertEqual( self.GB.graph_it([('1D1', [(1, 1)])]), ((1, 1), (100.0, 100.0), [axes_data]) )
class GraphBox(BoxLayout): '''buttons for making graphs. 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.GraphBox(mvm.TableManager(), mvm.HistoryManager(), True)) def __init__(self, **kwargs): super(GraphBox, self).__init__(**kwargs) self.confirm = Popup(title='Delete everything?', content=BoxLayout(), size_hint=(0.8, 0.4), title_align='center', title_size=75) self.confirm.content.add_widget(Button(text='EVERY\nTHING!!!', on_press=self.clear_all, texture_size=self.size)) self.confirm.content.add_widget(Button(text='never\nmind', on_press=self.confirm.dismiss)) def initialize(self): '''called at main app init. workaround for kv file loading after py''' self.ids['graph_space'].add_widget(PlotCheckBox(size_hint=(1, 0.5), parent_obj=self)) self.update() def update(self): '''updates the current window to display new graph history and current table to graph''' current, history = self.view_model.display() #sz_hint for 'past graphs' label to take up all the space #base_y make sure other widgets fit rows = len(history) + 3 base_y = .99/rows if base_y > 0.1: base_y = 0.1 sz_hint = (1, 1 - (rows - 1) * base_y) self.ids['graph_space'].clear_widgets() self.ids['graph_space'].add_widget(Label(text='past graphs', halign='center', size_hint=sz_hint)) for text_, tuple_list_ in history: check = PlotCheckBox(size_hint=(0.79, base_y), active=False, tuple_list=tuple_list_) reload_ = FlashButton( size_hint=(0.2, base_y), lst=[text_, tuple_list_], max_lines=1, text='reload', valign='middle', halign='center', on_press=lambda btn: btn.delay(self.reload, btn) ) self.ids['graph_space'].add_widget(check) self.ids['graph_space'].add_widget(reload_) check.text = text_ self.ids['graph_space'].add_widget(Label(text='new table', size_hint=(1, base_y))) check = PlotCheckBox(size_hint=(1, base_y), active=True, tuple_list=current[1]) self.ids['graph_space'].add_widget(check) check.text = current[0] Clock.schedule_once(lambda dt: check.ids['label'].flash_it(), 0.01) def reload(self, btn): '''reloads from history to current table''' self.view_model.reload(btn.lst[0], btn.lst[1]) self.parent.parent.do_update() def graph_it(self): '''prepares plot and calls PlotPopup''' to_plot = [] for item in self.ids['graph_space'].children[:]: if isinstance(item, PlotCheckBox): if item.active: to_plot.append((item.text, item.tuple_list)) plots = self.view_model.graph_it(to_plot) self.update() if plots[2]: plotter = PlotPopup(*plots) plotter.open() def clear_all(self, btn): '''clear graph history''' self.confirm.dismiss() self.view_model.clear_all() self.update() def clear_selected(self): '''clear selected checked items from graph history''' to_clear = [] for item in self.ids['graph_space'].children[1:]: if isinstance(item, PlotCheckBox): if item.active: to_clear.append((item.text, item.tuple_list)) self.view_model.clear_selected(to_clear) self.update()