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

« back to all changes in this revision

Viewing changes to shared/python/awnlib.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-08-29 14:29:52 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100829142952-rhvuetyms9bv5uu7
Tags: upstream-0.4.0+bzr1372
ImportĀ upstreamĀ versionĀ 0.4.0+bzr1372

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import gtk
25
25
 
26
26
from desktopagnostic import config, Color
27
 
from desktopagnostic.ui import ColorButton
28
27
import awn
29
 
from awn.extras import configbinder, __version__
 
28
from awn.extras import _, configbinder, __version__
30
29
 
31
30
import cairo
32
31
import cPickle as cpickle
74
73
    combobox.add_attribute(text, "text", 0)
75
74
 
76
75
 
77
 
def deprecated(old, new):
78
 
    def decorator(f):
79
 
        def wrapper(*args, **kwargs):
80
 
            m = "\nawnlib warning in %s:\n\t%s is deprecated; use %s instead\n"
81
 
            print m % (os.path.split(___file___)[1], old, new)
82
 
            return f(*args, **kwargs)
83
 
        return wrapper
84
 
    return decorator
85
 
 
86
 
 
87
76
class KeyRingError:
88
77
 
89
78
    def __init__(self, str):
118
107
        if all([key in meta_keys for key in ("name", "author", "copyright-year")]):
119
108
            about_dialog = self.new("about")
120
109
 
121
 
            about_item = gtk.ImageMenuItem("_About %s" % self.__parent.meta["name"])
 
110
            about_item = gtk.ImageMenuItem(_("_About %s") % self.__parent.meta["name"])
122
111
            if gtk.gtk_version >= (2, 16, 0):
123
112
                about_item.props.always_show_image = True
124
113
            about_item.set_image(gtk.image_new_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_MENU))
192
181
        if dialog in self.__register:
193
182
            raise RuntimeError("Dialog '%s' already registered" % dialog)
194
183
 
195
 
        if focus and dialog not in self.__special_dialogs:
 
184
        if focus and dialog not in self.__special_dialogs and isinstance(dlog, awn.Dialog):
196
185
            dlog.props.hide_on_unfocus = focus
197
186
 
198
187
        self.__register[dialog] = dlog
374
363
            self.set_resizable(False)
375
364
            self.set_border_width(5)
376
365
 
377
 
            self.set_title(parent.meta["name"] + " Preferences")
 
366
            # This is a window title, %s is an applet's name.
 
367
            self.set_title(_("%s Preferences") % parent.meta["name"])
378
368
            self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
379
369
 
380
370
 
681
671
 
682
672
            if url is not None:
683
673
                alignment = gtk.Alignment(xalign=0.5, xscale=0.0)
684
 
                alignment.add(gtk.LinkButton(url))
 
674
                alignment.add(gtk.LinkButton(url, url))
685
675
                self.vbox.pack_start(alignment, expand=False)
686
676
 
687
677
 
1233
1223
            self.__notification.show()            
1234
1224
 
1235
1225
 
1236
 
class Effects:
1237
 
 
1238
 
    def __init__(self, parent):
1239
 
        """Create a new Effects object.
1240
 
 
1241
 
        @param parent: The parent applet of the effects instance.
1242
 
        @type parent: L{Applet}
1243
 
 
1244
 
        """
1245
 
        self.__effects = parent.get_icon().get_effects()
1246
 
 
1247
 
    def attention(self):
1248
 
        """Launch the notify effect.
1249
 
 
1250
 
        Should be used when the user's attention is required.
1251
 
 
1252
 
        """
1253
 
        self.__effects.start("attention")
1254
 
 
1255
 
    def launch(self):
1256
 
        """Launch the launch effect.
1257
 
 
1258
 
        Should be used when launching another program.
1259
 
 
1260
 
        """
1261
 
        self.__effects.start("launching")
1262
 
 
1263
 
 
1264
1226
class Meta:
1265
1227
 
1266
1228
    def __init__(self, parent, info={}, options=()):
1280
1242
        self.__parent = parent
1281
1243
 
1282
1244
        self.__info = info
1283
 
 
1284
 
        self.__options = {}
1285
 
        self.options(options)
1286
 
 
1287
 
    def update(self, info):
1288
 
        """Update the meta instance with new information.
1289
 
 
1290
 
        @param info: Updated values for the meta dictionary
1291
 
        @type info: C{dict}
1292
 
 
1293
 
        """
1294
 
        self.__info.update(info)
1295
 
 
1296
 
    def options(self, opts):
1297
 
        """Update the options the applet has set
1298
 
 
1299
 
        @param opts: Options to set
1300
 
        @type opts: C{list} or C{tuple}
1301
 
 
1302
 
        """
1303
 
        self.__options.update(self.__parse_options(opts))
 
1245
        self.__options = options
1304
1246
 
1305
1247
    def has_option(self, option):
1306
1248
        """Check if the applet has set a specific option.
1307
1249
 
1308
 
        @param option: Option to check. Format: "option/suboption/suboption"
 
1250
        @param option: Option to check
1309
1251
        @type option: C{str}
1310
1252
 
1311
1253
        """
1312
 
        option = option.split("/")
1313
 
        srch = self.__options
1314
 
        for i in option:
1315
 
            if i not in srch or not srch[i]:
1316
 
                return False
1317
 
            elif srch[i] == True:  # tuples evaluate to True
1318
 
                return True
1319
 
            else:
1320
 
                srch = srch[i]
1321
 
        return True
1322
 
 
1323
 
    def __parse_options(self, options):
1324
 
        t = {}
1325
 
        for i in options:
1326
 
            if type(i) is str:
1327
 
                t[i] = True
1328
 
            elif type(i) in (tuple, list):
1329
 
                if type(i[1]) is bool:
1330
 
                    t[i[0]] = i[1]
1331
 
                elif type(i[1]) in (tuple, list):
1332
 
                    t[i[0]] = f(i[1])
1333
 
        return t
 
1254
        return option in self.__options
1334
1255
 
1335
1256
    def __getitem__(self, key):
1336
1257
        """Get a key from the dictionary.
1341
1262
        """
1342
1263
        return self.__info[key]
1343
1264
 
1344
 
    def __setitem__(self, key, value):
1345
 
        """Set a key in the dictionary.
1346
 
 
1347
 
        @param key: The key
1348
 
        @type key: C{string}
1349
 
        @param value: The value
1350
 
        @type value: C{string}
1351
 
 
1352
 
        """
1353
 
        self.__info[key] = value
1354
 
 
1355
 
    def __delitem__(self, key):
1356
 
        """Delete a key from the dictionary.
1357
 
 
1358
 
        @param key: The key
1359
 
        @type key: C{string}
1360
 
 
1361
 
        """
1362
 
        del self.__info[key]
1363
 
 
1364
1265
    def keys(self):
1365
1266
        """Return a list of keys from the dictionary.
1366
1267
 
1395
1296
        """
1396
1297
        awn.AppletSimple.__init__(self, meta["short"], uid, panel_id)
1397
1298
 
1398
 
        self.uid = uid
1399
 
 
1400
1299
        # Create all required child-objects, others will be lazy-loaded
1401
1300
        self.meta = Meta(self, meta, options)
1402
1301
        self.icon = Icon(self)
1403
1302
        self.tooltip = Tooltip(self)
1404
 
 
1405
 
        # Dialogs depends on settings
1406
1303
        self.dialog = Dialogs(self)
1407
1304
 
1408
1305
    def connect_size_changed(self, callback):
1419
1316
        instance = {}
1420
1317
 
1421
1318
        def getter(self):
1422
 
            if module not in instance:
1423
 
                instance[module] = module(self)
1424
 
            return instance[module]
 
1319
            key = (self, module)
 
1320
            if key not in instance:
 
1321
                instance[key] = module(self)
 
1322
            return instance[key]
1425
1323
        return property(getter)
1426
1324
 
1427
1325
    settings = __getmodule(Settings)
1430
1328
    errors = __getmodule(Errors)
1431
1329
    keyring = __getmodule(Keyring)
1432
1330
    notify = __getmodule(Notify)
1433
 
    effects = __getmodule(Effects)
1434
1331
 
1435
1332
 
1436
1333
def init_start(applet_class, meta={}, options=[]):