Пример #1
0
    def __init__(self):
        self.display = InkyPHAT("black")
        self.display.set_border(self.display.WHITE)
        self.font = ImageFont.truetype('resources/Eden_Mills_Bold.ttf', 12)
        self.lock = threading.Lock()

        self.startup()
Пример #2
0
    def __init__(self):
        self.debug = False
        self.display = None
        self.current = None
        self.last = None
        self.last_load = None
        self.bg = None
        self.noaa = None
        self.darksky = None
        self.btn_down = False

        if args.debug is 'true' or args.debug is 'True':
            self.debug = True

        if pzwglobals.RUN_ON_RASPBERRY_PI:
            self.display = InkyPHAT("yellow")
            self.display.set_border(WHITE)

        self.screens = {
            'current_weather':
            CurrentWeather('current_weather',
                           debug=self.debug,
                           display=self.display),
            'forecast_days':
            ForecastDays('forecast_days',
                         debug=self.debug,
                         display=self.display)
        }
Пример #3
0
 def __init__(self, rotation=180):
     self.inky_display = InkyPHAT("red")
     self.inky_display.set_border(self.inky_display.BLACK)
     self.WIDTH = self.inky_display.WIDTH
     self.HEIGHT = self.inky_display.HEIGHT
     self.WHITE = self.inky_display.WHITE
     self.RED = self.inky_display.RED
     self.BLACK = self.inky_display.BLACK
     self.rotation = 180
Пример #4
0
    def __init__(self,
                 color="red",
                 font_type=FredokaOne,
                 font_size=20,
                 more_text_postfix="..."):
        self.inkyphat = InkyPHAT(color)
        self.color = self.__get_inky_color(color)

        self.more_text_postfix = more_text_postfix
        self.img = Image.new("P", (self.inkyphat.WIDTH, self.inkyphat.HEIGHT))
        self.font = ImageFont.truetype(font_type, font_size)
Пример #5
0
    def __init__(self):
        # Start by loading the word list
        with open('longwords.txt', 'r') as f:
            self.word_list = f.read().splitlines()

        self.d = InkyPHAT("red")
        self.d.set_border(self.d.RED)

        self.d.h_flip = True
        self.d.v_flip = True

        self.font = ImageFont.load("font.pil")
Пример #6
0
 def __init__(self, display_resources, sensors, weather_info, moon_info):
     self.__logger = logging.getLogger(self.__class__.__name__)
     self.__resources = display_resources
     self.__sensors = sensors
     self.__weather_info = weather_info
     self.__moon_info = moon_info
     self.__display = InkyPHAT('yellow')
     self.__display.set_border(InkyPHAT.BLACK)
     self.__screen_image = Image.open(self.__resources['background'])
     self.__digit_fonts = {}
     for name, font in self.__resources['digit-fonts'].items():
         self.__digit_fonts[name] = Font(font)
     self.__labels = {}
     for name, label in self.__resources['labels'].items():
         self.__labels[name] = Font(label)
     self.__weather_icons_day = {}
     self.__weather_icons_night = {}
     for _, icon in self.__resources['weather-icons'].items():
         day = Icon(icon['day'])
         night = Icon(icon['night'])
         for code in icon['codes']:
             self.__weather_icons_day[code] = day
             self.__weather_icons_night[code] = night
     self.__moon_icons = {}
     for name, icon in self.__resources['moon-icons'].items():
         self.__moon_icons[name] = Icon(icon)
     self.__power_icons = {}
     for name, icon in self.__resources['power-icons'].items():
         self.__power_icons[name] = Icon(icon)
     self.__old_temperature = None
     self.__old_humidity = None
     self.__old_pressure = None
     self.__old_date = None
     self.__old_sunset_time = None
     self.__old_sunrise_time = None
     self.__old_today_forecast = None
     self.__old_tomorrow_forecast = None
     self.__old_is_daytime = None
     self.__old_next_moon_phase = None
     self.__old_next_moon_phase_date = None
     self.__old_uv_index = None
     #initialize gpio ofr power monitoring
     self.__main_line = gpiozero.Button(pin=5, pull_up=False)
     self.__main_line.when_activated = self.__on_power_state_changed
     self.__main_line.when_deactivated = self.__on_power_state_changed
     self.__battery_low = gpiozero.Button(pin=6, pull_up=False)
     self.__battery_low.when_activated = self.__on_power_state_changed
     self.__battery_low.when_deactivated = self.__on_power_state_changed
     #set default power icon icon (battery low)
     self.__power_state = None
     self.__on_power_state_changed()
Пример #7
0
def displayInky(output):
    from PIL import Image, ImageFont, ImageDraw
    from inky import InkyPHAT

    inky_display = InkyPHAT("red")
    inky_display.set_border(inky_display.RED)

    img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
    draw = ImageDraw.Draw(img)

    headerSize = 12
    headerFont = ImageFont.truetype(
        "/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf",
        headerSize)
    messageFont = ImageFont.truetype(
        "/usr/share/fonts/truetype/liberation2/LiberationMono-Regular.ttf",
        int(75 / (output['bodyLines'])))

    x = 0
    y = 0
    draw.text((x, y), output['header'] + ' - ' + output['subHeader'],
              inky_display.RED, headerFont)
    draw.text((x, y + headerSize), output['body'], inky_display.BLACK,
              messageFont)
    inky_display.set_image(img)
    inky_display.show()
Пример #8
0
def initialiseDisplay():
    """

    Basic setup of display

    Inputs: None
    Return Values: None
    Global Objects Created: inkyDisplay (instance of inkyPHAT)

    """
    global inkyDisplay
    inkyDisplay = InkyPHAT(deviceColour)
    # I think we do this here.
    inkyDisplay.set_border(inkyDisplay.WHITE)
    inkyDisplay.set_border(inkyDisplay.BLACK)
Пример #9
0
    def _init_display(self):
        if self._is_inky():
            from inky import InkyPHAT
            self._display = InkyPHAT(self._display_color)
            self._display.set_border(InkyPHAT.BLACK)
            self._render_cb = self._inky_render
        elif self._is_waveshare1():
            from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
            # core.log("display module started")
            self._display = EPD()
            self._display.init(self._display.lut_full_update)
            self._display.Clear(0xFF)
            self._display.init(self._display.lut_partial_update)
            self._render_cb = self._waveshare_render
        elif self._is_waveshare2():
            from pwnagotchi.ui.waveshare.v2.waveshare import EPD
            # core.log("display module started")
            self._display = EPD()
            self._display.init(self._display.FULL_UPDATE)
            self._display.Clear(WHITE)
            self._display.init(self._display.PART_UPDATE)
            self._render_cb = self._waveshare_render
        else:
            core.log("unknown display type %s" % self._display_type)

        self.on_render(self._on_view_rendered)

        core.log("display type '%s' initialized (color:%s)" % (self._display_type, self._display_color))
Пример #10
0
    def initialize(self):
        logging.info("initializing inky display")

        if self.config['color'] == 'fastAndFurious':
            logging.info("Initializing Inky in 2-color FAST MODE")
            logging.info(
                "THIS MAY BE POTENTIALLY DANGEROUS. NO WARRANTY IS PROVIDED")
            logging.info("USE THIS DISPLAY IN THIS MODE AT YOUR OWN RISK")

            from pwnagotchi.ui.hw.libs.inkyphat.inkyphatfast import InkyPHATFast
            self._display = InkyPHATFast('black')
            self._display.set_border(InkyPHATFast.BLACK)
        else:
            from inky import InkyPHAT
            self._display = InkyPHAT(self.config['color'])
            self._display.set_border(InkyPHAT.BLACK)
Пример #11
0
def test_init_phat_black():
    """Test initialisation of InkyPHAT with 'black' colour choice."""
    mockery()

    from inky import InkyPHAT

    InkyPHAT('black')
Пример #12
0
def test_init_phat_yellow():
    """Test initialisation of InkyPHAT with 'yellow' colour choice."""
    mockery()

    from inky import InkyPHAT

    InkyPHAT('red')
Пример #13
0
def main():
    """Get desk status from API."""
    parser = argparse.ArgumentParser()
    parser.add_argument("--desk-id",
                        "-i",
                        type=str,
                        required=True,
                        help="Desk unique identifier")
    parser.add_argument(
        "--url",
        "-u",
        type=str,
        default="http://127.0.0.1:5000",
        help="URL of the REST API, from where statuses are obtained")

    clargs = parser.parse_args()

    inky_display = InkyPHAT(COLOUR)

    status = requests.get("/".join([clargs.url, clargs.desk_id])).json()

    update_display(inky_display,
                   status["status"],
                   clargs.desk_id,
                   name=status["name"],
                   until=status["until"])
Пример #14
0
def main():
    """Set desk status 'offline'."""
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--status",
        "-s",
        type=str,
        required=True,
        choices=["taken", "free"],
        help="The status of the desk, either 'taken' or 'free'")
    parser.add_argument(
        "--desk-id",
        "-i",
        type=str,
        required=True,
        help="A unique identifier for the desk (used for booking)")
    parser.add_argument(
        "--name",
        "-n",
        type=str,
        required=False,
        help="The name of the person who has reserved the desk")
    parser.add_argument("--until",
                        "-u",
                        type=str,
                        required=False,
                        help="The time when a desk is free until")

    clargs = parser.parse_args()

    inky_display = InkyPHAT(COLOUR)

    update_display(inky_display, clargs.status, clargs.desk_id, clargs.name,
                   clargs.until)
Пример #15
0
def hype(word):
	print(word)

	# Set up the correct display and scaling factors
	inky_display = InkyPHAT('black')
	inky_display.set_border(inky_display.BLACK)
	# inky_display.set_rotation(180)

	w = inky_display.WIDTH
	h = inky_display.HEIGHT

	# Create a new canvas to draw on
	img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
	draw = ImageDraw.Draw(img)

	# Load the fonts
	font_size = 88
	from fonts.ttf import AmaticSC, FredokaOne

	#font = ImageFont.truetype(SourceSansProSemibold, font_size)
	font = ImageFont.truetype(AmaticSC, font_size)
	#font = ImageFont.truetype(FredokaOne, font_size)

	padding = 20 
	max_width = w - padding
	max_height = h - padding

	below_max_length = False
	while not below_max_length:
			p_w, p_h = font.getsize(word)  # Width and height of quote
			#p_h = p_h * (word.count("\n") + 1)   # Multiply through by number of lines

			if p_h < max_height and p_w < max_width:
					below_max_length = True              # The quote fits! Break out of the loop.

			else:
					font_size = font_size - 2
					#font = ImageFont.truetype(SourceSansProSemibold, font_size)
					font = ImageFont.truetype(AmaticSC, font_size)
					#font = ImageFont.truetype(FredokaOne, font_size)

					continue

	# x- and y-coordinates for the top left of the quote
	#word_x = (w - max_width) / 2
	#word_x = (max_width - p_w) / 2
	#word_y = (max_height - p_h) / 2
	word_x = (w - max_width) / 2
	#word_y = ((h - max_height) + (max_height - p_h - font.getsize("ABCD ")[1])) / 2
	word_y = (h - p_h) / 2

	draw.multiline_text((word_x, word_y), word, fill=inky_display.BLACK, font=font, align="left")
	draw.line((169, 58, 169, 58), 2)

	# Display the completed canvas on Inky wHAT
	inky_display.set_image(img)
	inky_display.show()
Пример #16
0
class RenderQueue():
    def __init__(self):
        self.img_stack = []
        self.inky_display = InkyPHAT("black")
        pub.subscribe(self.add_image, 'add_image')

    def add_image(self, img):
        self.img_stack.append(img)

    def run(self):
        while True:
            if len(self.img_stack) > 0:
                most_recent_frame = self.img_stack.pop()
                self.img_stack = []
                self.inky_display.set_image(most_recent_frame)
                self.inky_display.show()
            time.sleep(0.1)
Пример #17
0
def main():
    inky_display = InkyPHAT("black")
    inky_display.set_border(inky_display.WHITE)

    config = importconfig()

    if config['showtime'] == "True":
        showtime = True
    else:
        showtime = False


#Need to work out the config mode
    if len(config["stops"]) > 1:
        multistops(config, showtime, inky_display)
    else:
        stops = config["stops"][0]
        singlestop(stops, showtime, inky_display)
Пример #18
0
    def draw_to_display():
        # Set up properties of eInk display
        inky_display = InkyPHAT("red")
        inky_display.set_border(inky_display.BLACK)

        # Load previously generated image
        img = draw_semester_display()

        # Display generated semester progress image
        inky_display.set_image(img)
        inky_display.show()
Пример #19
0
class MagicBoxScreen():
    def __init__(self):
        self._inky = InkyPHAT("black")
        self._font = ImageFont.truetype(FredokaOne, 16)

    def displayMessage(self, message: str="No Message"):
        w, h = self._font.getsize(message)
        x = (self._inky.WIDTH / 2) - (w / 2)
        y = (self._inky.HEIGHT / 2) - (h / 2)
        img = Image.new("P", (self._inky.WIDTH, self._inky.HEIGHT))
        draw = ImageDraw.Draw(img)
        draw.text((x, y), message, self._inky.BLACK, self._font)
        self._inky.set_image(img)
        self._inky.show()

    def displayQuestion(self, \
        questionText: str="What is the speed of light?", \
        answerText: List[str] = \
        ['0 m/s', '100 m/s', '1 km/s', '3,000 km/s', '300,000 km/s']):
Пример #20
0
def presentOnInkyScreen(image):
    logging.info("Loading View onto Inky Phat.")
    from inky import InkyPHAT

    #Test invert image.
    image = image.convert('L')
    image = ImageOps.invert(image)
    image = image.convert('1')

    # Set up the display
    inky_display = InkyPHAT("black")
    #inky_display.set_border(inky_display.BLACK)
    inky_display.v_flip = True
    inky_display.h_flip = True

    # Display
    inky_display.set_border("black")
    inky_display.set_image(image)
    inky_display.show()
    logging.info("View Sent to Device Successfully")
Пример #21
0
def run():

    inky_display = InkyPHAT(COLOR)

    # inky_display.set_rotation(180)
    inky_display.set_border(InkyPHAT.RED)

    img = Image.new("P", (InkyPHAT.WIDTH, InkyPHAT.HEIGHT))
    palletize(img)
    image_draw = ImageDraw.Draw(img)

    if DEBUG:
        # Draw vertical line
        for y in xrange(InkyPHAT.HEIGHT):
            img.putpixel((InkyPHAT.WIDTH / 2, y), inky_display.RED)
            img.putpixel((InkyPHAT.WIDTH / 4, y), inky_display.RED)

        # Draw horizontal line
        for x in xrange(InkyPHAT.WIDTH):
            img.putpixel((x, InkyPHAT.HEIGHT / 2), inky_display.RED)

    weather = Weather(location_coords)

    if weather.is_same_as_temp_data():
        if DEBUG:
            print("Not updating the display since the forecast is the same as last time")
        weather.save_temp_forecast(only_if_no_such_file=True)
        return
    else:
        if DEBUG:
            print("Updating display since the forecast has changed since the last render")
        weather.save_temp_forecast()

    draw_text(image_draw, 2, "UV",                        "l")
    draw_text(image_draw, 2, weather.uv_index,            "r",
              color=InkyPHAT.RED if weather.is_uv_warning() else InkyPHAT.BLACK)
    draw_text(image_draw, 1, get_high_temp_copy(weather), "c")
    draw_text(image_draw, 4, get_low_temp_copy(weather),  "c")

    if weather.precipitation_is_likely():
        precip_chance_str = str(int(round(weather.current_precip_probability * 100))) + "%"
        draw_text(image_draw, 3, get_sky_icon(weather), "l", is_icon=True)
        draw_text(image_draw, 3, precip_chance_str,     "r", is_icon=False)
    else:
        draw_text(image_draw, 3, get_sky_icon(weather), "c", is_icon=True)

    inky_display.set_image(img)
    inky_display.show()

    if DEBUG:
        print(weather.eink_data_string())
Пример #22
0
def updateeink(issdetails, mapdot, trail):
    """update location text and map to the e-ink screen"""
    issx = int(mapdot[0])
    issy = int(mapdot[1])
    inky_display = InkyPHAT("yellow")

    palette = [255, 255, 255, 0, 0, 0, 255, 0, 0]

    font10 = ImageFont.truetype('/home/pi/isstracker/FreeSans.ttf', 10)
    font14 = ImageFont.truetype('/home/pi/isstracker/FreeSans.ttf', 14)
    font16 = ImageFont.truetype('/home/pi/isstracker/FreeSans.ttf', 16)
    font18 = ImageFont.truetype('/home/pi/isstracker/FreeSans.ttf', 18)

    im = Image.open('/home/pi/isstracker/small-world-map.png')
    d = ImageDraw.ImageDraw(im)

    taille_pt = 3
    isspos = (int(mapdot[0]) - taille_pt, int(mapdot[1]) - taille_pt,
              int(mapdot[0]) + taille_pt, int(mapdot[1]) + taille_pt)
    d.ellipse(isspos, fill=2)
    for item in point2ellipse(trail, 1):
        d.ellipse(item, fill=2)

    d.text((3, 80),
           'à ' + str(round(issdetails[2])) + ' Km de ' + issdetails[1] +
           ' (' + issdetails[0] + ')',
           font=font18,
           fill=2)

    from uptime import uptime
    uptime = round(uptime() / 60, 1)
    d.text((0, 70), "ut : " + str(uptime) + " min", font=font10, fill=1)

    inky_display.set_image(im)
    inky_display.show()
Пример #23
0
class InkyDriver:
    def __init__(self):
        self.inky = InkyPHAT('yellow')

    def create_new_image(self, countries_cases):
        current_height = 0
        # inky_display.set_rotation(180)
        self.inky.set_border(self.inky.RED)

        # Create a new canvas to draw on
        img = Image.new("P", (self.inky.WIDTH, self.inky.HEIGHT))
        draw = ImageDraw.Draw(img)

        # Load the fonts
        font = ImageFont.truetype(HankenGroteskBold, 20)

        # Calculate the positioning and draw the text
        for countryCases in countries_cases:
            text = str(countryCases[0]) + ": " + str(countryCases[1])
            width, height = font.getsize(text)
            center = int((self.inky.WIDTH - width) / 2)
            draw.text((center, current_height),
                      text,
                      self.inky.BLACK,
                      font=font)
            current_height += height

        # Display the completed picture
        self.inky.set_image(img)
        self.inky.show()
Пример #24
0
    def _init_display(self):
        if self._is_inky():
            logging.info("initializing inky display")
            from inky import InkyPHAT
            self._display = InkyPHAT(self._display_color)
            self._display.set_border(InkyPHAT.BLACK)
            self._render_cb = self._inky_render

        elif self._is_papirus():
            logging.info("initializing papirus display")
            from pwnagotchi.ui.papirus.epd import EPD
            os.environ['EPD_SIZE'] = '2.0'
            self._display = EPD()
            self._display.clear()
            self._render_cb = self._papirus_render

        elif self._is_waveshare_v1():
            if self._display_color == 'black':
                logging.info(
                    "initializing waveshare v1 display in monochromatic mode")
                from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
                self._display = EPD()
                self._display.init(self._display.lut_full_update)
                self._display.Clear(0xFF)
                self._display.init(self._display.lut_partial_update)
                self._render_cb = self._waveshare_render

            else:
                logging.info("initializing waveshare v1 display 3-color mode")
                from pwnagotchi.ui.waveshare.v1.epd2in13bc import EPD
                self._display = EPD()
                self._display.init()
                self._display.Clear()
                self._render_cb = self._waveshare_bc_render

        elif self._is_waveshare_v2():
            logging.info("initializing waveshare v2 display")
            from pwnagotchi.ui.waveshare.v2.waveshare import EPD
            self._display = EPD()
            self._display.init(self._display.FULL_UPDATE)
            self._display.Clear(WHITE)
            self._display.init(self._display.PART_UPDATE)
            self._render_cb = self._waveshare_render

        else:
            logging.critical("unknown display type %s" % self._display_type)

        plugins.on('display_setup', self._display)

        self.on_render(self._on_view_rendered)
Пример #25
0
    def __init__(self, font):
        """
        Constructor
        """
        self.__font = font

        self.__device = InkyPHAT(self.COLOUR)

        self.__image = Image.new("P",
                                 (self.__device.WIDTH, self.__device.HEIGHT))
        self.__drawing = ImageDraw.Draw(self.__image)

        m_width, m_height = self.__font.getsize("M")

        self.__text_width = self.__device.WIDTH // m_width
        self.__text_height = self.__device.HEIGHT // m_height + 1

        self.__stop = None
        self.__render_timeout = Timeout(self.DRAW_TIME)

        # self.__spi = SPI(self.__SPI_BUS, self.__SPI_DEVICE, None, None)
        self.__spi = SPI(self.__SPI_BUS, self.__SPI_DEVICE, self.__SPI_MODE,
                         self.__SPI_CLOCK)
Пример #26
0
def draw_display_message(text: str):
    # Set up properties of eInk display
    inky_display = InkyPHAT("red")
    inky_display.set_border(inky_display.BLACK)

    hanked_medium = ImageFont.truetype(HankenGroteskMedium, 20)

    img = Image.new("P", size=(InkyPHAT.WIDTH, InkyPHAT.HEIGHT))
    draw = ImageDraw.Draw(img)

    text_w, text_h = hanked_medium.getsize(text)
    text_x = (InkyPHAT.WIDTH - text_w) // 2
    text_y = (InkyPHAT.HEIGHT - text_h) // 2
    draw.text((text_x, text_y), text, InkyPHAT.BLACK, font=hanked_medium)

    inky_display.set_image(img)
    inky_display.show()
Пример #27
0
def refreshDisplay(intervall, priority, scheduler):

    logging.info("Refresh Display - start")

    lastValue = readLastValue()
    avgMonth = readAvgFromDays(31)
    avgYear = readAvgFromDays(365)

    inkyDisplay = InkyPHAT(colour)
    inkyDisplay.set_border(inkyDisplay.BLACK)

    # Load our background image
    img = Image.open("/var/local/cellarsense/cellarsense-background.png")
    draw = ImageDraw.Draw(img)

    mainHeaderFont = ImageFont.truetype("FreeMonoBold.ttf", 20)
    mainFont = ImageFont.truetype("FreeMono.ttf", 20)
    medianFont = ImageFont.truetype("FreeMono.ttf", 15)

    lastValuePrint = "{:4.1f}°C {:4.1f}%".format(lastValue["temperature"],
                                                 lastValue["humidity"])
    avgMonthPrint = "øm {:4.1f}°C {:4.1f}%".format(avgMonth["temperature"],
                                                   avgMonth["humidity"])
    avgYearPrint = "øa {:4.1f}°C {:4.1f}%".format(avgYear["temperature"],
                                                  avgYear["humidity"])

    logging.debug("Refresh Display - %s", lastValuePrint)
    logging.debug("Refresh Display - %s", avgMonthPrint)
    logging.debug("Refresh Display - %s", avgYearPrint)

    draw.text((5, 5),
              "CellarSense",
              fill=inkyDisplay.BLACK,
              font=mainHeaderFont)
    draw.text((20, 35), lastValuePrint, fill=inkyDisplay.BLACK, font=mainFont)
    draw.text((10, 70), avgMonthPrint, fill=inkyDisplay.BLACK, font=medianFont)
    draw.text((10, 85), avgYearPrint, fill=inkyDisplay.BLACK, font=medianFont)

    inkyDisplay.set_image(img)
    inkyDisplay.show()

    logging.info("Refresh Display - done")

    # reschedule
    scheduler.enter(intervall, priority, refreshDisplay,
                    (intervall, priority, scheduler))
Пример #28
0
 def _init_display(self, color: str, mock=False, display_type='phat'):
     if mock:
         from inky import InkyMockPHAT as InkyPHAT
         from inky import InkyMockWHAT as InkyWHAT
     else:
         from inky import InkyPHAT
         from inky import InkyWHAT
     if display_type == 'phat':
         self._display = InkyPHAT(color)
         self._scale_size = 1.0
         self._padding = 2
     elif display_type == 'what':
         self._display = InkyWHAT(color)
         self._scale_size = 2.20
         self._padding = 15
     self._display.set_border(self._display.BLACK)
Пример #29
0
def my_draw(message):
  inky_display = InkyPHAT("black")
  inky_display.set_border(inky_display.WHITE)

  img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
  draw = ImageDraw.Draw(img)

  font = ImageFont.truetype(FredokaOne, 30)

  w, h = font.getsize(message)
  #x = (inky_display.WIDTH / 2) - (w / 2)
  #y = (inky_display.HEIGHT / 2) - (h / 2)
  x = 1
  y = 1
      
  draw.text((x, y), message, inky_display.BLACK, font)
  inky_display.set_image(img)
  inky_display.show()
Пример #30
0
def print_text(text):
    """Displays text in Inky pHAT display.

    Args:
        text: String that is displayed on the Inky pHAT
    """
    inky_display = InkyPHAT("black")
    inky_display.set_border(inky_display.WHITE)
    img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
    draw = ImageDraw.Draw(img)
    font = ImageFont.truetype(FredokaOne, 30)
    message = text
    width, height = font.getsize(message)
    x_axis = (inky_display.WIDTH / 2) - (width / 2)
    y_axis = (inky_display.HEIGHT / 2) - (height / 2)
    draw.text((x_axis, y_axis), message, inky_display.BLACK, font)
    inky_display.set_image(img)
    inky_display.show()