~doctormo/gnome-wallchanger/trunk

« back to all changes in this revision

Viewing changes to gwc/plugins/folder.py

  • Committer: Martin Owens (DoctorMO)
  • Date: 2009-10-11 19:32:33 UTC
  • Revision ID: doctormo@gmail.com-20091011193233-15p70kim7zsjyhqx
Add new modules for ver 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2009, Martin Owens.
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation, either version 3 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
"""
 
18
List images in a single directory.
 
19
"""
 
20
 
 
21
from gwc.base import ListerBase, add_lister
 
22
 
 
23
class folderLister(ListerBase):
 
24
    """Pick a wallpaper out of a folder at random"""
 
25
    lid        = 'folder'
 
26
    name       = 'Local Folder'
 
27
    icon       = 'gtk-directory'
 
28
    variables  = [ 'localfolder' ]
 
29
 
 
30
    def __init__(self, dir):
 
31
        lister.__init__(self, dir)
 
32
 
 
33
    def getList(self):
 
34
        if os.path.exists(self._dir):
 
35
            for item in self.imgList(self._dir):
 
36
                yield item
 
37
 
 
38
    def imgList(self, dir):
 
39
        for f in os.listdir(dir):
 
40
            path = os.path.join(dir, f)
 
41
            if os.path.isfile(path) and os.access(path,os.R_OK):
 
42
                fh = open(path, "rb")
 
43
                if imghdr.what(fh):
 
44
                    yield path
 
45
                fh.close()
 
46
            elif os.path.isdir(path) and config['recursive']=='True':
 
47
                for item in self.imgList(path):
 
48
                    yield item
 
49
 
 
50
    def widgets(self, config):
 
51
        """Return a list of widgets for local folder selection"""
 
52
        result = []
 
53
        return result
 
54
 
 
55
 
 
56
if __name__ != '__main__':
 
57
    add_lister(folderLister)
 
58