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()

Edited 6 Years Ago by Archenemie: n/a

Almost done it - I get this error though "panel1 = mypanel(notebook, "lightgrey")
TypeError: 'Panel' object is not callable". Does anyone have a way around this? ive tried defining a panel object and making a panel class but it seems to interfere with my code and cause my initial problem...

#!/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))
        notebook = wx.Notebook(self, -1)
        mypanel = wx.Panel(self)
        panel1 = mypanel(notebook, "lightgrey")
        panel2 = mypanel(notebook, "green")
        panel3 = mypanel(notebook, "red")

        notebook.AddPage(panel1, "Page1")
        notebook.AddPage(panel2, "Page2")
        notebook.AddPage(panel3, "Page3")
        #mainpanel = wx.Panel(self)
        
        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()

Edited 6 Years Ago by Archenemie: n/a

can anyone help, im sure this is a simple problem with a simple solution, but im not sure how to do it, i know one way of doing it where i make the panel the class, but then i cant use lines like

exitbutton = wx.Button(panel2, label="Close",
             pos=(210, 230),size=(50, 30))
        self.Bind(wx.EVT_BUTTON, self.oncloseme, exitbutton)

because it tells me "self has not been defined"

This question has already been answered. Start a new discussion instead.