/gtk/eog-manage-raws

To get this branch, use:
bzr branch http://bzr.ed.am/gtk/eog-manage-raws

« back to all changes in this revision

Viewing changes to raw-tools.py

  • Committer: edam
  • Date: 2011-04-08 13:25:29 UTC
  • Revision ID: edam@waxworlds.org-20110408132529-jparj2k4z692532h
- added status bar information
- added delete remaining raw files option

Show diffs side-by-side

added added

removed removed

1
 
# raw-tools.py
2
 
#
3
 
# Copyright (C) 2011 Tim Marston <edam@waxworlds.org>
4
 
#
5
 
# This file is part of Raw Tools (hereafter referred to as "this program").
6
 
# See http://www.waxworlds.org/edam/software/gtk/eog-raw-tools for more
7
 
# information.
8
 
#
9
 
# This program is free software: you can redistribute it and/or modify
10
 
# it under the terms of the GNU General Public License as published by
11
 
# the Free Software Foundation, either version 3 of the License, or
12
 
# (at your option) any later version.
13
 
#
14
 
# This program is distributed in the hope that it will be useful,
15
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
# GNU General Public License for more details.
18
 
#
19
 
# You should have received a copy of the GNU General Public License
20
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
 
22
 
 
23
 
# version 0.1
24
 
 
25
 
 
26
 
import eog, gtk, os, re, gio
27
 
 
28
 
class RawToolsPlugin(eog.Plugin):
 
1
import eog, gtk, os, re
 
2
 
 
3
class HelloWorldPlugin(eog.Plugin):
29
4
 
30
5
    raw_file_extensions = [ 'cr2', '3fr', 'ari', 'arw', 'srf', 'sr2', 'bay',
31
6
        'crw', 'cr2', 'cap', 'iiq', 'eip', 'dcs', 'dcr', 'drf', 'k25', 'kdc',
45
20
            _( 'Keep Raw Image' ), 'K',
46
21
            _( "Move the accompanying raw file to a 'raw' subdirectory" ),
47
22
            self.on_keep_raw_image ) ] )
48
 
        self._action_group.add_actions( [ ( 'EogPluginRunUnkeepRaw', None,
49
 
            _( 'Unkeep Raw Image' ), 'U',
50
 
            _( "Move the accompanying raw file back to the image's directory" ),
51
 
            self.on_unkeep_raw_image ) ] )
52
23
        self._action_group.add_actions( [ ( 'EogPluginRunDeleteRaw', None,
53
24
            _( 'Delete Unkept Raw Images' ), None,
54
25
            _( "Delete all raw files in the current image's directory (the unkept ones)" ),
61
32
                        <separator />
62
33
                        <menuitem name="EogPluginRunKeepRaw"
63
34
                            action="EogPluginRunKeepRaw" />
64
 
                        <menuitem name="EogPluginRunUnkeepRaw"
65
 
                            action="EogPluginRunUnkeepRaw" />
66
35
                        <menuitem name="EogPluginRunDeleteRaw"
67
36
                            action="EogPluginRunDeleteRaw" />
68
37
                        <separator />
79
48
        # insert status bar
80
49
        self._statusbar = gtk.Statusbar()
81
50
        self._statusbar.set_has_resize_grip( False )
82
 
        self._statusbar.set_size_request( 80, 10 )
 
51
        self._statusbar.set_size_request( 85, 10 )
83
52
        statusbar = window.get_statusbar()
84
53
        statusbar.pack_end( self._statusbar, False, False, 0 );
85
54
        self._statusbar.show()
172
141
            if( raw_fname is False ):
173
142
                self._statusbar.push( 0, _( 'raw: -' ) )
174
143
            elif( os.path.isfile( path + '/' + raw_fname ) ):
175
 
                self._statusbar.push( 0, _( 'raw: unkept' ) )
 
144
                self._statusbar.push( 0, _( 'raw: delete' ) )
176
145
            else:
177
146
                self._statusbar.push( 0, _( 'raw: keep' ) )
178
147
 
191
160
            # update ui
192
161
            self.update_status( self._window )
193
162
 
194
 
    def on_unkeep_raw_image( self, action ):
195
 
 
196
 
        # do we have just the one selected image? we can't handle multiple
197
 
        # images because EogThumbView.get_selected_images() doesn't work.
198
 
        thumb_view = self._window.get_thumb_view()
199
 
        if( thumb_view.get_n_selected() == 1 ):
200
 
 
201
 
            # get the image
202
 
            image = thumb_view.get_first_selected_image()
203
 
            if( image != None ):
204
 
                self.unkeep_raw_image( image )
205
 
 
206
 
            # update ui
207
 
            self.update_status( self._window )
208
 
 
209
163
    def keep_raw_image( self, image ):
210
164
 
211
165
        raw_fname = self.get_raw_filename_from_image( image )
230
184
            # move the raw file in to the raw directory
231
185
            os.rename( path + '/' + raw_fname, path + '/raw/' + raw_fname )
232
186
 
233
 
    def unkeep_raw_image( self, image ):
234
 
 
235
 
        raw_fname = self.get_raw_filename_from_image( image )
236
 
        if( raw_fname is False ):
237
 
            dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
238
 
                gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
239
 
                _( 'Raw file not found!' ) )
240
 
            dialog.format_secondary_text( _( "This image doesn't appear to " +
241
 
                "have an accompanying raw file." ) )
242
 
            dialog.run()
243
 
            dialog.destroy()
244
 
            return
245
 
 
246
 
        # does raw file exist?
247
 
        path = os.path.dirname( image.get_file().get_path() )
248
 
        if( os.path.isfile( path + '/raw/' + raw_fname ) ):
249
 
 
250
 
            # move the raw file back to the parent directory
251
 
            os.rename( path + '/raw/' + raw_fname, path + '/' + raw_fname )
252
 
 
253
 
            # if the raw directory is empty, remove it
254
 
            if( len( os.listdir( path + '/raw' ) ) == 0 ):
255
 
                os.rmdir( path + '/raw' )
256
 
 
257
187
    def on_delete_raw_images( self, action ):
258
188
 
259
189
        # get path to first selected image, if there is one
296
226
 
297
227
                # delete the files
298
228
                for file in files:
299
 
                    gio.file_parse_name( path + '/' + file ).trash()
300
 
                    #os.unlink( path + '/' + file )
 
229
                    os.unlink( path + '/' + file )
301
230
 
302
231
                self.update_status( self._window )
303
232