-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardinalsin.rb
executable file
·74 lines (60 loc) · 1.65 KB
/
cardinalsin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env ruby1.8
# Cardinal Sin
# © 2009 Omari Stephens <[email protected]>
#
# This software is released under the GNU General Public License (GNU GPL).
# Please read the included file COPYING for more information.
# This software comes with no warranty of any kind, use at your own risk!
require 'gtk2'
require 'pathname'
require 'set'
require 'set_view'
IMAGE_DIR = Pathname.new('images/')
ICON_SIZE = 240
# store [hash, sets, path, filename/title, image]
# hash is a hash of the canonical path
store = Gtk::ListStore.new(Integer, Set, Pathname, String, Gdk::Pixbuf)
real_tmp_set = CSTK::HScrolledIconView.new(store)
real_tmp_set.pixbuf_column = 3
IMAGE_DIR.children.sort.each {
|img|
begin
pixbuf = Gdk::Pixbuf.new(img.to_s)
rescue Gdk::PixbufError
# probably wasn't an image; skip it
next
end
iter = store.append
iter[0] = img.realpath.hash
iter[1] = Set.new
iter[2] = img
iter[3] = img.basename
w = pixbuf.width
h = pixbuf.height
if(w > h)
# landscape orientation
iter[4] = pixbuf.scale(ICON_SIZE, h*ICON_SIZE/w)
else
# portrait or square
iter[4] = pixbuf.scale(w*ICON_SIZE/h, ICON_SIZE)
end
}
tmp_set = Gtk::IconView.new(store)
tmp_set.pixbuf_column = 4
tmp_set.text_column = 3
sw = Gtk::ScrolledWindow.new
sw.add_with_viewport(tmp_set)
sw.vscrollbar_policy=Gtk::POLICY_NEVER
tmp = Gtk::VPaned.new
tmp.add1(real_tmp_set)
tmp.add2(sw)
window = Gtk::Window.new
window.title = "Cardinal Sin"
window.set_size_request(640, 480)
window.border_width = 10
window.signal_connect("destroy") {
Gtk.main_quit
}
window.add(tmp)
window.show_all
Gtk.main