1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """
20 Utilities used by drawers.
21 """
22
23
24 import wx
25
26
28 """
29 Convert between pixel coordinates and time coordinates.
30 """
31
32 - def __init__(self, size, time_type, time_period, divider_line_slider):
33 self.width, self.height = size
34 self.half_width = self.width / 2
35 self.half_height = self.height / 2
36 self.half_height = int(round(divider_line_slider * self.height))
37 self.time_type = time_type
38 self.time_period = time_period
39
41 """Return the x position in pixels as a float for the given time."""
42 delta1 = self.time_type.div_timedeltas(time - self.time_period.start_time,
43 self.time_period.delta())
44 float_res = self.width * delta1
45 return float_res
46
48 """Return the x position in pixels as an integer for the given time."""
49 return int(round(self.calc_exact_x(time)))
50
52 """Return the with in pixels as a float for the given time_period."""
53 return (self.calc_exact_x(time_period.end_time) -
54 self.calc_exact_x(time_period.start_time))
55
57 """Return the with in pixels as an integer for the given time_period."""
58 return (self.calc_x(time_period.end_time) -
59 self.calc_x(time_period.start_time)) + 1
60
62 """Return the time at pixel `x`."""
63 return self.time_type.get_time_at_x(self.time_period, float(x) / self.width)
64
66 """Return the time length between two x positions."""
67 return self.get_time(x1) - self.get_time(x2)
68
69
71 if bold:
72 weight = wx.FONTWEIGHT_BOLD
73 else:
74 weight = wx.FONTWEIGHT_NORMAL
75 return wx.Font(size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, weight)
76
77
79 r, g, b = color
80 new_r = int(r * factor)
81 new_g = int(g * factor)
82 new_b = int(b * factor)
83 return (new_r, new_g, new_b)
84