summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Back <fredericback@gmail.com>2006-09-22 13:27:36 +0000
committerFrederic Back <fredericback@gmail.com>2006-09-22 13:27:36 +0000
commite62c4666f06a4e1e9370c68ceefa21af43482f25 (patch)
tree3f8c04477eed8113690141f77fa5766530471a56
parent21f53597da1197ae02c3f4aeb79ef41a191a9918 (diff)
* initial import
git-svn-id: file:///home/lennart/svn/public/fring/trunk@3 d0d2c35f-0a1e-0410-abeb-dabff30a67ee
-rw-r--r--COPYING340
-rw-r--r--TODO17
-rwxr-xr-xfring.py38
-rw-r--r--fringrenderer.py221
-rw-r--r--fringui.py276
-rw-r--r--fringwalker.py153
6 files changed, 1045 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..3912109
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..768167a
--- /dev/null
+++ b/TODO
@@ -0,0 +1,17 @@
+TODO
+
+[x] menubar (fring,help)
+ [x] refresh
+ [x] save to file
+ [x] select directory
+ [x] show hidden files
+ [x] "about" dialogue
+ [x] open parent folder
+
+[x] click on folder -> open it
+
+[ ] always render text on top
+[ ] make sure that filenames are always visible
+[ ] do more magic adjustments
+[ ] clean gui -> renderer interface
+
diff --git a/fring.py b/fring.py
new file mode 100755
index 0000000..8e3b107
--- /dev/null
+++ b/fring.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+# $Id$
+
+# fring is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# fring is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with fring; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+# Copyright Lennart Poettering, 2006
+
+import sys, os
+import gtk
+import fringui
+
+if __name__ == "__main__":
+
+ if len(sys.argv) >= 2:
+ tree_path = sys.argv[1]
+ else:
+ tree_path = os.path.expanduser("~")
+
+ ui = fringui.UI(tree_path)
+
+ gtk.gdk.threads_init()
+ gtk.gdk.threads_enter()
+ gtk.main()
+ gtk.gdk.threads_leave()
diff --git a/fringrenderer.py b/fringrenderer.py
new file mode 100644
index 0000000..a0d5a4b
--- /dev/null
+++ b/fringrenderer.py
@@ -0,0 +1,221 @@
+import cairo
+import pango
+from math import *
+from fringwalker import sum_list
+import os
+
+class Hotspot:
+
+ def __init__(self, minpos, maxpos, folder):
+ self.minx,self.miny = minpos
+ self.maxx,self.maxy = maxpos
+ self.folder = folder
+
+
+class FringRenderer:
+
+ def __init__(self):
+ self.MAX_LEVEL = 1
+ self.WIDTH, HEIGHT = 1024, 768
+ self.WIDTH, HEIGHT = 1024, 768
+ self.INNER_RADIUS = 100
+ self.RING_RADIUS = 60
+ self.RING_SPACE = 0
+ self.RINGS_MAX = 4
+ self.LINE_WIDTH = .5
+ self.LEG_LINE_WIDTH = 1
+
+ self.LABEL_UNTIL_RING = 0
+
+ self.hotspots = []
+
+ def prepare_layouts(self,ctx):
+ self.linklayout = ctx.create_layout()
+ self.linklayout.set_font_description(pango.FontDescription("sans 10"))
+
+ def draw_segment(self,ctx, ring, start_angle, end_angle, start_hue, end_hue, data, previouspath=""):
+
+ assert isinstance(data, sum_list)
+
+ CENTERX, CENTERY = self.WIDTH/2, self.HEIGHT/2
+ ctx.move_to(CENTERX, CENTERY)
+
+ if ring == 0:
+ self._draw_centered_text(ctx, self._pretty_size(data.the_sum))
+
+ n = len(data.data)
+ i = 0
+
+ accumulated = 0
+ last = start_angle
+
+ for fn, d in data.data:
+ start = last
+ value = self._list_value(d)
+ accumulated += value
+
+ end = start_angle+(end_angle - start_angle)*1.0*accumulated/data.the_sum
+
+ if end-start >= .01:
+
+ 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)
+
+ r = self.INNER_RADIUS + ring * (self.RING_RADIUS + self.RING_SPACE)
+
+ ctx.move_to(CENTERX+r*cos(start*2*pi), CENTERY+r*sin(start*2*pi))
+ ctx.arc(CENTERX, CENTERY, r+self.RING_RADIUS, start*2*pi, end*2*pi)
+ ctx.arc_negative(CENTERX, CENTERY, r, end*2*pi, start*2*pi)
+ ctx.close_path()
+
+ ctx.set_line_width(self.LINE_WIDTH)
+ ctx.set_source_rgb(*color)
+ ctx.fill_preserve()
+
+ ctx.set_source_rgb(0, 0, 0)
+ ctx.stroke()
+
+ if isinstance(d, sum_list) and ring+1 < self.RINGS_MAX:
+ self.draw_segment(ctx, ring+1, start, end, v,
+ start_hue + (end_hue-start_hue)*1.0*(i+1)/n, d,
+ previouspath+os.sep+fn)
+
+ r += self.RING_RADIUS/2
+ middle = CENTERX+r*cos((start+end)*pi), CENTERY+r*sin((start+end)*pi)
+
+ if ring <= 0:
+ ctx.move_to(*middle)
+
+ leg_radius = self.INNER_RADIUS + (self.RINGS_MAX+1) * (self.RING_RADIUS + self.RING_SPACE)
+ leg_radius -= (self.RING_RADIUS + self.RING_SPACE) / 2
+
+ ctx.line_to(CENTERX+leg_radius*cos((start+end)*pi), CENTERY+leg_radius*sin((start+end)*pi))
+
+ if cos((start+end)*pi) >= 0:
+ x = self.WIDTH/2 + leg_radius
+ align_x = 1
+ else:
+ x = self.WIDTH/2 - leg_radius
+ align_x = 0
+
+ # get line target point
+ y = CENTERY+leg_radius*sin((start+end)*pi)
+ xmod = 2*(align_x*2-1)
+
+ # draw line
+ ctx.line_to(x, y)
+ ctx.set_source_rgb(.5, .5, .5)
+ ctx.set_line_width(self.LEG_LINE_WIDTH)
+ ctx.stroke()
+
+ # write folder name and register a hotspot
+ ctx.move_to(x+xmod,y)
+
+ # register a hotspot ONLY if directory
+ if isinstance(d, sum_list):
+ ctx.set_source_rgb(0,0,1)
+ width,height = self._draw_centered_text(ctx, fn, align_x)
+ link = previouspath+os.sep+fn
+ if align_x == 0: width *= -1
+ self.__register_hotspot(link,x,y+(height/2),x+(width),y-(height/2))
+
+ else:
+ ctx.set_source_rgb(0.5,0.5,0.5)
+ width,height = self._draw_centered_text(ctx, fn, align_x)
+
+
+ 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))
+
+ last = end
+ i += 1
+
+ def get_hotspot_at(self,x,y):
+ for h in self.hotspots:
+ if x >= h.minx and x <= h.maxx and \
+ y >= h.miny and y <= h.maxy:
+ return h.folder
+
+ def __register_hotspot(self,folder,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), folder ))
+
+
+ def hsv2rgb(self,h,s,v):
+ if s<=0:
+ return 255*v,255*v,255*v
+
+ h=6.0*(h%1.0)
+ f=h-int(h)
+ p=int(255*v*(1.0-s))
+ q=int(255*v*(1.0-(s*f)))
+ t=int(255*v*(1.0-(s*(1.0-f))))
+ v=int(255*v)
+
+ return ((v,t,p),
+ (q,v,p),
+ (p,v,t),
+ (p,q,v),
+ (t,p,v),
+ (v,p,q))[int(h)]
+
+ def _list_value(self,l):
+ if isinstance(l, sum_list):
+ 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,
+
+
+ def _draw_centered_text(self,ctx, text, align_x = .5, align_y = .5):
+ try: text = unicode(text)
+ except: return
+
+ self.linklayout.set_text(text)
+ width,height = self.linklayout.get_pixel_size()
+ ctx.rel_move_to(-width*(1-align_x), -height*align_y)
+ ctx.show_layout(self.linklayout)
+ return width,height
+
+
+ def _draw_centered_text2(self,ctx, text1, text2):
+ try:
+ text1 = unicode(text1)
+ text2 = unicode(text2)
+ except: return
+
+ extents1 = ctx.text_extents(text1)
+ extents2 = ctx.text_extents(text2)
+
+ h = max((extents1[3], extents2[3]))
+
+ p = ctx.get_current_point()
+ ctx.rel_move_to(-extents1[2]/2, -1)
+ ctx.show_text(text1)
+
+ ctx.move_to(*p)
+ ctx.rel_move_to(-extents2[2]/2, h+1)
+ ctx.show_text(text2)
+
+
+
+
diff --git a/fringui.py b/fringui.py
new file mode 100644
index 0000000..f6e231b
--- /dev/null
+++ b/fringui.py
@@ -0,0 +1,276 @@
+import gtk
+import cairo
+import sys
+import os
+
+from fringwalker import FringWalker
+from fringrenderer import FringRenderer
+
+GPL = """
+fring is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+fring is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with fring; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+USA.
+"""
+
+ui = """
+<ui>
+
+ <menubar name="MenuBar">
+ <menu action="FRing">
+ <menuitem action="SelectFolder"/>
+ <menuitem action="OpenParent"/>
+ <menuitem action="Refresh"/>
+ <separator />
+ <menuitem action="Save Image..."/>
+ <separator />
+ <menuitem action="Quit"/>
+ </menu>
+ <menu action="View">
+ <menuitem action="Show Hidden Files"/>
+ <separator />
+ <menuitem action="Zoom In"/>
+ <menuitem action="Zoom Out"/>
+ </menu>
+ <menu action="Help">
+ <menuitem action="About"/>
+ </menu>
+ </menubar>
+
+ <toolbar name="Toolbar">
+ </toolbar>
+
+</ui>"""
+
+
+class UI( gtk.Window ):
+
+ def __init__(self, path):
+ self.backgroundColour = (1,1,1)
+ self.data = None
+ self.zoomfactor = 1.0
+ self.renderer = FringRenderer()
+ self.walker = FringWalker();
+
+ # create gui
+ gtk.Window.__init__(self)
+ self.set_title("fring");
+ self.__init_gui(path)
+
+ # walk directory
+ self.walker.connect("list-changed",self.__list_changed)
+ self.open_folder(path)
+
+
+ def __init_gui(self, path):
+
+ # create menubar
+ uimanager = gtk.UIManager()
+ accelgroup = uimanager.get_accel_group()
+ self.add_accel_group(accelgroup)
+ ag_global = gtk.ActionGroup('ag_global')
+ ag_global.add_actions([
+ ('FRing', None, "_Folder"),
+ ('View', None, "_View"),
+ ('Help', None, "_Help"),
+ ('OpenParent', gtk.STOCK_GO_UP, "Open _Parent", "<alt>Up", "Open the parent folder", self.open_parent),
+ ('SelectFolder', gtk.STOCK_OPEN, "_Open Folder...", None, "Open Folder...", self.__selectfolder),
+ ('Quit', gtk.STOCK_QUIT, "_Quit", None, "Quit", self.close),
+ ('Zoom In', gtk.STOCK_ZOOM_IN, "Zoom _In", "<ctrl>Up", "Zoom In", lambda w: self.zoom(w,0.2)),
+ ('Zoom Out', gtk.STOCK_ZOOM_OUT, "Zoom _Out", "<ctrl>Down", "Zoom Out", lambda w: self.zoom(w,-0.2)),
+ ('Save Image...', gtk.STOCK_SAVE_AS, "_Save Image...", None, "Save Image...", self.save_image),
+ ('Refresh', gtk.STOCK_REFRESH, "_Refresh Tree", "<ctrl>R", "Refresh Tree", lambda w: self.__set_path(self.path)),
+ ('About', gtk.STOCK_ABOUT, "_About", None, "About", self.about_dialog),
+ ])
+ action = gtk.ToggleAction("Show Hidden Files", "Show Hidden Files", None, None)
+ action.connect("toggled",self.__hidden_files_toggled)
+ ag_global.add_action(action)
+ uimanager.insert_action_group(ag_global, 0)
+ uimanager.add_ui_from_string(ui)
+ menubar = uimanager.get_widget('/MenuBar')
+ menubar.show()
+
+ # create toolbar
+ toolbar = gtk.HBox()
+
+ b = gtk.Button()
+ img = gtk.image_new_from_stock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_BUTTON)
+ b.set_property("image", img)
+ uimanager.get_action("/MenuBar/FRing/OpenParent").connect_proxy(b)
+ toolbar.pack_start( b, False )
+
+ b = gtk.FileChooserButton('Select a Folder')
+ b.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ b.connect("current-folder-changed", lambda w: self.__set_path(w.get_current_folder()))
+ toolbar.pack_start( b, True )
+ self.filechooserbutton = b
+
+ # create canvas
+ self.eventbox = gtk.EventBox()
+ self.image = gtk.Image()
+ self.eventbox.add(self.image)
+ self.eventbox.add_events( gtk.gdk.EXPOSURE_MASK
+ | gtk.gdk.LEAVE_NOTIFY_MASK
+ | gtk.gdk.BUTTON_PRESS_MASK
+ | gtk.gdk.POINTER_MOTION_MASK )
+ self.eventbox.connect("scroll_event", self.__scroll_event)
+ self.eventbox.connect("button-press-event",self.__click_event)
+ self.eventbox.connect("motion-notify-event",self.__move_event)
+
+ # aligh menubar, toolbar and canvas vertically
+ vbox = gtk.VBox();
+ vbox.pack_start(menubar,False,False)
+ vbox.pack_start(toolbar,False,False)
+ f = gtk.Frame()
+ f.set_shadow_type(gtk.SHADOW_IN)
+ f.add(self.eventbox)
+ vbox.pack_start(f)
+ self.add(vbox)
+
+ # show everything
+ # Note: With set_default_size, the image can't be downsized.
+ self.set_size_request(100,100) # minimum size, needed!
+ self.resize(500,350)
+ self.show_all()
+ self.__create_canvas()
+ self.eventbox.connect("size-allocate",self.__on_resize)
+ self.connect("delete_event", self.close)
+
+ def open_folder(self,path):
+ print "open",path
+ # change folder by changing the chooser button
+ self.filechooserbutton.set_current_folder(path)
+
+ def about_dialog(self,widget):
+ d = gtk.AboutDialog()
+ d.set_name("fring");
+ d.set_license(GPL);
+ d.set_copyright("copyright 2006 Lennart Poettering, Frederic Back")
+ d.run()
+ d.destroy()
+
+ def close(self,w=None,e=None):
+ self.walker.stop()
+ self.destroy()
+ gtk.main_quit()
+
+ def open_parent(self,widget):
+ p = os.path.split(self.path)
+ p = os.path.join(p[:-1])
+ self.open_folder(p[0])
+
+ def zoom(self,widget,factor):
+ self.zoomfactor += factor
+ if self.zoomfactor < 0:
+ self.zoomfactor = 0
+ self.redraw()
+
+ def redraw(self,widget=None):
+ # clear the canvas
+ self.ctx.rectangle(0,0,self.width,self.height)
+ self.ctx.set_source_rgb(*self.backgroundColour)
+ self.ctx.fill()
+
+ # draw segments
+ if not self.data: return
+ self.renderer.WIDTH = self.width
+ self.renderer.HEIGHT = self.height
+ self.renderer.INNER_RADIUS = self.height/15
+ self.renderer.RING_RADIUS = self.height/10
+ #self.renderer.INNER_RADIUS *= self.zoomfactor
+ self.renderer.RING_RADIUS *= self.zoomfactor
+ self.renderer.RINGS_MAX = 3
+
+ self.renderer.LABEL_UNTIL_RING = int(self.zoomfactor - 0.4)
+ if self.zoomfactor < 0.8: self.renderer.LABEL_UNTIL_RING = -1
+
+ self.renderer.hotspots = []
+ self.renderer.draw_segment(self.ctx, 0, 0, 1, 0, 1, self.data, self.path)
+ self.image.queue_draw()
+
+ def save_image(self, widget=None):
+ d = gtk.FileChooserDialog("Save As...",
+ self.get_toplevel(), gtk.FILE_CHOOSER_ACTION_SAVE,
+ (gtk.STOCK_CANCEL,0,gtk.STOCK_OK,1), None)
+ d.set_current_name( self.data.name.replace(" ","_") + ".png" )
+ r = d.run()
+ if r == 1:
+ #print d.get_uri()
+ pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,True,8,self.width,self.height)
+ pixmap, mask = self.image.get_pixmap()
+ pixbuf.get_from_drawable(pixmap,pixmap.get_colormap(),0,0,0,0,-1,-1)
+ #pixbuf.save(d.get_filename(), "jpeg", {"quality":"100"})
+ pixbuf.save(d.get_filename(), "png", {})
+ d.destroy()
+
+ #----------------------------------------------------------- private methods
+
+ def __set_path(self,path):
+ """ Set a path and start parsing. Also used to refresh or reset. """
+ self.path = path
+ self.walker.stop()
+ if path is None: return
+ self.walker.walk(path);
+
+ def __selectfolder(self,widget):
+ """ Open a dialog to select a folder """
+ d = gtk.FileChooserDialog(None, self,
+ gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ (gtk.STOCK_CANCEL,0,gtk.STOCK_OK,1))
+ if d.run() == 1: self.open_folder(d.get_current_folder())
+ d.destroy()
+
+ def __hidden_files_toggled(self,widget):
+ if self.walker.showhidden == widget.get_active(): return
+ self.walker.showhidden = widget.get_active()
+ self.__set_path(self.path)
+
+ def __move_event(self, widget, event):
+ 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))
+ 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)
+
+ def __scroll_event(self, widget, event):
+ if event.direction is gtk.gdk.SCROLL_UP:
+ self.zoom(widget, 0.2)
+ elif event.direction is gtk.gdk.SCROLL_DOWN:
+ self.zoom(widget, -0.2)
+
+ def __create_canvas(self):
+ # create a new pixmap and cairo context
+ r = self.eventbox.get_allocation()
+ self.width, self.height = r.width, r.height
+ self.pixmap = gtk.gdk.Pixmap(self.window,r.width,r.height)
+ self.image.set_from_pixmap(self.pixmap,None)
+ self.ctx = self.pixmap.cairo_create()
+ self.renderer.prepare_layouts(self.ctx)
+
+ def __list_changed(self,widget,data):
+ self.data = data
+ self.redraw()
+ #print data.name
+
+ def __on_resize(self, widget, event):
+ r = self.eventbox.get_allocation()
+ if (r.width,r.height) != (self.width,self.height):
+ self.__create_canvas()
+ self.redraw()
+
+
+
diff --git a/fringwalker.py b/fringwalker.py
new file mode 100644
index 0000000..274ea24
--- /dev/null
+++ b/fringwalker.py
@@ -0,0 +1,153 @@
+import os, os.path, stat, sys
+
+import gobject, gtk
+from threading import Thread
+import time
+
+class sum_list:
+ data = []
+ the_sum = 0
+ name = None
+
+ def __init__(self, l, name = None):
+
+ self.data = list(l)
+ self.name = name
+
+ for fn, i in self.data:
+
+ if isinstance(i, sum_list):
+ self.the_sum += i.the_sum
+ else:
+ self.the_sum += i
+
+ def __str__(self):
+ return self.name+": "+str(self.data)
+
+
+class FringWalker( gobject.GObject ):
+
+ __gsignals__ = {
+ 'list-changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
+ 'finished': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
+ 'progress': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,gobject.TYPE_INT)),
+ }
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+ self.thread = None
+ self.stopsignal = False
+ self.showhidden = False
+
+ def walk(self,path):
+ self.thread = Thread(None,self._parse,None,(path,))
+ self.stopsignal = False
+ print "stard thread (%s)"%path
+ self.thread.start()
+
+
+ def stop(self):
+ if self.thread is None:
+ return
+
+ if not self.thread.isAlive():
+ self.thread = None
+ return
+
+ self.stopsignal = True
+ print "stopping thread:"
+ #self.thread.join()
+ print "ok"
+
+
+ def _parse(self,path):
+ """ Parse the root directory """
+
+ l = []
+ i = 0
+ subdirectories = {}
+
+ try:
+ for fn in os.listdir(path):
+
+ if not self.showhidden and fn[0] == '.': continue
+
+ try: p = os.path.join(path, fn)
+ except: continue
+
+ s = os.lstat(p)
+
+ if stat.S_ISDIR(s.st_mode):
+ subdirectories[i] = (fn,p);
+ l.append((fn, s.st_size))
+ elif stat.S_ISREG(s.st_mode):
+ l.append((fn, s.st_size))
+
+ i += 1
+
+ except:
+ pass
+
+ gtk.gdk.threads_enter()
+ self.emit("list-changed",sum_list(l, os.path.split(path)[-1]))
+ gtk.gdk.threads_leave()
+
+ c = 0
+ for n in subdirectories:
+ c += 1
+
+ # give gtk a breath to redraw
+ time.sleep(0.05)
+
+ # walk subdirectory
+ fn,p = subdirectories[n]
+ l[n] = (fn, self._build_tree(p));
+ if self.stopsignal: return
+
+ # emit signals
+ gtk.gdk.threads_enter()
+ self.emit("progress",c,len(subdirectories))
+ self.emit("list-changed",sum_list(l, os.path.split(path)[-1]))
+ gtk.gdk.threads_leave()
+
+
+ gtk.gdk.threads_enter()
+ self.emit("finished",sum_list(l, os.path.split(path)[-1]))
+ gtk.gdk.threads_leave()
+
+ print "finished walking",path
+
+
+ def _build_tree(self,path):
+ """ Parse directories recursively """
+ l = []
+ try:
+
+ # walk files in directory
+ subdirectories = []
+ for fn in os.listdir(path):
+
+ if self.stopsignal: return sum_list([])
+
+ if not self.showhidden and fn[0] == '.': continue
+
+ try: p = os.path.join(path, fn)
+ except: continue
+
+ s = os.lstat(p)
+
+ if stat.S_ISDIR(s.st_mode):
+ subdirectories.append( (fn,p) );
+ elif stat.S_ISREG(s.st_mode):
+ l.append((fn, s.st_size))
+
+ # add subdirectories after files
+ for fn,p in subdirectories:
+ l.append((fn, self._build_tree(p)))
+ if self.stopsignal: return sum_list([])
+
+ except:
+ pass
+
+ return sum_list(l, os.path.split(path)[-1])
+