Esempio n. 1
0
    def menu_batch(self):
        import os
        filename = tkutil_dialog.ask_openfile(
            title="Choose representative file (same directory, type).")
        if not filename: return
        if '.' not in filename:
            print('Could not find extension.')
            return
        path, filename = os.path.split(filename)
        ext = filename.split('.')[-1]
        files = [file for file in os.listdir(path) if file.endswith('.' + ext)]

        outputfilename = tkutil_dialog.ask_savefile(
            title='Choose directory and format of output images.',
            types=[
                '.png|Png image', '.bmp|Bitmap image', '.jpg|Jpeg image',
                '.tif|TIFF image'
            ])
        outputpath, outputfilename = os.path.split(outputfilename)
        outputext = outputfilename.split('.')[-1]

        confirm = tkutil_dialog.ask_okcancel('Run current script on ' +
                                             str(len(files)) +
                                             ' files of type .' + ext +
                                             ' in directory ' + path + '?')
        if not confirm: return
        for file in files:
            filename = os.path.join(path, file)
            outputfilename = os.path.join(outputpath,
                                          file[0:-len(ext)] + outputext)
            if os.path.exists(outputfilename):
                print('Skipped: File already exists:', outputfilename)
                continue

            try:
                im = Image.open(filename)
                im.load()
            except:
                print('Skipped: Could not open image.')
                continue

            imgResult = runScript(tkutil.gettext(self.fldScript), im)
            if imgResult == None:
                print('Skipped: Script error.')
                continue

            try:
                imgResult.save(outputfilename)
            except:
                print('Error. Could not save ', outputfilename)
            print('Saved: ' + outputfilename)

        print('Job complete.')
Esempio n. 2
0
	def menu_openImage(self):
		filename = tkutil_dialog.ask_openfile(title="Open Image")
		if not filename: return
		try:
			im = Image.open(filename)
		except:
			print 'Error: Could not open image.'
			return
		if im.mode != 'RGB':
			print 'Error: For now, only RGB mode images are supported.'
			return
		self.imgInput = im
		self.updateInput()
Esempio n. 3
0
 def menu_openImage(self):
     filename = tkutil_dialog.ask_openfile(title="Open Image")
     if not filename: return
     try:
         im = Image.open(filename)
     except:
         print('Error: Could not open image.')
         return
     if im.mode != 'RGB':
         print('Error: For now, only RGB mode images are supported.')
         return
     self.imgInput = im
     self.updateInput()
Esempio n. 4
0
	def menu_batch(self):
		import os
		filename = tkutil_dialog.ask_openfile(title="Choose representative file (same directory, type).")
		if not filename: return
		if '.' not in filename:
			print 'Could not find extension.'
			return
		path, filename = os.path.split(filename)
		ext = filename.split('.')[-1]
		files = [file for file in os.listdir(path) if file.endswith('.'+ext)]
		
		outputfilename = tkutil_dialog.ask_savefile(title = 'Choose directory and format of output images.',types=['.png|Png image','.bmp|Bitmap image','.jpg|Jpeg image','.tif|TIFF image'])
		outputpath, outputfilename = os.path.split(outputfilename)
		outputext = outputfilename.split('.')[-1]
		
		confirm = tkutil_dialog.ask_okcancel('Run current script on '+str(len(files))+' files of type .'+ext +' in directory '+path+'?')
		if not confirm: return
		for file in files:
			filename = os.path.join(path, file)
			outputfilename = os.path.join( outputpath, file[0:-len(ext)] + outputext)
			if os.path.exists(outputfilename):
				print 'Skipped: File already exists:',  outputfilename
				continue
			
			try:
				im = Image.open(filename)
				im.load()
			except:
				print 'Skipped: Could not open image.'
				continue
				
			imgResult = runScript(tkutil.gettext(self.fldScript), im)
			if imgResult==None:
				print 'Skipped: Script error.'
				continue
			
			try:
				imgResult.save(outputfilename)
			except:
				print 'Error. Could not save ',outputfilename
			print 'Saved: '+outputfilename
			
		print 'Job complete.'
Esempio n. 5
0
	def menu_openScript(self):
		filename = tkutil_dialog.ask_openfile(title="Open Script", types=['.pyx|Scripts'])
		if not filename: return
		self._setScriptFile(filename)
Esempio n. 6
0
 def menu_openScript(self):
     filename = tkutil_dialog.ask_openfile(title="Open Script",
                                           types=['.pyx|Scripts'])
     if not filename: return
     self._setScriptFile(filename)