I have a widget that list filenames
but doesn’t yet replace out commas in the naming.
I’m having a hard time understanding
how to pass variables between functions.
Basically I need:
[filename.rename(f, f.replace(’,’,
‘’)) for f in filename(’.’) if not f.startswith(’.’)]
to execute when I click the button.
Any help would be grateful.
import os
import sys
import wx
import re
class MainFrame(wx.Frame):
def init(self):
args = sys.argv[1:]
wx.Frame.init(self,None,wx.ID_ANY,title=‘List and Correct Naming of Files’,size=(600, 450))
self.hbox2 = wx.BoxSizer()
self.vbox= wx.BoxSizer(wx.VERTICAL)
self.background = wx.Panel(self)
self.top2 = wx.TextCtrl(self.background,style=wx.PROCESS_ENTER)
self.top2.Bind(wx.EVT_LEFT_UP,self.OnChooseRoot)
self.bottomview = wx.TextCtrl(self.background,style = wx.TE_MULTILINE|wx.TE_RICH)
self.butExport2 = wx.Button(self.background,wx.ID_ANY,label = 'auto rename')
self.hbox2.Add(self.top2,proportion = 1,border=0)
self.hbox2.Add(self.butExport2,proportion = 0,border=0)
self.vbox.Add(self.hbox2,proportion = 0,flag = wx.EXPAND,border=0)
self.vbox.Add(self.bottomview,proportion = 1,flag = wx.EXPAND,border=0)
self.Bind(wx.EVT_BUTTON, self.checkBtnClick2, self.butExport2)
self.background.SetSizer(self.vbox)
self.Show()
font1 = wx.Font(10, wx.SWISS, wx.ITALIC, wx.LIGHT, False, u'Courier New')
font4 = wx.Font(10, wx.SWISS, wx.ITALIC, wx.LIGHT, False, u'Courier New')
self.top2.SetFont(font4)
self.top2.SetForegroundColour((140,140,140))
self.top2.SetValue("application feedback interruptor")
def OnChooseRoot(self, event):
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
for dirname, dirnames, filenames in os.walk(dlg.GetPath()):
for filename in filenames:
if ',' in filename:
font4 = wx.Font(8, wx.SWISS, wx.ITALIC, wx.LIGHT, False, u'Courier New')
self.top2.SetFont(font4)
self.top2.SetForegroundColour((250,100,100))
self.top2.SetValue("errors detected in naming")
font2 = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
self.bottomview.SetFont(font2)
s=('\n')
bs=(os.path.join(filename,s))
bf = (bs.replace("\\",""))
self.bottomview.AppendText(bf)
dlg.Destroy()
def checkBtnClick2(filename, filenames):
print filename
[filename.rename(f, f.replace(',', '')) for f in filename('.') if not f.startswith('.')] ## not callable
for filename in filenames: ## not iterable
filename.replace(",", "")