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