Skip to content

An animated bar graph type widget for Kivy which emulates the appearance of liquid inside a sight glass.

License

Notifications You must be signed in to change notification settings

clickworkorange/KivySightGlass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This Kivy bar graph widget seeks to emulate the appearance of liquid inside a sight glass. It is currently at an experimental stage - consider it early alpha at best.

A sight glass or water gauge is a type of level sensor, a transparent tube through which the operator of a tank or boiler can observe the level of liquid contained within.

https://en.wikipedia.org/wiki/Sight_glass

Preview

simplescreenrecorder-2023-05-09_22.32.24.mp4

Design

This could probably have been better realised using a shader/mesh approach, but as I suffer from a major OpenGL-fu deficit I decided to try a more basic approach: instead of a mesh the "liquid" consists of layered bitmap textures with a wavy top edge, which animate from side to side on a sine function. The extent of the animation is dampened over time, calming the surface, though it increases again whenever the level is changed, agitating the liquid. Some slight randomisation of alpha, colour, position, speed and movement range between the layeres helps improve the illusion, and means no two sight glasses will look exactly the same. Additionally, the liquid will "overshoot" a requested level and oscillate around it for a while before settling down (note that at the moment it doesn't always settle precisely at the right level, because maths, but I hope to have that fixed soon).

The "tube" portion consists of horizontal front and rear gradients, with the "liquid" appearing in between. A third vertical shading gradient is added on top to add to the illusion of an actual tube. The whole widget is contained inside a StencilView, which creates the outline of the tube by masking the image layers outside it. The maximum level visible inside the tube is 100, and the minimum 0, though -10 to 110 is allowed (for completely full/empty appearance, without any visible sloshing).

An optional scale can be added, which is currently drawn on the parent widget's Canvas (to allow ofsetting it beyond the edges of the StencilView). This can be divided into a maximum of 100 "major" lines, each further divided by a maximum of 10 "minor" lines. The graduation lines are actually ellipses, or partial ellipses, and can be given a curvature and up to 360° length.

Much of all this can be configured directly in kvlang, though at the moment a lot of things remain hard-coded.

Goals

  • Derive the ufo parameter that is used to represent the window height minus the height of the sight glass from the actual properties. This value is needed to accurately set the level and is currently hard-coded, because Kivy is being weird about it.

  • Make every aspect of the sight glass widget dynamic and configurable from .kv, ideally without cluttering the class with a ton of attributes. I am looking at AliasProperty as a possible way to achieve this.

  • Maybe add a cylindrical mesh transformation to the waves, so they appear to follow the walls of the tube rather than move linearly from side to side. Keeping resource usage low is a more important goal though, and a 3D transformation might just prove too costly.

  • The ability to give a rounded appearance to the ends of the tube might be nice, perhaps by using a bitmap as the mask instead of (or in addition to) the StencilView. Or it may be possible to use Canvas drawing tools (i.e. Line and Ellipse) to draw a Stencil that has an adjustable top & bottom curvature.

  • Drawing the portion of the scale that is on the back of the tube (if any) behind the liquid (and the rear gradient).

  • Attaching a list of strings to the "major" scale lines, so numbers (or any other characters) can be shown alongside.

  • Adding bubbles which ocassionally rise through the liquid.

Example usage

#:import SightGlass kivy_sight_glass.SightGlass

SightGlass:
    id: myglass
    size_hint: .2,1
    level: 33
    glass_color: rgba(127,191,255,63)
    glass_shade: rgba(0,0,0,63)
    liquid_color: rgba(0,215,255,255)
    scale_major: 10
    scale_minor: 5
    scale_color: rgba(255,255,255,95)

Button:
    on_press: myglass.level=90

Installation

Clone the repository and install with pip install .

Suggested use cases

  • On an automation dashboard, showing tank levels.

  • As the health/mana bars (or similiar) in a game.

  • In interactive kiosk applications.

Wetware at work

Resistance may indeed be futile, and I for one welcome our new software based overlords - who I'm sure are paying close attention*. But this software was written by a human, and only humans can enjoy writing code. Perhaps that joy by itself will one day be seen as an act of resistance?

Wetware at work

*) This repository was cloned 200 times in the first five days after putting it up.

About

An animated bar graph type widget for Kivy which emulates the appearance of liquid inside a sight glass.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages