Make conf private, expose the nick name from env
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import gtk
|
||||
import dbus
|
||||
|
||||
from sugar import conf
|
||||
import conf
|
||||
from sugar.activity import Activity
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sugar import conf
|
||||
import conf
|
||||
from sugar.chat.BuddyChat import BuddyChat
|
||||
from sugar.activity import ActivityFactory
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
+14
-14
@@ -2,35 +2,35 @@ import gtk
|
||||
|
||||
from gettext import gettext as _
|
||||
|
||||
from sugar import conf
|
||||
import conf
|
||||
|
||||
class FirstTimeDialog(gtk.Window):
|
||||
class FirstTimeDialog(gtk.Dialog):
|
||||
def __init__(self):
|
||||
gtk.Window.__init__(self)
|
||||
|
||||
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
||||
|
||||
vbox = gtk.VBox(False, 6)
|
||||
vbox.set_border_width(12)
|
||||
gtk.Dialog.__init__(self)
|
||||
|
||||
label = gtk.Label(_('Nick Name:'))
|
||||
label.set_alignment(0.0, 0.5)
|
||||
vbox.pack_start(label)
|
||||
self.vbox.pack_start(label)
|
||||
label.show()
|
||||
|
||||
self._entry = gtk.Entry()
|
||||
vbox.pack_start(self._entry)
|
||||
self.vbox.pack_start(self._entry)
|
||||
self._entry.show()
|
||||
|
||||
button = gtk.Button(None, gtk.STOCK_OK)
|
||||
vbox.pack_start(button)
|
||||
self.vbox.pack_start(button)
|
||||
button.connect('clicked', self.__ok_button_clicked_cb)
|
||||
button.show()
|
||||
|
||||
self.add(vbox)
|
||||
vbox.show()
|
||||
|
||||
def __ok_button_clicked_cb(self, button):
|
||||
profile = conf.get_profile()
|
||||
profile.set_nick_name(self._entry.get_text())
|
||||
self.destroy()
|
||||
|
||||
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
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
import gobject
|
||||
|
||||
import conf
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar import conf
|
||||
|
||||
class Invite:
|
||||
def __init__(self, issuer, bundle_id, activity_id):
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
SUBDIRS = data session frame home PresenceService
|
||||
SUBDIRS = conf data session frame home PresenceService
|
||||
|
||||
bin_SCRIPTS = \
|
||||
sugar \
|
||||
|
||||
+1
-1
@@ -2,10 +2,10 @@ import os
|
||||
import random
|
||||
import base64
|
||||
|
||||
import conf
|
||||
from sugar import env
|
||||
from sugar.p2p import Stream
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
from Friends import Friends
|
||||
from Invites import Invites
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import random
|
||||
import logging
|
||||
from sugar import env
|
||||
from sugar import util
|
||||
from sugar import conf
|
||||
|
||||
def _get_local_ip_address(ifname):
|
||||
"""Call Linux specific bits to retrieve our own IP address."""
|
||||
@@ -370,7 +369,7 @@ class PresenceService(object):
|
||||
self._dbus_helper.ServiceAppeared(service.object_path())
|
||||
except KeyError:
|
||||
# Should this service mark the owner?
|
||||
owner_nick = conf.get_profile().get_nick_name()
|
||||
owner_nick = env.get_nick_name()
|
||||
source_addr = service.get_source_address()
|
||||
objid = self._get_next_object_id()
|
||||
if name == owner_nick and source_addr in self._local_addrs.values():
|
||||
|
||||
+13
-28
@@ -14,10 +14,9 @@ from ActivityHost import ActivityHost
|
||||
from ChatController import ChatController
|
||||
from sugar.activity import ActivityFactory
|
||||
from sugar.activity import Activity
|
||||
from FirstTimeDialog import FirstTimeDialog
|
||||
from frame.Frame import Frame
|
||||
from globalkeys import KeyGrabber
|
||||
from sugar import conf
|
||||
import conf
|
||||
from sugar import env
|
||||
import sugar
|
||||
import sugar.logger
|
||||
@@ -67,32 +66,6 @@ class Shell(gobject.GObject):
|
||||
self._screen.connect('active-window-changed',
|
||||
self.__active_window_changed_cb)
|
||||
|
||||
profile = conf.get_profile()
|
||||
if profile.get_nick_name() == None:
|
||||
dialog = FirstTimeDialog()
|
||||
dialog.connect('destroy', self.__first_time_dialog_destroy_cb)
|
||||
dialog.set_transient_for(self._home_window)
|
||||
dialog.show()
|
||||
else:
|
||||
self.start()
|
||||
|
||||
def __global_key_pressed_cb(self, grabber, key):
|
||||
if key == 'F1':
|
||||
self.set_zoom_level(sugar.ZOOM_ACTIVITY)
|
||||
elif key == 'F2':
|
||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||
elif key == 'F3':
|
||||
self.set_zoom_level(sugar.ZOOM_FRIENDS)
|
||||
elif key == 'F4':
|
||||
self.set_zoom_level(sugar.ZOOM_MESH)
|
||||
elif key == 'F5':
|
||||
self._frame.toggle_visibility()
|
||||
|
||||
def __first_time_dialog_destroy_cb(self, dialog):
|
||||
conf.get_profile().save()
|
||||
self.start()
|
||||
|
||||
def start(self):
|
||||
session_bus = dbus.SessionBus()
|
||||
bus_name = dbus.service.BusName('com.redhat.Sugar.Shell', bus=session_bus)
|
||||
ShellDbusService(self, bus_name)
|
||||
@@ -111,6 +84,18 @@ class Shell(gobject.GObject):
|
||||
self._frame = Frame(self, self._owner)
|
||||
self._frame.show_and_hide(10)
|
||||
|
||||
def __global_key_pressed_cb(self, grabber, key):
|
||||
if key == 'F1':
|
||||
self.set_zoom_level(sugar.ZOOM_ACTIVITY)
|
||||
elif key == 'F2':
|
||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||
elif key == 'F3':
|
||||
self.set_zoom_level(sugar.ZOOM_FRIENDS)
|
||||
elif key == 'F4':
|
||||
self.set_zoom_level(sugar.ZOOM_MESH)
|
||||
elif key == 'F5':
|
||||
self._frame.toggle_visibility()
|
||||
|
||||
def set_console(self, console):
|
||||
self._console = console
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
import logging
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
from ConfigParser import NoOptionError
|
||||
|
||||
from sugar import activity
|
||||
from sugar import env
|
||||
import sugar
|
||||
|
||||
class ActivityModule:
|
||||
"""Info about an activity module. Wraps a .activity file."""
|
||||
|
||||
def __init__(self, name, activity_id, directory):
|
||||
self._name = name
|
||||
self._icon = None
|
||||
self._id = activity_id
|
||||
self._directory = directory
|
||||
self._show_launcher = False
|
||||
|
||||
def get_name(self):
|
||||
"""Get the activity user visible name."""
|
||||
return self._name
|
||||
|
||||
def get_id(self):
|
||||
"""Get the activity identifier"""
|
||||
return self._id
|
||||
|
||||
def get_icon(self):
|
||||
"""Get the activity icon name"""
|
||||
return self._icon
|
||||
|
||||
def set_icon(self, icon):
|
||||
"""Set the activity icon name"""
|
||||
self._icon = icon
|
||||
|
||||
def get_directory(self):
|
||||
"""Get the path to activity directory."""
|
||||
return self._directory
|
||||
|
||||
def get_default_type(self):
|
||||
"""Get the the type of the default activity service."""
|
||||
return activity.get_default_type(self._id)
|
||||
|
||||
def set_default_type(self, default_type):
|
||||
"""Set the the type of the default activity service."""
|
||||
self._default_type = default_type
|
||||
|
||||
def get_show_launcher(self):
|
||||
"""Get whether there should be a visible launcher for the activity"""
|
||||
return self._show_launcher
|
||||
|
||||
def set_show_launcher(self, show_launcher):
|
||||
"""Set whether there should be a visible launcher for the activity"""
|
||||
self._show_launcher = show_launcher
|
||||
|
||||
class _ActivityRegistry:
|
||||
"""Service that tracks the available activities"""
|
||||
|
||||
def __init__(self):
|
||||
self._activities = []
|
||||
self.scan_directory(env.get_activities_dir())
|
||||
|
||||
def get_activity(self, activity_id):
|
||||
"""Returns an activity given his identifier"""
|
||||
for activity in self._activities:
|
||||
if activity.get_id() == activity_id:
|
||||
return activity
|
||||
return None
|
||||
|
||||
def get_activity_from_type(self, default_type):
|
||||
"""Returns an activity given his default type"""
|
||||
for activity in self._activities:
|
||||
if activity.get_default_type() == default_type:
|
||||
return activity
|
||||
return None
|
||||
|
||||
def scan_directory(self, path):
|
||||
"""Scan a directory for activities and add them to the registry."""
|
||||
if os.path.isdir(path):
|
||||
for f in os.listdir(path):
|
||||
if f.endswith(".activity"):
|
||||
self.add(os.path.join(path, f))
|
||||
|
||||
def add(self, path):
|
||||
"""Add an activity to the registry. The path points to a .activity file."""
|
||||
cp = ConfigParser()
|
||||
cp.read([path])
|
||||
|
||||
directory = os.path.dirname(path)
|
||||
|
||||
try:
|
||||
activity_id = cp.get('Activity', 'id')
|
||||
except NoOptionError:
|
||||
logging.error('%s miss the required id option' % (path))
|
||||
return False
|
||||
|
||||
try:
|
||||
name = cp.get('Activity', 'name')
|
||||
except NoOptionError:
|
||||
logging.error('%s miss the required name option' % (path))
|
||||
return False
|
||||
|
||||
module = ActivityModule(name, activity_id, directory)
|
||||
self._activities.append(module)
|
||||
|
||||
if cp.has_option('Activity', 'show_launcher'):
|
||||
module.set_show_launcher(True)
|
||||
|
||||
if cp.has_option('Activity', 'icon'):
|
||||
module.set_icon(cp.get('Activity', 'icon'))
|
||||
|
||||
return True
|
||||
|
||||
def list_activities(self):
|
||||
"""Enumerate the registered activities as an ActivityModule list."""
|
||||
return self._activities
|
||||
@@ -0,0 +1,5 @@
|
||||
sugardir = $(pythondir)/sugar/conf
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ActivityRegistry.py \
|
||||
Profile.py
|
||||
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar import env
|
||||
|
||||
class _Profile:
|
||||
def __init__(self,):
|
||||
self._path = env.get_profile_path()
|
||||
self._nick_name = None
|
||||
self._color = None
|
||||
|
||||
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'):
|
||||
self._color = IconColor(cp.get('Buddy', 'Color'))
|
||||
|
||||
if self._color == None:
|
||||
self.set_color(IconColor())
|
||||
|
||||
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.get_fill_color())
|
||||
|
||||
fileobject = open(self._get_config_path(), 'w')
|
||||
cp.write(fileobject)
|
||||
fileobject.close()
|
||||
|
||||
def _get_config_path(self):
|
||||
return os.path.join(self._path, 'config')
|
||||
@@ -0,0 +1,11 @@
|
||||
from conf.ActivityRegistry import _ActivityRegistry
|
||||
from conf.Profile import _Profile
|
||||
|
||||
__registry = _ActivityRegistry()
|
||||
__profile = _Profile()
|
||||
|
||||
def get_activity_registry():
|
||||
return __registry
|
||||
|
||||
def get_profile():
|
||||
return __profile
|
||||
@@ -1,12 +1,12 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
import logging
|
||||
|
||||
import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
from frame.Panel import Panel
|
||||
import logging
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity, size):
|
||||
|
||||
@@ -2,11 +2,10 @@ import gtk
|
||||
import goocanvas
|
||||
import wnck
|
||||
|
||||
import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from home.DonutItem import DonutItem
|
||||
import sugar.conf
|
||||
|
||||
import Theme
|
||||
|
||||
class TasksItem(DonutItem):
|
||||
@@ -65,7 +64,7 @@ class HomeGroup(goocanvas.Group):
|
||||
tasks.translate(600, 450)
|
||||
self.add_child(tasks)
|
||||
|
||||
profile = sugar.conf.get_profile()
|
||||
profile = conf.get_profile()
|
||||
me = IconItem(icon_name = 'stock-buddy',
|
||||
color = profile.get_color(), size = 150)
|
||||
me.translate(600 - (me.get_property('size') / 2),
|
||||
|
||||
@@ -2,10 +2,10 @@ import random
|
||||
|
||||
import goocanvas
|
||||
|
||||
import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
|
||||
import Theme
|
||||
|
||||
|
||||
+12
-1
@@ -17,7 +17,7 @@ else:
|
||||
|
||||
from sugar import env
|
||||
|
||||
env.setup()
|
||||
env.setup_system()
|
||||
|
||||
from session.Emulator import Emulator
|
||||
|
||||
@@ -26,6 +26,17 @@ if os.environ.has_key('SUGAR_EMULATOR') and \
|
||||
emulator = Emulator()
|
||||
emulator.start()
|
||||
|
||||
from FirstTimeDialog import FirstTimeDialog
|
||||
import conf
|
||||
|
||||
profile = conf.get_profile()
|
||||
if profile.get_nick_name() == None:
|
||||
dialog = FirstTimeDialog()
|
||||
dialog.run()
|
||||
profile.save()
|
||||
|
||||
env.setup_user(profile)
|
||||
|
||||
from session.Session import Session
|
||||
|
||||
session = Session()
|
||||
|
||||
Reference in New Issue
Block a user