Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Last active February 1, 2021 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixtyfive/ab24550182dfac24ed293a9ee290685f to your computer and use it in GitHub Desktop.
Save sixtyfive/ab24550182dfac24ed293a9ee290685f to your computer and use it in GitHub Desktop.
#!/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