comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Updateable Message Widget
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
RE: Updateable Message Widget [message #4847 is a reply to message #4755] Thu, 03 August 1995 00:00 Go to previous messageGo to previous message
mallozzi is currently offline  mallozzi
Messages: 60
Registered: August 1994
Member
Here is a simple widget program that mimics IDL's WMENU.
It is useful to provide a message notification or to query
the user for a response. You call it just like WMENU, and there
are a couple extra keywords, too.

-Bob Mallozzi

- - - - - - - - - - - - - - - - - - SNIP, SNIP - - - - - - - - - - - - - - - - -

; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;+
; NAME:
; WIDMENU
;
; PURPOSE:
; Widget version of WMENU, plus optional SCROLL bar
;
; CATEGORY:
; WIDGETS
;
; CALLING SEQUENCE:
; RESULT = WIDMENU(SELECTIONS, [TITLE = , INITIAL = , /SCROLL, SIZE = ])
;
; INPUTS:
; SELECTIONS: STRARR of the menu selections
;
; KEYWORD PARAMETERS:
; TITLE: the title
; INITIAL: the inital cursor selection
; SCROLL: adds a scroll bar
; WIDTH: width of the widget in pixels (height is set automatically
; based on the number of buttons)
;
; OUTPUTS:
; RESULT = index of the menu item (including TITLE, if supplied)
;
; COMMON BLOCKS:
; NONE
;
; SIDE EFFECTS:
; Creates a button widget
;
; RESTRICTIONS:
; TITLE can only be a single line on the widget
;
; PROCEDURE:
; Mimics WMENU
;
; EXAMPLES:
; Error notification message:
; INDEX = WIDMENU(['ERROR Opening File to Read', 'OK'], $
; title = 0, initial = 1)
;
; QUIT confirmation:
; INDEX = WIDMENU(['Do you really want to QUIT?', 'Yes', 'No'], $
; title = 0, initial = 1)
;
; MODIFICATION HISTORY:
; Written, mallozzi@gibson.msfc.nasa.gov, Dec 1994.
;-

FUNCTION WIDMENU, SELECTIONS, TITLE = TITLE, SCROLL = SCROLL, $
INITIAL = INITIAL, WIDTH = WIDTH


; Save the device, in case it's not 'X'
DEVICE_SAVE = !D.NAME
SET_PLOT, 'X'

NUM_BUTTONS = N_ELEMENTS(SELECTIONS)

IF (N_ELEMENTS(TITLE) NE 0) THEN BEGIN
IF (TITLE GT NUM_BUTTONS) THEN TITLE = NUM_BUTTONS - 1
TTITLE = SELECTIONS(TITLE)
LOCAL_SELECTIONS = SELECTIONS(WHERE(INDGEN(NUM_BUTTONS) NE TITLE))
TCHECK = 1
ENDIF ELSE BEGIN
TTITLE = ''
LOCAL_SELECTIONS = SELECTIONS
TCHECK = 0
ENDELSE

; Parent
IF (N_ELEMENTS(WIDTH) NE 0) THEN BEGIN
MENU_BASE = WIDGET_BASE(TITLE=' ', /COLUMN, XSIZE = WIDTH)
ENDIF ELSE BEGIN
MENU_BASE = WIDGET_BASE(TITLE=' ', /COLUMN)
ENDELSE

; Add the title, if it's supplied
IF (N_ELEMENTS(TITLE) NE 0) THEN T_BASE = WIDGET_LABEL(MENU_BASE, VALUE=TTITLE)

; Selection buttons
IF (KEYWORD_SET(SCROLL)) THEN BEGIN
SUB_BASE = WIDGET_BASE(MENU_BASE, /COLUMN, /FRAME, /SCROLL)
ENDIF ELSE BEGIN
SUB_BASE = WIDGET_BASE(MENU_BASE, /COLUMN, /FRAME)
ENDELSE

M_BUT = LONARR(NUM_BUTTONS)
FOR i=0, N_ELEMENTS(LOCAL_SELECTIONS)-1 DO BEGIN
M_BUT(i) = WIDGET_BUTTON(SUB_BASE, VALUE = LOCAL_SELECTIONS(i), UVALUE = i)
ENDFOR

; Make it so
WIDGET_CONTROL, MENU_BASE, /REALIZE

; An attempt to get the widget to appear in the center of the screen.
; Disabled because it causes the widget to flash in the UL corner, and
; then reappear in the center of the screen. One should be able to
; use the command WIDGET_CONTROL, MENU_BASE, /REALIZE, MAP = 0, but
; this does not do what one expects. When a widget is /REALIZED, apparently
; it MUST make an appearance on the screen...
;
;DEVICE, GET_SCREEN_SIZE = CURRENT_SCREEN
;WIDGET_CONTROL, MENU_BASE, TLB_GET_SIZE = MENU_SIZE
;MENU_CENTER = [(CURRENT_SCREEN(0) / 2.0) - (MENU_SIZE(0) / 2.0), $
; (CURRENT_SCREEN(1) / 2.0) - (MENU_SIZE(1) / 2.0)]
;WIDGET_CONTROL, MENU_BASE, $
; TLB_SET_XOFFSET = MENU_CENTER(0), $
; TLB_SET_YOFFSET = MENU_CENTER(1)

; Place the cursor
LNUM = N_ELEMENTS(LOCAL_SELECTIONS)
IF (N_ELEMENTS(INITIAL) NE 0) THEN BEGIN
IF (TCHECK EQ 1) THEN BEGIN
CASE 1 OF
(TITLE GE INITIAL) : SPOT = INITIAL
(TITLE LT INITIAL) : SPOT = INITIAL - 1
(INITIAL GT LNUM) : SPOT = LNUM - 1
ELSE : SPOT = 0
ENDCASE
ENDIF ELSE BEGIN
CASE 1 OF
(INITIAL GT LNUM) : SPOT = LNUM -1
ELSE : SPOT = INITIAL
ENDCASE
ENDELSE
IF (SPOT LT 0) THEN SPOT = 0
ENDIF ELSE BEGIN
SPOT = 0
ENDELSE
WIDGET_CONTROL, M_BUT(SPOT), /INPUT_FOCUS

; Get the event, without using XMANAGER
EVENT = WIDGET_EVENT(MENU_BASE)

; Process the event
TYPE = TAG_NAMES(EVENT, /STRUCTURE)
CASE TYPE OF

; The button widget events
'WIDGET_BUTTON': BEGIN
WIDGET_CONTROL,EVENT.ID,GET_VALUE = VALUE,GET_UVALUE = UVALUE

FOR I=0, N_ELEMENTS(LOCAL_SELECTIONS)-1 DO BEGIN
IF (UVALUE EQ I) THEN BEGIN
WIDGET_CONTROL, EVENT.TOP, /DESTROY
IF (TCHECK EQ 1) THEN BEGIN
IF (I GE TITLE) THEN ADD_I = TCHECK ELSE ADD_I = 0
ENDIF ELSE ADD_I = 0
SET_PLOT, DEVICE_SAVE
RETURN, I + ADD_I
ENDIF
ENDFOR
END

ENDCASE ; for TYPE


END
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Increasing the whitespace between plot axes and the label?
Next Topic: Does anyone have any experience with using SciDB with IDL (or any other language)?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:29:01 PDT 2025

Total time taken to generate the page: 0.00363 seconds