Previous Next Table of Contents
As mentioned on the previous post, I'm performing the GUI portion of the Home Security/Automation System using Kivy.
I've had quite a learning curve to get the Monitor Screen (below) to the point where it is now. While I like Kivy, the documentation is still a struggle for me, so I have to build a lot of simple GUIs and work with them, then gradually adding complexity.
The screen below is a mockup of what I'm envisioning. It doesn't have any logic behind it, just ability to show the zone buttons and checkboxes.
I don't like the way the checkboxes are being displayed. With the buttons, it's easy to see the button boundary, but the checkboxes just all run together to me; can't really tell where one zone's checkboxes ends and another's begins.
So I'm researching, trying to find a way to add some sort of visual delimiter that separates the zone's checkboxes from the next zone's checkboxes.
Here's what I've got so far (first the picture, then the code - note: Kivy code is two part; a Python portion (*.py) and a Kivy language portion (*.kv). I've posted both below.
First - the picture of the Monitor Screen (currently titled as 'Dynamic Button Text')
Here's the Python code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# DynamicButtonText.py
#
# http://BBQandBanjos.blogspot.com
#
# 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()
========
And here's the Kivy code:
#dynamicbuttontext.kv
ZoneLayout:
orientation: 'vertical'
text: "Zone " + str(root._instance_count + 1) + ": " + root._zoneNames[root._instance_count]
# text: "Button: "
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"
cols: 2
ZoneButton:
ZoneCheckBoxes:
No comments:
Post a Comment