def _update_ball_devices(self, **kwargs): del kwargs # TODO: do not create widgets. just update contents self.ball_device_widgets = [] self.ball_device_widgets.append(Label("BALL COUNTS")) self.ball_device_widgets.append(Divider()) try: for pf in self.machine.playfields.values(): widget = Label('{}: {} '.format(pf.name, pf.balls)) if pf.balls: widget.custom_colour = "pf_active" else: widget.custom_colour = "pf_inactive" self.ball_device_widgets.append(widget) except AttributeError: pass for bd in self.ball_devices: widget = Label('{}: {} ({})'.format(bd.name, bd.balls, bd.state)) if bd.balls: widget.custom_colour = "pf_active" else: widget.custom_colour = "pf_inactive" self.ball_device_widgets.append(widget) self.ball_device_widgets.append(Label("")) self._layout_change = True self._schedule_draw_screen()
def _create_window(self): self.screen = Screen.open() self.frame = Frame(self.screen, self.screen.height, self.screen.width, has_border=False, title="Test") self.frame.set_theme("mpf_theme") title_layout = Layout([1, 5, 1]) self.frame.add_layout(title_layout) title_left = Label("") title_left.custom_colour = "title" title_layout.add_widget(title_left, 0) title = 'Mission Pinball Framework v{}'.format( mpf._version.__version__) # noqa title_text = Label(title, align="^") title_text.custom_colour = "title" title_layout.add_widget(title_text, 1) exit_label = Label("< CTRL + C > TO EXIT", align=">") exit_label.custom_colour = "title_exit" title_layout.add_widget(exit_label, 2) self.layout = MpfLayout([1, 1, 1, 1], fill_frame=True) self.frame.add_layout(self.layout) footer_layout = Layout([1, 1, 1]) self.frame.add_layout(footer_layout) self.footer_memory = Label("", align=">") self.footer_memory.custom_colour = "footer_memory" self.footer_uptime = Label("", align=">") self.footer_uptime.custom_colour = "footer_memory" self.footer_mc_cpu = Label("") self.footer_mc_cpu.custom_colour = "footer_mc_cpu" self.footer_cpu = Label("") self.footer_cpu.custom_colour = "footer_cpu" footer_path = Label(self.machine.machine_path) footer_path.custom_colour = "footer_path" footer_empty = Label("") footer_empty.custom_colour = "footer_memory" footer_layout.add_widget(footer_path, 0) footer_layout.add_widget(self.footer_cpu, 0) footer_layout.add_widget(footer_empty, 1) footer_layout.add_widget(self.footer_mc_cpu, 1) footer_layout.add_widget(self.footer_uptime, 2) footer_layout.add_widget(self.footer_memory, 2) self.scene = Scene([self.frame], -1) self.screen.set_scenes([self.scene], start_scene=self.scene) # prevent main from scrolling out the footer self.layout.set_max_height(self.screen.height - 2)
def _update_switch_layout(self): num = 0 self.switch_widgets = [] self.switches = {} self.switch_widgets.append((Label("SWITCHES"), 1)) self.switch_widgets.append((Divider(), 1)) self.switch_widgets.append((Label(""), 2)) self.switch_widgets.append((Divider(), 2)) for sw in sorted(self.machine.switches.values()): if sw.invert: name = sw.name + '*' else: name = sw.name col = 1 if num <= int(len(self.machine.switches) / 2) else 2 switch_widget = Label(name) if sw.state: switch_widget.custom_colour = "active_switch" self.switch_widgets.append((switch_widget, col)) self.switches[sw.name] = (sw, switch_widget) num += 1 self._schedule_draw_screen()
def __init__(self, screen): super(PlayersFrame, self).__init__( screen, screen.height, screen.width, has_border=False, hover_focus=True, name="Players" ) layout = Layout([1]) layout2 = Layout([1]) self.add_layout(layout) self.add_layout(layout2) padding = Label("", align='^', height=10) padding.custom_colour = "field" layout.add_widget(padding, 0) self.add_effect(self._figlet(self._canvas, {"text": "PLAYERS", "font": 'starwars'},[screen.width // 2, 1], 38)) self.players_title = Label("Scores", height=2, align='^') self.players_label = Label("", height=1000, align='^') self.players_label.custom_colour = "field" layout2.add_widget(self.players_title, 0) layout2.add_widget(self.players_label, 0) self.fix()
def __init__(self, screen): super(ClueFrame, self).__init__(screen, screen.height, screen.width, has_border=False, hover_focus=True, name="Jeopardy Clue") layout = Layout([1]) layout2 = Layout([1]) self.add_layout(layout) self.add_layout(layout2) self.add_effect( self._figlet(self._canvas, { "text": "CLUE", "font": 'starwars' }, [screen.width // 2, 1], 20)) padding = Label("", align='^', height=10) padding.custom_colour = "field" layout.add_widget(padding, 0) self.clue = Label("", align='^') self.clue.custom_colour = "field" layout2.add_widget(self.clue, 0) question_padding = Label("", align='^', height=5) layout2.add_widget(question_padding, 0) self.question = Label("", align='^') self.question.custom_colour = "field" layout2.add_widget(self.question, 0) answer_padding = Label("", align='^', height=10) layout2.add_widget(question_padding, 0) self.buzzed_players = Label("", align='^') self.buzzed_players.custom_colour = "field" layout2.add_widget(self.buzzed_players, 0) # Prepare the Frame for use. self.fix()
def define_grid(self, screen): # Create the grid of categories and values for category_index in range(len(categories)): category = Label(categories[category_index]['category'], align='^') category.custom_colour = "field" self.layouts[0].add_widget(category, category_index) self.layouts[0].add_widget(Divider(), category_index) for clue_index in range(len(categories[category_index]['clues'])): button = Button( categories[category_index]["clues"][clue_index]["points"], self._clicked) button._name = f"{category_index},{clue_index}" button._location = {"x": category_index, "y": clue_index} button._on_click = lambda bound_value=button: self._clicked( screen, bound_value) self.layouts[clue_index + 1].add_widget(button, category_index) self.layouts[clue_index + 1].add_widget( Divider(draw_line=False, height=screen.height // 7), category_index)