Exemple #1
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')
def aclock():
    uv = lambda phi : cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
              'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False)  # Border in fg color
    lbltim = Label(wri, 5, 85, 35)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
        secs.value(sstart * uv(-t[5] * pi/30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1)
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)
        self.reg_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)
Exemple #4
0
class BaseScreen(Screen):
    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()

    def on_open(self):
        self.lbl_result.value(Aperture.value())
Exemple #5
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=DARKBLUE,
                                        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')
Exemple #6
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
        lbl_result = Label((0, 106), **labels)

        def cbbtn(button, arg):
            lbl_result.value(arg)

        x = 0
        for t in table:
            Button((x, 30),
                   shape=CIRCLE,
                   fgcolor=GREY,
                   fontcolor=BLACK,
                   litcolor=WHITE,
                   font=font10,
                   callback=cbbtn,
                   height=30,
                   **t)
            x += 43
        lbl_pad = Label((0, 76),
                        value='touch me',
                        fontcolor=WHITE,
                        border=2,
                        fgcolor=RED,
                        bgcolor=DARKGREEN,
                        font=font10)
        pad = Pad((0, 76),
                  width=lbl_pad.width,
                  onrelease=False,
                  callback=lambda _: lbl_pad.value('Short'),
                  lp_callback=lambda _: lbl_pad.value('Long'))
        backbutton()
Exemple #7
0
def clock(x):
    print('Clock test.')
    refresh(ssd, True)  # Clear any prior image
    lbl = Label(wri, 5, 85, 'Clock')
    dial = Dial(wri, 5, 5, height = 75, ticks = 12, bdcolor=None, label=50)  # Border in fg color
    hrs = Pointer(dial)
    mins = Pointer(dial)
    hrs.value(0 + 0.7j, RED)
    mins.value(0 + 0.9j, YELLOW)
    dm = cmath.rect(1, -cmath.pi/30)  # Rotate by 1 minute (CW)
    dh = cmath.rect(1, -cmath.pi/1800)  # Rotate hours by 1 minute
    for n in range(x):
        refresh(ssd)
        utime.sleep_ms(200)
        mins.value(mins.value() * dm, YELLOW)
        hrs.value(hrs.value() * dh, RED)
        dial.text('ticks: {}'.format(n))
    lbl.value('Done')
def aclock():
    rtc = pyb.RTC()
    uv = lambda phi: cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug',
              'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate Writer
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, font_small, verbose=False)
    wri.set_clip(True, True, False)
    wri_tim = Writer(ssd, font_large, verbose=False)
    wri_tim.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height=215, ticks=12, bdcolor=None, pip=True)
    lbltim = Label(wri_tim, 50, 230, '00.00.00')
    lbldat = Label(wri, 100, 230, 100)
    hrs = Pointer(dial)
    mins = Pointer(dial)

    hstart = 0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    while True:
        t = rtc.datetime(
        )  # (year, month, day, weekday, hours, minutes, seconds, subseconds)
        hang = -t[4] * pi / 6 - t[5] * pi / 360  # Angles of hands in radians
        mang = -t[5] * pi / 30
        if abs(hang -
               mang) < pi / 360:  # Avoid visually confusing overlap of hands
            hang += pi / 30  # by making hr hand lag slightly
        hrs.value(hstart * uv(hang))
        mins.value(mstart * uv(mang))
        lbltim.value('{:02d}.{:02d}'.format(t[4], t[5]))
        lbldat.value('{} {} {} {}'.format(days[t[3] - 1], t[2],
                                          months[t[1] - 1], t[0]))
        refresh(ssd)
        # Power saving: only refresh every 30s
        for _ in range(30):
            upower.lpdelay(1000)
            ssd.update()  # Toggle VCOM
def aclock():
    uv = lambda phi : cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
              'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate Writer
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, font_small, verbose=False)
    wri.set_clip(True, True, False)
    wri_tim = Writer(ssd, font_large, verbose=False)
    wri_tim.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height = 215, ticks = 12, bdcolor=None, pip=True)
    lbltim = Label(wri_tim, 50, 230, '00.00.00')
    lbldat = Label(wri, 100, 230, 100)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hang = -t[3]*pi/6 - t[4]*pi/360  # Angles of hour and minute hands
        mang = -t[4] * pi/30
        sang = -t[5] * pi/30
        if abs(hang - mang) < pi/360:  # Avoid overlap of hr and min hands
            hang += pi/30  # which is visually confusing. Add slight lag to hrs
        hrs.value(hstart * uv(hang))
        mins.value(mstart * uv(mang))
        secs.value(sstart * uv(sang))
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        lbldat.value('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1)
Exemple #10
0
async def aclock():
    do_connect.do_connect()
    asyncio.create_task(set_rtc())
    asyncio.create_task(ramcheck())
    uv = lambda phi: cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('January', 'February', 'March', 'April', 'May', 'June', 'July',
              'August', 'September', 'October', 'November', 'December')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height=130, ticks=12,
                bdcolor=None)  # Border in fg color
    lbltim = Label(wri, 140, 2, 130)
    lblday = Label(wri, 170, 2, 130)
    lblmonth = Label(wri, 190, 2, 130)
    lblyr = Label(wri, 210, 2, 130)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart = 0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j
    t = time.localtime()
    while True:
        hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi / 30 - t[5] * pi / 1800), YELLOW)
        secs.value(sstart * uv(-t[5] * pi / 30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d} {}'.format(t[3], t[4], t[5],
                                                      'BST' if bst else 'UTC'))
        lblday.value('{}'.format(days[t[6]]))
        lblmonth.value('{} {}'.format(t[2], months[t[1] - 1]))
        lblyr.value('{}'.format(t[0]))
        refresh(ssd)
        st = t
        while st == t:
            await asyncio.sleep_ms(100)
            t = time.localtime()
Exemple #11
0
def fields(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, fixed, verbose=False)
    wri.set_clip(False, False, False)
    textfield = Label(wri, 0, 2, wri.stringlen('longer'))
    numfield = Label(wri, 25, 2, wri.stringlen('99.99'), bdcolor=None)
    countfield = Label(wri, 0, 90, wri.stringlen('1'))
    n = 1
    random = xorshift64star(65535)
    for s in ('short', 'longer', '1', ''):
        textfield.value(s)
        numfield.value('{:5.2f}'.format(random() / 1000))
        countfield.value('{:1d}'.format(n))
        n += 1
        refresh(ssd)
        utime.sleep(2)
    textfield.value('Done', True)
    refresh(ssd)
Exemple #12
0
async def fields(evt):
    wri = Writer(ssd, fixed, verbose=False)
    wri.set_clip(False, False, False)
    textfield = Label(wri, 0, 2, wri.stringlen('longer'))
    numfield = Label(wri, 25, 2, wri.stringlen('99.990'), bdcolor=None)
    countfield = Label(wri, 0, 90, wri.stringlen('1'))
    n = 1
    random = xorshift64star(65535)
    while True:
        for s in ('short', 'longer', '1', ''):
            textfield.value(s)
            numfield.value('{:5.2f}'.format(random() /1000))
            countfield.value('{:1d}'.format(n))
            n += 1
            await evt.wait()
Exemple #13
0
def vari_fields():
    print('vari_fields')
    refresh(ssd, True)  # Clear any prior image
    Label(wri, 0, 0, 'Text:')
    Label(wri, 20, 0, 'Border:')
    width = wri.stringlen('Yellow')
    lbl_text = Label(wri, 0, 40, width)
    lbl_bord = Label(wri, 20, 40, width)
    lbl_text.value('Red')
    lbl_bord.value('Red')
    lbl_var = Label(wri, 40, 2, '25.46', fgcolor=RED, bdcolor=RED)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('Yellow')
    lbl_var.value(bdcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('None')
    lbl_var.value(bdcolor=False)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Yellow')
    lbl_bord.value('None')
    lbl_var.value(fgcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Blue')
    lbl_bord.value('Green')
    lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN)
    refresh(ssd)
Exemple #14
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)
        self.reg_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 = int.from_bytes(os.urandom(1), 1) / 255
            steps = 20
            delta = (val - oldvalue) / steps
            for _ in range(steps):
                oldvalue += delta
                self.meter.value(oldvalue)
                await asyncio.sleep_ms(100)
class BaseScreen(Screen):
    def __init__(self):
        super().__init__()

        # Scale with custom variable and legends.
        def legendcb(f):
            return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88))

        self.scale = Scale((0, 0),
                           font6,
                           width=159,
                           legendcb=legendcb,
                           fgcolor=GREEN,
                           pointercolor=RED,
                           fontcolor=YELLOW)
        self.reg_task(self.radio())

        # Scale with varying color.
        def tickcb(f, c):
            if f > 0.8:
                return RED
            if f < -0.8:
                return BLUE
            return c

        self.lbl_result = Label((0, 105),
                                font=font10,
                                fontcolor=WHITE,
                                width=70,
                                border=2,
                                fgcolor=RED,
                                bgcolor=DARKGREEN)
        self.scale1 = Scale((0, 70),
                            font6,
                            width=159,
                            tickcb=tickcb,
                            fgcolor=GREEN,
                            pointercolor=RED,
                            fontcolor=YELLOW)
        self.reg_task(self.default())
        quitbutton()


# COROUTINES

    async def radio(self):
        cv = 88.0  # Current value
        val = 108.0  # Target value
        while True:
            v1, v2 = val, cv
            steps = 200
            delta = (val - cv) / steps
            for _ in range(steps):
                cv += delta
                # Map user variable to -1.0..+1.0
                self.scale.value(2 * (cv - 88) / (108 - 88) - 1)
                await asyncio.sleep_ms(200)
            val, cv = v2, v1

    async def default(self):
        cv = -1.0  # Current
        val = 1.0
        while True:
            v1, v2 = val, cv
            steps = 400
            delta = (val - cv) / steps
            for _ in range(steps):
                cv += delta
                self.scale1.value(cv)
                self.lbl_result.value('{:4.3f}'.format(cv))
                await asyncio.sleep_ms(250)
            val, cv = v2, v1
Exemple #16
0
class AssortedScreen(Screen):
    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, ))

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

    def cbreset(self, button):
        self.bs.value(self.bs0)
        self.lbl_result.value('Short')

    def cb_en_dis(self, button, disable):
        for item in self.buttons:
            item.greyed_out(disable)
def vari_fields():
    print('Variable label styles.')
    refresh(ssd, True)  # Clear any prior image
    wri_large = CWriter(ssd, freesans20, GREEN, BLACK, verbose=False)
    wri_large.set_clip(True, True, False)
    Label(wri_large, 0, 0, 'Text')
    Label(wri_large, 20, 0, 'Border')
    width = wri_large.stringlen('Yellow')
    lbl_text = Label(wri_large, 0, 65, width)
    lbl_bord = Label(wri_large, 20, 65, width)
    lbl_text.value('Red')
    lbl_bord.value('Red')
    lbl_var = Label(wri_large, 50, 2, '25.46', fgcolor=RED, bdcolor=RED)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('Yellow')
    lbl_var.value(bdcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('None')
    lbl_var.value(bdcolor=False)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Yellow')
    lbl_bord.value('None')
    lbl_var.value(fgcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Blue')
    lbl_bord.value('Green')
    lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN)
    Label(wri, ssd.height - wri.height - 2, 0, 'Done', fgcolor=RED)
    refresh(ssd)
Exemple #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())