-
Notifications
You must be signed in to change notification settings - Fork 9
/
timeline.py
248 lines (169 loc) · 6.76 KB
/
timeline.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, math
from PyQt4 import QtGui, QtCore
DELAY = 100 * 1 # 5 seconds in milli-seconds
class Timeline:
def drawRectangles(self, qp, start, end, lines):
width = end["x"] - start["x"]
height = end["y"] - start["y"]
color = QtGui.QColor(0, 0, 0)
color.setNamedColor('#d4d4d4')
qp.setPen(color)
# white
qp.setBrush(QtGui.QColor(255, 255, 255))
qp.drawRect(start["x"] - 2, start["y"] - 2, width, height)
# blue
qp.setBrush(QtGui.QColor(0, 0, 255))
qp.drawRect(start["x"] -2 , start["y"] + lines["long"] + 3, width , height - lines["long"] - 3)
# green
qp.setBrush(QtGui.QColor(0, 255, 0))
qp.drawRect(start["x"] -2 + 50 , start["y"] + lines["long"] + 3, width - 180 , height - lines["long"] - 3)
def drawLines(self, qp, start, end, lines):
pen = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
qp.setPen(pen)
cnt = 0
for x in xrange( start["x"], end["x"], (end["x"] - start["x"]) / 25 ) :
cnt = cnt + 1
if cnt % 5 == 0:
qp.drawLine(x, start["y"], x, start["y"] + lines["long"] )
else :
qp.drawLine(x, start["y"], x, start["y"] + lines["short"])
def drawTicker(self, qp, start, end, lines, ctr):
pen = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
qp.setPen(pen)
qp.drawLine(start["x"] - 2 + ctr, start["y"] + lines["long"] + 3 , start["x"] - 2 + ctr, end["y"])
ctr = ctr + 1
class Widget(QtGui.QWidget) :
ctr = 0
def __init__(self, timeline):
super(Widget, self).__init__()
self.timeline = timeline
self.initUI()
self.timer = QtCore.QTimer(self)
self.connect(self.timer,
QtCore.SIGNAL("timeout()"),
self.update)
self.timer.start(DELAY)
def initUI(self):
self.setGeometry(300, 300, 350, 100)
self.setWindowTitle('Colours')
self.show()
def paintEvent(self, e):
start = {"x" : 10, "y" : 15 }
end = {"x" : 300, "y" : 60 }
lines = { "short" : 5, "long" : 12 }
qp = QtGui.QPainter()
qp.begin(self)
self.timeline.drawRectangles(qp, start, end, lines)
self.timeline.drawLines(qp, start, end, lines)
self.timeline.drawTicker(qp, start, end, lines, self.ctr)
qp.end()
def update( self) :
self.ctr = self.ctr + 1
self.repaint()
class AnotherTimeline(QtGui.QWidget):
def __init__(self, parent, my_range, loc):
super(AnotherTimeline, self).__init__()
self.parent = parent
self.w = loc["w"]
self.h = loc["h"]
self.startX = loc["x"]
self.startY = loc["y"]
self.bannerStart = self.bannerEnd = 0
self.initUI(my_range)
def initUI(self, my_range):
self.setMinimumSize(1, 30 )
self.value = 0
self.num = []
self.my_range = my_range
for x in range( my_range + 1 ) :
if x % 60 == 0 :
self.num.append( x )
def setValue(self, value):
self.value = value
def setBannerDuration(self, start, end) :
self.bannerStart = start
self.bannerEnd = end
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self.parent)
self.drawWidget(qp)
qp.end()
def drawWidget(self, qp):
if self.my_range <= 30 :
self.interval = 1 # 1 sec for 10 sec
elif self.my_range <= 60 :
self.interval = 5 # 5 sec for 60 sec
elif self.my_range <= 180 :
self.interval = 10
elif self.my_range <= 300 :
self.interval = 30
elif self.my_range <= 600 :
self.interval = 60
else :
self.interval = 600
font = QtGui.QFont('Serif', 7, QtGui.QFont.Light)
qp.setFont(font)
size = self.size()
# step = int(round(w / 10.0))
count_of_steps = self.my_range / ( 1.0 * self.interval)
step = self.w / (1.0 * count_of_steps) # size of each count
step_per_unit = (step / self.interval)
till = step_per_unit * self.value
full = self.w
# print "till %s full %s value %s" %( str(till), str(full), str(self.value) )
# video progress bar
qp.setPen(QtGui.QColor(255, 255, 255))
qp.setBrush(QtGui.QColor(255, 255, 184))
qp.drawRect(self.startX, self.startY, till, self.h)
#banner duration
qp.setPen(QtGui.QColor(255, 255, 255))
qp.setBrush(QtGui.QColor("red"))
qp.drawRect(self.startX + step_per_unit * self.bannerStart , self.startY, step_per_unit * (self.bannerEnd - self.bannerStart), self.h)
#main timeline box
pen = QtGui.QPen(QtGui.QColor(20, 20, 20), 1, QtCore.Qt.SolidLine)
qp.setPen(pen)
qp.setBrush(QtCore.Qt.NoBrush)
qp.drawRect(self.startX, self.startY, full, self.h)
j = 0
countNumber = int(self.interval)
for i in range(int(step), self.w, int(step)):
qp.drawLine( self.startX + i, self.startY, self.startX + i, self.startY + 5)
metrics = qp.fontMetrics()
fw = metrics.width(str( countNumber))
qp.drawText( self.startX + i-fw, self.startY + 15, str(countNumber))
countNumber = countNumber + self.interval
class Communicate(QtCore.QObject):
updateBW = QtCore.pyqtSignal(int)
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
#self.initUI()
def initUI(self, my_range ):
sld = QtGui.QSlider(QtCore.Qt.Horizontal, self)
sld.setFocusPolicy(QtCore.Qt.NoFocus)
sld.setRange(0, my_range)
sld.setValue(5)
sld.setGeometry(30, 40, 150, 30)
self.c = Communicate()
self.wid = AnotherTimeline( self, my_range, {"w" : 400, "h" : 50, "x" : 100, "y" : 100} )
self.c.updateBW[int].connect(self.wid.setValue)
sld.valueChanged[int].connect(self.changeValue)
self.setGeometry(300, 300, 390, 210)
self.setWindowTitle('Burning widget')
self.show()
def changeValue(self, value):
self.c.updateBW.emit(value)
self.repaint()
def paintEvent(self, e):
self.wid.paintEvent(e)
def main():
app = QtGui.QApplication(sys.argv)
#ex = Timeline()
#widget = Widget(ex)
ey = Example()
ey.initUI(84)
sys.exit(app.exec_())
if __name__ == '__main__':
main()