2
# -*- coding: utf-8 -*-
5
# Copyright Nicolas Bertrand (nico@inattendu.org), 2009
7
# This file is part of Luciole.
9
# Luciole is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# Luciole is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with Luciole. If not, see <http://www.gnu.org/licenses/>.
27
Started on ven 28 déc 2007 12:57:52 @USER-NAME@
28
Last update ven 28 déc 2007 12:57:52 @USER-NAME@
33
COMMENT : only PNG and JPEG are supportted.
39
import luciole_global as MG
40
import luciole_file_in_out as MF
41
import luciole_constants as MCONST
42
import luciole_class as MC
45
class luciole_import(object) :
46
""" Manage the import of images. COMMENT : only PNG and JPEG are supported.
49
def __init__(self,gladefile,windowname):
50
""" Init of module """
51
self._gladefile=gladefile
52
self._windowname=windowname
53
self._tvCapture = MG.luciole_global.dico[MC.LucioleGtkTreeView.__name__]
55
self._inputImageList =[]
56
self._outputImageList =[]
57
def gui_import(self) :
58
""" Import from gui. """
59
if ( (MF.luciole_project_file.__name__ in MG.luciole_global.dico)
61
( MG.luciole_global.dico[MF.luciole_project_file.__name__].ProjectLoaded) ) :
62
self._Project = MG.luciole_global.dico[MF.luciole_project_file.__name__]
63
# clear imageList when a project is Loaded
64
self._inputImageList =[]
65
self._outputImageList =[]
66
# a project exists and it loaded, the fileChosser Window can be opened
67
self.openFileWindow=gtk.glade.XML(self._gladefile,self._windowname)
68
dialog = self.openFileWindow.get_widget(self._windowname)
69
# set user dir as default dir
70
dialog.set_current_folder(os.path.expandvars('$HOME'))
72
#set filters All files and all mime type images
74
filter = gtk.FileFilter()
75
filter.add_mime_type("image/jpeg")
76
filter.set_name("Images ( jpeg )")
77
dialog.add_filter(filter)
80
filter = gtk.FileFilter()
81
filter.add_pattern("*")
82
filter.set_name("All files")
83
dialog.add_filter(filter)
86
# value 10 choosen in glade file th standard respone gtk.REPONSE_OK = -5
87
# provides no result. It look like a bug in glade ...
89
print "Ok clicked files selected :"
90
self._inputImageList = dialog.get_filenames()
91
self.processImageList()
92
elif response == gtk.RESPONSE_CANCEL:
93
print 'Cancel clicked'
97
# No Project Loaded send a message.
98
message = "Opération non permise quand un projet n'est pas chargé. Veuillez créer un nouveau porojet ou en charger un."
99
MG.luciole_global.dico['appgui'].ErrMessage(message)
101
def processImageList(self) :
102
""" Process the Image list , transform and Append it in capture treeview"""
103
for image in self._inputImageList :
105
imageTransformed = self.Transform(image)
106
#append image in treview
107
if imageTransformed :
108
self._tvCapture.AppendFromCapture(imageTransformed)
110
def Transform(self,imagePath) :
111
""" Transform an image in jpeg format and defined size"""
113
print " Image Process : ",imagePath
114
im = Image.open(imagePath)
115
(base,ext) = os.path.splitext(imagePath)
116
(rep,base) = os.path.split(base)
117
print im.format, im.size, im.mode
118
if im.format == "JPEG" and im.size == MCONST.VIDEO_PAL_RES :
119
print " Nothing to do image ",imagePath," is in correct format"
120
IsImageTransformed =False
121
if im.size != MCONST.VIDEO_PAL_RES :
122
# image need to be rescaled
123
out = im.resize(MCONST.VIDEO_PAL_RES)
124
IsImageTransformed = True
126
dirOut = os.path.join(self._Project.project_dir,"work")
127
fileOut = base+".jpeg"
128
fileOut = os.path.join(dirOut,fileOut)
129
if IsImageTransformed :
132
#image not transformed just copy it
133
MF.luciole_file_tools.copy(imagePath,fileOut)