3
class HelloWorldPlugin(eog.Plugin):
5
raw_file_extensions = [ 'cr2', '3fr', 'ari', 'arw', 'srf', 'sr2', 'bay',
6
'crw', 'cr2', 'cap', 'iiq', 'eip', 'dcs', 'dcr', 'drf', 'k25', 'kdc',
7
'dng', 'erf', 'fff', 'mef', 'mos', 'mrw', 'nef', 'nrw', 'orf', 'ptx',
8
'pef', 'pxn', 'r3d', 'raf', 'raw', 'rw2', 'rwl', 'rwz', 'x3f' ]
11
eog.Plugin.__init__( self )
13
def activate( self, window ):
17
manager = window.get_ui_manager()
18
self._action_group = gtk.ActionGroup( "EogRawToolsPluginActions" )
19
self._action_group.add_actions( [ ( "EogPluginRunKeepRaw", None,
20
_( "Keep Raw Image" ), "K",
21
_( "Keep accompanying raw image" ),
22
self.on_keep_raw_image ) ] )
23
manager.insert_action_group( self._action_group, -1 )
24
self._ui_id = manager.add_ui_from_string( """
26
<menubar name="MainMenu">
27
<menu name="ToolsMenu" action="Tools">
29
<menuitem name="EogPluginRawTools"
30
action="EogPluginRunKeepRaw" />
34
<popup name="ViewPopup">
36
<menuitem action="EogPluginRunKeepRaw" />
42
# connect to selection change
43
thumb_view = window.get_thumb_view()
44
self._on_selection_change_id = thumb_view.connect_after( \
45
"selection_changed", self.on_selection_change, window )
48
self.update_action_group_sensitivity( window )
50
def deactivate( self, window ):
53
manager = window.get_ui_manager()
54
manager.remove_ui( self._ui_id )
55
manager.remove_action_group( self._action_group )
56
manager.ensure_update()
59
thumb_view = window.get_thumb_view()
60
thumb_view.disconnect( self._on_selection_change_id )
62
def on_selection_change( self, view, data ):
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 ):
87
fname = image.get_file().get_path()
89
# strip the file extension off, ready to search for raw files
90
base_fname = image.get_file().get_path()
91
pos = base_fname.rfind( '.' )
93
base_fname = base_fname[ 0 : pos ]
96
if( base_fname[ -1 : None ] == '/' ):
97
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
98
gtk.BUTTONS_CLOSE, "Image is invalid!" )
103
# path the raw images will be moved to
104
raw_path = os.path.dirname( fname ) + '/raw';
106
# loop through valid raw file extensions
108
for ext in self.raw_file_extensions + \
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." )