Exemple #1
0
    def __init__(self, pageList):
        self._group = displayio.Group(max_size=99)

        #Our button collection
        self.buttons = []
        self.pageList = pageList

        btnUpper = Button(x=0,
                          y=0,
                          width=240,
                          height=40,
                          style=Button.ROUNDRECT,
                          outline_color=0xdddddd,
                          fill_color=None,
                          label_color=0xdddddd,
                          label_font=terminalio.FONT,
                          label="TOP",
                          selected_fill=0xdddddd)
        self.buttons.append(btnUpper)
        self._group.append(btnUpper)

        btnMid = Button(x=0,
                        y=40,
                        width=240,
                        height=50,
                        style=Button.ROUNDRECT,
                        outline_color=0xdddddd,
                        fill_color=None,
                        label_color=0xdddddd,
                        label_font=terminalio.FONT,
                        label="MID",
                        selected_fill=0xdddddd)
        btnMid.selected = True
        self.buttons.append(btnMid)
        self._group.append(btnMid)

        btnLow = Button(x=0,
                        y=90,
                        width=240,
                        height=40,
                        style=Button.ROUNDRECT,
                        outline_color=0xdddddd,
                        fill_color=None,
                        label_color=0xdddddd,
                        label_font=terminalio.FONT,
                        label="LOW",
                        selected_fill=0xdddddd)
        self.buttons.append(btnLow)
        self._group.append(btnLow)
    def __init__(self, *menu_items):
        self.menu_items = menu_items
        self.current_index = 0
        self.buttons = []

        self.menu_group = displayio.Group(max_size=len(self.menu_items) + 1)

        display_height = 120
        step = int(display_height / (len(self.menu_items) + 1))

        title = Button(
            x=1,
            y=0,
            width=159,
            height=step,
            label_color=0xFFFFFF,
            fill_color=0x000,
            label="Microsoft PyBadge v1.0",
            label_font=terminalio.FONT,
        )
        self.menu_group.append(title.group)

        for index, menu_item in enumerate(self.menu_items, start=1):
            button = Button(
                style=Button.ROUNDRECT,
                x=1,
                y=index * step,
                width=159,
                height=step,
                label_color=0xFFFF,
                outline_color=0x767676,
                fill_color=0x5C5B5C,
                selected_fill=0x5A5A5A,
                selected_outline=0xFF00FF,
                selected_label=0xFFFF00,
                label=menu_item.label,
                label_font=terminalio.FONT,
            )
            if index - 1 == self.current_index:
                button.selected = True
            self.menu_group.append(button.group)
            self.buttons.append(button)
Exemple #3
0
                    height=40,
                    label=i['label'],
                    label_font=font,
                    style=Button.SHADOWROUNDRECT)
    buttons.append(button)

# add buttons to the group
for b in buttons:
    button_group.append(b.group)

while True:
    touch = ts.touch_point
    if touch:
        for i, button in enumerate(buttons):
            if button.contains(touch):
                button.selected = True
                if button.name == 'lamp':
                    current_light = lifx_lights[0]
                    print('Switching to ', current_light)
                elif button.name == 'room':
                    current_light = lifx_lights[1]
                    print('Switching to ', current_light)
                elif button.name == 'onoff':
                    print('Toggling {0}...'.format(current_light))
                    lifx.toggle_light(current_light)
                elif button.name == 'up':
                    light_brightness += 0.25
                    print('Setting {0} brightness to {1}'.format(
                        current_light, light_brightness))
                    lifx.set_brightness(current_light, light_brightness)
                elif button.name == 'down':
Exemple #4
0
        print("View2 On")
    else:
        hideLayer(view1)
        hideLayer(view2)
        button_view1.selected = True
        button_view2.selected = True
        button_view3.selected = False
        showLayer(view3)
        view_live = 3
        print("View3 On")


#pylint: enable=global-statement

# Set veriables and startup states
button_view1.selected = False
button_view2.selected = True
button_view3.selected = True
showLayer(view1)
hideLayer(view2)
hideLayer(view3)

view_live = 1
icon = 1
icon_name = "Ruby"
button_mode = 1
switch_state = 0
button_switch.label = "OFF"
button_switch.selected = True

# Update out Labels with display text.
Exemple #5
0
splash = displayio.Group()
board.DISPLAY.show(splash)

# Make the button
button = Button(
    x=BUTTON_X,
    y=BUTTON_Y,
    width=BUTTON_WIDTH,
    height=BUTTON_HEIGHT,
    style=BUTTON_STYLE,
    fill_color=BUTTON_FILL_COLOR,
    outline_color=BUTTON_OUTLINE_COLOR,
    label=BUTTON_LABEL,
    label_font=terminalio.FONT,
    label_color=BUTTON_LABEL_COLOR,
)

# Add button to the display context
splash.append(button)

# Loop and look for touches
while True:
    p = ts.touch_point
    if p:
        if button.contains(p):
            button.selected = True
        else:
            button.selected = False  # if touch is dragged outside of button
    else:
        button.selected = False  # if touch is released
Exemple #6
0
        view_live = 3
        print("View3 On")
#pylint: enable=global-statement

# Set veriables and startup states
showLayer(view1)

view_live = 1
icon = 1
button_mode = 1
switch_state = 0
switch_state1 = 0
switch_state2 = 0
switch_state3 = 1
button_switch.label = "OFF"
button_switch.selected = True
button_icon3.selected = True

# Update out Labels with display text.

text_box(feed1_label, 0,
        '{}/{}/{}'.format(time.localtime().tm_mon, time.localtime().tm_mday,time.localtime().tm_year), 12)

text_box(feed2_label, TABS_Y + 60, 'Light Hours (On/Off):', 32)

board.DISPLAY.show(splash)
localtime_refresh= time.monotonic()
# ------------- Code Loop ------------- #
while True:
    if (not localtime_refresh) or (time.monotonic() - localtime_refresh) > 60: # check internet time every minute
        print("Getting time from internet!")
        print()
#pylint: enable=global-statement

#----------- End functions -------------------------------------------------------------#

# Set variables and startup states
# Set the background
set_image(bg_group, "/images/bg_green.bmp")
# Set the Backlight
set_backlight(1)    # Or vary with ambient...
# Init the view_live variable
view_live = 1
# Set neopixel to lite red
pixel.fill(LITE_RED)
# Set up buttons
button_att_view.selected = False
button_def_view.selected = True
button_roll_view.selected = True
# Set up layers
showLayer(att_view)
print('Att view initialized')
print()
hideLayer(def_view)
hideLayer(roll_view)
# Come out of splash screen
board.DISPLAY.show(main)

# ------------- Code Loop ------------- #
while True:
    touch = ts.touch_point
    time.sleep(.05)     # Seems to help debounce touchscreen
# Defiine the button
button = Button(
    x=BUTTON_X,
    y=BUTTON_Y,
    width=BUTTON_WIDTH,
    height=BUTTON_HEIGHT,
    style=BUTTON_STYLE,
    fill_color=BUTTON_FILL_COLOR,
    outline_color=BUTTON_OUTLINE_COLOR,
    label=BUTTON_LABEL,
    label_font=terminalio.FONT,
    label_color=BUTTON_LABEL_COLOR,
)

# Add button to the displayio group
splash.append(button)

# Loop and look for touches
while True:
    p = ts.touch_point
    if p:
        if button.contains(p):
            button.selected = True
            # Perform a task related to the button press here
            time.sleep(
                0.25)  # Wait a bit so we can see the button color change
        else:
            button.selected = False  # When touch moves outside of button
    else:
        button.selected = False  # When button is released