~alex-k-1/pictoric/pictoric

« back to all changes in this revision

Viewing changes to pictoric/PictoricInit.py

  • Committer: Alexander Kendrick
  • Date: 2012-07-14 21:05:42 UTC
  • mfrom: (0.1.5 pictoric)
  • Revision ID: alex_k@cybermesa.com-20120714210542-elqukpdjqv7k59xb
Merged with app-review revisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
### BEGIN LICENSE
 
2
# Copyright (C) 2012 Cole Kendrick colej.kendrick@gmail.com Alexander Kendrick kentalex8@gmail.com
 
3
# This program is free software: you can redistribute it and/or modify it 
 
4
# under the terms of the GNU General Public License version 3, as published 
 
5
# by the Free Software Foundation.
 
6
 
7
# This program is distributed in the hope that it will be useful, but 
 
8
# WITHOUT ANY WARRANTY; without even the implied warranties of 
 
9
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
10
# PURPOSE.  See the GNU General Public License for more details.
 
11
 
12
# You should have received a copy of the GNU General Public License along 
 
13
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
14
### END LICENSE
 
15
 
 
16
from gi.repository import Gtk, Gio, Gdk
 
17
from gi.repository.GdkPixbuf import Pixbuf
 
18
import os
 
19
 
 
20
def InitDisplay(self,builder, sourceFolder,sourceInterval):
 
21
    files = 0
 
22
    files_jpg = 0
 
23
    files_png = 0
 
24
    self.builder.get_object("folderChooser").set_current_folder(sourceFolder)
 
25
    self.builder.get_object("intervalEdit").set_value(int(sourceInterval))
 
26
    iconStore = Gtk.ListStore(Pixbuf)
 
27
    iconview = self.builder.get_object("displayView")
 
28
    iconview.set_columns(-1)
 
29
    iconview.set_model(iconStore)
 
30
    iconview.set_pixbuf_column(0)
 
31
    Status = self.builder.get_object("status")
 
32
 
 
33
    #ensure the directory exists before continuing.
 
34
    if os.path.exists(sourceFolder):
 
35
        print "Directory "+sourceFolder+" is valid"
 
36
    else:
 
37
        # maybe do a dialog here?
 
38
        try:
 
39
            print "Could not find directory "+sourceFolder+" attempting to create it."
 
40
            os.makedirs(sourceFolder)
 
41
            print "Directory created at "+sourceFolder
 
42
        except OSError:
 
43
            print "Could not create directory at "+sourceFolder
 
44
            
 
45
    for name in os.listdir(sourceFolder):
 
46
        filename = os.path.join(sourceFolder, name)
 
47
        if name.endswith(".jpg") or name.endswith(".png") or name.endswith(".jpeg"):
 
48
            if name.endswith(".jpg") or name.endswith(".jpeg"):
 
49
                files_jpg = files_jpg + 1
 
50
            if name.endswith(".png"):
 
51
                files_png = files_png + 1
 
52
            files = files + 1 
 
53
            pixbuf = Pixbuf.new_from_file_at_size(filename,96,96)
 
54
            iconStore.append([pixbuf])
 
55
        else:
 
56
            print ("%s not a image file!" % (filename))
 
57
            
 
58
 
 
59
    if files == 0:
 
60
        Status.push(1,"No images found in %s" % (sourceFolder))
 
61
    else:
 
62
        Status.push(1,"%s images found (%s .jpg, %s .png)" % (files, files_jpg, files_png))
 
63
    print "+++++++"
 
64
    
 
65
    return