def __init__(self): self.group = displayio.Group(max_size=4) self.glyph_width, self.glyph_height = font.get_bounding_box()[:2] self.pbar = ProgressBar(0, 0, board.DISPLAY.width, self.glyph_height, bar_color=0x0000ff, outline_color=0x333333, stroke=1) self.iconbar = icons.IconBar() self.iconbar.group.y = 112 for i in range(5, 8): self.iconbar.icons[i].x += 32 self.label = adafruit_display_text.label.Label(font, line_spacing=1.0, max_glyphs=256) self.label.y = 6 self._bitmap_filename = None self._fallback_bitmap = ["/rsrc/background.bmp"] self.set_bitmap([]) # Must be first! self.group.append(self.pbar) self.group.append(self.label) self.group.append(self.iconbar.group) self.pixels = neopixel.NeoPixel(board.NEOPIXEL, 5) self.pixels.auto_write = False self.pixels.fill(0) self.pixels.show() self.paused = False self.next_choice = 0
def get_otp_group(): otp_group = displayio.Group(max_size=10, scale=1, x=0, y=0) # OTP Code text_group1 = displayio.Group(max_size=10, scale=6, x=15, y=100) text1 = "999999" text_area1 = label.Label(terminalio.FONT, text=text1, color=0x00FF00) text_group1.append(text_area1) # Subgroup for text scaling otp_group.append(text_group1) # OTP label text_group2 = displayio.Group(max_size=10, scale=3, x=40, y=20) text2 = "OTP Label" text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFF0000) text_group2.append(text_area2) otp_group.append(text_group2) """ # 2 rectangles seemed to fit, but adjusting their width afterward does not refresh the display. # grey rectangle rect1 = rect.Rect(0, 70, 240, 4, fill=0x1e1e1e) otp_group.append(rect1) # time left rect2 = rect.Rect(0, 70, 120, 4, fill=0x00fa00) otp_group.append(rect2) """ progress = ProgressBar(0, 60, 240, 9, bar_color=0x00fa00, outline_color=0x1e1e1e) otp_group.append(progress) return otp_group, text_area1, text_area2, progress
def __init__(self): super(ProgressScreen, self).__init__() self.bar = ProgressBar(x=0, y=0, width=300, height=30, progress=0.0, bar_color=0x00AA00, outline_color=0xFFFFFF, stroke=3) self.bargroup = displayio.Group(max_size=10, x=10, y=210) self.bargroup.append(self.bar) self.cancelButton = self.addButton(120, 160, 80, 40, "Cancel", self.cancel) self.progress = 0 self.grinding = False self.startTime = 0.0 self.endTime = 0.0
) # set progress bar width and height relative to board's display BAR_WIDTH = (magtag.graphics.display.width // 2) - 10 BAR_HEIGHT = 13 NY_BAR_X = magtag.graphics.display.width // 4 - BAR_WIDTH // 2 US_BAR_X = (magtag.graphics.display.width // 4) * 3 - (BAR_WIDTH // 2) DOSE1_BAR_Y = 66 DOSE2_BAR_Y = 81 dose1_ny_progress_bar = ProgressBar( NY_BAR_X, DOSE1_BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000, ) dose1_us_progress_bar = ProgressBar( US_BAR_X, DOSE1_BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000, ) dose2_ny_progress_bar = ProgressBar( NY_BAR_X,
) magtag.set_text(bottom_lbl_txt, index=1) magtag.set_text(top_lbl_txt, index=2) # set progress bar width and height relative to board's display BAR_WIDTH = magtag.graphics.display.width - 80 BAR_HEIGHT = 30 BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2 BAR_Y = 66 # Create a new progress_bar object at (x, y) progress_bar = ProgressBar(BAR_X, BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000) magtag.graphics.splash.append(progress_bar) timestamp = None while True: # We will use deep sleep once it's available in CircuitPython if (not timestamp or (time.monotonic() - timestamp) > 24 * 60 * 60): # once per day... try: value = magtag.fetch() print("Response is", value)
btn_x += 63 # append buttons to splash group for b in buttons: splash.append(b.group) # refrsh timer label label_timer = Label(font, max_glyphs=2) label_timer.x = (display.width // 2) // 13 label_timer.y = 15 splash.append(label_timer) # create a new progress bar progress_bar = ProgressBar(display.width // 5, 125, 200, 30, bar_color=0xFFFFFF) splash.append(progress_bar) # how long to stay on if not in always_on mode countdown = ON_SECONDS # current button state, defaults to first item in totp_keys current_button = secrets['totp_keys'][0][0] buttons[0].selected = True while ALWAYS_ON or (countdown > 0): # Calculate current time based on NTP + monotonic unix_time = t - mono_time + int(time.monotonic())
BUTTON_WIDTH = int(screen_width / 3) BOTTOM_BUTTON_Y = int(screen_height - BUTTON_HEIGHT) # Set the NeoPixel brightness BRIGHTNESS = 0.1 BAR_WIDTH = screen_width - 40 BAR_HEIGHT = screen_height - (3 * BUTTON_HEIGHT) BARX = screen_width // 2 - BAR_WIDTH // 2 BARY = BUTTON_HEIGHT progress_bar = ProgressBar(BARX, BARY, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x666666, outline_color=0xFFFFFF) # Setup PyPortal without networking pyportal = PyPortal(default_bg=BACKGROUND_COLOR) num_pixels = 16 # Adjust to fit your device ring_1 = neopixel.NeoPixel(board.D4, num_pixels, brightness=BRIGHTNESS) # Adjust to fit your device ring_1.fill(GREEN) ring_1.show() buttons = [] font = bitmap_font.load_font("/fonts/Arial-ItalicMT-17.bdf")
import displayio from adafruit_progressbar import ProgressBar # Make the display context splash = displayio.Group(max_size=10) board.DISPLAY.show(splash) # set progress bar width and height relative to board's display width = board.DISPLAY.width - 40 height = 30 x = board.DISPLAY.width // 2 - width // 2 y = board.DISPLAY.height // 3 # Create a new progress_bar object at (x, y) progress_bar = ProgressBar(x, y, width, height, 1.0) # Append progress_bar to the splash group splash.append(progress_bar) current_progress = 0.0 while True: # range end is exclusive so we need to use 1 bigger than max number that we want for current_progress in range(0, 101, 1): print("Progress: {}%".format(current_progress)) progress_bar.progress = current_progress / 100 # convert to decimal time.sleep(0.01) time.sleep(0.3) progress_bar.progress = 0.0 time.sleep(0.3)
def __init__(self, display, layout_json): self.json = layout_json if "view_type" not in layout_json: raise MissingTypeError if layout_json["view_type"] != "ProgressBar": raise IncorrectTypeError( "view_type '{}' does not match Layout Class 'ProgressBar'". format(layout_json["view_type"])) self._display = display if "attributes" in layout_json: _missing_attrs = [] for attribute in REQUIRED_ATTRIBUTES: if attribute not in layout_json: _missing_attrs.append(attribute) if len(_missing_attrs) > 0: raise MissingRequiredAttributesError( "Missing required attributes: {}".format(_missing_attrs)) _bar_color = 0xFFFFFF if "bar_color" in layout_json["attributes"]: _bar_color = int(layout_json["attributes"]["bar_color"], 16) _outline_color = 0x000000 if "outline_color" in layout_json["attributes"]: _outline_color = int( layout_json["attributes"]["outline_color"], 16) _progress = 0.0 if "progress" in layout_json["attributes"]: _progress = layout_json["attributes"]["progress"] _stroke = 1 if "stroke" in layout_json["attributes"]: _stroke = int(layout_json["attributes"]["stroke"]) _width = 30 if "width" in layout_json["attributes"]: _width = self.keyword_compiler( layout_json["attributes"]["width"]) _height = 10 if "height" in layout_json["attributes"]: _height = self.keyword_compiler( layout_json["attributes"]["height"]) _x = 0 if "x" in layout_json["attributes"]: _x = self.keyword_compiler(layout_json["attributes"]["x"], { "WIDTH": _width, "HEIGHT": _height }) _y = 0 if "y" in layout_json["attributes"]: _y = self.keyword_compiler(layout_json["attributes"]["y"], { "WIDTH": _width, "HEIGHT": _height }) self.progress_bar = ProgressBar(_x, _y, _width, _height, 0.0, _bar_color, _outline_color, _stroke) self.progress_bar.progress = _progress self.view = self.progress_bar else: #default attributes pass
# Make the display context splash = displayio.Group(max_size=10) display.show(splash) # set progress bar width and height relative to board's display BAR_WIDTH = display.width - 40 BAR_HEIGHT = 30 x = display.width // 2 - BAR_WIDTH // 2 y = display.height // 3 # Create a new progress_bar object at (x, y) progress_bar = ProgressBar(x, y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x666666, outline_color=0xFFFFFF) # Append progress_bar to the splash group splash.append(progress_bar) current_progress = (time.monotonic() % 101) / 100.0 print(current_progress) progress_bar.progress = current_progress # refresh the display display.refresh() prev_a = a_btn.value
text_anchor_point=(0.5, 0.5), is_data=False, ) # set progress bar width and height relative to board's display BAR_WIDTH = magtag.graphics.display.width - 80 BAR_HEIGHT = 30 BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2 BAR_Y = 80 # Create a new progress_bar object at (x, y) progress_bar = ProgressBar(BAR_X, BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000) magtag.graphics.splash.append(progress_bar) try: magtag.network.get_local_time() now = rtc.RTC().datetime progress_bar.progress = now.tm_yday / days_in_year(now) magtag.set_text("{:.2f}%".format(now.tm_yday / days_in_year(now) * 100.0), index=1) print(now) magtag.exit_and_deep_sleep(24 * 60 * 60) # one day
text_position=( (magtag.graphics.display.width // 2) - 1, 85, ), text_anchor_point=(0.5, 0.5), is_data=False, ) # Fully vaccinated text BAR_WIDTH = magtag.graphics.display.width - 80 BAR_HEIGHT = 25 BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2 progress_bar = ProgressBar(BAR_X, 50, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000) progress_bar_1 = ProgressBar(BAR_X, 95, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000) magtag.graphics.splash.append(progress_bar) magtag.graphics.splash.append(progress_bar_1) magtag.graphics.set_background("/bmps/background.bmp")
# creating display and default brightness clue_display = board.DISPLAY clue_display.brightness = 0.5 # graphics group clueGroup = displayio.Group(max_size=20) # loading bitmap background clue_bg = displayio.OnDiskBitmap(open(clue_bgBMP, "rb")) clue_tilegrid = displayio.TileGrid(clue_bg, pixel_shader=displayio.ColorConverter()) clueGroup.append(clue_tilegrid) # creating the ProgressBar object bar_group = displayio.Group(max_size=20) prog_bar = ProgressBar(1, 1, 239, 25, bar_color=0x652f8f) bar_group.append(prog_bar) clueGroup.append(bar_group) # text for step goal steps_countdown = Label(small_font, text='%d Steps Remaining' % step_goal, color=clue.WHITE) steps_countdown.x = 55 steps_countdown.y = 12 # text for steps text_steps = Label(big_font, text="0 ", color=0xe90e8b) text_steps.x = 45 text_steps.y = 70 # text for steps per hour
# Make a background color fill color_bitmap = displayio.Bitmap(320, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x0 bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette) splash.append(bg_sprite) ########################################################################## # set progress bar width and height relative to board's display x = board.DISPLAY.width // 5 y = board.DISPLAY.height // 3 # Create a new progress_bar object at (x, y) progress_bar = ProgressBar(x, y, 200, 30, 1.0) # Append progress_bar to the splash group splash.append(progress_bar) current_progress = 0.0 while True: while current_progress <= 1.0: print("Progress: {}%".format(current_progress * 100)) progress_bar.progress = current_progress current_progress += 0.05 if current_progress >= 1.0: current_progress = 0.0 time.sleep(0.01)