/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: 2012-01-21 22:31:42 UTC
  • mfrom: (5.1.1 eog-raw-tools)
  • Revision ID: edam@waxworlds.org-20120121223142-xrzlappx4kt0t365
update for GTK 3.0

Show diffs side-by-side

added added

removed removed

1
 
# manage-raws.py
 
1
# raw-tools.py
2
2
#
3
3
# Copyright (C) 2011 Tim Marston <edam@waxworlds.org>
4
4
#
5
 
# This file is part of Manage Raws (hereafter referred to as "this
6
 
# program").  See http://ed.am/dev/gtk/eog-manage-raws for more
 
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
7
# information.
8
8
#
9
9
# This program is free software: you can redistribute it and/or modify
22
22
 
23
23
# version 0.1
24
24
 
25
 
from gi.repository import GObject, Gtk, Eog, Gio
26
 
import os, re
 
25
from gi.repository import GObject, Gtk, Eog
 
26
import os, re, gio
27
27
 
28
 
class ManageRawsPlugin( GObject.Object, Eog.WindowActivatable ):
 
28
class RawToolsPlugin( GObject.Object, Eog.WindowActivatable ):
29
29
 
30
30
    # Override EogWindowActivatable's window property
31
31
    window = GObject.property( type = Eog.Window )
43
43
 
44
44
        # insert menu item
45
45
        ui_manager = self.window.get_ui_manager()
46
 
        self.action_group = Gtk.ActionGroup( 'EogManageRawsPluginActions' )
 
46
        self.action_group = Gtk.ActionGroup( 'EogRawToolsPluginActions' )
47
47
        self.action_group.add_actions( [ ( 'EogPluginRunKeepRaw', None,
48
 
            _( 'Keep Raw File' ), 'K',
 
48
            _( 'Keep Raw Image' ), 'K',
49
49
            _( "Move the accompanying raw file to a 'raw' subdirectory" ),
50
 
            self.do_keep_raw_file ) ], self.window )
 
50
            self.do_keep_raw_image ) ], self.window )
51
51
        self.action_group.add_actions( [ ( 'EogPluginRunUnkeepRaw', None,
52
 
            _( 'Unkeep Raw File' ), 'U',
 
52
            _( 'Unkeep Raw Image' ), 'U',
53
53
            _( "Move the accompanying raw file back to the image's directory" ),
54
 
            self.do_unkeep_raw_file ) ], self.window )
 
54
            self.do_unkeep_raw_image ) ], self.window )
55
55
        self.action_group.add_actions( [ ( 'EogPluginRunDeleteRaw', None,
56
 
            _( 'Delete Unkept Raw Files' ), None,
 
56
            _( 'Delete Unkept Raw Images' ), None,
57
57
            _( "Delete all raw files in the current image's directory (the unkept ones)" ),
58
 
            self.do_delete_raw_files ) ], self.window )
 
58
            self.do_delete_raw_images ) ], self.window )
59
59
        ui_manager.insert_action_group( self.action_group, -1 )
60
60
        self.ui_id = ui_manager.add_ui_from_string( """
61
61
            <ui>
144
144
            if( os.path.isfile( base_fname + '.' + ext ) ):
145
145
                return os.path.basename( base_fname + '.' + ext );
146
146
 
147
 
        # path the raw files will be moved to
 
147
        # path the raw images will be moved to
148
148
        raw_path = os.path.dirname( fname ) + '/raw';
149
149
 
150
150
        # loop through valid raw file extensions, uppercase and lowercase
180
180
            else:
181
181
                self.statusbar.push( 0, "  " + _( 'raw: keep' ) )
182
182
 
183
 
    def do_keep_raw_file( self, action, window ):
184
 
 
185
 
        # do we have just the one selected image? we can't handle multiple
186
 
        # images because EogThumbView.get_selected_images() doesn't work.
187
 
        thumb_view = window.get_thumb_view()
188
 
        if( thumb_view.get_n_selected() == 1 ):
189
 
 
190
 
            # get the image
191
 
            image = thumb_view.get_first_selected_image()
192
 
            if( image != None ):
193
 
                self.keep_raw_file( image )
194
 
 
195
 
            # update ui
196
 
            self.update_status( window )
197
 
 
198
 
    def do_unkeep_raw_file( self, action, window ):
199
 
 
200
 
        # do we have just the one selected image? we can't handle multiple
201
 
        # images because EogThumbView.get_selected_images() doesn't work.
202
 
        thumb_view = window.get_thumb_view()
203
 
        if( thumb_view.get_n_selected() == 1 ):
204
 
 
205
 
            # get the image
206
 
            image = thumb_view.get_first_selected_image()
207
 
            if( image != None ):
208
 
                self.unkeep_raw_file( image )
209
 
 
210
 
            # update ui
211
 
            self.update_status( window )
212
 
 
213
 
    def keep_raw_file( self, image ):
 
183
    def do_keep_raw_image( self, action, window ):
 
184
 
 
185
        # do we have just the one selected image? we can't handle multiple
 
186
        # images because EogThumbView.get_selected_images() doesn't work.
 
187
        thumb_view = window.get_thumb_view()
 
188
        if( thumb_view.get_n_selected() == 1 ):
 
189
 
 
190
            # get the image
 
191
            image = thumb_view.get_first_selected_image()
 
192
            if( image != None ):
 
193
                self.keep_raw_image( image )
 
194
 
 
195
            # update ui
 
196
            self.update_status( window )
 
197
 
 
198
    def do_unkeep_raw_image( self, action, window ):
 
199
 
 
200
        # do we have just the one selected image? we can't handle multiple
 
201
        # images because EogThumbView.get_selected_images() doesn't work.
 
202
        thumb_view = window.get_thumb_view()
 
203
        if( thumb_view.get_n_selected() == 1 ):
 
204
 
 
205
            # get the image
 
206
            image = thumb_view.get_first_selected_image()
 
207
            if( image != None ):
 
208
                self.unkeep_raw_image( image )
 
209
 
 
210
            # update ui
 
211
            self.update_status( window )
 
212
 
 
213
    def keep_raw_image( self, image ):
214
214
 
215
215
        raw_fname = self.get_raw_filename_from_image( image )
216
216
        if( raw_fname is False ):
234
234
            # move the raw file in to the raw directory
235
235
            os.rename( path + '/' + raw_fname, path + '/raw/' + raw_fname )
236
236
 
237
 
    def unkeep_raw_file( self, image ):
 
237
    def unkeep_raw_image( self, image ):
238
238
 
239
239
        raw_fname = self.get_raw_filename_from_image( image )
240
240
        if( raw_fname is False ):
258
258
            if( len( os.listdir( path + '/raw' ) ) == 0 ):
259
259
                os.rmdir( path + '/raw' )
260
260
 
261
 
    def do_delete_raw_files( self, action, window ):
 
261
    def do_delete_raw_images( self, action, window ):
262
262
 
263
263
        # get path to first selected image, if there is one
264
264
        thumb_view = window.get_thumb_view()
300
300
 
301
301
                # delete the files
302
302
                for file in files:
303
 
                    Gio.file_parse_name( path + '/' + file ).trash( None )
 
303
                    gio.file_parse_name( path + '/' + file ).trash()
304
304
                    #os.unlink( path + '/' + file )
305
305
 
306
306
                self.update_status( window )