-
Notifications
You must be signed in to change notification settings - Fork 1
/
image_viewer.py
111 lines (100 loc) · 2.94 KB
/
image_viewer.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
#Simple Image Viewer, with slideshow
#(c) Noprianto <nop@noprianto.com>, 2009, GPL
#
#usage: image_viewer.py <interval> <pattern1> [pattern2] ... [patternn]
#set interval to 0 to disable slideshow
#
import os
import sys
import glob
#
import gtk
import gobject
class Main:
def __init__(self, interval, images):
self.images = images
self.index = -1
self.interval = interval
#
self.win = gtk.Window()
self.win.set_title('Image Viewer')
self.win.connect('destroy', self.quit)
#
self.img = gtk.Image()
#
self.btn_prev = gtk.Button(stock=gtk.STOCK_MEDIA_PREVIOUS)
self.btn_prev.connect('clicked', self.navigate, -1)
self.btn_next = gtk.Button(stock=gtk.STOCK_MEDIA_NEXT)
self.btn_next.connect('clicked', self.navigate, 1)
self.btnbox = gtk.HButtonBox()
self.btnbox.set_layout(gtk.BUTTONBOX_SPREAD)
self.btnbox.set_spacing(10)
self.btnbox.pack_start(self.btn_prev)
self.btnbox.pack_start(self.btn_next)
#
self.statb = gtk.Statusbar()
#
self.vbox = gtk.VBox()
self.vbox.pack_start(self.img, expand=True, padding=2)
self.vbox.pack_start(self.btnbox, expand=False, padding=2)
self.vbox.pack_start(self.statb, expand=False, padding=2)
#
self.win.add(self.vbox)
self.btn_next.clicked()
self.win.show_all()
#
if self.interval > 0:
self.tid = gobject.timeout_add(self.interval, self.slide_show)
def quit(self, widget):
try:
gobject.source_remove(self.tid)
except:
pass
gtk.main_quit()
def navigate(self, widget, step):
self.index += step
fname = self.images[self.index]
#
go_next = False
#
if self.index < 1:
self.btn_prev.set_sensitive(False)
else:
self.btn_prev.set_sensitive(True)
#
if self.index > len(self.images) - 2:
self.btn_next.set_sensitive(False)
else:
self.btn_next.set_sensitive(True)
go_next = True
#
self.img.set_from_file(fname)
self.statb.push(1, fname)
#
return go_next
def slide_show(self):
ret = self.navigate(None, 1)
return ret
if __name__ == '__main__':
images = []
if len(sys.argv) < 3:
print '%s <interval> <pattern1> [pattern2] ... [patternn]' %(
sys.argv[0])
else:
try:
interval = int(sys.argv[1])
except:
interval = 0
#
pats = sys.argv[2:]
for p in pats:
files = glob.glob(p)
for f in files:
images.append(os.path.abspath(f))
#
if images:
app = Main(interval, images)
gtk.main()
else:
print 'No files found'