[pygtk] not enough arguments?

Christopher Spears cspears2002 at yahoo.com
Sat Aug 5 08:33:21 WST 2006


I writing a script that creates a GUI in which a user
types in a base path and a glob pattern.  The script
tranverses the directories of the base path and
returns the files that match glob.  Here is what I
have so far:

import glob, os, os.path, sys
try:
	import pygtk
	pygtk.require("2.0")
except:
	pass
	
try:
	import gtk
	import gtk.glade
except:
	sys.exit(1)
	
class findFileGUI:
	"""A GUI used to find files with glob"""
	
	def on_mainWindow_delete(self, widget, event):
		gtk.main_quit()
		
	def get_path(self, widget, entry, path):
		base_path = entry.get_text()
		return base_path
		
	def create_dict(path, globbed_dict):
		cwd = os.getcwd()
		os.chdir(path)
		matched_files = glob.glob(pattern)
		if matched_files != []:
			globbed_dict[path] = matched_files
		#Make sure the script returns to the user's original
directory
		os.chdir(cwd)
		return globbed_dict

	def glob_files(pattern, base_path = '.'):
		abs_base = os.path.abspath(base_path)
		globbed_dict = {}
		#Check the root directory first
		globbed_dict = create_dict(abs_base, globbed_dict)
		#Check other directories
		for root,dirs,files in os.walk(abs_base):
			for name in dirs:
				path = os.path.join(root, name)
				globbed_dict = create_dict(path, globbed_dict)
				os.chdir(abs_base)
		return globbed_dict
	
	def print_dict(globbed_dict):
		paths = globbed_dict.keys()
		paths.sort()
		for p in paths:
			print p,": "
			file_list = globbed_dict[p]
			for f in file_list:
				print "\t",f
				
	def __init__(self):
		self.gladefile = "find_files.glade"
		self.wTree = gtk.glade.XML(self.gladefile)
		
		path_entry = self.wTree.get_widget("path_entry")
		
		dic = { "on_mainWindow_delete_event" :
self.on_mainWindow_delete,
			"on_path_entry_activate" : (self.get_path,
path_entry) }
		self.wTree.signal_autoconnect(dic)
		
	
if __name__ == "__main__":
	fFG = findFileGUI()
	main = gtk.main()
	

My main problem seems to be between

dic = { "on_mainWindow_delete_event" :
self.on_mainWindow_delete,
			"on_path_entry_activate" : (self.get_path,
path_entry) }
		self.wTree.signal_autoconnect(dic)
		
and 

def get_path(self, widget, entry, path):
		base_path = entry.get_text()
		return base_path

Right now, I just want the get_path function to print
to the screen, so I can see if it is working
correctly.    However, if I run the script and type a
path, I just get this:

TypeError: get_path() takes exactly 4 arguments (3
given)

I've looked over some older scripts and examined some
tutorials, but I still can't find what the problem is.
 


More information about the pygtk mailing list