2017-10-28 08:23:58 -05:00
|
|
|
#!/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'
|
2017-10-28 08:23:58 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2017-12-17 12:06:39 -06:00
|
|
|
#self.connect('enter-notify-event', self.selected)
|
|
|
|
#self.connect('leave-notify-event', self.unselected)
|
2017-10-23 18:35:35 -05:00
|
|
|
self.connect('button-press-event', self.clicked)
|
|
|
|
self.add(self.hbox)
|
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
def clicked(self, button):
|
2017-10-23 18:35:35 -05:00
|
|
|
_, index = button.get_button()
|
|
|
|
if index == 1:
|
2017-12-17 12:06:39 -06:00
|
|
|
subprocess.run([PATH, 'load', self.name])
|
2017-10-23 18:35:35 -05:00
|
|
|
Gtk.main_quit()
|
|
|
|
return None
|
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
#def selected(self, *args):
|
|
|
|
# return None
|
2017-10-23 18:35:35 -05:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
#def unselected(self, *args):
|
|
|
|
# return None
|
2017-10-23 18:35:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
def load_configs():
|
|
|
|
broken = subprocess.check_output([PATH, 'check', GROUP])
|
|
|
|
broken = broken.decode('utf-8').split('\n')
|
|
|
|
path = '{}/.gorice/output.yaml'.format(os.environ['HOME'])
|
2017-12-17 12:06:39 -06:00
|
|
|
output = []
|
2017-10-23 18:35:35 -05:00
|
|
|
|
|
|
|
with open(path, 'r') as f:
|
|
|
|
data = yaml.load(f.read())
|
|
|
|
|
|
|
|
names = sorted(data['configs'])
|
2017-12-17 12:06:39 -06:00
|
|
|
|
2017-10-23 18:35:35 -05:00
|
|
|
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
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
window.modify_font(Pango.FontDescription('Ubuntu 10'))
|
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)
|
2017-10-23 18:35:35 -05:00
|
|
|
window.connect('delete-event', Gtk.main_quit)
|
2017-12-17 12:06:39 -06:00
|
|
|
#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
|
|
|
|
|
|
|
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()
|