Hi Steve,
The GUI is executing the watermarking program as a separate task. As
I am pretty new to python, I paste the code in case you could help:
#!/usr/bin/python
# WipGUI.py
import wx, os, shutil, fnmatch, Image, ImageEnhance, sys, textwrap,
re, wx.lib.intctrl, time
ID_HELP = 1
ID_ABOUT = 2
ID_GO = 3
class Wip(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(750,500))
#Define menus
menubar = wx.MenuBar()
#Define file menu
file = wx.Menu()
quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
file.AppendItem(quit)
self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
#Define help menu
helpMenu = wx.Menu()
helpMenu.Append(ID_HELP, '&Help')
helpMenu.Append(ID_ABOUT, '&About')
self.Bind(wx.EVT_MENU, self.OnAboutBox, id=ID_ABOUT)
#Append menus
menubar.Append(file, '&File')
menubar.Append(helpMenu, '&Help')
self.SetMenuBar(menubar)
#Define main panel
panel = wx.Panel(self, -1)
vbox1 = wx.BoxSizer(wx.VERTICAL)
#Define buttons
#Define button to select the pictures folder
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.picsFolder = wx.Button(panel,-1,"Select your picture
directory",size=(210,30))
self.DirPathTextBox=wx.TextCtrl(panel,-1,"",size=(400,-1))
self.Bind(wx.EVT_BUTTON, self.SelDir, self.picsFolder)
hbox1.Add(self.picsFolder, 0, wx.ALL , 5)
hbox1.Add(self.DirPathTextBox, 0, wx.ALL , 5)
#Define the button to select the watermark file
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
mask ='*.png'
self.markFile = wx.Button(panel,-1,"Select your watermark
file",size=(210,30))
self.Bind(wx.EVT_BUTTON, self.SelFile, self.markFile)
self.FilePathTextBox=wx.TextCtrl(panel,-1,"",size=(400,-1))
hbox2.Add(self.markFile, 0, wx.ALL , 5)
hbox2.Add(self.FilePathTextBox, 0, wx.ALL , 5)
#Define a text box to select desired size
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.pxText = wx.StaticText(panel, -1,'Desired size of the
longest picture side in pixels: ', pos=(300, 170), size=(321,30))
self.px = wx.lib.intctrl.IntCtrl(panel, -1, value=1024,
pos=wx.Point(10, 90), size=(45, 30))
hbox3.Add(self.pxText, 0, wx.ALL , 5)
hbox3.Add(self.px, 0, wx.ALL , 0)
#Define the button to start processing
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
go = wx.Button(panel, -1, 'Go', size=(100, 30))
hbox4.Add(go, 0, wx.ALL , 5)
self.Bind(wx.EVT_BUTTON, self.WaterMark, go)
#Console
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
text = wx.TextCtrl(panel, -1,
style=wx.TE_MULTILINE|wx.TE_READONLY, size=(550, 200))
self.text = text
hbox5.Add(text, 0, wx.ALL , 5)
#Merge sizers
vbox1.Add(hbox1, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox1.Add(hbox2, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox1.Add(hbox3, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox1.Add(hbox4, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
vbox1.Add(hbox5, 0, wx.ALIGN_CENTER | wx.ALL, 5)
panel.SetSizer(vbox1)
self.Centre()
self.Show(True)
def OnQuit(self, event):
self.Close()
def OnAboutBox(self, event):
info = wx.AboutDialogInfo()
info.SetIcon(wx.Icon('icons/exit.png', wx.BITMAP_TYPE_PNG))
info.SetName('Watermark Image Processing')
info.SetVersion('1.0b')
description = open('docs/info.txt').read()
info.SetDescription(description)
info.SetCopyright('(C) 2010 Acrocephalus Soft')
info.SetWebSite('')
license = open('docs/licence.txt').read()
info.SetLicence(license)
info.AddDeveloper('Daniel Valverde')
info.AddDocWriter('Daniel Valverde')
info.AddArtist('Daniel Valverde')
info.AddTranslator('Daniel Valverde')
wx.AboutBox(info)
def SelDir(self,event): dialog = wx.DirDialog(None, "Select your picture
directory",style=wx.DD_DEFAULT_STYLE | wx.DD_CHANGE_DIR)
if dialog.ShowModal() == wx.ID_OK:
self.dirname=dialog.GetPath()
self.DirPathTextBox.write(self.dirname)
dialog.Destroy
def SelFile(self,event): markFile = wx.FileDialog(None, “Select your watermark
file”,style=wx.FD_OPEN, wildcard=“PNG files (.png)|.png”)
if markFile.ShowModal() == wx.ID_OK:
self.markFile=markFile.GetPath()
self.FilePathTextBox.write(self.markFile)
markFile.Destroy
def textoutput(self, text):
self.Refresh()
self.text.AppendText(text)
def WaterMark(self, event):
cwd = os.getcwd()
markFile=self.markFile
px = self.px.GetValue()
#Create a Backup directory
if not os.path.exists(‘Backup’):
os.mkdir(‘Backup’)
#Create a Resized directory
if not os.path.exists(‘Resized’):
os.mkdir(‘Resized’)
#Create a marked directory
if not os.path.exists(‘Watermarked’):
os.mkdir(‘Watermarked’)
#Copy images to backup folder
for file in fnmatch.filter(os.listdir(cwd),’.jpg’):
shutil.copy2(file, ‘Backup/%s’ % file)
self.textoutput(‘Copying ’ + file + ’ to Backup/\n’)
print ‘Copying ’ + file + ’ to Backup/\n’
#Image processing for file in fnmatch.filter(os.listdir(cwd),’.jpg’):
self.textoutput(‘Resizing ’ + file + ‘\n’)
print ‘Resizing ’ + file + ‘\n’
# Open the image
img = Image.open(file)
#Get actual image size and convert it to float
width, height = img.size
width = float(width)
height = float(height)
#Resize landscape images
if width > height:
resizeFactor = width/int(px2)
img =
img.resize((int(width/resizeFactor),int(height/resizeFactor)))
width, height = img.size
img = img.resize((int(width/2),int(height/2)),
Image.ANTIALIAS)
#Resize portrait images
elif width<height:
resizeFactor = height/int(px2)
img =
img.resize((int(width/resizeFactor),int(height/resizeFactor)))
width, height = img.size
img = img.resize((int(width/2),int(height/2)),
Image.ANTIALIAS)
#Resize square images
else:
img = img.resize((int(px2),int(px2)))
width, height = img.size
img = img.resize((int(px),int(px)), Image.ANTIALIAS)
#Save resized image
img.save(file)
#Copy pictures to a Resized directory
for filename in fnmatch.filter(os.listdir(cwd),’*.jpg’):
shutil.copy2(filename, ‘Resized/%s’ % filename)
···
wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=enhttp://www.acrocephalus.net
http://www.sentex.net/
-- Daniel Valverde Saubí
c/Guillem Colteller 9 Baixos 3
17005 Girona
Spain
Cellular: +34651987662
e-mail: Si no és del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudaràs a estalviar aigua, energia i recursos forestals. GRÀCIES!
Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!
dani.valverde@gmail.comhttp://www.acrocephalus.nethttp://natupics.blogspot.com