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
=== modified file 'src/lib/options/base.py'
--- src/lib/options/base.py 2011-03-28 15:24:57 +0000
+++ src/lib/options/base.py 2011-04-24 19:22:27 +0000
@@ -1,5 +1,5 @@
1#1#
2# Copyright (C) 2009 Martin Owens (DoctorMO) <doctormo@gmail.com>2# Copyright (C) 2011 Martin Owens (DoctorMO) <doctormo@gmail.com>
3#3#
4# This program is free software; you can redistribute it and/or modify4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by5# it under the terms of the GNU General Public License as published by
@@ -31,6 +31,8 @@
31# Option-classes and subclasses31# Option-classes and subclasses
32# -----------------------------------------------------------------------32# -----------------------------------------------------------------------
3333
34OPT_ATTRS = [ 'default', 'label', 'desc', 'choices' ]
35
34class Option(gobject.GObject):36class Option(gobject.GObject):
35 """An Option stores information about a certain object-attribute. It doesn't37 """An Option stores information about a certain object-attribute. It doesn't
36 carry information about the value or the object it belongs to - it is only a38 carry information about the value or the object it belongs to - it is only a
@@ -49,14 +51,14 @@
49 def __init__ (self, group, name, *attr, **args):51 def __init__ (self, group, name, *attr, **args):
50 """Creates a new Option with the given information."""52 """Creates a new Option with the given information."""
51 super(Option, self).__init__()53 super(Option, self).__init__()
54 if name == None:
55 raise ValueError("Option widget %s must have name." % str(type(self)) )
52 self.name = name56 self.name = name
53 self.group = group57 self.group = group
54 # To maintain compatability, we parse out the 3 attributes and58 # To maintain compatability, we parse out the 3 attributes and
55 # Move into known arguments.59 # Move into known arguments.
56 if len(attr) == 3:60 for i in range(len(attr)):
57 args.setdefault('default', attr[0])61 args.setdefault(OPT_ATTRS[i], attr[i])
58 args.setdefault('label', attr[1])
59 args.setdefault('desc', attr[2])
60 # This should allow any of the class options to be set on init.62 # This should allow any of the class options to be set on init.
61 for name in args.keys():63 for name in args.keys():
62 if hasattr(self, name):64 if hasattr(self, name):
@@ -404,8 +406,10 @@
404 # and create inputs406 # and create inputs
405 for option in group_data['options']:407 for option in group_data['options']:
406 if option.hidden == False:408 if option.hidden == False:
407 val = getattr(obj, option.name)409 name = getattr(obj, option.name)
408 w = self.generate_widget( option, val )410 if name == None:
411 raise ValueError("Option %s has no name" % str(type(obj)))
412 w = self.generate_widget( option, name )
409 if w:413 if w:
410 box.pack_start(w, 0, 0)414 box.pack_start(w, 0, 0)
411 w.show()415 w.show()

Subscribers

People subscribed via source and target branches

to status/vote changes: