/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 src/raw-tools.py

  • Committer: edam
  • Date: 2011-09-22 21:51:14 UTC
  • Revision ID: edam@waxworlds.org-20110922215114-mdmf2k6vd16bibh3
- added unkeep command
- delete raw iamges now moves them to trash

Show diffs side-by-side

added added

removed removed

1
 
import eog, gtk, os, re
2
 
 
3
 
class HelloWorldPlugin(eog.Plugin):
 
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):
4
29
 
5
30
    raw_file_extensions = [ 'cr2', '3fr', 'ari', 'arw', 'srf', 'sr2', 'bay',
6
31
        'crw', 'cr2', 'cap', 'iiq', 'eip', 'dcs', 'dcr', 'drf', 'k25', 'kdc',
20
45
            _( 'Keep Raw Image' ), 'K',
21
46
            _( "Move the accompanying raw file to a 'raw' subdirectory" ),
22
47
            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 ) ] )
23
52
        self._action_group.add_actions( [ ( 'EogPluginRunDeleteRaw', None,
24
53
            _( 'Delete Unkept Raw Images' ), None,
25
54
            _( "Delete all raw files in the current image's directory (the unkept ones)" ),
32
61
                        <separator />
33
62
                        <menuitem name="EogPluginRunKeepRaw"
34
63
                            action="EogPluginRunKeepRaw" />
 
64
                        <menuitem name="EogPluginRunUnkeepRaw"
 
65
                            action="EogPluginRunUnkeepRaw" />
35
66
                        <menuitem name="EogPluginRunDeleteRaw"
36
67
                            action="EogPluginRunDeleteRaw" />
37
68
                        <separator />
48
79
        # insert status bar
49
80
        self._statusbar = gtk.Statusbar()
50
81
        self._statusbar.set_has_resize_grip( False )
51
 
        self._statusbar.set_size_request( 85, 10 )
 
82
        self._statusbar.set_size_request( 80, 10 )
52
83
        statusbar = window.get_statusbar()
53
84
        statusbar.pack_end( self._statusbar, False, False, 0 );
54
85
        self._statusbar.show()
141
172
            if( raw_fname is False ):
142
173
                self._statusbar.push( 0, _( 'raw: -' ) )
143
174
            elif( os.path.isfile( path + '/' + raw_fname ) ):
144
 
                self._statusbar.push( 0, _( 'raw: delete' ) )
 
175
                self._statusbar.push( 0, _( 'raw: unkept' ) )
145
176
            else:
146
177
                self._statusbar.push( 0, _( 'raw: keep' ) )
147
178
 
160
191
            # update ui
161
192
            self.update_status( self._window )
162
193
 
 
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
 
163
209
    def keep_raw_image( self, image ):
164
210
 
165
211
        raw_fname = self.get_raw_filename_from_image( image )
184
230
            # move the raw file in to the raw directory
185
231
            os.rename( path + '/' + raw_fname, path + '/raw/' + raw_fname )
186
232
 
 
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
 
187
257
    def on_delete_raw_images( self, action ):
188
258
 
189
259
        # get path to first selected image, if there is one
226
296
 
227
297
                # delete the files
228
298
                for file in files:
229
 
                    os.unlink( path + '/' + file )
 
299
                    gio.file_parse_name( path + '/' + file ).trash()
 
300
                    #os.unlink( path + '/' + file )
230
301
 
231
302
                self.update_status( self._window )
232
303