From bf8f1e30adf4894883a8a9dc024e067202c021a1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 22 Aug 2006 16:15:52 +0200 Subject: [PATCH] Forgot to add these --- shell/FirstTimeDialog.py | 36 +++++++++++++++++++++++++++++ sugar/conf/Profile.py | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 shell/FirstTimeDialog.py create mode 100644 sugar/conf/Profile.py diff --git a/shell/FirstTimeDialog.py b/shell/FirstTimeDialog.py new file mode 100644 index 00000000..7a7e4876 --- /dev/null +++ b/shell/FirstTimeDialog.py @@ -0,0 +1,36 @@ +import gtk + +from gettext import gettext as _ + +from sugar import conf + +class FirstTimeDialog(gtk.Window): + 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) + + label = gtk.Label(_('Nick Name:')) + label.set_alignment(0.0, 0.5) + vbox.pack_start(label) + label.show() + + self._entry = gtk.Entry() + vbox.pack_start(self._entry) + self._entry.show() + + button = gtk.Button(None, gtk.STOCK_OK) + 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() diff --git a/sugar/conf/Profile.py b/sugar/conf/Profile.py new file mode 100644 index 00000000..2a15f85a --- /dev/null +++ b/sugar/conf/Profile.py @@ -0,0 +1,50 @@ +import os +from ConfigParser import ConfigParser + +class Profile: + def __init__(self): + self._nick_name = None + + 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_nick_name(self): + return self._nick_name + + def set_nick_name(self, nick_name): + self._nick_name = nick_name + self.save() + + def get_path(self): + return self._path + + def read(self, profile_id): + self._profile_id = profile_id + + base_path = os.path.expanduser('~/.sugar') + self._path = os.path.join(base_path, profile_id) + 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') + + def save(self): + cp = ConfigParser() + + section = 'Buddy' + cp.add_section(section) + cp.set(section, 'NickName', self._nick_name) + + fileobject = open(self._get_config_path(), 'w') + cp.write(fileobject) + fileobject.close() + + def _get_config_path(self): + return os.path.join(self._path, 'config')