-
Notifications
You must be signed in to change notification settings - Fork 0
/
sicc_window.py
124 lines (105 loc) · 4.35 KB
/
sicc_window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import gi
import math
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk
from sicc import GitAssistant
gtk_builder_file = os.path.splitext(__file__)[0] + '.ui'
COLOR_CYCLE = [
('#ffffff'), ('#d6e685'),
('#8cc665'), ('#44a340'),
('#1e6823')
]
class SiccWindow(object):
def __init__(self, *args, **kwargs):
self.color_to_counter = {}
for color in COLOR_CYCLE:
self.color_to_counter[color] = 0
self.assistant = GitAssistant()
self.builder = Gtk.Builder()
self.builder.add_from_file(gtk_builder_file)
self.window = self.builder.get_object('main_window')
self.window.connect('destroy', self.signal_window_destroy)
self.grid = self.builder.get_object('calendar_grid')
self.entry = self.builder.get_object('date_entry')
self.entry.connect('changed', self.signal_entry_changed)
self.entry.set_text('2016')
self.export = self.builder.get_object('export')
self.export.connect('clicked', self.signal_export)
self.window.show_all()
def signal_window_destroy(self, _):
self.window.destroy()
Gtk.main_quit()
def populate_calendar(self, cols, last, beginning):
for child in self.grid.get_children():
self.grid.remove(child)
for i in range(cols + 1):
for j in range(7):
if i == cols and j >= last:
continue
button = Gtk.Button()
button.connect('clicked', self.signal_button_press)
rgb = Gdk.RGBA()
rgb.parse(COLOR_CYCLE[0])
button.override_background_color(Gtk.StateFlags.NORMAL, rgb)
self.grid.attach(button, i, j, 1, 1)
self.grid.show_all()
def signal_button_press(self, button):
curr = button.get_style_context().get_background_color(Gtk.StateFlags.NORMAL)
counter = 0
color = COLOR_CYCLE[counter]
rgb = Gdk.RGBA()
rgb.parse(color)
while not rgb.equal(curr):
counter = (counter + 1) % len(COLOR_CYCLE)
color = COLOR_CYCLE[counter]
rgb.parse(color)
rgb.parse(COLOR_CYCLE[(counter + 1) % len(COLOR_CYCLE)])
button.override_background_color(Gtk.StateFlags.NORMAL, rgb)
if counter % len(COLOR_CYCLE) != 0:
self.color_to_counter[COLOR_CYCLE[counter % len(COLOR_CYCLE)]] -= 1
if (counter + 1) % len(COLOR_CYCLE) != 0:
self.color_to_counter[COLOR_CYCLE[(counter + 1) % len(COLOR_CYCLE)]] += 1
def signal_entry_changed(self, text):
text = text.get_text()
if text.isnumeric() and int(text) > 1900 and int(text) < 3000:
self.year = int(text)
self.params = self.assistant.calculate_start_date(self.year)
self.populate_calendar(self.params[0], self.params[1], self.params[2])
def signal_export(self, _):
color_max = 0
counter = len(COLOR_CYCLE) - 1
while counter > 0:
if self.color_to_counter[COLOR_CYCLE[counter]] != 0:
color_max = counter
counter = -1
counter -= 1
mask = self.get_mask()
for color in mask:
if color != 0 :
if color != math.ceil(int(color * 1.0 / color_max * 100) / 25):
print("Not a possible color scheme, still parsing...")
break
startday = self.params[2].toordinal()
self.assistant.generate_repo(startday, mask)
def get_mask(self):
mask = []
for i in range(self.params[0] + 1):
for j in range(7):
if i == self.params[0] and j >= self.params[1]:
break
button = self.grid.get_child_at(i, j)
curr = button.get_style_context().get_background_color(Gtk.StateFlags.NORMAL)
counter = 0
color = COLOR_CYCLE[counter]
rgb = Gdk.RGBA()
rgb.parse(color)
while not rgb.equal(curr):
counter = (counter + 1) % len(COLOR_CYCLE)
color = COLOR_CYCLE[counter]
rgb.parse(color)
mask.append(counter)
return mask
if __name__ == '__main__':
x = SiccWindow()
Gtk.main()