Ejemplo n.º 1
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font14, value='Dialog box demonstration.')
     Label((0, 100),
           font=font10,
           value='User written and gdialog generated')
     self.lbl_result = Label((10, 50),
                             font=font10,
                             fontcolor=WHITE,
                             width=70,
                             border=2,
                             fgcolor=RED,
                             bgcolor=DARKGREEN)
     # User written dialog
     fwdbutton(195, 242, UserDialogBox, text='User')
     # Dialog built using gdialog.py DialogBox
     dialog_elements = (('Yes', GREEN), ('No', RED), ('Foo', YELLOW))
     fwdbutton(0,
               242,
               DialogBox,
               text='Gen',
               args=(font14, ),
               kwargs={
                   'elements': dialog_elements,
                   'label': 'Test dialog'
               })
     quitbutton(390, 242)
Ejemplo n.º 2
0
    def __init__(self):
        super().__init__()
        fwdbutton(0, 242, BackScreen, 'Fast')
        fwdbutton(120, 242, TabScreen, 'Tabs')
        quitbutton()
        tb1 = Textbox((0, 0), 200, 8, font=IFONT16, **tbargs)
        tb2 = Textbox((210, 0), 200, 8, font=IFONT16, clip=False, **tbargs)
        Label((0, 135), width=200, value='Clipping', **labels)
        Label((210, 135), width=200, value='Wrapping', **labels)

        btns = (Button((0, 180),
                       text='Up',
                       callback=btn_cb,
                       args=(tb1, tb2, 1),
                       **btntable),
                Button((120, 180),
                       text='Down',
                       callback=btn_cb,
                       args=(tb1, tb2, -1),
                       **btntable))
        for btn in btns:
            btn.greyed_out(True)  # Disallow until textboxes are populated

        self.reg_task(txt_test(tb1, None))
        self.reg_task(txt_test(tb2, btns))
Ejemplo n.º 3
0
    def __init__(self):
        super().__init__()
        # Scale with custom variable and legends.
        Label((0, 0), font=font14, value='FM radio scale 88-108MHz.')

        def legendcb(f):
            return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88))

        self.scale = Scale((0, 30),
                           font10,
                           legendcb=legendcb,
                           width=350,
                           height=60,
                           bgcolor=BLACK,
                           fgcolor=GREEN,
                           pointercolor=RED,
                           fontcolor=YELLOW)
        self.reg_task(self.radio())
        # Scale with varying color.
        Label((0, 130),
              font=font14,
              value='Default scale -1 to +1, varying colors.')

        def tickcb(f, c):
            if f > 0.8:
                return RED
            if f < -0.8:
                return BLUE
            return c

        self.lbl_result = Label((0, 240),
                                font=font14,
                                fontcolor=WHITE,
                                width=70,
                                border=2,
                                fgcolor=RED,
                                bgcolor=DARKGREEN)
        self.scale1 = Scale((0, 160),
                            font10,
                            tickcb=tickcb,
                            width=350,
                            height=60,
                            bgcolor=BLACK,
                            fgcolor=GREEN,
                            pointercolor=RED,
                            fontcolor=YELLOW)
        self.reg_task(self.default())
        quitbutton(390, 242)
Ejemplo n.º 4
0
 def __init__(self):
     super().__init__()
     labels = { 'width' : 60,
             'fontcolor' : WHITE,
             'border' : 2,
             'fgcolor' : RED,
             'bgcolor' : DARKGREEN,
             'font' : font10,
             }
     quitbutton()
     meter1 = Meter((320, 0), barcolor=YELLOW, fgcolor=CYAN, bgcolor=BLACK)
     meter2 = Meter((360, 0), font=font10, legends=('0','5','10'), barcolor=GREEN,
                        fgcolor=CYAN, bgcolor=BLACK, cb_move=self.meter_change)
     x = 230
     lstlbl = []
     for n in range(3):
         lstlbl.append(Label((x, 40 + 60 * n), **labels))
     led = LED((420, 0), border = 2)
     slave1 = HorizSlider((10, 100), fgcolor = GREEN,
                              cb_move = self.slave_moved, cbm_args = (lstlbl[1],), border = 2)
     slave2 = HorizSlider((10, 160), fgcolor = GREEN,
                              cb_move = self.slave_moved, cbm_args = (lstlbl[2],), border = 2)
     master = HorizSlider((10, 40), font = font10, fgcolor = YELLOW, fontcolor = WHITE,
                               legends = ('0', '5', '10'), cb_end = self.callback,
                               cbe_args = ('Master',), cb_move = self.master_moved, cbm_args = (lstlbl[0], slave1, slave2, led),
                               value=0.5, border = 2)
 # On/Off toggle: enable/disable quit button and one slider
     bs = ButtonList(self.cb_en_dis)
     lst_en_dis = [slave1, slave2, master]
     bs.add_button((280, 240), font = font14, fontcolor = BLACK, fgcolor = GREEN,
                   text = 'Disable', height=30, width=90, args = [True, lst_en_dis])
     bs.add_button((280, 240), font = font14, fontcolor = BLACK, fgcolor = RED,
                   text = 'Enable', height=30, width=90, args = [False, lst_en_dis])
     self.reg_task(self.test_meter(meter1))
     self.reg_task(self.test_meter(meter2))
Ejemplo n.º 5
0
 def __init__(self, font, *, elements, location=(20, 20), label=None,
              bgcolor=DARKGREEN, buttonwidth=25, closebutton=True):
     height = 150
     spacing = 20
     buttonwidth = max(max([TFT.get_stringsize(x[0], font)[0] for x in elements]) + 4, buttonwidth)
     buttonheight = max(TFT.get_stringsize('x', font)[1], 25)
     nelements = len(elements)
     width = spacing + (buttonwidth + spacing) * nelements
     if label is not None:
         width = max(width, TFT.get_stringsize(label, font)[0] + 2 * spacing)
     super().__init__(location, height, width, bgcolor = bgcolor)
     x = self.location[0] + spacing # Coordinates relative to physical display
     gap = 0
     if nelements > 1:
         gap = ((width - 2 * spacing) - nelements * buttonwidth) // (nelements - 1)
     y = self.location[1] + self.height - buttonheight - 10
     if label is not None:
         Label((x, self.location[1] + 50), font = font, bgcolor = bgcolor, value = label)
     for text, color in elements:
         Button((x, y), height = buttonheight, width = buttonwidth, font = font, fontcolor = BLACK, fgcolor = color,
             text = text, shape = RECTANGLE,
             callback = self.back, args = (text,))
         x += buttonwidth + gap
     if closebutton:
         x, y = TFT.get_stringsize('X', font)
         size = max(x, y, 25)
         Button((self.location[0] + width - (size + 1), self.location[1] + 1), height = size, width = size, font = font,
             fgcolor = RED,  text = 'X', shape = RECTANGLE,
             callback = self.back, args = ('Close',))
Ejemplo n.º 6
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font14, value='Multiple screen demonstration.')
     fwdbutton(0, 242, KnobScreen, 'Knobs')
     fwdbutton(100, 242, SliderScreen, 'Sliders')
     fwdbutton(200, 242, AssortedScreen, 'Various')
     fwdbutton(0, 100, TaskScreen, 'Tasks')
     quitbutton(390, 242)
Ejemplo n.º 7
0
 def __init__(self):
     super().__init__()
     Label((0, 0),
           font=font14,
           value='Demo of linear and log scale controls.')
     fwdbutton(10, 50, linearScreen, 'Linear')
     fwdbutton(10, 100, LogScreen, 'Log')
     quitbutton(200, 242)
Ejemplo n.º 8
0
def volume(x, y):  # Volume slider
    table = {
        'fontcolor': WHITE,
        'font': font10,
        'fgcolor': YELLOW,
        'legends': ('0', '5', '11'),
        'value': 0.7,
    }
    Label((x + 50, y + 100), font=font14, value='Volume')
    return Slider((x, y + 10), **table)
Ejemplo n.º 9
0
def balance(x, y):  # Balance slider
    table = {
        'fontcolor': WHITE,
        'legends': ('L', 'C', 'R'),
        'font': font10,
        'fgcolor': CYAN,
        'value': 0.5,
    }
    Label((x, y + 50), font=font14, value='Balance')
    return HorizSlider((x, y), **table)
Ejemplo n.º 10
0
    def __init__(self):
        super().__init__()
        backbutton(390, 242)
        fwdbutton(0, 242, BackScreen)
        labels = {
            'width': 70,
            'fontcolor': WHITE,
            'border': 2,
            'fgcolor': RED,
            'bgcolor': (0, 40, 0),
        }

        lstlbl = []
        for n in range(2):
            lstlbl.append(Label((120, 120 + 40 * n), font=font10, **labels))
        lbl_1 = Label((120, 120), font=font10, **labels)
        lbl_2 = Label((120, 160), font=font10, **labels)
        meter1 = Meter((320, 0),
                       font=font10,
                       legends=('0', '5', '10'),
                       barcolor=YELLOW,
                       fgcolor=GREEN,
                       bgcolor=BLACK)
        dial1 = Dial((120, 0), fgcolor=YELLOW, border=2, pointers=(0.9, 0.7))
        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=[dial1, 0, lbl_1, meter1])
        Knob((0, 120),
             fgcolor=WHITE,
             border=2,
             cb_move=self.knob_moved,
             cbm_args=[dial1, 1, lbl_2],
             cb_end=self.callback,
             cbe_args=['Knob2'],
             arc=pi * 1.5)
Ejemplo n.º 11
0
    def __init__(self):
        super().__init__()
        self.tasks = []  # Control cancellation explicitly
        Label((0, 0), font=font14, value='Green dial runs only')
        Label((0, 30), font=font14, value='when screen is visible')
        Label((0, 120), font=font14, value="Yellow dial's value is")
        Label((0, 150), font=font14, value='computed continuously.')
        self.dial1 = Dial((350, 10),
                          fgcolor=GREEN,
                          border=2,
                          pointers=(0.9, 0.7))
        self.dial2 = Dial((350, 120),
                          fgcolor=YELLOW,
                          border=2,
                          pointers=(0.9, 0.7))
        self.pause = False  # asyncio can't pause coros so handle at application level
        self.tasks.append(asyncio.create_task(self.maintask(self.dial1, True)))
        self.tasks.append(asyncio.create_task(self.maintask(self.dial2)))

        fwdbutton(0, 242, BackScreen)
        self.backbutton(390, 242)  # Special backbutton
Ejemplo n.º 12
0
    def show(self):
        tft = self.tft
        width = self.width
        font = self.font
        fh = self.font.height()
        fhdelta = fh / 2
        tl = self.ticklen
        x0 = self.x0
        x1 = self.x1
        y0 = self.y0
        y1 = self.y1
        height = y1 - y0
        if self.redraw:  # An overlaying screen has closed. Force redraw.
            self.redraw = False
            self.drawn = False
            self.ptr_y = None  # Invalidate previous bar so it's redrawn.
        if not self.drawn:
            self.drawn = True
            if self.divisions > 0:
                xs = x0 + 1
                xe = x1 - 1
                dy = height / (self.divisions)  # Tick marks
                for tick in range(self.divisions + 1):
                    ypos = int(y0 + dy * tick)
                    tft.draw_line(xs, ypos, xe, ypos, self.fgcolor)

            if self.legends is not None and font is not None:  # Legends
                if len(self.legends) <= 1:
                    dy = 0
                else:
                    dy = height / (len(self.legends) - 1)
                yl = self.y1  # Start at bottom
                for legend in self.legends:
                    # constrain y to vertical extent of widget
                    loc = (x1 + 4, min(y1 - fh, max(y0, int(yl - fhdelta))))
                    Label(loc,
                          font=font,
                          fontcolor=self.fontcolor,
                          value=legend)
                    yl -= dy

        ptr_y = round(y1 - self._value *
                      (height - 1))  # y position of top of bar
        if self.ptr_y is None:
            tft.fill_rectangle(x0 + tl, y0 + 1, x1 - tl, y1 - 1, self.bgcolor)
            self.ptr_y = y1
        if ptr_y < self.ptr_y:  # Bar has moved up
            tft.fill_rectangle(x0 + tl, ptr_y, x1 - tl, self.ptr_y,
                               self.barcolor)
        elif ptr_y > self.ptr_y:  # Moved down, blank the area
            tft.fill_rectangle(x0 + tl, ptr_y, x1 - tl, self.ptr_y,
                               self.bgcolor)
        self.ptr_y = ptr_y
Ejemplo n.º 13
0
def source(x, y, cb=lambda *_: None):  # Source radiobuttons
    rb = RadioButtons(BLUE, cb)
    for t in (('1', 'Radio'), ('2', 'CD'), ('3', 'Vinyl'), ('4', 'TV')):
        button = rb.add_button((x, y),
                               font=font14,
                               fontcolor=WHITE,
                               shape=CIRCLE,
                               fgcolor=(0, 0, 90),
                               height=40,
                               width=40,
                               text=t[0])
        Label((x + 50, y + 10), font=font14, value=t[1])
        y += 55
Ejemplo n.º 14
0
def geq(x, y):  # Graphic equaliser
    fr = ('25Hz', '50Hz', '100Hz', '200Hz', '400Hz', '800Hz', '1.5KHz', '3KHz',
          '6KHz', '12KHz')
    table = {
        'fontcolor': WHITE,
        'legends': ('-20', '0', '20'),
        'font': font10,
        'fgcolor': GREEN,
        'value': 0.5,
    }
    sliders = []
    for freq in fr:
        sliders.append(Slider((x, y), **table))
        Label((x, y + 210), font=font10, value=freq)
        x += 80
    return sliders
Ejemplo n.º 15
0
 def __init__(self):
     super().__init__()
     # Common args for the labels
     labels = {
         'width': 75,
         'fontcolor': WHITE,
         'border': 2,
         'fgcolor': RED,
         'bgcolor': (0, 40, 0),
     }
     # Common arguments for all three sliders
     table = {
         'fontcolor': WHITE,
         'legends': ('0', '5', '10'),
     }
     backbutton(390, 242)
     fwdbutton(0, 242, BackScreen)
     self.lstlbl = []
     for n in range(3):
         self.lstlbl.append(Label((80 * n, 215), font=font10, **labels))
     y = 5
     self.slave1 = Slider((80, y),
                          font=font10,
                          fgcolor=GREEN,
                          cb_end=self.callback,
                          cbe_args=('Slave1', ),
                          cb_move=self.slave_moved,
                          cbm_args=(1, ),
                          **table)
     self.slave2 = Slider((160, y),
                          font=font10,
                          fgcolor=GREEN,
                          cb_end=self.callback,
                          cbe_args=('Slave2', ),
                          cb_move=self.slave_moved,
                          cbm_args=(2, ),
                          **table)
     master = Slider((0, y),
                     font=font10,
                     fgcolor=YELLOW,
                     cb_end=self.callback,
                     cbe_args=('Master', ),
                     cb_move=self.master_moved,
                     cbm_args=(0, ),
                     value=0.5,
                     border=2,
                     **table)
Ejemplo n.º 16
0
    def show(self):
        tft = self.tft
        # Blank slot, ticks and slider
        tft.fill_rectangle(
            self.x0, self.y0, self.x1, self.y1,
            self.bgcolor)  # Blank and redraw slot, ticks and slider
        self.redraw = False
        x = self.slot_x0
        y = self.y0
        if self.divisions > 0:
            dx = self.slot_len / (self.divisions)  # Tick marks
            ys = y + 1
            ye = y + self.dy - 1
            for tick in range(self.divisions + 1):
                xpos = int(x + dx * tick)
                tft.draw_line(xpos, ys, xpos, ye, self.fgcolor)
        # Blank and redraw slot
        tft.fill_rectangle(self.slot_x0, self.slot_y0, self.slot_x1,
                           self.slot_y1, self.bgcolor)
        tft.draw_rectangle(self.slot_x0, self.slot_y0, self.slot_x1,
                           self.slot_y1, self.fgcolor)

        # Legends: if redrawing, they are already on the Screen's display list
        if self.legends is not None and not self.drawn:
            if len(self.legends) <= 1:
                dx = 0
            else:
                dx = self.slot_len / (len(self.legends) - 1)
            xl = x
            font = self.font
            bw = self.border
            for legend in self.legends:
                offset = tft.get_stringsize(legend, font)[0] / 2
                loc = int(xl - offset), y - font.height() - bw - 1
                Label(loc, font=font, fontcolor=self.fontcolor, value=legend)
                xl += dx
        if self._value is None:
            self.value(self._initial_value, show=False)  # prevent recursion

        self.slide_x = self.slide_x0 + self._value * self.slot_len
        color = self.slidecolor if self.slidecolor is not None else self.fgcolor
        tft.fill_rectangle(self.slide_x, self.slide_y0,
                           self.slide_x + self.slidewidth, self.slide_y1,
                           color)
        self.drawn = True
Ejemplo n.º 17
0
    def show(self):
        tft = self.tft
        # Blank slot, ticks and slider
        tft.fill_rectangle(self.x0, self.y0, self.x1, self.y1, self.bgcolor)
        self.redraw = False
        x = self.x0
        y = self.slot_y0
        slot_len = self.slot_len  # Height of slot
        if self.divisions > 0:
            dy = slot_len / (self.divisions)  # Tick marks
            xs = x + 1
            xe = x + self.dx - 1
            for tick in range(self.divisions + 1):
                ypos = int(y + dy * tick)
                tft.draw_line(xs, ypos, xe, ypos, self.fgcolor)
        # Blank and redraw slot
        tft.fill_rectangle(self.slot_x0, self.slot_y0, self.slot_x1,
                           self.slot_y1, self.bgcolor)
        tft.draw_rectangle(self.slot_x0, self.slot_y0, self.slot_x1,
                           self.slot_y1, self.fgcolor)

        # Legends: if redrawing, they are already on the Screen's display list
        if self.legends is not None and not self.drawn:
            if len(self.legends) <= 1:
                dy = 0
            else:
                dy = slot_len / (len(self.legends) - 1)
            yl = y + slot_len  # Start at bottom
            fhdelta = self.font.height() / 2
            font = self.font
            for legend in self.legends:
                loc = (x + self.width, int(yl - fhdelta))
                Label(loc, font=font, fontcolor=self.fontcolor, value=legend)
                yl -= dy
        if self._value is None:
            self.value(self._initial_value, show=False)  # Prevent recursion
        self.slide_y = self.slide_y0 - self._value * self.slot_len
        color = self.slidecolor if self.slidecolor is not None else self.fgcolor
        tft.fill_rectangle(self.slide_x0, self.slide_y, self.slide_x1,
                           self.slide_y + self.slideheight, color)
        self.drawn = True
Ejemplo n.º 18
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font10, value='Plot module demonstrator.')
     y = 30
     dy = 42
     fwdbutton(0, y, Tseq, 'TSeq')
     Label((75, y + 5), font=font10, value='Time sequence demo.')
     y += dy
     fwdbutton(0, y, PolarScreen, 'Polar')
     Label((75, y + 5), font=font10, value='A polar plot.')
     y += dy
     fwdbutton(0, y, XYScreen, 'XY')
     Label((75, y + 5), font=font10, value='Cartesian plot.')
     y += dy
     fwdbutton(0, y, RealtimeScreen, 'RT')
     Label((75, y + 5), font=font10, value='Realtime demo.')
     y += dy
     fwdbutton(0, y, PolarORScreen, 'Over')
     Label((75, y + 5), font=font10, value='Two demos of clipping.')
     y += dy
     fwdbutton(0, y, DiscontScreen, 'Lines')
     quitbutton()
Ejemplo n.º 19
0
class BaseScreen(Screen):
    def __init__(self):
        super().__init__()
        # Scale with custom variable and legends.
        Label((0, 0), font=font14, value='FM radio scale 88-108MHz.')

        def legendcb(f):
            return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88))

        self.scale = Scale((0, 30),
                           font10,
                           legendcb=legendcb,
                           width=350,
                           height=60,
                           bgcolor=BLACK,
                           fgcolor=GREEN,
                           pointercolor=RED,
                           fontcolor=YELLOW)
        self.reg_task(self.radio())
        # Scale with varying color.
        Label((0, 130),
              font=font14,
              value='Default scale -1 to +1, varying colors.')

        def tickcb(f, c):
            if f > 0.8:
                return RED
            if f < -0.8:
                return BLUE
            return c

        self.lbl_result = Label((0, 240),
                                font=font14,
                                fontcolor=WHITE,
                                width=70,
                                border=2,
                                fgcolor=RED,
                                bgcolor=DARKGREEN)
        self.scale1 = Scale((0, 160),
                            font10,
                            tickcb=tickcb,
                            width=350,
                            height=60,
                            bgcolor=BLACK,
                            fgcolor=GREEN,
                            pointercolor=RED,
                            fontcolor=YELLOW)
        self.reg_task(self.default())
        quitbutton(390, 242)


# 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
Ejemplo n.º 20
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font14, value='Ensure back refreshes properly')
     backbutton(390, 242)
     self.open_arg = 'Opening'
     self.hide_arg = 'Hiding'
Ejemplo n.º 21
0
    def __init__(self):
        super().__init__()
        labels = {
            'width': 70,
            'fontcolor': WHITE,
            'border': 2,
            'fgcolor': RED,
            'bgcolor': (0, 40, 0),
            'font': font14,
        }
        radiobuttons = [
            {
                'text': '1',
                'args': ['1']
            },
            {
                'text': '2',
                'args': ['2']
            },
            {
                'text': '3',
                'args': ['3']
            },
            {
                'text': '4',
                'args': ['4']
            },
        ]
        buttonlist = [
            {
                'fgcolor': GREEN,
                'shape': CLIPPED_RECT,
                'text': 'Start',
                'args': ['Live']
            },
            {
                'fgcolor': RED,
                'shape': CLIPPED_RECT,
                'text': 'Stop',
                'args': ['Die']
            },
        ]

        backbutton(390, 242)
        fwdbutton(0, 242, BackScreen)
        lstlbl = []
        for n in range(4):
            lstlbl.append(Label((350, 40 * n), **labels))
        self.led = LED((440, 0), border=2)
        Checkbox((300, 0), callback=self.cbcb, args=[lstlbl[0], False])
        Checkbox((300, 40),
                 fillcolor=RED,
                 callback=self.cbcb,
                 args=[lstlbl[1], True])

        # On/Off toggle
        x = 1
        bs = ButtonList(self.callback)
        bs0 = None
        for t in buttonlist:  # Buttons overlay each other at same location
            t['args'].append(lstlbl[2])
            button = bs.add_button((x, 120),
                                   font=font14,
                                   height=30,
                                   fontcolor=BLACK,
                                   **t)
            if bs0 is None:
                bs0 = button


# Radio buttons
        x = 1
        rb = RadioButtons(BLUE, self.callback)  # color of selected button
        for t in radiobuttons:
            t['args'].append(lstlbl[3])
            button = rb.add_button((x, 180),
                                   font=font14,
                                   fontcolor=WHITE,
                                   fgcolor=(0, 0, 90),
                                   height=40,
                                   width=40,
                                   **t)
            x += 60
Ejemplo n.º 22
0
 def __init__(self):
     super().__init__()
     Label((0, 0), font=font10, value='Refresh test')
     backbutton()
Ejemplo n.º 23
0
    def __init__(self):
        super().__init__()

        # Scale 0
        Label((0, 0), font=font14, value='Default scale 5 decades.')
        lbl_result0 = Label((0, 240), **labels)

        # Define callbacks for scale 0
        def legendcb(f):
            if f < 999:
                return '{:<1.0f}'.format(f)
            return '{:<1.0f}K'.format(f / 1000)

        def scale_move0(scale):
            sv = scale.value()
            lbl_result0.value('{:6.2f}'.format(sv))
            self.scale1.value(
                scale.value())  # Cause lower scale to mimic this one

        self.scale0 = ScaleLog((0, 30),
                               legendcb=legendcb,
                               value=15,
                               cb_move=scale_move0,
                               **scales)
        # Scale 1 with varying color.
        Label((0, 130),
              font=font14,
              value='Varying colors, follows top scale.')
        lbl_result1 = Label((200, 240), **labels)

        # Define callbacks for scale 1
        def tickcb(f, c):
            if f > 30000:
                return RED
            if f < 10:
                return BLUE
            return c

        def scale_move1(scale):
            sv = scale.value()
            lbl_result1.value('{:6.2f}'.format(sv))

        self.scale1 = ScaleLog((0, 160),
                               tickcb=tickcb,
                               cb_move=scale_move1,
                               **scales)
        # Define buttons
        x = 390
        y = 242
        backbutton(x, y)
        y -= 50
        Button((x, y),
               fgcolor=GREEN,
               text='Enable',
               callback=self.en,
               **buttons)
        y -= 50
        Button((x, y),
               fgcolor=YELLOW,
               text='Disable',
               callback=self.dis,
               **buttons)
        y -= 50
        Button((x, y),
               fgcolor=BLUE,
               text='Reset',
               callback=lambda _: self.scale1.value(1),
               **buttons)
Ejemplo n.º 24
0
    def __init__(self):
        super().__init__()

        # Scale 0 with custom variable and legends.
        Label((0, 0), font=font14, value='FM radio scale 88-108MHz.')
        lbl_result0 = Label((0, 240), **labels)

        # Define callbacks for scale 0
        def legendcb(f):
            return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88))

        def scale_move0(scale):
            sv = scale.value()
            sv = (sv + 1) / 2  # 0 <= sv <= 1
            lbl_result0.value('{:6.2f}'.format(sv * (108 - 88) + 88))

        self.scale0 = ScaleCtrl((0, 30),
                                legendcb=legendcb,
                                cb_move=scale_move0,
                                **scales)
        # Scale 1 with varying color.
        Label((0, 130),
              font=font14,
              value='Default scale -1 to +1, varying colors.')
        lbl_result1 = Label((200, 240), **labels)

        # Define callbacks for scale 1
        def tickcb(f, c):
            if f > 0.8:
                return RED
            if f < -0.8:
                return BLUE
            return c

        def scale_move1(scale):
            sv = scale.value()
            lbl_result1.value('{:4.3f}'.format(sv))

        self.scale1 = ScaleCtrl((0, 160),
                                tickcb=tickcb,
                                cb_move=scale_move1,
                                **scales)
        # Define buttons
        x = 390
        y = 242
        backbutton(x, y)
        #Button((x, y), fgcolor = RED, text = 'Quit',
        #callback = lambda _: Screen.shutdown(), **buttons)
        y -= 50
        Button((x, y),
               fgcolor=GREEN,
               text='Enable',
               callback=self.en,
               **buttons)
        y -= 50
        Button((x, y),
               fgcolor=YELLOW,
               text='Disable',
               callback=self.dis,
               **buttons)
        y -= 50
        Button((x, y),
               fgcolor=BLUE,
               text='Zero',
               callback=lambda _: self.scale1.value(0),
               **buttons)
Ejemplo n.º 25
0
    def __init__(self):
        super().__init__()
        Button((390, 240),
               font=IFONT16,
               callback=self.quit,
               fgcolor=RED,
               text='Quit',
               shape=RECTANGLE,
               width=80,
               height=30)
        dial = VectorDial((120, 0), fgcolor=YELLOW, border=2)
        hrs = Pointer(dial)
        mins = Pointer(dial)
        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=(mins, 0.9))
        k1 = Knob((0, 120),
                  fgcolor=WHITE,
                  border=2,
                  arc=pi * 1.5,
                  cb_end=self.callback,
                  cbe_args=['Knob2'],
                  cb_move=self.knob_moved,
                  cbm_args=(hrs, 0.7))
        Label((0, 225), font=font10, value='Arc = 270 degs.')
        # Dropdown
        self.lbl_dd = Label((120, 120),
                            font=IFONT16,
                            width=100,
                            border=2,
                            bgcolor=(0, 40, 0),
                            fgcolor=RED)
        self.dropdown = Dropdown(
            (280, 0),
            font=IFONT16,
            width=100,
            callback=self.cbdb,
            elements=('Dog', 'Cat', 'Rat', 'Goat', 'Snake', 'Pig'))

        btnrst = Button((280, 70),
                        font=IFONT16,
                        callback=self.set_dropdown,
                        fgcolor=BLUE,
                        text='Reset',
                        shape=RECTANGLE,
                        width=80,
                        height=30)  # Test of set by value
        btnsnake = Button((280, 120),
                          font=IFONT16,
                          callback=self.set_bytext,
                          args=('Snake', ),
                          fgcolor=CYAN,
                          fontcolor=BLACK,
                          text='Snake',
                          shape=RECTANGLE,
                          width=80,
                          height=30)  # test set by text
        # Listbox
        self.lbl_lb = Label((120, 150),
                            font=IFONT16,
                            width=100,
                            border=2,
                            bgcolor=(0, 40, 0),
                            fgcolor=RED)
        listbox = Listbox(
            (370, 70),
            font=IFONT16,
            width=105,
            bgcolor=GREY,
            fgcolor=YELLOW,
            select_color=BLUE,
            elements=('aardvark', 'zebra', 'armadillo', 'warthog'),
            callback=self.cblb)
        # On/Off toggle grey style
        self.lbl_style = Label((170, 210),
                               font=font10,
                               value='Current style: grey')
        bstyle = ButtonList(self.cb_style)
        bstyle.add_button((170, 240),
                          font=IFONT16,
                          fontcolor=WHITE,
                          height=30,
                          width=90,
                          fgcolor=RED,
                          shape=RECTANGLE,
                          text='Dim',
                          args=(False, ))
        bstyle.add_button((170, 240),
                          font=IFONT16,
                          fontcolor=WHITE,
                          height=30,
                          width=90,
                          fgcolor=GREEN,
                          shape=RECTANGLE,
                          text='Grey',
                          args=(True, ))
        # On/Off toggle enable/disable
        bs = ButtonList(self.cb_en_dis)
        self.lst_en_dis = (bstyle, k0, k1, self.dropdown, listbox, btnrst,
                           btnsnake)
        bs.add_button((280, 240),
                      font=IFONT16,
                      fontcolor=BLACK,
                      height=30,
                      width=90,
                      fgcolor=GREEN,
                      shape=RECTANGLE,
                      text='Disable',
                      args=(True, ))
        bs.add_button((280, 240),
                      font=IFONT16,
                      fontcolor=BLACK,
                      height=30,
                      width=90,
                      fgcolor=RED,
                      shape=RECTANGLE,
                      text='Enable',
                      args=(False, ))
Ejemplo n.º 26
0
 def __init__(self):
     super().__init__()
     # Common args for the labels
     labels = {
         'width': 60,
         'fontcolor': WHITE,
         'border': 2,
         'fgcolor': RED,
         'bgcolor': (0, 40, 0),
     }
     # Common args for all three sliders
     table = {
         'fontcolor': WHITE,
         'legends': ('0', '5', '10'),
         'cb_end': self.callback,
     }
     btnquit = Button((390, 240),
                      font=font14,
                      callback=quit,
                      fgcolor=RED,
                      text='Quit',
                      shape=RECTANGLE,
                      width=80,
                      height=30)
     self.dial1 = Dial((350, 10),
                       fgcolor=YELLOW,
                       border=2,
                       pointers=(0.9, 0.7))
     self.dial2 = Dial((350, 120),
                       fgcolor=YELLOW,
                       border=2,
                       pointers=(0.9, 0.7))
     self.lstlbl = []
     for n in range(3):
         self.lstlbl.append(Label((80 * n, 240), font=font10, **labels))
     y = 5
     self.slave1 = Slider((80, y),
                          font=font10,
                          fgcolor=GREEN,
                          cbe_args=('Slave1', ),
                          cb_move=self.slave_moved,
                          cbm_args=(1, ),
                          **table)
     self.slave2 = Slider((160, y),
                          font=font10,
                          fgcolor=GREEN,
                          cbe_args=('Slave2', ),
                          cb_move=self.slave_moved,
                          cbm_args=(2, ),
                          **table)
     master = Slider((0, y),
                     font=font10,
                     fgcolor=YELLOW,
                     cbe_args=('Master', ),
                     cb_move=self.master_moved,
                     value=0.5,
                     border=2,
                     **table)
     self.reg_task(self.task1())
     self.reg_task(self.task2())
     # On/Off toggle: enable/disable quit button and one slider
     bs = ButtonList(self.cb_en_dis)
     lst_en_dis = [self.slave1, btnquit]
     button = bs.add_button((280, 240),
                            font=font14,
                            fontcolor=BLACK,
                            height=30,
                            width=90,
                            fgcolor=GREEN,
                            shape=RECTANGLE,
                            text='Disable',
                            args=[True, lst_en_dis])
     button = bs.add_button((280, 240),
                            font=font14,
                            fontcolor=BLACK,
                            height=30,
                            width=90,
                            fgcolor=RED,
                            shape=RECTANGLE,
                            text='Enable',
                            args=[False, lst_en_dis])
Ejemplo n.º 27
0
    def __init__(self):
        super().__init__()
        # These tables contain args that differ between members of a set of related buttons
        table = [
            {
                'fgcolor': GREEN,
                'text': 'Yes',
                'args': ('Oui', 2),
                'fontcolor': (0, 0, 0)
            },
            {
                'fgcolor': RED,
                'text': 'No',
                'args': ('Non', 2)
            },
            {
                'fgcolor': BLUE,
                'text': '???',
                'args': ('Que?', 2)
            },  # 'fill': False to see effect
            {
                'fgcolor': GREY,
                'text': 'Rats',
                'args': ('Rats', 2)
            },
        ]
        # Highlight buttons: only tabulate data that varies
        table_highlight = [
            {
                'text': 'P',
                'args': ('p', 2)
            },
            {
                'text': 'Q',
                'args': ('q', 2)
            },
            {
                'text': 'R',
                'args': ('r', 2)
            },
            {
                'text': 'S',
                'args': ('s', 2)
            },
        ]
        # A Buttonset with two entries
        table_buttonset = [
            {
                'fgcolor': GREEN,
                'shape': CLIPPED_RECT,
                'text': 'Start',
                'args': ('Live', 2)
            },
            {
                'fgcolor': RED,
                'shape': CLIPPED_RECT,
                'text': 'Stop',
                'args': ('Die', 2)
            },
        ]

        table_radiobuttons = [
            {
                'text': '1',
                'args': ('1', 3)
            },
            {
                'text': '2',
                'args': ('2', 3)
            },
            {
                'text': '3',
                'args': ('3', 3)
            },
            {
                'text': '4',
                'args': ('4', 3)
            },
        ]

        labels = {
            'width': 70,
            'fontcolor': WHITE,
            'border': 2,
            'fgcolor': RED,
            'bgcolor': (0, 40, 0),
            'font': font14,
        }

        # Uncomment this line to see 'skeleton' style greying-out:
        #        Screen.tft.grey_color()

        # Labels
        self.lstlbl = []
        for n in range(5):
            self.lstlbl.append(Label((390, 40 * n), **labels))

        self.lst_en_dis = []  # Controls affected by disable button.
        # Button assortment
        x = 0
        for t in table:
            self.lst_en_dis.append(
                Button((x, 0),
                       font=font14,
                       shape=CIRCLE,
                       callback=self.callback,
                       **t))
            x += 70

# Highlighting buttons
        x = 0
        for t in table_highlight:
            self.lst_en_dis.append(
                Button((x, 60),
                       fgcolor=CYAN,
                       shape=CIRCLE,
                       fontcolor=BLACK,
                       litcolor=WHITE,
                       font=font14,
                       callback=self.callback,
                       **t))
            x += 70


# Pad
        lbl_pad = Label((0, 200),
                        value='touch me',
                        fontcolor=WHITE,
                        border=2,
                        fgcolor=RED,
                        bgcolor=DARKGREEN,
                        font=font14)
        pad = Pad((0, 200),
                  width=lbl_pad.width,
                  height=lbl_pad.height,
                  onrelease=False,
                  callback=lambda _: lbl_pad.value('Short'),
                  lp_callback=lambda _: lbl_pad.value('Long'))
        self.lst_en_dis.append(pad)

        # Start/Stop toggle
        self.bs = ButtonList(self.callback)
        self.bs0 = None
        for t in table_buttonset:  # Buttons overlay each other at same location
            button = self.bs.add_button((0, 240),
                                        font=font14,
                                        fontcolor=BLACK,
                                        height=30,
                                        **t)
            if self.bs0 is None:  # Save for reset button callback
                self.bs0 = button
        self.lst_en_dis.append(self.bs)

        # Radio buttons
        x = 0
        self.rb = RadioButtons(BLUE, self.callback)  # color of selected button
        self.rb0 = None
        for t in table_radiobuttons:
            button = self.rb.add_button((x, 140),
                                        font=font14,
                                        fontcolor=WHITE,
                                        fgcolor=(0, 0, 90),
                                        height=40,
                                        width=40,
                                        **t)
            if self.rb0 is None:  # Save for reset button callback
                self.rb0 = button
            x += 60
        self.lst_en_dis.append(self.rb)
        # Checkbox
        self.cb1 = Checkbox((340, 0), callback=self.cbcb, args=(0, ))
        self.cb2 = Checkbox((340, 40),
                            fillcolor=RED,
                            callback=self.cbcb,
                            args=(1, ))
        self.lst_en_dis.extend([self.cb1, self.cb2])
        # Reset button
        self.lbl_reset = Label((200, 210),
                               font=font10,
                               value='Reset also responds to long press')
        self.btn_reset = Button((300, 240),
                                font=font14,
                                height=30,
                                width=80,
                                fgcolor=BLUE,
                                shape=RECTANGLE,
                                text='Reset',
                                fill=True,
                                callback=self.cbreset,
                                args=(4, ),
                                onrelease=False,
                                lp_callback=self.callback,
                                lp_args=('long', 4))
        # Quit
        self.btn_quit = Button((390, 240),
                               font=font14,
                               height=30,
                               width=80,
                               fgcolor=RED,
                               shape=RECTANGLE,
                               text='Quit',
                               callback=self.quit)
        # Enable/Disable toggle
        self.bs_en = ButtonList(self.cb_en_dis)
        self.bs_en.add_button((200, 240),
                              font=font14,
                              fontcolor=BLACK,
                              height=30,
                              width=90,
                              fgcolor=GREEN,
                              shape=RECTANGLE,
                              text='Disable',
                              args=(True, ))
        self.bs_en.add_button((200, 240),
                              font=font14,
                              fontcolor=BLACK,
                              height=30,
                              width=90,
                              fgcolor=RED,
                              shape=RECTANGLE,
                              text='Enable',
                              args=(False, ))
Ejemplo n.º 28
0
class KnobScreen(Screen):
    def __init__(self):
        super().__init__()
        Button((390, 240),
               font=IFONT16,
               callback=self.quit,
               fgcolor=RED,
               text='Quit',
               shape=RECTANGLE,
               width=80,
               height=30)
        dial = VectorDial((120, 0), fgcolor=YELLOW, border=2)
        hrs = Pointer(dial)
        mins = Pointer(dial)
        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=(mins, 0.9))
        k1 = Knob((0, 120),
                  fgcolor=WHITE,
                  border=2,
                  arc=pi * 1.5,
                  cb_end=self.callback,
                  cbe_args=['Knob2'],
                  cb_move=self.knob_moved,
                  cbm_args=(hrs, 0.7))
        Label((0, 225), font=font10, value='Arc = 270 degs.')
        # Dropdown
        self.lbl_dd = Label((120, 120),
                            font=IFONT16,
                            width=100,
                            border=2,
                            bgcolor=(0, 40, 0),
                            fgcolor=RED)
        self.dropdown = Dropdown(
            (280, 0),
            font=IFONT16,
            width=100,
            callback=self.cbdb,
            elements=('Dog', 'Cat', 'Rat', 'Goat', 'Snake', 'Pig'))

        btnrst = Button((280, 70),
                        font=IFONT16,
                        callback=self.set_dropdown,
                        fgcolor=BLUE,
                        text='Reset',
                        shape=RECTANGLE,
                        width=80,
                        height=30)  # Test of set by value
        btnsnake = Button((280, 120),
                          font=IFONT16,
                          callback=self.set_bytext,
                          args=('Snake', ),
                          fgcolor=CYAN,
                          fontcolor=BLACK,
                          text='Snake',
                          shape=RECTANGLE,
                          width=80,
                          height=30)  # test set by text
        # Listbox
        self.lbl_lb = Label((120, 150),
                            font=IFONT16,
                            width=100,
                            border=2,
                            bgcolor=(0, 40, 0),
                            fgcolor=RED)
        listbox = Listbox(
            (370, 70),
            font=IFONT16,
            width=105,
            bgcolor=GREY,
            fgcolor=YELLOW,
            select_color=BLUE,
            elements=('aardvark', 'zebra', 'armadillo', 'warthog'),
            callback=self.cblb)
        # On/Off toggle grey style
        self.lbl_style = Label((170, 210),
                               font=font10,
                               value='Current style: grey')
        bstyle = ButtonList(self.cb_style)
        bstyle.add_button((170, 240),
                          font=IFONT16,
                          fontcolor=WHITE,
                          height=30,
                          width=90,
                          fgcolor=RED,
                          shape=RECTANGLE,
                          text='Dim',
                          args=(False, ))
        bstyle.add_button((170, 240),
                          font=IFONT16,
                          fontcolor=WHITE,
                          height=30,
                          width=90,
                          fgcolor=GREEN,
                          shape=RECTANGLE,
                          text='Grey',
                          args=(True, ))
        # On/Off toggle enable/disable
        bs = ButtonList(self.cb_en_dis)
        self.lst_en_dis = (bstyle, k0, k1, self.dropdown, listbox, btnrst,
                           btnsnake)
        bs.add_button((280, 240),
                      font=IFONT16,
                      fontcolor=BLACK,
                      height=30,
                      width=90,
                      fgcolor=GREEN,
                      shape=RECTANGLE,
                      text='Disable',
                      args=(True, ))
        bs.add_button((280, 240),
                      font=IFONT16,
                      fontcolor=BLACK,
                      height=30,
                      width=90,
                      fgcolor=RED,
                      shape=RECTANGLE,
                      text='Enable',
                      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, length):
        val = knob.value()  # range 0..1
        pointer.value(length * cmath.exp(-2j * val * pi))

    def quit(self, button):
        Screen.shutdown()

    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)

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

    def cblb(self, listbox):
        self.lbl_lb.value(listbox.textvalue())

    def set_dropdown(self, button):
        self.dropdown.value(0)

    def set_bytext(self, button, txt):
        self.dropdown.textvalue(txt)
Ejemplo n.º 29
0
def passthru(x, y, items):  # Passthru checkbox
    Checkbox((x, y), callback=cb_en_dis, args=(items, ))
    Label((x + 40, y), font=font14, value='Flat response')