Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.boxlayout import BoxLayout
- from kivy.properties import ObjectProperty
- import sys
- if sys.platform == 'win32':
- import winpexpect
- elif sys.platform == 'linux' or sys.platform == 'linux32':
- import pexpect
- from multiprocessing import Process, Queue
- Builder.load_string('''
- #:kivy 1.8.0
- <RootWidget>:
- label_text: label_text
- Label:
- id: label_text
- text: 'initial'
- ''')
- def puthello(q):
- if sys.platform == 'win32':
- child = winpexpect.winspawn("cmd", timeout=9000)
- elif sys.platform == 'linux' or sys.platform == 'linux32':
- child = pexpect.spawn("cmd", timeout=9000)
- while True:
- child.sendline('echo hello')
- child.expect('\r\n')
- q.put(child.before+child.after)
- class RootWidget(BoxLayout):
- """Root Kivy widget class"""
- label_text = ObjectProperty()
- q = Queue()
- p = Process(target=puthello, args=(q,))
- def __init__(self):
- super(RootWidget, self).__init__()
- self.launchprocess()
- def launchprocess(self):
- self.p.start()
- while True:
- print self.q.get()
- self.label_text.text = self.q.get()
- class ExampleApp(App):
- def build(self):
- return RootWidget()
- if __name__ == '__main__':
- ExampleApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement