Skip to content

Instantly share code, notes, and snippets.

@ccprog
Last active May 16, 2016 18:09
Show Gist options
  • Save ccprog/5128c2aebd952dd084482d2c755b5a6d to your computer and use it in GitHub Desktop.
Save ccprog/5128c2aebd952dd084482d2c755b5a6d to your computer and use it in GitHub Desktop.
Cinnamon applet settings: display a setting value by choosing an option
const Applet = imports.ui.applet;
const Settings = imports.ui.settings;
function MyApplet(metadata, orientation, panelHeight, instanceId) {
this.settings = new Settings.AppletSettings(this, UUID, instanceId);
this._init(orientation, panelHeight, instanceId);
}
MyApplet.prototype = Object.create(Applet.TextIconApplet.prototype, {
_init: { value: function (orientation, panelHeight, instanceId) {
Applet.TextIconApplet.prototype._init.call(this, orientation, panelHeight, instanceId);
// 'webservice' is a combobox
this.settings.bindProperty(Settings.BindingDirection.IN, 'webservice',
'webservice', this.on_change_webservice);
// 'location_id' is a entry field
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, 'location_id',
'location_id', this.on_change_location);
// 'location_store' is a generic, default = {}
this.settings.bindProperty(Settings.BindingDirection.OUT, 'locations_store',
'locations_store');
},
on_change_webservice: function () {
this.location_id = this.locations_store[this.webservice];
},
on_change_location: function () {
let cache = this.locations_store;
cache[this.webservice] = this.location_id;
// save the complete Object to the key
this.locations_store = cache;
}
}
{
"webservice":
{ "type": "combobox"
, "default": "yahoo"
, "description": "Weather data provider"
, "options":
{ "Yahoo! Weather": "yahoo"
, "OpenWeatherMap": "owm"
}
}
, "location_id":
{ "type": "entry"
, "default": ""
, "description": "Location ID"
}
, "locations_store":
{ "type": "generic"
, "default": {}
}
}
--- /usr/share/cinnamon/cinnamon-settings/bin/XletSettingsWidgets.py
+++ /usr/share/cinnamon/cinnamon-settings/bin/XletSettingsWidgets_live_update.py
@@ -50,6 +50,7 @@
self.handler = self.file_monitor.connect("changed", self.on_file_changed)
self.file_changed_timeout = None
self.resume_timeout = None
+ self.monitor_exeption = None
def create(self, key, setting_type, uuid):
try:
@@ -66,13 +67,13 @@
def do_reload(self):
self.settings.reload()
for key in self.widgets.keys():
- self.widgets[key].on_settings_file_changed()
+ if key != self.monitor_exeption:
+ self.widgets[key].on_settings_file_changed()
self.file_changed_timeout = None
return False
- def pause_monitor(self):
- self.file_monitor.cancel()
- self.handler = None
+ def pause_monitor(self, exeption):
+ self.monitor_exeption = exeption
def resume_monitor(self):
if self.resume_timeout:
@@ -80,8 +81,7 @@
self.resume_timeout = GObject.timeout_add(2000, self.do_resume)
def do_resume(self):
- self.file_monitor = self.file_obj.monitor_file(Gio.FileMonitorFlags.SEND_MOVED, None)
- self.handler = self.file_monitor.connect("changed", self.on_file_changed)
+ self.monitor_exeption = None
self.resume_timeout = None
return False
@@ -133,7 +133,7 @@
def save (self, name = None):
if name is None:
name = self.file_name
- self.factory.pause_monitor()
+ self.factory.pause_monitor(None)
if os.path.exists(name):
os.remove(name)
raw_data = json.dumps(self.data, indent=4)
@@ -148,7 +148,7 @@
return key in self.data.keys()
def real_update_dbus(self, key):
- self.factory.pause_monitor()
+ self.factory.pause_monitor(key)
session_bus = dbus.SessionBus()
cinnamon_dbus = session_bus.get_object("org.Cinnamon", "/org/Cinnamon")
setter = cinnamon_dbus.get_dbus_method('updateSetting', 'org.Cinnamon')
@ccprog
Copy link
Author

ccprog commented May 16, 2016

XletSettingsWidgets.patch might be a possible patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment