CheckBox doesn't "come with" a label property?

259 views
Skip to first unread message

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 1:34:56 PM2/23/15
to kivy-...@googlegroups.com
Hi!  Before I implement something that's there, just not well-documented (neither I nor my boss could find any evidence of it), is it correct that the CheckBox widget doesn't already have a Label property?  (I find this rather hard to believe, as what use is an unlabeled checkbox?)  Thanks!

DLG

ZenCODE

unread,
Feb 23, 2015, 1:42:09 PM2/23/15
to kivy-...@googlegroups.com
Correct, it does not. That is because it's not always used with text. e.g. We use images to depict options, not text. Best would be to sub-class it (or the Label, or create a mix-in, or create a containing class?) and add the label you require...

Peace

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 1:48:46 PM2/23/15
to kivy-...@googlegroups.com
That's what I'm doing.  Still, regardless of what you're using to "label" it, you're still "labeling" it, and regardless of what you're using to label it, you still need to provide and specify a position for the label; I fail to see what difference the nature of the label makes with respect to, well, anything, other than the things you can do to the label itself.

DLG

On Mon, Feb 23, 2015 at 10:42 AM, ZenCODE <zenkey....@gmail.com> wrote:
Correct, it does not. That is because it's not always used with text. e.g. We use images to depict options, not text. Best would be to sub-class it (or the Label, or create a mix-in, or create a containing class?) and add the label you require...

Peace

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
David Lawrence Goldsmith (DLG)
Software Engineer
Fishery Resource Analysis and Monitoring Division
Northwest Fisheries Science Center – NOAA
2725 Montlake Blvd E.
Seattle, WA 98112
(206) 302-2420 (w)

ZenCODE

unread,
Feb 23, 2015, 1:54:43 PM2/23/15
to kivy-...@googlegroups.com
ell, for example, it our case it's an Image, not a label. So having a "text" property makes no sense, just as a "source" property would make no sense for a label. So, because the semantics around creating this "label" would differ for use cases, it does not make a lot of sense to build it into the label. You could specify the position, yes, but not much else. Does that make sense, or am I missing you?

Cheers

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 2:04:03 PM2/23/15
to kivy-...@googlegroups.com
But having a "label" property--which is allowed to take either a text or an image value--does make sense: either way, one still needs it, and one still needs to specify where it should be placed relative to the checkbox itself.

Anyway, how do I refer to the box portion of the checkbox itself?  In other words, what I have is:

<import the various requirements>

class LabeledChcekBox(CheckBox):
  loc = OptionProperty("Lt", # Label position relative to its checkbox
options=["Rt", # right
"Lt", # left
"Ab", # above
"Be"  # below
])

  def __init__(self, label='Checkbox', **kwargs):
super(LabeledCheckBox, self).__init__(**kwargs)
lbl = Label(text=label)
if (self.loc=='Lt'):
self.layout = BoxLayout(orientation='horizontal')
self.layout.add_widget(lbl)
self.layout.add_widget(self.canvas) # is this how to add the CheckBox's box???
etc.

Or do I need to subclass Widget and add a distinct CheckBox Instance?  Thanks!

DLG

On Mon, Feb 23, 2015 at 10:54 AM, ZenCODE <zenkey....@gmail.com> wrote:
ell, for example, it our case it's an Image, not a label. So having a "text" property makes no sense, just as a "source" property would make no sense for a label. So, because the semantics around creating this "label" would differ for use cases, it does not make a lot of sense to build it into the label. You could specify the position, yes, but not much else. Does that make sense, or am I missing you?

Cheers

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 2:12:42 PM2/23/15
to kivy-...@googlegroups.com
ZenCODE: Sorry, I didn't finish reading your email before I replied, but clearly, we'll just have to agree to disagree: just because it would have "not much else" doesn't change the fact that that "not much else" is still a functionally essential part of the object.  (Such is the position taken by the developers of wxPython, for example, which I wish I could be using, but my boss is dictating that I use your product, resulting in me having to write a great deal more code than I otherwise would.)

DLG

Alexander Taylor

unread,
Feb 23, 2015, 3:37:16 PM2/23/15
to kivy-...@googlegroups.com
I would take a different approach - don't try to add a Label to a CheckBox, but create a new widget that contains both a Label and CheckBox.

For instance, you could declare in python 'class LabeledCheckBox(BoxLayout):' then use a kv rule:

<LabeledCheckBox>:
    text: ''
    Label:
        text: root.text
    CheckBox:
       
Of course you can add (or pass through from root) any other property settings you like.

Your attempt to add self.canvas is not a good way to go - the CheckBox is already a widget, you don't want to add an internal boxlayout and add itself to itself in a loop.

ZenCODE

unread,
Feb 23, 2015, 4:55:29 PM2/23/15
to kivy-...@googlegroups.com
I would also suggest Alexander's approach. Perhaps even subclassing a StackLayout or BoxLayout and adding the CheckBox and Label to that. You can then add the properties you want to this containing layout and delegate the property changes to the CheckBox and Label as appropriate. Something like

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty


class MyCheckBox(BoxLayout):
    active
= BooleanProperty(False)

   
def on_active(self, widget, value):
       
print('active change to ' + str(value))

class TestApp(App):
   
def build(self):
       
return Builder.load_string('''
MyCheckBox:
    CheckBox:
        id: check_box
        on_active: root.active = self.active
    Label:
        id: label
        text: '
Hello'
        on_touch_down: if self.collide_point(*args[1].pos): check_box.active = not check_box.active
'''
)


if __name__=="__main__":
   
TestApp().run()



David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 5:04:22 PM2/23/15
to kivy-...@googlegroups.com
Yeah, I figured that was the way I was going to need to go, then decided if that was what needed to be done, it was more trouble than it was worth.  Besides, I still think a check-box without a label property (and I don't know if it's a language barrier or what, but you all appear to be interpreting the word "label" too narrowly) is useless.

DLG

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Molina

unread,
Feb 23, 2015, 6:06:22 PM2/23/15
to kivy-...@googlegroups.com
Another way with dynamic classes combining Label and CheckBox,  and some canvas rewrite using almost the same canvas instructions for each one. (kivy 1.8)


from kivy.lang import Builder
from kivy.base import runTouchApp

kv="""
<LabelCheckBox@Label+CheckBox>:
    check_pos: "left"
    canvas:
        Clear

        Color:
            rgb: 1, 1, 1
 
        Rectangle:
            texture: self.texture
            size: self.texture_size
            pos: int(self.center_x - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.)

        Rectangle:
            source: 'atlas://data/images/defaulttheme/checkbox%s%s_%s' % (('_radio' if self.group else ''), ('_disabled' if self.disabled else ''), ('on' if self.active else 'off'))
            size: sp(32), sp(32)
            pos: int(self.x  if self.check_pos == 'left' else self.x + self.width -sp(32)), int(self.center_y - sp(16))
            

GridLayout:
    cols: 2
    rows: 2
    LabelCheckBox:
        text: "Option 1"
        check_pos: "left"
    LabelCheckBox:
        text: "Option 2"
        check_pos: "right"
    LabelCheckBox:
        text: "Option 3"
        group: "group"
        check_pos: "left"
    LabelCheckBox:
        text: "Option 4"
        group: "group"
        check_pos: "right"
"""

root = Builder.load_string(kv)
runTouchApp(root)

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 6:24:33 PM2/23/15
to kivy-...@googlegroups.com
So may I suggest that this (with support for text and image "labels") be added to the standard distribution?

DLG 

Alexander Taylor

unread,
Feb 23, 2015, 6:31:23 PM2/23/15
to kivy-...@googlegroups.com
I'll bear it in mind, but I think it's unlikely that we will add this,
since I don't think any of us perceive it as a significant problem
(indeed the opposite, kivy aims to provide easily composable widgets and
let you join them however you like, particularly with the advantage of
kv language).

We might consider a pull request with such a widget (and it might
generate discussion), and would certainly accept it in the kivy garden
repository.
> self.collide_point(*args[1].__pos): check_box.active = not
> check_box.active
> ''')
>
>
> if__name__=="__main__":
> TestApp().run()
> |
>
>
>
> --
> You received this message because you are subscribed to a
> topic in the Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/__topic/kivy-users/ZzLhhW_S8vo/__unsubscribe
> <https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe>.
> To unsubscribe from this group and all its topics, send an
> email to kivy-users+...@__googlegroups.com.
> For more options, visit https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
>
>
>
> --
> David Lawrence Goldsmith (DLG)
> Software Engineer
> Fishery Resource Analysis and Monitoring Division
> Northwest Fisheries Science Center – NOAA
> 2725 Montlake Blvd E.
> Seattle, WA 98112
> (206) 302-2420 (w)
> (360) 481-3800 <tel:%28360%29%20481-3800> (c)
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> David Lawrence Goldsmith (DLG)
> Software Engineer
> Fishery Resource Analysis and Monitoring Division
> Northwest Fisheries Science Center – NOAA
> 2725 Montlake Blvd E.
> Seattle, WA 98112
> (206) 302-2420 <tel:%28206%29%20860-3341> (w)
> (360) 481-3800 (c)
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
signature.asc

David Goldsmith - NOAA Affiliate

unread,
Feb 23, 2015, 6:50:51 PM2/23/15
to kivy-...@googlegroups.com
That's what I figured (which is why I didn't just submit a formal feature request--I could tell it would be a waste of time).

DLG

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
David Lawrence Goldsmith (DLG)
Software Engineer
Fishery Resource Analysis and Monitoring Division
Northwest Fisheries Science Center – NOAA
2725 Montlake Blvd E.
Seattle, WA 98112
(206) 302-2420 (w)

David Goldsmith - NOAA Affiliate

unread,
Feb 25, 2015, 4:03:17 PM2/25/15
to kivy-...@googlegroups.com
Thanks for the code (but I'm removing the Label's on_touch_down method 'cause I never meant for the label to be an active component of the widget, merely an indicator of what the box controls.)  I'd like to credit you in the code: how should I do so--as ZenCODE from the kivy-users list?  

ZenCODE

unread,
Feb 25, 2015, 4:36:50 PM2/25/15
to kivy-...@googlegroups.com
Thanks for the thought :-), but don't worry about it. It's simple enough, and was really just to help get you on track...

David Goldsmith - NOAA Affiliate

unread,
Feb 25, 2015, 4:39:13 PM2/25/15
to kivy-...@googlegroups.com
OK, thanks!

On Wed, Feb 25, 2015 at 1:36 PM, ZenCODE <zenkey....@gmail.com> wrote:
Thanks for the thought :-), but don't worry about it. It's simple enough, and was really just to help get you on track...

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/ZzLhhW_S8vo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

qua non

unread,
Feb 27, 2015, 3:22:54 AM2/27/15
to kivy-...@googlegroups.com
The main reason these kind of widget's are not accepted part of the core is what Alexander mentioned, core needs to be lean and allow you to manage making custom additions easily.

The fact is though that there are many widgets like these; that are staple widgets that are available in other frameworks like wx,  The solution is to have these be available in `garden`. The problem with garden is it's not implemented properly. It make it feel like garden widgets are second class citizens when they are not.

We should really should be making garden widget's more highlighted on the main kivy website and add easier, more transparent way to access the garden widgets in kivy itself.

@David a widget like this would be welcome in garden, we will be making things with garden more smooth in the future making it easier to include and use within kivy.

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

David Goldsmith - NOAA Affiliate

unread,
Feb 27, 2015, 3:45:22 AM2/27/15
to kivy-...@googlegroups.com
Roger that.  How would you unit test something like this: which attributes are both essential and readily testable?

qua non

unread,
Feb 27, 2015, 4:07:35 AM2/27/15
to kivy-...@googlegroups.com
This would be a new widget in garden, so you have total control over it. You can make it from scratch or based on top of checkbox.

I would try making it respect existing properties, you can add a unit test too on to garden with your widget if you want.
Reply all
Reply to author
Forward
0 new messages