49
self._statusbar = gtk.Statusbar()
50
self._statusbar.set_has_resize_grip( False )
51
self._statusbar.set_size_request( 85, 10 )
52
statusbar = window.get_statusbar()
53
statusbar.pack_end( self._statusbar, False, False, 0 );
54
self._statusbar.show()
56
42
# connect to selection change
57
43
thumb_view = window.get_thumb_view()
58
44
self._on_selection_change_id = thumb_view.connect_after( \
59
'selection_changed', self.on_selection_change, window )
45
"selection_changed", self.on_selection_change, window )
62
self.update_status( window )
48
self.update_action_group_sensitivity( window )
64
50
def deactivate( self, window ):
67
thumb_view = window.get_thumb_view()
68
thumb_view.disconnect( self._on_selection_change_id )
70
52
# remove menu items
71
53
manager = window.get_ui_manager()
72
54
manager.remove_ui( self._ui_id )
73
55
manager.remove_action_group( self._action_group )
74
56
manager.ensure_update()
76
# remove status bar entry
77
statusbar = window.get_statusbar()
78
statusbar.remove( self._statusbar )
59
thumb_view = window.get_thumb_view()
60
thumb_view.disconnect( self._on_selection_change_id )
80
62
def on_selection_change( self, view, data ):
81
self.update_status( data )
83
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 ):
84
87
fname = image.get_file().get_path()
86
# get the base fileanme (with no extension), read for searching
89
# strip the file extension off, ready to search for raw files
87
90
base_fname = image.get_file().get_path()
88
91
pos = base_fname.rfind( '.' )
91
# check if the extension of the current image makes it a raw file
92
for ext in self.raw_file_extensions + \
93
map( lambda x: x.upper(), self.raw_file_extensions ):
94
if( base_fname[ pos : ] == ext ):
97
# remove extension from base filename
98
93
base_fname = base_fname[ 0 : pos ]
100
95
# check for stupidity
101
96
if( base_fname[ -1 : None ] == '/' ):
104
# loop through valid raw file extensions, uppercase and lowercase
105
for ext in self.raw_file_extensions + \
106
map( lambda x: x.upper(), self.raw_file_extensions ):
108
# if the raw file exists, we found it
109
if( os.path.isfile( base_fname + '.' + ext ) ):
110
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!" )
112
103
# path the raw images will be moved to
113
104
raw_path = os.path.dirname( fname ) + '/raw';
115
# loop through valid raw file extensions, uppercase and lowercase
106
# loop through valid raw file extensions
116
108
for ext in self.raw_file_extensions + \
117
map( lambda x: x.upper(), self.raw_file_extensions ):
119
# if the raw file exists, we found it
120
if( os.path.isfile( os.path.dirname( fname ) + '/raw/' + \
121
os.path.basename( base_fname + '.' + ext ) ) ):
122
return os.path.basename( base_fname + '.' + ext );
127
def update_status( self, window ):
128
thumb_view = window.get_thumb_view()
130
# do we have just the one selected image? we can't handle multiple
131
# images because EogThumbView.get_selected_images() doesn't work.
132
self._action_group.set_sensitive( \
133
thumb_view.get_n_selected() == 1 )
135
# update the status bar
136
if( thumb_view.get_n_selected() > 0 ):
137
image = thumb_view.get_first_selected_image()
138
raw_fname = self.get_raw_filename_from_image( image )
139
path = os.path.dirname( image.get_file().get_path() )
140
self._statusbar.pop( 0 )
141
if( raw_fname is False ):
142
self._statusbar.push( 0, _( 'raw: -' ) )
143
elif( os.path.isfile( path + '/' + raw_fname ) ):
144
self._statusbar.push( 0, _( 'raw: delete' ) )
146
self._statusbar.push( 0, _( 'raw: keep' ) )
148
def on_keep_raw_image( self, action ):
150
# do we have just the one selected image? we can't handle multiple
151
# images because EogThumbView.get_selected_images() doesn't work.
152
thumb_view = self._window.get_thumb_view()
153
if( thumb_view.get_n_selected() == 1 ):
156
image = thumb_view.get_first_selected_image()
158
self.keep_raw_image( image )
161
self.update_status( self._window )
163
def keep_raw_image( self, image ):
165
raw_fname = self.get_raw_filename_from_image( image )
166
if( raw_fname is False ):
167
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
168
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
169
_( 'Raw file not found!' ) )
170
dialog.format_secondary_text( _( "This image doesn't appear to " +
171
"have an accompanying raw file." ) )
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." )
176
# does raw file exist?
177
path = os.path.dirname( image.get_file().get_path() )
178
if( os.path.isfile( path + '/' + raw_fname ) ):
180
# create the raw directory, if it doesn't exist
181
if( not os.path.isdir( path + '/raw' ) ):
182
os.mkdir( path + '/raw' );
184
# move the raw file in to the raw directory
185
os.rename( path + '/' + raw_fname, path + '/raw/' + raw_fname )
187
def on_delete_raw_images( self, action ):
189
# get path to first selected image, if there is one
190
thumb_view = self._window.get_thumb_view()
191
if( thumb_view.get_n_selected() == 1 ):
192
image = thumb_view.get_first_selected_image()
193
path = os.path.dirname( image.get_file().get_path() )
195
# build a regex that will match raw filenames
197
'.*\.(' + '|'.join( self.raw_file_extensions ) + ')', re.I )
199
# itterate through files in the dir
201
for file in os.listdir( path ):
202
if( regex.match( file ) ):
205
# do we have any files to delete?
206
if( len( files ) > 0 ):
208
# ask the user if they are sure
209
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
210
gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
211
_( 'Delete Raw Files?' ) )
212
if( len( files ) == 1 ):
213
subject = _( ' remaining raw file' )
215
subject = _( ' remaining raw files' )
216
dialog.format_secondary_text(
217
_( 'You are about to delete the ' ) +
218
str( len( files ) ) + subject +
219
_( " that you haven't specifically asked to keep from " +
220
"the directory that the current image is in.\n\n" +
221
"Do you want to continue?" ) )
222
result = dialog.run()
224
if( result != gtk.RESPONSE_YES ):
229
os.unlink( path + '/' + file )
231
self.update_status( self._window )
233
# else, tell the user there aren't any raw files!
235
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL,
236
gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
237
_( 'No raw files to delete!' ) )
238
dialog.format_secondary_text(
239
_( 'There are no raw files to delete!' ) )