Skip to content

Commit

Permalink
Merge pull request #1173 from Cobinja/cobidev-gsettings-range
Browse files Browse the repository at this point in the history
make GSettingsSpinButton aware of ranges defined in the schema
  • Loading branch information
clefebvre committed Jan 30, 2013
2 parents 22b40f2 + 6ff18ed commit bf8a48c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions data/org.cinnamon.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@

<key name="panel-top-height" type="i">
<default>25</default>
<range min="20" />
<_summary>Panel size</_summary>
<_description>
User-defined panel-height for top panel
Expand All @@ -109,6 +110,7 @@

<key name="panel-bottom-height" type="i">
<default>25</default>
<range min="20" />
<_summary>Panel size</_summary>
<_description>
User-defined panel-height for bottom panel
Expand Down Expand Up @@ -412,6 +414,7 @@
</key>

<key type="i" name="workspace-osd-x">
<range min="5" max="95" />
<default>50</default>
<_summary>Workspace horizontal position (in percent of the monitor's width)</_summary>
<_description>
Expand All @@ -420,6 +423,7 @@
</key>

<key type="i" name="workspace-osd-y">
<range min="5" max="95" />
<default>50</default>
<_summary>Workspace vertical position (in percent of the monitor's height)</_summary>
<_description>
Expand Down
24 changes: 18 additions & 6 deletions files/usr/lib/cinnamon-settings/bin/SettingsWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,33 @@ def on_dependency_setting_changed(self, settings, dep_key):
class GSettingsSpinButton(Gtk.HBox):
def __init__(self, label, schema, key, dep_key, min, max, step, page, units):
self.key = key
self.min = min
self.max = max
self.dep_key = dep_key
super(GSettingsSpinButton, self).__init__()
self.label = Gtk.Label(label)
self.content_widget = Gtk.SpinButton()
self.units = Gtk.Label(units)
if (label != ""):
self.pack_start(self.label, False, False, 2)
self.pack_start(self.content_widget, False, False, 2)
self.pack_start(self.label, False, False, 2)
self.pack_start(self.content_widget, False, False, 2)
if (units != ""):
self.pack_start(self.units, False, False, 2)
self.pack_start(self.units, False, False, 2)

self.content_widget.set_range(min, max)
self.content_widget.set_increments(step, page)
#self.content_widget.set_editable(False)
self.settings = Gio.Settings.new(schema)
self.settings = Gio.Settings.new(schema)
range = self.settings.get_range(self.key)
if range[0] == "range":
rangeDefault = (1 << 32) - 1
rangeMin = rangeDefault
rangeMax = rangeDefault
range = range[1]
rangeMin = range[0] if range[0] < rangeDefault else rangeDefault
rangeMax = range[1] if range[1] < rangeDefault else rangeDefault
self.min = min if min > rangeMin else rangeMin
self.max = max if max < rangeMax else rangeMax
self.content_widget.set_range(self.min, self.max)
self.content_widget.set_increments(step, page)
self.content_widget.set_value(self.settings.get_int(self.key))
self.settings.connect("changed::"+self.key, self.on_my_setting_changed)
self.content_widget.connect('value-changed', self.on_my_value_changed)
Expand Down

0 comments on commit bf8a48c

Please sign in to comment.