Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/compizconfig.pyx b/src/compizconfig.pyx
- index d306a88..ace260d 100644
- --- a/src/compizconfig.pyx
- +++ b/src/compizconfig.pyx
- @@ -1,25 +1,34 @@
- -'''
- -This program is free software; you can redistribute it and/or
- -modify it under the terms of the GNU Lesser General Public License
- -as published by the Free Software Foundation; either version 2
- -of the License, or (at your option) any later version.
- -
- -This program is distributed in the hope that it will be useful,
- -but WITHOUT ANY WARRANTY; without even the implied warranty of
- -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- -GNU General Public License for more details.
- -
- -You should have received a copy of the GNU Lesser General Public License
- -along with this program; if not, write to the Free Software
- -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- -
- -Authors:
- - Quinn Storm (quinn@beryl-project.org)
- - Patrick Niklaus (marex@opencompositing.org)
- - Guillaume Seguin (guillaume@segu.in)
- -Copyright (C) 2007 Quinn Storm
- -'''
- -
- +# This program is free software; you can redistribute it and/or
- +# modify it under the terms of the GNU Lesser General Public License
- +# as published by the Free Software Foundation; either version 2
- +# of the License, or (at your option) any later version.
- +#
- +# This program is distributed in the hope that it will be useful,
- +# but WITHOUT ANY WARRANTY; without even the implied warranty of
- +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +# GNU General Public License for more details.
- +#
- +# You should have received a copy of the GNU Lesser General Public License
- +# along with this program; if not, write to the Free Software
- +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- +#
- +# Authors:
- +# Quinn Storm (quinn@beryl-project.org)
- +# Patrick Niklaus (marex@opencompositing.org)
- +# Guillaume Seguin (guillaume@segu.in)
- +# Copyright (C) 2007 Quinn Storm
- +
- +"""Python bindings to libcompizconfig.
- +
- +All functionality of compizconfig must be accessed by creating a L{Context}.
- +
- + >>> import compizconfig
- + >>> context = compizconfig.Context()
- + >>> print context.Plugins['core'].Name
- + 'core'
- +
- +
- +"""
- ctypedef unsigned int Bool
- cdef enum CCSSettingType:
- @@ -231,7 +240,7 @@ cdef struct CCSPluginConflict:
- CCSPluginConflictType type
- CCSPluginList * plugins
- -'''Context functions'''
- +# Context functions
- cdef extern void ccsSetBasicMetadata (Bool value)
- cdef extern CCSContext * ccsContextNew (unsigned int * screens,
- unsigned int numScreens)
- @@ -239,7 +248,7 @@ cdef extern CCSContext * ccsEmptyContextNew (unsigned int * screens,
- unsigned int numScreens)
- cdef extern void ccsContextDestroy (CCSContext * context)
- -'''Plugin functions'''
- +# Plugin functions
- cdef extern Bool ccsLoadPlugin (CCSContext * context, char * name)
- cdef extern CCSPlugin * ccsFindPlugin (CCSContext * context, char * name)
- cdef extern CCSSetting * ccsFindSetting (CCSPlugin * plugin,
- @@ -249,14 +258,14 @@ cdef extern CCSSetting * ccsFindSetting (CCSPlugin * plugin,
- cdef extern CCSSettingList * ccsGetPluginSettings (CCSPlugin * plugin)
- cdef extern CCSGroupList * ccsGetPluginGroups (CCSPlugin * plugin)
- -'''Action => String'''
- +# Action => String
- cdef extern char * ccsModifiersToString (unsigned int modMask)
- cdef extern char * ccsEdgesToString (unsigned int edge)
- cdef extern char * ccsEdgesToModString (unsigned int edge)
- cdef extern char * ccsKeyBindingToString (CCSSettingKeyValue *key)
- cdef extern char * ccsButtonBindingToString (CCSSettingButtonValue *button)
- -'''String utils'''
- +# String utils
- cdef extern from 'string.h':
- ctypedef int size_t
- cdef extern char * strdup (char * s)
- @@ -264,7 +273,7 @@ cdef extern from 'string.h':
- cdef extern void free (void * f)
- cdef extern void * malloc (size_t s)
- -'''String => Action'''
- +# String => Action
- cdef extern unsigned int ccsStringToModifiers (char *binding)
- cdef extern unsigned int ccsStringToEdges (char *edge)
- cdef extern unsigned int ccsModStringToEdges (char *edge)
- @@ -273,7 +282,7 @@ cdef extern Bool ccsStringToKeyBinding (char * binding,
- cdef extern Bool ccsStringToButtonBinding (char * binding,
- CCSSettingButtonValue * button)
- -'''General settings handling'''
- +# General settings handling
- cdef extern Bool ccsSetValue (CCSSetting * setting,
- CCSSettingValue * value)
- cdef extern void ccsFreeSettingValue (CCSSettingValue * value)
- @@ -283,42 +292,42 @@ cdef extern CCSSettingValueList * ccsSettingValueListAppend (
- cdef extern CCSSettingList *ccsSettingListFree (CCSSettingList * list,
- Bool freeObj)
- -'''Profiles'''
- +# Profiles
- cdef extern CCSStringList * ccsGetExistingProfiles (CCSContext * context)
- cdef extern void ccsDeleteProfile (CCSContext * context, char * name)
- cdef extern void ccsSetProfile (CCSContext * context, char * name)
- cdef extern char* ccsGetProfile (CCSContext * context)
- -'''Backends'''
- +# Backends
- cdef extern CCSBackendInfoList * ccsGetExistingBackends ()
- cdef extern Bool ccsSetBackend (CCSContext * context, char * name)
- cdef extern char* ccsGetBackend (CCSContext * context)
- -'''Sorting'''
- +# Sorting
- cdef extern void ccsSetPluginListAutoSort (CCSContext *context, Bool value)
- cdef extern Bool ccsGetPluginListAutoSort (CCSContext *context)
- -'''Integration'''
- +# Integration
- cdef extern void ccsSetIntegrationEnabled (CCSContext * context, Bool value)
- cdef extern Bool ccsGetIntegrationEnabled (CCSContext * context)
- -'''IO handling'''
- +# IO handling
- cdef extern void ccsReadSettings (CCSContext * c)
- cdef extern void ccsWriteSettings (CCSContext * c)
- cdef extern void ccsWriteChangedSettings (CCSContext * c)
- cdef extern void ccsResetToDefault (CCSSetting * s)
- -'''Event loop'''
- +# Event loop
- ProcessEventsNoGlibMainLoopMask = (1 << 0)
- cdef extern void ccsProcessEvents (CCSContext * context, unsigned int flags)
- -'''Import/export'''
- +# Import/export
- cdef extern Bool ccsExportToFile (CCSContext * context, char * fileName, Bool skipDefaults)
- cdef extern Bool ccsImportFromFile (CCSContext * context,
- char * fileName,
- Bool overwrite)
- -'''Misc. Plugin/Setting utils'''
- +# Misc. Plugin/Setting utils
- cdef extern Bool ccsSettingIsReadOnly (CCSSetting * setting)
- cdef extern Bool ccsSettingIsIntegrated (CCSSetting * setting)
- @@ -540,6 +549,7 @@ cdef object DecodeValue (CCSSettingValue * value):
- return "Unhandled"
- cdef class Setting:
- + """A representation of setting in a plugin"""
- cdef CCSSetting * ccsSetting
- cdef object info
- cdef Plugin plugin
- @@ -570,41 +580,75 @@ cdef class Setting:
- self.info = info
- def Reset (self):
- + """Restore the setting's value to the default"""
- ccsResetToDefault (self.ccsSetting)
- property Plugin:
- + """The L{Plugin<compizconfig.Plugin>} which owns the setting"""
- def __get__ (self):
- return self.plugin
- property Name:
- + """The untranslated name of the setting"""
- def __get__ (self):
- return self.ccsSetting.name
- property ShortDesc:
- + """A localized label for the setting"""
- def __get__ (self):
- return self.ccsSetting.shortDesc
- property LongDesc:
- + """A localized description of the setting suitable for display in tooltips"""
- def __get__ (self):
- return self.ccsSetting.longDesc
- property Group:
- + """Localized name of the group containing the setting"""
- def __get__ (self):
- return self.ccsSetting.group
- property SubGroup:
- + """Localizedd name of the subgroup containing the setting"""
- def __get__ (self):
- return self.ccsSetting.subGroup
- property Type:
- + """Setting type as a string. One of L{SettingTypeString}"""
- def __get__ (self):
- return SettingTypeString[self.ccsSetting.type]
- property Info:
- + """A tuple containing informatation about the setting. The values of the tuple elements for each type are as follows::
- +
- + Int:
- + minimum value
- + maximum value
- + int desc dictionary (a dictionary of string values for Int settings used as enumerations)*
- + Float:
- + minimum value
- + maximum value
- + precision
- + Key, Button, Edge, and Bell:
- + internal action (one that only conflicts with other internal settings in the plugin)
- + List:
- + list type
- + (Info tuple for that type)
- +
- + For all other setting types, Info will be an empty tuple.
- +
- + *the int desc dictionary is not available if basic_metadata is used.
- +
- + """
- def __get__ (self):
- return self.info
- property Hints:
- + """Additional hints about a setting's value for use by settings managers. For example, a String setting might have a "file" hint which indicates that its value is a filename
- +
- + This property does not work with basic_metadata
- +
- + """
- def __get__ (self):
- if self.ccsSetting.hints == '':
- return []
- @@ -612,16 +656,19 @@ cdef class Setting:
- return str (self.ccsSetting.hints).split (";")[:-1]
- property IsDefault:
- + """Whether the setting is at the default value"""
- def __get__ (self):
- if self.ccsSetting.isDefault:
- return True
- return False
- property DefaultValue:
- + """The setting's default value"""
- def __get__ (self):
- return DecodeValue (&self.ccsSetting.defaultValue)
- property Value:
- + """The settings's value. The value is always a copy, so when changing items in a list setting, you must mutate the list in place, then write the list back. In-place assignment like setting.Value[3] = "foo" will not work."""
- def __get__ (self):
- return DecodeValue (self.ccsSetting.value)
- def __set__ (self, value):
- @@ -631,14 +678,17 @@ cdef class Setting:
- ccsFreeSettingValue (sv)
- property Integrated:
- + """Whether the current settings backend is integrating this setting. See L{Context.Integration}"""
- def __get__ (self):
- return bool (ccsSettingIsIntegrated (self.ccsSetting))
- property ReadOnly:
- + """Whether the setting is set to be read-only in the metadata"""
- def __get__ (self):
- return bool (ccsSettingIsReadOnly (self.ccsSetting))
- cdef class SSGroup:
- + """A subgroup of settings in a plugin"""
- cdef object display
- cdef object screens
- @@ -647,18 +697,23 @@ cdef class SSGroup:
- self.screens = screen
- property Display:
- + """A dictionary of settings with similar semantics to L{Plugin.Display}"""
- def __get__ (self):
- return self.display
- def __set__ (self, value):
- self.display = value
- property Screens:
- + """A list of dictionaries of settings with similar semantics to L{Plugin.Screens}"""
- def __get__ (self):
- return self.screens
- def __set__ (self, value):
- self.screens = value
- cdef class Plugin:
- + """A representation of a compiz plugin. Through the plugin object, the plugin can be enabled or disabled and its settings can be viewed and manipulated.
- +
- + """
- cdef CCSPlugin * ccsPlugin
- cdef Context context
- cdef object screens
- @@ -679,6 +734,14 @@ cdef class Plugin:
- self.screens.append ({})
- def Update (self):
- + """Build dictionaries of plugin settings and groups. This occurs
- + automatically as needed, but each plugin can be forcibly initialized
- + with this method while waiting for user input.
- +
- + The L{Initialized} property will return True if this
- + process has already occurred.
- +
- + """
- cdef CCSList * setlist
- cdef CCSList * glist
- cdef CCSList * sglist
- @@ -725,59 +788,93 @@ cdef class Plugin:
- self.loaded = True
- property Context:
- + """The L{Context<compizconfig.Context>} which owns the Plugin"""
- def __get__ (self):
- return self.context
- property Groups:
- + """A (nested) dictionary of plugin groups and subgroups. The first level contains group names as keys and dictionaries of subgroups as values. The secondary dictionaries contain subgroup names as keys and L{SSGroup} objects as values.
- +
- + The simplest example for a plugin which contains no groups or subgroups is:
- +
- + C{{'': {'': <compizconfig.SSGroup object>}}}
- +
- + The '' keys in each dictionary represent settings outside of a group or subgroup, respectively. If a plugin has settings which are in a group but not a subgroup, they will appear in a SSGroup with the key '' in the dictionary for that group.
- +
- + """
- def __get__ (self):
- if not self.loaded:
- self.Update ()
- return self.groups
- property Display:
- + """A dictionary of all display-specific settings for the plugin. This collection is equivalent to the "/allscreens" path in the compiz D-Bus API."""
- def __get__ (self):
- if not self.loaded:
- self.Update ()
- return self.display
- property Screens:
- + """A list of dictionaries of screen-specific settings for each managed screen."""
- def __get__ (self):
- if not self.loaded:
- self.Update ()
- return self.screens
- property Ranking:
- + """A dictionary of "ranked" settings to preserve the sorting of the plugin's settings. in the form:
- +
- + {"setting_name": rank, ...}
- +
- + """
- def __get__ (self):
- if not self.loaded:
- self.Update ()
- return self.ranking
- property Name:
- + """The plugin's name (which is never translated)"""
- def __get__ (self):
- return self.ccsPlugin.name
- property ShortDesc:
- + """A localized label for the plugin.
- +
- + Not available with basic_metadata.
- +
- + """
- def __get__ (self):
- return self.ccsPlugin.shortDesc
- property LongDesc:
- + """A localized description of the plugin
- +
- + Not available with basic_metadata.
- +
- + """
- def __get__ (self):
- return self.ccsPlugin.longDesc
- property Category:
- + """The plugin's Category name"""
- def __get__ (self):
- return self.ccsPlugin.category
- property Features:
- + """A list of features provided by the plugin"""
- def __get__ (self):
- features = StringListToList (self.ccsPlugin.providesFeature)
- return features
- property Initialized:
- + """Indicates whether the setting and group objects for the plugin have been created. This will occur automatically if any property which requires it is read, but you can force initialization by calling the L{Update} method.
- +
- + """
- def __get__ (self):
- return bool (self.loaded)
- property Enabled:
- + """Indicates whether the plugin is enabled. This should only be used if L{Context.AutoSort} is Enabled."""
- def __get__ (self):
- return bool (ccsPluginIsActive (self.context.ccsContext,
- self.ccsPlugin.name))
- @@ -792,6 +889,11 @@ cdef class Plugin:
- ccsPluginSetActive (self.ccsPlugin, False)
- property EnableConflicts:
- + """A list of three-tuples containing conflicts which would prevent the plugin from being enabled
- +
- + Each tuple is of the form: (type, value, plugins), where type is the conflict type, value is the name of the conflict, and plugins is a list of plugins which conflict (if applicable).
- +
- + """
- def __get__ (self):
- cdef CCSPluginConflictList * pl, * pls
- cdef CCSPluginConflict * pc
- @@ -820,6 +922,11 @@ cdef class Plugin:
- return ret
- property DisableConflicts:
- + """A list of three-tuples containing conflicts which would prevent the plugin from being disabled
- +
- + Each tuple is of the form: (type, value, plugins), where type is the conflict type, value is the name of the conflict, and plugins is a list of plugins which conflict (if applicable).
- +
- + """
- def __get__ (self):
- cdef CCSPluginConflictList * pl, * pls
- cdef CCSPluginConflict * pc
- @@ -848,6 +955,7 @@ cdef class Plugin:
- return ret
- cdef class Profile:
- + """An object representing a settings profile"""
- cdef Context context
- cdef char * name
- @@ -859,13 +967,20 @@ cdef class Profile:
- free (self.name)
- def Delete (self):
- + """Delete the profile represented by the Profile object. This will only succeed on a profile other than the default profile ("")."""
- ccsDeleteProfile (self.context.ccsContext, self.name)
- property Name:
- + """The profile's name, which may be user-provided"""
- def __get__ (self):
- return self.name
- cdef class Backend:
- + """The backend is a plugin for libcompizconfig which implements storage of user settings.
- +
- + libcompizconfig ships with an ini (Flat File) backend, and the gconf and kconfig backends are packaged separately.
- +
- + """
- cdef Context context
- cdef char * name
- cdef char * shortDesc
- @@ -887,26 +1002,52 @@ cdef class Backend:
- free (self.longDesc)
- property Name:
- + """Untranslated backend name"""
- def __get__ (self):
- return self.name
- property ShortDesc:
- + """Localized short label"""
- def __get__ (self):
- return self.shortDesc
- property LongDesc:
- + """Localized longer description"""
- def __get__ (self):
- return self.longDesc
- property IntegrationSupport:
- + """Whether the backend suports enabling L{Desktop Integration<Context.Integration>}."""
- def __get__ (self):
- return self.integrationSupport
- property ProfileSupport:
- + """Whether the backend supports switching between multiple profiles."""
- def __get__ (self):
- return self.profileSupport
- cdef class Context:
- + """The Context is the tool used to view and manipulate the entire CompizConfig system.
- +
- + To increase the performance of context creation, you may limit the scope of the context:
- +
- + >>> import compizconfig
- + >>> context = compizconfig.Context(plugins=['core', 'decoration'], basic_metadata=True)
- + >>> context.Plugins['move']
- + Traceback (most recent call last):
- + ...
- + KeyError: 'move'
- + >>> decoration = context.Plugins['decoration']
- + >>> decoration.Name
- + 'decoration'
- + >>> decoration.ShortDesc
- + 'decoration'
- + >>> decoration.LongDesc
- + 'decoration'
- +
- + Without basic_metadata set, the L{ShortDesc<Plugin.ShortDesc>} and L{LongDesc<Plugin.LongDesc>} properties would produce localized descriptions of the plugin. In general, the ShortDesc, LongDesc, and Hints properties of all objects should be avoided when using basic_metadata. Check the documentation for any property used to ensure that it is still usable with basic_metadata.
- +
- + """
- cdef CCSContext * ccsContext
- cdef object plugins
- cdef object categories
- @@ -960,10 +1101,16 @@ cdef class Context:
- ccsContextDestroy (self.ccsContext)
- def LoadPlugin (self, plugin):
- + """Add a plugin to the context (or reload an existing one) by name."""
- return ccsLoadPlugin (self.ccsContext, plugin)
- # Returns the settings that should be updated
- def ProcessEvents (self, flags = 0):
- + """Call this method to process any changes which have occurred in other contexts. In an interactive application, you may want to call this periodically to receive updated, but always call it before L{writing<Write>} the context.
- + @param flags: Pass L{ProcessEventsNoGlibMainLoopMask} if there is no GLib mainloop running
- + @return: True if changes have occurred, False otherwise.
- +
- + """
- ccsProcessEvents (self.ccsContext, flags)
- if len (self.ChangedSettings):
- self.Read ()
- @@ -971,15 +1118,22 @@ cdef class Context:
- return False
- def Write (self, onlyChanged = True):
- + """Write all changes made the context. If onlyChanged is False, the entire context will be written, not just values which have been modified.
- +
- + """
- if onlyChanged:
- ccsWriteChangedSettings (self.ccsContext)
- else:
- ccsWriteSettings (self.ccsContext)
- def Read (self):
- + """Read all settings which have already been created. It is usually not necessary to call this method yourself
- +
- + """
- ccsReadSettings (self.ccsContext)
- def UpdateProfiles (self):
- + """Re-read the list of profiles and backends"""
- self.profiles = {}
- self.currentProfile = Profile (self, ccsGetProfile (self.ccsContext))
- cdef CCSStringList * profileList
- @@ -1004,28 +1158,38 @@ cdef class Context:
- self.currentBackend = self.backends[ccsGetBackend (self.ccsContext)]
- def ResetProfile (self):
- + """Set the profile to the default profile"""
- self.currentProfile = Profile (self, "")
- ccsSetProfile (self.ccsContext, "")
- ccsReadSettings (self.ccsContext)
- def Import (self, path, autoSave = True):
- + """Import settings from an .ini file specified at path. The imported settings will be written directly onto the current profile, so a new profile should be created if the existing settings should be preserved.
- +
- + """
- ret = bool (ccsImportFromFile (self.ccsContext, path, True))
- if autoSave:
- ccsWriteSettings (self.ccsContext)
- return ret
- def Export (self, path, skipDefaults = False):
- + """Export an .ini file of settings which may be imported with L{Import}. if skipDefaults is True, only setting values which differ from the defaults will be exported.
- +
- + """
- return bool (ccsExportToFile (self.ccsContext, path, skipDefaults))
- property Plugins:
- + """A dictionary of all plugins (not just active plugins) with plugin names used as keys and L{Plugin} objects used as values"""
- def __get__ (self):
- return self.plugins
- property Categories:
- + """A dictionary of categories. the '' category contains plugins which are uncategorized"""
- def __get__ (self):
- return self.categories
- property CurrentProfile:
- + """A L{Profile} object representing the current profile"""
- def __get__ (self):
- return self.currentProfile
- def __set__ (self, profile):
- @@ -1046,10 +1210,12 @@ cdef class Context:
- ccsReadSettings (self.ccsContext)
- property Backends:
- + """All available L{Backends<compizconfig.Backend>}"""
- def __get__ (self):
- return self.backends
- property ChangedSettings:
- + """A list of settings populated by the L{ProcessEvents} method. Each setting in this list has changed in value since the last ProcessEvents call (or since creation of the context if ProcessEvents has not been called)"""
- def __get__ (self):
- return SettingListToList (self, self.ccsContext.changedSettings)
- def __set__ (self, value):
- @@ -1062,16 +1228,25 @@ cdef class Context:
- self.ccsContext.changedSettings = settingList
- property AutoSort:
- + """ AutoSort determines whether libcompizconfig will manage the active_plugins list internally. If enabled, plugins can be enabled or disabled by setting the L{Enabled<Plugin.Enabled>} property, otherwise, the plugin must be added to the value of the active_plugins setting.
- +
- + """
- def __get__ (self):
- return bool (ccsGetPluginListAutoSort (self.ccsContext))
- def __set__ (self, value):
- ccsSetPluginListAutoSort (self.ccsContext, bool (value))
- property NScreens:
- + """The number of screens managed by the context"""
- def __get__ (self):
- return self.nScreens
- property Integration:
- + """Desktop Integration is a feature supported by some settings backends where they read certain settings from somewhere outside of compiz. For example, the GConf backend reads several settings from metacity when integration is enabled. Backends which support integration will have L{IntegrationSupport<Backend.IntegrationSupport>} set to True.
- +
- + If integration is enabled, the L{Integrated<Setting.Integrated>} property of each integrated setting will return True.
- +
- + """
- def __get__ (self):
- return bool (self.integration)
- def __set__ (self, value):
Add Comment
Please, Sign In to add comment