Merge lp:~doctormo/screenlets/bugfix-lp-769795 into lp:screenlets

Proposed by Martin Owens
Status: Merged
Merge reported by: Märt Põder
Merged at revision: not available
Proposed branch: lp:~doctormo/screenlets/bugfix-lp-769795
Merge into: lp:screenlets
Diff against target: 51 lines (+11/-7)
1 file modified
src/lib/options/base.py (+11/-7)
To merge this branch: bzr merge lp:~doctormo/screenlets/bugfix-lp-769795
Reviewer Review Type Date Requested Status
Screenlets Dev Team Pending
Review via email: mp+58901@code.launchpad.net

Description of the change

Add in some checks to alert coders when they don't pass in a name for our option.

To post a comment you must log in.
652. By Martin Owens

Organise compatability with 'choices' attribute.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lib/options/base.py'
2--- src/lib/options/base.py 2011-03-28 15:24:57 +0000
3+++ src/lib/options/base.py 2011-04-24 19:22:27 +0000
4@@ -1,5 +1,5 @@
5 #
6-# Copyright (C) 2009 Martin Owens (DoctorMO) <doctormo@gmail.com>
7+# Copyright (C) 2011 Martin Owens (DoctorMO) <doctormo@gmail.com>
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11@@ -31,6 +31,8 @@
12 # Option-classes and subclasses
13 # -----------------------------------------------------------------------
14
15+OPT_ATTRS = [ 'default', 'label', 'desc', 'choices' ]
16+
17 class Option(gobject.GObject):
18 """An Option stores information about a certain object-attribute. It doesn't
19 carry information about the value or the object it belongs to - it is only a
20@@ -49,14 +51,14 @@
21 def __init__ (self, group, name, *attr, **args):
22 """Creates a new Option with the given information."""
23 super(Option, self).__init__()
24+ if name == None:
25+ raise ValueError("Option widget %s must have name." % str(type(self)) )
26 self.name = name
27 self.group = group
28 # To maintain compatability, we parse out the 3 attributes and
29 # Move into known arguments.
30- if len(attr) == 3:
31- args.setdefault('default', attr[0])
32- args.setdefault('label', attr[1])
33- args.setdefault('desc', attr[2])
34+ for i in range(len(attr)):
35+ args.setdefault(OPT_ATTRS[i], attr[i])
36 # This should allow any of the class options to be set on init.
37 for name in args.keys():
38 if hasattr(self, name):
39@@ -404,8 +406,10 @@
40 # and create inputs
41 for option in group_data['options']:
42 if option.hidden == False:
43- val = getattr(obj, option.name)
44- w = self.generate_widget( option, val )
45+ name = getattr(obj, option.name)
46+ if name == None:
47+ raise ValueError("Option %s has no name" % str(type(obj)))
48+ w = self.generate_widget( option, name )
49 if w:
50 box.pack_start(w, 0, 0)
51 w.show()

Subscribers

People subscribed via source and target branches

to status/vote changes: