Skip to content

Commit cf56832

Browse files
committed
feat: add option to randomize new tag colors
1 parent 55de19a commit cf56832

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

timetagger/app/dialogs.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ def _set_default_color(self):
21482148
self._set_color(self._default_color)
21492149

21502150
def _set_random_color(self):
2151-
clr = "#" + Math.floor(Math.random() * 16777215).toString(16)
2151+
clr = utils.color_random()
21522152
self._set_color(clr)
21532153

21542154
def _set_color(self, clr):
@@ -3920,9 +3920,18 @@ def open(self, callback=None):
39203920
</select>
39213921
</div>
39223922
<h2><i class='fas'>\uf085</i>&nbsp;&nbsp;Misc</h2>
3923+
<div class='formlayout'>
3924+
<div>Default tag color:</div>
3925+
<select>
3926+
<option value='default'>Default</option>
3927+
<option value='name'>From Tag Name</option>
3928+
<option value='random'>Random</option>
3929+
</select>
3930+
</div>
39233931
<label>
39243932
<input type='checkbox' checked='true'></input>
3925-
Show elapsed time below start-button</label>
3933+
Show elapsed time below start-button
3934+
</label>
39263935
39273936
<hr style='margin-top: 1em;' />
39283937
@@ -3971,6 +3980,7 @@ def open(self, callback=None):
39713980
_, # Time repr header
39723981
self._repr_form,
39733982
_, # Misc header
3983+
self._tag_form,
39743984
self._stopwatch_label,
39753985
_, # hr
39763986
_, # Section: per device
@@ -4032,6 +4042,12 @@ def open(self, callback=None):
40324042
self._today_end_offset.value = today_end_offset
40334043
self._today_end_offset.onchange = self._on_today_end_offset_change
40344044

4045+
# Tag color
4046+
tag_color = window.simplesettings.get("tag_color")
4047+
self._tag_color = self._tag_form.children[1]
4048+
self._tag_color.value = tag_color
4049+
self._tag_color.onchange = self._on_tag_color_change
4050+
40354051
# Stopwatch
40364052
show_stopwatch = window.simplesettings.get("show_stopwatch")
40374053
self._stopwatch_check = self._stopwatch_label.children[0]
@@ -4128,6 +4144,10 @@ def _on_stopwatch_check(self):
41284144
show_stopwatch = bool(self._stopwatch_check.checked)
41294145
window.simplesettings.set("show_stopwatch", show_stopwatch)
41304146

4147+
def _on_tag_color_change(self):
4148+
tag_color = self._tag_color.value
4149+
window.simplesettings.set("tag_color", tag_color)
4150+
41314151

41324152
class GuideDialog(BaseDialog):
41334153
"""Dialog to have quick access to the guide."""

timetagger/app/stores.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,15 @@ def get_tag_info(self, tagz):
358358
def get_color_for_tag(self, tag):
359359
info = self.get_tag_info(tag)
360360
color = info.get("color", "")
361-
return color or window.front.COLORS.acc_clr
361+
if not color:
362+
if window.simplesettings.get("tag_color") == "tag_name":
363+
color = utils.color_from_name(tag)
364+
elif window.simplesettings.get("tag_color") == "random":
365+
color = utils.color_random()
366+
else:
367+
color = window.front.COLORS.acc_clr
368+
self.set_tag_info(tag, {"color": color})
369+
return color
362370

363371

364372
class RecordStore(BaseStore):

timetagger/app/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def color_from_name(name):
104104
_lasthashedcolors[name] = PALETTE1[color % len(PALETTE1)]
105105
return _lasthashedcolors[name]
106106

107+
def color_random():
108+
"""Generate a random color"""
109+
clr = "#" + Math.floor(Math.random() * 16777215).toString(16)
110+
return clr
111+
107112

108113
def create_palettes():
109114
# The Github color palette, consisting of 8 strong colors and 8 lighter variants.
@@ -629,6 +634,7 @@ def __init__(self):
629634
"today_snap_offset": "",
630635
"today_end_offset": "",
631636
"show_stopwatch": True,
637+
"tag_color": "default",
632638
}
633639
# The data store for synced source
634640
self._store = None

0 commit comments

Comments
 (0)