#!/usr/bin/python3

import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gtk, Gdk

Gtk.init_check(None)

provider = Gtk.CssProvider()
provider.load_from_data(bytes("""
levelbar.discrete trough block.filled.low {
    border-color: darker(red);
    background: red;
}

levelbar.discrete trough block.filled.medium {
    border-color: darker(orange);
    background: orange;
}

levelbar.discrete trough block.filled.high {
    border-color: darker(yellow);
    background: yellow;
}
""", "utf-8"))

Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider,
        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

levelbar = Gtk.LevelBar(mode=Gtk.LevelBarMode.DISCRETE, min_value=0, max_value=4)
levelbar.add_offset_value("low", 2)
levelbar.add_offset_value("medium", 3)
levelbar.add_offset_value("high", 4)

def increase_level(button, levelbar):
    levelbar.set_value(levelbar.get_value() + 1)

def decrease_level(button, levelbar):
    levelbar.set_value(levelbar.get_value() - 1)

plus_button = Gtk.Button(label="+")
plus_button.connect("clicked", increase_level, levelbar)

minus_button = Gtk.Button(label="-")
minus_button.connect("clicked", decrease_level, levelbar)

grid = Gtk.Grid()
grid.attach(levelbar, 0, 0, 2, 1)
grid.attach(minus_button, 0, 1, 1, 1)
grid.attach(plus_button, 1, 1, 1, 1)

window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
window.add(grid)
window.show_all()

Gtk.main()
