26
import eog, gtk, os, re, gio
28
class RawToolsPlugin(eog.Plugin):
25
from gi.repository import GObject, Gtk, Eog, Gio
28
class ManageRawsPlugin( GObject.Object, Eog.WindowActivatable ):
30
# Override EogWindowActivatable's window property
31
window = GObject.property( type = Eog.Window )
33
# list of file extension to recognise as RAW files
30
34
raw_file_extensions = [ 'cr2', '3fr', 'ari', 'arw', 'srf', 'sr2', 'bay',
31
35
'crw', 'cr2', 'cap', 'iiq', 'eip', 'dcs', 'dcr', 'drf', 'k25', 'kdc',
32
36
'dng', 'erf', 'fff', 'mef', 'mos', 'mrw', 'nef', 'nrw', 'orf', 'ptx',
33
37
'pef', 'pxn', 'r3d', 'raf', 'raw', 'rw2', 'rwl', 'rwz', 'x3f' ]
35
39
def __init__( self ):
36
eog.Plugin.__init__( self )
40
GObject.Object.__init__( self )
38
def activate( self, window ):
42
def do_activate( self ):
42
manager = window.get_ui_manager()
43
self._action_group = gtk.ActionGroup( 'EogRawToolsPluginActions' )
44
self._action_group.add_actions( [ ( 'EogPluginRunKeepRaw', None,
45
ui_manager = self.window.get_ui_manager()
46
self.action_group = Gtk.ActionGroup( 'EogManageRawsPluginActions' )
47
self.action_group.add_actions( [ ( 'EogPluginRunKeepRaw', None,
45
48
_( 'Keep Raw Image' ), 'K',
46
49
_( "Move the accompanying raw file to a 'raw' subdirectory" ),
47
self.on_keep_raw_image ) ] )
48
self._action_group.add_actions( [ ( 'EogPluginRunUnkeepRaw', None,
50
self.do_keep_raw_image ) ], self.window )
51
self.action_group.add_actions( [ ( 'EogPluginRunUnkeepRaw', None,
49
52
_( 'Unkeep Raw Image' ), 'U',
50
53
_( "Move the accompanying raw file back to the image's directory" ),
51
self.on_unkeep_raw_image ) ] )
52
self._action_group.add_actions( [ ( 'EogPluginRunDeleteRaw', None,
54
self.do_unkeep_raw_image ) ], self.window )
55
self.action_group.add_actions( [ ( 'EogPluginRunDeleteRaw', None,
53
56
_( 'Delete Unkept Raw Images' ), None,
54
57
_( "Delete all raw files in the current image's directory (the unkept ones)" ),
55
self.on_delete_raw_images ) ] )
56
manager.insert_action_group( self._action_group, -1 )
57
self._ui_id = manager.add_ui_from_string( """
58
self.do_delete_raw_images ) ], self.window )
59
ui_manager.insert_action_group( self.action_group, -1 )
60
self.ui_id = ui_manager.add_ui_from_string( """
59
62
<menubar name="MainMenu">
60
63
<menu name="ToolsMenu" action="Tools">
79
82
# insert status bar
80
self._statusbar = gtk.Statusbar()
81
self._statusbar.set_has_resize_grip( False )
82
self._statusbar.set_size_request( 80, 10 )
83
statusbar = window.get_statusbar()
84
statusbar.pack_end( self._statusbar, False, False, 0 );
85
self._statusbar.show()
83
self.statusbar = Gtk.Statusbar()
84
#self.statusbar.set_size_request( 100, 10 )
85
statusbar = self.window.get_statusbar()
86
statusbar.pack_end( self.statusbar, False, False, 0 );
87
89
# connect to selection change
88
thumb_view = window.get_thumb_view()
89
self._on_selection_change_id = thumb_view.connect_after( \
90
'selection_changed', self.on_selection_change, window )
90
thumb_view = self.window.get_thumb_view()
91
self.on_selection_change_id = thumb_view.connect_after( \
92
'selection_changed', self.on_selection_change, self.window )
93
self.update_status( window )
95
def deactivate( self, window ):
95
self.update_status( self.window )
97
def do_deactivate( self ):
100
ui_manager = self.window.get_ui_manager()
101
ui_manager.remove_ui( self.ui_id )
103
ui_manager.remove_action_group( self.action_group )
104
self.action_group = None
105
ui_manager.ensure_update()
97
107
# disconnect handlers
98
thumb_view = window.get_thumb_view()
99
thumb_view.disconnect( self._on_selection_change_id )
102
manager = window.get_ui_manager()
103
manager.remove_ui( self._ui_id )
104
manager.remove_action_group( self._action_group )
105
manager.ensure_update()
108
thumb_view = self.window.get_thumb_view()
109
thumb_view.disconnect( self.on_selection_change_id )
107
111
# remove status bar entry
108
statusbar = window.get_statusbar()
109
statusbar.remove( self._statusbar )
112
statusbar = self.window.get_statusbar()
113
Gtk.Container.remove( statusbar, self.statusbar )
111
115
def on_selection_change( self, view, data ):
112
116
self.update_status( data )
168
172
image = thumb_view.get_first_selected_image()
169
173
raw_fname = self.get_raw_filename_from_image( image )
170
174
path = os.path.dirname( image.get_file().get_path() )
171
self._statusbar.pop( 0 )
175
self.statusbar.pop( 0 )
172
176
if( raw_fname is False ):
173
self._statusbar.push( 0, _( 'raw: -' ) )
177
self.statusbar.push( 0, " " + _( 'raw: -' ) )
174
178
elif( os.path.isfile( path + '/' + raw_fname ) ):
175
self._statusbar.push( 0, _( 'raw: unkept' ) )
179
self.statusbar.push( 0, " " + _( 'raw: unkept' ) )
177
self._statusbar.push( 0, _( 'raw: keep' ) )
181
self.statusbar.push( 0, " " + _( 'raw: keep' ) )
179
def on_keep_raw_image( self, action ):
183
def do_keep_raw_image( self, action, window ):
181
185
# do we have just the one selected image? we can't handle multiple
182
186
# images because EogThumbView.get_selected_images() doesn't work.
183
thumb_view = self._window.get_thumb_view()
187
thumb_view = window.get_thumb_view()
184
188
if( thumb_view.get_n_selected() == 1 ):
189
193
self.keep_raw_image( image )
192
self.update_status( self._window )
196
self.update_status( window )
194
def on_unkeep_raw_image( self, action ):
198
def do_unkeep_raw_image( self, action, window ):
196
200
# do we have just the one selected image? we can't handle multiple
197
201
# images because EogThumbView.get_selected_images() doesn't work.
198
thumb_view = self._window.get_thumb_view()
202
thumb_view = window.get_thumb_view()
199
203
if( thumb_view.get_n_selected() == 1 ):
204
208
self.unkeep_raw_image( image )
207
self.update_status( self._window )
211
self.update_status( window )
209
213
def keep_raw_image( self, image ):
211
215
raw_fname = self.get_raw_filename_from_image( image )
212
216
if( raw_fname is False ):
213
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
214
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
217
dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL,
218
Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE,
215
219
_( 'Raw file not found!' ) )
216
220
dialog.format_secondary_text( _( "This image doesn't appear to " +
217
221
"have an accompanying raw file." ) )
235
239
raw_fname = self.get_raw_filename_from_image( image )
236
240
if( raw_fname is False ):
237
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
238
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
241
dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL,
242
Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE,
239
243
_( 'Raw file not found!' ) )
240
244
dialog.format_secondary_text( _( "This image doesn't appear to " +
241
245
"have an accompanying raw file." ) )
254
258
if( len( os.listdir( path + '/raw' ) ) == 0 ):
255
259
os.rmdir( path + '/raw' )
257
def on_delete_raw_images( self, action ):
261
def do_delete_raw_images( self, action, window ):
259
263
# get path to first selected image, if there is one
260
thumb_view = self._window.get_thumb_view()
264
thumb_view = window.get_thumb_view()
261
265
if( thumb_view.get_n_selected() == 1 ):
262
266
image = thumb_view.get_first_selected_image()
263
267
path = os.path.dirname( image.get_file().get_path() )
291
295
"Do you want to continue?" ) )
292
296
result = dialog.run()
294
if( result != gtk.RESPONSE_YES ):
298
if( result != Gtk.ResponseType.YES ):
297
301
# delete the files
298
302
for file in files:
299
gio.file_parse_name( path + '/' + file ).trash()
303
Gio.file_parse_name( path + '/' + file ).trash( None )
300
304
#os.unlink( path + '/' + file )
302
self.update_status( self._window )
306
self.update_status( window )
304
308
# else, tell the user there aren't any raw files!
306
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
307
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
310
dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL,
311
Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE,
308
312
_( 'No raw files to delete!' ) )
309
313
dialog.format_secondary_text(
310
314
_( 'There are no raw files to delete!' ) )