Added PAC skeleton
[findit] / src / files / outdiagram.py
diff --git a/src/files/outdiagram.py b/src/files/outdiagram.py
new file mode 100755 (executable)
index 0000000..b309dca
--- /dev/null
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+# -*-coding: utf-8 -*-
+# vim: sw=4 ts=4 expandtab ai
+
+import gtk
+import gobject
+from random import randint
+
+
+class Control(object):
+    def __init__(self, config):
+        win_width = config.get('window_width')
+        win_height = config.get('window_height')
+        self.out_ui = Out_Diag_Presentation(win_width, win_height)
+
+    def show(self, filelist, fullsize):
+        self.out_ui.get_data(filelist, fullsize)
+
+    def run(self):
+        self.out_ui.run()
+
+
+class Abstraction(object):
+    pass
+
+
+class Gtk_Presentation(object):
+
+    def __init__(self):
+
+        self.area = gtk.DrawingArea()
+        self.area.set_size_request(250, 200) ###
+        self.area.set_events(gtk.gdk.POINTER_MOTION_MASK |
+                             gtk.gdk.POINTER_MOTION_HINT_MASK )
+        self.area.connect('expose-event', self.expose_event)
+        self.pixmap = None
+
+    def expose_event(self, widget, event):
+        if not self.pixmap:
+            self.build_pixmap()
+        x, y, width, height = event.area
+        widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
+                                    self.pixmap, x, y, x, y, width, height)
+        return False
+
+    def build_pixmap(self):
+        #self.pixmap = gtk.gdk.Pixmap(self.window, self.width, self.height)
+        self.pixmap = gtk.gdk.Pixmap(None, 250, 200, 8) ###
+        cm = self.pixmap.get_colormap()
+        self.color = {}
+        self.color['black'] = cm.alloc_color('black')
+        self.color['white'] = cm.alloc_color('white')
+        self.gc = self.pixmap.new_gc()
+        self.gc.set_foreground(self.color['white'])
+        self.pixmap.draw_rectangle(self.gc, True, 0, 0, self.width, self.height)
+
+    def draw_diag(self):
+        start_angle = 0
+        for path, size, bsize in self.filelist:
+            end_angle = (bsize*360*64)/self.fullsize
+            print start_angle, end_angle
+            gc = self.pixmap.new_gc()
+            cm = self.pixmap.get_colormap()
+            col1 = cm.alloc_color(self.rand_color())
+            gc.set_foreground(col1)
+            gc.set_line_attributes(1,gtk.gdk.LINE_SOLID,gtk.gdk.CAP_NOT_LAST,gtk.gdk.JOIN_MITER)
+            self.pixmap.draw_arc(gc, True, 0, 0, self.width, self.height, start_angle, end_angle)
+            start_angle = start_angle + end_angle
+        self.area.queue_draw()
+
+    def rand_color(self):
+        r = randint(0, 65535)
+        g = randint(0, 65535)
+        b = randint(0, 65535)
+        return gtk.gdk.Color(r, g, b, 0)
+
+    def run(self):
+        self.show_all()
+        gobject.timeout_add(1000, self.draw_diag)
+        gtk.main()
+
+    def get_data(self, filelist, fullsize):
+        self.filelist = filelist
+        self.fullsize = fullsize
+
+    #=== Toplevel widget for embedding to search area =========================
+    def get_toplevel(self):
+        return self.area