Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Composite screen with image and text #104

Merged
merged 6 commits into from
May 17, 2017

Conversation

PeuX
Copy link
Contributor

@PeuX PeuX commented Apr 1, 2017

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

PapirusComposite exemple

@shawaj
Copy link
Member

shawaj commented Apr 1, 2017

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

@shawaj
Copy link
Member

shawaj commented Apr 1, 2017

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

@PeuX
Copy link
Contributor Author

PeuX commented Apr 1, 2017

the change on textPos allow Composite to extend textPos

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

  • AddImage(image, x=0, y=0, size = (10,10), Id = None): Add an image to the screen ex : AddImage ('/path/to/image.bmp', 10,20,(20,20),'TOP') this add image "image.bmp" to the position 10,20 whithe the width 20 et height 20 and use the Top ref (as AddText From TextPos )
  • UpdateImg(Id, image): update image ex : UpdateImage ('TOP','/path/to/newImgae.bmp') change the image from the prévious ex with the newImage.bmp
  • RemoveImg(Id): remove image ex : RemoveImg('TOP') (it create a white blank image to set on the image to remove)

(sorry for my english,... )

@shawaj
Copy link
Member

shawaj commented Apr 1, 2017

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
Copy link
Contributor Author

PeuX commented Apr 1, 2017

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
Copy link
Member

shawaj commented Apr 2, 2017 via email

@PeuX
Copy link
Contributor Author

PeuX commented Apr 3, 2017

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
Copy link

3DJupp commented May 6, 2017

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
Copy link
Contributor

Hi @PeuX , really nice class!

  • Could you please change the AddImage method to AddImg or change the others so that the method calls are consistent

  • Could you amend the init.py to include composite

  • Please provide a new version of the README.md with the class usage

  • It would be great but completely at your discretion, if you could provide a papirus-composite demo file to add to the bin folder

Many thanks for your contribution!

PeuX added 2 commits May 16, 2017 23:01
- Change papirus/composit.py to by more consistent whith textpos
- add composite to __init__.py
- provide demo in bin/papirus-composite-write (a really small demo)
@francesco-vannini
Copy link
Contributor

Fantastic @PeuX , thanks.

@francesco-vannini francesco-vannini merged commit 87fd766 into PiSupply:master May 17, 2017
@vanillabrand
Copy link

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

@francesco-vannini
Copy link
Contributor

francesco-vannini commented May 23, 2017 via email

@tvoverbeek
Copy link
Contributor

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 b65a91b#diff-d6287b584fd2b4213720ee5e0b974eb5.
The object argument disappeared on May 17 because of the merge in 7c786e5#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
Copy link
Member

shawaj commented Jun 12, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants