[caribou/introspection: 1/10] pygi: Made settings bits work in pygi.
- From: Eitan Isaacson <eitani src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [caribou/introspection: 1/10] pygi: Made settings bits work in pygi.
- Date: Thu, 6 Jan 2011 01:04:38 +0000 (UTC)
commit dd4eab3a6403bd994e264f4871f251600eb84f1e
Author: Eitan Isaacson <eitan monotonous org>
Date: Tue Dec 14 15:54:07 2010 -0800
pygi: Made settings bits work in pygi.
caribou/common/setting_types.py | 38 ++++++++++++---
caribou/common/settings.py | 2 +-
caribou/common/settings_manager.py | 25 ++++++----
caribou/ui/preferences_window.py | 91 +++++++++++++++++++++---------------
4 files changed, 100 insertions(+), 56 deletions(-)
---
diff --git a/caribou/common/setting_types.py b/caribou/common/setting_types.py
index 17faa61..5b8aa95 100644
--- a/caribou/common/setting_types.py
+++ b/caribou/common/setting_types.py
@@ -1,4 +1,5 @@
import gobject
+from gi.repository import GConf
GCONF_DIR="/apps/caribou/osk/"
@@ -36,7 +37,6 @@ class Setting(gobject.GObject):
self._sensitive = sensitive
self.emit('sensitivity-changed', sensitive)
-
def __len__(self):
return len(self.children)
@@ -56,7 +56,7 @@ class SettingsGroup(Setting):
pass
class ValueSetting(Setting):
- gconf_type = ''
+ gconf_type = GConf.ValueType.INVALID
entry_type=ENTRY_DEFAULT
def __init__(self, name, label, default, short_desc="", long_desc="",
allowed=[], entry_type=ENTRY_DEFAULT, sensitive=None,
@@ -80,7 +80,7 @@ class ValueSetting(Setting):
@value.setter
def value(self, val):
- _val = self.convert_value(val)
+ _val = self.convert_value(self._from_gconf_value(val))
if self.allowed and _val not in [a for a, b in self.allowed]:
raise ValueError, "'%s' not a valid value" % _val
self._value = _val
@@ -98,8 +98,32 @@ class ValueSetting(Setting):
def gconf_default(self):
return self.default
+ def set_gconf_value(self, val):
+ if val.type == GConf.ValueType.BOOL:
+ return val.set_bool(self.value)
+ if val.type == GConf.ValueType.FLOAT:
+ return val.set_float(self.value)
+ if val.type == GConf.ValueType.INT:
+ return val.set_int(self.value)
+ if val.type == GConf.ValueType.STRING:
+ return val.set_string(self.value)
+
+ def _from_gconf_value(self, val):
+ if not isinstance(val, GConf.Value):
+ return val
+ if val.type == GConf.ValueType.BOOL:
+ return val.get_bool()
+ if val.type == GConf.ValueType.FLOAT:
+ return val.get_float()
+ if val.type == GConf.ValueType.INT:
+ return val.get_int()
+ if val.type == GConf.ValueType.STRING:
+ return val.get_string()
+
+ return val.to_string()
+
class BooleanSetting(ValueSetting):
- gconf_type = 'boolean'
+ gconf_type = GConf.ValueType.BOOL
entry_type = ENTRY_CHECKBOX
def convert_value(self, val):
# Almost anything could be a boolean.
@@ -110,7 +134,7 @@ class BooleanSetting(ValueSetting):
str(self.default).lower()
class IntegerSetting(ValueSetting):
- gconf_type = 'int'
+ gconf_type = GConf.ValueType.INT
entry_type = ENTRY_SPIN
def __init__(self, *args, **kwargs):
self.min = kwargs.pop('min', gobject.G_MININT)
@@ -121,7 +145,7 @@ class IntegerSetting(ValueSetting):
return int(val)
class FloatSetting(ValueSetting):
- gconf_type = 'float'
+ gconf_type = GConf.ValueType.FLOAT
entry_type = ENTRY_SPIN
def __init__(self, *args, **kwargs):
self.min = kwargs.pop('min', gobject.G_MINFLOAT)
@@ -132,7 +156,7 @@ class FloatSetting(ValueSetting):
return float(val)
class StringSetting(ValueSetting):
- gconf_type = 'string'
+ gconf_type = GConf.ValueType.STRING
def convert_value(self, val):
return str(val)
diff --git a/caribou/common/settings.py b/caribou/common/settings.py
index 6f08774..757e4f0 100644
--- a/caribou/common/settings.py
+++ b/caribou/common/settings.py
@@ -166,7 +166,7 @@ if __name__ == "__main__":
doc, schema, [('key', '/schemas' + setting.gconf_key),
('applyto', setting.gconf_key),
('owner', 'caribou'),
- ('type', setting.gconf_type),
+ ('type', setting.gconf_type.value_nick),
('default', setting.gconf_default)])
locale = doc.createElement('locale')
locale.setAttribute('name', 'C')
diff --git a/caribou/common/settings_manager.py b/caribou/common/settings_manager.py
index 256ef76..92b5137 100644
--- a/caribou/common/settings_manager.py
+++ b/caribou/common/settings_manager.py
@@ -1,5 +1,5 @@
import os
-import gconf
+from gi.repository import GConf
from setting_types import *
from settings import settings
import const
@@ -7,9 +7,9 @@ import const
class _SettingsManager(object):
def __init__(self, settings):
self.groups = settings
- self.gconf_client = gconf.client_get_default()
+ self.gconf_client = GConf.Client.get_default()
self.gconf_client.add_dir(const.CARIBOU_GCONF,
- gconf.CLIENT_PRELOAD_NONE)
+ GConf.ClientPreloadType.PRELOAD_NONE)
self._settings_map = {}
self._map_settings(self.groups)
@@ -35,18 +35,20 @@ class _SettingsManager(object):
if isinstance(setting, SettingsGroup):
continue
try:
- setting.value = self.gconf_client.get_value(setting.gconf_key)
+ setting.value = self.gconf_client.get(setting.gconf_key)
except ValueError:
- self.gconf_client.set_value(setting.gconf_key, setting.value)
+ val = GConf.Value.new(setting.gconf_type)
+ setting.set_gconf_value(val)
+ self.gconf_client.set(setting.gconf_key, val)
self._change_dependant_sensitivity(setting)
handler_id = setting.connect('value-changed',
self._on_value_changed)
- self.gconf_client.notify_add(setting.gconf_key,
- self._gconf_setting_changed_cb,
- (setting, handler_id))
+ #self.gconf_client.notify_add(setting.gconf_key,
+ # self._gconf_setting_changed_cb,
+ # (setting, handler_id))
def _change_dependant_sensitivity(self, setting):
for name in setting.insensitive_when_false:
@@ -59,8 +61,11 @@ class _SettingsManager(object):
child.sensitive = i == index
def _on_value_changed(self, setting, value):
- if value != self.gconf_client.get_value(setting.gconf_key):
- self.gconf_client.set_value(setting.gconf_key, value)
+ if value != self.gconf_client.get(setting.gconf_key):
+ print setting.gconf_type
+ val = GConf.Value.new(setting.gconf_type)
+ setting.set_gconf_value(val)
+ self.gconf_client.set(setting.gconf_key, val)
self._change_dependant_sensitivity(setting)
def _gconf_setting_changed_cb(self, client, connection_id, entry, data):
diff --git a/caribou/ui/preferences_window.py b/caribou/ui/preferences_window.py
index c11cbf8..69ce8b1 100644
--- a/caribou/ui/preferences_window.py
+++ b/caribou/ui/preferences_window.py
@@ -20,12 +20,13 @@
import caribou.common.const as const
from caribou.common.setting_types import *
+from caribou.common.settings_manager import SettingsManager
-import scan
-import gconf
+from gi.repository import GConf
import gobject
-import gtk
-import pango
+from gi.repository import Gdk
+from gi.repository import Gtk
+from gi.repository import Pango
import sys
import virtkey
import os
@@ -41,25 +42,26 @@ import xml.etree.ElementTree as ET
from xml.dom import minidom
import gettext
import i18n
-from caribou.common.settings_manager import SettingsManager
-class PreferencesWindow(gtk.Dialog):
+class PreferencesWindow(Gtk.Dialog):
__gtype_name__ = "PreferencesWindow"
def __init__(self):
- gtk.Dialog.__init__(self, _("Caribou Preferences"),
- buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
+ gobject.GObject.__init__(self)
+ self.set_title(_("Caribou Preferences"))
+ self.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
self.set_border_width(6)
- notebook = gtk.Notebook()
- self.vbox.add(notebook)
+ notebook = Gtk.Notebook()
+ vbox = self.get_content_area()
+ vbox.add(notebook)
self._populate_settings(notebook, SettingsManager.groups)
def _populate_settings(self, parent, setting, level=0):
if level == 0:
for s in setting:
- vbox = gtk.VBox()
- parent.append_page(vbox, gtk.Label(s.label))
+ vbox = Gtk.VBox()
+ parent.append_page(vbox, Gtk.Label(label=s.label))
self._populate_settings(vbox, s, 1)
else:
parent.set_border_width(6)
@@ -68,7 +70,7 @@ class PreferencesWindow(gtk.Dialog):
for s in setting:
if not isinstance(s, SettingsGroup):
if table is None:
- table = gtk.Table(1, 2)
+ table = Gtk.Table.new(1, 2, False)
table.set_row_spacings(3)
table.set_col_spacings(3)
parent.pack_start(table, False, False, 0)
@@ -76,12 +78,12 @@ class PreferencesWindow(gtk.Dialog):
row += 1
else:
table = None
- frame = gtk.Frame()
- frame.set_shadow_type(gtk.SHADOW_NONE)
- label = gtk.Label()
+ frame = Gtk.Frame()
+ frame.set_shadow_type(Gtk.ShadowType.NONE)
+ label = Gtk.Label()
label.set_markup('<b>%s</b>' % s.label)
frame.set_label_widget(label)
- vbox = gtk.VBox()
+ vbox = Gtk.VBox()
frame.add(vbox)
parent.pack_start(frame, False, False, 0)
self._sensitivity_changed_cb(s, s.sensitive, frame, None)
@@ -91,36 +93,35 @@ class PreferencesWindow(gtk.Dialog):
self._populate_settings(vbox, s, level + 1)
def _create_widget(self, table, row, setting, xpadding=0):
- print 'create', setting.name
control = None
label = None
value_changed_cb = None
control_changed_cb = None
control_changed_signal = None
if isinstance(setting, BooleanSetting):
- control = gtk.CheckButton(setting.label)
+ control = Gtk.CheckButton.new_with_label(setting.label)
control.set_active(setting.value)
value_changed_cb = lambda s, v, w: w.set_active(v)
control_changed_cb = self._checkbutton_toggled_cb
control_changed_signal = 'toggled'
else:
- label = gtk.Label("%s:" % setting.label)
+ label = Gtk.Label(label="%s:" % setting.label)
label.set_alignment(0.0, 0.5)
if setting.entry_type == ENTRY_COLOR:
- control = gtk.ColorButton(
- gtk.gdk.color_parse(setting.value))
+ control = Gtk.ColorButton.new_with_color(
+ Gdk.color_parse(setting.value)[1])
value_changed_cb = \
- lambda s, v, w: w.set_color(gtk.gdk.color_parse(v))
+ lambda s, v, w: w.set_color(Gdk.color_parse(v))
control_changed_cb = self._colorbutton_changed_cb
control_changed_signal = 'color-set'
elif setting.entry_type == ENTRY_FONT:
- control = gtk.FontButton(setting.value)
+ control = Gtk.FontButton.new_with_font(setting.value)
value_changed_cb = lambda s, v, w: w.set_font_name(v)
control_changed_cb = self._fontbutton_changed_cb
control_changed_signal = 'font-set'
elif setting.entry_type == ENTRY_SPIN:
- control = gtk.SpinButton()
+ control = Gtk.SpinButton()
if isinstance(setting.value, float):
control.set_digits(2)
control.set_increments(0.01, 0.1)
@@ -136,15 +137,16 @@ class PreferencesWindow(gtk.Dialog):
"If a radio entry has children, they must be equal " \
"in quantity to the allowed values."
label = None
- control = gtk.Table(
- len(setting.allowed) + len(setting.children), 2)
+ control = Gtk.Table.new(
+ len(setting.allowed) + len(setting.children), 2, False)
control.set_row_spacings(3)
control.set_col_spacings(3)
radios = []
for string, localized in setting.allowed:
- radios.append(gtk.RadioButton(None, localized))
- for radio in radios[1:]:
- radio.set_group(radios[0])
+ radios.append(Gtk.RadioButton.new_with_label(
+ [], localized))
+ for radio in radios:
+ radio.set_group(radios)
hid = setting.connect(
'value-changed',
@@ -157,7 +159,11 @@ class PreferencesWindow(gtk.Dialog):
for i, radio in enumerate(radios):
radio.connect('toggled', self._radio_changed_cb, setting,
radios, hid)
- control.attach(radio, 0, 2, r, r + 1)
+ control.attach(
+ radio, 0, 2, r, r + 1,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ 0, 0)
r += 1
if setting.children:
self._create_widget(control, r,
@@ -165,7 +171,7 @@ class PreferencesWindow(gtk.Dialog):
r += 1
elif setting.entry_type == ENTRY_COMBO or setting.allowed:
- control = gtk.combo_box_new_text()
+ control = Gtk.ComboBox.new_text()
for option in setting.allowed:
control.append_text(option[1])
control.set_active(
@@ -175,17 +181,26 @@ class PreferencesWindow(gtk.Dialog):
control_changed_cb = self._combo_changed_cb
control_changed_signal = 'changed'
else:
- control = gtk.Entry()
+ control = Gtk.Entry()
control.set_text(setting.value)
value_changed_cb = lambda s, v, w: w.set_text(v)
control_changed_cb = self._string_changed_cb
control_changed_signal = 'insert-at-cursor'
if label is not None:
- table.attach(label, 0, 1, row, row + 1, xpadding=xpadding)
- table.attach(control, 1, 2, row, row + 1)
+ table.attach(label, 0, 1, row, row + 1,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ xpadding, 0)
+ table.attach(control, 1, 2, row, row + 1,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ 0, 0)
else:
- table.attach(control, 0, 2, row, row + 1, xpadding=xpadding)
+ table.attach(control, 0, 2, row, row + 1,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ xpadding, 0)
self._sensitivity_changed_cb(setting, setting.sensitive, control,
label)
@@ -238,9 +253,9 @@ class PreferencesWindow(gtk.Dialog):
if __name__ == "__main__":
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
- w = PreferencesWindow_()
+ w = PreferencesWindow()
w.show_all()
try:
w.run()
except KeyboardInterrupt:
- gtk.main_quit()
+ Gtk.main_quit()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]