Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/iconview.py
blob: a8c273a2f04567edaa44559269cf4c7a3bbc1a54 (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 pygtk
pygtk.require('2.0')

import getopt
import sys
import gtk
import gtk.gdk

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, gtk.gdk.Pixbuf)
    i = 0
    while i < len(args):
        scaled_pixbuf = gtk.gdk.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.POLICY_AUTOMATIC, gtk.POLICY_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)
    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)