ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
431 stars 145 forks source link

Question: How can I change the default draw.text font (size)? #323

Closed DJuego closed 7 years ago

DJuego commented 7 years ago

We are working in a Robotic Challenge with Open Roberta and we have serious problems with the text size. It is too small!

For our challenge the students work in a low ilumination environment, and they must navigate through a menu in the little EV3 screen... :-( draw.text has a 'font' argument. And it is possible to use larger fonts. But the code is generated by Open Roberta (with Open Roberta connector) . And the argument is not used.

My question: Is it possible to change the default font for draw.text? Perhaps we can overwrite the default font (a dirty solution but enough for our purposes) ... How? Where?

Thanks!

ddemidov commented 7 years ago

draw.text() function comes from Pillow library. When no font is specified, it uses getfont() function, which calls ImageFont.get_default(), which has the font hardcoded. So there is no better way than to provide some non-default font. May be you should ask @ensonic to add the support for this.

ensonic commented 7 years ago

@DJuego this would be better filed for https://github.com/OpenRoberta/robertalab I'll compare the font-size on the ev3dev version with what they use on lejos. One reason we're not adding a font-size there is that the x-y pos is made for the text size and not for pixels.

DJuego commented 7 years ago

Thank you, @ddemidov, @ensonic four your valuable and swift answers. 👍

As I need an immediate solution (this week is the Challenge) I think i will try to modify the source of Pillow library with a new 'default' font... Any advice? Any recommended font?

DJuego

ddemidov commented 7 years ago

There is a table with all fonts distributed with ev3dev-lang-python here: http://python-ev3dev.readthedocs.io/en/stable/other.html#bitmap-fonts.

I suggest you pick one you like and replace the font = self.getfont() line with ev3dev.fonts.load('font_you_like').

ensonic commented 7 years ago

@DJuego try changing the font here: https://github.com/OpenRoberta/robertalab-ev3dev/blob/develop/roberta/ev3.py#L36

ensonic commented 7 years ago

DJuego, could we help you? Can we close this?

DJuego commented 7 years ago

Hi. @ensonic. I'm sorry very much i did not answer earlier! Due to our Robotic Challenge I've been traveling a lot of days.

However, I had not forgotten this. I simply wanted to answer after having tested the solution you proposed. Sorry for my delay. I tried the @ddemidov suggestion inmediately but it does not work. I read your suggestion but i had not time for testing.

Meanwhile, my 'team' decided a different approach to the problem (no text in the screen) and my priorities changed suddenly. But i always wanted to try your workaround. For this reason, i did not close this issue.

But now (today) i have tried your suggestion... and it is strange but i am unable to connect. :-? I am surprised. I receive messages like:

"You are trying to connect a robot of a different type as selected in the menu. Please switch the robot type in the robot's menu and try to connect again!"

However I choose Ev3->EV3dev,

I am using a Open Roberta Local Server (2.2.3 version, and now, 2.2.4 version). But i have tried it too with Open Roberta Online. I am using USB cable.

I have tried in three differents PCs with two differents EV3 bricks. After that i have updated fully the ev3dev (with openrobertalab connector update). The problem persist. I am unable to connect to OpenRoberta. (!!)

The last week i connected without problems multiple times. :-O It is true I worked with a different robot design but i have disconnect all ports and still stuck... Consequently I have not been able to test your suggestion. :-((( In any case this unexpected problem is much more worryng.

DJuego

P.S-1: I am working in Windows 10 x64 P.S-2: I am suspecting of connmanctl. I have activated the wifi precisely in the EV3s i am testing now! Could it be related? I have removed the Wifi dongle but i have not 'disabled' the Wifi. P.S-3: I have disabled the wifi with connmanctl. No changes. :-(

DJuego commented 7 years ago

I have opened an specific issue: https://github.com/OpenRoberta/robertalab-ev3dev/issues/42

DJuego

dwalton76 commented 7 years ago

ok to close since an issue was opened with OpenRoberta?

ensonic commented 7 years ago

Sure, please close.