blob: 77043ce491e300fd2a6e4cf0da076946ec2bb5f8 (
plain)
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
|
#! /usr/bin/env python
import gi
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
import getopt
import sys
def extract_filename(filename):
partition_tuple = filename.rpartition('/')
return partition_tuple[2]
def make_iconview(args):
# First create an iconview
view = Gtk.IconView()
# Create a store for our iconview and fill it with stock icons
store = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
i = 0
while i < len(args):
scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(args[i], 160, 120)
filename = extract_filename(args[i])
store.append(['%s' % filename, scaled_pixbuf])
i = i + 1
# Connect our iconview with our store
view.set_model(store)
# Map store text and pixbuf columns to iconview
view.set_text_column(0)
view.set_pixbuf_column(1)
# Pack our iconview into a scrolled window
swin = Gtk.ScrolledWindow()
swin.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
swin.add_with_viewport(view)
swin.show_all()
# pack the scrolled window into a simple dialog and run it
dialog = Gtk.Dialog('IconView Demo')
close = dialog.add_button(Gtk.STOCK_CLOSE, Gtk.RESPONSE_NONE)
dialog.set_default_size(1024,800)
dialog.vbox.pack_start(swin, False, False, 0)
dialog.run()
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "")
make_iconview(args)
except getopt.error, msg:
print msg
print "This program has no options"
sys.exit(2)
|