On Wed, Jul 23, 2008 at 10:34 AM, Dirk Meyer <[EMAIL PROTECTED]> wrote:
> "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.
>
Yes that is the plan. We should add some simple general purpose widgets.
> > 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.
>
Sounds good. I will keep that in mind when I code widgets.
>
> > 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
Ok will look at progressbar.py to get some ideas.
>
> as example. Secondly, activeBackground should be active_background,
> see http://doc.freevo.org/CodingStandard for more details.
>
Sure. That code was just my mind dump (and I am more used to java coding
style than C/Python :)
>
> > 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.
>
We definitely want to make height and width optional. They can just stretch
based on the container size they are added to. As for labels, I think font
can be optional too, but I guess it should definitely honor font sizes if
they as passed by users. You see if I wanted to make a container with first
line as big bold font and next 2 lines smaller fonts, that can be a problem.
My guess is the current style is fine i.e. height depends on font.
However I have a feature request. I can only align the label horizontally.
It would be nice to do vertical alignment too (top, bottom, center). That
way the button can always have the font centered in the button container (if
the alignment is so provided in the xml or otherwise). We will have a lot of
ways to customize how the button looks ("left - vertical centered" etc).
While we are on this topic, the doc string for label mentions that size can
be None, however in the __init__ you use size[1], so we need to get rid of
that or the doc string.
> > 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.
>
I agree, this is a bad idea.
>
> 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):
>
I don't like using name as I mentioned before. Name is something we want the
users to use and not the framework to use.
>
> | @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?
>
Yes! I like use-as. Let's here from others too.
>
> | <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
>
-------------------------------------------------------------------------
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