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

Writing text to a specific position not working #58

Closed
ChrisHaPunkt opened this issue Sep 14, 2016 · 6 comments
Closed

Writing text to a specific position not working #58

ChrisHaPunkt opened this issue Sep 14, 2016 · 6 comments

Comments

@ChrisHaPunkt
Copy link

Taking the snippet from the docs:
text.write("hello world", (10, 10) )
results in

File "getEvents.py", line 26, in
text.write("hello world", (10, 10))
File "/usr/local/lib/python2.7/dist-packages/papirus/text.py", line 24, in write
font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', size)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 240, in truetype
return FreeTypeFont(font, size, index, encoding)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 137, in init
self.font = core.getfont(font, size, index, encoding)
TypeError: an integer is required

@ChrisHaPunkt
Copy link
Author

I'm not able to set the position of the text to write...
Even " " and tabs are not working and became trimmed.

@BenScarb
Copy link
Contributor

BenScarb commented Dec 4, 2016

I'm getting the same thing.

The file:
/usr/local/lib/python2.7/dist-packages/papirus/text.py
doesn't have a function to take a (X,Y) parameter.

@shawaj
Copy link
Member

shawaj commented Dec 5, 2016 via email

@dreadnoult
Copy link

dreadnoult commented Dec 30, 2016

It's pretty sad that such a basic functionality does not work out of the box and nobody tells you about that when you are buying the display. Nevertheless there is a simple workaround. You don't need the text module at all but you do need PIL (should be installed already if you have Papirus installed). Just do this:

from papirus import Papirus 
from PIL import Image, ImageDraw, ImageFont
  
# The epaper screen object                                                                                            
screen = Papirus()                                                                                

# Create a new blank image with a size of  the screen and get a drawing context                                                                                   
image=Image.new('1',screen.size, 1)
draw=ImageDraw.Draw(image)                                                                        
 
# Specify a font you want to use and its size (last argument)                                                                                              
 font=ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf',32)              

# Draw text on the image at the desired position                                                                                                    
 draw.text((10,10),'Hello', font = font, fill = 0)                                             
 draw.text((10,60), 'World', font = font, fill = 0)                                           
 
# Update the screen                                                                                               
 screen.display(image)                                                                             
 screen.update()

Hope it helps

@BenScarb
Copy link
Contributor

BenScarb commented Dec 31, 2016

I've added in some positional text (PaPiRusTextPos) stuff, pull request is in. See if it's the sort of thing you want.
Request: #68 (Didn't know it would shorten it to a number!)

@francesco-vannini
Copy link
Contributor

Implemented in #68

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

No branches or pull requests

5 participants