creating one window with toolbar presentation
[findit] / src / outdiag.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 class Out_Diag_Control(object):
10     def __init__(self, config):
11         win_width = config.get('window_width')
12         win_height = config.get('window_height')
13         self.out_ui = Out_Diag_Presentation(win_width, win_height)
14
15     def show(self, filelist, fullsize):
16         self.out_ui.get_data(filelist, fullsize)
17
18     def run(self):
19         self.out_ui.run()
20
21
22 class Out_Diag_Abstraction(object):
23     pass
24
25
26 class Out_Diag_Presentation(gtk.Window):
27
28     def __init__(self, win_width, win_height):
29         gtk.Window.__init__(self)
30         self.width = win_width
31         self.height = win_height
32         self.set_default_size(self.width, self.height)
33         self.set_border_width(4)
34         self.connect('delete_event', gtk.main_quit) 
35
36         scrollwind = gtk.ScrolledWindow()
37         scrollwind.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
38         
39         self.area = gtk.DrawingArea()
40         self.area.set_size_request(win_width, win_height)
41         self.area.set_events(gtk.gdk.POINTER_MOTION_MASK | 
42                 gtk.gdk.POINTER_MOTION_HINT_MASK )
43         self.area.connect("expose-event", self.expose_event)
44         self.pixmap = None        
45         
46         scrollwind.add_with_viewport(self.area)
47         self.add(scrollwind)
48
49     
50     def expose_event(self, widget, event):
51         if not self.pixmap:
52             self.build_pixmap()
53         x , y, width, height = event.area
54         widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], \
55                 self.pixmap, x, y, x, y, width, height)
56         return False
57
58     def build_pixmap(self):
59         self.pixmap=gtk.gdk.Pixmap(self.window, self.width, self.height)
60         cm=self.pixmap.get_colormap()
61         self.color={}
62         self.color['black']=cm.alloc_color("black")
63         self.color['white']=cm.alloc_color("white")
64         self.gc=self.pixmap.new_gc()
65         self.gc.set_foreground(self.color['white'])
66         self.pixmap.draw_rectangle(self.gc, True, 0, 0, self.width, self.height)
67     
68     def draw_diag(self):
69         start_angle = 0
70         for path, size, bsize in self.filelist:
71             end_angle = (bsize*360*64)/self.fullsize
72             print start_angle, end_angle
73             gc=self.pixmap.new_gc()
74             cm=self.pixmap.get_colormap()
75             col1 = cm.alloc_color(self.rand_color())
76             gc.set_foreground(col1)
77             gc.set_line_attributes(1,gtk.gdk.LINE_SOLID,gtk.gdk.CAP_NOT_LAST,gtk.gdk.JOIN_MITER)
78             self.pixmap.draw_arc(gc, True, 0, 0, self.width, self.height, start_angle, end_angle)
79             start_angle = start_angle + end_angle
80         self.area.queue_draw()
81
82     def rand_color(self):
83         r = randint(0, 65535)
84         g = randint(0, 65535)
85         b = randint(0, 65535)
86         return gtk.gdk.Color(r, g, b, 0)
87
88     def run(self):
89         self.show_all()
90         gobject.timeout_add(1000, self.draw_diag)
91         gtk.main()
92     
93     def get_data(self, filelist, fullsize):
94         self.filelist = filelist
95         self.fullsize = fullsize