~ubuntu-branches/debian/sid/awn-extras-applets/sid

« back to all changes in this revision

Viewing changes to src/to-do/settings.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-06-16 21:39:36 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100616213936-wia5mqfah6zameyo
Tags: 0.4.0-1
* New upstream release.
 - Catch error in weather applet (LP: #359668)
 - Stack applet close on click (LP: #261520)
 - Close cairo-menu after a click (LP: #511256)
 - Fix crash of awn-system-monitor (LP: #545164)
 - Fix crash when removing a volume >1 or adding volume >1 or using prefs
   while > 1 volumes is present (LP: #556175)
 - Fix crash of media-control when Rhythmbox quit (LP: #558463)
 - Fix crash of file-browser-launcher when there is no .gtk-bookmarks
   (LP: #551119)
* Update applets location:
 - Plugger, Filebrowser, Trasher, DesktopManager, Lastfm, Meebo, Digg, Pynot,
   RTM applets removed.
 - Sysmon, Bandwidth-monitor, Dialect, Hardware sensors, YAMA, Slickswitcher
   applets added
 - Separator applet move to Awn package.
 - Trash applet replaced by Garbage applet.
 - Arss applet replaced by Feeds applet.
 - Showdesktop applet move from python-core to c-core.
 - Digital Clock applet move from python-extras to c-extras.
 - Mimenu applet desactived.
* debian/series: disable 01-ftbfs-python-2.6.patch.
* debian/patches/02-shinyswitcher-default-layout.patch refreshed. 
* debian/watch: Update to the new package naming.
* debian/control:
 - Description updated with new applets.
 - Update Depends, Recommends and Suggests for all applets and add comments.
 - Add recommends on python-rsvg and python-wnck on python-core rather
   than python-extras applets. Thanks Mark Lee for the patch (LP: #423598).
 - Bump debhelper build-depends to (>= 7.0.50~) for overrides.
 - Bump build-depends libawn-dev (>= 0.4.0) and valac (>= 0.7.7).
 - 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, awn-manager,
   libglade2-dev and libgnomeui-dev.
 - Add build-depends on libdesktop-agnostic-bin and vala-awn.
 - Demote gconf-editor to Suggests, it's only needed for very advanced
   settings.
 - Add a debug package for C applets.
 - Add a common package for translations, and make it depends on all applets
   packages.
 - Add proper Conflicts/Replaces for updates of applets location
   (LP: #524559).
* debian/rules
 - Rewrite to use overrides and dh_install --fail-missing.
 - Disable dropper (not finished), mimenu (unstable) vala-test, python-test,
   wobblyzini (only for development purpose) applets.
 - Remove useless call to dh_makeshlibs.
 - Add dh_strip call for awn-applets-c-dbg binary.
 - Make scripts executable.
* debian/awn-applets-c-core.links: dropped, not needed.
* debian/libawn-extras*: Removed, libawn-extras was removed upstream.
* debian/python-awnlib*: Merged with python-awn-extras.
* debian/python-awn-extras.install: Install only py files.
* debian/copyright:
 - Update copyright and licenses.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# Copyright (c) 2008 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
 
 
23
 
class Settings:
24
 
  def __init__(self,applet_name,applet_uid):
25
 
    
26
 
    self._default_client = awn.Config(applet_name,None)
27
 
    self._instance_client = awn.Config(applet_name,applet_uid)
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
 
      #print 'getting '+string
49
 
      if self._instance_client.exists('DEFAULT', string):
50
 
        #print string+' exists in instance'
51
 
        if self._registered[string] in ['string','str',str]:
52
 
          self._values[string] = self._instance_client.get_string('DEFAULT', string)
53
 
        elif self._registered[string] in ['integer','int',int]:
54
 
          self._values[string] = self._instance_client.get_int('DEFAULT', string)
55
 
        elif self._registered[string] in ['float',float]:
56
 
          self._values[string] = self._instance_client.get_float('DEFAULT', string)
57
 
        elif self._registered[string] in ['boolean','bool',bool]:
58
 
          self._values[string] = self._instance_client.get_bool('DEFAULT', string)
59
 
        elif self._registered[string] in ['list-string','list-str',['string'],['str'],[str]]:
60
 
          self._values[string] = self._instance_client.get_list('DEFAULT', string,awn.CONFIG_LIST_STRING)
61
 
        elif self._registered[string] in ['list-integer','list-int',['integer'],['int'],[int]]:
62
 
          self._values[string] = intify(self._instance_client.get_list('DEFAULT', string,awn.CONFIG_LIST_STRING))
63
 
        elif self._registered[string] in ['list-boolean','list-bool',['boolean'],['bool'],[bool]]:
64
 
          self._values[string] = self._instance_client.get_list('DEFAULT', string,awn.CONFIG_LIST_BOOL)
65
 
        
66
 
        else:#Error when registering the key (setting the type)
67
 
          #print "KEY TYPE ERROR for %s" % string
68
 
          return "KEY TYPE ERROR for %s" % string
69
 
        #print 'Got '+string+' from instance'
70
 
      else:
71
 
        #print string+' not in instance'
72
 
        if self._registered[string] in ['string','str',str]:
73
 
          self._values[string] = self._default_client.get_string('DEFAULT', string)
74
 
        elif self._registered[string] in ['integer','int',int]:
75
 
          self._values[string] = self._default_client.get_int('DEFAULT', string)
76
 
        elif self._registered[string] in ['float',float]:
77
 
          self._values[string] = self._default_client.get_float('DEFAULT', string)
78
 
        elif self._registered[string] in ['boolean','bool',bool]:
79
 
          self._values[string] = self._default_client.get_bool('DEFAULT', string)
80
 
        elif self._registered[string] in ['list-string','list-str',['string'],['str'],[str]]:
81
 
          self._values[string] = self._default_client.get_list('DEFAULT', string,awn.CONFIG_LIST_STRING)
82
 
        elif self._registered[string] in ['list-integer','list-int',['integer'],['int'],[int]]:
83
 
          self._values[string] = intify(self._default_client.get_list('DEFAULT', string,awn.CONFIG_LIST_STRING))
84
 
        elif self._registered[string] in ['list-boolean','list-bool',['boolean'],['bool'],[bool]]:
85
 
          self._values[string] = self._default_client.get_list('DEFAULT', string,awn.CONFIG_LIST_BOOL)
86
 
        else:#Error when registering the key (setting the type)
87
 
          #print "KEY TYPE ERROR for %s" % string
88
 
          return "KEY TYPE ERROR for %s" % string
89
 
        #print 'Got '+string+' from default'
90
 
      
91
 
      #Set the functions to call for when <string> is changed as an empty list
92
 
      self._connects[string] = []
93
 
      
94
 
      #Return the value
95
 
      return self._values[string]
96
 
  
97
 
  #A function to call self.get -- in case someone messes up
98
 
  def get_value(self,string):
99
 
    self.get(string)
100
 
  
101
 
  #A function to set the value of a key -- assumes that <string> has already been registered and the <value> is the
102
 
  #same type as when registered
103
 
  def set(self,string,value):
104
 
    #print 'setting '+string+' to '+str(value)
105
 
    #Set the AwnCC value first
106
 
    if self._registered[string] in ['string','str',str]:
107
 
      self._instance_client.set_string('DEFAULT', string, value)
108
 
    elif self._registered[string] in ['integer','int',int]:
109
 
      self._instance_client.set_int('DEFAULT', string, value)
110
 
    elif self._registered[string] in ['float',float]:
111
 
      self._instance_client.set_float('DEFAULT', string, value)
112
 
    elif self._registered[string] in ['boolean','bool',bool]:
113
 
      self._instance_client.set_bool('DEFAULT', string, value)
114
 
    elif self._registered[string] in ['list-string','list-str',['string'],['str'],[str]]:
115
 
      self._instance_client.set_list('DEFAULT', string, awn.CONFIG_LIST_STRING, value)
116
 
    elif self._registered[string] in ['list-integer','list-int',['integer'],['int'],[int]]:
117
 
      self._instance_client.set_list('DEFAULT', string, awn.CONFIG_LIST_STRING, stringify(value))
118
 
    elif self._registered[string] in ['list-boolean','list-bool',['boolean'],['bool'],[bool]]:
119
 
      self._instance_client.set_list('DEFAULT', string, awn.CONFIG_LIST_BOOL, value)
120
 
    else:
121
 
      #print "KEY TYPE ERROR for %s" % self._registered[string]
122
 
      return "KEY TYPE ERROR for %s" % self._registered[string]
123
 
    #print 'set '+string+' to '+str(value)
124
 
    
125
 
    #Set the value (internally)
126
 
    self._values[string] = value
127
 
    
128
 
    #Last, go through any functions set to call for when <string> is changed
129
 
    for x in self._connects[string]:
130
 
      x[0](string,value,*x[1],**x[2])
131
 
  
132
 
  #A function to call set.set -- in case someone messes up
133
 
  def set_value(self,string,value):
134
 
    self.set(string,value)
135
 
  
136
 
  #A function to set a function to be called when one of <strings> is changed
137
 
  #<arg> is an optional parameter which will be passed to the function, if called
138
 
  #This assumes that each of <strings> has been registered
139
 
  def connect(self,strings,function,*args1,**args2):
140
 
    if type(strings)==type(''):#<strings> is a single string
141
 
      self._connects[strings].append([function,args1,args2])
142
 
    else:#Assume that <strings> is a list of strings
143
 
      for x in strings:
144
 
        self._connects[x].append([function,args1,args2])
145
 
  
146
 
  #Opposite of connect
147
 
  def disconnect(self, strings, function):
148
 
    if type(strings) == str:
149
 
      for func in self._connects[strings]:
150
 
        if func[0] == function:
151
 
          self._connects[strings].remove(func)
152
 
    
153
 
    else:
154
 
      for string in strings:
155
 
        for func in self._connects[strings]:
156
 
          if func[0] == function:
157
 
            self._connects[strings].remove(func)
158
 
  
159
 
  #In case the user wants to get a value via <settingsinstance>[<key>]
160
 
  def __getitem__(self,key):
161
 
    return self.get(key)
162
 
  
163
 
  #In case the user wants to set a value via <settingsinstance>[<key>] = ...
164
 
  def __setitem__(self,key,value):
165
 
    return self.set(key,value)
166
 
 
167
 
#list of integers -> list of equivalent strings
168
 
def stringify(list1):
169
 
  list2 = []
170
 
  for item in list1:
171
 
    list2.append(str(item))
172
 
  return list2
173
 
 
174
 
#list of strings -> list of equivalent integers
175
 
def intify(list1):
176
 
  list2 = []
177
 
  for item in list1:
178
 
    list2.append(int(float(item)))
179
 
  return list2