A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
grid.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3import cairo
4import sys
5import re
6import gtk
7
8
9
11
17 def __init__(self, start=0, end=0, value=''):
18 """! Initializer
19 @param self this object
20 @param start start
21 @param end end
22 @param value value
23 """
24 self.start = start
25 self.end = end
26 self.value = value
27
29
33 def __init__(self, at=0, value=''):
34 """! Initializer
35 @param self this object
36 @param at you
37 @param value value
38 """
39 self.at = at
40 self.value = value
41
43
47 def __init__(self, at=0, value=0.0):
48 """! Initializer
49 @param self this object
50 @param at you
51 @param value value
52 """
53 self.at = at
54 self.value = value
55
57
61 def __init__(self, at=0, value=0.0):
62 """! Initializer
63 @param self this object
64 @param at you
65 @param value value
66 """
67 self.at = at
68 self.value = value
69def ranges_cmp(a, b):
70 diff = a.start - b.start
71 if diff < 0:
72 return -1
73 elif diff > 0:
74 return +1
75 else:
76 return 0
77def events_cmp(a, b):
78 diff = a.at - b.at
79 if diff < 0:
80 return -1
81 elif diff > 0:
82 return +1
83 else:
84 return 0
85
87
91 def __init__(self, name=''):
92 """! Initializer
93 @param self this object
94 @param name name
95 """
96 self.name = name
97 self.ranges = []
98 return
99 def __search(self, key):
100 """! Search
101 @param self this object
102 @param key key
103 @return index if found or -1 if not found
104 """
105 l = 0
106 u = len(self.ranges)-1
107 while l <= u:
108 i = int((l + u) / 2)
109 if key >= self.ranges[i].start and key <= self.ranges[i].end:
110 return i
111 elif key < self.ranges[i].start:
112 u = i - 1
113 else:
114 # key > self.ranges[i].end
115 l = i + 1
116 return - 1
117 def add_range(self, range):
118 """! Add range
119 @param self this object
120 @param range range
121 @return none
122 """
123 self.ranges.append(range)
124 def get_all(self):
125 """! Get all ranges
126 @param self this object
127 @return the ranges
128 """
129 return self.ranges
130 def get_ranges(self, start, end):
131 """! Get selected ranges
132 @param self this object
133 @param start range start
134 @param end range end
135 @return the range or and empty list
136 """
137 s = self.__search(start)
138 e = self.__search(end)
139 if s == -1 and e == -1:
140 return []
141 elif s == -1:
142 return self.ranges[0:e + 1]
143 elif e == -1:
144 return self.ranges[s:len(self.ranges)]
145 else:
146 return self.ranges[s:e + 1]
147 def get_ranges_bounds(self, start, end):
148 """! Get ranges bounds
149 @param self this object
150 @param start range start
151 @param end range end
152 @return range
153 """
154 s = self.__search(start)
155 e = self.__search(end)
156 if s == -1 and e == -1:
157 return (0, 0)
158 elif s == -1:
159 return (0, e + 1)
160 elif e == -1:
161 return (s, len(self.ranges))
162 else:
163 return (s, e + 1)
164 def sort(self):
165 """! Sort ranges
166 @param self this object
167 @return none
168 """
169 self.ranges.sort(ranges_cmp)
170 def get_bounds(self):
171 """! Get bounds
172 @param self this object
173 @return the bounds
174 """
175 if len(self.ranges) > 0:
176 lo = self.ranges[0].start
177 hi = self.ranges[len(self.ranges)-1].end
178 return (lo, hi)
179 else:
180 return (0, 0)
181
183
187 def __init__(self, name=''):
188 """! Get ranges bounds
189 @param self this object
190 @param name name
191 """
192 self.name = name
193 self.events = []
194 def __search(self, key):
195 """! Search function
196 @param self this object
197 @param key the key
198 @return event index
199 """
200 l = 0
201 u = len(self.events)-1
202 while l <= u:
203 i = int((l + u) / 2)
204 if key == self.events[i].at:
205 return i
206 elif key < self.events[i].at:
207 u = i - 1
208 else:
209 # key > self.events[i].at
210 l = i + 1
211 return l
212 def add_event(self, event):
213 """! Add Event
214 @param self this object
215 @param event event to add
216 @return none
217 """
218 self.events.append(event)
219 def get_events(self, start, end):
220 """! Get Events
221 @param self this object
222 @param start starting event
223 @param end ending event
224 @return the events
225 """
226 s = self.__search(start)
227 e = self.__search(end)
228 return self.events[s:e + 1]
229 def get_events_bounds(self, start, end):
230 """! Get Events Bounds
231 @param self this object
232 @param start starting event
233 @param end ending event
234 @return event bounds
235 """
236 s = self.__search(start)
237 e = self.__search(end)
238 return (s, e + 1)
239 def sort(self):
240 """! Sort function
241 @param self this object
242 @return none
243 """
244 self.events.sort(events_cmp)
245 def get_bounds(self):
246 """! Get Bounds
247 @param self this object
248 @return the bounds
249 """
250 if len(self.events) > 0:
251 lo = self.events[0].at
252 hi = self.events[-1].at
253 return (lo, hi)
254 else:
255 return (0, 0)
256
257
259
267 def __init__(self, name=''):
268 """! Initializer
269 @param self this object
270 @param name name
271 """
272 self.ranges = []
273 self.event_str = []
274 self.event_int = []
275 self.name = name
276 def get_range(self, name):
277 """! Get range
278 @param self this object
279 @param name name
280 @return the range
281 """
282 for range in self.ranges:
283 if range.name == name:
284 return range
285 timeline = TimelineDataRange(name)
286 self.ranges.append(timeline)
287 return timeline
288 def get_event_str(self, name):
289 """! Get Event String
290 @param self this object
291 @param name name
292 @return the event string
293 """
294 for event_str in self.event_str:
295 if event_str.name == name:
296 return event_str
297 timeline = TimelineEvent(name)
298 self.event_str.append(timeline)
299 return timeline
300 def get_event_int(self, name):
301 """! Get Event Int
302 @param self this object
303 @param name name
304 @return eevent int
305 """
306 for event_int in self.event_int:
307 if event_int.name == name:
308 return event_int
309 timeline = TimelineEvent(name)
310 self.event_int.append(timeline)
311 return timeline
312 def get_ranges(self):
313 """! Get Ranges
314 @param self this object
315 @return the ranges
316 """
317 return self.ranges
318 def get_events_str(self):
319 """! Get Events string
320 @param self this object
321 @return event string
322 """
323 return self.event_str
324 def get_events_int(self):
325 """! Get Events int
326 @param self this object
327 @return evrnt int
328 """
329 return self.event_int
330 def sort(self):
331 """! Sort the ranges and events
332 @param self this object
333 @return none
334 """
335 for range in self.ranges:
336 range.sort()
337 for event in self.event_int:
338 event.sort()
339 for event in self.event_str:
340 event.sort()
341 def get_bounds(self):
342 """! Get Bounds
343 @param self this object
344 @return the bounds
345 """
346 lo = 0
347 hi = 0
348 for range in self.ranges:
349 (range_lo, range_hi) = range.get_bounds()
350 if range_lo < lo:
351 lo = range_lo
352 if range_hi > hi:
353 hi = range_hi
354 for event_str in self.event_str:
355 (ev_lo, ev_hi) = event_str.get_bounds()
356 if ev_lo < lo:
357 lo = ev_lo
358 if ev_hi > hi:
359 hi = ev_hi
360 for event_int in self.event_int:
361 (ev_lo, ev_hi) = event_int.get_bounds()
362 if ev_lo < lo:
363 lo = ev_lo
364 if ev_hi > hi:
365 hi = ev_hi
366 return (lo, hi)
367
368
370
372 def __init__(self):
373 """ Initializer
374 @param self: this object
375 """
376 self.timelines = []
377 def get(self, name):
378 """! Get Timeline
379 @param self this object
380 @param name name
381 @return the timeline for the name
382 """
383 for timeline in self.timelines:
384 if timeline.name == name:
385 return timeline
386 timeline = Timeline(name)
387 self.timelines.append(timeline)
388 return timeline
389 def get_all(self):
390 """! Get All Timeline
391 @param self this object
392 @return all timelines
393 """
394 return self.timelines
395 def sort(self):
396 """! Sort the timelines
397 @param self this object
398 @return none
399 """
400 for timeline in self.timelines:
401 timeline.sort()
402 def get_bounds(self):
403 """! Get Bounds
404 @param self this object
405 @return the bounds for all timelines
406 """
407 lo = 0
408 hi = 0
409 for timeline in self.timelines:
410 (t_lo, t_hi) = timeline.get_bounds()
411 if t_lo < lo:
412 lo = t_lo
413 if t_hi > hi:
414 hi = t_hi
415 return (lo, hi)
417 """! Get All Ranges
418 @param self this object
419 @return the keys for all ranges
420 """
421 range_values = {}
422 for timeline in self.timelines:
423 for ranges in timeline.get_ranges():
424 for ran in ranges.get_all():
425 range_values[ran.value] = 1
426 return range_values.keys()
427
428
429class Color:
430
436 def __init__(self, r=0.0, g=0.0, b=0.0):
437 """! Initializer
438 @param self: this object
439 @param r: red
440 @param g: green
441 @param b: blue
442 """
443 self.r = r
444 self.g = g
445 self.b = b
446 def set(self, r, g, b):
447 """! Set color
448 @param self: this object
449 @param r: red
450 @param g: green
451 @param b: blue
452 @return none
453 """
454 self.r = r
455 self.g = g
456 self.b = b
457
458
459class Colors:
460
465 default_colors = [Color(1, 0, 0), Color(0, 1, 0), Color(0, 0, 1), Color(1, 1, 0), Color(1, 0, 1), Color(0, 1, 1)]
466 def __init__(self):
467 """! Initializer
468 @param self this object
469 """
470 self.__colors = {}
471 def add(self, name, color):
472 """! Add
473 @param self this object
474 @param name name of the color
475 @param color color value
476 @return none
477 """
478 self.__colors[name] = color
479 def lookup(self, name):
480 """! Lookup name
481 @param self this object
482 @param name name
483 @return named color
484 """
485 if not self.__colors.has_key(name):
486 self.add(name, self.default_colors.pop())
487 return self.__colors.get(name)
488
489
491
501 def __init__(self):
502 """! Initializer
503 @param self this object
504 """
505 self.__padding = 10
506 def set_padding(self, padding):
507 """! Set padding
508 @param self this object
509 @param padding padding
510 @return none
511 """
512 self.__padding = padding
513 def set_legends(self, legends, colors):
514 """! Set padding
515 @param self this object
516 @param legends legends
517 @param colors colors
518 @return none
519 """
520 self.__legends = legends
521 self.__colors = colors
522 def layout(self, width):
523 """! Set padding
524 @param self this object
525 @param width width
526 @return none
527 """
528 self.__width = width
529 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
530 ctx = cairo.Context(surface)
531 line_height = 0
532 total_height = self.__padding
533 line_used = self.__padding
534 for legend in self.__legends:
535 (t_width, t_height) = ctx.text_extents(legend)[2:4]
536 item_width = self.__padding + self.__padding + t_width + self.__padding
537 item_height = t_height + self.__padding
538 if item_height > line_height:
539 line_height = item_height
540 if line_used + item_width > self.__width:
541 line_used = self.__padding + item_width
542 total_height += line_height
543 else:
544 line_used += item_width
545 x = line_used - item_width
546 total_height += line_height
547 self.__height = total_height
548
549 def get_height(self):
550 """! Set padding
551 @param self this object
552 @return height
553 """
554 return self.__height
555 def draw(self, ctx):
556 """! Set padding
557 @param self this object
558 @param ctx ctx
559 @return none
560 """
561 i = 0
562 line_height = 0
563 total_height = self.__padding
564 line_used = self.__padding
565 for legend in self.__legends:
566 (t_width, t_height) = ctx.text_extents(legend)[2:4]
567 item_width = self.__padding + self.__padding + t_width + self.__padding
568 item_height = t_height + self.__padding
569 if item_height > line_height:
570 line_height = item_height
571 if line_used + item_width > self.__width:
572 line_used = self.__padding + item_width
573 total_height += line_height
574 else:
575 line_used += item_width
576 x = line_used - item_width
577 ctx.rectangle(x, total_height, self.__padding, self.__padding)
578 ctx.set_source_rgb(0, 0, 0)
579 ctx.set_line_width(2)
580 ctx.stroke_preserve()
581 ctx.set_source_rgb(self.__colors[i].r,
582 self.__colors[i].g,
583 self.__colors[i].b)
584 ctx.fill()
585 ctx.move_to(x + self.__padding*2, total_height + t_height)
586 ctx.set_source_rgb(0, 0, 0)
587 ctx.show_text(legend)
588 i += 1
589
590
592
614 def __init__(self):
615 """! Initializer
616 @param self this object
617 """
618 self.padding = 10
619 return
620 def get_height(self):
621 """! Get Height
622 @param self this object
623 @return height
624 """
625 return self.height
626 def set_timelines(self, timelines, colors):
627 """! Set Timelines
628 @param self this object
629 @param timelines timelines
630 @param colors colors
631 @return none
632 """
633 self.timelines = timelines
634 self.colors = colors
635 def set_render_range(self, start, end):
636 """! Set Render Range
637 @param self this object
638 @param start start
639 @param end end
640 @return none
641 """
642 self.start = start
643 self.end = end
645 """! Get Data X Start
646 @param self: this object
647 @return X start
648 """
649 return self.padding / 2 + self.left_width + self.padding + self.right_width + self.padding / 2
650 def layout(self, width):
651 """! Get Data X Start
652 @param self this object
653 @param width width
654 @return none
655 """
656 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
657 ctx = cairo.Context(surface)
658 max_text_height = ctx.text_extents("ABCDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789")[3]
659
660 left_width = 0
661 right_width = 0
662 left_n_lines = 0
663 range_n = 0
664 eventint_n = 0
665 eventstr_n = 0
666 for timeline in self.timelines.get_all():
667 left_n_lines += 1
668 t_width = ctx.text_extents(timeline.name)[2]
669 left_width = max(left_width, t_width)
670 for rang in timeline.get_ranges():
671 t_width = ctx.text_extents(rang.name)[2]
672 right_width = max(right_width, t_width)
673 range_n += 1
674 for events_int in timeline.get_events_int():
675 t_width = ctx.text_extents(events_int.name)[2]
676 right_width = max(right_width, t_width)
677 eventint_n += 1
678 for events_str in timeline.get_events_str():
679 t_width = ctx.text_extents(events_str.name)[2]
680 right_width = max(right_width, t_width)
681 eventstr_n += 1
682
683 left_height = left_n_lines * max_text_height + (left_n_lines - 1) * self.padding
684 right_n_lines = range_n + eventint_n + eventstr_n
685 right_height = (right_n_lines - 1) * self.padding + right_n_lines * max_text_height
686 right_data_height = (eventint_n + eventstr_n) * (max_text_height + 5) + range_n * 10
687 right_data_height += (right_n_lines - 1) * self.padding
688
689 height = max(left_height, right_height)
690 height = max(height, right_data_height)
691
692 self.left_width = left_width
693 self.right_width = right_width
694 self.max_text_height = max_text_height
695 self.width = width
696 self.height = height + self.padding
697 def draw_line(self, ctx, x, y, width, height):
698 """! Draw Line
699 @param self this object
700 @param ctx ctx
701 @param x x
702 @param y y
703 @param width width
704 @param height height
705 @return none
706 """
707 ctx.move_to(x, y)
708 ctx.rel_line_to(width, height)
709 ctx.close_path()
710 ctx.set_operator(cairo.OPERATOR_SOURCE)
711 ctx.set_line_width(1.0)
712 ctx.set_source_rgb(0, 0, 0)
713 ctx.stroke()
714 def draw_events(self, ctx, events, x, y, width, height):
715 """! Draw Event
716 @param self this object
717 @param ctx ctx
718 @param events events
719 @param x x
720 @param y y
721 @param width width
722 @param height height
723 @return none
724 """
725 if (self.grey_background % 2) == 0:
726 ctx.rectangle(x, y - self.padding / 2,
727 width, height + self.padding)
728 ctx.set_source_rgb(0.9, 0.9, 0.9)
729 ctx.fill()
730 last_x_drawn = int(x)
731 (lo, hi) = events.get_events_bounds(self.start, self.end)
732 for event in events.events[lo:hi]:
733 real_x = int(x + (event.at - self.start) * width / (self.end - self.start))
734 if real_x > last_x_drawn + 2:
735 ctx.rectangle(real_x, y, 1, 1)
736 ctx.set_source_rgb(1, 0, 0)
737 ctx.stroke()
738 ctx.move_to(real_x, y + self.max_text_height)
739 ctx.set_source_rgb(0, 0, 0)
740 ctx.show_text(str(event.value))
741 last_x_drawn = real_x
742 self.grey_background += 1
743 def draw_ranges(self, ctx, ranges, x, y, width, height):
744 """! Draw Ranges
745 @param self this object
746 @param ctx ctx
747 @param ranges ranges
748 @param x x
749 @param y y
750 @param width width
751 @param height height
752 @return none
753 """
754 if (self.grey_background % 2) == 0:
755 ctx.rectangle(x, y - self.padding / 2,
756 width, height + self.padding)
757 ctx.set_source_rgb(0.9, 0.9, 0.9)
758 ctx.fill()
759 last_x_drawn = int(x - 1)
760 (lo, hi) = ranges.get_ranges_bounds(self.start, self.end)
761 for data_range in ranges.ranges[lo:hi]:
762 s = max(data_range.start, self.start)
763 e = min(data_range.end, self.end)
764 x_start = int(x + (s - self.start) * width / (self.end - self.start))
765 x_end = int(x + (e - self.start) * width / (self.end - self.start))
766 if x_end > last_x_drawn:
767 ctx.rectangle(x_start, y, x_end - x_start, 10)
768 ctx.set_source_rgb(0, 0, 0)
769 ctx.stroke_preserve()
770 color = self.colors.lookup(data_range.value)
771 ctx.set_source_rgb(color.r, color.g, color.b)
772 ctx.fill()
773 last_x_drawn = x_end
774
775 self.grey_background += 1
776
777 def draw(self, ctx):
778 """! Draw
779 @param self this object
780 @param ctx ctx
781 @return none
782 """
783 timeline_top = 0
784 top_y = self.padding / 2
785 left_x_start = self.padding / 2
786 left_x_end = left_x_start + self.left_width
787 right_x_start = left_x_end + self.padding
788 right_x_end = right_x_start + self.right_width
789 data_x_start = right_x_end + self.padding / 2
790 data_x_end = self.width
791 data_width = data_x_end - data_x_start
792 cur_y = top_y
793 self.draw_line(ctx, 0, 0, self.width, 0)
795 for timeline in self.timelines.get_all():
796 (y_bearing, t_width, t_height) = ctx.text_extents(timeline.name)[1:4]
797 ctx.move_to(left_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
798 ctx.show_text(timeline.name)
799 for events_int in timeline.get_events_int():
800 (y_bearing, t_width, t_height) = ctx.text_extents(events_int.name)[1:4]
801 ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
802 ctx.show_text(events_int.name)
803 self.draw_events(ctx, events_int, data_x_start, cur_y, data_width, self.max_text_height + 5)
804 cur_y += self.max_text_height + 5 + self.padding
805 self.draw_line(ctx, right_x_start - self.padding / 2, cur_y - self.padding / 2,
806 self.right_width + self.padding, 0)
807
808 for events_str in timeline.get_events_str():
809 (y_bearing, t_width, t_height) = ctx.text_extents(events_str.name)[1:4]
810 ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
811 ctx.show_text(events_str.name)
812 self.draw_events(ctx, events_str, data_x_start, cur_y, data_width, self.max_text_height + 5)
813 cur_y += self.max_text_height + 5 + self.padding
814 self.draw_line(ctx, right_x_start - self.padding / 2, cur_y - self.padding / 2,
815 self.right_width + self.padding, 0)
816 for ranges in timeline.get_ranges():
817 (y_bearing, t_width, t_height) = ctx.text_extents(ranges.name)[1:4]
818 ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
819 ctx.show_text(ranges.name)
820 self.draw_ranges(ctx, ranges, data_x_start, cur_y, data_width, 10)
821 cur_y += self.max_text_height + self.padding
822 self.draw_line(ctx, right_x_start - self.padding / 2, cur_y - self.padding / 2,
823 self.right_width + self.padding, 0)
824 self.draw_line(ctx, 0, cur_y - self.padding / 2,
825 self.width, 0)
826 bot_y = cur_y - self.padding / 2
827 self.draw_line(ctx, left_x_end + self.padding / 2, 0,
828 0, bot_y)
829 self.draw_line(ctx, right_x_end + self.padding / 2, 0,
830 0, bot_y)
831
832
834
848 def __init__(self):
849 """! Initializer
850 @param self this object
851 """
852 self.__top = 0
853 return
854 def set_bounds(self, lo, hi):
855 """! Set Bounds
856 @param self this object
857 @param lo lo
858 @param hi hi
859 @return none
860 """
861 self.__lo = lo
862 self.__hi = hi
863 def get_position(self, x):
864 """! Get Position
865 @param self this object
866 @param x x
867 @return real x
868 """
869 real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo)
870 return real_x
871 def set_top(self):
872 """! Set Top
873 @param self this object
874 @return none
875 """
876 self.__top = 1
877 def set_bot(self):
878 """! Set Bottom
879 @param self this object
880 @return none
881 """
882 self.__top = 0
883 def layout(self, width):
884 """! Layout
885 @param self this object
886 @param width width
887 @return none
888 """
889 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
890 ctx = cairo.Context(surface)
891
892 # calculate scale delta
893 data_delta = self.__hi - self.__lo
894 closest = 1
895 while (closest*10) < data_delta:
896 closest *= 10
897 if (data_delta / closest) == 0:
898 delta = closest
899 elif (data_delta / closest) == 1:
900 delta = closest / 10
901 else:
902 delta = closest
903 start = self.__lo - (self.__lo % delta) + delta
904 end = self.__hi - (self.__hi % delta)
905
906 self.__delta = delta
907 self.__width = width
908
909 # calculate text height
910 max_text_height = ctx.text_extents("ABCDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789")[3]
911 self.max_text_height = max_text_height
912 height = max_text_height + 10
913 self.__height = height
914
915 def get_height(self):
916 """! Get Height
917 @param self: this object
918 @return height
919 """
920 return self.__height
921 def draw(self, ctx):
922 """! Draw
923 @param self this object
924 @param ctx ctx
925 @return none
926 """
927 delta = self.__delta
928 start = self.__lo - (self.__lo % delta) + delta
929 end = self.__hi - (self.__hi % delta)
930
931 if self.__top == 1:
932 s = -1
933 else:
934 s = 1
935 # print scale points
936 ctx.set_source_rgb(0, 0, 0)
937 ctx.set_line_width(1.0)
938 ticks = range(int(start), int(end + delta), int(delta))
939 for x in ticks:
940 real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo)
941 ctx.move_to(real_x, 0)
942 ctx.line_to(real_x, 5*s)
943 ctx.close_path()
944 ctx.stroke()
945 (t_y_bearing, t_width, t_height) = ctx.text_extents(str(x))[1:4]
946 if self.__top:
947 text_delta = t_height + t_y_bearing
948 else:
949 text_delta = -t_y_bearing
950 ctx.move_to(real_x - t_width / 2, (5 + 5 + text_delta)*s)
951 ctx.show_text(str(x))
952 # draw subticks
953 delta /= 10
954 if delta > 0:
955 start = self.__lo - (self.__lo % delta) + delta
956 end = self.__hi - (self.__hi % delta)
957 for x in range(int(start), int(end + delta), int(delta)):
958 real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo)
959 ctx.move_to(real_x, 0)
960 ctx.line_to(real_x, 3*s)
961 ctx.close_path()
962 ctx.stroke()
963
964
965
967
989 def __init__(self, start, end):
990 """! Initializer
991 @param self this object
992 @param start start
993 @param end end
994 """
995 self.__start = float(start)
996 self.__end = float(end)
998 self.__mid_scale.set_top()
1000 self.__bot_scale.set_bounds(start, end)
1001 self.__bot_scale.set_bot()
1002 self.__width = 1
1003 self.__height = 1
1004 def get_width(self):
1005 """! Get Width
1006 @param self: this object
1007 @return width
1008 """
1009 return self.__width
1010 def get_height(self):
1011 """! Get Height
1012 @param self this object
1013 @return height
1014 """
1015 return self.__height
1016 # return x, y, width, height
1018 """! Get Data Rectangle
1019 @param self this object
1020 @return rectangle
1021 """
1022 y_start = self.__top_legend.get_height()
1023 x_start = self.__data.get_data_x_start()
1024 return (x_start, y_start, self.__width - x_start, self.__data.get_height())
1025 def scale_data(self, x):
1026 """! Get Data Rectangle
1027 @param self this object
1028 @param x x
1029 @return scaled x
1030 """
1031 x_start = self.__data.get_data_x_start()
1032 x_scaled = x / (self.__width - x_start) * (self.__r_end - self.__r_start)
1033 return x_scaled
1034 # return x, y, width, height
1036 """! Get Selection Rectangle
1037 @param self this object
1038 @return rectangle
1039 """
1040 y_start = self.__top_legend.get_height() + self.__data.get_height() + self.__mid_scale.get_height() + 20
1041 y_height = self.__bot_scale.get_height() + 20
1042 x_start = self.__bot_scale.get_position(self.__r_start)
1043 x_end = self.__bot_scale.get_position(self.__r_end)
1044 return (x_start, y_start, x_end - x_start, y_height)
1045 def scale_selection(self, x):
1046 """! Scale Selection
1047 @param self this object
1048 @param x the X
1049 @return scaled X
1050 """
1051 x_scaled = x / self.__width * (self.__end - self.__start)
1052 return x_scaled
1053 def set_range(self, start, end):
1054 """! Set Range
1055 @param self this object
1056 @param start start
1057 @param end end
1058 @return none
1059 """
1060 s = min(start, end)
1061 e = max(start, end)
1062 start = max(self.__start, s)
1063 end = min(self.__end, e)
1064 self.__r_start = start
1065 self.__r_end = end
1066 self.__data.set_render_range(start, end)
1067 self.__mid_scale.set_bounds(start, end)
1068 self.layout(self.__width, self.__height)
1069 def get_range(self):
1070 """! Get Range
1071 @param self this object
1072 @return range
1073 """
1074 return (self.__r_start, self.__r_end)
1075 def set_data(self, data):
1076 """! Set Date
1077 @param self this object
1078 @param data data
1079 @return none
1080 """
1081 self.__data = data
1082 def set_top_legend(self, top_legend):
1083 """! Set Top Legend
1084 @param self this object
1085 @param top_legend The legend
1086 @return none
1087 """
1088 self.__top_legend = top_legend
1089 def layout(self, width, height):
1090 """! Set Layout
1091 @param self this object
1092 @param width width
1093 @param height height
1094 @return none
1095 """
1096 self.__width = width
1097 self.__height = height
1098 self.__top_legend.layout(width)
1099 top_legend_height = self.__top_legend.get_height()
1100 self.__data.layout(width)
1101 self.__mid_scale.layout(width - self.__data.get_data_x_start())
1102 self.__bot_scale.layout(width)
1103 return
1104 def __x_pixel(self, x, width):
1105 """! X Pixel
1106 @param self this object
1107 @param x x
1108 @param width width
1109 @return x pixel
1110 """
1111 new_x = (x - self.__start) * width / (self.__end - self.__start)
1112 return new_x
1113
1114 def draw(self, ctx):
1115 """! Draw
1116 @param self this object
1117 @param ctx ctx
1118 @return none
1119 """
1120 # default background is white
1121 ctx.save()
1122 ctx.set_source_rgb(1, 1, 1)
1123 ctx.set_operator(cairo.OPERATOR_SOURCE)
1124 ctx.rectangle(0, 0, self.__width, self.__height)
1125 ctx.fill()
1126
1127 # top legend
1128 ctx.save()
1129 self.__top_legend.draw(ctx)
1130 top_legend_height = self.__top_legend.get_height()
1131 ctx.restore()
1132
1133 # separation line
1134 ctx.move_to(0, top_legend_height)
1135 ctx.line_to(self.__width, top_legend_height)
1136 ctx.close_path()
1137 ctx.set_line_width(2)
1138 ctx.set_source_rgb(0, 0, 0)
1139 ctx.stroke()
1140
1141 # data
1142 ctx.save()
1143 ctx.translate(0,
1144 top_legend_height)
1145 self.__data.draw(ctx)
1146 ctx.restore()
1147
1148 # scale below data
1149 ctx.save()
1150 ctx.translate(self.__data.get_data_x_start(),
1151 top_legend_height + self.__data.get_height() + self.__mid_scale.get_height())
1152 self.__mid_scale.draw(ctx)
1153 ctx.restore()
1154
1155 height_used = top_legend_height + self.__data.get_height() + self.__mid_scale.get_height()
1156
1157 # separation between scale and left pane
1158 ctx.move_to(self.__data.get_data_x_start(), height_used)
1159 ctx.rel_line_to(0, -self.__mid_scale.get_height())
1160 ctx.close_path()
1161 ctx.set_source_rgb(0, 0, 0)
1162 ctx.set_line_width(2)
1163 ctx.stroke()
1164
1165 # separation below scale
1166 ctx.move_to(0, height_used)
1167 ctx.line_to(self.__width, height_used)
1168 ctx.close_path()
1169 ctx.set_line_width(2)
1170 ctx.set_source_rgb(0, 0, 0)
1171 ctx.stroke()
1172
1173 select_start = self.__bot_scale.get_position(self.__r_start)
1174 select_end = self.__bot_scale.get_position(self.__r_end)
1175
1176 # left connection between top scale and bottom scale
1177 ctx.move_to(0, height_used)
1178 ctx.line_to(self.__data.get_data_x_start(), height_used)
1179 ctx.line_to(select_start, height_used + 20)
1180 ctx.line_to(0, height_used + 20)
1181 ctx.line_to(0, height_used)
1182 ctx.set_source_rgb(0, 0, 0)
1183 ctx.set_line_width(1)
1184 ctx.stroke_preserve()
1185 ctx.set_source_rgb(0.9, 0.9, 0.9)
1186 ctx.fill()
1187
1188 # right connection between top scale and bottom scale
1189 ctx.move_to(self.__width, height_used)
1190 ctx.line_to(self.__width, height_used + 20)
1191 ctx.line_to(select_end, height_used + 20)
1192 ctx.line_to(self.__width, height_used)
1193 ctx.set_source_rgb(0, 0, 0)
1194 ctx.set_line_width(1)
1195 ctx.stroke_preserve()
1196 ctx.set_source_rgb(0.9, 0.9, 0.9)
1197 ctx.fill()
1198
1199 height_used += 20
1200
1201 # unused area background
1202 unused_start = self.__bot_scale.get_position(self.__r_start)
1203 unused_end = self.__bot_scale.get_position(self.__r_end)
1204 unused_height = self.__bot_scale.get_height() + 20
1205 ctx.rectangle(0, height_used,
1206 unused_start,
1207 unused_height)
1208 ctx.rectangle(unused_end,
1209 height_used,
1210 self.__width - unused_end,
1211 unused_height)
1212 ctx.set_source_rgb(0.9, 0.9, 0.9)
1213 ctx.fill()
1214
1215 # border line around bottom scale
1216 ctx.move_to(unused_end, height_used)
1217 ctx.line_to(self.__width, height_used)
1218 ctx.line_to(self.__width, height_used + unused_height)
1219 ctx.line_to(0, height_used + unused_height)
1220 ctx.line_to(0, height_used)
1221 ctx.line_to(unused_start, height_used)
1222 ctx.close_path()
1223 ctx.set_line_width(2)
1224 ctx.set_source_rgb(0, 0, 0)
1225 ctx.stroke()
1226 ctx.move_to(unused_start, height_used)
1227 ctx.line_to(unused_end, height_used)
1228 ctx.close_path()
1229 ctx.set_line_width(1)
1230 ctx.set_source_rgb(0.9, 0.9, 0.9)
1231 ctx.stroke()
1232
1233 # unused area dot borders
1234 ctx.save()
1235 ctx.move_to(max(unused_start, 2), height_used)
1236 ctx.rel_line_to(0, unused_height)
1237 ctx.move_to(min(unused_end, self.__width - 2), height_used)
1238 ctx.rel_line_to(0, unused_height)
1239 ctx.set_dash([5], 0)
1240 ctx.set_source_rgb(0, 0, 0)
1241 ctx.set_line_width(1)
1242 ctx.stroke()
1243 ctx.restore()
1244
1245 # bottom scale
1246 ctx.save()
1247 ctx.translate(0, height_used)
1248 self.__bot_scale.draw(ctx)
1249 ctx.restore()
1250
1251
1252class GtkGraphicRenderer(gtk.DrawingArea):
1253
1283 def __init__(self, data):
1284 """! Initializer
1285 @param self this object
1286 @param data data
1287 """
1288 super(GtkGraphicRenderer, self).__init__()
1289 self.__data = data
1290 self.__moving_left = False
1291 self.__moving_right = False
1292 self.__moving_both = False
1293 self.__moving_top = False
1295 self.add_events(gtk.gdk.POINTER_MOTION_MASK)
1296 self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
1297 self.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
1298 self.connect("expose_event", self.expose)
1299 self.connect('size-allocate', self.size_allocate)
1300 self.connect('motion-notify-event', self.motion_notify)
1301 self.connect('button-press-event', self.button_press)
1302 self.connect('button-release-event', self.button_release)
1304 """! Set Smaller Zoom
1305 @param self this object
1306 @return none
1307 """
1308 (start, end) = self.__data.get_range()
1309 self.__data.set_range(start, start + (end - start)*2)
1310 self.__force_full_redraw = True
1311 self.queue_draw()
1313 """! Set Bigger Zoom
1314 @param self this object
1315 @return none
1316 """
1317 (start, end) = self.__data.get_range()
1318 self.__data.set_range(start, start + (end - start) / 2)
1319 self.__force_full_redraw = True
1320 self.queue_draw()
1321 def output_png(self, filename):
1322 """! Output PNG
1323 @param self this object
1324 @param filename file name
1325 @return none
1326 """
1327 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
1328 self.__data.get_width(),
1329 self.__data.get_height())
1330 ctx = cairo.Context(self.__buffer_surface)
1331 self.__data.draw(ctx)
1332 surface.write_to_png(filename)
1333 def button_press(self, widget, event):
1334 """! Button Press
1335 @param self this object
1336 @param widget widget
1337 @param event event
1338 @return true if button has been pressed otherwise false
1339 """
1340 (x, y, width, height) = self.__data.get_selection_rectangle()
1341 (d_x, d_y, d_width, d_height) = self.__data.get_data_rectangle()
1342 if event.y > y and event.y < y + height:
1343 if abs(event.x - x) < 5:
1344 self.__moving_left = True
1345 return True
1346 if abs(event.x - (x + width)) < 5:
1347 self.__moving_right = True
1348 return True
1349 if event.x > x and event.x < x + width:
1350 self.__moving_both = True
1351 self.__moving_both_start = event.x
1352 self.__moving_both_cur = event.x
1353 return True
1354 if event.y > d_y and event.y < (d_y + d_height):
1355 if event.x > d_x and event.x < (d_x + d_width):
1356 self.__moving_top = True
1357 self.__moving_top_start = event.x
1358 self.__moving_top_cur = event.x
1359 return True
1360 return False
1361 def button_release(self, widget, event):
1362 """! Button Release
1363 @param self this object
1364 @param widget widget
1365 @param event event
1366 @return true if button was released otherwise false
1367 """
1368 if self.__moving_left:
1369 self.__moving_left = False
1370 left = self.__data.scale_selection(self.__moving_left_cur)
1371 right = self.__data.get_range()[1]
1372 self.__data.set_range(left, right)
1373 self.__force_full_redraw = True
1374 self.queue_draw()
1375 return True
1376 if self.__moving_right:
1377 self.__moving_right = False
1378 right = self.__data.scale_selection(self.__moving_right_cur)
1379 left = self.__data.get_range()[0]
1380 self.__data.set_range(left, right)
1381 self.__force_full_redraw = True
1382 self.queue_draw()
1383 return True
1384 if self.__moving_both:
1385 self.__moving_both = False
1386 delta = self.__data.scale_selection(self.__moving_both_cur - self.__moving_both_start)
1387 (left, right) = self.__data.get_range()
1388 self.__data.set_range(left + delta, right + delta)
1389 self.__force_full_redraw = True
1390 self.queue_draw()
1391 return True
1392 if self.__moving_top:
1393 self.__moving_top = False
1394 return False
1395 def motion_notify(self, widget, event):
1396 """! Motion Notify
1397 @param self this object
1398 @param widget widget
1399 @param event event
1400 @return true if moving otherwise false
1401 """
1402 (x, y, width, height) = self.__data.get_selection_rectangle()
1403 if self.__moving_left:
1404 if event.x <= 0:
1406 elif event.x >= x + width:
1407 self.__moving_left_cur = x + width
1408 else:
1409 self.__moving_left_cur = event.x
1410 self.queue_draw_area(0, int(y), int(self.__width), int(height))
1411 return True
1412 if self.__moving_right:
1413 if event.x >= self.__width:
1414 self.__moving_right = self.__width
1415 elif event.x < x:
1417 else:
1418 self.__moving_right_cur = event.x
1419 self.queue_draw_area(0, int(y), int(self.__width), int(height))
1420 return True
1421 if self.__moving_both:
1422 cur_e = self.__width - (x + width - self.__moving_both_start)
1423 cur_s = (self.__moving_both_start - x)
1424 if event.x < cur_s:
1425 self.__moving_both_cur = cur_s
1426 elif event.x > cur_e:
1427 self.__moving_both_cur = cur_e
1428 else:
1429 self.__moving_both_cur = event.x
1430 self.queue_draw_area(0, int(y), int(self.__width), int(height))
1431 return True
1432 if self.__moving_top:
1433 self.__moving_top_cur = event.x
1434 delta = self.__data.scale_data(self.__moving_top_start - self.__moving_top_cur)
1435 (left, right) = self.__data.get_range()
1436 self.__data.set_range(left + delta, right + delta)
1437 self.__force_full_redraw = True
1438 self.__moving_top_start = event.x
1439 self.queue_draw()
1440 return True
1441 (d_x, d_y, d_width, d_height) = self.__data.get_data_rectangle()
1442 if event.y > y and event.y < y + height:
1443 if abs(event.x - x) < 5 or abs(event.x - (x + width)) < 5:
1444 widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.SB_H_DOUBLE_ARROW))
1445 return True
1446 if event.x > x and event.x < x + width:
1447 widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
1448 return True
1449 if event.y > d_y and event.y < (d_y + d_height):
1450 if event.x > d_x and event.x < (d_x + d_width):
1451 widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
1452 return True
1453 widget.window.set_cursor(None)
1454 return False
1455 def size_allocate(self, widget, allocation):
1456 """! Size Allocate
1457 @param self this object
1458 @param widget widget
1459 @param allocation allocation
1460 @return none
1461 """
1462 self.__width = allocation.width
1463 self.__height = allocation.height
1464 self.__data.layout(allocation.width, allocation.height)
1465 self.__force_full_redraw = True
1466 self.queue_draw()
1467 def expose(self, widget, event):
1468 """! Expose
1469 @param self this object
1470 @param widget widget
1471 @param event event
1472 @return false
1473 """
1474 if self.__force_full_redraw:
1475 self.__buffer_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
1476 self.__data.get_width(),
1477 self.__data.get_height())
1478 ctx = cairo.Context(self.__buffer_surface)
1479 self.__data.draw(ctx)
1480 self.__force_full_redraw = False
1481 ctx = widget.window.cairo_create()
1482 ctx.rectangle(event.area.x, event.area.y,
1483 event.area.width, event.area.height)
1484 ctx.clip()
1485 ctx.set_source_surface(self.__buffer_surface)
1486 ctx.paint()
1487 (x, y, width, height) = self.__data.get_selection_rectangle()
1488 if self.__moving_left:
1489 ctx.move_to(max(self.__moving_left_cur, 2), y)
1490 ctx.rel_line_to(0, height)
1491 ctx.close_path()
1492 ctx.set_line_width(1)
1493 ctx.set_source_rgb(0, 0, 0)
1494 ctx.stroke()
1495 if self.__moving_right:
1496 ctx.move_to(min(self.__moving_right_cur, self.__width - 2), y)
1497 ctx.rel_line_to(0, height)
1498 ctx.close_path()
1499 ctx.set_line_width(1)
1500 ctx.set_source_rgb(0, 0, 0)
1501 ctx.stroke()
1502 if self.__moving_both:
1503 delta_x = self.__moving_both_cur - self.__moving_both_start
1504 left_x = x + delta_x
1505 ctx.move_to(x + delta_x, y)
1506 ctx.rel_line_to(0, height)
1507 ctx.close_path()
1508 ctx.move_to(x + width + delta_x, y)
1509 ctx.rel_line_to(0, height)
1510 ctx.close_path()
1511 ctx.set_source_rgb(0, 0, 0)
1512 ctx.set_line_width(1)
1513 ctx.stroke()
1514 return False
1515
1516
1518
1524 def __init__(self):
1525 """! Initializer
1526 @param self this object
1527 """
1528 return
1529 def run(self, graphic):
1530 """! Run function
1531 @param self this object
1532 @param graphic graphic
1533 @return none
1534 """
1535 window = gtk.Window()
1536 self.__window = window
1537 window.set_default_size(200, 200)
1538 vbox = gtk.VBox()
1539 window.add(vbox)
1540 render = GtkGraphicRenderer(graphic)
1541 self.__render = render
1542 vbox.pack_end(render, True, True, 0)
1543 hbox = gtk.HBox()
1544 vbox.pack_start(hbox, False, False, 0)
1545 smaller_zoom = gtk.Button("Zoom Out")
1546 smaller_zoom.connect("clicked", self.__set_smaller_cb)
1547 hbox.pack_start(smaller_zoom)
1548 bigger_zoom = gtk.Button("Zoom In")
1549 bigger_zoom.connect("clicked", self.__set_bigger_cb)
1550 hbox.pack_start(bigger_zoom)
1551 output_png = gtk.Button("Output Png")
1552 output_png.connect("clicked", self.__output_png_cb)
1553 hbox.pack_start(output_png)
1554 window.connect('destroy', gtk.main_quit)
1555 window.show_all()
1556 #gtk.bindings_activate(gtk.main_quit, 'q', 0)
1557 gtk.main()
1558 def __set_smaller_cb(self, widget):
1559 """! Set Smaller Callback
1560 @param self this object
1561 @param widget widget
1562 @return none
1563 """
1564 self.__render.set_smaller_zoom()
1565 def __set_bigger_cb(self, widget):
1566 """! Set Bigger Callback
1567 @param self this object
1568 @param widget widget
1569 @return none
1570 """
1571 self.__render.set_bigger_zoom()
1572 def __output_png_cb(self, widget):
1573 """! Output PNG Callback
1574 @param self this object
1575 @param widget widget
1576 @return none
1577 """
1578 dialog = gtk.FileChooserDialog("Output Png", self.__window,
1579 gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
1580 self.__dialog = dialog
1581 dialog.set_default_response(1)
1582 dialog.connect("response", self.__dialog_response_cb)
1583 dialog.show()
1584 def __dialog_response_cb(self, widget, response):
1585 """! Dialog Response Callback
1586 @param self this object
1587 @param widget widget
1588 @param response response
1589 @return none
1590 """
1591 if response == 1:
1592 filename = self.__dialog.get_filename()
1593 self.__render.output_png(filename)
1594 widget.hide()
1595
1596
1597
1598def read_data(filename):
1599 timelines = Timelines()
1600 colors = Colors()
1601 m1 = re.compile('range ([^ ]+) ([^ ]+) ([^ ]+) ([0-9]+) ([0-9]+)')
1602 m2 = re.compile('event-str ([^ ]+) ([^ ]+) ([^ ]+) ([0-9]+)')
1603 m3 = re.compile('event-int ([^ ]+) ([^ ]+) ([0-9]+) ([0-9]+)')
1604 m4 = re.compile('color ([^ ]+) #([a-fA-F0-9]{2,2})([a-fA-F0-9]{2,2})([a-fA-F0-9]{2,2})')
1605
1606 with open(filename, encoding='utf-8') as fh:
1607 for line in fh.readlines():
1608 m = m1.match(line)
1609 if m:
1610 line_name = m.group(1)
1611 timeline = timelines.get(m.group(1))
1612 rang = timeline.get_range(m.group(2))
1613 data_range = DataRange()
1614 data_range.value = m.group(3)
1615 data_range.start = int(m.group(4))
1616 data_range.end = int(m.group(5))
1617 rang.add_range(data_range)
1618 continue
1619 m = m2.match(line)
1620 if m:
1621 line_name = m.group(1)
1622 timeline = timelines.get(m.group(1))
1623 ev = timeline.get_event_str(m.group(2))
1624 event = EventString()
1625 event.value = m.group(3)
1626 event.at = int(m.group(4))
1627 ev.add_event(event)
1628 continue
1629 m = m3.match(line)
1630 if m:
1631 line_name = m.group(1)
1632 timeline = timelines.get(m.group(1))
1633 ev = timeline.get_event_int(m.group(2))
1634 event = EventInt()
1635 event.value = int(m.group(3))
1636 event.at = int(m.group(4))
1637 ev.add_event(event)
1638 continue
1639
1640 m = m4.match(line)
1641 if m:
1642 r = int(m.group(2), 16)
1643 g = int(m.group(3), 16)
1644 b = int(m.group(4), 16)
1645 color = Color(r / 255, g / 255, b / 255)
1646 colors.add(m.group(1), color)
1647 continue
1648 timelines.sort()
1649 return (colors, timelines)
1650
1651
1652def main():
1653 (colors, timelines) = read_data(sys.argv[1])
1654 (lower_bound, upper_bound) = timelines.get_bounds()
1655 graphic = GraphicRenderer(lower_bound, upper_bound)
1656 top_legend = TopLegendRenderer()
1657 range_values = timelines.get_all_range_values()
1658 range_colors = []
1659 for range_value in range_values:
1660 range_colors.append(colors.lookup(range_value))
1661 top_legend.set_legends(range_values,
1662 range_colors)
1663 graphic.set_top_legend(top_legend)
1664 data = TimelinesRenderer()
1665 data.set_timelines(timelines, colors)
1666 graphic.set_data(data)
1667
1668 # default range
1669 range_mid = (upper_bound - lower_bound) / 2
1670 range_width = (upper_bound - lower_bound) / 10
1671 range_lo = range_mid - range_width / 2
1672 range_hi = range_mid + range_width / 2
1673 graphic.set_range(range_lo, range_hi)
1674
1675 main_window = MainWindow()
1676 main_window.run(graphic)
1677
1678
1679main()
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
Color class.
Definition: grid.py:429
def __init__(self, r=0.0, g=0.0, b=0.0)
Initializer.
Definition: grid.py:436
def set(self, r, g, b)
Set color.
Definition: grid.py:446
r
red
Definition: grid.py:443
g
green
Definition: grid.py:444
b
blue
Definition: grid.py:445
Colors class.
Definition: grid.py:459
def __init__(self)
Initializer.
Definition: grid.py:466
def lookup(self, name)
Lookup name.
Definition: grid.py:479
def add(self, name, color)
Add.
Definition: grid.py:471
list default_colors
default colors XXX add more
Definition: grid.py:465
__colors
colors
Definition: grid.py:470
DataRange class.
Definition: grid.py:10
value
value
Definition: grid.py:26
start
start
Definition: grid.py:24
def __init__(self, start=0, end=0, value='')
Initializer.
Definition: grid.py:17
EventFloat class.
Definition: grid.py:42
def __init__(self, at=0, value=0.0)
Initializer.
Definition: grid.py:47
value
value
Definition: grid.py:54
EventInt class.
Definition: grid.py:56
def __init__(self, at=0, value=0.0)
Initializer.
Definition: grid.py:61
value
value
Definition: grid.py:68
EventString class.
Definition: grid.py:28
value
value
Definition: grid.py:40
def __init__(self, at=0, value='')
Initializer.
Definition: grid.py:33
GraphicRenderer class.
Definition: grid.py:966
__mid_scale
mid scale
Definition: grid.py:997
def set_top_legend(self, top_legend)
Set Top Legend.
Definition: grid.py:1082
def get_range(self)
Get Range.
Definition: grid.py:1069
def draw(self, ctx)
Draw.
Definition: grid.py:1114
def get_selection_rectangle(self)
Get Selection Rectangle.
Definition: grid.py:1035
def set_range(self, start, end)
Set Range.
Definition: grid.py:1053
def get_height(self)
Get Height.
Definition: grid.py:1010
def get_data_rectangle(self)
Get Data Rectangle.
Definition: grid.py:1017
__bot_scale
bottom scale
Definition: grid.py:999
def scale_selection(self, x)
Scale Selection.
Definition: grid.py:1045
__top_legend
top legend
Definition: grid.py:1088
def layout(self, width, height)
Set Layout.
Definition: grid.py:1089
def set_data(self, data)
Set Date.
Definition: grid.py:1075
def __x_pixel(self, x, width)
X Pixel.
Definition: grid.py:1104
def __init__(self, start, end)
Initializer.
Definition: grid.py:989
def get_width(self)
Get Width.
Definition: grid.py:1004
def scale_data(self, x)
Get Data Rectangle.
Definition: grid.py:1025
GtkGraphicRenderer class.
Definition: grid.py:1252
__force_full_redraw
full redraw
Definition: grid.py:1294
__moving_top_start
moving top start
Definition: grid.py:1357
def set_smaller_zoom(self)
Set Smaller Zoom.
Definition: grid.py:1303
def motion_notify(self, widget, event)
Motion Notify.
Definition: grid.py:1395
__moving_both_cur
moving both cur
Definition: grid.py:1352
__moving_right
moving right
Definition: grid.py:1291
__moving_left
moving left
Definition: grid.py:1290
__moving_right_cur
moving right cur
Definition: grid.py:1416
__buffer_surface
buffer surface
Definition: grid.py:1475
__moving_top_cur
moving top cur
Definition: grid.py:1358
def size_allocate(self, widget, allocation)
Size Allocate.
Definition: grid.py:1455
__moving_top
moving top
Definition: grid.py:1293
__moving_both_start
moving both start
Definition: grid.py:1351
def set_bigger_zoom(self)
Set Bigger Zoom.
Definition: grid.py:1312
def button_press(self, widget, event)
Button Press.
Definition: grid.py:1333
def button_release(self, widget, event)
Button Release.
Definition: grid.py:1361
__moving_both
moving both
Definition: grid.py:1292
__moving_left_cur
moving left cur
Definition: grid.py:1405
def output_png(self, filename)
Output PNG.
Definition: grid.py:1321
def __init__(self, data)
Initializer.
Definition: grid.py:1283
def expose(self, widget, event)
Expose.
Definition: grid.py:1467
MainWindow class.
Definition: grid.py:1517
def run(self, graphic)
Run function.
Definition: grid.py:1529
def __dialog_response_cb(self, widget, response)
Dialog Response Callback.
Definition: grid.py:1584
def __init__(self)
Initializer.
Definition: grid.py:1524
def __set_smaller_cb(self, widget)
Set Smaller Callback.
Definition: grid.py:1558
__dialog
dialog
Definition: grid.py:1580
__window
window
Definition: grid.py:1536
def __output_png_cb(self, widget)
Output PNG Callback.
Definition: grid.py:1572
def __set_bigger_cb(self, widget)
Set Bigger Callback.
Definition: grid.py:1565
__render
render
Definition: grid.py:1541
ScaleRenderer class.
Definition: grid.py:833
def layout(self, width)
Layout.
Definition: grid.py:883
def draw(self, ctx)
Draw.
Definition: grid.py:921
max_text_height
maximum text height
Definition: grid.py:911
def get_position(self, x)
Get Position.
Definition: grid.py:863
def set_bot(self)
Set Bottom.
Definition: grid.py:877
__height
height
Definition: grid.py:913
def set_top(self)
Set Top.
Definition: grid.py:871
def __init__(self)
Initializer.
Definition: grid.py:848
def get_height(self)
Get Height.
Definition: grid.py:915
TimelineDataRange.
Definition: grid.py:86
def __init__(self, name='')
Initializer.
Definition: grid.py:91
def get_bounds(self)
Get bounds.
Definition: grid.py:170
def add_range(self, range)
Add range.
Definition: grid.py:117
def __search(self, key)
Search.
Definition: grid.py:99
def get_ranges_bounds(self, start, end)
Get ranges bounds.
Definition: grid.py:147
def get_ranges(self, start, end)
Get selected ranges.
Definition: grid.py:130
def sort(self)
Sort ranges.
Definition: grid.py:164
def get_all(self)
Get all ranges.
Definition: grid.py:124
TimelineEvent class.
Definition: grid.py:182
def add_event(self, event)
Add Event.
Definition: grid.py:212
def get_events(self, start, end)
Get Events.
Definition: grid.py:219
def __init__(self, name='')
Get ranges bounds.
Definition: grid.py:187
def get_events_bounds(self, start, end)
Get Events Bounds.
Definition: grid.py:229
def sort(self)
Sort function.
Definition: grid.py:239
def get_bounds(self)
Get Bounds.
Definition: grid.py:245
def __search(self, key)
Search function.
Definition: grid.py:194
events
events
Definition: grid.py:193
Timeline class.
Definition: grid.py:258
def get_ranges(self)
Get Ranges.
Definition: grid.py:312
def get_range(self, name)
Get range.
Definition: grid.py:276
def get_event_int(self, name)
Get Event Int.
Definition: grid.py:300
event_int
event int
Definition: grid.py:274
def get_events_int(self)
Get Events int.
Definition: grid.py:324
ranges
ranges
Definition: grid.py:272
def get_event_str(self, name)
Get Event String.
Definition: grid.py:288
def __init__(self, name='')
Initializer.
Definition: grid.py:267
event_str
event string
Definition: grid.py:273
def get_bounds(self)
Get Bounds.
Definition: grid.py:341
def get_events_str(self)
Get Events string.
Definition: grid.py:318
def sort(self)
Sort the ranges and events.
Definition: grid.py:330
name
name
Definition: grid.py:275
Timelines class.
Definition: grid.py:369
def get_bounds(self)
Get Bounds.
Definition: grid.py:402
def __init__(self)
Definition: grid.py:372
def get(self, name)
Get Timeline.
Definition: grid.py:377
timelines
timelines
Definition: grid.py:376
def get_all_range_values(self)
Get All Ranges.
Definition: grid.py:416
def get_all(self)
Get All Timeline.
Definition: grid.py:389
def sort(self)
Sort the timelines.
Definition: grid.py:395
TimelinesRenderer class.
Definition: grid.py:591
right_width
right width
Definition: grid.py:693
def set_timelines(self, timelines, colors)
Set Timelines.
Definition: grid.py:626
grey_background
grey background
Definition: grid.py:794
def draw_line(self, ctx, x, y, width, height)
Draw Line.
Definition: grid.py:697
def get_data_x_start(self)
Get Data X Start.
Definition: grid.py:644
def set_render_range(self, start, end)
Set Render Range.
Definition: grid.py:635
timelines
timelines
Definition: grid.py:633
def layout(self, width)
Get Data X Start.
Definition: grid.py:650
def draw(self, ctx)
Draw.
Definition: grid.py:777
max_text_height
maximum text height
Definition: grid.py:694
def draw_events(self, ctx, events, x, y, width, height)
Draw Event.
Definition: grid.py:714
def __init__(self)
Initializer.
Definition: grid.py:614
def get_height(self)
Get Height.
Definition: grid.py:620
def draw_ranges(self, ctx, ranges, x, y, width, height)
Draw Ranges.
Definition: grid.py:743
left_width
left width
Definition: grid.py:692
TopLegendRenderer class.
Definition: grid.py:490
def get_height(self)
Set padding.
Definition: grid.py:549
def layout(self, width)
Set padding.
Definition: grid.py:522
def __init__(self)
Initializer.
Definition: grid.py:501
def draw(self, ctx)
Set padding.
Definition: grid.py:555
def set_padding(self, padding)
Set padding.
Definition: grid.py:506
def set_legends(self, legends, colors)
Set padding.
Definition: grid.py:513
def ranges_cmp(a, b)
Definition: grid.py:69
def events_cmp(a, b)
Definition: grid.py:77
def read_data(filename)
read_data function
Definition: grid.py:1598