diff --git a/examples/widgets/codeinput.py b/examples/widgets/codeinput.py new file mode 100644 index 000000000..0cfd972cf --- /dev/null +++ b/examples/widgets/codeinput.py @@ -0,0 +1,83 @@ +from kivy.app import App +from kivy.extras.highlight import KivyLexer +from kivy.uix.codeinput import CodeInput +from kivy.factory import Factory +import pygments + +example_text = ''' +---------------------Python---------------------------------- +import kivy +kivy.require('1.0.6') # replace with your current kivy version ! +from kivy.app import App +from kivy.uix.button import Button + +class MyApp(App): + def build(self): + return Button(text='Hello World') + +if __name__ == '__main__': + MyApp().run() +----------------------Java------------------------------------ + +public static byte toUnsignedByte(int intVal) { + byte byteVal; + return (byte)(intVal & 0xFF); +} +---------------------kv lang------------------------- +#:kivy 1.0 + +: + canvas: + Color: + rgb: .5, .5, .5 + Rectangle: + pos: self.pos + size: self.size +-----------------HTML----------------------------- + +
+ + + +''' + + +class CodeInputTest(App): + def build(self): + b = Factory.BoxLayout(orientation='vertical') + languages = Factory.Spinner( + text='language', + values=sorted(['KvLexer', ] + pygments.lexers.LEXERS.keys()), + size_hint_y=None, + height='30pt') + + languages.bind(text=self.change_lang) + b.add_widget(languages) + + self.codeinput = CodeInput( + lexer=KivyLexer(), + font_name='data/fonts/DroidSansMono.ttf', font_size=12, + text=example_text) + + b.add_widget(self.codeinput) + + return b + + def change_lang(self, instance, l): + if l == 'KvLexer': + lx = KivyLexer() + + else: + lx = pygments.lexers.get_lexer_by_name( + pygments.lexers.LEXERS[l][2][0]) + + self.codeinput.lexer = lx + + +CodeInputTest().run()