Ejemplo n.º 1
0
 def __init__(self):
     height = 80
     width = 130
     super().__init__((20, 20), height, width, bgcolor=DARKGREEN)
     y = self.height - 30
     Button(self.locn(10, y),
            font=font10,
            fontcolor=BLACK,
            fgcolor=RED,
            text='Cat',
            callback=self.back,
            args=('Cat', ))
     Button(self.locn(70, y),
            font=font10,
            fontcolor=BLACK,
            fgcolor=GREEN,
            text='Dog',
            callback=self.back,
            args=('Dog', ))
     Button(self.locn(width - 21, 1),
            height=20,
            width=20,
            font=font10,
            fgcolor=RED,
            text='X',
            callback=self.back,
            args=('Close', ))
Ejemplo n.º 2
0
 def __init__(self,
              font,
              *,
              elements,
              location=(20, 20),
              label=None,
              bgcolor=DARKGREEN,
              buttonwidth=25,
              closebutton=True):
     height = 100
     spacing = 5
     buttonwidth = max(
         max([get_stringsize(x[0], font)[0] for x in elements]) + 4,
         buttonwidth)
     buttonheight = max(get_stringsize('x', font)[1], 20)
     nelements = len(elements)
     width = spacing + (buttonwidth + spacing) * nelements
     if label is not None:
         width = max(width, 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] + 25),
               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 = get_stringsize('X', font)
         size = max(x, y, 20)
         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.º 3
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, ))
Ejemplo n.º 4
0
 def __init__(self, clip):
     super().__init__()
     backbutton()
     tb = Textbox((0, 0), 159, 7, font=font3, clip=clip, tab=64, **tbargs)
     Button((0, 107),
            text='Fill',
            callback=populate,
            args=(tb, ),
            **btntable)
     Button((54, 107),
            text='Clear',
            callback=lambda b, tb: tb.clear(),
            args=(tb, ),
            **btntable)
Ejemplo n.º 5
0
def backbutton():
    def back(button):
        Screen.back()

    Button((109, 107),
           font=font10,
           fontcolor=BLACK,
           callback=back,
           fgcolor=CYAN,
           text='Back')
Ejemplo n.º 6
0
    def __init__(self, clip):
        super().__init__()
        backbutton()
        tb = Textbox((0, 0), 159, 7, font=font3, clip=clip, **tbargs)

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

        self.reg_task(txt_test(tb, btns))
Ejemplo n.º 7
0
def fwdbutton(x, y, cls_screen, text='Next'):
    def fwd(button):
        Screen.change(cls_screen)

    Button((x, y),
           font=font10,
           callback=fwd,
           fgcolor=RED,
           text=text,
           shape=RECTANGLE)
Ejemplo n.º 8
0
def quitbutton():
    def quit(button):
        Screen.shutdown()

    Button(
        (109, 107),
        font=font10,
        callback=quit,
        fgcolor=RED,
        text='Quit',
    )
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
 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', ))
Ejemplo n.º 11
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', ))
Ejemplo n.º 12
0
def ovlbutton():
    def fwd(button):
        Screen.change(BackScreen)
    return Button((139, 35), font = font10, fontcolor = BLACK, callback = fwd,
                  fgcolor = CYAN, text = 'O', height = 20, width = 20)
Ejemplo n.º 13
0
def backbutton():
    def back(button):
        Screen.back()
    return Button((139, 0), font = font10, fontcolor = BLACK, callback = back,
           fgcolor = RED,  text = 'X', height = 20, width = 20)
Ejemplo n.º 14
0
def fwdbutton(x, y, screen, text='Next'):
    def fwd(button, screen):
        Screen.change(screen)
    return Button((x, y), font = font10, fontcolor = BLACK, callback = fwd,
                  onrelease = False, args = [screen], fgcolor = CYAN, text = text)
Ejemplo n.º 15
0
def fwdbutton(x, y, cls_screen, *, text='Next', args=[], kwargs={}):
    def fwd(button):
        Screen.change(cls_screen, args=args, kwargs=kwargs)

    Button((x, y), font=font10, callback=fwd, fgcolor=RED, text=text)
Ejemplo n.º 16
0
def fwdbutton(cls_screen):
    def fwd(button):
        Screen.change(cls_screen)
    Button((0, 107), font = font10, callback = fwd, fgcolor = RED,
           onrelease=False, text = 'Next', shape = RECTANGLE)
Ejemplo n.º 17
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, ))
Ejemplo n.º 18
0
def clearbutton(graph):
    def clear(button):
        graph.clear()
    return Button((139, 71), font = font10, fontcolor = BLACK, callback = clear,
           fgcolor = GREEN,  text = 'C', height = 20, width = 20)
Ejemplo n.º 19
0
def refreshbutton(curvelist):
    def refresh(button):
        for curve in curvelist:
            curve.show()
    return Button((139, 107), font = font10, fontcolor = BLACK, callback = refresh,
           fgcolor = GREEN,  text = 'R', height = 20, width = 20)
Ejemplo n.º 20
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())