Repository: kivy/kivy

Issue:
A way to set the VKeyboard font size could be added
I'm not sure how to go about this small but probably useful change. Currently, no clean way seems to exist for setting the font size of the keys in a VKeyboard. Indeed, the `draw_keys` method of the `VKeyboard` class has the following code:

    w, h = self.size
    # ...
    font_size = int(w) / 46

But the rendered keyboard is not pleasing to the eye as rendered on half of the screen of a 7'' touchscreen running on a Raspberry Pi. I changed the denominator from 46 to 32 and the keys look much better. So my question is, how could this customization be cleaner?


Discussion:
Instead of the raw `46` value make a `NumericProperty` e.g. in `VKeyboard` and put it in that place, which will expose the more useful option to the users. Of course note, that if you are going to make a pull request, each exposed property has to be documented (docstring, version tags, what class it actually is, etc). Examples how it should look you can find all over the repository. 🐰 
Right, but would people be happy to tweak an abstract parameter such as that denominator? Maybe, if it has some sort of concept behind it. My question would be, how was that value 46 computed/determined?
That's like a super-old line. I put `len()` on a lot of stuff there or just printed stuff but found nothing like `46` value. That guy might even put there `42`, that would be a nice pun for this mystery.

However, I think [the intention](https://github.com/kivy/kivy/commit/576a4ba09b97fd22bbc4ea0bae1073e03ddd9dfa#diff-41a5e58e29320aba7dacc7be3b6cb51dR463) was to have a `font_size` equal on android to something similar as it'd be by default on desktop (`==15`, `kivy.metrics` hadn't been around for about a year judging from the git history). That line needs a fix, most likely with the width cut off completely as it brings up only confusion (and metrics work quite well even without messing up with sizes).

You might as well just remove the line and expose the property to the main class (`VKeyboard`), so that any user can customize that if really necessary.

Resolving patch:
diff --git a/kivy/uix/vkeyboard.py b/kivy/uix/vkeyboard.py
--- a/kivy/uix/vkeyboard.py
+++ b/kivy/uix/vkeyboard.py
@@ -224,6 +224,17 @@ class VKeyboard(Scatter):
     to [2, 2, 2, 2]
     '''
 
+    font_size = NumericProperty(20.)
+    '''font_size, specifies the size of the text of virtual keyboard.
+    It should be kept within a limit otherwise text either goes outside
+    the bounds of the key or becomes too small to read.
+
+    .. versionadded:: 1.9.2
+
+    :attr:`font_size` is a :class:`~kivy.properties.NumericProperty` and
+    defaults to 20.
+    '''
+
     background_color = ListProperty([1, 1, 1, 1])
     '''Background color, in the format (r, g, b, a). If a background is
     set, the color will be combined with the background texture.
@@ -319,7 +330,6 @@ class VKeyboard(Scatter):
     have_shift = BooleanProperty(False)
     have_special = BooleanProperty(False)
     active_keys = DictProperty({})
-    font_size = NumericProperty('20dp')
     font_name = StringProperty('data/fonts/DejaVuSans.ttf')
     repeat_touch = ObjectProperty(allownone=True)
 
@@ -634,8 +644,6 @@ def draw_keys(self):
         layout_mode = self.layout_mode
 
         # draw background
-        w, h = self.size
-
         background = resource_find(self.background_disabled
                                    if self.disabled else
                                    self.background)
@@ -661,16 +669,13 @@ def draw_keys(self):
                                     border=self.key_border)
 
         # then draw the text
-        # calculate font_size
-        font_size = int(w) / 46
-        # draw
         for line_nb in range(1, layout_rows + 1):
             key_nb = 0
             for pos, size in layout_geometry['LINE_%d' % line_nb]:
                 # retrieve the relative text
                 text = layout[layout_mode + '_' + str(line_nb)][key_nb][0]
-                z = Label(text=text, font_size=font_size, pos=pos, size=size,
-                          font_name=self.font_name)
+                z = Label(text=text, font_size=self.font_size, pos=pos,
+                           size=size, font_name=self.font_name)
                 self.add_widget(z)
                 key_nb += 1
 


Test patch: