-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissues.py
162 lines (129 loc) · 4.57 KB
/
issues.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""Issue handling"""
from kivy import Logger
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import StringProperty, ListProperty, ColorProperty, DictProperty
from kivy.uix.boxlayout import BoxLayout
from reloadable_json import JsonObserver
Builder.load_string("""
<IssueEntry>
orientation: 'horizontal'
size_hint: 1, None
spacing: 4
Label:
text: root.issue_id
size: 50, 0
size_hint_x: None
text_size: self.size[0]-12, self.size[1]
halign: 'right'
valign: 'center'
font_size: 14
font_name: 'assets/FiraMono-Regular.ttf'
color: root.id_color
canvas.before:
Color:
rgba: root.id_background
RoundedRectangle:
pos: self.pos[0] + 2, self.pos[1] + 1
size: self.size[0] - 4, self.size[1] - 2
radius: [5,5]
Label:
text: root.issue_label
text_size: self.size[0], self.size[1]
halign: 'left'
valign: 'center'
font_size: 14
color: root.label_color
<IssueList>
orientation: 'vertical'
size: 300, 300
padding: 4
spacing: 4
canvas.before:
Color:
rgba: root.border_color
Line:
rounded_rectangle: self.pos[0]+2, self.pos[1]+2, self.size[0]-4, self.size[1]-4, 5, 100
Line:
points:
root.pos[0] + 6, \\
root.pos[1] + root.size[1] - 24 - 4, \\
root.pos[0] + root.size[0] - 6, \\
root.pos[1] + root.size[1] - 24 - 4
Label:
text: root.conf.get('label', 'GTD') if root.conf else "GTD"
size_hint: 1, None
size: 0, 24
color: root.header_color
bold: True
RecycleView:
id: rv
data: root.entries
viewclass: 'IssueEntry'
size_hint: 1, 1
RecycleBoxLayout:
orientation: 'vertical'
default_size: 0, 20
""")
class IssueEntry(BoxLayout):
issue_label = StringProperty()
issue_id = StringProperty()
# id_color = ColorProperty([0 / 256, 0 / 256, 0 / 256, 1])
id_color = ColorProperty([256 / 256, 256 / 256, 256 / 256, 1])
# id_background = ColorProperty([0 / 256, 132 / 256, 176 / 256, 1])
id_background = ColorProperty([24 / 256, 56 / 256, 107 / 256, 1])
label_color = ColorProperty([256 / 256, 256 / 256, 256 / 256, 1])
class IssueList(BoxLayout):
conf = DictProperty(None)
entries = ListProperty()
border_color = ColorProperty([249 / 256, 176 / 256, 0 / 256, 1])
header_color = ColorProperty([249 / 256, 176 / 256, 0 / 256, 1])
issue_list_path = StringProperty(None)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issue_list = None
self._observer = None
self.bind(conf=self._on_conf)
self.property('conf').dispatch(self)
def __del__(self):
if self._observer is not None:
self._observer.teardown()
def _on_conf(self, _instance, conf: dict) -> None:
if self._observer:
self._observer.teardown()
self._observer = None
path = conf.get("path", None) if conf else None
if path is not None:
self._observer = JsonObserver(path,
self.update_issue_list,
self._border_mark)
try:
self._observer.setup()
self._observer.on_modified(None)
except FileNotFoundError as e:
Logger.warning("Issues: %s", e)
self._border_mark(failed=True)
def update_issue_list(self, issue_list):
self.issue_list = issue_list
self.entries.clear()
for issue in issue_list['issues']:
self.entries.append({
'opacity': 1,
'issue_id': str(issue['id']),
'issue_label': issue['label'],
'size_hint': [1, None]
})
self.entries.append({
'issue_id': '',
'issue_label': '',
'opacity': 0,
'size_hint': [1, 1]
})
Clock.schedule_once(lambda dt: self.ids.rv.refresh_from_data())
def _border_mark(self, failed: bool) -> None:
if failed:
self.border_color = [228 / 256, 5 / 256, 41 / 256, 1]
self.header_color = [228 / 256, 5 / 256, 41 / 256, 1]
else:
self.border_color = [249 / 256, 176 / 256, 0 / 256, 1]
self.header_color = [249 / 256, 176 / 256, 0 / 256, 1]