21
20
def __init__(self):
26
self.adj = gtk.Adjustment(5, 1, 10, 1)
27
self.db = cPickle.load(open('data/db', 'rb'))
28
self.ind = int(cPickle.load(open('data/num', 'rb')))
29
todayPicName = "pictures/" + str(self.ind) + ".png"
29
# If the `~/.photostory/photos` directory doesn't exist, create it:
30
if not os.path.exists(os.path.expanduser('~/.photostory/photos')):
31
os.makedirs(os.path.expanduser('~/.photostory/photos'))
33
# If the `~/.photostory/db` pickle doesn't exist, create it:
34
if not os.path.isfile(os.path.expanduser('~/.photostory/db')):
35
cPickle.dump({}, open(os.path.expanduser('~/.photostory/db'), 'w'))
37
# If the `~/.photostory/num` pickle doesn't exist, create it:
38
if not os.path.isfile(os.path.expanduser('~/.photostory/num')):
39
cPickle.dump(0, open(os.path.expanduser('~/.photostory/num'), 'w'))
41
# Load the `db` and `num` pickles:
42
self.db = cPickle.load(open(os.path.expanduser('~/.photostory/db'), 'rb'))
43
self.ind = int(cPickle.load(open(os.path.expanduser('~/.photostory/num'), 'rb')))
45
todayPicName = os.path.expanduser('~/.photostory/photos/') + str(self.ind) + ".png"
32
48
def chooseDay(cal):
36
52
def closedown(win):
37
53
print 'ind ' + str(self.ind)
38
54
print 'db' + str(self.db)
39
cPickle.dump(self.db, open('data/db', 'wb'))
40
cPickle.dump(self.ind, open('data/num', 'wb'))
55
cPickle.dump(self.db, open(os.path.expanduser('~/.photostory/db'), 'wb'))
56
cPickle.dump(self.ind, open(os.path.expanduser('~/.photostory/num'), 'wb'))
43
59
def about(aboutBut):
44
60
dAbout = gtk.AboutDialog()
45
61
dAbout.set_name("Photostory")
46
dAbout.set_comments("Photostory is an application that lets you tell the story of your life in pictures, by taking a snapshot of you each day. You can then make these into a video to share with friends or on the internet.")
62
dAbout.set_comments("Photostory is an application that lets you tell the story of your life in photos, by taking a snapshot of you each day. You can then make these into a video to share with friends or on the internet.")
63
dAbout.set_artists(("Josh Brown", ""))
64
dAbout.set_authors(("Joel Auterson", "David Turner", "Josh Brown"))
65
dAbout.set_website("http://launchpad.net/photostory")
47
66
response = dAbout.run()
54
73
movPicker = gtk.FileChooserDialog(title="Choose a save location", parent=movDia, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(("Save Here", -6)), backend=None)
55
74
movRes = movPicker.run()
57
movPath = movPicker.get_filename()
76
self.movPath = movPicker.get_filename()
58
77
movPicker.destroy()
60
79
def movGen(movButton):
64
83
filmPipe = gst.Pipeline("filmPipe")
65
84
filmSrc = gst.element_factory_make("multifilesrc", "filmSrc")
66
filmSrc.set_property("location", "pictures/%d.png")
85
filmSrc.set_property("location", os.path.expanduser("~/.photostory/photos/") + "%d.png")
67
86
filmFilt1 = gst.element_factory_make("capsfilter", "filmFilt1")
68
filmCap1 = gst.Caps("image/png,framerate=5/1,pixel-aspect-ratio=1/1")
87
filmCap1 = gst.Caps("image/png,framerate=" + str(int(self.adj.get_value())) + "/1,pixel-aspect-ratio=1/1")
69
88
filmFilt1.set_property("caps", filmCap1)
70
89
filmPngDec = gst.element_factory_make("pngdec", "filmPngDec")
71
90
filmff = gst.element_factory_make("ffmpegcolorspace", "filmff")
75
94
filmTheora = gst.element_factory_make("xvidenc", "filmTheora")
76
95
filmOggmux = gst.element_factory_make("ffmux_mp4", "filmOggmux")
77
96
filmFilesink = gst.element_factory_make("filesink", "filmFilesink")
78
filmFilesink.set_property("location", movPath)
97
filmFilesink.set_property("location", self.movPath)
80
99
filmPipe.add(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
81
100
gst.element_link_many(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
88
107
movDia.set_resizable(False)
89
108
filmBut.set_sensitive(False)
90
109
movVbox = gtk.VBox(homogeneous=False, spacing=2)
91
movLabel = gtk.Label("Here you can create a video made up of all your pictures. \n\nJust choose a save location and hit 'create'.\n\nRemember, the path must end in '.mp4'.\n")
110
movLabel = gtk.Label("Here you can create a video made up of all your photos. \n\nJust choose a save location and hit 'create'.\n\nRemember, the path must end in '.mp4'.\n")
92
111
movFileButton = gtk.Button(label="Choose a location")
93
112
movButton = gtk.Button(label="Create")
115
movSliderBox = gtk.HBox(homogeneous=False, spacing=3)
116
movSliderLabel = gtk.Label("FPS:")
117
movSlider = gtk.HScale(self.adj)
118
movSlider.set_digits(0)
119
movSliderBox.pack_start(movSliderLabel, expand=False)
120
movSliderBox.pack_start(movSlider, expand=True)
94
122
movDia.add(movVbox)
95
123
movVbox.pack_start(movLabel, expand=False)
124
movVbox.pack_start(movSliderBox, expand=False)
96
125
movVbox.pack_start(movFileButton, expand=False)
97
126
movVbox.pack_start(movButton, expand=False)
98
127
movButton.connect("clicked", movGen)
133
162
os.remove(self.db[date])
135
164
if date == todayDate:
136
takeBut.set_label("Take today's picture")
165
takeBut.set_label("Take today's photo")
137
166
takeBut.set_sensitive(True)
140
169
for element in self.db:
141
oldPath = "pictures/" + str(i) + ".png"
170
oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
142
171
if not os.path.exists(oldPath):
145
oldPath = "pictures/" + str(i) + ".png"
174
oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
146
175
if os.path.exists(oldPath):
147
176
key = getKey(self.db, oldPath)
148
newPath = "pictures/" + str(i-gaps) + ".png"
177
newPath = os.path.expanduser('~/.photostory/photos/') + str(i-gaps) + ".png"
149
178
os.rename(oldPath, newPath)
150
179
self.db[key] = newPath
159
188
if date in self.db:
160
189
self.pic = gtk.Image()
161
190
self.pic.set_from_file(self.db[date])
162
takeBut.set_label("Picture taken for this day.")
191
takeBut.set_label("Photo taken for this day.")
163
192
takeBut.set_sensitive(False)
165
194
if date == todayDate:
166
takeBut.set_label("Take today's picture")
195
takeBut.set_label("Take today's photo")
167
196
takeBut.set_sensitive(True)
169
takeBut.set_label("Take today's picture")
198
takeBut.set_label("Take today's photo")
170
199
takeBut.set_sensitive(False)
171
200
self.pic = gtk.Label()
172
201
self.pic.set_justify(gtk.JUSTIFY_CENTER)
173
self.pic.set_markup("<span size='54000'>No Picture\nToday</span>");
202
self.pic.set_markup("<span size='54000'>No Photo\nToday</span>");
174
203
self.pic.set_size_request(640, 480)
175
204
vbox1.pack_start(self.pic)
176
205
vbox1.pack_start(hbox2)
182
211
win.set_default_size(900, 600)
183
212
win.set_resizable(False)
184
213
win.set_title("Photostory")
185
win.set_icon_from_file("data/icon.svg")
214
win.set_icon_from_file("photostory.svg")
186
215
movie = gtk.DrawingArea()
216
movie.set_size_request(320, 240)
187
217
hbox = gtk.HBox(homogeneous=False, spacing=3)
188
218
vbox1 = gtk.VBox(homogeneous=False)
189
219
vbox2 = gtk.VBox(homogeneous = False)
190
220
filmBut = gtk.Button(label="Create Film")
191
221
filmBut.connect("clicked", movify)
192
deleteBut = gtk.Button(label="Delete Picture")
222
deleteBut = gtk.Button(label="Delete Photo")
193
223
deleteBut.connect("clicked", deletePic)
194
224
shareBut = gtk.Button(label="Share Video")
195
225
hbox2 = gtk.HBox(homogeneous=True)
196
226
aboutBut = gtk.Button(label="About")
197
227
aboutBut.connect("clicked", about)
199
229
cal = gtk.Calendar()
200
230
todayDate = cal.get_date()
201
231
cal.connect("day-selected", chooseDay)
203
takeBut = gtk.Button(label="Take today's picture")
233
takeBut = gtk.Button(label="Take today's photo")
204
234
takeBut.connect("clicked", capture)
206
236
setPic(todayDate)
209
239
hbox.pack_start(vbox1, expand=False)
210
hbox.pack_start(vbox2)
211
240
hbox2.pack_start(filmBut, expand=False)
212
241
hbox2.pack_start(deleteBut, expand=False)
213
242
#hbox2.pack_start(shareBut)
214
243
hbox2.pack_start(aboutBut)
215
hbox.pack_start(vbox2)
216
244
vbox2.pack_start(movie)
217
vbox2.pack_start(cal, expand=False, padding=50)
245
vbox2.pack_start(cal, expand=True, padding=10)
218
246
vbox2.pack_start(takeBut, expand=False)
247
hbox.pack_start(vbox2)
222
250
#Pipeline stuff - feed
225
253
camera = gst.element_factory_make("v4l2src", "camera")
226
254
camera.set_property("device", "/dev/video0")
228
256
caps = gst.Caps("video/x-raw-yuv,width=640,height=480,framerate=30/1")
229
257
filt = gst.element_factory_make("capsfilter", "filter")
230
258
filt.set_property("caps", caps)