We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
codeinput.py example missing Pro.ttf
I was trying the various kivy examples, and one of them failed, the `codeinput.py` file, with the following error:

```
sinclair@blastocyst  $ kivy /Users/sinclair/kivy/examples/widgets/codeinput.py
[INFO              ] Kivy v1.8.0
[INFO              ] [Logger      ] Record log in /Users/sinclair/.kivy/logs/kivy_14-12-27_20.txt
[INFO              ] [Factory     ] 157 symbols loaded
[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO              ] [Image       ] Providers: img_imageio, img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[INFO              ] [Text        ] Provider: pygame
[DEBUG             ] [Window      ] Ignored <egl_rpi> (import error)
[INFO              ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG             ] [Window      ] Display driver Quartz
[DEBUG             ] [Window      ] Actual window size: 800x600
[DEBUG             ] [Window      ] Actual color bits r8 g8 b8 a8
[DEBUG             ] [Window      ] Actual depth bits: 24
[DEBUG             ] [Window      ] Actual stencil bits: 8
[DEBUG             ] [Window      ] Actual multisampling samples: 4
[INFO              ] [GL          ] OpenGL version <2.1 INTEL-10.0.86>
[INFO              ] [GL          ] OpenGL vendor <Intel Inc.>
[INFO              ] [GL          ] OpenGL renderer <Intel HD Graphics 5000 OpenGL Engine>
[INFO              ] [GL          ] OpenGL parsed version: 2, 1
[INFO              ] [GL          ] Shading version <1.20>
[INFO              ] [GL          ] Texture max size <16384>
[INFO              ] [GL          ] Texture max units <16>
[DEBUG             ] [Shader      ] Fragment compiled successfully
[DEBUG             ] [Shader      ] Vertex compiled successfully
[DEBUG             ] [ImageImageIO] Load </Applications/Kivy.app/Contents/Resources/kivy/kivy/data/glsl/default.png>
[INFO              ] [GL          ] BGRA texture support is available
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[DEBUG             ] [Cache       ] register <kv.loader> with limit=500, timeout=60s
[INFO              ] [Loader      ] using a thread pool of 2 workers
[DEBUG             ] [Cache       ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG             ] [Cache       ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG             ] [App         ] Loading kv </Users/sinclair/kivy/examples/widgets/codeinputtest.kv>
 Traceback (most recent call last):
   File "/Users/sinclair/kivy/examples/widgets/codeinput.py", line 179, in <module>
     CodeInputTest().run()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/app.py", line 766, in run
     root = self.build()
   File "/Users/sinclair/kivy/examples/widgets/codeinput.py", line 111, in build
     values=sorted(map(str, fonts.get_fonts())))
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py", line 116, in __init__
     self._build_dropdown()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py", line 130, in _build_dropdown
     self._update_dropdown()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py", line 139, in _update_dropdown
     item = cls(text=value)
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/behaviors.py", line 72, in __init__
     super(ButtonBehavior, self).__init__(**kwargs)
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/label.py", line 141, in __init__
     self._create_label()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/label.py", line 161, in _create_label
     self._label = CoreLabel(**dkw)
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/text/__init__.py", line 136, in __init__
     self.resolve_font_name()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/text/__init__.py", line 196, in resolve_font_name
     raise IOError('Label: File %r not found' % fontname)
 IOError: Label: File u'/Library/Fonts/ Pro.ttf' not found
```

I am using OS X 10.10.1

I tried adding a font file called "Pro.ttf" at that location to make it happy, but the result was the same.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/widgets/codeinput.py`
Content:
```
1 from kivy.app import App
2 from kivy.extras.highlight import KivyLexer
3 from kivy.uix.spinner import Spinner, SpinnerOption
4 from kivy.uix.boxlayout import BoxLayout
5 from kivy.uix.codeinput import CodeInput
6 from kivy.uix.popup import Popup
7 from kivy.properties import ListProperty
8 from kivy.core.window import Window
9 from pygments import lexers
10 from pygame import font as fonts
11 import codecs, os
12 
13 example_text = '''
14 ---------------------Python----------------------------------
15 import kivy
16 kivy.require('1.0.6') # replace with your current kivy version !
17 from kivy.app import App
18 from kivy.uix.button import Button
19 
20 class MyApp(App):
21     def build(self):
22         return Button(text='Hello World')
23 
24 if __name__ == '__main__':
25     MyApp().run()
26 ----------------------Java-----------------------------------
27 
28 public static byte toUnsignedByte(int intVal) {
29     byte byteVal;
30     return (byte)(intVal & 0xFF);
31 }
32 ---------------------kv lang---------------------------------
33 #:kivy 1.0
34 
35 <YourWidget>:
36     canvas:
37         Color:
38             rgb: .5, .5, .5
39         Rectangle:
40             pos: self.pos
41             size: self.size
42 ---------------------HTML------------------------------------
43 <!-- Place this tag where you want the +1 button to render. -->
44 <div class="g-plusone" data-annotation="inline" data-width="300"></div>
45 
46 <!-- Place this tag after the last +1 button tag. -->
47 <script type="text/javascript">
48   (function() {
49     var po = document.createElement('script');
50     po.type = 'text/javascript';
51     po.async = true;
52     po.src = 'https://apis.google.com/js/plusone.js';
53     var s = document.getElementsByTagName('script')[0];
54     s.parentNode.insertBefore(po, s);
55   })();
56 </script>
57 '''
58 
59 
60 class Fnt_SpinnerOption(SpinnerOption):
61     pass
62 
63 
64 class LoadDialog(Popup):
65 
66     def load(self, path, selection):
67         self.choosen_file = [None, ]
68         self.choosen_file = selection
69         Window.title = selection[0][selection[0].rfind(os.sep)+1:]
70         self.dismiss()
71 
72     def cancel(self):
73         self.dismiss()
74 
75 
76 class SaveDialog(Popup):
77 
78     def save(self, path, selection):
79         _file = codecs.open(selection, 'w', encoding='utf8')
80         _file.write(self.text)
81         Window.title = selection[selection.rfind(os.sep)+1:]
82         _file.close()
83         self.dismiss()
84 
85     def cancel(self):
86         self.dismiss()
87 
88 
89 class CodeInputTest(App):
90 
91     files = ListProperty([None, ])
92 
93     def build(self):
94         b = BoxLayout(orientation='vertical')
95         languages = Spinner(
96             text='language',
97             values=sorted(['KvLexer', ] + list(lexers.LEXERS.keys())))
98 
99         languages.bind(text=self.change_lang)
100 
101         menu = BoxLayout(
102             size_hint_y=None,
103             height='30pt')
104         fnt_size = Spinner(
105             text='12',
106             values=list(map(str, list(range(5, 40)))))
107         fnt_size.bind(text=self._update_size)
108         fnt_name = Spinner(
109             text='DroidSansMono',
110             option_cls=Fnt_SpinnerOption,
111             values=sorted(map(str, fonts.get_fonts())))
112         fnt_name.bind(text=self._update_font)
113         mnu_file = Spinner(
114             text='File',
115             values=('Open', 'SaveAs', 'Save', 'Close'))
116         mnu_file.bind(text=self._file_menu_selected)
117 
118         menu.add_widget(mnu_file)
119         menu.add_widget(fnt_size)
120         menu.add_widget(fnt_name)
121         menu.add_widget(languages)
122         b.add_widget(menu)
123 
124         self.codeinput = CodeInput(
125             lexer=KivyLexer(),
126             font_name='data/fonts/DroidSansMono.ttf', font_size=12,
127             text=example_text)
128 
129         b.add_widget(self.codeinput)
130 
131         return b
132 
133     def _update_size(self, instance, size):
134         self.codeinput.font_size = float(size)
135 
136     def _update_font(self, instance, fnt_name):
137         instance.font_name = self.codeinput.font_name =\
138             fonts.match_font(fnt_name)
139 
140     def _file_menu_selected(self, instance, value):
141         if value == 'File':
142             return
143         instance.text = 'File'
144         if value == 'Open':
145             if not hasattr(self, 'load_dialog'):
146                 self.load_dialog = LoadDialog()
147             self.load_dialog.open()
148             self.load_dialog.bind(choosen_file=self.setter('files'))
149         elif value == 'SaveAs':
150             if not hasattr(self, 'saveas_dialog'):
151                 self.saveas_dialog = SaveDialog()
152             self.saveas_dialog.text = self.codeinput.text
153             self.saveas_dialog.open()
154         elif value == 'Save':
155             if self.files[0]:
156                 _file = codecs.open(self.files[0], 'w', encoding='utf8')
157                 _file.write(self.codeinput.text)
158                 _file.close()
159         elif value == 'Close':
160             if self.files[0]:
161                 self.codeinput.text = ''
162                 Window.title = 'untitled'
163 
164     def on_files(self, instance, values):
165         if not values[0]:
166             return
167         _file = codecs.open(values[0], 'r', encoding='utf8')
168         self.codeinput.text = _file.read()
169         _file.close()
170 
171     def change_lang(self, instance, l):
172         if l == 'KvLexer':
173             lx = KivyLexer()
174         else:
175             lx = lexers.get_lexer_by_name(lexers.LEXERS[l][2][0])
176         self.codeinput.lexer = lx
177 
178 if __name__ == '__main__':
179     CodeInputTest().run()
180
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/widgets/codeinput.py b/examples/widgets/codeinput.py
--- a/examples/widgets/codeinput.py
+++ b/examples/widgets/codeinput.py
@@ -134,8 +134,9 @@
         self.codeinput.font_size = float(size)
 
     def _update_font(self, instance, fnt_name):
-        instance.font_name = self.codeinput.font_name =\
-            fonts.match_font(fnt_name)
+        font_name = fonts.match_font(fnt_name)
+        if os.path.exists(font_name):
+            instance.font_name = self.codeinput.font_name = font_name
 
     def _file_menu_selected(self, instance, value):
         if value == 'File':

{"golden_diff": "diff --git a/examples/widgets/codeinput.py b/examples/widgets/codeinput.py\n--- a/examples/widgets/codeinput.py\n+++ b/examples/widgets/codeinput.py\n@@ -134,8 +134,9 @@\n         self.codeinput.font_size = float(size)\n \n     def _update_font(self, instance, fnt_name):\n-        instance.font_name = self.codeinput.font_name =\\\n-            fonts.match_font(fnt_name)\n+        font_name = fonts.match_font(fnt_name)\n+        if os.path.exists(font_name):\n+            instance.font_name = self.codeinput.font_name = font_name\n \n     def _file_menu_selected(self, instance, value):\n         if value == 'File':\n", "issue": "codeinput.py example missing Pro.ttf\nI was trying the various kivy examples, and one of them failed, the `codeinput.py` file, with the following error:\n\n```\nsinclair@blastocyst  $ kivy /Users/sinclair/kivy/examples/widgets/codeinput.py\n[INFO              ] Kivy v1.8.0\n[INFO              ] [Logger      ] Record log in /Users/sinclair/.kivy/logs/kivy_14-12-27_20.txt\n[INFO              ] [Factory     ] 157 symbols loaded\n[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones\n[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s\n[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones\n[INFO              ] [Image       ] Providers: img_imageio, img_tex, img_dds, img_pygame, img_gif (img_pil ignored)\n[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s\n[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s\n[INFO              ] [Text        ] Provider: pygame\n[DEBUG             ] [Window      ] Ignored <egl_rpi> (import error)\n[INFO              ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)\n[DEBUG             ] [Window      ] Display driver Quartz\n[DEBUG             ] [Window      ] Actual window size: 800x600\n[DEBUG             ] [Window      ] Actual color bits r8 g8 b8 a8\n[DEBUG             ] [Window      ] Actual depth bits: 24\n[DEBUG             ] [Window      ] Actual stencil bits: 8\n[DEBUG             ] [Window      ] Actual multisampling samples: 4\n[INFO              ] [GL          ] OpenGL version <2.1 INTEL-10.0.86>\n[INFO              ] [GL          ] OpenGL vendor <Intel Inc.>\n[INFO              ] [GL          ] OpenGL renderer <Intel HD Graphics 5000 OpenGL Engine>\n[INFO              ] [GL          ] OpenGL parsed version: 2, 1\n[INFO              ] [GL          ] Shading version <1.20>\n[INFO              ] [GL          ] Texture max size <16384>\n[INFO              ] [GL          ] Texture max units <16>\n[DEBUG             ] [Shader      ] Fragment compiled successfully\n[DEBUG             ] [Shader      ] Vertex compiled successfully\n[DEBUG             ] [ImageImageIO] Load </Applications/Kivy.app/Contents/Resources/kivy/kivy/data/glsl/default.png>\n[INFO              ] [GL          ] BGRA texture support is available\n[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked\n[DEBUG             ] [Cache       ] register <kv.loader> with limit=500, timeout=60s\n[INFO              ] [Loader      ] using a thread pool of 2 workers\n[DEBUG             ] [Cache       ] register <textinput.label> with limit=None, timeout=60.0s\n[DEBUG             ] [Cache       ] register <textinput.width> with limit=None, timeout=60.0s\n[DEBUG             ] [App         ] Loading kv </Users/sinclair/kivy/examples/widgets/codeinputtest.kv>\n Traceback (most recent call last):\n   File \"/Users/sinclair/kivy/examples/widgets/codeinput.py\", line 179, in <module>\n     CodeInputTest().run()\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/app.py\", line 766, in run\n     root = self.build()\n   File \"/Users/sinclair/kivy/examples/widgets/codeinput.py\", line 111, in build\n     values=sorted(map(str, fonts.get_fonts())))\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py\", line 116, in __init__\n     self._build_dropdown()\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py\", line 130, in _build_dropdown\n     self._update_dropdown()\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/spinner.py\", line 139, in _update_dropdown\n     item = cls(text=value)\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/behaviors.py\", line 72, in __init__\n     super(ButtonBehavior, self).__init__(**kwargs)\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/label.py\", line 141, in __init__\n     self._create_label()\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/uix/label.py\", line 161, in _create_label\n     self._label = CoreLabel(**dkw)\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/text/__init__.py\", line 136, in __init__\n     self.resolve_font_name()\n   File \"/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/text/__init__.py\", line 196, in resolve_font_name\n     raise IOError('Label: File %r not found' % fontname)\n IOError: Label: File u'/Library/Fonts/ Pro.ttf' not found\n```\n\nI am using OS X 10.10.1\n\nI tried adding a font file called \"Pro.ttf\" at that location to make it happy, but the result was the same.\n\n", "before_files": [{"content": "from kivy.app import App\nfrom kivy.extras.highlight import KivyLexer\nfrom kivy.uix.spinner import Spinner, SpinnerOption\nfrom kivy.uix.boxlayout import BoxLayout\nfrom kivy.uix.codeinput import CodeInput\nfrom kivy.uix.popup import Popup\nfrom kivy.properties import ListProperty\nfrom kivy.core.window import Window\nfrom pygments import lexers\nfrom pygame import font as fonts\nimport codecs, os\n\nexample_text = '''\n---------------------Python----------------------------------\nimport kivy\nkivy.require('1.0.6') # replace with your current kivy version !\nfrom kivy.app import App\nfrom kivy.uix.button import Button\n\nclass MyApp(App):\n    def build(self):\n        return Button(text='Hello World')\n\nif __name__ == '__main__':\n    MyApp().run()\n----------------------Java-----------------------------------\n\npublic static byte toUnsignedByte(int intVal) {\n    byte byteVal;\n    return (byte)(intVal & 0xFF);\n}\n---------------------kv lang---------------------------------\n#:kivy 1.0\n\n<YourWidget>:\n    canvas:\n        Color:\n            rgb: .5, .5, .5\n        Rectangle:\n            pos: self.pos\n            size: self.size\n---------------------HTML------------------------------------\n<!-- Place this tag where you want the +1 button to render. -->\n<div class=\"g-plusone\" data-annotation=\"inline\" data-width=\"300\"></div>\n\n<!-- Place this tag after the last +1 button tag. -->\n<script type=\"text/javascript\">\n  (function() {\n    var po = document.createElement('script');\n    po.type = 'text/javascript';\n    po.async = true;\n    po.src = 'https://apis.google.com/js/plusone.js';\n    var s = document.getElementsByTagName('script')[0];\n    s.parentNode.insertBefore(po, s);\n  })();\n</script>\n'''\n\n\nclass Fnt_SpinnerOption(SpinnerOption):\n    pass\n\n\nclass LoadDialog(Popup):\n\n    def load(self, path, selection):\n        self.choosen_file = [None, ]\n        self.choosen_file = selection\n        Window.title = selection[0][selection[0].rfind(os.sep)+1:]\n        self.dismiss()\n\n    def cancel(self):\n        self.dismiss()\n\n\nclass SaveDialog(Popup):\n\n    def save(self, path, selection):\n        _file = codecs.open(selection, 'w', encoding='utf8')\n        _file.write(self.text)\n        Window.title = selection[selection.rfind(os.sep)+1:]\n        _file.close()\n        self.dismiss()\n\n    def cancel(self):\n        self.dismiss()\n\n\nclass CodeInputTest(App):\n\n    files = ListProperty([None, ])\n\n    def build(self):\n        b = BoxLayout(orientation='vertical')\n        languages = Spinner(\n            text='language',\n            values=sorted(['KvLexer', ] + list(lexers.LEXERS.keys())))\n\n        languages.bind(text=self.change_lang)\n\n        menu = BoxLayout(\n            size_hint_y=None,\n            height='30pt')\n        fnt_size = Spinner(\n            text='12',\n            values=list(map(str, list(range(5, 40)))))\n        fnt_size.bind(text=self._update_size)\n        fnt_name = Spinner(\n            text='DroidSansMono',\n            option_cls=Fnt_SpinnerOption,\n            values=sorted(map(str, fonts.get_fonts())))\n        fnt_name.bind(text=self._update_font)\n        mnu_file = Spinner(\n            text='File',\n            values=('Open', 'SaveAs', 'Save', 'Close'))\n        mnu_file.bind(text=self._file_menu_selected)\n\n        menu.add_widget(mnu_file)\n        menu.add_widget(fnt_size)\n        menu.add_widget(fnt_name)\n        menu.add_widget(languages)\n        b.add_widget(menu)\n\n        self.codeinput = CodeInput(\n            lexer=KivyLexer(),\n            font_name='data/fonts/DroidSansMono.ttf', font_size=12,\n            text=example_text)\n\n        b.add_widget(self.codeinput)\n\n        return b\n\n    def _update_size(self, instance, size):\n        self.codeinput.font_size = float(size)\n\n    def _update_font(self, instance, fnt_name):\n        instance.font_name = self.codeinput.font_name =\\\n            fonts.match_font(fnt_name)\n\n    def _file_menu_selected(self, instance, value):\n        if value == 'File':\n            return\n        instance.text = 'File'\n        if value == 'Open':\n            if not hasattr(self, 'load_dialog'):\n                self.load_dialog = LoadDialog()\n            self.load_dialog.open()\n            self.load_dialog.bind(choosen_file=self.setter('files'))\n        elif value == 'SaveAs':\n            if not hasattr(self, 'saveas_dialog'):\n                self.saveas_dialog = SaveDialog()\n            self.saveas_dialog.text = self.codeinput.text\n            self.saveas_dialog.open()\n        elif value == 'Save':\n            if self.files[0]:\n                _file = codecs.open(self.files[0], 'w', encoding='utf8')\n                _file.write(self.codeinput.text)\n                _file.close()\n        elif value == 'Close':\n            if self.files[0]:\n                self.codeinput.text = ''\n                Window.title = 'untitled'\n\n    def on_files(self, instance, values):\n        if not values[0]:\n            return\n        _file = codecs.open(values[0], 'r', encoding='utf8')\n        self.codeinput.text = _file.read()\n        _file.close()\n\n    def change_lang(self, instance, l):\n        if l == 'KvLexer':\n            lx = KivyLexer()\n        else:\n            lx = lexers.get_lexer_by_name(lexers.LEXERS[l][2][0])\n        self.codeinput.lexer = lx\n\nif __name__ == '__main__':\n    CodeInputTest().run()\n", "path": "examples/widgets/codeinput.py"}], "after_files": [{"content": "from kivy.app import App\nfrom kivy.extras.highlight import KivyLexer\nfrom kivy.uix.spinner import Spinner, SpinnerOption\nfrom kivy.uix.boxlayout import BoxLayout\nfrom kivy.uix.codeinput import CodeInput\nfrom kivy.uix.popup import Popup\nfrom kivy.properties import ListProperty\nfrom kivy.core.window import Window\nfrom pygments import lexers\nfrom pygame import font as fonts\nimport codecs, os\n\nexample_text = '''\n---------------------Python----------------------------------\nimport kivy\nkivy.require('1.0.6') # replace with your current kivy version !\nfrom kivy.app import App\nfrom kivy.uix.button import Button\n\nclass MyApp(App):\n    def build(self):\n        return Button(text='Hello World')\n\nif __name__ == '__main__':\n    MyApp().run()\n----------------------Java-----------------------------------\n\npublic static byte toUnsignedByte(int intVal) {\n    byte byteVal;\n    return (byte)(intVal & 0xFF);\n}\n---------------------kv lang---------------------------------\n#:kivy 1.0\n\n<YourWidget>:\n    canvas:\n        Color:\n            rgb: .5, .5, .5\n        Rectangle:\n            pos: self.pos\n            size: self.size\n---------------------HTML------------------------------------\n<!-- Place this tag where you want the +1 button to render. -->\n<div class=\"g-plusone\" data-annotation=\"inline\" data-width=\"300\"></div>\n\n<!-- Place this tag after the last +1 button tag. -->\n<script type=\"text/javascript\">\n  (function() {\n    var po = document.createElement('script');\n    po.type = 'text/javascript';\n    po.async = true;\n    po.src = 'https://apis.google.com/js/plusone.js';\n    var s = document.getElementsByTagName('script')[0];\n    s.parentNode.insertBefore(po, s);\n  })();\n</script>\n'''\n\n\nclass Fnt_SpinnerOption(SpinnerOption):\n    pass\n\n\nclass LoadDialog(Popup):\n\n    def load(self, path, selection):\n        self.choosen_file = [None, ]\n        self.choosen_file = selection\n        Window.title = selection[0][selection[0].rfind(os.sep)+1:]\n        self.dismiss()\n\n    def cancel(self):\n        self.dismiss()\n\n\nclass SaveDialog(Popup):\n\n    def save(self, path, selection):\n        _file = codecs.open(selection, 'w', encoding='utf8')\n        _file.write(self.text)\n        Window.title = selection[selection.rfind(os.sep)+1:]\n        _file.close()\n        self.dismiss()\n\n    def cancel(self):\n        self.dismiss()\n\n\nclass CodeInputTest(App):\n\n    files = ListProperty([None, ])\n\n    def build(self):\n        b = BoxLayout(orientation='vertical')\n        languages = Spinner(\n            text='language',\n            values=sorted(['KvLexer', ] + list(lexers.LEXERS.keys())))\n\n        languages.bind(text=self.change_lang)\n\n        menu = BoxLayout(\n            size_hint_y=None,\n            height='30pt')\n        fnt_size = Spinner(\n            text='12',\n            values=list(map(str, list(range(5, 40)))))\n        fnt_size.bind(text=self._update_size)\n        fnt_name = Spinner(\n            text='DroidSansMono',\n            option_cls=Fnt_SpinnerOption,\n            values=sorted(map(str, fonts.get_fonts())))\n        fnt_name.bind(text=self._update_font)\n        mnu_file = Spinner(\n            text='File',\n            values=('Open', 'SaveAs', 'Save', 'Close'))\n        mnu_file.bind(text=self._file_menu_selected)\n\n        menu.add_widget(mnu_file)\n        menu.add_widget(fnt_size)\n        menu.add_widget(fnt_name)\n        menu.add_widget(languages)\n        b.add_widget(menu)\n\n        self.codeinput = CodeInput(\n            lexer=KivyLexer(),\n            font_name='data/fonts/DroidSansMono.ttf', font_size=12,\n            text=example_text)\n\n        b.add_widget(self.codeinput)\n\n        return b\n\n    def _update_size(self, instance, size):\n        self.codeinput.font_size = float(size)\n\n    def _update_font(self, instance, fnt_name):\n        font_name = fonts.match_font(fnt_name)\n        if os.path.exists(font_name):\n            instance.font_name = self.codeinput.font_name = font_name\n\n    def _file_menu_selected(self, instance, value):\n        if value == 'File':\n            return\n        instance.text = 'File'\n        if value == 'Open':\n            if not hasattr(self, 'load_dialog'):\n                self.load_dialog = LoadDialog()\n            self.load_dialog.open()\n            self.load_dialog.bind(choosen_file=self.setter('files'))\n        elif value == 'SaveAs':\n            if not hasattr(self, 'saveas_dialog'):\n                self.saveas_dialog = SaveDialog()\n            self.saveas_dialog.text = self.codeinput.text\n            self.saveas_dialog.open()\n        elif value == 'Save':\n            if self.files[0]:\n                _file = codecs.open(self.files[0], 'w', encoding='utf8')\n                _file.write(self.codeinput.text)\n                _file.close()\n        elif value == 'Close':\n            if self.files[0]:\n                self.codeinput.text = ''\n                Window.title = 'untitled'\n\n    def on_files(self, instance, values):\n        if not values[0]:\n            return\n        _file = codecs.open(values[0], 'r', encoding='utf8')\n        self.codeinput.text = _file.read()\n        _file.close()\n\n    def change_lang(self, instance, l):\n        if l == 'KvLexer':\n            lx = KivyLexer()\n        else:\n            lx = lexers.get_lexer_by_name(lexers.LEXERS[l][2][0])\n        self.codeinput.lexer = lx\n\nif __name__ == '__main__':\n    CodeInputTest().run()\n", "path": "examples/widgets/codeinput.py"}]}