Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions timetagger/app/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,10 @@ def open(self, mode, record, callback=None):
self._delete_but2.onclick = self._delete2
self.maindiv.addEventListener("click", self._autocompleter.clear)

# Generate the next random tag color
color = utils.color_random()
window.simplesettings.set("next_random_color", color)

# Enable for some more info (e.g. during dev)
if False:
for x in [f"ID: {record.key}", f"Modified: {dt.time2localstr(record.mt)}"]:
Expand Down Expand Up @@ -2148,7 +2152,7 @@ def _set_default_color(self):
self._set_color(self._default_color)

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

def _set_color(self, clr):
Expand Down Expand Up @@ -3920,9 +3924,18 @@ def open(self, callback=None):
</select>
</div>
<h2><i class='fas'>\uf085</i>&nbsp;&nbsp;Misc</h2>
<div class='formlayout'>
<div>Default tag color:</div>
<select>
<option value='default'>Yellow</option>
<option value='tag_name'>From Name</option>
<option value='random'>Random</option>
</select>
</div>
<label>
<input type='checkbox' checked='true'></input>
Show elapsed time below start-button</label>
Show elapsed time below start-button
</label>

<hr style='margin-top: 1em;' />

Expand Down Expand Up @@ -3971,6 +3984,7 @@ def open(self, callback=None):
_, # Time repr header
self._repr_form,
_, # Misc header
self._tag_form,
self._stopwatch_label,
_, # hr
_, # Section: per device
Expand Down Expand Up @@ -4032,6 +4046,12 @@ def open(self, callback=None):
self._today_end_offset.value = today_end_offset
self._today_end_offset.onchange = self._on_today_end_offset_change

# Tag color
tag_color = window.simplesettings.get("tag_color")
self._tag_color = self._tag_form.children[1]
self._tag_color.value = tag_color
self._tag_color.onchange = self._on_tag_color_change

# Stopwatch
show_stopwatch = window.simplesettings.get("show_stopwatch")
self._stopwatch_check = self._stopwatch_label.children[0]
Expand Down Expand Up @@ -4128,6 +4148,10 @@ def _on_stopwatch_check(self):
show_stopwatch = bool(self._stopwatch_check.checked)
window.simplesettings.set("show_stopwatch", show_stopwatch)

def _on_tag_color_change(self):
tag_color = self._tag_color.value
window.simplesettings.set("tag_color", tag_color)


class GuideDialog(BaseDialog):
"""Dialog to have quick access to the guide."""
Expand Down
10 changes: 9 additions & 1 deletion timetagger/app/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,15 @@ def get_tag_info(self, tagz):
def get_color_for_tag(self, tag):
info = self.get_tag_info(tag)
color = info.get("color", "")
return color or window.front.COLORS.acc_clr
if not color:
if window.simplesettings.get("tag_color") == "tag_name":
color = utils.color_from_name(tag)
elif window.simplesettings.get("tag_color") == "random":
color = window.simplesettings.get("next_random_color")
else:
color = window.front.COLORS.acc_clr
self.set_tag_info(tag, {"color": color})
return color


class RecordStore(BaseStore):
Expand Down
7 changes: 7 additions & 0 deletions timetagger/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def color_from_name(name):
return _lasthashedcolors[name]


def color_random():
"""Generate a random color"""
clr = "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
return clr


def create_palettes():
# The Github color palette, consisting of 8 strong colors and 8 lighter variants.
# The difference between these variants is pretty big.
Expand Down Expand Up @@ -629,6 +635,7 @@ def __init__(self):
"today_snap_offset": "",
"today_end_offset": "",
"show_stopwatch": True,
"tag_color": "default",
}
# The data store for synced source
self._store = None
Expand Down
Loading