1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#!/usr/bin/python -t
# -*- tab-width: 4; indent-tabs-mode: t -*-
import dbus
import dbus.service
import dbus.glib
import pygtk
pygtk.require('2.0')
import gtk, gobject
import sys
import os
import pwd
import gc
import socket
import types
import select
import string
import time
sys.path.append(os.getcwd())
sys.path.append('../shell/example-activity/')
import activity
XEPHYR_PATH = "/usr/bin/Xephyr"
MATCHBOX_PATH = "/usr/bin/matchbox-window-manager"
class LegacyActivity(activity.Activity):
def __init__(self, args):
activity.Activity.__init__(self)
self._act_name = os.path.basename(args[1])
self._display = 5
self._args = args[1:]
self._act_pid = None
self._matchbox_pid = None
self._xephyr_pid = None
def _xephyr_function(self, pid, condition, data=None):
print "Xephyr: PID: %d, condition: %s" % (pid, condition)
def _matchbox_function(self, pid, condition, data=None):
print "WM: PID: %d, condition: %s" % (pid, condition)
def _act_function(self, pid, condition, data=None):
print "ACT: PID: %d, condition: %s" % (pid, condition)
if condition == 0:
self._act_pid = None
gtk.main_quit()
def __key_press_event_cb(self, widget, event):
print event
def _start(self):
args = string.split("%s :%d -ac -parent %d -host-cursor" % (XEPHYR_PATH, self._display, self._plug.get_id()))
(self._xephyr_pid, a, b, c) = gobject.spawn_async(args, standard_output=sys.stdout, standard_error=sys.stderr)
self._xephyr_watch = gobject.child_watch_add(self._xephyr_pid, self._xephyr_function)
envp = ["DISPLAY=:%d" % self._display]
envp.append("INPUTRC=/etc/inputrc")
envp.append("XMODIFIERS=@im=SCIM")
envp.append("GTK_IM_MODULE=scim")
try:
envp.append("LANG=%s" % os.environ['LANG'])
except:
envp.append("LANG=en_US.UTF-8")
args = string.split("%s" % MATCHBOX_PATH)
(self._matchbox_pid, a, b, c) = gobject.spawn_async(args, envp=envp, standard_output=sys.stdout, standard_error=sys.stderr)
gobject.child_watch_add(self._matchbox_pid, self._matchbox_function)
args = [os.path.abspath(self._args[0])]
for arg in self._args[1:]:
args.append(arg)
(self._act_pid, a, b, c) = gobject.spawn_async(args, envp=envp, standard_output=sys.stdout, standard_error=sys.stderr)
gobject.child_watch_add(self._act_pid, self._act_function)
def activity_on_connected_to_shell(self):
print "act %d: in activity_on_connected_to_shell" % self.activity_get_id()
self.activity_set_tab_text(self._act_name)
self._plug = self.activity_get_gtk_plug()
self._plug.add_events(gtk.gdk.ALL_EVENTS_MASK)
self._plug.connect("key-press-event", self.__key_press_event_cb)
self._plug.show()
self._start()
self._plug.grab_focus()
def activity_on_disconnected_from_shell(self):
print "act %d: in activity_on_disconnected_from_shell"%self.activity_get_id()
print "act %d: Shell disappeared..."%self.activity_get_id()
gc.collect()
def activity_on_close_from_user(self):
print "act %d: in activity_on_close_from_user"%self.activity_get_id()
self.activity_shutdown()
def activity_on_lost_focus(self):
print "act %d: in activity_on_lost_focus"%self.activity_get_id()
def activity_on_got_focus(self):
print "act %d: in activity_on_got_focus"%self.activity_get_id()
self._plug.grab_focus()
def cleanup(self):
try:
if self._act_pid:
os.kill(self._act_pid, 9)
time.sleep(0.2)
if self._xephyr_pid:
os.kill(self._xephyr_pid, 9)
time.sleep(0.2)
if self._matchbox_pid:
os.kill(self._matchbox_pid, 9)
time.sleep(0.2)
except OSError, e:
pass
def run(self):
try:
gtk.main()
except KeyboardInterrupt:
pass
def main(args):
app = LegacyActivity(args)
app.activity_connect_to_shell()
app.run()
app.cleanup()
if __name__ == "__main__":
main(sys.argv)
|