Exemple #1
0
    def __init__(self, **kwargs):
        super(ABSplashScreen, self).__init__(x=0, y=0, w=240, h=64, **kwargs)

        # AutoBrew
        ab_name = Label(text='AutoBrew', font='16x26', x=10, y=10)
        # ab_img = Image(path='user/beer.png', x=190, y=2)

        # self.add_element(ab_img)
        self.add_element(ab_name)
Exemple #2
0
    def __init__(self, **kwargs):
        self._sel_radius = kwargs.pop('selector_radius')
        self._font = kwargs.pop('font')
        self._colnum = kwargs.pop('cols')
        if 'selector_spacing' in kwargs:
            self._sel_spacing = kwargs.pop('selector_spacing')
        else:
            self._sel_spacing = 2
        if 'value_format' in kwargs:
            self._value_format = kwargs.pop('value_format')
        else:
            self._value_format = '{}'
        font_size = Label.guess_font_size(self._font)

        if font_size is None:
            try:
                self._font_w = kwargs.pop('font_w')
                self._font_h = kwargs.pop('font_h')
            except KeyError:
                raise MenuError('could not guess font size '
                                'and missing arguments "font_w" '
                                'and/or "font_h"')
        else:
            self._font_w = font_size['w']
            self._font_h = font_size['h']

        super(Menu, self).__init__(**kwargs)

        self._items = []
        self._group = RadioGroup()

        # item placement position
        self._current_position = Coordinate(0, 0)

        # calculate maximum length, etc
        col_w = self.w / self._colnum
        self._col_max_len = (col_w - 2 * self._sel_radius -
                             self._sel_spacing) / self._font_w
        self._max_item_count = self._colnum * (
            self.h / (2 * self._sel_radius + self._sel_spacing))

        self._item_value = None
        self._editing = False
Exemple #3
0
    def __init__(self, **kwargs):
        super(ABMainScreen, self).__init__(x=0, y=0, w=240, h=64, **kwargs)

        # AutoBrew
        ab_name = Label(text='AutoBrew', font='16x26', x=10, y=10)
        # ab_img = Image(path='user/beer.png', x=190, y=2)

        # lower buttons
        self._footb_l = Button(text='',
                               font='6x8',
                               x=0,
                               y=self.h - self._foot_btn_height - 1,
                               w=self.w / 4 - 1,
                               h=self._foot_btn_height)
        self._footb_ml = Button(text='Receitas',
                                font='6x8',
                                x=self.w / 4,
                                y=self.h - self._foot_btn_height - 1,
                                w=self.w / 4 - 1,
                                h=self._foot_btn_height)
        self._footb_mr = Button(text='BoilCtl',
                                font='6x8',
                                x=self.w / 2,
                                y=self.h - self._foot_btn_height - 1,
                                w=self.w / 4 - 1,
                                h=self._foot_btn_height)
        self._footb_r = Button(text='MashCtl',
                               font='6x8',
                               x=3 * self.w / 4,
                               y=self.h - self._foot_btn_height - 1,
                               w=self.w / 4 - 1,
                               h=self._foot_btn_height)

        # self.add_element(ab_img)
        self.add_element(ab_name)
        self.add_element(self._footb_l)
        self.add_element(self._footb_ml)
        self.add_element(self._footb_mr)
        self.add_element(self._footb_r)
Exemple #4
0
class ABCtlScreen(Screen):

    _foot_btn_height = 10

    def __init__(self, **kwargs):
        if 'varspace' in kwargs:
            self._varspace = kwargs.pop('varspace')
        else:
            self._varspace = None

        if 'label_1s' in kwargs:
            self._label_1s = kwargs.pop('label_1s')
        else:
            self._label_1s = ''

        if 'label_2s' in kwargs:
            self._label_2s = kwargs.pop('label_2s')
        else:
            self._label_2s = 'Inicia'

        if 'label_3s' in kwargs:
            self._label_3s = kwargs.pop('label_3s')
        else:
            self._label_3s = 'Config'

        if 'label_4s' in kwargs:
            self._label_4s = kwargs.pop('label_4s')
        else:
            self._label_4s = 'Sair'

        if 'label_1c' in kwargs:
            self._label_1c = kwargs.pop('label_1c')
        else:
            self._label_1c = ''

        if 'label_2c' in kwargs:
            self._label_2c = kwargs.pop('label_2c')
        else:
            self._label_2c = 'Edita'

        if 'label_3c' in kwargs:
            self._label_3c = kwargs.pop('label_3c')
        else:
            self._label_3c = 'Status'

        if 'label_4c' in kwargs:
            self._label_4c = kwargs.pop('label_4c')
        else:
            self._label_4c = 'Sair'

        self._title_text = kwargs.pop('title')
        super(ABCtlScreen, self).__init__(x=0, y=0, w=240, h=64, **kwargs)

        # upper 'title'
        self._title = Button(text=_composite_label_text(self._title_text,
                                                        ' ',
                                                        29),
                             font='8x8',
                             x=0,
                             y=0,
                             w=239,
                             h=10)

        # lower buttons
        self._footb_l = Button(text=self._label_1s,
                               font='8x8',
                               x=0, y=self.h-self._foot_btn_height-1,
                               w=self.w/4-1,
                               h=self._foot_btn_height)
        self._footb_ml = Button(text=self._label_2s,
                                font='8x8',
                                x=self.w/4,
                                y=self.h-self._foot_btn_height-1,
                                w=self.w/4-1,
                                h=self._foot_btn_height)
        self._footb_mr = Button(text=self._label_3s,
                                font='8x8',
                                x=self.w/2,
                                y=self.h-self._foot_btn_height-1,
                                w=self.w/4-1,
                                h=self._foot_btn_height)
        self._footb_r = Button(text=self._label_4s,
                               font='8x8',
                               x=3*self.w/4,
                               y=self.h-self._foot_btn_height-1,
                               w=self.w/4-1,
                               h=self._foot_btn_height)

        self._statframe = Frame(x=0,
                                y=self._title.y+self._title.h+1,
                                w=self.w-1,
                                h=(self.h -
                                   self._foot_btn_height -
                                   self._title.h - 3))

        self._configframe = Frame(x=0,
                                  y=(self._title.y +
                                     self._title.h+1),
                                  w=self.w-1,
                                  h=(self.h -
                                     self._foot_btn_height -
                                     self._title.h - 3))

        # message modal
        self._msg_modal = Modal(y=10,
                                x=10,
                                w=self.w-20,
                                h=self.h-20)
        self._modal_label_1 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+2)
        self._modal_label_2 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+16)
        self._modal_label_3 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+30)

        self._msg_modal.add_element(self._modal_label_1)
        self._msg_modal.add_element(self._modal_label_2)
        self._msg_modal.add_element(self._modal_label_3)

        # add stuff
        self.add_element(self._statframe)
        self.add_element(self._configframe)

        self.add_element(self._title)
        self.add_element(self._footb_l)
        self.add_element(self._footb_ml)
        self.add_element(self._footb_mr)
        self.add_element(self._footb_r)

        self.add_element(self._msg_modal)

        # configuration menu
        self._cfgmenu = Menu(x=0,
                             y=self._title.y+self._title.h+3,
                             w=self.w-1,
                             h=(self.h -
                                self._foot_btn_height -
                                self._title.h - 5),
                             selector_radius=5,
                             font='5x12',
                             cols=2,
                             value_format='[{}]')

        self.add_element(self._cfgmenu)

        # track manual mode
        self._manual = False
        self._manual_changed = True

        # local state tracking
        self._modal_showing = False
        self._panic_saved_state = None

        # recurrent call
        self._upd_call_id = None

        # configuration / stat
        self._current_frame = 'stat'

    def _show_stats(self):
        self._cfgmenu.hide()
        self._statframe.show()
        self._footb_ml.set_text(self._label_2s)
        self._footb_mr.set_text(self._label_3s)
        self._current_frame = 'stat'

    def _show_config(self):
        self._statframe.hide()
        self._cfgmenu.show()
        self._update_config()
        self._footb_ml.set_text(self._label_2c)
        self._footb_mr.set_text(self._label_3c)
        self._current_frame = 'config'

    def _update_config(self):
        self._cfgmenu.update_values()

    def _screen_added(self, **kwargs):
        super(ABCtlScreen, self)._screen_added(**kwargs)
        # update NOW
        self._cfgmenu.select_first()
        self.update_screen()

    def _confirm_press(self):
        if self._modal_showing:
            self._hide_msg_modal()

    def _cancel_press(self):
        if self._modal_showing:
            self._hide_msg_modal()

    def _show_msg_modal(self, message):
        lines = message.split('\n')

        while len(lines) < 3:
            lines.append('')

        if len(lines) > 3:
            # self.log_err('exceeded number of lines in message, truncating')
            lines = lines[0:3]

        # allocate lines
        self._modal_label_1.set_text(lines[0])
        self._modal_label_2.set_text(lines[1])
        self._modal_label_3.set_text(lines[2])
        self._modal_showing = True
        self._msg_modal.show()

    def _hide_msg_modal(self):
        self._modal_showing = False
        self._msg_modal.hide()

    def _input_event(self, evt):
        if evt['event'] == 'switches.press':

            if self._modal_showing:
                if evt['data'] == '5':
                    self._confirm_press()
                    return
                elif evt['data'] != '4':
                    self._cancel_press()
                    return

            if evt['data'] == '3':
                if self._current_frame == 'config' and\
                   self._cfgmenu.is_editing():
                    self._cfgmenu.cancel_edit()
                # else:
                #    self._parent.activate_screen('main')

            if evt['data'] == '2':
                if self._current_frame == 'stat':
                    self._show_config()
                else:
                    self._cfgmenu.cancel_edit()
                    self._show_stats()

            if evt['data'] == '1':
                if self._current_frame == 'stat':
                    pass
                else:
                    self._cfgmenu.item_click()

        elif evt['event'] == 'mode.change':
            self._manual_changed = True
            if evt['data'] == 'manual':
                self._manual = True
            elif evt['data'] == 'normal':
                self._manual = False

        elif evt['event'] == 'encoder.cw':
            if self._current_frame == 'config':
                self._cfgmenu.select_next()
        elif evt['event'] == 'encoder.ccw':
            if self._current_frame == 'config':
                self._cfgmenu.select_prev()

        elif evt['event'] == 'keypad.press':
            if self._current_frame == 'config':
                if evt['data'] == '*':
                    self._cfgmenu.delete_value()
                    return

                try:
                    numeric_value = int(evt['data'])
                except TypeError:
                    return
                self._cfgmenu.insert_value(numeric_value)

    def _screen_activated(self, **kwargs):
        super(ABCtlScreen, self)._screen_activated(**kwargs)

        # install recurrent call
        self._upd_call_id = self._parent.add_recurrent_call(self.update_screen, 1)

        # show default view
        self._show_stats()

    def _screen_deactivated(self, **kwargs):
        super(ABCtlScreen, self)._screen_deactivated(**kwargs)

        # remove recurrent call
        if self._upd_call_id is not None:
            self._parent.remove_recurrent_call(self._upd_call_id)
            self._upd_call_id = None

    def update_screen(self):
        # update to current values
        main_title = self._title_text
        if self._current_frame == 'config':
            main_title += ' - CONFIG'
        if self._manual:
            self._title.set_text(_composite_label_text(main_title,
                                                       'MANUAL',
                                                       29))
        else:
            self._title.set_text(_composite_label_text(main_title,
                                                       ' ',
                                                       29))
Exemple #5
0
    def __init__(self, **kwargs):
        if 'varspace' in kwargs:
            self._varspace = kwargs.pop('varspace')
        else:
            self._varspace = None

        if 'label_1s' in kwargs:
            self._label_1s = kwargs.pop('label_1s')
        else:
            self._label_1s = ''

        if 'label_2s' in kwargs:
            self._label_2s = kwargs.pop('label_2s')
        else:
            self._label_2s = 'Inicia'

        if 'label_3s' in kwargs:
            self._label_3s = kwargs.pop('label_3s')
        else:
            self._label_3s = 'Config'

        if 'label_4s' in kwargs:
            self._label_4s = kwargs.pop('label_4s')
        else:
            self._label_4s = 'Sair'

        if 'label_1c' in kwargs:
            self._label_1c = kwargs.pop('label_1c')
        else:
            self._label_1c = ''

        if 'label_2c' in kwargs:
            self._label_2c = kwargs.pop('label_2c')
        else:
            self._label_2c = 'Edita'

        if 'label_3c' in kwargs:
            self._label_3c = kwargs.pop('label_3c')
        else:
            self._label_3c = 'Status'

        if 'label_4c' in kwargs:
            self._label_4c = kwargs.pop('label_4c')
        else:
            self._label_4c = 'Sair'

        self._title_text = kwargs.pop('title')
        super(ABCtlScreen, self).__init__(x=0, y=0, w=240, h=64, **kwargs)

        # upper 'title'
        self._title = Button(text=_composite_label_text(self._title_text,
                                                        ' ',
                                                        29),
                             font='8x8',
                             x=0,
                             y=0,
                             w=239,
                             h=10)

        # lower buttons
        self._footb_l = Button(text=self._label_1s,
                               font='8x8',
                               x=0, y=self.h-self._foot_btn_height-1,
                               w=self.w/4-1,
                               h=self._foot_btn_height)
        self._footb_ml = Button(text=self._label_2s,
                                font='8x8',
                                x=self.w/4,
                                y=self.h-self._foot_btn_height-1,
                                w=self.w/4-1,
                                h=self._foot_btn_height)
        self._footb_mr = Button(text=self._label_3s,
                                font='8x8',
                                x=self.w/2,
                                y=self.h-self._foot_btn_height-1,
                                w=self.w/4-1,
                                h=self._foot_btn_height)
        self._footb_r = Button(text=self._label_4s,
                               font='8x8',
                               x=3*self.w/4,
                               y=self.h-self._foot_btn_height-1,
                               w=self.w/4-1,
                               h=self._foot_btn_height)

        self._statframe = Frame(x=0,
                                y=self._title.y+self._title.h+1,
                                w=self.w-1,
                                h=(self.h -
                                   self._foot_btn_height -
                                   self._title.h - 3))

        self._configframe = Frame(x=0,
                                  y=(self._title.y +
                                     self._title.h+1),
                                  w=self.w-1,
                                  h=(self.h -
                                     self._foot_btn_height -
                                     self._title.h - 3))

        # message modal
        self._msg_modal = Modal(y=10,
                                x=10,
                                w=self.w-20,
                                h=self.h-20)
        self._modal_label_1 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+2)
        self._modal_label_2 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+16)
        self._modal_label_3 = Label(text='',
                                    font='5x12',
                                    x=self._msg_modal.x+2,
                                    y=self._msg_modal.y+30)

        self._msg_modal.add_element(self._modal_label_1)
        self._msg_modal.add_element(self._modal_label_2)
        self._msg_modal.add_element(self._modal_label_3)

        # add stuff
        self.add_element(self._statframe)
        self.add_element(self._configframe)

        self.add_element(self._title)
        self.add_element(self._footb_l)
        self.add_element(self._footb_ml)
        self.add_element(self._footb_mr)
        self.add_element(self._footb_r)

        self.add_element(self._msg_modal)

        # configuration menu
        self._cfgmenu = Menu(x=0,
                             y=self._title.y+self._title.h+3,
                             w=self.w-1,
                             h=(self.h -
                                self._foot_btn_height -
                                self._title.h - 5),
                             selector_radius=5,
                             font='5x12',
                             cols=2,
                             value_format='[{}]')

        self.add_element(self._cfgmenu)

        # track manual mode
        self._manual = False
        self._manual_changed = True

        # local state tracking
        self._modal_showing = False
        self._panic_saved_state = None

        # recurrent call
        self._upd_call_id = None

        # configuration / stat
        self._current_frame = 'stat'
Exemple #6
0
    def __init__(self, **kwargs):
        kwargs['title'] = 'Boil Ctl'
        self._recipemgr = kwargs.pop('recipemgr')
        super(ABBoilScreen, self).__init__(**kwargs)

        # labels
        self._state_label = Label(text='STATE', font='5x12', y=2, x=2)

        self._timer_label = Label(text='TIMER',
                                  font='5x12',
                                  **self._state_label.southwest)

        self.ctl_inst = self._varspace.find_driver_by_classname(
            'BoilController')[0]

        # boxes
        self._box_l = Box(x=0,
                          y=0,
                          w=self.w / 2 - 1,
                          h=(self.h - self._foot_btn_height - self._title.h -
                             3))
        self._box_r = Box(x=self.w / 2,
                          y=0,
                          w=self.w / 2 - 1,
                          h=(self.h - self._foot_btn_height - self._title.h -
                             3))

        self._recipe_label = Label(text=_composite_label_text(
            'Receita', 'Nenhum', 23),
                                   font='5x12',
                                   **self._timer_label.southwest)

        # hops

        self._hop_title = Button(text='Lupulo e outros',
                                 font='6x8',
                                 x=self._box_r.x,
                                 y=self._box_r.y,
                                 w=self._box_r.w,
                                 h=10)

        # hops list
        self._hop1 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop_title.southwest + (2, 2))
        self._hop2 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop1.southwest)
        self._hop3 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop2.southwest)
        self._hop4 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop3.southwest)
        self._hop5 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop1.northeast)
        self._hop6 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop5.southwest)
        self._hop7 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop6.southwest)
        self._hop8 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop7.southwest)

        # configure menu
        def get_fn(inst, method):
            return self._varspace.get_driver_method(inst, method)

        def _cfgitems():
            yield MenuItem('boildur',
                           'Duracao Fervura',
                           value_getter=get_fn(self.ctl_inst,
                                               'get_boil_duration'),
                           value_setter=get_fn(self.ctl_inst,
                                               'set_boil_duration'),
                           value_type=int,
                           item_action='edit')

        # add elements
        self._cfgmenu.add_items(_cfgitems())
        self._statframe.add_element(self._state_label)
        self._statframe.add_element(self._timer_label)
        self._statframe.add_element(self._recipe_label)
        self._statframe.add_element(self._box_l)
        self._statframe.add_element(self._box_r)
        self._statframe.add_element(self._hop1)
        self._statframe.add_element(self._hop2)
        self._statframe.add_element(self._hop3)
        self._statframe.add_element(self._hop4)
        self._statframe.add_element(self._hop5)
        self._statframe.add_element(self._hop6)
        self._statframe.add_element(self._hop7)
        self._statframe.add_element(self._hop8)
        self._statframe.add_element(self._hop_title)

        self._screen_state = 'idle'
        self._waiting_stop = False
        self._loaded_recipe = None
Exemple #7
0
class ABBoilScreen(ABCtlScreen):
    def __init__(self, **kwargs):
        kwargs['title'] = 'Boil Ctl'
        self._recipemgr = kwargs.pop('recipemgr')
        super(ABBoilScreen, self).__init__(**kwargs)

        # labels
        self._state_label = Label(text='STATE', font='5x12', y=2, x=2)

        self._timer_label = Label(text='TIMER',
                                  font='5x12',
                                  **self._state_label.southwest)

        self.ctl_inst = self._varspace.find_driver_by_classname(
            'BoilController')[0]

        # boxes
        self._box_l = Box(x=0,
                          y=0,
                          w=self.w / 2 - 1,
                          h=(self.h - self._foot_btn_height - self._title.h -
                             3))
        self._box_r = Box(x=self.w / 2,
                          y=0,
                          w=self.w / 2 - 1,
                          h=(self.h - self._foot_btn_height - self._title.h -
                             3))

        self._recipe_label = Label(text=_composite_label_text(
            'Receita', 'Nenhum', 23),
                                   font='5x12',
                                   **self._timer_label.southwest)

        # hops

        self._hop_title = Button(text='Lupulo e outros',
                                 font='6x8',
                                 x=self._box_r.x,
                                 y=self._box_r.y,
                                 w=self._box_r.w,
                                 h=10)

        # hops list
        self._hop1 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop_title.southwest + (2, 2))
        self._hop2 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop1.southwest)
        self._hop3 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop2.southwest)
        self._hop4 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop3.southwest)
        self._hop5 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop1.northeast)
        self._hop6 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop5.southwest)
        self._hop7 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop6.southwest)
        self._hop8 = ValueCaption(caption='',
                                  maximum_length=11,
                                  font='5x8',
                                  **self._hop7.southwest)

        # configure menu
        def get_fn(inst, method):
            return self._varspace.get_driver_method(inst, method)

        def _cfgitems():
            yield MenuItem('boildur',
                           'Duracao Fervura',
                           value_getter=get_fn(self.ctl_inst,
                                               'get_boil_duration'),
                           value_setter=get_fn(self.ctl_inst,
                                               'set_boil_duration'),
                           value_type=int,
                           item_action='edit')

        # add elements
        self._cfgmenu.add_items(_cfgitems())
        self._statframe.add_element(self._state_label)
        self._statframe.add_element(self._timer_label)
        self._statframe.add_element(self._recipe_label)
        self._statframe.add_element(self._box_l)
        self._statframe.add_element(self._box_r)
        self._statframe.add_element(self._hop1)
        self._statframe.add_element(self._hop2)
        self._statframe.add_element(self._hop3)
        self._statframe.add_element(self._hop4)
        self._statframe.add_element(self._hop5)
        self._statframe.add_element(self._hop6)
        self._statframe.add_element(self._hop7)
        self._statframe.add_element(self._hop8)
        self._statframe.add_element(self._hop_title)

        self._screen_state = 'idle'
        self._waiting_stop = False
        self._loaded_recipe = None

    def _start_boil(self):
        self._footb_ml.set_text('Pausa')
        self._footb_r.set_text('Parar')
        self._varspace.call_driver_method(self.ctl_inst, 'start_boil')
        self._screen_state = 'boil_started'

    def _stop_boil(self):
        self._idle()
        self._varspace.call_driver_method(self.ctl_inst, 'stop_boil')

    def _confirm_stop(self):
        self._waiting_stop = True
        self._show_msg_modal('Realmente parar?\nPressione CONFIRMA')

    def _idle(self):
        self._footb_ml.set_text('Inicia')
        self._footb_r.set_text('Sair')
        self._screen_state = 'idle'

    def _screen_activated(self, **kwargs):
        super(ABBoilScreen, self)._screen_activated(**kwargs)

        self._idle()
        self.load_recipe()
        self._varspace.call_driver_method(self.ctl_inst, 'activate')

    def _screen_deactivated(self, **kwargs):
        super(ABBoilScreen, self)._screen_deactivated(**kwargs)
        self._varspace.call_driver_method(self.ctl_inst, 'deactivate')

    def _hide_hops(self):
        self._hop1.set_caption('')
        self._hop1.set_value('')
        self._hop2.set_caption('')
        self._hop2.set_value('')
        self._hop3.set_caption('')
        self._hop3.set_value('')
        self._hop4.set_caption('')
        self._hop4.set_value('')
        self._hop5.set_caption('')
        self._hop5.set_value('')
        self._hop6.set_caption('')
        self._hop6.set_value('')
        self._hop7.set_caption('')
        self._hop7.set_value('')
        self._hop8.set_caption('')
        self._hop8.set_value('')

    def _hop_label(self, index):
        return self.__getattribute__('_hop{}'.format(index + 1))

    def load_recipe(self):
        active_recipe = self._recipemgr.get_loaded_recipe()

        if active_recipe is not None:
            recipe = self._recipemgr.get_recipe(active_recipe)
            self._loaded_recipe = recipe['abbrev']

            hops = recipe['boil']['hops']
            self._hide_hops()
            for i in range(0, len(hops)):
                self._hop_label(i).set_caption(hops[i]['name'])
                self._hop_label(i).set_value("{}'".format(hops[i]['time']))

            boil_duration = recipe['boil']['duration']
            self._varspace.call_driver_method(self.ctl_inst,
                                              'set_boil_duration',
                                              value=boil_duration)

    def update_screen(self):
        super(ABBoilScreen, self).update_screen()

        bk_temp = self._varspace.call_driver_method(self.ctl_inst,
                                                    'get_bk_temp')

        state = self._varspace.call_driver_method(self.ctl_inst, 'get_state')

        if self._loaded_recipe is not None:
            self._recipe_label.set_text(
                _composite_label_text('Receita', self._loaded_recipe, 23))

        if state == 'boil':

            self._state_label.set_text(
                _composite_label_text('Estado', 'fervendo', 23))

            timer_end = self._varspace.call_driver_method(
                self.ctl_inst, 'get_timer_end')
            timer_time = timer_end - datetime.now()
            if timer_time.total_seconds() > 0:
                self._timer_label.set_text(
                    _composite_label_text('Timer',
                                          str(timer_time).split('.')[0], 23))
        else:

            if state == 'preheat':
                self._state_label.set_text(
                    _composite_label_text('Estado', 'aquecendo', 23))
            else:
                self._state_label.set_text(
                    _composite_label_text('Estado', 'ocioso', 23))

            self._timer_label.set_text(
                _composite_label_text('Timer', 'Nenhum', 23))

    def _confirm_press(self):
        super(ABBoilScreen, self)._confirm_press()

        if self._waiting_stop:
            self._stop_boil()
            self._waiting_stop = False

    def _cancel_press(self):
        super(ABBoilScreen, self)._cancel_press()

        self._waiting_stop = False

    def _input_event(self, evt):

        super(ABBoilScreen, self)._input_event(evt)

        if evt['event'] == 'switches.press':
            if evt['data'] == '3':
                if self._screen_state == 'idle' and\
                   self._current_frame == 'stat':
                    self._parent.activate_screen('main')
                elif self._screen_state != 'idle' and\
                     self._waiting_stop is False:
                    self._confirm_stop()

            elif evt['data'] == '1':
                if self._screen_state == 'idle' and\
                   self._current_frame == 'stat':
                    if self._recipemgr.get_loaded_recipe() is not None:
                        self._start_boil()
                    else:
                        self._show_msg_modal('Nenhuma receita carregada!')