Added PAC skeleton
[findit] / src / files / outdiagram.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4
5 import gtk
6 import gobject
7 from random import randint
8
9
10 class Control(object):
11     def __init__(self, config):
12         win_width = config.get('window_width')
13         win_height = config.get('window_height')
14         self.out_ui = Out_Diag_Presentation(win_width, win_height)
15
16     def show(self, filelist, fullsize):
17         self.out_ui.get_data(filelist, fullsize)
18
19     def run(self):
20         self.out_ui.run()
21
22
23 class Abstraction(object):
24     pass
25
26
27 class Gtk_Presentation(object):
28
29     def __init__(self):
30
31         self.area = gtk.DrawingArea()
32         self.area.set_size_request(250, 200) ###
33         self.area.set_events(gtk.gdk.POINTER_MOTION_MASK |
34                              gtk.gdk.POINTER_MOTION_HINT_MASK )
35         self.area.connect('expose-event', self.expose_event)
36         self.pixmap = None
37
38     def expose_event(self, widget, event):
39         if not self.pixmap:
40             self.build_pixmap()
41         x, y, width, height = event.area
42         widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
43                                     self.pixmap, x, y, x, y, width, height)
44         return False
45
46     def build_pixmap(self):
47         #self.pixmap = gtk.gdk.Pixmap(self.window, self.width, self.height)
48         self.pixmap = gtk.gdk.Pixmap(None, 250, 200, 8) ###
49         cm = self.pixmap.get_colormap()
50         self.color = {}
51         self.color['black'] = cm.alloc_color('black')
52         self.color['white'] = cm.alloc_color('white')
53         self.gc = self.pixmap.new_gc()
54         self.gc.set_foreground(self.color['white'])
55         self.pixmap.draw_rectangle(self.gc, True, 0, 0, self.width, self.height)
56
57     def draw_diag(self):
58         start_angle = 0
59         for path, size, bsize in self.filelist:
60             end_angle = (bsize*360*64)/self.fullsize
61             print start_angle, end_angle
62             gc = self.pixmap.new_gc()
63             cm = self.pixmap.get_colormap()
64             col1 = cm.alloc_color(self.rand_color())
65             gc.set_foreground(col1)
66             gc.set_line_attributes(1,gtk.gdk.LINE_SOLID,gtk.gdk.CAP_NOT_LAST,gtk.gdk.JOIN_MITER)
67             self.pixmap.draw_arc(gc, True, 0, 0, self.width, self.height, start_angle, end_angle)
68             start_angle = start_angle + end_angle
69         self.area.queue_draw()
70
71     def rand_color(self):
72         r = randint(0, 65535)
73         g = randint(0, 65535)
74         b = randint(0, 65535)
75         return gtk.gdk.Color(r, g, b, 0)
76
77     def run(self):
78         self.show_all()
79         gobject.timeout_add(1000, self.draw_diag)
80         gtk.main()
81
82     def get_data(self, filelist, fullsize):
83         self.filelist = filelist
84         self.fullsize = fullsize
85
86     #=== Toplevel widget for embedding to search area =========================
87     def get_toplevel(self):
88         return self.area