1
from kivy.support import install_twisted_reactor
2
install_twisted_reactor()
7
from kivy.app import App
8
from kivy.uix.gridlayout import GridLayout
9
from kivy.properties import BooleanProperty
10
from kivy.lang import Builder
12
from twisted.scripts._twistd_unix import UnixApplicationRunner, ServerOptions
13
from twisted.application.service import IServiceCollection
15
TWISTD = 'twistd web -p 8087'
18
class AndroidApplicationRunner(UnixApplicationRunner):
23
self.application = self.createOrGetApplication()
24
self.logger.start(self.application)
25
sc = IServiceCollection(self.application)
27
# reactor is already running, so we just start the service collection
29
return self.application
32
Builder.load_string('''
36
text: root.running and 'STOP' or 'START'
37
on_release: root.cb_twistd()
41
class TwistedTwistd(GridLayout):
43
running = BooleanProperty(False)
45
def cb_twistd(self, *la):
48
IServiceCollection(self.app).stopService()
52
sys.path.insert(0, os.path.abspath(os.getcwd()))
53
sys.argv = TWISTD.split(' ')
54
config = ServerOptions()
56
self.app = AndroidApplicationRunner(config).run()
60
class TwistedTwistdApp(App):
63
return TwistedTwistd()
66
if __name__ == '__main__':
67
TwistedTwistdApp().run()