Refactor startup. In progress, give me a couple hours.
For now start sugar with "sugar-emulator shell/sugar-shell"
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
SUBDIRS = conf data model view
|
||||
|
||||
bin_SCRIPTS = \
|
||||
sugar \
|
||||
sugar-shell \
|
||||
sugar-activity \
|
||||
sugar-activity-factory \
|
||||
sugar-console
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar.graphics import iconcolor
|
||||
from sugar import env
|
||||
|
||||
class _Profile:
|
||||
def __init__(self,):
|
||||
self._path = env.get_profile_path()
|
||||
self._nick_name = None
|
||||
self._color = iconcolor.IconColor()
|
||||
|
||||
self._ensure_dirs()
|
||||
|
||||
cp = ConfigParser()
|
||||
parsed = cp.read([self._get_config_path()])
|
||||
|
||||
if cp.has_option('Buddy', 'NickName'):
|
||||
self._nick_name = cp.get('Buddy', 'NickName')
|
||||
if cp.has_option('Buddy', 'Color'):
|
||||
color = cp.get('Buddy', 'Color')
|
||||
if iconcolor.is_valid(color):
|
||||
self._color = iconcolor.IconColor(color)
|
||||
|
||||
def _ensure_dirs(self):
|
||||
try:
|
||||
os.makedirs(self._path)
|
||||
except OSError, exc:
|
||||
if exc[0] != 17: # file exists
|
||||
print "Could not create user directory."
|
||||
|
||||
def get_color(self):
|
||||
return self._color
|
||||
|
||||
def set_color(self, color):
|
||||
self._color = color
|
||||
|
||||
def get_nick_name(self):
|
||||
return self._nick_name
|
||||
|
||||
def set_nick_name(self, nick_name):
|
||||
self._nick_name = nick_name
|
||||
|
||||
def get_path(self):
|
||||
return self._path
|
||||
|
||||
def save(self):
|
||||
cp = ConfigParser()
|
||||
|
||||
section = 'Buddy'
|
||||
cp.add_section(section)
|
||||
cp.set(section, 'NickName', self._nick_name)
|
||||
cp.set(section, 'Color', self._color.to_string())
|
||||
|
||||
fileobject = open(self._get_config_path(), 'w')
|
||||
cp.write(fileobject)
|
||||
fileobject.close()
|
||||
|
||||
def _get_config_path(self):
|
||||
return os.path.join(self._path, 'config')
|
||||
@@ -1,11 +1,6 @@
|
||||
from conf.ActivityRegistry import _ActivityRegistry
|
||||
from conf.Profile import _Profile
|
||||
|
||||
__registry = _ActivityRegistry()
|
||||
__profile = _Profile()
|
||||
_activity_registry = _ActivityRegistry()
|
||||
|
||||
def get_activity_registry():
|
||||
return __registry
|
||||
|
||||
def get_profile():
|
||||
return __profile
|
||||
return _activity_registry
|
||||
|
||||
@@ -18,15 +18,15 @@ import os
|
||||
import random
|
||||
import base64
|
||||
import time
|
||||
|
||||
import conf
|
||||
from sugar import env
|
||||
import logging
|
||||
import dbus
|
||||
|
||||
from sugar import env
|
||||
from sugar import profile
|
||||
from sugar.p2p import Stream
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import util
|
||||
from model.Invites import Invites
|
||||
import dbus
|
||||
|
||||
PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
|
||||
|
||||
@@ -35,10 +35,8 @@ class ShellOwner(object):
|
||||
runs in the shell and serves up the buddy icon and other stuff. It's the
|
||||
server portion of the Owner, paired with the client portion in Buddy.py."""
|
||||
def __init__(self):
|
||||
profile = conf.get_profile()
|
||||
|
||||
self._nick = profile.get_nick_name()
|
||||
user_dir = profile.get_path()
|
||||
user_dir = env.get_profile_path()
|
||||
|
||||
self._icon = None
|
||||
self._icon_hash = ""
|
||||
@@ -71,7 +69,7 @@ class ShellOwner(object):
|
||||
|
||||
def announce(self):
|
||||
# Create and announce our presence
|
||||
color = conf.get_profile().get_color()
|
||||
color = profile.get_color()
|
||||
props = {'color': color.to_string(), 'icon-hash': self._icon_hash}
|
||||
self._service = self._pservice.register_service(self._nick,
|
||||
PRESENCE_SERVICE_TYPE, properties=props)
|
||||
|
||||
@@ -16,33 +16,27 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
import gtk
|
||||
|
||||
curdir = os.path.abspath(os.path.dirname(__file__))
|
||||
sourcedir = os.path.dirname(curdir)
|
||||
from sugar import profile
|
||||
from sugar import TracebackUtils
|
||||
from view.FirstTimeDialog import FirstTimeDialog
|
||||
from view.Shell import Shell
|
||||
from model.ShellModel import ShellModel
|
||||
|
||||
if os.path.isfile(os.path.join(sourcedir, 'sugar/__uninstalled__.py')):
|
||||
print 'Running sugar from ' + sourcedir + ' ...'
|
||||
sys.path.insert(0, sourcedir)
|
||||
else:
|
||||
print 'Running the installed sugar...'
|
||||
name = profile.get_nick_name()
|
||||
if not name or not len(name):
|
||||
dialog = FirstTimeDialog()
|
||||
dialog.run()
|
||||
|
||||
from sugar import env
|
||||
model = ShellModel()
|
||||
shell = Shell(model)
|
||||
|
||||
env.setup_system()
|
||||
|
||||
from sugar.session.Emulator import Emulator
|
||||
|
||||
if os.environ.has_key('SUGAR_EMULATOR') and \
|
||||
os.environ['SUGAR_EMULATOR'] == 'yes':
|
||||
emulator = Emulator()
|
||||
emulator.start()
|
||||
|
||||
from Session import Session
|
||||
|
||||
session = Session()
|
||||
session.start()
|
||||
tbh = TracebackUtils.TracebackHelper()
|
||||
try:
|
||||
gtk.main()
|
||||
except KeyboardInterrupt:
|
||||
print 'Ctrl+C pressed, exiting...'
|
||||
del tbh
|
||||
@@ -18,6 +18,7 @@ import gtk
|
||||
import dbus
|
||||
|
||||
import conf
|
||||
from sugar import profile
|
||||
from sugar.activity import Activity
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
@@ -92,7 +93,7 @@ class ActivityHost:
|
||||
if activity != None:
|
||||
return IconColor(activity.get_color())
|
||||
else:
|
||||
return conf.get_profile().get_color()
|
||||
return profile.get_color()
|
||||
|
||||
def share(self):
|
||||
self._activity.share()
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import gtk
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
import gtk
|
||||
from gettext import gettext as _
|
||||
|
||||
import conf
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
from sugar import env
|
||||
|
||||
class FirstTimeDialog(gtk.Dialog):
|
||||
def __init__(self):
|
||||
@@ -37,22 +40,24 @@ class FirstTimeDialog(gtk.Dialog):
|
||||
self._ok = gtk.Button(None, gtk.STOCK_OK)
|
||||
self._ok.set_sensitive(False)
|
||||
self.vbox.pack_start(self._ok)
|
||||
self._ok.connect('clicked', self.__ok_button_clicked_cb)
|
||||
self._ok.connect('clicked', self._ok_button_clicked_cb)
|
||||
self._ok.show()
|
||||
|
||||
def _entry_changed_cb(self, entry):
|
||||
valid = (len(entry.get_text()) > 0)
|
||||
self._ok.set_sensitive(valid)
|
||||
|
||||
def __ok_button_clicked_cb(self, button):
|
||||
profile = conf.get_profile()
|
||||
profile.set_nick_name(self._entry.get_text())
|
||||
self.destroy()
|
||||
def _ok_button_clicked_cb(self, button):
|
||||
cp = ConfigParser()
|
||||
|
||||
def get_profile():
|
||||
profile = conf.get_profile()
|
||||
if profile.get_nick_name() == None:
|
||||
dialog = FirstTimeDialog()
|
||||
dialog.connect('destroy', self.__first_time_dialog_destroy_cb)
|
||||
dialog.show()
|
||||
return profile
|
||||
section = 'Buddy'
|
||||
cp.add_section(section)
|
||||
cp.set(section, 'NickName', self._entry.get_text())
|
||||
cp.set(section, 'Color', IconColor().to_string())
|
||||
|
||||
config_path = os.path.join(env.get_profile_path(), 'config')
|
||||
fileobject = open(config_path, 'w')
|
||||
cp.write(fileobject)
|
||||
fileobject.close()
|
||||
|
||||
self.destroy()
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
import conf
|
||||
from sugar import profile
|
||||
|
||||
class MyIcon(CanvasIcon):
|
||||
def __init__(self):
|
||||
profile = conf.get_profile()
|
||||
CanvasIcon.__init__(self, icon_name='stock-buddy',
|
||||
color=profile.get_color())
|
||||
|
||||
Reference in New Issue
Block a user