"Chandan Pitta" wrote: > I am planning to write a button widget, but I need your advise before I > start. So my plan is to create a button widget which has an "active > background" widget and an "inactive background" widget and another widget > that becomes the label of the button.
Cool. Let's make kaa.candy a full featured widget set. I like that. > Example (I just typed this in the email so some API calls may be > different or non-existent): Some notes about the API idea: > class Button(kaa.candy.Container): Files inside kaa.candy should not import kaa.candy and should use relative imports. It works with the kaa.candy import but it would break epydoc. See other widgets for examples. > def __init__(self, activeBackground, inactiveBackground, label): > add(activeBackground) > add(inactiveBackground) > add(label) The XML subsystem will create activeBackground as Template, not as Widget. A user not using XML will provide a Widget and not a Template. You should check that using is_template. See progressbar.py as example. Secondly, activeBackground should be active_background, see http://doc.freevo.org/CodingStandard for more details. > A button can be made active (selected) or inactive with a method like so. > def setActive(self, state): again, set_active. > And the candy xml may look like > <candyxml geometry="800x600"> > <button name="test"> > <rectangle width="200" height="50" color="0x888888" > border_size="2" border_color="0xffffff" radius="10" name="inactiveBg"/> > <rectangle width="200" height="50" color="0x008800" > border_size="2" border_color="0xffffff" radius="10" name="activeBg" /> > <label name="test" align="center" font="Vera:24" > color="0xffffff" name="label"> > Hello world > </label> > </button> > </candyxml> > Everytime I read something like this (also in my code) I do not like that fact that you have to use height for rectangle and a font size for the label. I guess label should also have a height and calculate the font size based on it. I will think about how to fix it, not your problem. > Now my question is, how do I make button read the first rectangle (might as > well be any other widget say Image) as inactive background and the next > rectangle as active background and then the label (could be any widget) as > button label? Assuming the names "inactiveBg" "activeBg" etc in Button class > is stupid, but I did not know how else to do it. Please recommend a proper > course of action. Or may be my whole thinking is wrong and you have a better > suggestion for how a button should look and behave? Two ideas. The first one is just to asume the children are in a specific order. Not a good idea but it will work. See grid.py how to access a child. The grid asumes there is only one child with the item template. This will work but IMHO it is a bad style to do so. So the second idea is to use a special attribute in XML. The parsers will ignore everything they don't understand. So if you add name to rectangle and label, you can still parse it (see grid.py how) and they will ignore the name. You have to get it yourself. Example to parse your XML file with the name (not tested, just written down): | @classmethod | def candyxml_parse(cls, element): | active_background = None | ... | for child in element: | if child.name == 'activeBg': | active_background = child.xmlcreate() | ... | return Super(button, cls).candyxml_parse.update( | active_background = active_background, ...) IMHO this is better than having a fixed order I only do not like the attribute name "name". You can also not use anything that is used by a widget itself and not "style" (this is used to have several classes for the same XML node name). So what else could we use? class (like in HTML div) sounds not right, paramater maybe? assignment? assign? use-as? | <rectangle ... color="0x008800" use-as="active-background"/> Doesn't look too bad. What do others think? Dischi -- I have yet to meet a C compiler that is more friendly and easier to use than eating soup with a knife. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Freevo-devel mailing list Freevo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freevo-devel