def __init__(self): super().__init__() Label((0, 0), font = font14, value = 'plot module demo.') Label((0, 100), font = font10, value = 'RT: simulate realtime data acquisition.') Label((0, 140), font = font10, value = 'Over, Lines: test clipping.') fwdbutton(0, 242, PolarScreen, 'Polar') fwdbutton(100, 242, XYScreen, 'XY') fwdbutton(200, 242, RealtimeScreen, 'RT') fwdbutton(0, 200, PolarORScreen, 'Over') fwdbutton(100, 200, DiscontScreen, 'Lines') quitbutton(390, 242)
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)
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)
def __init__(self, font, *, elements, location=(20, 20), label=None, bgcolor=DARKGREEN, buttonwidth=25, closebutton=True): height = 150 spacing = 20 buttonwidth = max( max([get_stringsize(x[0], font)[0] for x in elements]) + 4, buttonwidth) buttonheight = max(get_stringsize('x', font)[1], 25) 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] + 50), font=font, 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, 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', ))
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'), pointercolor=YELLOW, fgcolor=GREEN) 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)
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.mainthread(self.dial1, True))) self.tasks.append(asyncio.create_task(self.mainthread(self.dial2))) fwdbutton(0, 242, BackScreen) self.backbutton(390, 242)
def show(self): tft = self.tft bw = self.border height = self.height - 2 * bw width = self.pot_dimension # Length of slot x = self.location[ 0] + bw + self.slidewidth // 2 # Allow space left and right slot for slider at extremes y = self.location[1] + bw if self._value is None or self.redraw: # Initialising self.redraw = False self.render_slide(tft, self.bgcolor) # Erase slide if it exists dy = height // 2 - 2 # slot is 4 pixels wide tft.draw_rectangle(x, y + dy, x + width, y + height - dy, self.fgcolor) if self.divisions > 0: dx = width / (self.divisions) # Tick marks for tick in range(self.divisions + 1): xpos = int(x + dx * tick) tft.draw_vline( xpos, y + 1, dy, self.fgcolor) # TODO Why is +1 fiddle required here? tft.draw_vline(xpos, y + 2 + height // 2, dy, self.fgcolor) # Add half slot width # 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 = width / (len(self.legends) - 1) xl = x font = self.font for legend in self.legends: offset = get_stringsize(legend, self.font)[0] / 2 loc = int(xl - offset), y - self.font.height() - bw - 1 Label(loc, font=font, fontcolor=self.fontcolor, value=legend) xl += dx self.save_background(tft) if self._value is None: self.value(self._initial_value, show=False) # prevent recursion self.render_bg(tft) self.slide_x = self.update(tft) # Reflect new value in slider position self.save_background(tft) color = self.slidecolor if self.slidecolor is not None else self.fgcolor self.render_slide(tft, color) self.drawn = True
def show(self): tft = self.tft bw = self.border width = self.width - 2 * bw height = self.pot_dimension # Height of slot x = self.location[0] + bw y = self.location[ 1] + bw + self.slideheight // 2 # Allow space above and below slot if self._value is None or self.redraw: # Initialising self.redraw = False self.render_slide(tft, self.bgcolor) # Erase slide if it exists dx = width // 2 - 2 tft.draw_rectangle(x + dx, y, x + width - dx, y + height, self.fgcolor) if self.divisions > 0: dy = height / (self.divisions) # Tick marks for tick in range(self.divisions + 1): ypos = int(y + dy * tick) tft.draw_hline(x + 1, ypos, dx, self.fgcolor) tft.draw_hline(x + 2 + width // 2, ypos, dx, self.fgcolor) # Add half slot width # 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 = height / (len(self.legends) - 1) yl = y + height # 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 self.save_background(tft) if self._value is None: self.value(self._initial_value, show=False) # Prevent recursion self.render_bg(tft) self.slide_y = self.update(tft) # Reflect new value in slider position self.save_background(tft) color = self.slidecolor if self.slidecolor is not None else self.fgcolor self.render_slide(tft, color) self.drawn = True
def __init__(self): super().__init__() # Common args for the labels labels = { 'width': 70, '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)
def __init__(self): super().__init__() # Common args for the labels labels = { 'width' : 70, '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.thread1()) self.reg_task(self.thread2()) # 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])
def __init__(self): super().__init__() # Label common attributes labels = { 'width': 70, 'fontcolor': WHITE, 'border': 2, 'fgcolor': RED, 'bgcolor': (0, 40, 0), 'font': font14, } # Static labels Label((90, 0), font=font10, value='Flashing buttons') Label((90, 18), font=font10, value='(RH responds to long press)') Label((244, lr(1) + 5), font=font10, value='Reset radio button') Label((244, lr(2) + 5), font=font10, value='Reset checkbox') Label((244, lr(3) + 5), font=font10, value='Disable rb, checkbox') Label((370, 243), font=font14, value='Quit') # Dynamic labels self.lstlbl = [] for n in range(4): self.lstlbl.append(Label((400, lr(n)), **labels)) # Flashing buttons (RH one responds to long press) IconButton((10, lr(0)), icon_module=flash, flash=1.0, callback=self.callback, args=('A', 0)) IconButton((50, lr(0)), icon_module=flash, flash=1.0, callback=self.callback, args=('Short', 0), lp_callback=self.callback, lp_args=('Long', 0), onrelease=False) # Quit button IconButton((420, 240), icon_module=radiobutton, callback=quit) # Radio buttons rb = IconRadioButtons(callback=self.callback) rb0 = rb.add_button((10, lr(1)), icon_module=radiobutton, args=('1', 1)) rb.add_button((50, lr(1)), icon_module=radiobutton, args=('2', 1)) rb.add_button((90, lr(1)), icon_module=radiobutton, args=('3', 1)) rb.add_button((130, lr(1)), icon_module=radiobutton, args=('4', 1)) # Checkbox cb = IconButton((10, lr(2)), icon_module=threestate, toggle=True, callback=self.cbcb, args=(2, )) # Traffic light state change button IconButton((10, lr(4)), icon_module=traffic, toggle=True) # Reset buttons IconButton((200, lr(1)), icon_module=radiobutton, callback=self.rb_cancel, args=(rb, rb0)) IconButton((200, lr(2)), icon_module=radiobutton, callback=self.cb_cancel, args=(cb, )) # Switch sw = IconButton((10, lr(3)), icon_module=iconswitch, callback=self.cbswitch, toggle=True, args=(3, )) # Disable Checkbox IconButton((200, lr(3)), icon_module=checkbox, toggle=True, callback=self.cb_en_dis, args=((cb, rb, sw), )) # Gauge ig = IconGauge((80, lr(5)), icon_module=gauge) self.reg_task(self.maintask(ig))
def __init__(self): super().__init__() # Common args for the labels labels = { 'width': 70, 'fontcolor': WHITE, 'border': 2, 'fgcolor': RED, 'bgcolor': (0, 40, 0), } # Common arguments for all three sliders table = { 'fontcolor': WHITE, 'legends': ('0', '5', '10'), 'cb_end': self.slide_release, } self.led = LED((420, 0), border=2) meter1 = Meter((320, 0), font=font10, legends=('0', '5', '10'), pointercolor=YELLOW, fgcolor=GREEN) meter2 = Meter((360, 0), font=font10, legends=('0', '5', '10'), pointercolor=YELLOW) btnquit = Button((390, 240), font=font14, callback=self.quit, fgcolor=RED, text='Quit', shape=RECTANGLE, width=80, height=30) # Create labels x = 230 lstlbl = [] for n in range(3): lstlbl.append(Label((x, 40 + 60 * n), font=font10, **labels)) # Sliders x = 10 self.slave1 = HorizSlider((x, 100), font=font10, fgcolor=GREEN, cbe_args=('Slave1', ), cb_move=self.slave_moved, cbm_args=(lstlbl[1], ), **table) self.slave2 = HorizSlider((x, 160), font=font10, fgcolor=GREEN, cbe_args=('Slave2', ), cb_move=self.slave_moved, cbm_args=(lstlbl[2], ), **table) master = HorizSlider((x, 40), font=font10, fgcolor=YELLOW, cbe_args=('Master', ), cb_move=self.master_moved, slidecolor=RED, border=2, cbm_args=(lstlbl[0], ), value=0.5, **table) # On/Off toggle: enable/disable bs = ButtonList(self.cb_en_dis) self.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, )) button = bs.add_button((280, 240), font=font14, fontcolor=BLACK, height=30, width=90, fgcolor=RED, shape=RECTANGLE, text='Enable', args=(False, )) # Tasks test meters self.reg_task(self.test_meter(meter1)) self.reg_task(self.test_meter(meter2))
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 }, { 'fgcolor': GREY, 'text': 'Rats', 'args': ('Rats', 2), 'shape': CLIPPED_RECT, }, ] # 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)) # Button assortment x = 0 for t in table: Button((x, 0), font=font14, callback=self.callback, **t) x += 70 # Highlighting buttons x = 0 for t in table_highlight: Button((x, 60), fgcolor=GREY, fontcolor=BLACK, litcolor=WHITE, font=font14, callback=self.callback, **t) x += 70 # 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 # 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 # Checkbox self.cb1 = Checkbox((340, 0), callback=self.cbcb, args=(0, )) self.cb2 = Checkbox((340, 40), fillcolor=RED, callback=self.cbcb, args=(1, )) # Reset button self.lbl_reset = Label((200, 220), 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.tup_en_dis = (self.cb1, self.cb2, self.rb, self.bs ) # Items affected by enable/disable button 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, ))
def __init__(self): super().__init__() Button((390, 240), font=font14, callback=self.quit, fgcolor=RED, text='Quit', shape=RECTANGLE, width=80, height=30) self.dial = Dial((120, 0), fgcolor=YELLOW, border=2, pointers=(0.9, 0.7)) k0 = Knob((0, 0), fgcolor=GREEN, bgcolor=(0, 0, 80), color=(168, 63, 63), border=2, cb_end=self.callback, cbe_args=['Knob1'], cb_move=self.knob_moved, cbm_args=(0, )) k1 = Knob((0, 120), fgcolor=WHITE, border=2, arc=pi * 1.5, cb_end=self.callback, cbe_args=['Knob2'], cb_move=self.knob_moved, cbm_args=(1, )) # Dropdown self.lbl_dd = Label((120, 120), font=font14, width=100, border=2, bgcolor=(0, 40, 0), fgcolor=RED) self.dropdown = Dropdown( (280, 0), font=font14, width=100, callback=self.cbdb, elements=('Dog', 'Cat', 'Rat', 'Goat', 'Snake', 'Pig')) Button((280, 70), font=font14, callback=self.set_dropdown, fgcolor=BLUE, text='Reset', shape=RECTANGLE, width=80, height=30) # Test of set by value Button((280, 120), font=font14, callback=self.set_bytext, args=('Snake', ), fgcolor=CYAN, fontcolor=BLACK, text='Snake', shape=RECTANGLE, width=80, height=30) # test set by text # Listbox self.listbox = Listbox( (370, 70), font=font14, 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=font14, fontcolor=WHITE, height=30, width=90, fgcolor=RED, shape=RECTANGLE, text='Dim', args=(False, )) bstyle.add_button((170, 240), font=font14, 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, self.listbox) bs.add_button((280, 240), font=font14, fontcolor=BLACK, height=30, width=90, fgcolor=GREEN, shape=RECTANGLE, text='Disable', args=(True, )) bs.add_button((280, 240), font=font14, fontcolor=BLACK, height=30, width=90, fgcolor=RED, shape=RECTANGLE, text='Enable', args=(False, ))
class KnobScreen(Screen): def __init__(self): super().__init__() Button((390, 240), font=font14, callback=self.quit, fgcolor=RED, text='Quit', shape=RECTANGLE, width=80, height=30) self.dial = Dial((120, 0), fgcolor=YELLOW, border=2, pointers=(0.9, 0.7)) k0 = Knob((0, 0), fgcolor=GREEN, bgcolor=(0, 0, 80), color=(168, 63, 63), border=2, cb_end=self.callback, cbe_args=['Knob1'], cb_move=self.knob_moved, cbm_args=(0, )) k1 = Knob((0, 120), fgcolor=WHITE, border=2, arc=pi * 1.5, cb_end=self.callback, cbe_args=['Knob2'], cb_move=self.knob_moved, cbm_args=(1, )) # Dropdown self.lbl_dd = Label((120, 120), font=font14, width=100, border=2, bgcolor=(0, 40, 0), fgcolor=RED) self.dropdown = Dropdown( (280, 0), font=font14, width=100, callback=self.cbdb, elements=('Dog', 'Cat', 'Rat', 'Goat', 'Snake', 'Pig')) Button((280, 70), font=font14, callback=self.set_dropdown, fgcolor=BLUE, text='Reset', shape=RECTANGLE, width=80, height=30) # Test of set by value Button((280, 120), font=font14, callback=self.set_bytext, args=('Snake', ), fgcolor=CYAN, fontcolor=BLACK, text='Snake', shape=RECTANGLE, width=80, height=30) # test set by text # Listbox self.listbox = Listbox( (370, 70), font=font14, 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=font14, fontcolor=WHITE, height=30, width=90, fgcolor=RED, shape=RECTANGLE, text='Dim', args=(False, )) bstyle.add_button((170, 240), font=font14, 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, self.listbox) bs.add_button((280, 240), font=font14, fontcolor=BLACK, height=30, width=90, fgcolor=GREEN, shape=RECTANGLE, text='Disable', args=(True, )) bs.add_button((280, 240), font=font14, 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): val = knob.value() # range 0..1 self.dial.value(2 * (val - 0.5) * pi, pointer) 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): print(listbox.textvalue()) def set_dropdown(self, button): self.dropdown.value(0) def set_bytext(self, button, txt): self.dropdown.textvalue(txt)
def __init__(self): super().__init__() Label((0, 0), font = font10, value = 'Ensure back refreshes properly') backbutton(390, 242)
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'
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, 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