def save_preferences(self): """Save the preferences config file if modified @emits: preferences-changed """ # For profile independent plugins, sync back to default # preferences if self.notebook and self.notebook.profile: independent = [] for plugin in self.plugins: if plugin.is_profile_independent: independent.append(plugin.plugin_key) if independent: default = get_config("preferences.conf") for name in independent: if name not in default["General"]["plugins"]: default["General"]["plugins"].append(name) default.set_modified(True) section = plugin.__class__.__name__ if default[section] != plugin.preferences: default[section].update(plugin.preferences) if default.modified: default.write() # First emit, than write - avoid getting stuck with a set # that crashes the application if self.preferences.modified: self.emit("preferences-changed") self.preferences.write()
def __init__(self, ui, notebook=None, namespace=None, basename=None, append=None, text=None, template_options=None, attachments=None): self.config = get_config('quicknote.conf') self.uistate = self.config['QuickNoteDialog'] Dialog.__init__(self, ui, _('Quick Note')) self._updating_title = False self._title_set_manually = not basename is None self.attachments = attachments if notebook and not isinstance(notebook, basestring): notebook = notebook.uri self.uistate.setdefault('lastnotebook', None, basestring) if self.uistate['lastnotebook']: notebook = notebook or self.uistate['lastnotebook'] self.config['Namespaces'].setdefault(notebook, None, basestring) namespace = namespace or self.config['Namespaces'][notebook] self.form = InputForm() self.vbox.pack_start(self.form, False) # TODO dropdown could use an option "Other..." label = gtk.Label(_('Notebook')+': ') label.set_alignment(0.0, 0.5) self.form.attach(label, 0,1, 0,1, xoptions=gtk.FILL) # T: Field to select Notebook from drop down list self.notebookcombobox = NotebookComboBox(current=notebook) self.notebookcombobox.connect('changed', self.on_notebook_changed) self.form.attach(self.notebookcombobox, 1,2, 0,1) self._init_inputs(namespace, basename, append, text, template_options) self.uistate['lastnotebook'] = notebook self._set_autocomplete(notebook)
def testSyncingIndependentPluginConfig(self): # Make sure independent plugin not in default config names = self.ui.preferences["General"]["plugins"] self.assertNotIn("automount", names) self.assertFalse(self.ui.preferences["AutomountPlugin"]) # Save default calendar = self.ui.get_plugin("calendar") calendar.preferences["test"] = "old" self.ui.preferences.write() self.assertTrue(self.ui.preferences.file.file.exists()) # Switch profile self.nb.save_properties(profile="TestSyncing") # Add independent plugin, touch config and save self.ui.load_plugin("automount") automount = self.ui.get_plugin("automount") calendar = self.ui.get_plugin("calendar") automount.preferences["test"] = "new" calendar.preferences["test"] = "new" self.ui.save_preferences() # Ensure default config also has new config - but not all # is overwritten default = get_config("preferences.conf") self.assertIn("automount", default["General"]["plugins"]) self.assertEqual(default["AutomountPlugin"]["test"], "new") self.assertEqual(default["CalendarPlugin"]["test"], "old")
def main(*args): start_server_if_not_running() preferences = get_config('preferences.conf')['TrayIconPlugin'] preferences.setdefault('classic', False) if appindicator and not preferences['classic']: obj = RemoteObject('zim.plugins.trayicon.AppIndicatorTrayIcon') else: obj = RemoteObject('zim.plugins.trayicon.DaemonTrayIcon') server = ServerProxy() if not server.has_object(obj): server.init_object(obj)
def get_config(self, uri): '''Return the automount config for a specific notebook uri or C{None} @param uri: a notebook uri @returns: a config dict ''' config = get_config('automount.conf') groups = [k for k in config.keys() if k.startswith('Path')] for group in groups: path = group[4:].strip() # len('Path') = 4 myuri = Dir(path).uri # Allow "~/Folder" syntax if uri.startswith(myuri): return config[group] else: return None
def on_profile_changed(self, notebook): # Copy config for independent plugins independent_preferences = {} for plugin in self.plugins[:]: if plugin.is_profile_independent: independent_preferences[plugin.plugin_key] = plugin.preferences.copy() # Switch config if self.notebook.profile: # Load the preferences for the profile # In case new profile does not exist or is incomplete # we cary over any settings from the current one logger.debug("Profile changed to: %s", notebook.profile) basename = self.notebook.profile.lower() + ".conf" file = config_file(("profiles", basename)) self.preferences.change_file(file) self.preferences.write() else: # Load default preferences # We do a full flush to reset to default logger.debug("Profile reset to default") preferences = get_config("preferences.conf") file = preferences.file self.preferences.change_file(file) for section in self.preferences.values(): section.clear() self.preferences.read() # HACK Forces reading default as well # Notify ui objects self.emit("preferences-changed") # notify plugins of possible new preferences # and remove old plugins for plugin in self.plugins[:]: if plugin.plugin_key in self.preferences["General"]["plugins"]: plugin.emit("preferences-changed") elif plugin.is_profile_independent: self.preferences["General"]["plugins"].append(plugin.plugin_key) plugin.preferences.update(independent_preferences[plugin.plugin_key]) else: self.unload_plugin(plugin) # load new plugins self.load_plugins()
def __init__(self, notebook=None): """Constructor @keyword notebook: the L{Notebook} object to open in this interface. If not specified here you can call L{open_notebook()} to open one later. """ gobject.GObject.__init__(self) self.notebook = None self.plugins = [] self.preferences = get_config("preferences.conf") self.preferences["General"].setdefault( "plugins", ["calendar", "insertsymbol", "printtobrowser", "versioncontrol"] ) self.uistate = None self.load_early_plugins() if not notebook is None: self.open_notebook(notebook)