1. EuGTK - GTK_SELECTION_SINGLE?

In GtkEnums.e I find:
GTK_SELECTION_NONE = 0,
GTK_SELECTION_SINGLE,
GTK_SELECTION_BROWSE,
GTK_SELECTION_MULTIPLE,

http://scentric.net/tutorial/sec-sel-click-menus.html

6.1.1. Selection Modes 
 
You can use gtk_tree_selection_set_mode to influence the way that selections are handled. There are four selection modes: 
 
GTK_SELECTION_NONE - no items can be selected 
 
GTK_SELECTION_SINGLE - no more than one item can be selected 
 
GTK_SELECTION_BROWSE - exactly one item is always selected 
 
GTK_SELECTION_MULTIPLE - anything between no item and all items can be selected 

Does this mean there is a way to do a single click event on a listview?

Single click would make more sense than double click in DMAK.

new topic     » topic index » view message » categorize

2. Re: EuGTK - GTK_SELECTION_SINGLE?

Jerry_Story said...

In GtkEnums.e I find:
GTK_SELECTION_NONE = 0,
GTK_SELECTION_SINGLE,
GTK_SELECTION_BROWSE,
GTK_SELECTION_MULTIPLE,

}}}

Does this mean there is a way to do a single click event on a listview?

Single click would make more sense than double click in DMAK.

There is a way to do a single click event, but the above is not it.

To react to a single item being clicked once, you need to connect to the treeview/listview's selection "changed" signal, as in:

constant selection = get(tv,"selection") 
connect(selection,"changed",foo,[data]) -- data optional 

Be aware that there is a 'gotcha' that comes with deciding to use this. Using the up/down arrow keys also changes the selection!

Therefore - the proper way to do this is to allow multiple selections, and put an OK button somewhere to initiate the transfer.

http://etcwebspace.com/users/irvm/multisel.jpg

The SELECTION_NONE/SINGLE/MULTIPLE above refers to whether you want to be able to have selected (as in, highlighted) more than one row at a time. test33exp.ex demos this.

You can select several random items on a list by ctl-click, or several adjacent items by 'rubber banding' them (right-mouse-button and drag across to select).

Of course, when using multiple-selections, you can't respond to the first mouse click - so in those cases, you would want to have a button to push when the selection process was complete.

new topic     » goto parent     » topic index » view message » categorize

3. Re: EuGTK - GTK_SELECTION_SINGLE?

If you want to respond to a single-click of a mouse button, try connecting a generic event to the treeview/listview, then filtering the events to respond only to one particular mouse event:

function Foo(atom ctl, atom event) 
if peek(event) = 7 then -- mouse button released 
 if peek(event+40) = 1 then -- mouse left button 
  puts(1,get(tv,"text",column#)) 
 end if 
end if 
return 0 
end function 
constant foo = call_back(routine_id("Foo")) 
 
connect(tv,"event",foo) 

We wait for the button release, rather than getting the contents of the tv on mouse pressed (since the focus may not have changed to the control where the mouse is now sitting).

Alternate way, if you need the button #:

if peek(event) = 4 then -- some mouse button pressed 
 whichbtn = peek(event+40) -- 1, 2, or 3 == left, mid, right 
... 

Responding to a single-click means you can't select multiple items via "rubber banding". You still have ctl-click for that.

new topic     » goto parent     » topic index » view message » categorize

4. Re: EuGTK - GTK_SELECTION_SINGLE?

irv said...

To react to a single item being clicked once, you need to connect to the treeview/listview's selection "changed" signal, as in:

constant selection = get(tv,"selection") 
connect(selection,"changed",foo,[data]) -- data optional 

Be aware that there is a 'gotcha' that comes with deciding to use this. Using the up/down arrow keys also changes the selection!

That 'gotcha' would be correct behavior in DMAK.

I am confused about how to use that code. A demo probably would suffice.

new topic     » goto parent     » topic index » view message » categorize

5. Re: EuGTK - GTK_SELECTION_SINGLE?

include GtkEngine.e 
include GtkListView.e as LV  
-- note change in name from ListView to GtkListView for 
-- consistency with EuGTK_4.3.0  
-- [[http://sourceforge.net/projects/eugtk/]] 
 
constant veg = { 
	{"Asparagus","raw",23,8,9}, 
	{"Beet greens","boiled",164,12,11}, 
	{"Broccoli","raw",43,14,23}, 
	{"Cabbage","boiled",36,6}, 
	{"Chard, swiss","boiled",102,5}, 
	{"Collards","boiled",266,4}, 
	{"Onions","raw",37,10} 
} 
 
object lv = LV:Iter(4)  
 
constant tv  = LV:View(lv,{"Name","prep","mg/oz","Serving (oz)"})  
	set(tv,"rules hint",TRUE) -- shade alternate lines 
	set(tv,"grid lines",GTK_TREE_VIEW_GRID_LINES_BOTH) 
 
object store = LV:Store({gSTR,gSTR,gINT,gINT})  
	set(tv,"model",store) 
	 
constant win = create(GtkWindow)  
	connect(win,"destroy",quit) 
	set(win,"border width",5) 
 
constant panel = create(GtkVBox) 
	add(win,panel) 
	add(panel,tv) 
 
for i = 1 to length(veg) do -- load the list store with data 
   LV:Row(lv,store,veg[i],1)  
end for 
 
show_all(win) 
 
function Foo(atom ctl, atom event) 
if peek(event) = 7 then 
	if peek(event+40) = 1 then -- left btn, 2=mid, 3=right 
		printf(1,"%s\n",{get(tv,"text",1)}) -- txt from first column 
	end if 
end if 
return 0 
end function 
connect(tv,"event",call_back(routine_id("Foo"))) 
 
/*  

 alternate: replace above with this and see which one works best.  
 Be aware that this method may cause false events to be triggered  
 Sorting, for example, would cause a change, as might  
 adding or deleting an item from the list! 
*/ 
 
/* 

function Foo() 
   printf(1,"%s\n",{get(tv,"text",1)}) 
 return 1 
 end function 
constant selection = get(tv,"selection") 
connect(selection,"changed",call_back(routine_id("Foo"))) 
*/ 
 
main() 
new topic     » goto parent     » topic index » view message » categorize

6. Re: EuGTK - GTK_SELECTION_SINGLE?

irv said...
function Foo(atom ctl, atom event) 
if peek(event) = 7 then 
	if peek(event+40) = 1 then -- left btn, 2=mid, 3=right 
		printf(1,"%s\n",{get(tv,"text",1)}) -- txt from first column 
	end if 
end if 
return 0 
end function 
connect(tv,"event",call_back(routine_id("Foo"))) 

It works perfectly.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu