-
-
Save sixtyfive/ab24550182dfac24ed293a9ee290685f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import kivy | |
kivy.require('2.0.0') | |
from kivy.lang import Builder | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.app import App | |
from kivy.properties import ObjectProperty, StringProperty | |
import subprocess as sp | |
ruby = sp.run(['which', 'ruby'], capture_output=True).stdout.strip() | |
kv = """ | |
<MainScreen>: | |
orientation: 'vertical' | |
TextInput: | |
on_text: root.process(self.text) | |
TextInput: | |
id: output | |
""" | |
Builder.load_string(kv) | |
class MainScreen(BoxLayout): | |
pass | |
def process(self, yaml): | |
global ruby | |
code = f"print YAML.load('{yaml}').to_yaml.sub(/---\\n?/, '')" | |
res = sp.run([ruby, '-ryaml', '-e', code], capture_output=True) | |
outfield = self.ids.output | |
if res.stdout: | |
utf8_str = res.stdout.decode('UTF-8') | |
print(utf8_str) | |
outfield.text = utf8_str.strip() | |
outfield.foreground_color = (.17,.37,0, 1) | |
elif res.stderr: | |
outfield.text = res.stderr.strip() | |
outfield.foreground_color = (.67,0,.3, 1) | |
class YAMLTest(App): | |
def build(self): | |
return MainScreen() | |
if __name__ == '__main__': | |
YAMLTest().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment