Merge branch 'master' of git+ssh://dcbw@crank.laptop.org/git/sugar
This commit is contained in:
		
						commit
						d57fe375b9
					
				| @ -16,7 +16,7 @@ class LogWriter: | |||||||
| 		self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Logger') | 		self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Logger') | ||||||
| 			 | 			 | ||||||
| 	def start(self): | 	def start(self): | ||||||
| 		if os.environ.has_key('SUGAR_USE_CONSOLE') and self._use_console: | 		if self._use_console: | ||||||
| 			sys.stdout = self | 			sys.stdout = self | ||||||
| 			sys.stderr = self | 			sys.stderr = self | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,41 +1,59 @@ | |||||||
| import os | import os | ||||||
|  | import signal | ||||||
| from ConfigParser import ConfigParser | from ConfigParser import ConfigParser | ||||||
| 
 | 
 | ||||||
| import pygtk | import pygtk | ||||||
| pygtk.require('2.0') | pygtk.require('2.0') | ||||||
| import gtk | import gtk | ||||||
| 
 | 
 | ||||||
| from sugar.shell import shell | from sugar.shell.shell import Shell | ||||||
| from sugar import env | from sugar import env | ||||||
| 
 | 
 | ||||||
| def start(): | class Session: | ||||||
| 	shell.main() | 	def __init__(self): | ||||||
|  | 		self._activity_processes = {} | ||||||
| 
 | 
 | ||||||
| 	activities = [] | 	def start(self): | ||||||
|  | 		shell = Shell() | ||||||
|  | 		shell.connect('close', self._shell_close_cb) | ||||||
|  | 		shell.start() | ||||||
| 
 | 
 | ||||||
| 	activities_dirs = [] | 		activities = [] | ||||||
|  | 		activities_dirs = [] | ||||||
| 		 | 		 | ||||||
| 	for data_dir in env.get_data_dirs(): | 		for data_dir in env.get_data_dirs(): | ||||||
| 		act_dir = os.path.join(data_dir, env.get_activities_dir()) | 			act_dir = os.path.join(data_dir, env.get_activities_dir()) | ||||||
| 		activities_dirs.append(act_dir) | 			activities_dirs.append(act_dir) | ||||||
| 
 | 
 | ||||||
| 	activities_dirs.append(os.path.join(env.get_user_dir(), 'activities')) | 		activities_dirs.append(os.path.join(env.get_user_dir(), 'activities')) | ||||||
| 		 | 		 | ||||||
| 	for activities_dir in activities_dirs: | 		for activities_dir in activities_dirs: | ||||||
| 		if os.path.isdir(activities_dir): | 			if os.path.isdir(activities_dir): | ||||||
| 			for filename in os.listdir(activities_dir): | 				for filename in os.listdir(activities_dir): | ||||||
| 				if filename.endswith(".activity"): | 					if filename.endswith(".activity"): | ||||||
| 					path = os.path.join(activities_dir, filename) | 						path = os.path.join(activities_dir, filename) | ||||||
| 					cp = ConfigParser() | 						cp = ConfigParser() | ||||||
| 					cp.read([path]) | 						cp.read([path]) | ||||||
| 					python_class = cp.get('Activity', "python_class") | 						python_class = cp.get('Activity', "python_class") | ||||||
| 					activities.append(python_class) | 						activities.append(python_class) | ||||||
| 
 | 
 | ||||||
| 	for activity in activities: | 		for activity in activities: | ||||||
| 		args = [ 'python', '-m', activity ] | 			args = [ 'python', '-m', activity ] | ||||||
| 		os.spawnvp(os.P_NOWAIT, 'python', args) | 			pid = os.spawnvp(os.P_NOWAIT, 'python', args) | ||||||
|  | 			self._activity_processes[activity] = pid | ||||||
| 
 | 
 | ||||||
| 	try: | 		try: | ||||||
| 		gtk.main() | 			gtk.main() | ||||||
| 	except KeyboardInterrupt: | 		except KeyboardInterrupt: | ||||||
| 		print 'Ctrl+C pressed, exiting...' | 			print 'Ctrl+C pressed, exiting...' | ||||||
|  | 			self.shutdown() | ||||||
|  | 			 | ||||||
|  | 	def _shell_close_cb(self, shell): | ||||||
|  | 		self.shutdown() | ||||||
|  | 	 | ||||||
|  | 	def shutdown(self): | ||||||
|  | 		# FIXME Obviously we want to notify the activities to | ||||||
|  | 		# shutt down rather then killing them down forcefully. | ||||||
|  | 		for name in self._activity_processes.keys(): | ||||||
|  | 			print 'Shutting down %s' % (name)  | ||||||
|  | 			os.kill(self._activity_processes[name], signal.SIGTERM) | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ class WindowManager: | |||||||
| 	def set_position(self, position): | 	def set_position(self, position): | ||||||
| 		self._position = position | 		self._position = position | ||||||
| 
 | 
 | ||||||
| 	def _update_size_and_position(self): | 	def _calc_size_and_position(self): | ||||||
| 		screen_width = self._window.get_screen().get_width() | 		screen_width = self._window.get_screen().get_width() | ||||||
| 		screen_height = self._window.get_screen().get_height() | 		screen_height = self._window.get_screen().get_height() | ||||||
| 		 | 		 | ||||||
| @ -69,20 +69,30 @@ class WindowManager: | |||||||
| 			height = int(screen_height * self._height) | 			height = int(screen_height * self._height) | ||||||
| 			 | 			 | ||||||
| 		if self._position is WindowManager.CENTER: | 		if self._position is WindowManager.CENTER: | ||||||
| 			x = int((screen_width - width) / 2) | 			self._x = int((screen_width - width) / 2) | ||||||
| 			y = int((screen_height - height) / 2) | 			self._y = int((screen_height - height) / 2) | ||||||
| 		elif self._position is WindowManager.LEFT: | 		elif self._position is WindowManager.LEFT: | ||||||
| 			x = - int((1.0 - self._sliding_pos) * width) | 			self._x = - int((1.0 - self._sliding_pos) * width) | ||||||
| 			y = int((screen_height - height) / 2) | 			self._y = int((screen_height - height) / 2) | ||||||
| 		elif self._position is WindowManager.TOP: | 		elif self._position is WindowManager.TOP: | ||||||
| 			x = int((screen_width - width) / 2) | 			self._x = int((screen_width - width) / 2) | ||||||
| 			y = - int((1.0 - self._sliding_pos) * height) | 			self._y = - int((1.0 - self._sliding_pos) * height) | ||||||
| 		 | 		 | ||||||
| 		self._window.move(x, y) | 		self._real_width = width | ||||||
| 		self._window.resize(width, height) | 		self._real_height = height | ||||||
|  | 	 | ||||||
|  | 	def _update_size_and_position(self): | ||||||
|  | 		self._calc_size_and_position() | ||||||
|  | 		self._window.move(self._x, self._y) | ||||||
|  | 		self._window.resize(self._real_width, self._real_height) | ||||||
|  | 
 | ||||||
|  | 	def _update_position(self): | ||||||
|  | 		self._calc_size_and_position() | ||||||
|  | 		self._window.move(self._x, self._y) | ||||||
| 
 | 
 | ||||||
| 	def __slide_in_timeout_cb(self): | 	def __slide_in_timeout_cb(self): | ||||||
| 		self._window.show() | 		if self._sliding_pos == 0: | ||||||
|  | 			self._window.show() | ||||||
| 
 | 
 | ||||||
| 		left = 1.0 - self._sliding_pos | 		left = 1.0 - self._sliding_pos | ||||||
| 		self._sliding_pos += (left / 2) | 		self._sliding_pos += (left / 2) | ||||||
| @ -90,7 +100,7 @@ class WindowManager: | |||||||
| 		if self._sliding_pos > .999: | 		if self._sliding_pos > .999: | ||||||
| 			self._sliding_pos = 1.0 | 			self._sliding_pos = 1.0 | ||||||
| 
 | 
 | ||||||
| 		self._update_size_and_position() | 		self._update_position() | ||||||
| 
 | 
 | ||||||
| 		if self._sliding_pos == 1.0: | 		if self._sliding_pos == 1.0: | ||||||
| 			return False | 			return False | ||||||
| @ -106,7 +116,7 @@ class WindowManager: | |||||||
| 		if self._sliding_pos < .001: | 		if self._sliding_pos < .001: | ||||||
| 			self._sliding_pos = 0 | 			self._sliding_pos = 0 | ||||||
| 
 | 
 | ||||||
| 		self._update_size_and_position() | 		self._update_position() | ||||||
| 
 | 
 | ||||||
| 		if self._sliding_pos == 0: | 		if self._sliding_pos == 0: | ||||||
| 			self._window.hide() | 			self._window.hide() | ||||||
|  | |||||||
| @ -472,31 +472,44 @@ class ConsoleLogger(dbus.service.Object): | |||||||
| 		buf = console.get_buffer()  | 		buf = console.get_buffer()  | ||||||
| 		buf.insert(buf.get_end_iter(), message) | 		buf.insert(buf.get_end_iter(), message) | ||||||
| 
 | 
 | ||||||
| def main(): | class Shell(gobject.GObject): | ||||||
| 	console = ConsoleLogger() | 	__gsignals__ = { | ||||||
|  | 		'close': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, | ||||||
|  | 				 ([])), | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	log_writer = LogWriter("Shell", False) | 	def __init__(self): | ||||||
| 	log_writer.start() | 		gobject.GObject.__init__(self) | ||||||
| 
 | 
 | ||||||
| 	session_bus = dbus.SessionBus() | 	def start(self): | ||||||
| 	service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus) | 		console = ConsoleLogger() | ||||||
| 
 | 
 | ||||||
| 	activity_container = ActivityContainer(service, session_bus) | 		log_writer = LogWriter("Shell", False) | ||||||
| 	activity_container.show() | 		log_writer.start() | ||||||
| 
 | 
 | ||||||
| 	wm = WindowManager(activity_container.window) | 		session_bus = dbus.SessionBus() | ||||||
| 	wm.set_width(640, WindowManager.ABSOLUTE) | 		service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus) | ||||||
| 	wm.set_height(480, WindowManager.ABSOLUTE) |  | ||||||
| 	wm.set_position(WindowManager.CENTER) |  | ||||||
| 	wm.show() |  | ||||||
| 	wm.manage() |  | ||||||
| 
 | 
 | ||||||
| 	console.set_parent_window(activity_container.window) | 		activity_container = ActivityContainer(service, session_bus) | ||||||
|  | 		activity_container.window.connect('destroy', self.__activity_container_destroy_cb) | ||||||
|  | 		activity_container.show() | ||||||
|  | 
 | ||||||
|  | 		wm = WindowManager(activity_container.window) | ||||||
|  | 		wm.set_width(640, WindowManager.ABSOLUTE) | ||||||
|  | 		wm.set_height(480, WindowManager.ABSOLUTE) | ||||||
|  | 		wm.set_position(WindowManager.CENTER) | ||||||
|  | 		wm.show() | ||||||
|  | 		wm.manage() | ||||||
|  | 		 | ||||||
|  | 		console.set_parent_window(activity_container.window) | ||||||
|  | 
 | ||||||
|  | 	def __activity_container_destroy_cb(self, activity_container): | ||||||
|  | 		self.emit('close') | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
| 	main() | 	shell = Shell() | ||||||
|  | 	shell.start() | ||||||
| 	try: | 	try: | ||||||
| 		gtk.main() | 		gtk.main() | ||||||
| 	except KeyboardInterrupt: | 	except KeyboardInterrupt: | ||||||
| 		print 'Ctrl+c pressed, exiting...' | 		print 'Ctrl+c pressed, exiting...' | ||||||
| 		pass |  | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								sugar/sugar
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								sugar/sugar
									
									
									
									
									
								
							| @ -62,8 +62,6 @@ if curdir == '.': | |||||||
| else: | else: | ||||||
| 	basedir = os.path.dirname(curdir) | 	basedir = os.path.dirname(curdir) | ||||||
| 
 | 
 | ||||||
| console = False |  | ||||||
| 
 |  | ||||||
| if os.path.isfile(os.path.join(curdir, '__uninstalled__.py')): | if os.path.isfile(os.path.join(curdir, '__uninstalled__.py')): | ||||||
| 	if basedir == '': | 	if basedir == '': | ||||||
| 		print 'Running sugar from current directory...' | 		print 'Running sugar from current directory...' | ||||||
| @ -71,18 +69,16 @@ if os.path.isfile(os.path.join(curdir, '__uninstalled__.py')): | |||||||
| 		print 'Running sugar from ' + basedir + ' ...' | 		print 'Running sugar from ' + basedir + ' ...' | ||||||
| 	add_to_python_path(basedir) | 	add_to_python_path(basedir) | ||||||
| 	add_to_python_path(os.path.join(basedir, 'cut-n-paste')) | 	add_to_python_path(os.path.join(basedir, 'cut-n-paste')) | ||||||
| 	console = True |  | ||||||
| else: | else: | ||||||
| 	print 'Running the installed sugar...' | 	print 'Running the installed sugar...' | ||||||
| 	 | 	 | ||||||
| add_to_python_path(os.path.expanduser('~/.sugar/activities')) | add_to_python_path(os.path.expanduser('~/.sugar/activities')) | ||||||
| 
 | 
 | ||||||
| if console: | print 'Redirecting output to the console, press ctrl+d to open it.' | ||||||
| 	os.environ['SUGAR_USE_CONSOLE'] = 'yes' |  | ||||||
| 	print 'Redirecting output to the console, press ctrl+d to open it.' |  | ||||||
| 	 | 	 | ||||||
| from sugar.session import session | from sugar.session.session import Session | ||||||
| 
 | 
 | ||||||
|  | session = Session() | ||||||
| session.start() | session.start() | ||||||
| 
 | 
 | ||||||
| if dbus_daemon_pid: | if dbus_daemon_pid: | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Dan Williams
						Dan Williams