1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 Cole Kendrick colej.kendrick@gmail.com Alexander Kendrick kentalex8@gmail.com
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
import locale, os, time
19
from gi.repository import Gtk, Gio, Gdk # pylint: disable=E0611
20
from gi.repository.GdkPixbuf import Pixbuf
22
logger = logging.getLogger('pictoric')
24
TEXTDOMAIN = 'pictoric'
25
LOCALEDIR = '/opt/extras.ubuntu.com/pictoric/share/locale'
26
from locale import gettext as _
27
locale.bindtextdomain(TEXTDOMAIN, LOCALEDIR)
28
locale.textdomain(TEXTDOMAIN)
30
from pictoric_lib import Window
32
class PictoricWindow(Window):
33
__gtype_name__ = "PictoricWindow"
34
SCHEMA = 'org.gnome.desktop.background'
37
defaultDirectory = '/home/%s/Pictures' % (os.environ['USER'])
38
defaultInterval = minute*5
39
sourceFolder = defaultDirectory
40
iconStore = Gtk.ListStore(Pixbuf)
42
def finish_initializing(self, builder, sourceFolder=defaultDirectory, sourceInterval=defaultInterval, configPath ='/home/%s/.config/pictoric/pictoric.conf' % (os.environ['USER']), minute=60): # pylint: disable=E1002
43
"""Set up the main window"""
44
# self.set_default_size(400,500)
45
autofile = '/home/%s/.config/autostart/pictoric.desktop' % (os.environ['USER'])
46
confdir = '/home/%s/.config/pictoric/' % (os.environ['USER'])
47
runfile = '/home/%s/.config/pictoric/run_pictoric.sh' % (os.environ['USER'])
48
if os.path.exists(confdir):
49
if os.path.isfile(autofile) == False:
50
print "Writing '%s'" % (autofile)
51
autofile = open("%s" % (autofile), 'w')
52
autofile.write("[Desktop Entry]\n")
53
autofile.write("Type=Application\n")
54
autofile.write("Exec=/home/alex/.config/pictoric/run_pictoric.sh\n")
55
autofile.write("Hidden=false\n")
56
autofile.write("NoDisplay=false\n")
57
autofile.write("X-GNOME-Autostart-enabled=true\n")
58
autofile.write("Name[en_US]=Pictoric\n")
59
autofile.write("Name=Pictoric\n")
60
autofile.write("Comment[en_US]=Start Wallpaper Slideshow\n")
61
autofile.write("Comment=Start Wallpaper Slideshow\n")
63
if os.path.isfile(runfile) == False:
64
print "Writing '%s'" % (runfile)
65
runfile = open("%s" % (runfile), 'w')
66
runfile.write("#!/bin/bash\n")
67
runfile.write("python /opt/extras.ubuntu.com/pictoric/pictoric/PictoricBg.py")
69
if os.path.isfile(configPath) == False: #Tests if config file already exists
70
print "Writing '%s'" % (configPath)
71
config = open("%s" % (configPath), 'w')
72
config.write("%s\n" % (sourceFolder))
73
config.write("%s\n" % (sourceInterval))
75
if os.path.isfile(configPath) == True: #If exists, open for reading and future writing
76
config = open("%s" % (configPath), 'r')
77
sourceFolder = config.readline()
78
sourceInterval = config.readline()
82
print "Writing '%s'" % (configPath)
83
config = open("%s" % (configPath), 'w')
84
config.write("%s\n" % (sourceFolder))
85
config.write("%s\n" % (sourceInterval))
87
print "Writing '%s'" % (runfile)
88
runfile = open("%s" % (runfile), 'w')
89
runfile.write("#!/bin/bash\n")
90
runfile.write("python /opt/extras.ubuntu.com/pictoric/pictoric/PictoricBg.py")
92
if os.path.isfile(autofile) == False:
93
print "Writing '%s'" % (autofile)
94
autofile = open("%s" % (autofile), 'w')
95
autofile.write("[Desktop Entry]\n")
96
autofile.write("Type=Application\n")
97
autofile.write("Exec=/home/alex/.config/pictoric/run_pictoric.sh\n")
98
autofile.write("Hidden=false\n")
99
autofile.write("NoDisplay=false\n")
100
autofile.write("X-GNOME-Autostart-enabled=true\n")
101
autofile.write("Name[en_US]=Pictoric\n")
102
autofile.write("Name=Pictoric\n")
103
autofile.write("Comment[en_US]=Start Wallpaper Slideshow\n")
104
autofile.write("Comment=Start Wallpaper Slideshow\n")
107
super(PictoricWindow, self).finish_initializing(builder)
109
def changer(self,dir_path,sourceInterval=defaultInterval, minute=60):
110
print "Starting wallpaper slideshow with folder->'%s' and interval->%s" % (dir_path,sourceInterval)
111
gsettings = Gio.Settings.new(self.SCHEMA)
112
for name in os.listdir(dir_path):
113
background = (os.path.join(dir_path, name))
114
if name.endswith(".jpg") or name.endswith(".png") or name.endswith(".jpeg"):
115
gsettings.set_string(self.KEY, "file://" + background)
116
time.sleep(float(sourceInterval)*minute)
117
print "Set new background '%s' in %s minute(s)!" % (background, sourceInterval)
119
print "Warning: Tried setting background, but '%s' is not a image file!" % (background)
122
def button_apply(self, builder, sourceFolder=defaultDirectory,sourceInterval=defaultInterval, configPath ='/home/%s/.config/pictoric/pictoric.conf' % (os.environ['USER'])):
123
print "Saving '%s'" % (configPath)
124
sourceFolder = self.builder.get_object("folderChooser").get_filename()
125
sourceInterval = self.builder.get_object("intervalEdit").get_text()
126
if sourceInterval == '0':
128
config = open("%s" % (configPath), 'w')
129
config.write("%s\n" % (sourceFolder))
130
config.write("%s\n" % (sourceInterval))
134
def button_cancel(self, builder):
138
def update_folder(self, builder,sourceFolder=sourceFolder,iconStore=iconStore):
143
sourceFolder = self.builder.get_object("folderChooser").get_filename()
144
iconview = self.builder.get_object("displayView")
145
iconview.set_columns(-1)
146
iconview.set_model(iconStore)
147
iconview.set_pixbuf_column(0)
148
iconview.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
150
Status = self.builder.get_object("status")
151
#sourceFolder = "/home/cole/testme_dir2"
154
if os.path.exists(sourceFolder):
155
print "Directory "+sourceFolder+" is valid"
157
# maybe do a dialog here?
159
print "Could not find directory "+sourceFolder+" attempting to create it."
160
os.makedirs(sourceFolder)
161
print "Directory created at "+sourceFolder
163
print "Could not create directory at "+sourceFolder
166
for name in os.listdir(sourceFolder):
167
filename = os.path.join(sourceFolder, name)
168
if name.endswith(".jpg") or name.endswith(".png") or name.endswith(".jpeg"):
169
if name.endswith(".jpg") or name.endswith(".jpeg"):
170
files_jpg = files_jpg + 1
171
if name.endswith(".png"):
172
files_png = files_png + 1
174
pixbuf = Pixbuf.new_from_file_at_size(filename,96,96)
175
iconStore.append([pixbuf])
177
print "Warning: '%s' is not a image file!" % (filename)
179
Status.push(1,"No images found in %s" % (sourceFolder))
181
Status.push(1,"%s images found (%s .jpg, %s .png)" % (files, files_jpg, files_png))
186
def change_interval(self, builder):