Re: Tree using wxEuphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

The event handler you suggested works well as described.
I have still not understood
1. The sequence "items"
2. The "void" in the following line, although I have copied and modified it:

  void = add_tree_item( tree, items[i][2][j][1], nums3[i][j][k], qimg2,qimg2) 

3. I have failed to decipher exact structure of the sequence "items", to make it more meaningful in my modified demo as follows:-

-- #!/home/matt/euphoria/bin/exu 
-- tree-demo-modified.exw 
-- wxEuphoria tree control demo modified 
-- To demonstrate, open out the tree to any extent, and right click on any of the items. 
 
-- We start with the required includes 
include std/text.e 
include wxeu/wxeud.e 
include tbar_xpm.e 
 
without warning 
object void 
 
-- Create the main window 
global constant 
  main 	= create( wxFrame, {0, -1, "wxTreeCtrl and wxListCtrl Demo" }), 
  win		= create( wxPanel, main ), 
  tree	= create( wxTreeCtrl, win), 
  list	= create( wxListCtrl, win), 
  $ 
 
-- Create the image list 
global constant 
  ilist	= create( wxImageList, {24, 24, 1, 0}), 
  Bitmap1 = create( wxBitmap, {BM_XPM, copy_xpm}), 
  Bitmap2 = create( wxBitmap, {BM_XPM, paste_xpm}), 
  Bitmap3 = create( wxBitmap, {BM_XPM, ok_xpm}), 
  Bitmap4 = create( wxBitmap, {BM_XPM, left_arrow_xpm}), 
  Bitmap5 = create( wxBitmap, {BM_XPM, right_arrow_xpm}), 
  i1		= add_image( ilist, Bitmap1, 0 ), 
  i2		= add_image( ilist, Bitmap2, 0 ), 
  i3		= add_image( ilist, Bitmap3, 0 ), 
  i4		= add_image( ilist, Bitmap4, 0 ), 
  i5		= add_image( ilist, Bitmap5, 0 ), 
  images  = {i1, i2, i3, i4, i5}, 
  $ 
 
-- Execute the procedure setup 
setup() 
 
-- The functions and procedures used above 
function rand_image() 
	integer i 
	i = rand(4) + 1 
	return images[i] 
end function 
 
procedure setup() 
	atom root, parent, hsizer, qimg1, qimg2, qimg3 
	sequence nums,nums2, items, nums3A,nums3B, nums3C,nums3 
 
	-- assign an imagelist to the tree	 
	tree_imagelist( tree, ilist ) 
 
      -- The variables nums, nums2, and nums3 can be changed to suit your needs 
	nums = { "one", "two", "three" } 
	nums2 = {  
         { "One-Sub", "Two-Sub", "Three-Sub" }, 
         { "Four-Sub", "Five-Sub", "Six-Sub" }, 
         { "Seven-Sub", "Eight-Sub", "Nine-Sub" } } 
	nums3A = { { "ABC1", "BCD1", "DEF1" }, 
         { "EFG1", "FGH1", "GHI1" }, 
         { "HIJ1", "IJK1", "JKL1" } } 
	nums3B = { { "ABC2", "BCD2", "DEF2" }, 
         { "EFG2", "FGH2", "GHI2" }, 
         { "HIJ2", "IJK2", "JKL2" } } 
	nums3C = { { "ABC3", "BCD3", "DEF3" }, 
         { "EFG3", "FGH3", "GHI3" }, 
         { "HIJ3", "IJK3", "JKL3" } } 
      nums3 = {nums3A,nums3B,nums3C} 
	-- add the root item 
      qimg1 = images[5] 
      qimg2 = images[4] 
	root = add_tree_root( tree, "Demo", qimg1, qimg1) 
	-- add three layers of children to the tree 
	items = repeat({0,  repeat( {0, { 0,  repeat( 0, 3 ) }}, 3 )}, 3) 
	for i = 1 to 3 do 
		items[i][1] = add_tree_item( tree, root, nums[i], qimg1,qimg1) 
		for j = 1 to 3 do 
			items[i][2][j][1] = add_tree_item( tree, items[i][1], nums2[i][j] , qimg1,qimg1) 
			for k = 1 to 3 do 
				void = add_tree_item( tree, items[i][2][j][1], nums3[i][j][k], qimg2,qimg2) 
			end for 
		end for 
	end for 
 
	-- add two columns to the list 
	void = insert_list_column( list, 0, "Numbers", 0, -1 ) 
	void = insert_list_column( list, 1, "#", 0, -1 ) 
	 
	-- assign the image list to the list 
	list_imagelist( list, ilist, wxIMAGE_LIST_SMALL ) 
	 
	-- add three items to the list with text in each column 
	for i = 1 to 3 do 
		void = insert_listctrl_item( list, i-1, {nums[i], sprint(i)}, rand_image()) 
	end for 
	void = insert_listctrl_item( list, 3, {"Four", sprint(4)}, -1) 
	 
	-- put the controls into sizers 
	hsizer = create( wxBoxSizer, wxHORIZONTAL ) 
	add_window_to_sizer( hsizer, tree, 1, wxGROW, 0 ) 
	add_window_to_sizer( hsizer, list, 1, wxGROW, 0 ) 
	set_sizer( win, hsizer ) 
end procedure 
 
-- procedures for all event handlers here. 
-- keep the procedure and event handler together. 
procedure on_right_click(atom this, atom event_type, atom id, atom event )  
	atom item = get_tree_event_item( event )  
      -- Show the right clicked item 
	message_box( get_tree_text( tree, item ), "right click", wxOK )  
end procedure  
set_event_handler( tree, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, routine_id("on_right_click") )  
 
-- draw and show the window 
wxMain( main ) 
 

Thanks again. I am using Win XP Pro with SP2
and Euphoria 4.0.3 wxEuphoria ver 16

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu