~photostory/photostory/cleanup

« back to all changes in this revision

Viewing changes to photostory

  • Committer: Josh Brown
  • Date: 2011-02-08 23:07:11 UTC
  • Revision ID: joshbrown15@gmail.com-20110208230711-rhkjs1qv0n6m36xy
General cleanup; remove Main() function and other changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
#Photostory 0.9
4
 
#by Joel Auterson (joel.auterson@googlemail.com)
5
 
#http://www.launchpad.net/photostory
 
3
# Photostory 0.95
 
4
# Joel Auterson (joel.auterson@googlemail.com)
 
5
# http://launchpad.net/photostory
6
6
 
7
 
import pygst
8
 
pygst.require("0.10")
9
 
import gst
10
 
import pygtk
11
 
import gtk
12
 
from time import strftime
13
 
import time
14
 
import os.path
15
 
import os
16
 
import cPickle
 
7
import time, os, cPickle, gtk, gst, glib
17
8
from threading import Timer
18
 
import glib
19
 
 
20
 
class Main:
21
 
 
22
 
    def __init__(self):
23
 
 
24
 
        pipeline = None
25
 
        xvimagesink = None
26
 
        movie = None
27
 
        self.movPath = None
28
 
        self.adj = gtk.Adjustment(5, 1, 10, 1)
29
 
        self.pic=None
30
 
 
31
 
        # If the `~/.photostory/photos` directory doesn't exist, create it:
32
 
        if not os.path.exists(os.path.expanduser('~/.photostory/photos')):
33
 
            os.makedirs(os.path.expanduser('~/.photostory/photos'))
34
 
 
35
 
        # If the `~/.photostory/db` pickle doesn't exist, create it:
36
 
        if not os.path.isfile(os.path.expanduser('~/.photostory/db')):
37
 
            cPickle.dump({}, open(os.path.expanduser('~/.photostory/db'), 'w'))
38
 
 
39
 
        # If the `~/.photostory/num` pickle doesn't exist, create it:
40
 
        if not os.path.isfile(os.path.expanduser('~/.photostory/num')):
41
 
            cPickle.dump(0, open(os.path.expanduser('~/.photostory/num'), 'w'))
42
 
 
43
 
        # Load the `db` and `num` pickles:
44
 
        self.db = cPickle.load(open(os.path.expanduser('~/.photostory/db'), 'rb'))
45
 
        self.ind = int(cPickle.load(open(os.path.expanduser('~/.photostory/num'), 'rb')))
46
 
 
47
 
        todayPicName = os.path.expanduser('~/.photostory/photos/') + str(self.ind) + ".png"
48
 
        todayDate = None
49
 
 
50
 
        def chooseDay(cal):
51
 
            dateTuple = cal.get_date()
52
 
            setPic(dateTuple)
53
 
 
54
 
        def closedown(win):
55
 
            print 'ind ' + str(self.ind)
56
 
            print 'db' + str(self.db)
57
 
            cPickle.dump(self.db, open(os.path.expanduser('~/.photostory/db'), 'wb'))
58
 
            cPickle.dump(self.ind, open(os.path.expanduser('~/.photostory/num'), 'wb'))
59
 
            gtk.main_quit()
60
 
 
61
 
        def about(aboutBut):
62
 
            dAbout = gtk.AboutDialog()
63
 
            dAbout.set_name("Photostory")
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.")
65
 
            dAbout.set_artists(("Josh Brown", ""))
66
 
            dAbout.set_authors(("Joel Auterson", "David Turner", "Josh Brown"))
67
 
            dAbout.set_website("http://launchpad.net/photostory")
68
 
            response = dAbout.run()
69
 
            if response == -6:
70
 
                dAbout.destroy()
71
 
 
72
 
        def movify(filmBut):
73
 
 
74
 
            def movPick(movFileButton):
75
 
                movPicker = gtk.FileChooserDialog(title="Choose a save location", parent=movDia, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(("Save Here", -6)), backend=None)
76
 
                movRes = movPicker.run()
77
 
                if movRes == -6:
78
 
                    self.movPath = movPicker.get_filename()
79
 
                    movPicker.destroy()
80
 
 
81
 
            def movGen(movButton):
82
 
 
83
 
                movDia.destroy()
84
 
 
85
 
                filmPipe = gst.Pipeline("filmPipe")
86
 
                filmSrc = gst.element_factory_make("multifilesrc", "filmSrc")
87
 
                filmSrc.set_property("location", os.path.expanduser("~/.photostory/photos/") + "%d.png")
88
 
                filmFilt1 = gst.element_factory_make("capsfilter", "filmFilt1")
89
 
                filmCap1 = gst.Caps("image/png,framerate=" + str(int(self.adj.get_value())) + "/1,pixel-aspect-ratio=1/1")
90
 
                filmFilt1.set_property("caps", filmCap1)
91
 
                filmPngDec = gst.element_factory_make("pngdec", "filmPngDec")
92
 
                filmff = gst.element_factory_make("ffmpegcolorspace", "filmff")
93
 
                filmFilt2 = gst.element_factory_make("capsfilter", "filmFilt2")
94
 
                filmCap2 = gst.Caps("video/x-raw-yuv")
95
 
                filmFilt2.set_property("caps", filmCap2)
96
 
                filmTheora = gst.element_factory_make("xvidenc", "filmTheora")
97
 
                filmOggmux = gst.element_factory_make("ffmux_mp4", "filmOggmux")
98
 
                filmFilesink = gst.element_factory_make("filesink", "filmFilesink")
99
 
                filmFilesink.set_property("location", self.movPath)
100
 
 
101
 
                filmPipe.add(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
102
 
                gst.element_link_many(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
103
 
                filmPipe.set_state(gst.STATE_PLAYING)
104
 
                time.sleep(5)
105
 
                filmBut.set_sensitive(True)
106
 
 
107
 
            movDia = gtk.Window(gtk.WINDOW_TOPLEVEL)
108
 
            movDia.set_title("Create Film")
109
 
            movDia.set_resizable(False)
110
 
            filmBut.set_sensitive(False)
111
 
            movVbox = gtk.VBox(homogeneous=False, spacing=2)
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")
113
 
            movFileButton = gtk.Button(label="Choose a location")
114
 
            movButton = gtk.Button(label="Create")
115
 
 
116
 
            #FPS Slider
117
 
            movSliderBox = gtk.HBox(homogeneous=False, spacing=3)
118
 
            movSliderLabel = gtk.Label("FPS:")
119
 
            movSlider = gtk.HScale(self.adj)
120
 
            movSlider.set_digits(0)
121
 
            movSliderBox.pack_start(movSliderLabel, expand=False)
122
 
            movSliderBox.pack_start(movSlider, expand=True)
123
 
 
124
 
            movDia.add(movVbox)
125
 
            movVbox.pack_start(movLabel, expand=False)
126
 
            movVbox.pack_start(movSliderBox, expand=False)
127
 
            movVbox.pack_start(movFileButton, expand=False)
128
 
            movVbox.pack_start(movButton, expand=False)
129
 
            movButton.connect("clicked", movGen)
130
 
            movFileButton.connect("clicked", movPick)
131
 
            movDia.show_all()
132
 
 
133
 
        def capture(takeBut):
134
 
 
135
 
            def takePic():
136
 
                pipeline.set_state(gst.STATE_NULL)
137
 
                stillPipe = gst.Pipeline("stillPipe")
138
 
                stillCam = gst.element_factory_make("v4l2src", "stillPipe")
139
 
                stillFilt = gst.element_factory_make("capsfilter", "stillFilt")
140
 
                stillCap = gst.Caps("video/x-raw-yuv,width=640,height=480")
141
 
                stillFilt.set_property("caps", stillCap)
142
 
                ffmpegcolorspace = gst.element_factory_make("ffmpegcolorspace", "ffmpegcolorspace")
143
 
                pngEnc = gst.element_factory_make("pngenc", "pngenc")
144
 
                filesink = gst.element_factory_make("filesink", "filesink")
145
 
                filesink.set_property("location", todayPicName)
146
 
                self.db[todayDate] = todayPicName
147
 
                cal.freeze()
148
 
                cal.select_month(todayDate[1], todayDate[0])
149
 
                cal.select_day(todayDate[2])
150
 
                cal.thaw()
151
 
                stillPipe.add(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink)
152
 
                gst.element_link_many(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink)
153
 
                stillPipe.set_state(gst.STATE_PLAYING)
154
 
                time.sleep(1)
155
 
                stillPipe.set_state(gst.STATE_NULL)
156
 
                xvimagesink.set_xwindow_id(movie.window.xid)
157
 
                pipeline.set_state(gst.STATE_PLAYING)
158
 
                setPic(todayDate)
159
 
                self.ind += 1
160
 
 
161
 
            def countdown(n = 3):
162
 
                self.pic.set_markup("<span size='54000'>" + str(n) + "</span>")
163
 
                if n == 0: takePic()
164
 
                else: glib.timeout_add(1000, countdown, n-1)
165
 
 
166
 
            countdown()
167
 
 
168
 
        def deletePic(deleteBut):
169
 
            def getKey(dic, val):
170
 
                return [k for k, v in dic.iteritems() if v == val][0]
171
 
            date = cal.get_date()
172
 
            if date in self.db:
173
 
                os.remove(self.db[date])
174
 
                setPic("")
175
 
                if date == todayDate:
176
 
                    takeBut.set_label("Take today's photo")
177
 
                    takeBut.set_sensitive(True)
178
 
                gaps = 0
179
 
                i = 0
180
 
                for element in self.db:
181
 
                    oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
182
 
                    if not os.path.exists(oldPath):
183
 
                        gaps += 1
184
 
                        i += 1
185
 
                    oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
186
 
                    if os.path.exists(oldPath):
187
 
                        key = getKey(self.db, oldPath)
188
 
                        newPath = os.path.expanduser('~/.photostory/photos/') + str(i-gaps) + ".png"
189
 
                        os.rename(oldPath, newPath)
190
 
                        self.db[key] = newPath
191
 
                    i += 1
192
 
                del self.db[date]
193
 
                self.ind -= 1
194
 
 
195
 
        def setPic(date):
196
 
            if self.pic != None:
197
 
                vbox1.remove(self.pic)
198
 
                vbox1.remove(hbox2)
199
 
            if date in self.db:
200
 
                self.pic = gtk.Image()
201
 
                self.pic.set_from_file(self.db[date])
202
 
                takeBut.set_label("Photo taken for this day.")
203
 
                takeBut.set_sensitive(False)
204
 
            else: 
205
 
                if date == todayDate:
206
 
                    takeBut.set_label("Take today's photo")
207
 
                    takeBut.set_sensitive(True)
208
 
                else:
209
 
                    takeBut.set_label("Take today's photo")
210
 
                    takeBut.set_sensitive(False)
211
 
                self.pic = gtk.Label()
212
 
                self.pic.set_justify(gtk.JUSTIFY_CENTER)
213
 
                self.pic.set_markup("<span size='54000'>No Photo\nToday</span>");
214
 
                self.pic.set_size_request(640, 480)
215
 
            vbox1.pack_start(self.pic)
216
 
            vbox1.pack_start(hbox2)
217
 
            vbox1.show_all()
218
 
 
219
 
        #Interface
220
 
        self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
221
 
        self.win.connect("destroy", closedown)
222
 
        self.win.set_default_size(900, 600)
223
 
        self.win.set_resizable(False)
224
 
        self.win.set_title("Photostory")
225
 
        if os.path.exists("photostory.svg"):
226
 
            self.win.set_icon_from_file("photostory.svg")
227
 
        movie = gtk.DrawingArea()
228
 
        movie.set_size_request(320, 240)
229
 
        hbox = gtk.HBox(homogeneous=False, spacing=3)
230
 
        vbox1 = gtk.VBox(homogeneous=False)
231
 
        vbox2 = gtk.VBox(homogeneous = False)   
232
 
        filmBut = gtk.Button(label="Create Film")
233
 
        filmBut.connect("clicked", movify)
234
 
        deleteBut = gtk.Button(label="Delete Photo")
235
 
        deleteBut.connect("clicked", deletePic)
236
 
        shareBut = gtk.Button(label="Share Video")
237
 
        hbox2 = gtk.HBox(homogeneous=True)
238
 
        aboutBut = gtk.Button(label="About")
239
 
        aboutBut.connect("clicked", about)
240
 
 
241
 
        cal = gtk.Calendar()
242
 
        todayDate = cal.get_date()
243
 
        cal.connect("day-selected", chooseDay)
244
 
 
245
 
        takeBut = gtk.Button(label="Take today's photo")
246
 
        takeBut.connect("clicked", capture)
247
 
 
248
 
        setPic(todayDate)
249
 
 
250
 
        self.win.add(hbox)
251
 
        hbox.pack_start(vbox1, expand=False)
252
 
        hbox2.pack_start(filmBut, expand=False)
253
 
        hbox2.pack_start(deleteBut, expand=False)
254
 
        #hbox2.pack_start(shareBut)
255
 
        hbox2.pack_start(aboutBut)
256
 
        vbox2.pack_start(movie)
257
 
        vbox2.pack_start(cal, expand=False, padding=25)
258
 
        vbox2.pack_start(takeBut, expand=False)
259
 
        hbox.pack_start(vbox2)
260
 
 
261
 
        self.win.show_all()
262
 
 
263
 
        #Pipeline stuff - feed
264
 
        pipeline = gst.Pipeline("mypipeline")
265
 
 
266
 
        camera = gst.element_factory_make("v4l2src", "camera")
267
 
        camera.set_property("device", "/dev/video0")
268
 
 
269
 
        caps = gst.Caps("video/x-raw-yuv,width=640,height=480,framerate=30/1")
270
 
        filt = gst.element_factory_make("capsfilter", "filter")
271
 
        filt.set_property("caps", caps)
272
 
 
273
 
        xvimagesink = gst.element_factory_make("xvimagesink", "sink")
274
 
 
275
 
        pipeline.add(camera, filt, xvimagesink)
276
 
        gst.element_link_many(camera, filt, xvimagesink)
277
 
 
 
9
 
 
10
pipeline = None
 
11
xvimagesink = None
 
12
movie = None
 
13
movPath = None
 
14
adj = gtk.Adjustment(5, 1, 10, 1)
 
15
pic = None
 
16
 
 
17
# If the `~/.photostory/photos` directory doesn't exist, create it:
 
18
if not os.path.exists(os.path.expanduser('~/.photostory/photos')):
 
19
    os.makedirs(os.path.expanduser('~/.photostory/photos'))
 
20
 
 
21
# If the `~/.photostory/db` pickle doesn't exist, create it:
 
22
if not os.path.isfile(os.path.expanduser('~/.photostory/db')):
 
23
    cPickle.dump({}, open(os.path.expanduser('~/.photostory/db'), 'w'))
 
24
 
 
25
# If the `~/.photostory/num` pickle doesn't exist, create it:
 
26
if not os.path.isfile(os.path.expanduser('~/.photostory/num')):
 
27
    cPickle.dump(0, open(os.path.expanduser('~/.photostory/num'), 'w'))
 
28
 
 
29
# Load the `db` and `num` pickles:
 
30
db = cPickle.load(open(os.path.expanduser('~/.photostory/db'), 'rb'))
 
31
ind = int(cPickle.load(open(os.path.expanduser('~/.photostory/num'), 'rb')))
 
32
 
 
33
todayPicName = os.path.expanduser('~/.photostory/photos/') + str(self.ind) + ".png"
 
34
todayDate = None
 
35
 
 
36
def chooseDay(cal):
 
37
    dateTuple = cal.get_date()
 
38
    setPic(dateTuple)
 
39
 
 
40
def closedown(win):
 
41
    print 'ind ' + str(ind)
 
42
    print 'db' + str(db)
 
43
    cPickle.dump(db, open(os.path.expanduser('~/.photostory/db'), 'wb'))
 
44
    cPickle.dump(ind, open(os.path.expanduser('~/.photostory/num'), 'wb'))
 
45
    gtk.main_quit()
 
46
 
 
47
def about(aboutBut):
 
48
    dAbout = gtk.AboutDialog()
 
49
    dAbout.set_name("Photostory")
 
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.")
 
51
    dAbout.set_artists(("Josh Brown"))
 
52
    dAbout.set_authors(("Joel Auterson", "David Turner", "Josh Brown"))
 
53
    dAbout.set_website("http://launchpad.net/photostory")
 
54
    response = dAbout.run()
 
55
    if response == -6:
 
56
        dAbout.destroy()
 
57
 
 
58
def movify(filmBut):
 
59
    def movPick(movFileButton):
 
60
        movPicker = gtk.FileChooserDialog(title="Choose a save location", parent=movDia, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(("Save Here", -6)), backend=None)
 
61
        movRes = movPicker.run()
 
62
        if movRes == -6:
 
63
            movPath = movPicker.get_filename()
 
64
            movPicker.destroy()
 
65
 
 
66
    def movGen(movButton):
 
67
        movDia.destroy()
 
68
 
 
69
        filmPipe = gst.Pipeline("filmPipe")
 
70
        filmSrc = gst.element_factory_make("multifilesrc", "filmSrc")
 
71
        filmSrc.set_property("location", os.path.expanduser("~/.photostory/photos/") + "%d.png")
 
72
        filmFilt1 = gst.element_factory_make("capsfilter", "filmFilt1")
 
73
        filmCap1 = gst.Caps("image/png,framerate=" + str(int(self.adj.get_value())) + "/1,pixel-aspect-ratio=1/1")
 
74
        filmFilt1.set_property("caps", filmCap1)
 
75
        filmPngDec = gst.element_factory_make("pngdec", "filmPngDec")
 
76
        filmff = gst.element_factory_make("ffmpegcolorspace", "filmff")
 
77
        filmFilt2 = gst.element_factory_make("capsfilter", "filmFilt2")
 
78
        filmCap2 = gst.Caps("video/x-raw-yuv")
 
79
        filmFilt2.set_property("caps", filmCap2)
 
80
        filmTheora = gst.element_factory_make("xvidenc", "filmTheora")
 
81
        filmOggmux = gst.element_factory_make("ffmux_mp4", "filmOggmux")
 
82
        filmFilesink = gst.element_factory_make("filesink", "filmFilesink")
 
83
        filmFilesink.set_property("location", movPath)
 
84
 
 
85
        filmPipe.add(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
 
86
        gst.element_link_many(filmSrc, filmFilt1, filmPngDec, filmff, filmFilt2, filmTheora, filmOggmux, filmFilesink)
 
87
        filmPipe.set_state(gst.STATE_PLAYING)
 
88
        time.sleep(5)
 
89
        filmBut.set_sensitive(True)
 
90
 
 
91
    movDia = gtk.Window(gtk.WINDOW_TOPLEVEL)
 
92
    movDia.set_title("Create Film")
 
93
    movDia.set_resizable(False)
 
94
    filmBut.set_sensitive(False)
 
95
    movVbox = gtk.VBox(homogeneous=False, spacing=2)
 
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")
 
97
    movFileButton = gtk.Button(label="Choose a location")
 
98
    movButton = gtk.Button(label="Create")
 
99
 
 
100
    #FPS Slider
 
101
    movSliderBox = gtk.HBox(homogeneous=False, spacing=3)
 
102
    movSliderLabel = gtk.Label("FPS:")
 
103
    movSlider = gtk.HScale(adj)
 
104
    movSlider.set_digits(0)
 
105
    movSliderBox.pack_start(movSliderLabel, expand=False)
 
106
    movSliderBox.pack_start(movSlider, expand=True)
 
107
 
 
108
    movDia.add(movVbox)
 
109
    movVbox.pack_start(movLabel, expand=False)
 
110
    movVbox.pack_start(movSliderBox, expand=False)
 
111
    movVbox.pack_start(movFileButton, expand=False)
 
112
    movVbox.pack_start(movButton, expand=False)
 
113
    movButton.connect("clicked", movGen)
 
114
    movFileButton.connect("clicked", movPick)
 
115
    movDia.show_all()
 
116
 
 
117
def capture(takeBut):
 
118
    def takePic():
 
119
        pipeline.set_state(gst.STATE_NULL)
 
120
        stillPipe = gst.Pipeline("stillPipe")
 
121
        stillCam = gst.element_factory_make("v4l2src", "stillPipe")
 
122
        stillFilt = gst.element_factory_make("capsfilter", "stillFilt")
 
123
        stillCap = gst.Caps("video/x-raw-yuv,width=640,height=480")
 
124
        stillFilt.set_property("caps", stillCap)
 
125
        ffmpegcolorspace = gst.element_factory_make("ffmpegcolorspace", "ffmpegcolorspace")
 
126
        pngEnc = gst.element_factory_make("pngenc", "pngenc")
 
127
        filesink = gst.element_factory_make("filesink", "filesink")
 
128
        filesink.set_property("location", todayPicName)
 
129
        db[todayDate] = todayPicName
 
130
        cal.freeze()
 
131
        cal.select_month(todayDate[1], todayDate[0])
 
132
        cal.select_day(todayDate[2])
 
133
        cal.thaw()
 
134
        stillPipe.add(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink)
 
135
        gst.element_link_many(stillCam, stillFilt, ffmpegcolorspace, pngEnc, filesink)
 
136
        stillPipe.set_state(gst.STATE_PLAYING)
 
137
        time.sleep(1)
 
138
        stillPipe.set_state(gst.STATE_NULL)
278
139
        xvimagesink.set_xwindow_id(movie.window.xid)
279
 
 
280
140
        pipeline.set_state(gst.STATE_PLAYING)
281
 
 
282
 
start=Main()
 
141
        setPic(todayDate)
 
142
        ind += 1
 
143
 
 
144
    def countdown(n = 3):
 
145
        self.pic.set_markup("<span size='54000'>" + str(n) + "</span>")
 
146
        if n == 0: takePic()
 
147
        else: glib.timeout_add(1000, countdown, n-1)
 
148
 
 
149
    countdown()
 
150
 
 
151
def deletePic(deleteBut):
 
152
    def getKey(dic, val):
 
153
        return [k for k, v in dic.iteritems() if v == val][0]
 
154
    date = cal.get_date()
 
155
    if date in db:
 
156
        os.remove(db[date])
 
157
        setPic("")
 
158
        if date == todayDate:
 
159
            takeBut.set_label("Take today's photo")
 
160
            takeBut.set_sensitive(True)
 
161
        gaps = 0
 
162
        i = 0
 
163
        for element in db:
 
164
            oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
 
165
            if not os.path.exists(oldPath):
 
166
                gaps += 1
 
167
                i += 1
 
168
            oldPath = os.path.expanduser('~/.photostory/photos/') + str(i) + ".png"
 
169
            if os.path.exists(oldPath):
 
170
                key = getKey(db, oldPath)
 
171
                newPath = os.path.expanduser('~/.photostory/photos/') + str(i-gaps) + ".png"
 
172
                os.rename(oldPath, newPath)
 
173
                db[key] = newPath
 
174
            i += 1
 
175
        del db[date]
 
176
        ind -= 1
 
177
 
 
178
def setPic(date):
 
179
    global pic
 
180
    if pic != None:
 
181
        vbox1.remove(pic)
 
182
        vbox1.remove(hbox2)
 
183
    if date in db:
 
184
        pic = gtk.Image()
 
185
        pic.set_from_file(db[date])
 
186
        takeBut.set_label("Photo taken for this day.")
 
187
        takeBut.set_sensitive(False)
 
188
    else: 
 
189
        if date == todayDate:
 
190
            takeBut.set_label("Take today's photo")
 
191
            takeBut.set_sensitive(True)
 
192
        else:
 
193
            takeBut.set_label("Take today's photo")
 
194
            takeBut.set_sensitive(False)
 
195
        pic = gtk.Label()
 
196
        pic.set_justify(gtk.JUSTIFY_CENTER)
 
197
        pic.set_markup("<span size='54000'>No Photo\nToday</span>");
 
198
        pic.set_size_request(640, 480)
 
199
    vbox1.pack_start(pic)
 
200
    vbox1.pack_start(hbox2)
 
201
    vbox1.show_all()
 
202
 
 
203
#Interface
 
204
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
 
205
self.win.connect("destroy", closedown)
 
206
self.win.set_default_size(900, 600)
 
207
self.win.set_resizable(False)
 
208
self.win.set_title("Photostory")
 
209
if os.path.exists("photostory.svg"):
 
210
    self.win.set_icon_from_file("photostory.svg")
 
211
movie = gtk.DrawingArea()
 
212
movie.set_size_request(320, 240)
 
213
hbox = gtk.HBox(homogeneous=False, spacing=3)
 
214
vbox1 = gtk.VBox(homogeneous=False)
 
215
vbox2 = gtk.VBox(homogeneous = False)   
 
216
filmBut = gtk.Button(label="Create Film")
 
217
filmBut.connect("clicked", movify)
 
218
deleteBut = gtk.Button(label="Delete Photo")
 
219
deleteBut.connect("clicked", deletePic)
 
220
shareBut = gtk.Button(label="Share Video")
 
221
hbox2 = gtk.HBox(homogeneous=True)
 
222
aboutBut = gtk.Button(label="About")
 
223
aboutBut.connect("clicked", about)
 
224
 
 
225
cal = gtk.Calendar()
 
226
todayDate = cal.get_date()
 
227
cal.connect("day-selected", chooseDay)
 
228
 
 
229
takeBut = gtk.Button(label="Take today's photo")
 
230
takeBut.connect("clicked", capture)
 
231
 
 
232
setPic(todayDate)
 
233
 
 
234
self.win.add(hbox)
 
235
hbox.pack_start(vbox1, expand=False)
 
236
hbox2.pack_start(filmBut, expand=False)
 
237
hbox2.pack_start(deleteBut, expand=False)
 
238
#hbox2.pack_start(shareBut)
 
239
hbox2.pack_start(aboutBut)
 
240
vbox2.pack_start(movie)
 
241
vbox2.pack_start(cal, expand=False, padding=25)
 
242
vbox2.pack_start(takeBut, expand=False)
 
243
hbox.pack_start(vbox2)
 
244
 
 
245
self.win.show_all()
 
246
 
 
247
#Pipeline stuff - feed
 
248
pipeline = gst.Pipeline("mypipeline")
 
249
camera = gst.element_factory_make("v4l2src", "camera")
 
250
camera.set_property("device", "/dev/video0")
 
251
caps = gst.Caps("video/x-raw-yuv,width=640,height=480,framerate=30/1")
 
252
filt = gst.element_factory_make("capsfilter", "filter")
 
253
filt.set_property("caps", caps)
 
254
xvimagesink = gst.element_factory_make("xvimagesink", "sink")
 
255
pipeline.add(camera, filt, xvimagesink)
 
256
gst.element_link_many(camera, filt, xvimagesink)
 
257
xvimagesink.set_xwindow_id(movie.window.xid)
 
258
pipeline.set_state(gst.STATE_PLAYING)
 
259
 
 
260
# Start GTK
283
261
gtk.main()