Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 33545aa0346a7216257e3af870da888926730d59

  • avatar
  • Marco Pesenti Gritti <mpg @red…at.com>
  • Fri Apr 21 16:25:34 EDT 2006
Use activity.py
  
1010
1111import geckoembed
1212
13################################################################################
14# Code below will be moved to a module someday
13import sys
14sys.path.append('../shell/example-activity/')
15import activity
1516
16class Activity(dbus.service.Object):
17
18 def __init__(self):
19 pass
20
21 def name_owner_changed(self, service_name, old_service_name, new_service_name):
22 #print "in name_owner_changed: svc=%s oldsvc=%s newsvc=%s"%(service_name, old_service_name, new_service_name)
23 if service_name == "com.redhat.Sugar.Shell" and new_service_name == "":
24 self.activity_on_disconnected_from_shell()
25 #elif service_name == "com.redhat.Sugar.Shell" and old_service_name == "":
26 # self.activity_on_shell_reappeared()
27
28 def activity_connect_to_shell(self):
29 self.__bus = dbus.SessionBus()
30
31 self.__bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
32
33 self.__activity_container_object = self.__bus.get_object("com.redhat.Sugar.Shell", \
34 "/com/redhat/Sugar/Shell/ActivityContainer")
35 self.__activity_container = dbus.Interface(self.__activity_container_object, \
36 "com.redhat.Sugar.Shell.ActivityContainer")
37
38 self.__activity_id = self.__activity_container.add_activity("")
39 self.__object_path = "/com/redhat/Sugar/Shell/Activities/%d"%self.__activity_id
40
41 print "object_path = %s"%self.__object_path
42
43 self.__activity_object = dbus.Interface(self.__bus.get_object("com.redhat.Sugar.Shell", self.__object_path), \
44 "com.redhat.Sugar.Shell.ActivityHost")
45 self.__window_id = self.__activity_object.get_host_xembed_id()
46
47 print "XEMBED window_id = %d"%self.__window_id
48
49 self.__plug = gtk.Plug(self.__window_id)
50
51 # Now let the Activity register a peer service so the Shell can poke it
52 self.__peer_service_name = "com.redhat.Sugar.Activity%d"%self.__activity_id
53 self.__peer_object_name = "/com/redhat/Sugar/Activity/%d"%self.__activity_id
54 self.__service = dbus.service.BusName(self.__peer_service_name, bus=self.__bus)
55 dbus.service.Object.__init__(self, self.__service, self.__peer_object_name)
56
57 self.__activity_object.set_peer_service_name(self.__peer_service_name, self.__peer_object_name)
58
59 self.activity_on_connected_to_shell()
60
61 def activity_get_gtk_plug(self):
62 return self.__plug
63
64 def activity_set_can_close(self, can_close):
65 self.__activity_object.set_can_close(can_close)
66
67 @dbus.service.method("com.redhat.Sugar.Activity", \
68 in_signature="", \
69 out_signature="")
70
71 def activity_set_tab_text(self, text):
72 self.__activity_object.set_tab_text(text)
73
74 @dbus.service.method("com.redhat.Sugar.Activity", \
75 in_signature="", \
76 out_signature="")
77 def lost_focus(self):
78 self.activity_on_lost_focus()
79
80 @dbus.service.method("com.redhat.Sugar.Activity", \
81 in_signature="", \
82 out_signature="")
83 def got_focus(self):
84 self.activity_on_got_focus()
85
86
87 @dbus.service.method("com.redhat.Sugar.Activity", \
88 in_signature="", \
89 out_signature="")
90 def close_from_user(self):
91 self.activity_on_close_from_user()
92
93 def activity_get_id(self):
94 return self.__activity_id
95
96
97 def __shutdown_reply_cb(self):
98 print "in __reply_cb"
99
100 self.__plug.destroy()
101 self.__plug = None
102
103 self.__bus = None
104 self.__activity_container_object = None
105 self.__activity_container = None
106 self.__activity_object = None
107 self.__service = None
108
109 self.__bus.remove_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
110
111 self.activity_on_disconnected_from_shell()
112
113
114 del self
115
116
117
118 def __shutdown_error_cb(self, error):
119 print "in __error_cb"
120
121 def activity_shutdown(self):
122 self.__activity_object.shutdown(reply_handler = self.__shutdown_reply_cb, error_handler = self.__shutdown_error_cb)
123
124 # pure virtual methods
125
126 def activity_on_connected_to_shell(self):
127 print "act %d: you need to override activity_on_connected_to_shell"%self.activity_get_id()
128
129 def activity_on_disconnected_from_shell(self):
130 print "act %d: you need to override activity_on_disconnected_from_shell"%self.activity_get_id()
131
132 def activity_on_close_from_user(self):
133 print "act %d: you need to override activity_on_close_from_user"%self.activity_get_id()
134
135 def activity_on_lost_focus(self):
136 print "act %d: you need to override activity_on_lost_focus"%self.activity_get_id()
137
138 def activity_on_got_focus(self):
139 print "act %d: you need to override activity_on_got_focus"%self.activity_get_id()
140
141def my_exit():
142 sys.exit(0)
143
144def deferred_exit():
145 gobject.timeout_add(0, my_exit)
146
147################################################################################
148
14917class AddressToolbar(gtk.Toolbar):
15018 def __init__(self):
15119 gtk.Toolbar.__init__(self)
142142 def __open_address_cb(self, address):
143143 self.embed.load_url(address)
144144
145class BrowserActivity(Activity):
145class BrowserActivity(activity.Activity):
146146 def __init__(self, uri):
147 Activity.__init__(self)
147 activity.Activity.__init__(self)
148148 self.uri = uri
149149
150150 def activity_on_connected_to_shell(self):
176176 def activity_on_close_from_user(self):
177177 self.activity_shutdown()
178178
179class WebActivity(Activity):
179class WebActivity(activity.Activity):
180180 def __init__(self):
181 Activity.__init__(self)
181 activity.Activity.__init__(self)
182182
183183 def activity_on_connected_to_shell(self):
184184 self.activity_set_tab_text("Web Browser")
  
6060
6161 def activity_get_gtk_plug(self):
6262 return self.__plug
63
64 def activity_set_can_close(self, can_close):
65 self.__activity_object.set_can_close(can_close)
6366
67 @dbus.service.method("com.redhat.Sugar.Activity", \
68 in_signature="", \
69 out_signature="")
70
6471 def activity_set_tab_text(self, text):
6572 self.__activity_object.set_tab_text(text)
6673