forked from frans-fuerst/track
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimegraph.py
81 lines (63 loc) · 2.4 KB
/
timegraph.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore, Qt, uic
import track_common
class timegraph(QtGui.QFrame):
def __init__(self, parent):
self._tracker = None
super(timegraph, self).__init__(parent)
self.setMouseTracking(True)
self._selected = None
def leaveEvent(self, e):
self.select()
def setTracker(self, tracker):
self._tracker = tracker
def paintEvent(self, e):
super(timegraph, self).paintEvent(e)
if self._tracker is None:
return
qp = QtGui.QPainter()
qp.begin(self)
self.drawPoints(qp)
qp.end()
def mouseMoveEvent(self, e):
_index = self._tracker.begin_index() - 50 + e.x() - 1
_cs, _activity = self._tracker.info(_index)
_info_str = "%s: %s (%s)" % (
track_common.mins_to_dur(_index), _activity,
track_common.mins_to_dur(_cs[1]-_cs[0]))
# print("time: %d/%s" % (
# (e.x(), _info)))
self.select(_cs[0], _cs[1])
self.setToolTip(_info_str)
def drawPoints(self, qp):
x = self._tracker.begin_index()
_start_index = self._tracker.begin_index() - 50
for i in range(self.width() - 2):
_index = _start_index + i
# undo: evaluate always
_is_private = self._tracker.is_private(_index)
if i < 50 or _index > self._tracker.get_current_minute():
# dark gray on borders of tracked time
qp.setPen(QtCore.Qt.gray)
elif self._tracker.get_current_minute() == _index:
# black 'now' line
qp.setPen(QtCore.Qt.black)
elif not self._tracker.is_active(_index):
qp.setPen(QtCore.Qt.white)
elif _is_private:
qp.setPen(QtCore.Qt.darkCyan)
else:
qp.setPen(QtCore.Qt.cyan)
qp.drawLine(i + 1, 0, i + 1, self.height() - 2)
if self._selected is None:
return
qp.setPen(QtCore.Qt.blue)
for i in range(self._selected[0], self._selected[1] + 1):
qp.drawLine(i - _start_index, 0 + 20, i - _start_index, self.height() - 2 - 20)
def select(self, begin=None, end=None):
if not begin:
self._selected = None
else:
self._selected = (begin, end)
self.update()