This repository has been archived on 2024-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
al-skel/home/bin/config_ui

148 lines
4.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
2017-10-23 18:35:35 -05:00
import os
import struct
import subprocess
2017-12-02 01:06:11 -06:00
import yaml
import gi
2017-10-23 18:35:35 -05:00
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, Pango
# This is the name of the group where your configs are stored.
GROUP = 'i3'
PATH = '{}/bin/gorice'.format(os.environ['HOME'])
2017-10-23 18:35:35 -05:00
class Selection(Gtk.EventBox):
def __init__(self, name, colours, foreground, background, selected,
working=True):
super().__init__()
self.name = name
self.background = background
self.selected_colour = selected
if not working:
name = 'x ' + name
text = Gtk.Label(name)
hbox = Gtk.HBox()
hbox.set_size_request(0, 30)
hbox.pack_start(text, False, True, 20)
hbox.override_color(Gtk.StateType.NORMAL, Gdk.RGBA(*foreground))
hbox.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*background))
colour_widgets = Gtk.HBox()
for colour in colours:
box = Gtk.Box()
box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*colour))
box.set_size_request(15, 15)
padding = Gtk.Alignment()
padding.set_padding(10, 10, 0, 0)
padding.add(box)
colour_widgets.pack_start(padding, False, True, 2)
hbox.pack_end(colour_widgets, False, True, 20)
self.hbox = hbox
self.connect('enter-notify-event', self.selected)
self.connect('leave-notify-event', self.unselected)
self.connect('button-press-event', self.clicked)
self.add(self.hbox)
def clicked(self, widget, button):
_, index = button.get_button()
if index == 1:
proc = subprocess.run([PATH, 'load', self.name])
Gtk.main_quit()
return None
def selected(self, *args):
2017-12-02 01:06:11 -06:00
# self.hbox.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*self.selected))
2017-10-23 18:35:35 -05:00
return None
def unselected(self, *args):
2017-12-02 01:06:11 -06:00
# self.hbox.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*self.selected))
2017-10-23 18:35:35 -05:00
return None
def load_configs():
broken = subprocess.check_output([PATH, 'check', GROUP])
broken = broken.decode('utf-8').split('\n')
output = []
path = '{}/.gorice/output.yaml'.format(os.environ['HOME'])
with open(path, 'r') as f:
data = yaml.load(f.read())
names = sorted(data['configs'])
for config in names:
info = data['configs'][config]
config, ext = os.path.splitext(config)
if config == 'i3/default':
continue
_, name = config.split('/', 1)
foreground = rgb(info['foreground'])
background = rgb(info['background'])
selection = [x+0.02 for x in background]
colours = [rgb(x) for x in info['colors']]
item = Selection(config, colours, foreground, background, selection,
working=name not in broken)
output.append(item)
return output
def rgb(colour):
colour = colour[1:]
return [x/255 for x in struct.unpack('BBB', bytes.fromhex(colour))]
def keypress(window, key):
if key.keyval == 65307:
Gtk.main_quit()
return None
def main():
configs = load_configs()
window = Gtk.Window()
2017-12-02 01:06:11 -06:00
window.modify_font(Pango.FontDescription('xos4 Terminus 9'))
2017-10-23 18:35:35 -05:00
window.set_property('type-hint', Gdk.WindowTypeHint.SPLASHSCREEN)
window.set_decorated(False)
window.set_resizable(False)
2017-12-02 01:06:11 -06:00
window.connect('leave-notify-event', Gtk.main_quit)
# window.set_property('skip-taskbar-hint', False)
# window.set_title('bar-dropdown')
# window.set_border_width(0)
# window.stick()
2017-10-23 18:35:35 -05:00
window.connect('delete-event', Gtk.main_quit)
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
box = Gtk.VBox()
for config in configs:
box.pack_start(config, False, False, 0)
scrolled.add(box)
window.add(scrolled)
2017-12-02 01:06:11 -06:00
window.set_size_request(200, 420)
2017-10-23 18:35:35 -05:00
window.show_all()
2017-12-02 01:06:11 -06:00
window.move(10, 35)
2017-10-23 18:35:35 -05:00
window.connect('key-press-event', keypress)
window.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
Gtk.main()
return None
if __name__ == "__main__":
main()