Esempio n. 1
0
    def __init__(self):
        super().__init__()
        quitbutton()
        self.dial = Dial((106, 0), fgcolor = YELLOW, border = 2, pointers = (0.9, 0.7))
        k0 = Knob((0, 0), fgcolor = GREEN, bgcolor=(0, 0, 80), color = (168, 63, 63),
                  border = 2, cb_end = self.callback, cbe_args = ['Knob1'],
                  cb_move = self.knob_moved, cbm_args = (0,))
        k1 = Knob((53, 0), fgcolor = WHITE, border = 2, arc = pi * 1.5,
                  cb_end = self.callback, cbe_args = ['Knob2'],
                  cb_move = self.knob_moved, cbm_args = (1,))

# On/Off toggle grey style
        self.lbl_style = Label((0, 80), font = font10, value = 'Current style: grey')
        bstyle = ButtonList(self.cb_style)
        bstyle.add_button((0, 107), font = font10, fontcolor = WHITE, fgcolor = RED,
                          text = 'Dim', args = (False,))
        bstyle.add_button((0, 107), font = font10, fontcolor = WHITE, fgcolor = GREEN,
                          text = 'Grey', args = (True,))
# On/Off toggle enable/disable
        bs = ButtonList(self.cb_en_dis)
        self.lst_en_dis = (bstyle, k0, k1)
        bs.add_button((53, 107), font = font10, fontcolor = BLACK, fgcolor = GREEN,
                      text = 'Dis', args = (True,))
        bs.add_button((53, 107), font = font10, fontcolor = BLACK, fgcolor = RED,
                      text = 'En', args = (False,))
Esempio n. 2
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font10, value='Dialog box demo.')
     Label((0, 20), font=font10, value='User written and')
     Label((0, 40), font=font10, value='auto generated')
     self.lbl_result = Label((0, 80),
                             font=font10,
                             fontcolor=WHITE,
                             width=70,
                             border=2,
                             fgcolor=RED,
                             bgcolor=DARKGREEN)
     # User written dialog
     fwdbutton(54, 107, UserDialogBox, text='User')
     # Dialog built using DialogBox class
     dialog_elements = (('Yes', GREEN), ('No', RED), ('Foo', YELLOW))
     fwdbutton(0,
               107,
               DialogBox,
               text='Gen',
               args=(font10, ),
               kwargs={
                   'elements': dialog_elements,
                   'label': 'Test dialog'
               })
     quitbutton()
Esempio n. 3
0
class CheckboxScreen(Screen):
    def __init__(self):
        super().__init__()
        self.cb1 = Checkbox((0, 0), callback = self.cbcb, args = (0,))
        self.cb2 = Checkbox((0, 30), fillcolor = RED, callback = self.cbcb, args = (1,))
        self.lstlbl = [Label((30, 0), **labels), Label((30, 30), **labels)]
        self.lbl_result = Label((0, 106), **labels)
        backbutton()
        self.btn_reset = Button((109, 80), font = font10, fgcolor = BLUE,
                               text = 'Reset', fill = True, callback = self.cbreset,
                               onrelease = False, lp_callback = self.callback, lp_args = ('long',))

    def cbreset(self, button):
        self.cb1.value(0)
        self.cb2.value(0)
        self.lbl_result.value('Short')

    def callback(self, button, arg):
        self.lbl_result.value(arg)

    def cbcb(self, checkbox, idx_label):
        if checkbox.value():
            self.lstlbl[idx_label].value('True')
        else:
            self.lstlbl[idx_label].value('False')
Esempio n. 4
0
class RadioScreen(Screen):
    def __init__(self):
        super().__init__()
        table = [
            {'text' : '1', 'args' : ('one',)},
            {'text' : '2', 'args' : ('two',)},
            {'text' : '3', 'args' : ('three',)},
            {'text' : '4', 'args' : ('four',)},
        ]
        Label((0, 0), font = font10, value = 'Radio Buttons')
        x = 0
        self.rb = RadioButtons(BLUE, self.callback) # color of selected button
        self.rb0 = None
        for t in table:
            button = self.rb.add_button((x, 30), shape = CIRCLE, font = font10, fontcolor = WHITE,
                                fgcolor = (0, 0, 90), height = 30, width = 30, **t)
            if self.rb0 is None: # Save for reset button callback
                self.rb0 = button
            x += 43
        self.lbl_result = Label((0, 106), **labels)
        backbutton()
        self.btn_reset = Button((109, 80), font = font10, fgcolor = BLUE, text = 'Reset',
                                fill = True, callback = self.cbreset, onrelease = False,
                                lp_callback = self.callback, lp_args = ('long',))

    def callback(self, button, arg):
        self.lbl_result.value(arg)

    def cbreset(self, button):
        self.rb.value(self.rb0)
        self.lbl_result.value('Short')
Esempio n. 5
0
    def __init__(self):
        super().__init__()
# These tables contain args that differ between members of a set of related buttons
        table = [
            {'fgcolor' : GREEN, 'text' : 'Y', 'args' : ('Oui',),
                'fontcolor' : (0, 0, 0), 'height' : 30, 'shape' : CIRCLE},
            {'fgcolor' : RED, 'text' : 'N', 'args' : ('Non',),
                'height' : 30, 'shape' : CIRCLE},
            {'fgcolor' : BLUE, 'bgcolor' : BLACK, 'text' : '?',
                'args' : ('Que?',), 'fill': False, 'height' : 30, 'shape' : CIRCLE},
            {'fgcolor' : GREY, 'text' : '$', 'args' : ('Rats',),
                'height' : 30, 'width' : 30, 'shape' : CLIPPED_RECT},
        ]
# A Buttonset with two entries
        table_buttonset = [
            {'fgcolor' : YELLOW, 'text' : 'Start', 'args' : ('Live',)},
            {'fgcolor' : RED, 'text' : 'Stop', 'args' : ('Die',)},
        ]


# Uncomment this line to see 'skeleton' style greying-out:
#        Screen.tft.grey_color()
        self.lbl_result = Label((109, 53), **labels)
        backbutton()

# Button assortment
        self.buttons = []
        x = 0
        for t in table:
            b = Button((x, 0), font = font10, callback = self.callback, **t)
            self.buttons.append(b)
            x += 43


# Start/Stop toggle
        self.bs = ButtonList(self.callback)
        self.buttons.append(self.bs)
        self.bs0 = None
        for t in table_buttonset: # Buttons overlay each other at same location
            button = self.bs.add_button((0, 53), shape = CLIPPED_RECT, font = font10,
                                        width = 60, fontcolor = BLACK, **t)
            if self.bs0 is None: # Save for reset button callback
                self.bs0 = button



# Reset button
        r = self.btn_reset = Button((109, 80), font = font10,
                                fgcolor = BLUE, text = 'Reset', fill = True,
                                callback = self.cbreset, onrelease = False,
                                lp_callback = self.callback, lp_args = ('long',))
        self.buttons.append(r)

# Enable/Disable toggle 
        self.bs_en = ButtonList(self.cb_en_dis)
        self.bs_en.add_button((0, 107), font = font10, fontcolor = BLACK, width = 60,
                              fgcolor = GREEN, text = 'Disable', args = (True,))
        self.bs_en.add_button((0, 107), font = font10, fontcolor = BLACK, width = 60,
                              fgcolor = RED, text = 'Enable', args = (False,))
Esempio n. 6
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font = font10, value = 'plot module demo')
     Label((0, 22), font = font10, value = 'RT: simulate realtime')
     fwdbutton(0, 51, PolarScreen, 'Polar')
     fwdbutton(0, 79, XYScreen, 'XY')
     fwdbutton(0, 107, RealtimeScreen, 'RT')
     quitbutton()
Esempio n. 7
0
 def __init__(self):
     super().__init__()
     backbutton()
     Label((142, 45), font = font10, fontcolor = YELLOW, value = 'V')
     Label((145, 70), font = font10, fontcolor = RED, value = 'I')
     g = CartesianGraph((0, 0), height = 127, width = 135, xorigin = 0) # x >= 0
     Curve(g, self.populate, args = (mains_device.vplot,))
     Curve(g, self.populate, args = (mains_device.iplot,), color = RED)
Esempio n. 8
0
 def __init__(self):
     super().__init__()
     self.cb1 = Checkbox((0, 0), callback = self.cbcb, args = (0,))
     self.cb2 = Checkbox((0, 30), fillcolor = RED, callback = self.cbcb, args = (1,))
     self.lstlbl = [Label((30, 0), **labels), Label((30, 30), **labels)]
     self.lbl_result = Label((0, 106), **labels)
     backbutton()
     self.btn_reset = Button((109, 80), font = font10, fgcolor = BLUE,
                            text = 'Reset', fill = True, callback = self.cbreset,
                            onrelease = False, lp_callback = self.callback, lp_args = ('long',))
Esempio n. 9
0
    def __init__(self):
        super().__init__()
        quitbutton()
        # Dropdown
        self.lbl_dd = Label((0, 80),
                            font=font10,
                            width=60,
                            border=2,
                            bgcolor=DARKGREEN,
                            fgcolor=RED)
        self.dropdown = Dropdown((0, 0),
                                 font=font10,
                                 width=65,
                                 callback=self.cbdb,
                                 elements=('Dog', 'Cat', 'Rat', 'Goat', 'Pig'))
        # Listbox
        self.listbox = Listbox(
            (80, 0),
            font=font10,
            width=79,
            bgcolor=GREY,
            fgcolor=YELLOW,
            select_color=BLUE,
            elements=('aardvark', 'zebra', 'armadillo', 'warthog'),
            callback=self.cblb)

        self.btnrep = Button((0, 40),
                             height=20,
                             font=font10,
                             callback=self.cbrep,
                             fgcolor=RED,
                             text='Report',
                             shape=RECTANGLE,
                             width=60)

        # Enable/Disable toggle
        self.bs_en = ButtonList(self.cb_en_dis)
        self.bs_en.add_button((0, 107),
                              font=font10,
                              fontcolor=BLACK,
                              height=20,
                              width=60,
                              fgcolor=GREEN,
                              shape=RECTANGLE,
                              text='Disable',
                              args=(True, ))
        self.bs_en.add_button((0, 107),
                              font=font10,
                              fontcolor=BLACK,
                              height=20,
                              width=60,
                              fgcolor=RED,
                              shape=RECTANGLE,
                              text='Enable',
                              args=(False, ))
Esempio n. 10
0
 def __init__(self):
     super().__init__()
     labels = {
         'width': 50,
         'fontcolor': WHITE,
         'border': 2,
         'fgcolor': RED,
         'bgcolor': DARKGREEN,
         'font': font10,
     }
     quitbutton()
     self.meter = Meter((129, 0),
                        font=font6,
                        legends=('0', '5', '10'),
                        pointercolor=YELLOW,
                        fgcolor=CYAN)
     self.lbl_result = Label((25, 80), **labels)
     self.led = LED((0, 80), border=2)
     self.master = HorizSlider((0, 16),
                               font=font6,
                               fgcolor=YELLOW,
                               fontcolor=WHITE,
                               legends=('0', '5', '10'),
                               cb_end=self.callback,
                               cbe_args=('Master', ),
                               cb_move=self.master_moved,
                               value=0.5,
                               border=2)
     self.slave = HorizSlider((0, 44),
                              fgcolor=GREEN,
                              cbe_args=('Slave', ),
                              cb_move=self.slave_moved,
                              border=2)
     loop = asyncio.get_event_loop()
     loop.create_task(self.coro())
     # On/Off toggle: enable/disable quit button and one slider
     bs = ButtonList(self.cb_en_dis)
     lst_en_dis = [self.slave, self.master]
     button = bs.add_button((0, 107),
                            font=font10,
                            fontcolor=BLACK,
                            fgcolor=GREEN,
                            text='Dis',
                            args=[True, lst_en_dis])
     button = bs.add_button((0, 107),
                            font=font10,
                            fontcolor=BLACK,
                            fgcolor=RED,
                            text='En',
                            args=[False, lst_en_dis])
Esempio n. 11
0
    def __init__(self):
        super().__init__()
# tabulate data that varies between buttons
        table = [
            {'text' : 'F', 'args' : ('fwd',)},
            {'text' : 'B', 'args' : ('back',)},
            {'text' : 'U', 'args' : ('up',)},
            {'text' : 'D', 'args' : ('down',)},
        ]
        Label((0, 0), font = font10, value = 'Highlight Buttons')
# Highlighting buttons
        x = 0
        for t in table:
            Button((x, 30), shape = CIRCLE, fgcolor = GREY, fontcolor = BLACK, litcolor = WHITE,
                font = font10, callback = self.callback, height = 30, **t)
            x += 43
        self.lbl_result = Label((0, 106), **labels)
        backbutton()
Esempio n. 12
0
class KnobScreen(Screen):
    def __init__(self):
        super().__init__()
        quitbutton()
        self.dial = Dial((106, 0), fgcolor = YELLOW, border = 2, pointers = (0.9, 0.7))
        k0 = Knob((0, 0), fgcolor = GREEN, bgcolor=(0, 0, 80), color = (168, 63, 63),
                  border = 2, cb_end = self.callback, cbe_args = ['Knob1'],
                  cb_move = self.knob_moved, cbm_args = (0,))
        k1 = Knob((53, 0), fgcolor = WHITE, border = 2, arc = pi * 1.5,
                  cb_end = self.callback, cbe_args = ['Knob2'],
                  cb_move = self.knob_moved, cbm_args = (1,))

# On/Off toggle grey style
        self.lbl_style = Label((0, 80), font = font10, value = 'Current style: grey')
        bstyle = ButtonList(self.cb_style)
        bstyle.add_button((0, 107), font = font10, fontcolor = WHITE, fgcolor = RED,
                          text = 'Dim', args = (False,))
        bstyle.add_button((0, 107), font = font10, fontcolor = WHITE, fgcolor = GREEN,
                          text = 'Grey', args = (True,))
# On/Off toggle enable/disable
        bs = ButtonList(self.cb_en_dis)
        self.lst_en_dis = (bstyle, k0, k1)
        bs.add_button((53, 107), font = font10, fontcolor = BLACK, fgcolor = GREEN,
                      text = 'Dis', args = (True,))
        bs.add_button((53, 107), font = font10, fontcolor = BLACK, fgcolor = RED,
                      text = 'En', args = (False,))

# CALLBACKS
# cb_end occurs when user stops touching the control
    def callback(self, knob, control_name):
        print('{} returned {}'.format(control_name, knob.value()))

    def knob_moved(self, knob, pointer):
        val = knob.value() # range 0..1
        self.dial.value(2 * (val - 0.5) * pi, pointer)


    def cb_en_dis(self, button, disable):
        for item in self.lst_en_dis:
            item.greyed_out(disable)

    def cb_style(self, button, desaturate):
        self.lbl_style.value(''.join(('Current style: ', 'grey' if desaturate else 'dim')))
        Screen.set_grey_style(desaturate = desaturate)
Esempio n. 13
0
    def __init__(self):
        super().__init__()
        self.pwr_range = 3000
# Buttons
        fwdbutton(57, IntegScreen, 'Integ', CYAN)
        fwdbutton(82, PlotScreen, 'Plot', YELLOW)
# Labels
        self.lbl_pf = Label((0, 31), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_v = Label((0, 56), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_i = Label((0, 81), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_p = Label((0,106), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_va = Label((80,106), font = font10, width = 79, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
# Dial
        self.dial = Dial((109, 0), fgcolor = YELLOW, border = 2)
# Dropdown
        self.dropdown = Dropdown((0, 0), font = font10, width = 80, callback = self.cbdb,
                                 elements = ('3000W', '600W', '150W', '60W', '30W'))
        self.led = LED((84, 0), color = GREEN)
        self.led.value(True)
Esempio n. 14
0
    def __init__(self):
        super().__init__()
        table_highlight = [
            {'text' : '1', 'args' : (HighlightScreen,)},
            {'text' : '2', 'args' : (RadioScreen,)},
            {'text' : '3', 'args' : (AssortedScreen,)},
            {'text' : '4', 'args' : (CheckboxScreen,)},
        ]
        quitbutton()
        Label((0, 0), font = font10, value = 'Choose screen')
        self.lst_en_dis = []
        x = 0
        for t in table_highlight:
            b = Button((x, 25), font = font10, shape = CIRCLE, fgcolor = BLUE,
                       fontcolor = BLACK, callback = self.callback,
                       height = 30, **t)
            self.lst_en_dis.append(b)
            x += 43
# Enable/Disable toggle 
        self.bs_en = ButtonList(self.cb_en_dis)
        self.bs_en.add_button((0, 107), font = font10, fontcolor = BLACK, width = 60,
                              fgcolor = GREEN, text = 'Disable', args = (True,))
        self.bs_en.add_button((0, 107), font = font10, fontcolor = BLACK, width = 60,
                              fgcolor = RED, text = 'Enable', args = (False,))
Esempio n. 15
0
class BaseScreen(Screen):
    def __init__(self):
        super().__init__()
        self.pwr_range = 3000
# Buttons
        fwdbutton(57, IntegScreen, 'Integ', CYAN)
        fwdbutton(82, PlotScreen, 'Plot', YELLOW)
# Labels
        self.lbl_pf = Label((0, 31), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_v = Label((0, 56), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_i = Label((0, 81), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_p = Label((0,106), font = font10, width = 75, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_va = Label((80,106), font = font10, width = 79, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
# Dial
        self.dial = Dial((109, 0), fgcolor = YELLOW, border = 2)
# Dropdown
        self.dropdown = Dropdown((0, 0), font = font10, width = 80, callback = self.cbdb,
                                 elements = ('3000W', '600W', '150W', '60W', '30W'))
        self.led = LED((84, 0), color = GREEN)
        self.led.value(True)
# Dropdown callback: set range
    def cbdb(self, dropdown):
        self.pwr_range = int(dropdown.textvalue()[: -1])  # String of form 'nnnW'
        mains_device.set_range(self.pwr_range)
#        print('Range set to', self.pwr_range, dropdown.value())

    def reading(self, phase, vrms, irms, pwr, nelems, ovr):
#        print(phase, vrms, irms, pwr, nelems)
        self.lbl_v.value('{:5.1f}V'.format(vrms))
        if ovr:
            self.lbl_i.value('----')
            self.lbl_p.value('----')
            self.lbl_pf.value('----')
            self.lbl_va.value('----')
        else:
            self.lbl_i.value('{:6.3f}A'.format(irms))
            self.lbl_p.value('{:5.1f}W'.format(pwr))
            self.lbl_pf.value('PF:{:4.2f}'.format(pwr /(vrms * irms)))
            self.lbl_va.value('{:5.1f}VA'.format(vrms * irms))
        self.dial.value(phase + 1.5708)  # Conventional phasor orientation.
        if ovr:
            self.led.color(RED)  # Overrange
        elif abs(pwr) < abs(self.pwr_range) / 5:
            self.led.color(YELLOW)  # Underrange
        else:
            self.led.color(GREEN)  # OK

    def on_hide(self):
        mains_device.set_callback(None)  # Stop readings

    def after_open(self):
        mains_device.set_callback(self.reading)
Esempio n. 16
0
    def __init__(self):
        super().__init__()
# Buttons
        backbutton()
        plotbutton(80, PlotScreen, YELLOW)
# Labels
        self.lbl_p = Label((0, 0), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 4), font = font10, value = 'Power')
        self.lbl_pmax = Label((0, 30), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 34), font = font10, value = 'Max')
        self.lbl_pin = Label((0, 55), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_pmin = Label((0, 80), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 84), font = font10, value = 'Min')
        self.lbl_w_hr = Label((0,105), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_t = Label((88, 105), font = font10, width = 70, border = 2, bgcolor = DARKGREEN, fgcolor = RED)

        table = [
            {'fgcolor' : GREEN, 'text' : 'Max Gen', 'args' : (True,)},
            {'fgcolor' : BLUE, 'text' : 'Mean', 'args' : (False,)},
        ]
        bl = ButtonList(self.buttonlist_cb)
        for t in table: # Buttons overlay each other at same location
            bl.add_button((90, 56), width = 70, font = font10, fontcolor = BLACK, **t)
        self.showmean = False
        self.t_reading = None  # Time of last reading
        self.t_start = None  # Time of 1st reading
        self.joules = 0  # Cumulative energy
        self.overrange = False
        self.wmax = 0  # Max power out
        self.wmin = 0  # Max power in
        self.pwr_min = 10000 # Power corresponding to minimum absolute value
Esempio n. 17
0
class IntegScreen(Screen):
    def __init__(self):
        super().__init__()
# Buttons
        backbutton()
        plotbutton(80, PlotScreen, YELLOW)
# Labels
        self.lbl_p = Label((0, 0), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 4), font = font10, value = 'Power')
        self.lbl_pmax = Label((0, 30), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 34), font = font10, value = 'Max')
        self.lbl_pin = Label((0, 55), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_pmin = Label((0, 80), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        Label((90, 84), font = font10, value = 'Min')
        self.lbl_w_hr = Label((0,105), font = font10, width = 78, border = 2, bgcolor = DARKGREEN, fgcolor = RED)
        self.lbl_t = Label((88, 105), font = font10, width = 70, border = 2, bgcolor = DARKGREEN, fgcolor = RED)

        table = [
            {'fgcolor' : GREEN, 'text' : 'Max Gen', 'args' : (True,)},
            {'fgcolor' : BLUE, 'text' : 'Mean', 'args' : (False,)},
        ]
        bl = ButtonList(self.buttonlist_cb)
        for t in table: # Buttons overlay each other at same location
            bl.add_button((90, 56), width = 70, font = font10, fontcolor = BLACK, **t)
        self.showmean = False
        self.t_reading = None  # Time of last reading
        self.t_start = None  # Time of 1st reading
        self.joules = 0  # Cumulative energy
        self.overrange = False
        self.wmax = 0  # Max power out
        self.wmin = 0  # Max power in
        self.pwr_min = 10000 # Power corresponding to minimum absolute value

    def reading(self, phase, vrms, irms, pwr, nelems, ovr):
        self.wmax = max(self.wmax, pwr)
        self.wmin = min(self.wmin, pwr)
        if abs(pwr) < abs(self.pwr_min):
            self.pwr_min = pwr
        if ovr:
            self.overrange = True
        t_last = self.t_reading # Time of last reading (ms)
        self.t_reading = ticks_ms()
        if self.t_start is None:  # 1st reading
            self.t_start = self.t_reading  # Time of 1st reading
        else:
            self.joules += pwr * ticks_diff(self.t_reading, t_last) / 1000

        secs_since_start = ticks_diff(self.t_reading, self.t_start) / 1000  # Runtime
        mins, secs = divmod(int(secs_since_start), 60)
        hrs, mins = divmod(mins, 60)
        self.lbl_t.value('{:02d}:{:02d}:{:02d}'.format(hrs, mins, secs))
        if ovr:
            self.lbl_p.value('----')
        else:
            self.lbl_p.value('{:5.1f}W'.format(pwr))

        if self.showmean:
            self.lbl_pin.value('{:5.1f}W'.format(self.joules / max(secs_since_start, 1)))
        else:
            self.lbl_pin.value('{:5.1f}W'.format(self.wmin))

        self.lbl_pmin.value('{:5.1f}W'.format(self.pwr_min))
        if self.overrange:  # An overrange occurred during the measurement
            self.lbl_w_hr.value('----')
            self.lbl_pmax.value('----')
        else:
            self.lbl_pmax.value('{:5.1f}W'.format(self.wmax))
            units = self.joules / 3600
            if units < 1000:
                self.lbl_w_hr.value('{:6.0f}Wh'.format(units))
            else:
                self.lbl_w_hr.value('{:6.2f}KWh'.format(units / 1000))

    def buttonlist_cb(self, button, arg):
        self.showmean = arg

    def on_hide(self):
        mains_device.set_callback(None)  # Stop readings

    def after_open(self):
        mains_device.set_callback(self.reading)
Esempio n. 18
0
class BaseScreen(Screen):
    def __init__(self):
        super().__init__()
        quitbutton()
        # Dropdown
        self.lbl_dd = Label((0, 80),
                            font=font10,
                            width=60,
                            border=2,
                            bgcolor=DARKGREEN,
                            fgcolor=RED)
        self.dropdown = Dropdown((0, 0),
                                 font=font10,
                                 width=65,
                                 callback=self.cbdb,
                                 elements=('Dog', 'Cat', 'Rat', 'Goat', 'Pig'))
        # Listbox
        self.listbox = Listbox(
            (80, 0),
            font=font10,
            width=79,
            bgcolor=GREY,
            fgcolor=YELLOW,
            select_color=BLUE,
            elements=('aardvark', 'zebra', 'armadillo', 'warthog'),
            callback=self.cblb)

        self.btnrep = Button((0, 40),
                             height=20,
                             font=font10,
                             callback=self.cbrep,
                             fgcolor=RED,
                             text='Report',
                             shape=RECTANGLE,
                             width=60)

        # Enable/Disable toggle
        self.bs_en = ButtonList(self.cb_en_dis)
        self.bs_en.add_button((0, 107),
                              font=font10,
                              fontcolor=BLACK,
                              height=20,
                              width=60,
                              fgcolor=GREEN,
                              shape=RECTANGLE,
                              text='Disable',
                              args=(True, ))
        self.bs_en.add_button((0, 107),
                              font=font10,
                              fontcolor=BLACK,
                              height=20,
                              width=60,
                              fgcolor=RED,
                              shape=RECTANGLE,
                              text='Enable',
                              args=(False, ))

    def cb_en_dis(self, button, disable):
        self.listbox.greyed_out(disable)
        self.dropdown.greyed_out(disable)
        self.btnrep.greyed_out(disable)

    def cbdb(self, dropdown):
        self.lbl_dd.value(dropdown.textvalue())
        print('dropdown callback:', dropdown.textvalue(), dropdown.value())

    def cblb(self, listbox):
        print('listbox callback:', listbox.textvalue(), listbox.value())

    def cbrep(self, _):
        print('Report:')
        print('listbox', self.listbox.textvalue(), self.listbox.value())
        print('dropdown', self.dropdown.textvalue(), self.dropdown.value())
Esempio n. 19
0
class SliderScreen(Screen):
    def __init__(self):
        super().__init__()
        labels = {
            'width': 50,
            'fontcolor': WHITE,
            'border': 2,
            'fgcolor': RED,
            'bgcolor': DARKGREEN,
            'font': font10,
        }
        quitbutton()
        self.meter = Meter((129, 0),
                           font=font6,
                           legends=('0', '5', '10'),
                           pointercolor=YELLOW,
                           fgcolor=CYAN)
        self.lbl_result = Label((25, 80), **labels)
        self.led = LED((0, 80), border=2)
        self.master = HorizSlider((0, 16),
                                  font=font6,
                                  fgcolor=YELLOW,
                                  fontcolor=WHITE,
                                  legends=('0', '5', '10'),
                                  cb_end=self.callback,
                                  cbe_args=('Master', ),
                                  cb_move=self.master_moved,
                                  value=0.5,
                                  border=2)
        self.slave = HorizSlider((0, 44),
                                 fgcolor=GREEN,
                                 cbe_args=('Slave', ),
                                 cb_move=self.slave_moved,
                                 border=2)
        loop = asyncio.get_event_loop()
        loop.create_task(self.coro())
        # On/Off toggle: enable/disable quit button and one slider
        bs = ButtonList(self.cb_en_dis)
        lst_en_dis = [self.slave, self.master]
        button = bs.add_button((0, 107),
                               font=font10,
                               fontcolor=BLACK,
                               fgcolor=GREEN,
                               text='Dis',
                               args=[True, lst_en_dis])
        button = bs.add_button((0, 107),
                               font=font10,
                               fontcolor=BLACK,
                               fgcolor=RED,
                               text='En',
                               args=[False, lst_en_dis])

# CALLBACKS
# cb_end occurs when user stops touching the control

    def callback(self, slider, device):
        print('{} returned {}'.format(device, slider.value()))

    def master_moved(self, slider):
        val = slider.value()
        self.led.value(val > 0.8)
        self.slave.value(val)
        self.lbl_result.value(to_string(val))

    def cb_en_dis(self, button, disable, itemlist):
        for item in itemlist:
            item.greyed_out(disable)

# Either slave has had its slider moved (by user or by having value altered)

    def slave_moved(self, slider):
        val = slider.value()
        if val > 0.8:
            slider.color(RED)
        else:
            slider.color(GREEN)
        self.lbl_result.value(to_string(val))


# COROUTINE

    async def coro(self):
        oldvalue = 0
        await asyncio.sleep(0)
        while True:
            val = pyb.rng() / 2**30
            steps = 20
            delta = (val - oldvalue) / steps
            for _ in range(steps):
                oldvalue += delta
                self.meter.value(oldvalue)
                await asyncio.sleep_ms(100)
Esempio n. 20
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font10, value='Refresh test')
     backbutton()
Esempio n. 21
0
class VerticalSliderScreen(Screen):
    def __init__(self):
        super().__init__()
        labels = {
            'width': 50,
            'fontcolor': WHITE,
            'border': 2,
            'fgcolor': RED,
            'bgcolor': DARKGREEN,
            'font': font10,
        }
        quitbutton()
        self.dial = Dial((109, 0),
                         fgcolor=YELLOW,
                         border=2,
                         pointers=(0.9, 0.7))
        self.lbl_result = Label((109, 80), **labels)
        self.master = Slider((0, 5),
                             font=font6,
                             fgcolor=YELLOW,
                             fontcolor=WHITE,
                             legends=('0', '5', '10'),
                             cb_end=self.callback,
                             cbe_args=('Master', ),
                             cb_move=self.master_moved,
                             value=0.5,
                             border=2)
        self.slave = Slider((60, 5),
                            fgcolor=GREEN,
                            cbe_args=('Slave', ),
                            cb_move=self.slave_moved,
                            border=2)
        loop = asyncio.get_event_loop()
        loop.create_task(self.coro())
        # On/Off toggle: enable/disable quit button and one slider
        bs = ButtonList(self.cb_en_dis)
        lst_en_dis = [self.slave, self.master]
        button = bs.add_button((109, 53),
                               font=font10,
                               fontcolor=BLACK,
                               fgcolor=GREEN,
                               text='Dis',
                               args=[True, lst_en_dis])
        button = bs.add_button((109, 53),
                               font=font10,
                               fontcolor=BLACK,
                               fgcolor=RED,
                               text='En',
                               args=[False, lst_en_dis])

# CALLBACKS
# cb_end occurs when user stops touching the control

    def callback(self, slider, device):
        print('{} returned {}'.format(device, slider.value()))

    def master_moved(self, slider):
        val = slider.value()
        self.slave.value(val)
        self.lbl_result.value(to_string(val))

    def cb_en_dis(self, button, disable, itemlist):
        for item in itemlist:
            item.greyed_out(disable)

# Slave has had its slider moved (by user or by having value altered)

    def slave_moved(self, slider):
        val = slider.value()
        if val > 0.8:
            slider.color(RED)
        else:
            slider.color(GREEN)
        self.lbl_result.value(to_string(val))


# COROUTINE

    async def coro(self):
        angle = 0
        while True:
            await asyncio.sleep_ms(100)
            delta = self.slave.value()
            angle += pi * 2 * delta / 10
            self.dial.value(angle)
            self.dial.value(angle / 10, 1)