~ubuntu-branches/ubuntu/utopic/awn-extras-applets/utopic

« back to all changes in this revision

Viewing changes to applets/maintained/to-do/settings.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-01-13 21:50:33 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100113215033-kd9otcdjrajmiag0
Tags: 0.3.9~bzr1944-0ubuntu1
* New upstream snapshot.
 - Catch error in weather applet (LP: #359668)
* debian/patches: Refresh.
* debian/*.install: 
 - Update to new location and new applets.
 - Disable dialect applet until python-xklavier is in the archive.
 - Disable MiMenu and Pandora applets, there are unmaintained and not stable.
* debian/awn-applets-c-core: Dropped, not needed.
* debian/control:
 - Update description with new applets.
 - Remove libawn-extras and python-awnlib, all merged in python-awn-extras.
 - Replace awn-manager by awn-settings.
 - Drop build-depends on libgnome-desktop-dev, python*-dev, python2.5,
   awn-manager, libglade2-dev and libgnomeui-dev.
 - Add build-depends on libdesktop-agnostic-bin and vala-awn.
 - Bump build-depends of libawn-dev (>= 0.3.9~bzr1890), valac (>= 0.7.7) and
   debhelper (>= 7.0.50~).
 - Bump Standards-Version to 3.8.3 (no change needed).
 - Demote gconf-editor to Suggest, it's only needed for very advanced
   settings.
 - Update Recommends for python applets with new applets.
 - Suggest python-gconf for notification-area and alacarte for YAMA.
 - Add a debug package for C applets.
* debian/libawn-extras*: Removed, libawn-extras was removed upstream.
* debian/python-awnlib*: Merged with python-awn-extras.
* debian/rules:
 - Rewrite to use overrides.
* debian/copyright:
 - Update copyright and licenses.
* debian/README.source: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright (c) 2009 Sharkbaitbobby <sharkbaitbobby+awn@gmail.com>
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2 of the License, or (at your option) any later version.
 
8
#
 
9
# This library is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public
 
15
# License along with this library; if not, write to the
 
16
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
# Boston, MA 02111-1307, USA.
 
18
#
 
19
#A class to sort of act like a daemon for the AwnConfigClient settings
 
20
 
 
21
import awn
 
22
from desktopagnostic.config import GROUP_DEFAULT
 
23
 
 
24
class Settings:
 
25
    def __init__(self, applet):
 
26
 
 
27
        self.client = awn.config_get_default_for_applet(applet)
 
28
        self._values = {} #{key:value,key:value,etc:etc}
 
29
        self._registered = {} #{key:type,key:type,etc:etc}
 
30
        self._connects = {} #{key:[[func,arg],[func,arg]],key:[[func,arg],[func,arg]]}
 
31
 
 
32
    #A function to add another value to the registered dictionary -- includes the type
 
33
    def register(self,dictionary):
 
34
        for string, type_default in dictionary.items():
 
35
            try:#String has been registered -- no action necessary
 
36
                self._registered[string]
 
37
            except:#String has not been registered -- register it
 
38
                self._registered[string] = type_default[0]
 
39
                if self.get(string) is None:
 
40
                    self.set(string, type_default[1])
 
41
 
 
42
    #A function to get the value of a key -- assumes that <string> has already been registered
 
43
    def get(self,string):
 
44
        try:#Has been fetched from AwnCC -- return the value
 
45
            self._values[string]
 
46
            return self._values[string]
 
47
        except:#Has not been fetched from AwnCC -- fetch it and return the value
 
48
            self._values[string] = self.client.get_value(GROUP_DEFAULT, string)
 
49
 
 
50
            #Set the functions to call for when <string> is changed as an empty list
 
51
            self._connects[string] = []
 
52
            
 
53
            #Return the value
 
54
            return self._values[string]
 
55
 
 
56
    #A function to call self.get -- in case someone messes up
 
57
    def get_value(self,string):
 
58
        self.get(string)
 
59
 
 
60
    #A function to set the value of a key -- assumes that <string> has already been registered and the <value> is the
 
61
    #same type as when registered
 
62
    def set(self,string,value):
 
63
        #Set the AwnCC value first
 
64
        self.client.set_value(GROUP_DEFAULT, string, value)
 
65
 
 
66
        #Set the value (internally)
 
67
        self._values[string] = value
 
68
 
 
69
        #Last, go through any functions set to call for when <string> is changed
 
70
        for x in self._connects[string]:
 
71
            x[0](string,value,*x[1],**x[2])
 
72
 
 
73
    #A function to call set.set -- in case someone messes up
 
74
    def set_value(self,string,value):
 
75
        self.set(string,value)
 
76
 
 
77
    #A function to set a function to be called when one of <strings> is changed
 
78
    #<arg> is an optional parameter which will be passed to the function, if called
 
79
    #This assumes that each of <strings> has been registered
 
80
    def connect(self,strings,function,*args1,**args2):
 
81
        if type(strings)==type(''):#<strings> is a single string
 
82
            self._connects[strings].append([function,args1,args2])
 
83
        else:#Assume that <strings> is a list of strings
 
84
            for x in strings:
 
85
                self._connects[x].append([function,args1,args2])
 
86
 
 
87
    #Opposite of connect
 
88
    def disconnect(self, strings, function):
 
89
        if type(strings) == str:
 
90
            for func in self._connects[strings]:
 
91
                if func[0] == function:
 
92
                    self._connects[strings].remove(func)
 
93
 
 
94
        else:
 
95
            for string in strings:
 
96
                for func in self._connects[strings]:
 
97
                    if func[0] == function:
 
98
                        self._connects[strings].remove(func)
 
99
 
 
100
    #In case the user wants to get a value via <settingsinstance>[<key>]
 
101
    def __getitem__(self,key):
 
102
        return self.get(key)
 
103
 
 
104
    #In case the user wants to set a value via <settingsinstance>[<key>] = ...
 
105
    def __setitem__(self,key,value):
 
106
        return self.set(key,value)