Merge lp:~photostory/photostory/cleanup into lp:photostory
- cleanup
- Merge into code
Status: | Rejected |
---|---|
Rejected by: | Josh Brown |
Proposed branch: | lp:~photostory/photostory/cleanup |
Merge into: | lp:photostory |
Diff against target: |
541 lines (+254/-276) 1 file modified
photostory (+254/-276) |
To merge this branch: | bzr merge lp:~photostory/photostory/cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Josh Brown | Disapprove | ||
Joel Auterson | Needs Resubmitting | ||
Review via email: mp+40287@code.launchpad.net |
Commit message
Description of the change
- 26. By Josh Brown
-
Correct video creating path
- 27. By David Turner
-
-Fixed the FPS Video Creation Process
-Fixed a GTK Warning message - 28. By David Turner
-
-Fixed bug #672272: The program now starts if the logo is missing
- 29. By David Turner
-
-Fixed the program crashing on startup
Joel Auterson (joel-auterson) wrote : | # |
- 30. By Josh Brown
-
General cleanup; remove Main() function and other changes
Josh Brown (joshbrown) wrote : | # |
I've manually cleaned the newest version of <code> and overwrote this branch with the amended <code> branch. This is ready for merging into <code> again, although testing beforehand may be prudent.
Joel Auterson (joel-auterson) wrote : | # |
Could you do it AGAIN after I've got rid of the pickling? I have an
idea as to how we're going to do this.
Josh Brown (joshbrown) wrote : | # |
If you've already started work on the pickling then I'll redo the cleanup afterwards.
Josh Brown (joshbrown) wrote : | # |
I'm going to reject this as much of it has been incorporated into <lp:~photostory/photostory/code>, revision 34. Another proposal can be made at a later date if further changes are necessary, please feel free to reopen if you disagree.
Joel Auterson (joel-auterson) wrote : | # |
It's your code, Josh, do whatever you feel necessary. :)
Unmerged revisions
- 30. By Josh Brown
-
General cleanup; remove Main() function and other changes
Preview Diff
1 | === modified file 'photostory' | |||
2 | --- photostory 2011-01-24 04:12:08 +0000 | |||
3 | +++ photostory 2011-02-08 23:10:47 +0000 | |||
4 | @@ -1,283 +1,261 @@ | |||
5 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
6 | 2 | 2 | ||
10 | 3 | #Photostory 0.9 | 3 | # Photostory 0.95 |
11 | 4 | #by Joel Auterson (joel.auterson@googlemail.com) | 4 | # Joel Auterson (joel.auterson@googlemail.com) |
12 | 5 | #http://www.launchpad.net/photostory | 5 | # http://launchpad.net/photostory |
13 | 6 | 6 | ||
24 | 7 | import pygst | 7 | import time, os, cPickle, gtk, gst, glib |
15 | 8 | pygst.require("0.10") | ||
16 | 9 | import gst | ||
17 | 10 | import pygtk | ||
18 | 11 | import gtk | ||
19 | 12 | from time import strftime | ||
20 | 13 | import time | ||
21 | 14 | import os.path | ||
22 | 15 | import os | ||
23 | 16 | import cPickle | ||
25 | 17 | from threading import Timer | 8 | from threading import Timer |
286 | 18 | import glib | 9 | |
287 | 19 | 10 | pipeline = None | |
288 | 20 | class Main: | 11 | xvimagesink = None |
289 | 21 | 12 | movie = None | |
290 | 22 | def __init__(self): | 13 | movPath = None |
291 | 23 | 14 | adj = gtk.Adjustment(5, 1, 10, 1) | |
292 | 24 | pipeline = None | 15 | pic = None |
293 | 25 | xvimagesink = None | 16 | |
294 | 26 | movie = None | 17 | # If the `~/.photostory/photos` directory doesn't exist, create it: |
295 | 27 | self.movPath = None | 18 | if not os.path.exists(os.path.expanduser('~/.photostory/photos')): |
296 | 28 | self.adj = gtk.Adjustment(5, 1, 10, 1) | 19 | os.makedirs(os.path.expanduser('~/.photostory/photos')) |
297 | 29 | self.pic=None | 20 | |
298 | 30 | 21 | # If the `~/.photostory/db` pickle doesn't exist, create it: | |
299 | 31 | # If the `~/.photostory/photos` directory doesn't exist, create it: | 22 | if not os.path.isfile(os.path.expanduser('~/.photostory/db')): |
300 | 32 | if not os.path.exists(os.path.expanduser('~/.photostory/photos')): | 23 | cPickle.dump({}, open(os.path.expanduser('~/.photostory/db'), 'w')) |
301 | 33 | os.makedirs(os.path.expanduser('~/.photostory/photos')) | 24 | |
302 | 34 | 25 | # If the `~/.photostory/num` pickle doesn't exist, create it: | |
303 | 35 | # If the `~/.photostory/db` pickle doesn't exist, create it: | 26 | if not os.path.isfile(os.path.expanduser('~/.photostory/num')): |
304 | 36 | if not os.path.isfile(os.path.expanduser('~/.photostory/db')): | 27 | cPickle.dump(0, open(os.path.expanduser('~/.photostory/num'), 'w')) |
305 | 37 | cPickle.dump({}, open(os.path.expanduser('~/.photostory/db'), 'w')) | 28 | |
306 | 38 | 29 | # Load the `db` and `num` pickles: | |
307 | 39 | # If the `~/.photostory/num` pickle doesn't exist, create it: | 30 | db = cPickle.load(open(os.path.expanduser('~/.photostory/db'), 'rb')) |
308 | 40 | if not os.path.isfile(os.path.expanduser('~/.photostory/num')): | 31 | ind = int(cPickle.load(open(os.path.expanduser('~/.photostory/num'), 'rb'))) |
309 | 41 | cPickle.dump(0, open(os.path.expanduser('~/.photostory/num'), 'w')) | 32 | |
310 | 42 | 33 | todayPicName = os.path.expanduser('~/.photostory/photos/') + str(self.ind) + ".png" | |
311 | 43 | # Load the `db` and `num` pickles: | 34 | todayDate = None |
312 | 44 | self.db = cPickle.load(open(os.path.expanduser('~/.photostory/db'), 'rb')) | 35 | |
313 | 45 | self.ind = int(cPickle.load(open(os.path.expanduser('~/.photostory/num'), 'rb'))) | 36 | def chooseDay(cal): |
314 | 46 | 37 | dateTuple = cal.get_date() | |
315 | 47 | todayPicName = os.path.expanduser('~/.photostory/photos/') + str(self.ind) + ".png" | 38 | setPic(dateTuple) |
316 | 48 | todayDate = None | 39 | |
317 | 49 | 40 | def closedown(win): | |
318 | 50 | def chooseDay(cal): | 41 | print 'ind ' + str(ind) |
319 | 51 | dateTuple = cal.get_date() | 42 | print 'db' + str(db) |
320 | 52 | setPic(dateTuple) | 43 | cPickle.dump(db, open(os.path.expanduser('~/.photostory/db'), 'wb')) |
321 | 53 | 44 | cPickle.dump(ind, open(os.path.expanduser('~/.photostory/num'), 'wb')) | |
322 | 54 | def closedown(win): | 45 | gtk.main_quit() |
323 | 55 | print 'ind ' + str(self.ind) | 46 | |
324 | 56 | print 'db' + str(self.db) | 47 | def about(aboutBut): |
325 | 57 | cPickle.dump(self.db, open(os.path.expanduser('~/.photostory/db'), 'wb')) | 48 | dAbout = gtk.AboutDialog() |
326 | 58 | cPickle.dump(self.ind, open(os.path.expanduser('~/.photostory/num'), 'wb')) | 49 | dAbout.set_name("Photostory") |
327 | 59 | gtk.main_quit() | 50 | 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.") |
328 | 60 | 51 | dAbout.set_artists(("Josh Brown")) | |
329 | 61 | def about(aboutBut): | 52 | dAbout.set_authors(("Joel Auterson", "David Turner", "Josh Brown")) |
330 | 62 | dAbout = gtk.AboutDialog() | 53 | dAbout.set_website("http://launchpad.net/photostory") |
331 | 63 | dAbout.set_name("Photostory") | 54 | response = dAbout.run() |
332 | 64 | 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.") | 55 | if response == -6: |
333 | 65 | dAbout.set_artists(("Josh Brown", "")) | 56 | dAbout.destroy() |
334 | 66 | dAbout.set_authors(("Joel Auterson", "David Turner", "Josh Brown")) | 57 | |
335 | 67 | dAbout.set_website("http://launchpad.net/photostory") | 58 | def movify(filmBut): |
336 | 68 | response = dAbout.run() | 59 | def movPick(movFileButton): |
337 | 69 | if response == -6: | 60 | movPicker = gtk.FileChooserDialog(title="Choose a save location", parent=movDia, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(("Save Here", -6)), backend=None) |
338 | 70 | dAbout.destroy() | 61 | movRes = movPicker.run() |
339 | 71 | 62 | if movRes == -6: | |
340 | 72 | def movify(filmBut): | 63 | movPath = movPicker.get_filename() |
341 | 73 | 64 | movPicker.destroy() | |
342 | 74 | def movPick(movFileButton): | 65 | |
343 | 75 | movPicker = gtk.FileChooserDialog(title="Choose a save location", parent=movDia, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(("Save Here", -6)), backend=None) | 66 | def movGen(movButton): |
344 | 76 | movRes = movPicker.run() | 67 | movDia.destroy() |
345 | 77 | if movRes == -6: | 68 | |
346 | 78 | self.movPath = movPicker.get_filename() | 69 | filmPipe = gst.Pipeline("filmPipe") |
347 | 79 | movPicker.destroy() | 70 | filmSrc = gst.element_factory_make("multifilesrc", "filmSrc") |
348 | 80 | 71 | filmSrc.set_property("location", os.path.expanduser("~/.photostory/photos/") + "%d.png") | |
349 | 81 | def movGen(movButton): | 72 | filmFilt1 = gst.element_factory_make("capsfilter", "filmFilt1") |
350 | 82 | 73 | filmCap1 = gst.Caps("image/png,framerate=" + str(int(self.adj.get_value())) + "/1,pixel-aspect-ratio=1/1") | |
351 | 83 | movDia.destroy() | 74 | filmFilt1.set_property("caps", filmCap1) |
352 | 84 | 75 | filmPngDec = gst.element_factory_make("pngdec", "filmPngDec") | |
353 | 85 | filmPipe = gst.Pipeline("filmPipe") | 76 | filmff = gst.element_factory_make("ffmpegcolorspace", "filmff") |
354 | 86 | filmSrc = gst.element_factory_make("multifilesrc", "filmSrc") | 77 | filmFilt2 = gst.element_factory_make("capsfilter", "filmFilt2") |
355 | 87 | filmSrc.set_property("location", os.path.expanduser("~/.photostory/photos/") + "%d.png") | 78 | filmCap2 = gst.Caps("video/x-raw-yuv") |
356 | 88 | filmFilt1 = gst.element_factory_make("capsfilter", "filmFilt1") | 79 | filmFilt2.set_property("caps", filmCap2) |
357 | 89 | filmCap1 = gst.Caps("image/png,framerate=" + str(int(self.adj.get_value())) + "/1,pixel-aspect-ratio=1/1") | 80 | filmTheora = gst.element_factory_make("xvidenc", "filmTheora") |
358 | 90 | filmFilt1.set_property("caps", filmCap1) | 81 | filmOggmux = gst.element_factory_make("ffmux_mp4", "filmOggmux") |
359 | 91 | filmPngDec = gst.element_factory_make("pngdec", "filmPngDec") | 82 | filmFilesink = gst.element_factory_make("filesink", "filmFilesink") |
360 | 92 | filmff = gst.element_factory_make("ffmpegcolorspace", "filmff") | 83 | filmFilesink.set_property("location", movPath) |
361 | 93 | filmFilt2 = gst.element_factory_make("capsfilter", "filmFilt2") | 84 | |
362 | 94 | filmCap2 = gst.Caps("video/x-raw-yuv") | 85 | filmPipe.add(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink) |
363 | 95 | filmFilt2.set_property("caps", filmCap2) | 86 | gst.element_link_many(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink) |
364 | 96 | filmTheora = gst.element_factory_make("xvidenc", "filmTheora") | 87 | filmPipe.set_state(gst.STATE_PLAYING) |
365 | 97 | filmOggmux = gst.element_factory_make("ffmux_mp4", "filmOggmux") | 88 | time.sleep(5) |
366 | 98 | filmFilesink = gst.element_factory_make("filesink", "filmFilesink") | 89 | filmBut.set_sensitive(True) |
367 | 99 | filmFilesink.set_property("location", self.movPath) | 90 | |
368 | 100 | 91 | movDia = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
369 | 101 | filmPipe.add(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink) | 92 | movDia.set_title("Create Film") |
370 | 102 | gst.element_link_many(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink) | 93 | movDia.set_resizable(False) |
371 | 103 | filmPipe.set_state(gst.STATE_PLAYING) | 94 | filmBut.set_sensitive(False) |
372 | 104 | time.sleep(5) | 95 | movVbox = gtk.VBox(homogeneous=False, spacing=2) |
373 | 105 | filmBut.set_sensitive(True) | 96 | 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") |
374 | 106 | 97 | movFileButton = gtk.Button(label="Choose a location") | |
375 | 107 | movDia = gtk.Window(gtk.WINDOW_TOPLEVEL) | 98 | movButton = gtk.Button(label="Create") |
376 | 108 | movDia.set_title("Create Film") | 99 | |
377 | 109 | movDia.set_resizable(False) | 100 | #FPS Slider |
378 | 110 | filmBut.set_sensitive(False) | 101 | movSliderBox = gtk.HBox(homogeneous=False, spacing=3) |
379 | 111 | movVbox = gtk.VBox(homogeneous=False, spacing=2) | 102 | movSliderLabel = gtk.Label("FPS:") |
380 | 112 | 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") | 103 | movSlider = gtk.HScale(adj) |
381 | 113 | movFileButton = gtk.Button(label="Choose a location") | 104 | movSlider.set_digits(0) |
382 | 114 | movButton = gtk.Button(label="Create") | 105 | movSliderBox.pack_start(movSliderLabel, expand=False) |
383 | 115 | 106 | movSliderBox.pack_start(movSlider, expand=True) | |
384 | 116 | #FPS Slider | 107 | |
385 | 117 | movSliderBox = gtk.HBox(homogeneous=False, spacing=3) | 108 | movDia.add(movVbox) |
386 | 118 | movSliderLabel = gtk.Label("FPS:") | 109 | movVbox.pack_start(movLabel, expand=False) |
387 | 119 | movSlider = gtk.HScale(self.adj) | 110 | movVbox.pack_start(movSliderBox, expand=False) |
388 | 120 | movSlider.set_digits(0) | 111 | movVbox.pack_start(movFileButton, expand=False) |
389 | 121 | movSliderBox.pack_start(movSliderLabel, expand=False) | 112 | movVbox.pack_start(movButton, expand=False) |
390 | 122 | movSliderBox.pack_start(movSlider, expand=True) | 113 | movButton.connect("clicked", movGen) |
391 | 123 | 114 | movFileButton.connect("clicked", movPick) | |
392 | 124 | movDia.add(movVbox) | 115 | movDia.show_all() |
393 | 125 | movVbox.pack_start(movLabel, expand=False) | 116 | |
394 | 126 | movVbox.pack_start(movSliderBox, expand=False) | 117 | def capture(takeBut): |
395 | 127 | movVbox.pack_start(movFileButton, expand=False) | 118 | def takePic(): |
396 | 128 | movVbox.pack_start(movButton, expand=False) | 119 | pipeline.set_state(gst.STATE_NULL) |
397 | 129 | movButton.connect("clicked", movGen) | 120 | stillPipe = gst.Pipeline("stillPipe") |
398 | 130 | movFileButton.connect("clicked", movPick) | 121 | stillCam = gst.element_factory_make("v4l2src", "stillPipe") |
399 | 131 | movDia.show_all() | 122 | stillFilt = gst.element_factory_make("capsfilter", "stillFilt") |
400 | 132 | 123 | stillCap = gst.Caps("video/x-raw-yuv,width=640,height=480") | |
401 | 133 | def capture(takeBut): | 124 | stillFilt.set_property("caps", stillCap) |
402 | 134 | 125 | ffmpegcolorspace = gst.element_factory_make("ffmpegcolorspace", "ffmpegcolorspace") | |
403 | 135 | def takePic(): | 126 | pngEnc = gst.element_factory_make("pngenc", "pngenc") |
404 | 136 | pipeline.set_state(gst.STATE_NULL) | 127 | filesink = gst.element_factory_make("filesink", "filesink") |
405 | 137 | stillPipe = gst.Pipeline("stillPipe") | 128 | filesink.set_property("location", todayPicName) |
406 | 138 | stillCam = gst.element_factory_make("v4l2src", "stillPipe") | 129 | db[todayDate] = todayPicName |
407 | 139 | stillFilt = gst.element_factory_make("capsfilter", "stillFilt") | 130 | cal.freeze() |
408 | 140 | stillCap = gst.Caps("video/x-raw-yuv,width=640,height=480") | 131 | cal.select_month(todayDate[1], todayDate[0]) |
409 | 141 | stillFilt.set_property("caps", stillCap) | 132 | cal.select_day(todayDate[2]) |
410 | 142 | ffmpegcolorspace = gst.element_factory_make("ffmpegcolorspace", "ffmpegcolorspace") | 133 | cal.thaw() |
411 | 143 | pngEnc = gst.element_factory_make("pngenc", "pngenc") | 134 | stillPipe.add(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink) |
412 | 144 | filesink = gst.element_factory_make("filesink", "filesink") | 135 | gst.element_link_many(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink) |
413 | 145 | filesink.set_property("location", todayPicName) | 136 | stillPipe.set_state(gst.STATE_PLAYING) |
414 | 146 | self.db[todayDate] = todayPicName | 137 | time.sleep(1) |
415 | 147 | cal.freeze() | 138 | stillPipe.set_state(gst.STATE_NULL) |
156 | 148 | cal.select_month(todayDate[1], todayDate[0]) | ||
157 | 149 | cal.select_day(todayDate[2]) | ||
158 | 150 | cal.thaw() | ||
159 | 151 | stillPipe.add(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink) | ||
160 | 152 | gst.element_link_many(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink) | ||
161 | 153 | stillPipe.set_state(gst.STATE_PLAYING) | ||
162 | 154 | time.sleep(1) | ||
163 | 155 | stillPipe.set_state(gst.STATE_NULL) | ||
164 | 156 | xvimagesink.set_xwindow_id(movie.window.xid) | ||
165 | 157 | pipeline.set_state(gst.STATE_PLAYING) | ||
166 | 158 | setPic(todayDate) | ||
167 | 159 | self.ind += 1 | ||
168 | 160 | |||
169 | 161 | def countdown(n = 3): | ||
170 | 162 | self.pic.set_markup("<span size='54000'>" + str(n) + "</span>") | ||
171 | 163 | if n == 0: takePic() | ||
172 | 164 | else: glib.timeout_add(1000, countdown, n-1) | ||
173 | 165 | |||
174 | 166 | countdown() | ||
175 | 167 | |||
176 | 168 | def deletePic(deleteBut): | ||
177 | 169 | def getKey(dic, val): | ||
178 | 170 | return [k for k, v in dic.iteritems() if v == val][0] | ||
179 | 171 | date = cal.get_date() | ||
180 | 172 | if date in self.db: | ||
181 | 173 | os.remove(self.db[date]) | ||
182 | 174 | setPic("") | ||
183 | 175 | if date == todayDate: | ||
184 | 176 | takeBut.set_label("Take today's photo") | ||
185 | 177 | takeBut.set_sensitive(True) | ||
186 | 178 | gaps = 0 | ||
187 | 179 | i = 0 | ||
188 | 180 | for element in self.db: | ||
189 | 181 | oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png" | ||
190 | 182 | if not os.path.exists(oldPath): | ||
191 | 183 | gaps += 1 | ||
192 | 184 | i += 1 | ||
193 | 185 | oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png" | ||
194 | 186 | if os.path.exists(oldPath): | ||
195 | 187 | key = getKey(self.db, oldPath) | ||
196 | 188 | newPath = os.path.expanduser('~/.photostory/photos/') + str(i-gaps) + ".png" | ||
197 | 189 | os.rename(oldPath, newPath) | ||
198 | 190 | self.db[key] = newPath | ||
199 | 191 | i += 1 | ||
200 | 192 | del self.db[date] | ||
201 | 193 | self.ind -= 1 | ||
202 | 194 | |||
203 | 195 | def setPic(date): | ||
204 | 196 | if self.pic != None: | ||
205 | 197 | vbox1.remove(self.pic) | ||
206 | 198 | vbox1.remove(hbox2) | ||
207 | 199 | if date in self.db: | ||
208 | 200 | self.pic = gtk.Image() | ||
209 | 201 | self.pic.set_from_file(self.db[date]) | ||
210 | 202 | takeBut.set_label("Photo taken for this day.") | ||
211 | 203 | takeBut.set_sensitive(False) | ||
212 | 204 | else: | ||
213 | 205 | if date == todayDate: | ||
214 | 206 | takeBut.set_label("Take today's photo") | ||
215 | 207 | takeBut.set_sensitive(True) | ||
216 | 208 | else: | ||
217 | 209 | takeBut.set_label("Take today's photo") | ||
218 | 210 | takeBut.set_sensitive(False) | ||
219 | 211 | self.pic = gtk.Label() | ||
220 | 212 | self.pic.set_justify(gtk.JUSTIFY_CENTER) | ||
221 | 213 | self.pic.set_markup("<span size='54000'>No Photo\nToday</span>"); | ||
222 | 214 | self.pic.set_size_request(640, 480) | ||
223 | 215 | vbox1.pack_start(self.pic) | ||
224 | 216 | vbox1.pack_start(hbox2) | ||
225 | 217 | vbox1.show_all() | ||
226 | 218 | |||
227 | 219 | #Interface | ||
228 | 220 | self.win = gtk.Window(gtk.WINDOW_TOPLEVEL) | ||
229 | 221 | self.win.connect("destroy", closedown) | ||
230 | 222 | self.win.set_default_size(900, 600) | ||
231 | 223 | self.win.set_resizable(False) | ||
232 | 224 | self.win.set_title("Photostory") | ||
233 | 225 | if os.path.exists("photostory.svg"): | ||
234 | 226 | self.win.set_icon_from_file("photostory.svg") | ||
235 | 227 | movie = gtk.DrawingArea() | ||
236 | 228 | movie.set_size_request(320, 240) | ||
237 | 229 | hbox = gtk.HBox(homogeneous=False, spacing=3) | ||
238 | 230 | vbox1 = gtk.VBox(homogeneous=False) | ||
239 | 231 | vbox2 = gtk.VBox(homogeneous = False) | ||
240 | 232 | filmBut = gtk.Button(label="Create Film") | ||
241 | 233 | filmBut.connect("clicked", movify) | ||
242 | 234 | deleteBut = gtk.Button(label="Delete Photo") | ||
243 | 235 | deleteBut.connect("clicked", deletePic) | ||
244 | 236 | shareBut = gtk.Button(label="Share Video") | ||
245 | 237 | hbox2 = gtk.HBox(homogeneous=True) | ||
246 | 238 | aboutBut = gtk.Button(label="About") | ||
247 | 239 | aboutBut.connect("clicked", about) | ||
248 | 240 | |||
249 | 241 | cal = gtk.Calendar() | ||
250 | 242 | todayDate = cal.get_date() | ||
251 | 243 | cal.connect("day-selected", chooseDay) | ||
252 | 244 | |||
253 | 245 | takeBut = gtk.Button(label="Take today's photo") | ||
254 | 246 | takeBut.connect("clicked", capture) | ||
255 | 247 | |||
256 | 248 | setPic(todayDate) | ||
257 | 249 | |||
258 | 250 | self.win.add(hbox) | ||
259 | 251 | hbox.pack_start(vbox1, expand=False) | ||
260 | 252 | hbox2.pack_start(filmBut, expand=False) | ||
261 | 253 | hbox2.pack_start(deleteBut, expand=False) | ||
262 | 254 | #hbox2.pack_start(shareBut) | ||
263 | 255 | hbox2.pack_start(aboutBut) | ||
264 | 256 | vbox2.pack_start(movie) | ||
265 | 257 | vbox2.pack_start(cal, expand=False, padding=25) | ||
266 | 258 | vbox2.pack_start(takeBut, expand=False) | ||
267 | 259 | hbox.pack_start(vbox2) | ||
268 | 260 | |||
269 | 261 | self.win.show_all() | ||
270 | 262 | |||
271 | 263 | #Pipeline stuff - feed | ||
272 | 264 | pipeline = gst.Pipeline("mypipeline") | ||
273 | 265 | |||
274 | 266 | camera = gst.element_factory_make("v4l2src", "camera") | ||
275 | 267 | camera.set_property("device", "/dev/video0") | ||
276 | 268 | |||
277 | 269 | caps = gst.Caps("video/x-raw-yuv,width=640,height=480,framerate=30/1") | ||
278 | 270 | filt = gst.element_factory_make("capsfilter", "filter") | ||
279 | 271 | filt.set_property("caps", caps) | ||
280 | 272 | |||
281 | 273 | xvimagesink = gst.element_factory_make("xvimagesink", "sink") | ||
282 | 274 | |||
283 | 275 | pipeline.add(camera, filt, xvimagesink) | ||
284 | 276 | gst.element_link_many(camera, filt, xvimagesink) | ||
285 | 277 | |||
416 | 278 | xvimagesink.set_xwindow_id(movie.window.xid) | 139 | xvimagesink.set_xwindow_id(movie.window.xid) |
417 | 279 | |||
418 | 280 | pipeline.set_state(gst.STATE_PLAYING) | 140 | pipeline.set_state(gst.STATE_PLAYING) |
421 | 281 | 141 | setPic(todayDate) | |
422 | 282 | start=Main() | 142 | ind += 1 |
423 | 143 | |||
424 | 144 | def countdown(n = 3): | ||
425 | 145 | self.pic.set_markup("<span size='54000'>" + str(n) + "</span>") | ||
426 | 146 | if n == 0: takePic() | ||
427 | 147 | else: glib.timeout_add(1000, countdown, n-1) | ||
428 | 148 | |||
429 | 149 | countdown() | ||
430 | 150 | |||
431 | 151 | def deletePic(deleteBut): | ||
432 | 152 | def getKey(dic, val): | ||
433 | 153 | return [k for k, v in dic.iteritems() if v == val][0] | ||
434 | 154 | date = cal.get_date() | ||
435 | 155 | if date in db: | ||
436 | 156 | os.remove(db[date]) | ||
437 | 157 | setPic("") | ||
438 | 158 | if date == todayDate: | ||
439 | 159 | takeBut.set_label("Take today's photo") | ||
440 | 160 | takeBut.set_sensitive(True) | ||
441 | 161 | gaps = 0 | ||
442 | 162 | i = 0 | ||
443 | 163 | for element in db: | ||
444 | 164 | oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png" | ||
445 | 165 | if not os.path.exists(oldPath): | ||
446 | 166 | gaps += 1 | ||
447 | 167 | i += 1 | ||
448 | 168 | oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png" | ||
449 | 169 | if os.path.exists(oldPath): | ||
450 | 170 | key = getKey(db, oldPath) | ||
451 | 171 | newPath = os.path.expanduser('~/.photostory/photos/') + str(i-gaps) + ".png" | ||
452 | 172 | os.rename(oldPath, newPath) | ||
453 | 173 | db[key] = newPath | ||
454 | 174 | i += 1 | ||
455 | 175 | del db[date] | ||
456 | 176 | ind -= 1 | ||
457 | 177 | |||
458 | 178 | def setPic(date): | ||
459 | 179 | global pic | ||
460 | 180 | if pic != None: | ||
461 | 181 | vbox1.remove(pic) | ||
462 | 182 | vbox1.remove(hbox2) | ||
463 | 183 | if date in db: | ||
464 | 184 | pic = gtk.Image() | ||
465 | 185 | pic.set_from_file(db[date]) | ||
466 | 186 | takeBut.set_label("Photo taken for this day.") | ||
467 | 187 | takeBut.set_sensitive(False) | ||
468 | 188 | else: | ||
469 | 189 | if date == todayDate: | ||
470 | 190 | takeBut.set_label("Take today's photo") | ||
471 | 191 | takeBut.set_sensitive(True) | ||
472 | 192 | else: | ||
473 | 193 | takeBut.set_label("Take today's photo") | ||
474 | 194 | takeBut.set_sensitive(False) | ||
475 | 195 | pic = gtk.Label() | ||
476 | 196 | pic.set_justify(gtk.JUSTIFY_CENTER) | ||
477 | 197 | pic.set_markup("<span size='54000'>No Photo\nToday</span>"); | ||
478 | 198 | pic.set_size_request(640, 480) | ||
479 | 199 | vbox1.pack_start(pic) | ||
480 | 200 | vbox1.pack_start(hbox2) | ||
481 | 201 | vbox1.show_all() | ||
482 | 202 | |||
483 | 203 | #Interface | ||
484 | 204 | self.win = gtk.Window(gtk.WINDOW_TOPLEVEL) | ||
485 | 205 | self.win.connect("destroy", closedown) | ||
486 | 206 | self.win.set_default_size(900, 600) | ||
487 | 207 | self.win.set_resizable(False) | ||
488 | 208 | self.win.set_title("Photostory") | ||
489 | 209 | if os.path.exists("photostory.svg"): | ||
490 | 210 | self.win.set_icon_from_file("photostory.svg") | ||
491 | 211 | movie = gtk.DrawingArea() | ||
492 | 212 | movie.set_size_request(320, 240) | ||
493 | 213 | hbox = gtk.HBox(homogeneous=False, spacing=3) | ||
494 | 214 | vbox1 = gtk.VBox(homogeneous=False) | ||
495 | 215 | vbox2 = gtk.VBox(homogeneous = False) | ||
496 | 216 | filmBut = gtk.Button(label="Create Film") | ||
497 | 217 | filmBut.connect("clicked", movify) | ||
498 | 218 | deleteBut = gtk.Button(label="Delete Photo") | ||
499 | 219 | deleteBut.connect("clicked", deletePic) | ||
500 | 220 | shareBut = gtk.Button(label="Share Video") | ||
501 | 221 | hbox2 = gtk.HBox(homogeneous=True) | ||
502 | 222 | aboutBut = gtk.Button(label="About") | ||
503 | 223 | aboutBut.connect("clicked", about) | ||
504 | 224 | |||
505 | 225 | cal = gtk.Calendar() | ||
506 | 226 | todayDate = cal.get_date() | ||
507 | 227 | cal.connect("day-selected", chooseDay) | ||
508 | 228 | |||
509 | 229 | takeBut = gtk.Button(label="Take today's photo") | ||
510 | 230 | takeBut.connect("clicked", capture) | ||
511 | 231 | |||
512 | 232 | setPic(todayDate) | ||
513 | 233 | |||
514 | 234 | self.win.add(hbox) | ||
515 | 235 | hbox.pack_start(vbox1, expand=False) | ||
516 | 236 | hbox2.pack_start(filmBut, expand=False) | ||
517 | 237 | hbox2.pack_start(deleteBut, expand=False) | ||
518 | 238 | #hbox2.pack_start(shareBut) | ||
519 | 239 | hbox2.pack_start(aboutBut) | ||
520 | 240 | vbox2.pack_start(movie) | ||
521 | 241 | vbox2.pack_start(cal, expand=False, padding=25) | ||
522 | 242 | vbox2.pack_start(takeBut, expand=False) | ||
523 | 243 | hbox.pack_start(vbox2) | ||
524 | 244 | |||
525 | 245 | self.win.show_all() | ||
526 | 246 | |||
527 | 247 | #Pipeline stuff - feed | ||
528 | 248 | pipeline = gst.Pipeline("mypipeline") | ||
529 | 249 | camera = gst.element_factory_make("v4l2src", "camera") | ||
530 | 250 | camera.set_property("device", "/dev/video0") | ||
531 | 251 | caps = gst.Caps("video/x-raw-yuv,width=640,height=480,framerate=30/1") | ||
532 | 252 | filt = gst.element_factory_make("capsfilter", "filter") | ||
533 | 253 | filt.set_property("caps", caps) | ||
534 | 254 | xvimagesink = gst.element_factory_make("xvimagesink", "sink") | ||
535 | 255 | pipeline.add(camera, filt, xvimagesink) | ||
536 | 256 | gst.element_link_many(camera, filt, xvimagesink) | ||
537 | 257 | xvimagesink.set_xwindow_id(movie.window.xid) | ||
538 | 258 | pipeline.set_state(gst.STATE_PLAYING) | ||
539 | 259 | |||
540 | 260 | # Start GTK | ||
541 | 283 | gtk.main() | 261 | gtk.main() |
Check this out for the latest version, will you Josh? I never got around to approving it so it's probably out of date. Apologies.