i am new to PyGtk. i don't know how to get realtime update on gtk.
such as downloadmanagers show's every time the speed changes.

here is my. in this code the "f='/home/tree.txt'" is a log file .this file regularly updated by another thread. i want to add the file contents to TreeView with regular update. is it need any loop, if yes where i can loop?

import codecs,gtk

def redraw():
	f='/home/tree.txt'  #this is realtime log file
	log=codecs.open(f,'r','utf-8')
	d=log.read()
	log.close
	return d


DATA = [
	[0, redraw()],
	[1, "one"],
	[2, "two"],
	[3, "three"],
	[4, "four"],
	[5, "five"],
	[6, "six"],
	[7, "seven"],
	[8, "eight"],
	]

class t_treeview_sort(gtk.Window):
	def __init__(self):
		gtk.Window.__init__(self)

		self.set_title("Treeview")
		self.set_geometry_hints(min_width=200)
		self.connect("destroy", gtk.main_quit)

		self.list = gtk.ListStore(int, str)
		self.sort_order = gtk.SORT_ASCENDING
		while gtk.events_pending():
			gtk.main_iteration()
		for data in DATA:
			iter = self.list.append( data )
			self.list.set(iter)

		self.treeview = gtk.TreeView()
		model = self.treeview.get_selection()
		model.set_mode(gtk.SELECTION_SINGLE)
		r = gtk.CellRendererText()

		tc = gtk.TreeViewColumn("Id", r, text=0)
		self.treeview.insert_column(tc, -1)

		tc = gtk.TreeViewColumn("Text", r, text=1)
		self.treeview.insert_column(tc, -1)

		self.treeview.set_model(self.list)
		self.treeview.set_headers_clickable(True)
		

		self.treeview.show()
		self.add(self.treeview)

t = t_treeview_sort()
t.show()
gtk.main()

Thanks in advance.

I'd have a separate thread that looks for changes to the file. When it sees a change the thread should send a signal. You can then have your treeview listen for that signal and call a handler to update what's displayed. See http://zetcode.com/tutorials/pygtktutorial/signals/ for more info on creating your own signals.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.