~ubuntu-branches/debian/stretch/electrum/stretch

« back to all changes in this revision

Viewing changes to gui/kivy/tools/.buildozer/android/platform/python-for-android/dist/kivy/python-install/share/kivy-examples/frameworks/twisted/twistd_app.py

  • Committer: Package Import Robot
  • Author(s): Tristan Seligmann
  • Date: 2016-04-04 03:02:39 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20160404030239-0szgkio8yryjv7c9
Tags: 2.6.3-1
* New upstream release.
  - Drop backported install-wizard-connect.patch.
* Add Suggests: python-zbar and update the installation hint to suggest
  apt-get instead of pip (closes: #819517).
* Bump Standards-Version to 3.9.7 (no changes).
* Update Vcs-* links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from kivy.support import install_twisted_reactor
 
2
install_twisted_reactor()
 
3
 
 
4
import os
 
5
import sys
 
6
 
 
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
 
11
 
 
12
from twisted.scripts._twistd_unix import UnixApplicationRunner, ServerOptions
 
13
from twisted.application.service import IServiceCollection
 
14
 
 
15
TWISTD = 'twistd web -p 8087'
 
16
 
 
17
 
 
18
class AndroidApplicationRunner(UnixApplicationRunner):
 
19
 
 
20
    def run(self):
 
21
 
 
22
        self.preApplication()
 
23
        self.application = self.createOrGetApplication()
 
24
        self.logger.start(self.application)
 
25
        sc = IServiceCollection(self.application)
 
26
 
 
27
        # reactor is already running, so we just start the service collection
 
28
        sc.startService()
 
29
        return self.application
 
30
 
 
31
 
 
32
Builder.load_string('''
 
33
<TwistedTwistd>:
 
34
    cols: 1
 
35
    Button:
 
36
        text: root.running and 'STOP' or 'START'
 
37
        on_release: root.cb_twistd()
 
38
''')
 
39
 
 
40
 
 
41
class TwistedTwistd(GridLayout):
 
42
 
 
43
    running = BooleanProperty(False)
 
44
 
 
45
    def cb_twistd(self, *la):
 
46
 
 
47
        if self.running:
 
48
            IServiceCollection(self.app).stopService()
 
49
            self.running = False
 
50
        else:
 
51
            sys.exc_clear()
 
52
            sys.path.insert(0, os.path.abspath(os.getcwd()))
 
53
            sys.argv = TWISTD.split(' ')
 
54
            config = ServerOptions()
 
55
            config.parseOptions()
 
56
            self.app = AndroidApplicationRunner(config).run()
 
57
            self.running = True
 
58
 
 
59
 
 
60
class TwistedTwistdApp(App):
 
61
 
 
62
    def build(self):
 
63
        return TwistedTwistd()
 
64
 
 
65
 
 
66
if __name__ == '__main__':
 
67
    TwistedTwistdApp().run()