-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
158 lines (132 loc) · 4.59 KB
/
view.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'''
sunrise_helper
A script for making it easier to post pictures to Wordpress.com
Blaine Booher
http://aultparksunrise.com
http://github.com/booherbg/sunrise_helper
Licensed under the GPLv2
See http://github.com/booherbg/sunrise_helper for more info on this project
usage:
python view.py Day40/*.jpg
'''
from __future__ import division
import pygtk; pygtk.require('2.0')
import gtk
import glob
import os
import annotate
import sys
import datetime
if len(sys.argv) > 1:
files = sys.argv[1:]
else:
print "usage: %s <files>" % sys.argv[0]
print ""
print "For example, let's say you have a folder full of pictures."
print "This folder is located at /sunrise/Day40/"
print "$ python %s /sunrise/Day40/*.jpg" % sys.argv[0]
print " ^--- that would run the script on all the .jpg files located"
print "in the Day40/ folder, process them and prompt you for a name,"
print "and dump the new file (via image-magick) into Day40/ while "
print "leaving the original files intact. Try it out."
print ""
print "Requires: "
print " * python"
print " * image-magick"
print " * gtk+-2.0"
print " * python-gtk (pygtk)"
sys.exit(0)
for f in files:
sys.stderr.write("%s\n" % f)
func = annotate.process
class Image_Example(object):
def pressButton(self, widget, data=None):
self.set_next()
def delete_event(self, widget, event, data=None):
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def set_image(self, fname):
pb = gtk.gdk.pixbuf_new_from_file(fname)
width = pb.get_width()
height = pb.get_height()
ratio = width / height
self.image.set_from_pixbuf(pb.scale_simple(int(400*ratio),400,gtk.gdk.INTERP_BILINEAR))
def set_next(self):
self.index += 1
if self.index >= len(self.flist):
self.index = 0
fname = self.flist[self.index]
self.set_image(fname)
def process(self):
quit = False
for index, fname in enumerate(self.flist):
if "_4nn." in fname:
continue
self.set_image(fname)
name = ''
while True:
name = self.dialog()
day_of_year = int(datetime.datetime.now().strftime("%j"))
rename = '%#03d_%#02d_%s_4nn.jpg' % (day_of_year, index, name)
if name == 'exit':
quit = True
break
elif name.strip() == '':
continue
else:
break
if quit:
break
func(fname, os.path.join(os.path.split(fname)[0], rename))
#sys.stderr.write("%s\n" % rename)
def __init__(self, flist):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(10)
self.window.move(300,20)
self.button = gtk.Button()
self.button.connect("clicked", self.pressButton, None)
#self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
self.image = gtk.Image()
self.image.show()
self.button.add(self.image)
self.window.add(self.button)
self.button.show()
self.window.show()
self.flist = flist
self.index = -1
self.process()
#self.set_next()
def main(self):
gtk.main()
def responseToDialog(self, entry, dialog, response):
dialog.response(response)
def dialog(self):
# With some help from http://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/
#base this on a message dialog
dialog = gtk.MessageDialog(
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK,
None)
dialog.move(300,500)
dialog.set_markup('Please enter the filename, xx_filename.jpg')
#create the text input field
entry = gtk.Entry()
entry.connect("activate", lambda x,y,z: y.response(z), dialog, gtk.RESPONSE_OK)
hbox = gtk.HBox()
#hbox.pack_start(gtk.Label("Name:"), False, 5, 5)
hbox.pack_end(entry)
#add it and show it
dialog.vbox.pack_end(hbox, True, True, 0)
dialog.show_all()
dialog.run()
text = entry.get_text()
dialog.destroy()
return text
if __name__ == '__main__':
im = Image_Example(files)
im.main()