summaryrefslogtreecommitdiffstats
path: root/src/fringlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/fringlib')
-rw-r--r--src/fringlib/fringrenderer.py77
-rw-r--r--src/fringlib/fringui.py21
2 files changed, 53 insertions, 45 deletions
diff --git a/src/fringlib/fringrenderer.py b/src/fringlib/fringrenderer.py
index fb9a876..60256e5 100644
--- a/src/fringlib/fringrenderer.py
+++ b/src/fringlib/fringrenderer.py
@@ -2,26 +2,31 @@ import cairo
import pango
from math import *
from fringwalker import sum_list
+from fringutil import *
import os
class Hotspot:
- def __init__(self, minpos, maxpos, path, size, percentage):
- self.minx,self.miny = minpos
- self.maxx,self.maxy = maxpos
+ def __init__(self, is_dir, path, size, value):
+ self.is_dir = is_dir
self.path = path
self.size = size
- self.percentage = percentage
+ self.value = value
+ self.percentage = value*100
-class Segment:
+class SideLink(Hotspot):
- def __init__(self, start, end, path, size):
- self.start, self.end = start, end
- self.path = path
- self.size = size
+ def __init__(self, is_dir, path, size, value, minpos, maxpos):
+ Hotspot.__init__(self, is_dir, path, size, value)
+
+ self.minx,self.miny = minpos
+ self.maxx,self.maxy = maxpos
+
+class Segment(Hotspot):
- def percentage(self):
- return self.end - self.start
+ def __init__(self, is_dir, path, size, start, end):
+ Hotspot.__init__(self, is_dir, path, size, end-start)
+ self.start, self.end = start, end
class FringRenderer:
@@ -37,12 +42,12 @@ class FringRenderer:
self.LABEL_UNTIL_RING = 0
- self.hotspots = []
+ self.side_links = []
self.lookup_data = []
def prepare_layouts(self,ctx):
self.linklayout = ctx.create_layout()
- self.linklayout.set_font_description(pango.FontDescription("sans 10"))
+ self.linklayout.set_font_description(pango.FontDescription("sans 8"))
def draw_segment(self,ctx, ring, start_angle, end_angle, start_hue, end_hue, data, previouspath=""):
@@ -50,7 +55,7 @@ class FringRenderer:
if ring == 0:
self.lookup_data = []
- self.hotspots = []
+ self.side_links = []
while len(self.lookup_data) <= ring:
self.lookup_data.append([])
@@ -59,7 +64,7 @@ class FringRenderer:
ctx.move_to(CENTERX, CENTERY)
if ring == 0:
- self._draw_centered_text(ctx, self._pretty_size(data.the_sum))
+ self._draw_centered_text(ctx, pretty_size(data.the_sum))
n = len(data.data)
i = 0
@@ -77,7 +82,7 @@ class FringRenderer:
if end-start >= .01:
p = previouspath+os.sep+fn
- self.lookup_data[ring].append(Segment(start, end, p, value))
+ self.lookup_data[ring].append(Segment(isinstance(d, sum_list), p, value, start, end))
v = start_hue + (end_hue-start_hue)*1.0*i/n
color = self._choose_color(start_hue + (end_hue-start_hue)*1.0*i/n, ring)
@@ -131,33 +136,34 @@ class FringRenderer:
# write path name and register a hotspot
ctx.move_to(x+xmod,y)
- # register a hotspot ONLY if directory
+ # draw the side link label
if isinstance(d, sum_list):
ctx.set_source_rgb(0,0,1)
- width,height = self._draw_centered_text(ctx, fn, align_x)
- if align_x == 0: width *= -1
- self.__register_hotspot(p,value,end-start,x,y+(height/2),x+(width),y-(height/2))
-
+ width,height = self._draw_centered_text(ctx, fn + "/", align_x)
else:
ctx.set_source_rgb(0.5,0.5,0.5)
width,height = self._draw_centered_text(ctx, fn, align_x)
+ if align_x == 0:
+ width *= -1
+
+ self.__register_side_link(isinstance(d, sum_list),p,value,end-start,x,y+(height/2),x+(width),y-(height/2))
if ring <= self.LABEL_UNTIL_RING:
ctx.move_to(*middle)
ctx.set_source_rgb(0, 0, 0)
# write relative and absolute disk usage
- self._draw_centered_text2(ctx, "%.0f%%" % ((end-start)*100), self._pretty_size(value))
+ self._draw_centered_text2(ctx, "%.0f%%" % ((end-start)*100), pretty_size(value))
last = end
i += 1
def get_hotspot_at(self,x,y):
- for h in self.hotspots:
+ for h in self.side_links:
if x >= h.minx and x <= h.maxx and \
y >= h.miny and y <= h.maxy:
- return (h.path, h.size, h.percentage)
+ return h
def sqr(x):
return x*x
@@ -185,15 +191,12 @@ class FringRenderer:
p = int(maxidx*v) # Initial estimation
while True:
- assert p >= minidx
- assert p <= maxidx
-
d = data[p]
if v <= d.start:
maxidx = p-1
elif v <= d.end:
- return (d.path, d.size, d.percentage())
+ return d
else:
minidx = p+1
@@ -205,12 +208,12 @@ class FringRenderer:
if np == p:
return None
- p = np
+ p = np # Funny!
- def __register_hotspot(self,path,size,percentage,x0,y0,x1,y1):
+ def __register_side_link(self,is_dir,path,size,value,x0,y0,x1,y1):
if x1 < x0: x0,x1 = x1,x0 # swap
if y1 < y0: y0,y1 = y1,y0
- self.hotspots.append(Hotspot( (x0,y0), (x1,y1), path, size, percentage ))
+ self.side_links.append(SideLink(is_dir, path, size, value, (x0,y0), (x1,y1)))
def hsv2rgb(self,h,s,v):
if s<=0:
@@ -235,18 +238,6 @@ class FringRenderer:
return l.the_sum
return l
-
- def _pretty_size(self,size):
- if size >= 1024*1024*1024:
- return "%.1f GiB" % round(size/1024/1024/1024.0)
- elif size >= 1024*1024:
- return "%.1f MiB" % round(size/1024/1024.0)
- elif size >= 1024:
- return "%.1f KiB" % round(size/1024.0)
- else:
- return "%u B" % size
-
-
def _choose_color(self,v, ring):
color = self.hsv2rgb(v, .61, 1-ring*0.1)
return color[0]/256.0, color[1]/256.0, color[2]/256.0,
diff --git a/src/fringlib/fringui.py b/src/fringlib/fringui.py
index cf94eaa..1fe187d 100644
--- a/src/fringlib/fringui.py
+++ b/src/fringlib/fringui.py
@@ -5,6 +5,7 @@ import os
from fringwalker import FringWalker
from fringrenderer import FringRenderer
+from fringutil import *
GPL = """
fring is free software; you can redistribute it and/or modify
@@ -128,6 +129,12 @@ class UI( gtk.Window ):
self.eventbox.connect("button-press-event",self.__click_event)
self.eventbox.connect("motion-notify-event",self.__move_event)
+ # Create label
+ self.label = gtk.Label()
+ self.label.set_alignment(0, .5)
+ self.label.set_padding(6, 0)
+ self.label.set_text("Initializing")
+
# aligh menubar, toolbar and canvas vertically
vbox = gtk.VBox();
vbox.pack_start(menubar,False,False)
@@ -136,6 +143,7 @@ class UI( gtk.Window ):
f.set_shadow_type(gtk.SHADOW_IN)
f.add(self.eventbox)
vbox.pack_start(f)
+ vbox.pack_start(self.label,False,False,6)
self.add(vbox)
# show everything
@@ -248,13 +256,20 @@ class UI( gtk.Window ):
f = self.renderer.get_hotspot_at(event.x, event.y)
if f is None:
- self.eventbox.window.set_cursor(None) #gtk.gdk.Cursor(gtk.gdk.CROSSHAIR))
+ self.label.set_text("Ready.")
+ else:
+ self.label.set_markup("Path <b>%s</b>, %s, %0.1f%%" % (f.path, pretty_size(f.size), f.value*100))
+
+ if f is None or not f.is_dir:
+ self.eventbox.window.set_cursor(None)
else:
self.eventbox.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))
def __click_event(self, widget, event):
f = self.renderer.get_hotspot_at(event.x, event.y)
- if f is not None: self.open_folder(f[0])
+ if f is not None:
+ if f.is_dir:
+ self.open_folder(f.path)
def __scroll_event(self, widget, event):
if event.direction is gtk.gdk.SCROLL_UP:
@@ -289,8 +304,10 @@ class UI( gtk.Window ):
def __show_busy_cursor(self, value):
if self.busy_cursor <= 0 and self.busy_cursor+value >= 0:
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+ self.label.set_markup("Busy...")
elif self.busy_cursor > 0 and self.busy_cursor+value <= 0:
self.window.set_cursor(None)
+ self.label.set_text("Ready.")
self.busy_cursor += value