Discussion:
Context Menu ib widget_tree
(too old to reply)
mrO_o
2017-11-07 14:47:18 UTC
Permalink
Hi
i want add context menu to widget tree but i can't.
anybody can make example for me?
thanks a lot.

pro test_treecontext

tlb= widget_base(/column)
tre_bs= widget_tree(tlb, /no_bitmaps, /expanded)

tre_fo= widget_tree(tre_bs, /folder)
tre_s1= widget_tree(tre_fo, value='Size 1', /context_events) ;need context Menu
tre_s2= widget_tree(tre_fo, value='Size 2', /context_events) ;need context Menu
tre_s3= widget_tree(tre_fo, value='Size 3', /context_events) ;need context Menu


widget_control, tlb, /realize
end
klet Jegou
2017-11-29 10:20:55 UTC
Permalink
Hi,

Maybe have you find the answer to your question since, but if not, this is a way to do what you want.

I have found the explanation to do it on this two pages in Harris documentation:

http://www.harrisgeospatial.com/docs/Creating_Menus.html
https://www.harrisgeospatial.com/docs/widget_tree.html

You have also access to several examples in examples/doc/widgets subdirectory.

;-------------------------------------------------;

; Manage context_menu event
pro context_event_Handler, event
WIDGET_CONTROL, event.ID, get_value=value
case value of
'button1': BEGIN
print,'button1'
END

'button2': BEGIN
print,'button2'
END
endcase
end

; Manage classical event from the widget
pro test_treecontext_event, event

; Test for context menu events
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_CONTEXT') $
THEN BEGIN
; Obtain the widget ID of the context menu base.
contextBase = WIDGET_INFO(event.ID, $
FIND_BY_UNAME = 'contextMenu')
; Display the context menu and send its events to the
; other event handler routines.
WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, $
event.Y, contextBase
ENDIF

end


pro test_treecontext

tlb= widget_base(/column)
tre_bs= widget_tree(tlb, /no_bitmaps, /expanded, /CONTEXT_EVENTS)

tre_fo= widget_tree(tre_bs, /folder)
tre_s1= widget_tree(tre_fo, value='Size 1') ;need context Menu
tre_s2= widget_tree(tre_fo, value='Size 2') ;need context Menu
tre_s3= widget_tree(tre_fo, value='Size 3') ;need context Menu

contextMenuB = WIDGET_BASE(tre_bs, /CONTEXT_MENU, $
UNAME="contextMenu")
button1 = WIDGET_BUTTON(contextMenuB, value='button1', $
event_pro='context_event_Handler')
button2 = WIDGET_BUTTON(contextMenuB, value='button2', $
event_pro='context_event_Handler')


widget_control, tlb, /realize

; Handle the events from the GUI.
XMANAGER, 'test_treecontext', tlb, /NO_BLOCK
End

;-------------------------------------------------;

Klet

Continue reading on narkive:
Loading...