Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/example-activity/example-activity.py
blob: 05ce55af6c107b35bed0d07a27f781ba7fe19efc (plain)
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
#!/usr/bin/python
# -*- tab-width: 4; indent-tabs-mode: t -*- 

import string

import gc
import dbus
import dbus.service
import dbus.glib
import gobject
import pygtk
pygtk.require('2.0')
import gtk,sys

import activity

def my_exit():
	sys.exit(0)

def deferred_exit():
	gobject.timeout_add(0, my_exit)

################################################################################

class ExampleActivity(activity.Activity):

	def __init__(self, name):
		self.name = name

	def entry_changed(self, entry):
		self.activity_set_tab_text(entry.get_text())
	
	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.name)

		plug = self.activity_get_gtk_plug()
		self.entry = gtk.Entry()
		self.entry.set_text(self.name)
		self.entry.connect("changed", self.entry_changed)
		plug.add(self.entry)
		plug.show_all()

	    icon_theme = gtk.icon_theme_get_default()
		pixbuf = icon_theme.load_icon("gnome-dev-cdrom", gtk.ICON_SIZE_MENU, gtk.ICON_LOOKUP_USE_BUILTIN)
		self.activity_set_icon(pixbuf)
		self.activity_show_icon(True)

	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()

	def __del__(self):
		print "in __del__ for ExampleActivity"


if len(sys.argv) != 2:
	print "usage: example-activity.py <name_of_activity>"
	sys.exit(1)

gc.set_debug(gc.DEBUG_LEAK)

example_activity = ExampleActivity(sys.argv[1])
example_activity.activity_connect_to_shell()
example_activity = None

gtk.main()