GridLayout CheckBoxes Labels: How to border

2,499 views
Skip to first unread message

BBQTrader

unread,
Apr 4, 2014, 11:24:51 AM4/4/14
to kivy-...@googlegroups.com
I'm brand new to Kivy, but not new to programming.

I've got Home Automation/Security system I'm building using a BeagleBone Black.  The monitoring screen is networked so I can view on any computer/Android device.

I've been working on a mockup of the monitor screen (picture below).  I'm close to what I want, but the Checkboxes (actually, radio boxes as I'm using the 'group' command), except that I would like to differentiate the checkboxes/labels that are associated with a zone, from another zone.  Currently, they all run together.  The Buttons are easy to see that they're associated with a particular zone, but the checkboxes/labels just sort of all run together.

I'm wanting something - too new to Kivy to know what exactly - that will allow me to visually show that a series of checkboxes/labels is associated with the zone button - maybe a border, or a line, or something.

I'm looking for some suggestions, along with some code examples of how to implement a suggestion.

I'm posting the picture, the Python code, and the Kivy language code below, in that order.




====Python code ====
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  DynamicButtonText.py
#
#  

# Given a Dictionary of dynamic names,
# pick each up and assign it to the Button text.

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.checkbox import CheckBox

class ZoneList():
    _zoneL = ["Basement","Sun Room","Den","Living Room","Front Door"]

class ZoneElements(GridLayout):
    pass

class ZoneCheckBoxes(GridLayout):
    _instance_count = -1
    _zoneNames = ZoneList._zoneL

    def __init__(self, **kwargs):
        super(ZoneCheckBoxes, self).__init__(**kwargs)
        ZoneCheckBoxes._instance_count += 1
    

class ZoneButton(Button):
    _instance_count = -1
    _zoneNames = ZoneList._zoneL
    
    def __init__(self, **kwargs):
        super(ZoneButton, self).__init__(**kwargs)
        ZoneButton._instance_count += 1

class ZoneLayout(BoxLayout):
    def __init__(self, **kwargs):
        super(ZoneLayout, self).__init__(**kwargs)
        for i in range(len(ZoneList._zoneL)):
            self.add_widget(ZoneElements())

class DynamicButtonText(App):
    pass

def main():
    DynamicButtonText().run()   #run kivy app
    
    return 0

if __name__ == '__main__':
    main()

    
======end if Python code ===


====start of Kivy Language code ====
#dynamicbuttontext.kv

ZoneLayout:

<ZoneLayout>:
    orientation: 'vertical'
            
<ZoneButton>:
    text: "Zone " + str(root._instance_count + 1) + ": " + root._zoneNames[root._instance_count]
#    text: "Button: "
        
<ZoneCheckBoxes>:
    cols:2
    CheckBox:
        active: True
        group: "Zone " + root._zoneNames[root._instance_count]
    Label:
        text: "Active"
        
    CheckBox:
        group: "Zone " + root._zoneNames[root._instance_count]
    Label:
        text: "Inactive"
    
    CheckBox:
        group: "Zone " + root._zoneNames[root._instance_count]
    Label:
        text: "Bypass"
    
    CheckBox:
        group: "Zone " + root._zoneNames[root._instance_count]
    Label:
        text: "Monitor"
    
    CheckBox:
        group: "Zone " + root._zoneNames[root._instance_count]
    Label:
        text: "Test"


<ZoneElements>:
    cols: 2
    ZoneButton:

    ZoneCheckBoxes:

BBQTrader

unread,
Apr 6, 2014, 9:58:22 PM4/6/14
to kivy-...@googlegroups.com
Bump

BBQTrader

unread,
Apr 8, 2014, 7:20:36 AM4/8/14
to kivy-...@googlegroups.com
Well, disappointed I didn't get any suggestions.

I found my own.  I don't know if this is the correct/recommended approach, but it does what I needed:


<ZoneElements>:
    cols: 2
    ZoneButton:

    ZoneCheckBoxes:
    Label:
        size_hint:1,.01
        canvas.before: 
            Color: 
                rgb: .5,.5,0 
            Rectangle: 
                pos: self.pos
                size: self.size
    Label:
        size_hint:1,.01
        canvas.before: 
            Color: 
                rgb: .5,.5,0 
            Rectangle: 
                pos: self.pos
                size: self.size


On Friday, April 4, 2014 11:24:51 AM UTC-4, BBQTrader wrote:

Ben Rousch

unread,
Apr 8, 2014, 8:00:31 AM4/8/14
to kivy-...@googlegroups.com
This blog post is a pretty good guide to one bordering solution. It feels like a hack to me, but maybe there's nothing better. http://robertour.com/2013/10/02/easy-way-debugging-kivy-interfaces/


--
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.
For more options, visit https://groups.google.com/d/optout.



--
 Ben Rousch
   bro...@gmail.com
   http://clusterbleep.net/

BBQTrader

unread,
Apr 8, 2014, 6:07:12 PM4/8/14
to kivy-...@googlegroups.com
Thanks Ben - felt like a hack to me too, but I figured I needed to move forward.

ZenCODE

unread,
Apr 9, 2014, 2:05:57 AM4/9/14
to kivy-...@googlegroups.com
If it helps, the way we've approached this is, when we want things together, drop them into a layout. We then use the layout's canvas to draw the surrounding border/grouping cues.

This also makes the group essentially one widget, making it easy to re-use. Hope that's clear? Shout if you want a concrete example.

Peace out

BBQTrader

unread,
Apr 9, 2014, 11:24:48 PM4/9/14
to kivy-...@googlegroups.com
Thanks!  I'll give that a try.
Reply all
Reply to author
Forward
0 new messages