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()
87
42
# connect to selection change
88
43
thumb_view = window.get_thumb_view()
89
44
self._on_selection_change_id = thumb_view.connect_after( \
90
'selection_changed', self.on_selection_change, window )
45
"selection_changed", self.on_selection_change, window )
93
self.update_status( window )
48
self.update_action_group_sensitivity( window )
95
50
def deactivate( self, window ):
98
thumb_view = window.get_thumb_view()
99
thumb_view.disconnect( self._on_selection_change_id )
101
52
# remove menu items
102
53
manager = window.get_ui_manager()
103
54
manager.remove_ui( self._ui_id )
104
55
manager.remove_action_group( self._action_group )
105
56
manager.ensure_update()
107
# remove status bar entry
108
statusbar = window.get_statusbar()
109
statusbar.remove( self._statusbar )
59
thumb_view = window.get_thumb_view()
60
thumb_view.disconnect( self._on_selection_change_id )
111
62
def on_selection_change( self, view, data ):
112
self.update_status( data )
114
def get_raw_filename_from_image( self, image ):
63
self.update_action_group_sensitivity( data )
65
def update_action_group_sensitivity( self, window ):
67
# do we have just the one selected image? we can't handle multiple
68
# images because EogThumbView.get_selected_images() doesn't work.
69
thumb_view = window.get_thumb_view()
70
self._action_group.set_sensitive( \
71
thumb_view.get_n_selected() == 1 )
73
def on_keep_raw_image( self, action ):
75
# do we have just the one selected image? we can't handle multiple
76
# images because EogThumbView.get_selected_images() doesn't work.
77
thumb_view = self._window.get_thumb_view()
78
if( thumb_view.get_n_selected() == 1 ):
81
image = thumb_view.get_first_selected_image()
83
self.keep_raw_image( image )
85
def keep_raw_image( self, image ):
115
87
fname = image.get_file().get_path()
117
# get the base fileanme (with no extension), read for searching
89
# strip the file extension off, ready to search for raw files
118
90
base_fname = image.get_file().get_path()
119
91
pos = base_fname.rfind( '.' )
122
# check if the extension of the current image makes it a raw file
123
for ext in self.raw_file_extensions + \
124
map( lambda x: x.upper(), self.raw_file_extensions ):
125
if( base_fname[ pos : ] == ext ):
128
# remove extension from base filename
129
93
base_fname = base_fname[ 0 : pos ]
131
95
# check for stupidity
132
96
if( base_fname[ -1 : None ] == '/' ):
135
# loop through valid raw file extensions, uppercase and lowercase
136
for ext in self.raw_file_extensions + \
137
map( lambda x: x.upper(), self.raw_file_extensions ):
139
# if the raw file exists, we found it
140
if( os.path.isfile( base_fname + '.' + ext ) ):
141
return os.path.basename( base_fname + '.' + ext );
97
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
98
gtk.BUTTONS_CLOSE, "Image is invalid!" )
143
103
# path the raw images will be moved to
144
104
raw_path = os.path.dirname( fname ) + '/raw';
146
# loop through valid raw file extensions, uppercase and lowercase
106
# loop through valid raw file extensions
147
108
for ext in self.raw_file_extensions + \
148
map( lambda x: x.upper(), self.raw_file_extensions ):
150
# if the raw file exists, we found it
151
if( os.path.isfile( os.path.dirname( fname ) + '/raw/' + \
152
os.path.basename( base_fname + '.' + ext ) ) ):
153
return os.path.basename( base_fname + '.' + ext );
158
def update_status( self, window ):
159
thumb_view = window.get_thumb_view()
161
# do we have just the one selected image? we can't handle multiple
162
# images because EogThumbView.get_selected_images() doesn't work.
163
self._action_group.set_sensitive( \
164
thumb_view.get_n_selected() == 1 )
166
# update the status bar
167
if( thumb_view.get_n_selected() > 0 ):
168
image = thumb_view.get_first_selected_image()
169
raw_fname = self.get_raw_filename_from_image( image )
170
path = os.path.dirname( image.get_file().get_path() )
171
self._statusbar.pop( 0 )
172
if( raw_fname is False ):
173
self._statusbar.push( 0, _( 'raw: -' ) )
174
elif( os.path.isfile( path + '/' + raw_fname ) ):
175
self._statusbar.push( 0, _( 'raw: unkept' ) )
177
self._statusbar.push( 0, _( 'raw: keep' ) )
179
def on_keep_raw_image( self, action ):
181
# do we have just the one selected image? we can't handle multiple
182
# images because EogThumbView.get_selected_images() doesn't work.
183
thumb_view = self._window.get_thumb_view()
184
if( thumb_view.get_n_selected() == 1 ):
187
image = thumb_view.get_first_selected_image()
189
self.keep_raw_image( image )
192
self.update_status( self._window )
194
def on_unkeep_raw_image( self, action ):
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 ):
202
image = thumb_view.get_first_selected_image()
204
self.unkeep_raw_image( image )
207
self.update_status( self._window )
209
def keep_raw_image( self, image ):
211
raw_fname = self.get_raw_filename_from_image( image )
212
if( raw_fname is False ):
213
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
214
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
215
_( 'Raw file not found!' ) )
216
dialog.format_secondary_text( _( "This image doesn't appear to " +
217
"have an accompanying raw file." ) )
222
# does raw file exist?
223
path = os.path.dirname( image.get_file().get_path() )
224
if( os.path.isfile( path + '/' + raw_fname ) ):
226
# create the raw directory, if it doesn't exist
227
if( not os.path.isdir( path + '/raw' ) ):
228
os.mkdir( path + '/raw' );
230
# move the raw file in to the raw directory
231
os.rename( path + '/' + raw_fname, path + '/raw/' + raw_fname )
233
def unkeep_raw_image( self, image ):
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." ) )
246
# does raw file exist?
247
path = os.path.dirname( image.get_file().get_path() )
248
if( os.path.isfile( path + '/raw/' + raw_fname ) ):
250
# move the raw file back to the parent directory
251
os.rename( path + '/raw/' + raw_fname, path + '/' + raw_fname )
253
# if the raw directory is empty, remove it
254
if( len( os.listdir( path + '/raw' ) ) == 0 ):
255
os.rmdir( path + '/raw' )
257
def on_delete_raw_images( self, action ):
259
# get path to first selected image, if there is one
260
thumb_view = self._window.get_thumb_view()
261
if( thumb_view.get_n_selected() == 1 ):
262
image = thumb_view.get_first_selected_image()
263
path = os.path.dirname( image.get_file().get_path() )
265
# build a regex that will match raw filenames
267
'.*\.(' + '|'.join( self.raw_file_extensions ) + ')', re.I )
269
# itterate through files in the dir
271
for file in os.listdir( path ):
272
if( regex.match( file ) ):
275
# do we have any files to delete?
276
if( len( files ) > 0 ):
278
# ask the user if they are sure
279
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
280
gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
281
_( 'Delete Raw Files?' ) )
282
if( len( files ) == 1 ):
283
subject = _( ' remaining raw file' )
285
subject = _( ' remaining raw files' )
286
dialog.format_secondary_text(
287
_( 'You are about to delete the ' ) +
288
str( len( files ) ) + subject +
289
_( " that you haven't specifically asked to keep from " +
290
"the directory that the current image is in.\n\n" +
291
"Do you want to continue?" ) )
292
result = dialog.run()
294
if( result != gtk.RESPONSE_YES ):
299
gio.file_parse_name( path + '/' + file ).trash()
300
#os.unlink( path + '/' + file )
302
self.update_status( self._window )
304
# 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,
308
_( 'No raw files to delete!' ) )
309
dialog.format_secondary_text(
310
_( 'There are no raw files to delete!' ) )
109
map( lambda x: x.upper(), self.raw_file_extensions ):
111
# calculate the name of the raw file and where we would move it to
112
src_fname = base_fname + '.' + ext
113
dst_fname = raw_path + '/' + os.path.basename( src_fname )
115
# look for existing files
116
if( os.path.isfile( src_fname ) ):
119
# create the raw directory, if it doesn't exist
120
if( not os.path.isdir( raw_path ) ):
121
os.mkdir( raw_path );
123
# move the raw file in to the raw directory
124
os.rename( src_fname, dst_fname )
126
# check for already-moved raw files
127
elif( os.path.isfile( dst_fname ) ):
130
# check we found the raw file
132
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
133
gtk.BUTTONS_CLOSE, "Raw file not found!" )
134
dialog.format_secondary_text( "This image doesn't appear to have an accompanying raw file." )