PiSupply / PaPiRus

Resources for PaPiRus ePaper eInk displays
https://www.pi-supply.com/product/papirus-epaper-eink-screen-hat-for-raspberry-pi/
Other
346 stars 88 forks source link

make Composite screen with image and text #104

Closed PeuX closed 7 years ago

PeuX commented 7 years ago

this is an extended TextPos to create composite screen with image and text.

PapirusComposite exemple

shawaj commented 7 years ago

Thanks for this. Do you have any description of how it works so that we can add it to the readme?

shawaj commented 7 years ago

What does the change on line 23 of textpos.py do?

PeuX commented 7 years ago

the change on textPos allow Composite to extend textPos

Composite extend TextPos, so all textPos method are available (for text).

(sorry for my english,... )

shawaj commented 7 years ago

So how would you use composite.py? And how would you use textpos.py now?

Can you provide some specific examples to help us with testing?

Thanks

PeuX commented 7 years ago

here some code i use : i use an externalised composite and textPos (they are in my project folder )

import forecastio
import time
from datetime import datetime
import numpy as np
import colorsys
import sys
from composite import Composite

class HourSet():
    def __init__(self, tmax,tmin,t,p,icon):
        self.tmax = tmax
        self.tmin = tmin
        self.t = t
        self.p = p
        self.icon = icon

api_key = "SOME_API_KEY_FROM_darksky.net"
lat = 47.34638
lng = 0.45873

wait = 1800

screen = Composite(False)
hour = dict()
hour[4] = HourSet(0,0,0,0,'clear')
hour[8] = HourSet(0,0,0,0,'clear')
hour[12] = HourSet(0,0,0,0,'clear')

screen.AddImage('./icons/'+hour[4].icon+'.bmp',0, 0,(50,50),'i'+str(4))
text4 = "Maintenant\n T:"+str(hour[4].t)+" \ P:"+str(hour[4].p)+"%"
screen.AddText(text4,50,0,20,'t'+str(4))

screen.AddImage('./icons/'+hour[8].icon+'.bmp',0, 60,(50,50),'i'+str(8))
text8 = "+6h\n T:"+str(hour[8].t)+" \ P:"+str(hour[8].p)+"%"
screen.AddText(text8,50,60,20,'t'+str(8))

screen.AddImage('./icons/'+hour[12].icon+'.bmp',0, 120,(50,50),'i'+str(12))
text12 = "+10h\n T:"+str(hour[12].t)+" \ P:"+str(hour[12].p)+"%"
screen.AddText(text12,50,120,20,'t'+str(12))

while True:
    try:
        temp = np.array([])
        rain = 0
        forecast = forecastio.load_forecast(api_key, lat, lng)
        byHour = forecast.hourly()

        compteurHour = 0
        icon = byHour.data[0].icon
        for hourlyData in byHour.data[:12]:
            if(hourlyData.precipProbability > rain):
                icon = hourlyData.icon
                rain = round(hourlyData.precipProbability*100)
            # rain.append(hourlyData.precipProbability)
            temp = np.append(temp, hourlyData.temperature)
            compteurHour = compteurHour + 1
            if(compteurHour % 4 == 0):
                hour[compteurHour].t = round(np.median(temp),1)
                hour[compteurHour].tmax = tMax = round(temp.max(),1)
                hour[compteurHour].tmin = tMax = round(temp.min(),1)
                hour[compteurHour].p = rain
                hour[compteurHour].icon = icon
                temp = np.array([])
                rain = 0

        screen.UpdateImg('i'+str(4),'./icons/'+hour[4].icon+'.bmp')
        text4 = "Maintenant\n T:"+str(hour[4].t)+" \ P:"+str(hour[4].p)+"%"
        screen.UpdateText('t'+str(4),text4)

        screen.UpdateImg('i'+str(8),'./icons/'+hour[8].icon+'.bmp')
        text8 = "+6h\n T:"+str(hour[8].t)+" \ P:"+str(hour[8].p)+"%"
        screen.UpdateText('t'+str(8),text8)

        screen.UpdateImg('i'+str(12),'./icons/'+hour[12].icon+'.bmp')
        text12 = "+10h\n T:"+str(hour[12].t)+" \ P:"+str(hour[12].p)+"%"
        screen.UpdateText('t'+str(12),text12)

        screen.WriteAll()
        time.sleep(wait)
    except KeyboardInterrupt:
        screen.Clear();
        sys.exit(-1)
shawaj commented 7 years ago

Ok thanks we will take a look at this in more detail next week.

Still struggling to see how it would be used exactly to say write an image stored at /user/image.png and overlay that with the text "hello world"

Perhaps providing a more generic example lone that would help?

Can it be used from the command line at all?

Perhaps there could be a good way to combine papirus-write and papirus-draw into one command later on.

On 1 Apr 2017 3:14 pm, "PeuX" notifications@github.com wrote:

here some code i use : i use an externalised composite and textPos (they are in my project folder )

import forecastioimport timefrom datetime import datetimeimport numpy as npimport colorsysimport sysfrom composite import Composite class HourSet(): def init(self, tmax,tmin,t,p,icon): self.tmax = tmax self.tmin = tmin self.t = t self.p = p self.icon = icon

api_key = "SOME_API_KEY_FROM_darksky.net" lat = 47.34638 lng = 0.45873

wait = 1800

screen = Composite(False) hour = dict() hour[4] = HourSet(0,0,0,0,'clear') hour[8] = HourSet(0,0,0,0,'clear') hour[12] = HourSet(0,0,0,0,'clear')

screen.AddImage('./icons/'+hour[4].icon+'.bmp',0, 0,(50,50),'i'+str(4)) text4 = "Maintenant\n T:"+str(hour[4].t)+" \ P:"+str(hour[4].p)+"%" screen.AddText(text4,50,0,20,'t'+str(4))

screen.AddImage('./icons/'+hour[8].icon+'.bmp',0, 60,(50,50),'i'+str(8)) text8 = "+6h\n T:"+str(hour[8].t)+" \ P:"+str(hour[8].p)+"%" screen.AddText(text8,50,60,20,'t'+str(8))

screen.AddImage('./icons/'+hour[12].icon+'.bmp',0, 120,(50,50),'i'+str(12)) text12 = "+10h\n T:"+str(hour[12].t)+" \ P:"+str(hour[12].p)+"%" screen.AddText(text12,50,120,20,'t'+str(12))

while True: try: temp = np.array([]) rain = 0 forecast = forecastio.load_forecast(api_key, lat, lng) byHour = forecast.hourly()

    compteurHour = 0
    icon = byHour.data[0].icon
    for hourlyData in byHour.data[:12]:
        if(hourlyData.precipProbability > rain):
          icon = hourlyData.icon
            rain = round(hourlyData.precipProbability*100)
        # rain.append(hourlyData.precipProbability)
        temp = np.append(temp, hourlyData.temperature)
        compteurHour = compteurHour + 1
        if(compteurHour % 4 == 0):
            hour[compteurHour].t = round(np.median(temp),1)
            hour[compteurHour].tmax = tMax = round(temp.max(),1)
            hour[compteurHour].tmin = tMax = round(temp.min(),1)
            hour[compteurHour].p = rain
            hour[compteurHour].icon = icon
            temp = np.array([])
            rain = 0

    screen.UpdateImg('i'+str(4),'./icons/'+hour[4].icon+'.bmp')
    text4 = "Maintenant\n T:"+str(hour[4].t)+" \ P:"+str(hour[4].p)+"%"
    screen.UpdateText('t'+str(4),text4)

    screen.UpdateImg('i'+str(8),'./icons/'+hour[8].icon+'.bmp')
    text8 = "+6h\n T:"+str(hour[8].t)+" \ P:"+str(hour[8].p)+"%"
    screen.UpdateText('t'+str(8),text8)

    screen.UpdateImg('i'+str(12),'./icons/'+hour[12].icon+'.bmp')
    text12 = "+10h\n T:"+str(hour[12].t)+" \ P:"+str(hour[12].p)+"%"
    screen.UpdateText('t'+str(12),text12)

    screen.WriteAll()
    time.sleep(wait)
except KeyboardInterrupt:
    screen.Clear();
    sys.exit(-1)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/104#issuecomment-290922639, or mute the thread https://github.com/notifications/unsubscribe-auth/ADNCugZkANhoSa7SGi_NeKzJkxweytThks5rrlungaJpZM4MwauQ .

PeuX commented 7 years ago

here some basic usage

from papirus  import PapirusComposite
screen = PapirusComposite()

screen.AddImage('./icons/rain.bmp',0, 0,(20,20),"img_weather")
screen.AddText("text rain",50,0,20,'txt_weather')

screen.UpdateImg("img_weather",'./icons/clear.bmp')
screen.UpdateText("txt_weather","text clear")

For the command-line, i don't know how that work...

3DJupp commented 7 years ago

Do you think it's possible to save the content as a temporary image and then rotate it by 180 degree? This is what I'm trying to solve with PaPiRus, this improvement might be a step further.

francesco-vannini commented 7 years ago

Hi @PeuX , really nice class!

Many thanks for your contribution!

francesco-vannini commented 7 years ago

Fantastic @PeuX , thanks.

vanillabrand commented 7 years ago

This doesn't work on current release. When will it be live?

francesco-vannini commented 7 years ago

Could you be more specific? We pulled the code in last week and tested it.

On 22 May 2017 17:21, "vanillabrand" notifications@github.com wrote:

This doesn't work on current release. When will it be live?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/104#issuecomment-303149259, or mute the thread https://github.com/notifications/unsubscribe-auth/APUu19bAJJtRrabA-7TK_RjsXbThmofFks5r8bX1gaJpZM4MwauQ .

tvoverbeek commented 7 years ago

The PapirusComposite class inherits from PapirusTextPos. The code in the PapirusComposite init function requires the PapirusTextPos class to inherit from object (so called new class). The object argument was readded by Francesco on May 18 in commit https://github.com/PiSupply/PaPiRus/commit/b65a91b905c86a5602011b14193653ad0667722b#diff-d6287b584fd2b4213720ee5e0b974eb5. The object argument disappeared on May 17 because of the merge in https://github.com/PiSupply/PaPiRus/commit/7c786e57d63bf61f9f877977e411f0b51cbb8f16#diff-d6287b584fd2b4213720ee5e0b974eb5. In case @vanillabrand retrieved the code in between these two commits the composite code would not have worked. Cannot test now, since I am on travel.

shawaj commented 7 years ago

@francesco-vannini did we test this? it is working ok now?