This one has got me completely, i cant see why the notebook doesnt show, i wanted the gui interface i have already built to show on page 2 of the notebook, but for some wierd reason the page just comes up empty, and it is really baffeling me. Can anyone shed some light on the situation?
#!/usr/local/bin/python
# Authour - Rhys
# Version - 1.00
import re, os, wx
from os.path import join as pjoin, isdir
class renamerMacro(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Renaming Macro',
size=(300, 350))
def MyPanel(self, parent, bgcolor, toolbar=False):
wx.Panel.MyPanel(self, parent, wx.ID_ANY)
self.SetBackgroundColour(bgcolor)
notebook = wx.Notebook(renamerMacro, -1)
panel1 = MyPanel(notebook, "lightgrey")
panel2 = MyPanel(notebook, "green")
panel3 = MyPanel(notebook, "red")
notebook.AddPage(panel1, "Page1")
notebook.AddPage(panel2, "Page2")
notebook.AddPage(panel3, "Page3")
exitbutton = wx.Button(panel2, label="Close",
pos=(210, 230),size=(50, 30))
self.Bind(wx.EVT_BUTTON, self.oncloseme, exitbutton)
self.Bind(wx.EVT_CLOSE, self.onclosewindow)
doit = wx.Button(panel2, label="Do it",
pos=(20, 230),size=(50, 30))
self.Bind(wx.EVT_BUTTON, self.ondoit, doit)
wx.StaticText(panel2, -1, "Folder Location", (22, 20))
self.folderinput = wx.TextCtrl(panel2, -1, size=(240,20),
pos=(20,50))
wx.StaticText(panel2, -1, "New base name", (22, 90))
self.newnameinput = wx.TextCtrl(panel2, -1, size=(240,20),
pos=(20,110))
wx.StaticText(panel2, -1, "Please enter the file extension",
(22, 150))
self.extensioninput = wx.TextCtrl(panel2, -1, size=(240,20),
pos=(20,170))
self.Show()
def oncloseme(self, event):
self.Close(True)
def onclosewindow(self, event):
self.Destroy()
def ondoit(self, event):
targetfolder = self.folderinput.GetValue()
newname = self.newnameinput.GetValue()
rxin = self.extensioninput.GetValue()
os.chdir(targetfolder)
newname = pjoin(targetfolder, newname)
allowed_name = re.compile(rxin).match
a = 0
for fname in os.listdir(targetfolder):
if allowed_name(fname):
a += 1
d = " "
c = os.path.splitext(fname)
b = (newname + d + str(a) + c[1])
os.rename(fname, b)
app = wx.App(redirect = False)
frame = renamerMacro(parent=None, id=-1)
frame.Show()
app.MainLoop()