def render(self): display = badge.display screen = displayio.Group() screen.append( Rect(0, 32, display.width, display.height - 32, fill=0xffffff)) app_label = bitmap_label.Label(terminalio.FONT, text="Keyboard Test", color=0xffffff, save_text=True) app_label_group = displayio.Group(scale=2, x=40, y=14) app_label_group.append(app_label) screen.append(app_label_group) if self.keyboard: key_label = bitmap_label.Label(terminalio.FONT, text=self.text, color=0x0, scale=3, anchor_point=(0.5, 0.5), anchored_position=(display.width // 2, 70)) else: key_label = bitmap_label.Label( terminalio.FONT, text="Keyboard not connected\n :-(", color=0x0, scale=2, anchor_point=(0.5, 0.5), anchored_position=(display.width // 2, 70)) screen.append(key_label) display.show(screen) self.update_screen = False
def render(self): display = badge.display screen = displayio.Group() screen.append( Rect(0, 32, display.width, display.height - 32, fill=0xffffff)) banner_image = displayio.OnDiskBitmap( open("{}/icon.bmp".format(APP_ROOT), "rb")) palette = displayio.Palette(1) palette[0] = 0xffffff banner = displayio.TileGrid(banner_image, pixel_shader=palette, x=4, y=0) screen.append(banner) app_label = bitmap_label.Label(terminalio.FONT, text="Conference Agenda", color=0xffffff, save_text=True) app_label_group = displayio.Group(scale=2, x=40, y=14) app_label_group.append(app_label) screen.append(app_label_group) lines_group = displayio.Group(x=8, y=48) lines = self.agenda[self.current_agenda][self.screen * SCREEN_SIZE:(self.screen + 1) * SCREEN_SIZE] for (index, line) in enumerate(lines): lines_group.append( bitmap_label.Label(terminalio.FONT, text=line[0:40], color=0x0, y=index * 12, save_text=True)) screen.append(lines_group) # Display up/down arrows as needed if self.screen > 0: more_icon = displayio.OnDiskBitmap( open("{}/arrow_up.bmp".format(APP_ROOT), "rb")) screen.append( displayio.TileGrid(more_icon, pixel_shader=displayio.ColorConverter(), x=display.width - 20, y=40)) if self.screen + 1 < self.screen_count[self.current_agenda]: more_icon = displayio.OnDiskBitmap( open("{}/arrow_down.bmp".format(APP_ROOT), "rb")) screen.append( displayio.TileGrid(more_icon, pixel_shader=displayio.ColorConverter(), x=display.width - 20, y=display.height - 16)) display.show(screen)
def make_name_text(text, anchor_point, anchored_position, bg_color=LBL_BACKGROUND): """ Create label object for labeling data values. It will get a background color box and appropriate padding. :param text: Text to show :param anchor_point: location anchor_point :param anchored_position: location anchored_position :return bitmap_label.Label: the Label object """ return bitmap_label.Label( font, text=text, anchor_point=anchor_point, anchored_position=anchored_position, background_color=bg_color, padding_left=4, padding_right=4, padding_bottom=3, padding_top=3, line_spacing=1.0, )
def __init__(self, label_text, icon, on_disk=False, **kwargs): super().__init__(**kwargs) self._icon = icon if on_disk: self._file = open(self._icon, "rb") image = OnDiskBitmap(self._file) tile_grid = TileGrid(image, pixel_shader=ColorConverter()) else: image, palette = adafruit_imageload.load(icon) tile_grid = TileGrid(image, pixel_shader=palette) self.append(tile_grid) _label = bitmap_label.Label( terminalio.FONT, scale=1, text=label_text, anchor_point=(0.5, 0), anchored_position=(image.width // 2, image.height), ) self.append(_label) self.touch_boundary = ( 0, 0, image.width, image.height + _label.bounding_box[3], )
def __init__(self, text_color, song_list=None, current_track_number=0, max_chars=30, rows=3): super().__init__() self._rows = rows if song_list is None: song_list = [] self._song_list = song_list self._current_track_number = current_track_number self._max_chars = max_chars # the label to show track titles inside of self._label = bitmap_label.Label(terminalio.FONT, color=text_color) # default position, top left inside of the self instance group self._label.anchor_point = (0, 0) self._label.anchored_position = (0, 0) self.append(self._label) # initial refresh to show the songs self.update_display()
def make_value_text( anchor_point, anchored_position, custom_font=True, bg_color=0x000000, font_color=0xFFFFF, ): """ Create label object for showing data values. :param anchor_point: location anchor_point :param anchored_position: location anchored_position :param bool custom_font: weather to use the custom font or system font :return bitmap_label.Label: the Label object """ if custom_font: _font = font else: _font = terminalio.FONT return bitmap_label.Label( _font, text="", anchor_point=anchor_point, anchored_position=anchored_position, line_spacing=1.0, padding_top=3, background_color=bg_color, color=font_color, padding_right=4, padding_left=4, padding_bottom=4, )
def _create_label(self, file_name: str) -> bitmap_label.Label: # pylint: disable=too-many-branches """Creates and returns a label from a file object that contains valid valid json describing the text to use. See: examples/sample_text_slide.json """ with open(file_name, "rb") as file: json_data = json.loads(file.read()) _scale = 1 if "scale" in json_data: _scale = int(json_data["scale"]) if CUSTOM_FONTS: if "font" in json_data: _font = bitmap_font.load_font(json_data["font"]) else: _font = terminalio.FONT else: _font = terminalio.FONT label = bitmap_label.Label(_font, text=json_data["text"], scale=_scale) if "h_align" not in json_data or json_data["h_align"] == "LEFT": x_anchor_point = 0.0 x_anchored_position = 0 elif json_data["h_align"] == "CENTER": x_anchor_point = 0.5 x_anchored_position = self._display.width // 2 elif json_data["h_align"] == "RIGHT": x_anchor_point = 1.0 x_anchored_position = self._display.width - 1 else: # wrong value for align x_anchor_point = 0.0 x_anchored_position = 0 if "v_align" not in json_data or json_data["v_align"] == "TOP": y_anchor_point = 0.0 y_anchored_position = 0 elif json_data["v_align"] == "CENTER": y_anchor_point = 0.5 y_anchored_position = self._display.height // 2 elif json_data["v_align"] == "BOTTOM": y_anchor_point = 1.0 y_anchored_position = self._display.height - 1 else: # wrong value for align y_anchor_point = 0.0 y_anchored_position = 0 if "background_color" in json_data: label.background_color = int(json_data["background_color"], 16) if "color" in json_data: label.color = int(json_data["color"], 16) label.anchor_point = (x_anchor_point, y_anchor_point) label.anchored_position = (x_anchored_position, y_anchored_position) return label
def __init__(self, text_color): super().__init__() # seconds elapsed to show on the clock display self._seconds = 0 # Minutes tens digit label self.first_digit = bitmap_label.Label(terminalio.FONT, color=text_color) self.first_digit.anchor_point = (0, 0) self.first_digit.anchored_position = (0, 0) self.append(self.first_digit) # Minutes ones digit label self.second_digit = bitmap_label.Label(terminalio.FONT, color=text_color) self.second_digit.anchor_point = (0, 0) self.second_digit.anchored_position = (10, 0) self.append(self.second_digit) # Seconds tens digit label self.third_digit = bitmap_label.Label(terminalio.FONT, color=text_color) self.third_digit.anchor_point = (0, 0) self.third_digit.anchored_position = (26, 0) self.append(self.third_digit) # Seconds ones digit label self.fourth_digit = bitmap_label.Label(terminalio.FONT, color=text_color) self.fourth_digit.anchor_point = (0, 0) self.fourth_digit.anchored_position = (36, 0) self.append(self.fourth_digit) # initialize showing the display self.update_display()
def make_value_text(anchor_point, anchored_position, custom_font=True): """ Create label object for showing data values. :param anchor_point: location anchor_point :param anchored_position: location anchored_position :param bool custom_font: weather to use the custom font or system font :return bitmap_label.Label: the Label object """ if custom_font: _font = font else: _font = terminalio.FONT return bitmap_label.Label( _font, text="", anchor_point=anchor_point, anchored_position=anchored_position )
# Make the display context. Change size if you want display = board.DISPLAY background = displayio.Bitmap(320, 240, 1) bg_palette = displayio.Palette(1) bg_palette[0] = 0xDDDD00 # Make the display context main_group = displayio.Group(max_size=10) display.show(main_group) font = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf") reg_label = label.Label( font=font, text="CIRCUIT PYTHON", padding_bottom=20, color=None, scale=1, background_color=0x000000, ) reg_label.anchor_point = (0.5, 0.5) reg_label.anchored_position = (display.width // 2, display.height // 2) rainbow_bitmap = displayio.Bitmap( reg_label.bounding_box[2] * reg_label.scale, reg_label.bounding_box[3] * reg_label.scale, 255, ) rainbow_palette = displayio.Palette(255) for i in range(0, 255):
def draw_labels( target_bitmap, *, font, font_height, tick_labels, dial_center, dial_radius, start_angle, sweep_angle, rotate_labels=True, tick_label_scale=1.0, ): """Helper function for drawing text labels on the dial widget. Can be used to customize the dial face. :param displayio.Bitmap target_bitmap: Bitmap where ticks will be drawn into :param Font font: the font to be used to draw the tick mark text labels :param int font_height: the height of the font, used for text placement :param List[str] tick_labels: a list of strings for the tick text labels :param (int,int) dial_center: the (x,y) pixel location in the bitmap of the dial's center of rotation :param int dial_radius: the radius of the dial (not including padding), in pixels :param int tick_count: number of ticks to be drawn :param int tick_stroke: the pixel width of the line used to draw the tick :param float start_angle: starting angle of the dial, in degrees :param float sweep_angle: total sweep angle of the dial, in degrees :param bool rotate_labels: set to True if you want the label text to be rotated to align with the tick marks :param float tick_label_scale: scale factor for the tick text labels, default is 1.0 """ label_count = len(tick_labels) for i, this_label_text in enumerate(tick_labels): temp_label = bitmap_label.Label( font, text=this_label_text ) # make a tick line bitmap for blitting this_angle = (2 * math.pi / 360) * ( start_angle + i * sweep_angle / (label_count - 1) ) # in radians target_position_x = dial_center[0] + ( dial_radius + font_height // 2 ) * math.sin(this_angle) target_position_y = dial_center[1] - ( dial_radius + font_height // 2 ) * math.cos(this_angle) if rotate_labels: pass else: this_angle = 0 if "rotozoom" in dir(bitmaptools): # if core function is available bitmaptools.rotozoom( target_bitmap, ox=round(target_position_x), oy=round(target_position_y), source_bitmap=temp_label.bitmap, px=round(temp_label.bitmap.width // 2), py=round(temp_label.bitmap.height // 2), angle=this_angle, scale=tick_label_scale, ) else: _blit_rotate_scale( # translate and rotate the tick into the target_bitmap destination=target_bitmap, ox=round(target_position_x), oy=round(target_position_y), source=temp_label.bitmap, px=round(temp_label.bitmap.width // 2), py=round(temp_label.bitmap.height // 2), angle=this_angle, scale=tick_label_scale, )
def _initialize_dial(self, width, height): for _ in range(len(self)): self.pop() # get the tick label font height self._font_height = self._get_font_height( font=self._tick_label_font, scale=self._tick_label_scale ) # update the dial dimensions to fit inside the requested width and height self._adjust_dimensions(width, height) self._bounding_box = [0, 0, self._width, self._height] self._update_position() # create the dial palette and bitmaps self.dial_bitmap = displayio.Bitmap( self._width, self._height, 3 ) # 3 colors: background, ticks, tick label text # paint the dial major and minor ticks and labels draw_ticks( # major ticks target_bitmap=self.dial_bitmap, dial_center=self._dial_center, dial_radius=self._dial_radius, tick_count=self._major_ticks, tick_stroke=self._major_tick_stroke, tick_length=self._major_tick_length, start_angle=self._start_angle, sweep_angle=self._sweep_angle, tick_color_index=2, ) draw_ticks( # minor ticks target_bitmap=self.dial_bitmap, dial_center=self._dial_center, dial_radius=self._dial_radius, tick_count=self._minor_ticks * (self._major_ticks - 1) + 1, tick_stroke=self._minor_tick_stroke, tick_length=self._minor_tick_length, start_angle=self._start_angle, sweep_angle=self._sweep_angle, tick_color_index=2, ) draw_labels( target_bitmap=self.dial_bitmap, font=self._tick_label_font, tick_labels=self._major_tick_labels, dial_center=self._dial_center, dial_radius=self._dial_radius, start_angle=self._start_angle, sweep_angle=self._sweep_angle, rotate_labels=self._rotate_tick_labels, font_height=self._font_height, tick_label_scale=self._tick_label_scale, ) # create the dial palette self.dial_palette = displayio.Palette(4) if self._background_color is None: self.dial_palette.make_transparent(0) self.dial_palette[0] = 0x000000 else: self.dial_palette[0] = self._background_color self.dial_palette[1] = self._tick_label_color self.dial_palette[2] = self._tick_color # create the dial tilegrid and append to the self Widget->Group self.dial_tilegrid = displayio.TileGrid( self.dial_bitmap, pixel_shader=self.dial_palette ) self.append(self.dial_tilegrid) # create the label for the display_value if self._display_value: self._value_label = bitmap_label.Label( self._value_font, text="", color=self._value_color, baseline_alignment=True, ) self._value_label.anchor_point = self._label_anchor_point self._value_label.anchored_position = [ round(self._width * self._label_anchor_on_widget[0]), round(self._height * self._label_anchor_on_widget[1]), ] self._update_value() self.append(self._value_label) # create the needle self._create_needle() self.append(self._needle_vector_shape) self._update_needle(self._value)
x=91, y=28) splash.append(large_square) bottom_bitmap = displayio.Bitmap(110, 50, 1) bottom_rectangle = displayio.TileGrid(bottom_bitmap, pixel_shader=color_palette, x=10, y=69) splash.append(bottom_rectangle) # Draw some label text name_text = "Monochrome 1.12in" name_text_area = label.Label(terminalio.FONT, text=name_text, color=0xFFFFFF, x=8, y=8) splash.append(name_text_area) size_text = "128x128" size_text_area = label.Label(terminalio.FONT, text=size_text, color=0xFFFFFF, x=8, y=25) splash.append(size_text_area) oled_text = "OLED" oled_text_area = label.Label(terminalio.FONT, text=oled_text, scale=2, color=0xFFFFFF,
# loading screen loading_group = displayio.Group() # black background, screen size minus side buttons loading_background = displayio.Bitmap((display.width-40)//20, display.height//20, 1) loading_palette = displayio.Palette(1) loading_palette[0] = 0x0 # scaled group to match screen size minus side buttons loading_background_scale_group = displayio.Group(scale=20) loading_background_tilegrid = displayio.TileGrid(loading_background, pixel_shader=loading_palette) loading_background_scale_group.append(loading_background_tilegrid) # loading screen label loading_label = bitmap_label.Label(terminalio.FONT, text="Loading...", scale=3) loading_label.anchor_point = (0.5, 0.5) loading_label.anchored_position = (display.width // 2, display.height // 2) # append background and label to the group loading_group.append(loading_background_scale_group) loading_group.append(loading_label) # GridLayout to hold the icons # size and location can be adjusted to fit # different sized screens. layout = GridLayout( x=20, y=20, width=420, height=290,
import board import terminalio from adafruit_display_text import bitmap_label text = "Hello world" text_area = bitmap_label.Label(terminalio.FONT, text=text) text_area.x = 10 text_area.y = 10 board.DISPLAY.show(text_area) while True: pass
def __init__( self, x=None, y=None, text=None, font=FONT, delta_x=-15, delta_y=-10, widget=None, anchor_point=(0.0, 0.0), anchored_position=None, position_offset=(0, 0), stroke=3, # Not currently implemented in adafruit_display_shapes/line.py line_color=0xFFFFFF, text_color=None, text_offset=(0, -1), text_under=False, ): if widget: if (x is not None) or (y is not None): print("Note: Overriding (x,y) values with widget, anchor_point" " and/or anchored_position") widget_width = widget.bounding_box[2] widget_height = widget.bounding_box[3] if anchor_point is not None: line_x0 = (widget.x + round(widget_width * anchor_point[0]) + position_offset[0]) line_y0 = (widget.y + round(widget_height * anchor_point[1]) + position_offset[1]) elif anchored_position is not None: line_x0 = widget.x + anchored_position[0] + position_offset[0] line_y0 = widget.y + anchored_position[1] + position_offset[1] else: raise ValueError( "Must supply either anchor_point or anchored_position") elif (x is not None) and (y is not None): line_x0 = x line_y0 = y else: raise ValueError( "Must supply either (x,y) or widget and anchor_point or anchored_position" ) line_x1 = line_x0 + delta_x line_y1 = line_y0 + delta_y text_anchor_point = (0.0, 1.0 ) # default: set text anchor to left corner underline_x_multiplier = 1 if delta_x < 0: # line is heading to the left, set text anchor to right corner text_anchor_point = (1.0, 1.0) underline_x_multiplier = -1 if ( text_under ): # if text is under the line, set to text_anchor_point to upper edge text_anchor_point = (text_anchor_point[0], 0.0) if text_color is None: text_color = line_color self._label = bitmap_label.Label( text=text, font=font, color=text_color, anchor_point=text_anchor_point, anchored_position=(line_x1 + text_offset[0], line_y1 + text_offset[1]), ) label_width = self._label.bounding_box[2] line_x2 = line_x1 + label_width * underline_x_multiplier + text_offset[ 0] # lengthen the line if the text is offset line_y2 = line_y1 self._line0 = Line(line_x0, line_y0, line_x1, line_y1, color=line_color) self._line1 = Line(line_x1, line_y1, line_x2, line_y2, color=line_color) super().__init__(max_size=3) # Group elements: # 0. Line0 - from (x,y) to (x+delta_x, y+delta_y) # 1. Line1 - horizontal line for text # 2. Label self.append(self._line0) self.append(self._line1) self.append(self._label)
# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries # SPDX-License-Identifier: MIT """ CircuitPython simple sensor data display demo using LC709203 battery monitor and TFT display """ import time import board import terminalio from displayio import Group from adafruit_display_text import bitmap_label from adafruit_lc709203f import LC709203F text_area = bitmap_label.Label(terminalio.FONT, scale=2) text_area.anchor_point = (0.5, 0.5) text_area.anchored_position = (board.DISPLAY.width // 2, board.DISPLAY.height // 2) main_group = Group() main_group.append(text_area) print("LC709203F test") print("Make sure LiPoly battery is plugged into the board!") sensor = LC709203F(board.I2C()) print("IC version:", hex(sensor.ic_version)) board.DISPLAY.show(main_group) while True: text_area.text = "Battery:\n{:.1f} Volts \n{}%".format(sensor.cell_voltage, sensor.cell_percent)
cell_padding=6, max_size=10, ) _icons = [] _pressed_icons = [] """ for i in range(12): _new_icon = IconWidget("Shortcut {}".format(i), "images/test32_icon.bmp") _icons.append(_new_icon) layout.add_content(_new_icon, grid_position=(i%4, i//4), cell_size=(1, 1)) """ layer_label = bitmap_label.Label(terminalio.FONT) layer_label.anchor_point = (0.5, 0.0) layer_label.anchored_position = (display.width // 2, 4) main_group.append(layer_label) next_layer_btn = Button( x=layout.x + layout._width - 12, y=display.height - 70, width=50, height=70, style=Button.RECT, fill_color=0x00ff99, label="", label_font=terminalio.FONT, label_color=0x000000, )
def __init__( self, display, *, value_list=None, font=FONT, font_scale=1, color=0xFFFFFF, value=0, # initial value, index into the value_list arrow_touch_padding=0, # additional touch padding on the arrow sides of the Widget arrow_color=0x333333, arrow_outline=0x555555, arrow_height=30, arrow_width=30, arrow_gap=5, alt_touch_padding=0, # touch padding on the non-arrow sides of the Widget horizontal=True, animation_time=None, cool_down=0.0, **kwargs, ): super().__init__(**kwargs, max_size=4) # Group elements for the FlipInput. # 0. The text # 1. The group holding the temporary scroll bitmap # 2. Up arrow: Triangle # 3. Down arrow: Triangle # initialize the Control superclass # pylint: disable=bad-super-call super(Control, self).__init__() self.value_list = value_list self._value = value self._color = color self._font = font self._font_scale = font_scale # preload the glyphs self._arrow_touch_padding = arrow_touch_padding self._alt_touch_padding = alt_touch_padding self._horizontal = horizontal self._display = display self._animation_time = animation_time self._cool_down = cool_down self._last_pressed = time.monotonic() self._pressed = False # state variable # Find the maximum bounding box of the text and determine the # baseline (x,y) start point (top, left) left = None right = None top = None bottom = None for this_value in value_list: xposition = 0 for i, character in enumerate(this_value): glyph = self._font.get_glyph(ord(character)) if ( i == 0 ): # if it's the first character in the string, check the left value if left is None: left = glyph.dx else: left = min(left, glyph.dx) if right is None: right = max( xposition + glyph.dx + glyph.width, xposition + glyph.shift_x ) else: right = max( right, xposition + glyph.dx + glyph.width, xposition + glyph.shift_x, ) # match bitmap_label if top is None: top = -(glyph.height + glyph.dy) else: top = min(top, -(glyph.height + glyph.dy)) if bottom is None: bottom = -glyph.dy else: bottom = max(bottom, -glyph.dy) xposition = xposition + glyph.shift_x self._bounding_box = [ 0, 0, (right - left) * self._font_scale, (bottom - top) * self._font_scale, ] # Create the text label self._label = bitmap_label.Label( text=value_list[value], font=self._font, scale=self._font_scale, color=self._color, base_alignment=True, background_tight=True, ) self._label.x = -1 * left * self._font_scale self._label.y = -1 * top * self._font_scale self._left = left self._top = top self.append(self._label) # add the label to the self Group # set the touch_boundary including the touch_padding self._arrow_gap = arrow_gap # of pixel gap above/below label before the arrow if horizontal: # horizontal orientation, add arrow padding to x-dimension and # alt_padding to y-dimension self.touch_boundary = [ self._bounding_box[0] - self._arrow_gap - arrow_height - self._arrow_touch_padding, self._bounding_box[1] - self._alt_touch_padding, self._bounding_box[2] + 2 * (self._arrow_gap + arrow_height + self._arrow_touch_padding), self._bounding_box[3] + 2 * self._alt_touch_padding, ] else: # vertical orientation, add arrow padding to y-dimension and # alt_padding to x-dimension self.touch_boundary = [ self._bounding_box[0] - self._alt_touch_padding, self._bounding_box[1] - self._arrow_gap - arrow_height - self._arrow_touch_padding, self._bounding_box[2] + 2 * self._alt_touch_padding, self._bounding_box[3] + 2 * (self._arrow_gap + arrow_height + self._arrow_touch_padding), ] # create the Up/Down arrows self._update_position() # call Widget superclass function to reposition self._animation_group = displayio.Group( max_size=1, scale=self._font_scale, ) # holds the animation bitmap # self._animation_group.x = -1 * left * (1) # self._animation_group.y = -1 * top * (1) self._animation_group.hidden = True self.append(self._animation_group) # Add the two arrow triangles, if required if (arrow_color is not None) or (arrow_outline is not None): if horizontal: # horizontal orientation, add left and right arrows if ( (arrow_width is not None) and (arrow_height is not None) and (arrow_width > 0) ): mid_point_y = self._bounding_box[1] + self._bounding_box[3] // 2 self.append( Triangle( self._bounding_box[0] - self._arrow_gap, mid_point_y - arrow_height // 2, self._bounding_box[0] - self._arrow_gap, mid_point_y + arrow_height // 2, self._bounding_box[0] - self._arrow_gap - arrow_width, mid_point_y, fill=arrow_color, outline=arrow_outline, ) ) self.append( Triangle( self._bounding_box[0] + self._bounding_box[2] + self._arrow_gap, mid_point_y - arrow_height // 2, self._bounding_box[0] + self._bounding_box[2] + self._arrow_gap, mid_point_y + arrow_height // 2, self._bounding_box[0] + self._bounding_box[2] + self._arrow_gap + arrow_width, mid_point_y, fill=arrow_color, outline=arrow_outline, ) ) else: # vertical orientation, add upper and lower arrows if ( (arrow_height is not None) and (arrow_width is not None) and (arrow_height > 0) ): mid_point_x = self._bounding_box[0] + self._bounding_box[2] // 2 self.append( Triangle( mid_point_x - arrow_width // 2, self._bounding_box[1] - self._arrow_gap, mid_point_x + arrow_width // 2, self._bounding_box[1] - self._arrow_gap, mid_point_x, self._bounding_box[1] - self._arrow_gap - arrow_height, fill=arrow_color, outline=arrow_outline, ) ) self.append( Triangle( mid_point_x - arrow_width // 2, self._bounding_box[1] + self._bounding_box[3] + self._arrow_gap, mid_point_x + arrow_width // 2, self._bounding_box[1] + self._bounding_box[3] + self._arrow_gap, mid_point_x, self._bounding_box[1] + self._bounding_box[3] + self._arrow_gap + arrow_height, fill=arrow_color, outline=arrow_outline, ) )
def __init__(self, display, layout_json): self.json = layout_json if "view_type" not in layout_json: raise MissingTypeError if layout_json["view_type"] != "BitmapLabel": raise IncorrectTypeError( "view_type '{}' does not match Layout Class 'BitmapLabel'". 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)) _font = terminalio.FONT if "font" in layout_json["attributes"]: _font = bitmap_font.load_font( layout_json["attributes"]["text"]) _text = "" if "text" in layout_json["attributes"]: _text = layout_json["attributes"]["text"] _color = 0xFFFFFF if "color" in layout_json["attributes"]: _color = int(layout_json["attributes"]["color"], 16) _background_color = None if "background_color" in layout_json["attributes"]: _background_color = int( layout_json["attributes"]["background_color"], 16) _line_spacing = 1.25 if "line_spacing" in layout_json["attributes"]: _line_spacing = layout_json["attributes"]["line_spacing"] _max_glyphs = None if "max_glyphs" in layout_json["attributes"]: _max_glyphs = int(layout_json["attributes"]["max_glyphs"]) _background_tight = False if "background_tight" in layout_json["attributes"]: _background_tight = int( layout_json["attributes"]["background_tight"]) _padding_top = 0 _padding_right = 0 _padding_left = 0 _padding_bottom = 0 if "padding" in layout_json["attributes"]: _padding_top = int(layout_json["attributes"]["padding"]) _padding_right = int(layout_json["attributes"]["padding"]) _padding_left = int(layout_json["attributes"]["padding"]) _padding_bottom = int(layout_json["attributes"]["padding"]) if "padding_top" in layout_json["attributes"]: _padding_top = int(layout_json["attributes"]["padding_top"]) if "padding_right" in layout_json["attributes"]: _padding_right = int( layout_json["attributes"]["padding_right"]) if "padding_left" in layout_json["attributes"]: _padding_left = int(layout_json["attributes"]["padding_left"]) if "padding_bottom" in layout_json["attributes"]: _padding_bottom = int( layout_json["attributes"]["padding_bottom"]) self._scale = 1 if "scale" in layout_json["attributes"]: self._scale = int(layout_json["attributes"]["scale"]) self.label = label.Label(_font, text=_text, color=_color, max_glyphs=_max_glyphs, background_color=_background_color, line_spacing=_line_spacing, background_tight=_background_tight, padding_bottom=_padding_bottom, padding_left=_padding_left, padding_right=_padding_right, padding_top=_padding_top, scale=self._scale) self.update_position() if "anchor_point" in layout_json["attributes"]: point = layout_json["attributes"]["anchor_point"] self.label.anchor_point = (point[0], point[1]) if "anchored_position" in layout_json["attributes"]: pos = layout_json["attributes"]["anchored_position"] print(self.keyword_compiler(pos[0]), self.keyword_compiler(pos[1])) self.label.anchored_position = (self.keyword_compiler(pos[0]), self.keyword_compiler(pos[1])) self.view = self.label else: #default attributes pass
latched = [False] * 12 # list of the latched states, all off to start last_knob_pos = macropad.encoder # store knob position state # --- Pixel setup --- # macropad.pixels.brightness = 0.1 for i in range(12): macropad.pixels[i] = (keymap[i][0]) main_group = displayio.Group() macropad.display.show(main_group) title = label.Label( y=4, font=terminalio.FONT, color=0x0, text=" -Minecraft Turbopad- ", background_color=0xFFFFFF, ) layout = GridLayout(x=0, y=13, width=128, height=54, grid_size=(3, 4), cell_padding=5) label_text = [ "CREATE", "SURVIV", "SAY", "DAY", "NIGHT",
label2_padding = 10 ##### # Create the "bitmap_label.py" versions of the text labels. gc.collect() bitmap_label_start = gc.mem_free() bmap_label1 = bitmap_label.Label( font=fontToUse, text="bitmap_label", color=0xFFFFFF, background_color=0xFF0000, padding_bottom=0, padding_left=0, padding_right=0, padding_top=0, background_tight=True, line_spacing=1.25, scale=my_scale, anchor_point=(0.0, 0), anchored_position=(10, 60), ) bmap_label2 = bitmap_label.Label( font=fontToUse, text=long_string, color=0x000000, background_color=0xFFFF00, padding_bottom=label2_padding, padding_left=0,
anchored_position=(display.width // 2, display.height // 2), anchor_point=(0.5, 0.5), label_direction="RTL", ) main_group.append(text_initial_specs) display.show(main_group) time.sleep(TIME_PAUSE) main_group.pop() main_group.pop() # Testing creating label with initial position display.show(main_group) time.sleep(TIME_PAUSE) text_area = bitmap_label.Label(terminalio.FONT, text="Circuit Python", max_glyphs=40) main_group.append(text_area) display.show(main_group) time.sleep(TIME_PAUSE) # Testing position setter text_area.x = 10 text_area.y = 10 display.show(main_group) time.sleep(TIME_PAUSE) text_area.text = "Testing initiating without text" try: text_middle = label.Label(terminalio.FONT, max_glyphs=40) except TypeError: print("Fail setting-up label without text") warning_text = label.Label(
display = None if hasattr(board, "DISPLAY"): display = board.DISPLAY else: pass # insert external display init if display: group = displayio.Group() display.show(group) text_area = label.Label( terminalio.FONT, scale=3, color=(255, 255, 255), max_glyphs=50, anchor_point=(0.5, 0.5), anchored_position=( display.width // 2, display.height // 2, ), text="Hello", ) group.append(text_area) while True: now = time.localtime() clock = "{hour:02d}:{min:02d}:{seconds:02d}".format(hour=now.tm_hour, min=now.tm_min, seconds=now.tm_sec) print(clock) if display: text_area.text = clock
text_area_top_middle.anchor_point = (0.0, 0.0) text_area_top_middle.anchored_position = (100, 100) text_area_top_top = label.Label(FONT_TESTS[1], text=TEXT, background_color=TEXT_BACKGROUND_COLOR[1], x=100, y=40, scale=2) text_area_top_top.anchor_point = (0.0, 0.0) text_area_top_top.anchored_position = (100, 40) text_area_mid_bottom = bitmap_label.Label( FONT_TESTS[1], text=TEXT, color=0x4455AA, background_color=TEXT_BACKGROUND_COLOR[1], x=100, y=140, scale=1) text_area_mid_bottom.anchor_point = (0.5, 0.5) text_area_mid_bottom.anchored_position = (100, 140) text_area_mid_bottom2 = label.Label( FONT_TESTS[1], text=TEXT, background_color=TEXT_BACKGROUND_COLOR[1], scale=1, padding_bottom=10, padding_left=18, padding_right=5, padding_top=0,
# Font definition. You can choose any two fonts available in your system MEDIUM_FONT = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf") BIG_FONT = bitmap_font.load_font("fonts/LeagueGothic-Regular-36.bdf") TEXT_RIGHT = "MG" TEXT_LEFT = "32.47" main_group = displayio.Group() # Create labels # Base Alignment parameter False left_text = label.Label( BIG_FONT, text=TEXT_LEFT, color=0xDD00DD, x=10, y=50, base_alignment=False, ) main_group.append(left_text) right_text = label.Label( MEDIUM_FONT, text=TEXT_RIGHT, color=0xDD00DD, x=90, y=50, base_alignment=False, ) main_group.append(right_text)
from rainbowio import colorwheel from adafruit_displayio_layout.layouts.grid_layout import GridLayout from adafruit_display_text import bitmap_label as label from adafruit_macropad import MacroPad from shortcuts import shortcut_keys # Initialise MacroPad macropad = MacroPad() # Setup title and grid main_group = displayio.Group() macropad.display.show(main_group) title = label.Label( y=4, font=terminalio.FONT, color=0x0, text=" SHORTCUTS ", background_color=0xFFFFFF, ) layout = GridLayout(x=0, y=10, width=128, height=54, grid_size=(3, 4), cell_padding=5) # Extract data from shortcuts key_sounds = [sound[0] for sound in shortcut_keys["macros"]] label_names = [names[1] for names in shortcut_keys["macros"]] keys = [keys[3] for keys in shortcut_keys["macros"]]
def format_time(seconds): minutes = seconds // 60 seconds = int(seconds) % 60 return "{:02d}:{:02d}".format(minutes, seconds, width=2) timediff = 0 oven = ReflowOvenControl(board.D4) print("melting point: ", oven.sprofile["melting_point"]) font1 = bitmap_font.load_font("/fonts/OpenSans-9.bdf") font2 = bitmap_font.load_font("/fonts/OpenSans-12.bdf") font3 = bitmap_font.load_font("/fonts/OpenSans-16.bdf") label_reflow = label.Label(font1, text="", color=0xFFFFFF, line_spacing=0) label_reflow.x = 0 label_reflow.y = -20 display_group.append(label_reflow) title_label = label.Label(font3, text=TITLE) title_label.x = 5 title_label.y = 14 display_group.append(title_label) # version_label = label.Label(font1, text=VERSION, color=0xAAAAAA) # version_label.x = 300 # version_label.y = 40 # display_group.append(version_label) message = label.Label(font2, text="Wait") message.x = 100 message.y = 40 display_group.append(message)
def _draw_ticks(self) -> None: # ticks definition ticks = [10, 30, 50, 70, 90] subticks = [20, 40, 60, 80, 100] # X axes ticks for i in range(10, 100, 10): text_tick = str(round(self._xrange[0]) + round(i * self._normx)) text_dist = int(self._valuex * i) if i in ticks: shift_label_x = len(text_tick) * self._font_width tick_text = bitmap_label.Label( self._font, color=self._font_color, text=text_tick, x=text_dist - (shift_label_x // 2), y=self.height + self._axes_line_thickness + self._tick_line_height + self._font_height // 2 + 1, ) self.append(tick_text) rectangle_helper( text_dist, self._axes_line_thickness, self._tick_line_height, self._tick_line_thickness, self._axesx_bitmap, 1, self._screen_palette, True, ) if self._subticks: if i in subticks: rectangle_helper( text_dist, self._axes_line_thickness, self._tick_line_height // 2, 1, self._axesx_bitmap, 1, self._screen_palette, True, ) # Y axes ticks for i in range(10, 100, 10): text_tick = str(round(self._yrange[0]) + round(i * self._normy)) text_dist = int(self._valuey * i) if i in ticks: shift_label_x = len(text_tick) * self._font_width tick_text = bitmap_label.Label( self._font, color=self._font_color, text=text_tick, x=-shift_label_x - self._axes_line_thickness - self._tick_line_height - 2, y=0 + self.height - text_dist, ) self.append(tick_text) rectangle_helper( self._axesy_width - self._axes_line_thickness - self._tick_line_height - 1, text_dist, self._tick_line_thickness, self._tick_line_height, self._axesy_bitmap, 1, self._screen_palette, True, ) if self._subticks: if i in subticks: rectangle_helper( self._axesy_width - self._axes_line_thickness - self._tick_line_height // 2 - 1, text_dist, 1, self._tick_line_height // 2, self._axesy_bitmap, 1, self._screen_palette, True, )