this is using pygtk 2.3.91

There should be 1 row selected and I want the focus to be on list not the header.

Once the cursor moves into the window I want to be able to hit return and have
the callback function called.



Toon Verstraelen wrote:
Mike Bernson wrote:

That did not make a row in the list have the focus. I want a row in list
to have the focus so the use can just hit return to select the row without
having to clicking on it first.


Can you send an small but complete example program that ilustrates the problem?

regards,
Toon

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


#
# $Header: /data/myranch/cvs/myranch/code/lib/screen/widgets/list.py,v 1.9 2004/05/02 23:59:29 mike Exp $
#
import gobject
import gtk

class list:
	def 	create_widget(self):

		title_count = 0
		cell_x = None
		cell_y = None
		cell_width = None
		cell_height = None
		self.select_path = None
		sort_cell = None

		title_list = []
		self.column = []
		type_list = []
		row_max = 15
		row_count = 15

		scroll = gtk.ScrolledWindow()
		scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)

		type_list.append(gobject.TYPE_STRING)
		type_list.append(gobject.TYPE_STRING)
		type_list.append(gobject.TYPE_STRING)

		self.store = gtk.ListStore(*type_list)
		list = gtk.TreeView(self.store)
		self.treeView = list
		list.connect('row_activated', self.row_activated_event)
		list.set_rules_hint(gtk.TRUE)
		list.set_headers_clickable(gtk.TRUE)
		selection = list.get_selection()
		selection.set_mode(gtk.SELECTION_BROWSE)
		count = 0
		for title in ('colum1', 'column 2', 'column 3'):
			renderer = gtk.CellRendererText()
			column = gtk.TreeViewColumn(title, renderer,
				text=count)
			self.column.append({})


			self.column[count]['viewColumn'] = column
			self.column[count]['columnID'] = count
			column.set_resizable(gtk.TRUE)
			column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
			column.set_clickable(gtk.TRUE)
			column.set_sort_column_id(count)
			column.set_reorderable(gtk.TRUE)
			list.append_column(column)

			if cell_height == None:
				(rectangle, cell_x, cell_y, cell_width, cell_height) = column.cell_get_size()
			if sort_cell == None:
				sort_cell = column

			count += 1

		self.store.append(['row 1 col 1', 'row 1 col 2', 'row 1 col 3'])
		self.store.append(['row 2 col 1', 'row 2 col 2', 'row 2 col 3'])
		self.store.append(['row 3 col 1', 'row 3 col 2', 'row 3 col 3'])                                                      
		self.store.append(['row 4 col 1', 'row 4 col 2', 'row 4 col 3'])
		self.store.append(['row 5 col 1', 'row 5 col 2', 'row 5 col 3'])
		row_count = 5

		scroll.add(list)

		# why 6 pixel in heading
		scroll.set_size_request(-1, cell_height * (row_count+1) + 4)

		self.treeView.show_all()
		self.treeView.set_cursor_on_cell('0')
		self.store.sort_column_changed()
		sort_cell.clicked()

		return scroll

	def set_select_event(self, command):
		self.select_command = command

	def row_activated_event(self, treeview, path, view_column):
		if self.select_command != None:
			self.select_command()

	def get_select_data(self):
		select_model = self.treeView.get_selection()
		(store, iter) = select_model.get_selected()
		if iter == None:
			return None

		data = {}
		columnID = 0
		for column_data in self.config['column']:
			if 'variable' in column_data:
				data[column_data['variable']] = store.get_value(iter, columnID)
			elif 'field' in column_data:
				data[column_data['field']] = store.get_value(iter, columnID)
			columnID += 1

		return data

def	print_event():

	print 'select event called'

top_level = gtk.Window(gtk.WINDOW_TOPLEVEL)
list = list()
window = list.create_widget()
list.set_select_event(print_event)
top_level.add(window)
top_level.show_all()
gtk.main()
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to