I need to make it so when i click the Do IT botton the variables ive shown take the values of the text control box ive selected, and after an hour trolling the internet and trying different lines of code i still have no clue. Does anyone have any ideas? Thanks guys. (ive used comments for clarity)
#!/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))
panel = wx.Panel(self)
exitbotton = wx.Button(panel, label="Close", pos=(210, 230),size=(50, 30))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, exitbotton)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
doit = wx.Button(panel, label="Do it", pos=(20, 230),size=(50, 30))
self.Bind(wx.EVT_BUTTON, self.OnDoIt)
wx.StaticText(panel, -1, "Folder Location", (22, 20)) # Txt ctrl 1
self.folderinput = wx.TextCtrl(panel, -1, size=(240,20), pos=(20,50))
wx.StaticText(panel, -1, "New base name", (22, 90)) # Txt ctrl 2
self.newnameinput = wx.TextCtrl(panel, -1, size=(240,20), pos=(20,110))
wx.StaticText(panel, -1, "Please enter the file extension", (22, 150)) # Txt ctrl 3
self.extensioninput = wx.TextCtrl(panel, -1, size=(240,20), pos=(20,170))
statusBar = self.CreateStatusBar()
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuBar.Append(menu1, "&File")
self.SetMenuBar(menuBar)
self.Show()
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
def OnDoIt(self, event):
self.OnClick # here is where i think the missing code goes
app = wx.App()
frame = renamerMacro(parent=None, id=-1)
frame.Show()
app.MainLoop()
targetfolder = # needs to be Txt Ctrl 1
os.chdir(targetfolder)
newname=box = # needs to be Txt ctrl 2
newname = pjoin(targetfolder, newname)
rxin = # needs to be Txt ctrl 3
allowed_name = re.compile(rxin).match
a = 0
for fname in os.listdir(targetfolder):
if allowed_name(fname):
a += 1
c = os.path.splitext(fname)
b = (newname + str(a) + c[1])
os.rename(fname, b)