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

PaPiRus Positional Text #68

Merged
merged 14 commits into from
Mar 15, 2017
Merged

PaPiRus Positional Text #68

merged 14 commits into from
Mar 15, 2017

Conversation

BenScarb
Copy link
Contributor

Simple class for doing positional text on the PaPiRus screen.

Making PapirusTextPos available in the __init.py__
Using text.py as the base of textpos.py, this class will allow positioning of text on the screen as needed.

If an ID is given, each individual piece of text can be updated (only the text at the moment).

Simple example:

from papirus import PapirusTextPos
text = PapirusTextPos()

# Put "hello world%" at (20, 30), with the ID of "Line1"
text.AddText("hello world", 20, 30, Id="Line1")
# Add "Another line", at default coords of (0, 0).  No id given so not easily updated
text.AddText("More Items")
# Write all text items to the screen
text.WriteAll()
# Update the item with the ID "Line1" with new text
text.UpdateText("Line1", "It's a new world")
# Redraw all the text to the screen
text.WriteAll()
Added the ability to remove text from the collection (via Id)
Added section for the PaPiRusTextPos, with example code.
Overhauled to make use of "partial_update()".
Also implemented "AutoUpdate" as part of the instantiation of the class, defaults to True, so any changes are written directly.
Calling PaPiRusTextPos(False) will draw nothing automatically unless ".WriteAll()" is called (for more control over when updates are done).

Removing text will now remove it from the image by overwriting the text with a white rectangle.  May need a little work on the positioning/size of the rectangle.
Changed examples to show the two different ways of using PaPiRusTextPos, auto updating and manual screen push.
@shawaj
Copy link
Member

shawaj commented Jan 3, 2017

Just out of interest, does this allow for line breaks also?

@BenScarb
Copy link
Contributor Author

BenScarb commented Jan 4, 2017

No, currently the code doesn't take line breaks in to account.
I'll take a look at that next.

@shawaj
Copy link
Member

shawaj commented Jan 4, 2017 via email

PaPiRusTextPos will now drop any text following '\n' on to a new line.
It will take the given X coordinate in to account and NOT reset to x=0
Added a note about the \n awareness in PaPiRusTextPos and information about .Clear() method
@BenScarb
Copy link
Contributor Author

BenScarb commented Jan 4, 2017

There we go, \n line breaks now supported :)

@shawaj
Copy link
Member

shawaj commented Jan 5, 2017 via email

Using splitlines() to take \n, \r and \r\n in to account for line breaks
@BenScarb
Copy link
Contributor Author

BenScarb commented Jan 5, 2017

Yes, probably worth taking in to account. Also \r\n.
Using .splitlines() to do all three cases in one go :)

@shawaj
Copy link
Member

shawaj commented Jan 6, 2017 via email

@francesco-vannini
Copy link
Contributor

@BenScarb is there a way we could refactor papirus-write to include this new feature but end up with only one write approach instead of two?

@BenScarb
Copy link
Contributor Author

BenScarb commented Jan 22, 2017

I'll have a look, I thought papirus-write was a complied file!
Shouldn't be a problem to change it out, optional params for X and Y, then pass it all to the existing routines.
There wouldn't be any speed updates as it would happen once and then exit.

One question, does it need to run as root? I've been using it on the nearly latest OS and it seemed to be fine without sudo'ing anything.

@shawaj
Copy link
Member

shawaj commented Jan 22, 2017 via email

@shawaj
Copy link
Member

shawaj commented Feb 1, 2017

@BenScarb realised I forgot to tag you in my last reply. Just wanted to check you saw it

@BenScarb
Copy link
Contributor Author

BenScarb commented Feb 1, 2017

No worries, I'll be taking a look tomorrow :) Assuming I can find where I tidied my Pi away to!

@shawaj
Copy link
Member

shawaj commented Feb 2, 2017 via email

Unsure why but when used with Args are passed, the splitlines() wouldn't see the /n as a line break.
Parsing it as encoded makes sure this does happen.
Updated papirus-write to accept x and y coordinates and re-used the existing code base.
Fixed the MarkDown coding (Whoops, rookie mistake!)
Added information about paprirus-write positional arguments.
@BenScarb
Copy link
Contributor Author

BenScarb commented Feb 3, 2017

Found the Pi! Sorted the papirus-write to accept the X and Y coords and use the appropriate code.
Updated the textpos class as the strings weren't being accepted as having a line break in, so needed to be (un-)escaped.

Not sure what I've done to the ReadMe.md file, thought I'd fixed it, looked all right on http://dillinger.io/ but not do good on GitHub!

@francesco-vannini
Copy link
Contributor

Ben I'll take a look at this next week, thanks for the effort, really appreciated and sorry it is taking so long to review this. Keep you posted.

@BenScarb
Copy link
Contributor Author

No worries, I know life happens :) If anything else needs updating or de-conflicting, just drop me a message.

@francesco-vannini
Copy link
Contributor

Hi, I have finally tested the code which works really nicely, thanks! Only one thing now could you redo the README.md changes using the current file. That should also help cleaning up that strange behaviour you saw caused by you removing the "Your python script must be running with root privileges ... " part but you left behind one ```
Also if possible could you please clean up the various commits and collapse the new in just one as we did for #55
Many thanks once again. I'll merge as soon as I get the new changes.

@BenScarb
Copy link
Contributor Author

No worries, I'll see if I can get the changes done tonight. My "diffing skills" need working on me thinks, didn't see what I'd left behind! Read up on the "needing root" stuff, good call. I'll get the current ReadMe.MD updated and uploaded.

Added changes for positional text, with any luck, the formatting won't be damaged this time.
Another attempt to fixing the formatting.
@BenScarb
Copy link
Contributor Author

I have updated the README.md, I believe it's sorted but the conflict still exists.
Seems I need to research how to do that! I think just taking the version from branch will do it :)

@shawaj
Copy link
Member

shawaj commented Mar 12, 2017 via email

@BenScarb
Copy link
Contributor Author

Great stuff, sorry I can't give you a fully formed branch to pull in. Something for me to work on, every days a learning day :)

@shawaj
Copy link
Member

shawaj commented Mar 12, 2017 via email

@BenScarb
Copy link
Contributor Author

Once this is merged in, I'll take a look at inverting the colours, or at least having control over them :)
The White on Black seems like a good idea!

@shawaj
Copy link
Member

shawaj commented Mar 12, 2017 via email

@francesco-vannini francesco-vannini merged commit 805fb1a into PiSupply:master Mar 15, 2017
@francesco-vannini
Copy link
Contributor

Thanks a lot @BenScarb - all sorted and merged now :-)

Thanks so much for your contribution!

@BenScarb
Copy link
Contributor Author

Woohoo, my first proper submissions and completed PR!
Glad it'll be useful :)

@shawaj
Copy link
Member

shawaj commented Mar 15, 2017 via email

@BenScarb BenScarb deleted the PaPiRus-Positional-Text branch April 3, 2017 14:06
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.

3 participants