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

Home » Public Forums » archive » Re: X-windows text events
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: X-windows text events [message #30030] Thu, 04 April 2002 08:52 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Niel Malan (Niel.Malan@aber.ac.uk) writes:

> The idea of my line-based text widget is that it should only select lines, return the selected line as GET_VALUE, and replace
> the selected line with SET_VALUE. I do that by capturing events from a text widget, examining the position of the
> cursor/selection, and then setting the selection to the beginning and end of that line. WIDGET_CONTROL's GET_VALUE and
> SET_VALUE then uses this selection.
>
> The compound widget works well, but there is some side-effect behaviour. When the widget is first started, behaviour is
> normal. However, once the compound-widget event handler has handled some events, events are generated for text selection
> attempts on all open X-windows. Sometimes this behavior disappears after working in MS windows, but returns once the event
> handler has handled events: I can't yet replicate this at will.
>
> The nett effect is that it is impossible to select text from other X-windows while my widget is running. This includes the
> IDLE and IDL online help.

Did I say "user did something wrong" theory? I meant
"IDL is nuts" theory. Sorry. :-(

I don't see anything at all wrong with the way
you wrote your compound widget. But I have to
tell you that it doesn't work so well on Windows
machines. (We might have been able to predict this.)

As I spent nearly two weeks testing one time, IDL
makes it difficult (impossible?) to select a line
of text from a text array in a text widget. There
must be something about the way lines end in Windows,
but the counting is WAY off, using the keywords you
use in your program. I find I have to select the line
twice to get the program to work properly. The first
time, it grabs characters from the line above in the
selection, although it doesn't report these extra
characters when it does the Get_Value thing.

Anyway, I don't see any of the odd sorts of things
you report. But if I did, it wouldn't surprise me
much. :-)

Cheers,

David

P.S. Let's just say I found list widgets handy for
selecting lines of text. :-)
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: X-windows text events [message #30032 is a reply to message #30030] Thu, 04 April 2002 08:22 Go to previous messageGo to next message
Niel Malan is currently offline  Niel Malan
Messages: 7
Registered: April 2002
Junior Member
On Thu, 4 Apr 2002 06:39:43 -0700, David Fanning <david@dfanning.com> wrote:
> Niel Malan (Niel.Malan@aber.ac.uk) writes:
>
>> I'm writing a compound widget, basically a text widget with modified behaviour (returning the selected line as value)
>>
>> I'm using IDL 5.4, running an X-windows on Windows NT, the server being some Compaq workstation.
>>
>> My problem is that when my widget application is running, mouse actions in other X-windows, including the IDLDE, generate
>> events. At the moment the problem is small, only bothering me when editing in the IDLDE, but I see trouble ahead.
>>
>> Am I doing something wrong, or is this just the way things are?
>
> I guess I'd put my money on the "something wrong" theory.
> But it is impossible to say what with this short description.
>

The idea of my line-based text widget is that it should only select lines, return the selected line as GET_VALUE, and replace
the selected line with SET_VALUE. I do that by capturing events from a text widget, examining the position of the
cursor/selection, and then setting the selection to the beginning and end of that line. WIDGET_CONTROL's GET_VALUE and
SET_VALUE then uses this selection.

The compound widget works well, but there is some side-effect behaviour. When the widget is first started, behaviour is
normal. However, once the compound-widget event handler has handled some events, events are generated for text selection
attempts on all open X-windows. Sometimes this behavior disappears after working in MS windows, but returns once the event
handler has handled events: I can't yet replicate this at will.

The nett effect is that it is impossible to select text from other X-windows while my widget is running. This includes the
IDLE and IDL online help.

The code is below.

Niel

This is my compound widget, created from the IDL template:

;-Get & Set Value routines -------------------------------------------------
PRO textline_set_value, id, value
stash = WIDGET_INFO(id, /CHILD)
WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY

; Set the value here.
WIDGET_CONTROL, state.id, SET_VALUE = value, /USE_TEXT_SELECT, /NO_NEWLINE

; Send an event so that the newly inserted text is selected
; If you don't do this the next SET_VALUE inserts text
id = long(state.id)
top = WIDGET_INFO(LONG(state.id), /PARENT)
handler = 0L
structure = {id: id, top: top, handler: handler}
WIDGET_CONTROL, state.id, SEND_EVENT = structure

; Restore the state.
WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY
END

FUNCTION textline_get_value, id
COMPILE_OPT hidden
ON_ERROR, 2
stash = WIDGET_INFO(id, /CHILD)
WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY

; Get the value here
WIDGET_CONTROL, state.id, GET_VALUE = value, /USE_TEXT_SELECT
; Restore the state.
WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY

;Return the value here.
RETURN, value
END

;-----Compound Widget event handler----------------------------------------------------- -------------------

FUNCTION textline_event, ev
COMPILE_OPT hidden
parent=ev.handler

;get the selection/cursor location
selection = WIDGET_INFO(ev.id, /TEXT_SELECT)
xy = WIDGET_INFO(ev.id, TEXT_OFFSET_TO_XY = selection[0])

; get the beginning of the first line of the text
start = WIDGET_INFO(ev.id, TEXT_XY_TO_OFFSET = [0,xy[1]])

; get the beginning of the second line
endt = WIDGET_INFO(ev.id, TEXT_XY_TO_OFFSET = [0,xy[1]+1]) - 1
; handle out-of-bounds end: set end to end of text
IF endt LT 0 THEN BEGIN
endt = WIDGET_INFO(ev.id, /TEXT_NUMBER)
ENDIF

; endt now must have valid value; handle invalid start by
; pointing start to the first position of the same line
IF start LT 0 THEN BEGIN
xy = WIDGET_INFO(ev.id, TEXT_OFFSET_TO_XY = endt - 1 )
start = WIDGET_INFO(ev.id, TEXT_XY_TO_OFFSET = [0,xy[1]])
ENDIF

; Set the selected text
WIDGET_CONTROL, ev.id, SET_TEXT_SELECT = [start, endt-start]
;This print statement show when the event occurred
print, start, endt, SYSTIME(0), FORMAT = '("Start: ",I4," End: ", I4, " Time: ", A0)'

RETURN, { ID:parent, TOP:ev.top, HANDLER:0L }
END

;----Widget creation routine ------------------------------------------------------------ -------------

FUNCTION cw_textline, parent, UVALUE = uval, UNAME = uname, VALUE = value, _EXTRA = extra

IF (N_PARAMS() EQ 0) THEN MESSAGE, 'Must specify a parent for cw_textline'

; Defaults for keywords
IF NOT (KEYWORD_SET(uval)) THEN uval = 0
IF NOT (KEYWORD_SET(uname)) THEN uname = 'cw_textline_UNAME'

state = { id:0 }
mainbase = WIDGET_BASE(parent, UVALUE = uval, UNAME = uname, $
EVENT_FUNC = "textline_event", $
FUNC_GET_VALUE = "textline_get_value", $
PRO_SET_VALUE = "textline_set_value")
state.id = WIDGET_TEXT(mainbase, VALUE = value, /ALL_EVENTS, YSIZE = 10)
WIDGET_CONTROL, WIDGET_INFO(mainbase, /CHILD), SET_UVALUE=state, /NO_COPY
RETURN, mainbase

END
;-----End of line-selecting compound widget ------------------------------------------------------------ ---------


This is an example widget program that uses the compound widget:


; ------- Compound widget testing program --------------
PRO textline_test_event, event
WIDGET_CONTROL, event.top, get_uvalue = tuv

IF event.id EQ tuv.button1_id THEN BEGIN
WIDGET_CONTROL, tuv.text_id, SET_VALUE = 'Replacement Text'
ENDIF

IF event.id EQ tuv.button2_id THEN BEGIN
WIDGET_CONTROL, tuv.text_id, GET_VALUE = value
PRINT, FORMAT = '("Got value: ->",A0,"<-")', value
ENDIF

RETURN
END

PRO textline_test
base = WIDGET_BASE(/ROW)
text_id = cw_textline(base, VALUE = [ 'Line of text',$
'Next Line', $
'Another line',$
'One more', $
'But this is the last one'], $
YSIZE = 10 )
button1_id = widget_button(base, VALUE = '[Set Value]')
button2_id = widget_button(base, VALUE = '[Get Value]')
ids = {text_id :text_id, button1_id: button1_id, button2_id: button2_id}
widget_control, base, SET_UVALUE = ids
widget_control, base, /realize
xmanager, 'textline_test', base, /NO_BLOCK
END

;------ End of testing program -------------------------------------
Re: X-windows text events [message #30036 is a reply to message #30032] Thu, 04 April 2002 05:39 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Niel Malan (Niel.Malan@aber.ac.uk) writes:

> I'm writing a compound widget, basically a text widget with modified behaviour (returning the selected line as value)
>
> I'm using IDL 5.4, running an X-windows on Windows NT, the server being some Compaq workstation.
>
> My problem is that when my widget application is running, mouse actions in other X-windows, including the IDLDE, generate
> events. At the moment the problem is small, only bothering me when editing in the IDLDE, but I see trouble ahead.
>
> Am I doing something wrong, or is this just the way things are?

I guess I'd put my money on the "something wrong" theory.
But it is impossible to say what with this short description.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: X-windows text events [message #30159 is a reply to message #30030] Fri, 05 April 2002 01:33 Go to previous message
Niel Malan is currently offline  Niel Malan
Messages: 7
Registered: April 2002
Junior Member
On Thu, 4 Apr 2002 09:52:27 -0700, David Fanning <david@dfanning.com> wrote:
> Niel Malan (Niel.Malan@aber.ac.uk) writes:
>
>> The idea of my line-based text widget is that it should only select lines, return the selected line as GET_VALUE, and
replace
>> the selected line with SET_VALUE. I do that by capturing events from a text widget, examining the position of the
>> cursor/selection, and then setting the selection to the beginning and end of that line. WIDGET_CONTROL's GET_VALUE and
>> SET_VALUE then uses this selection.
>>
>> The compound widget works well, but there is some side-effect behaviour. When the widget is first started, behaviour is
>> normal. However, once the compound-widget event handler has handled some events, events are generated for text selection
>> attempts on all open X-windows. Sometimes this behavior disappears after working in MS windows, but returns once the event
>> handler has handled events: I can't yet replicate this at will.
>>
>> The nett effect is that it is impossible to select text from other X-windows while my widget is running. This includes the
>> IDLE and IDL online help.
>
> Did I say "user did something wrong" theory? I meant
> "IDL is nuts" theory. Sorry. :-(

To be honest, I've also noticed some wrong-line selection during development, but it went away after I cleaned up and added
the out-of bounds handling.

> P.S. Let's just say I found list widgets handy for
> selecting lines of text. :-)

Now he tells me! But I want the GET_VALUE thing. Badly.

I'll probably be better off making a compound widget wrapper for a list widget.

Niel
sec : U Re: X-windows text events [message #30165 is a reply to message #30030] Thu, 04 April 2002 17:02 Go to previous message
Andrew Cool is currently offline  Andrew Cool
Messages: 219
Registered: January 1996
Senior Member
David Fanning wrote:
>
> Niel Malan (Niel.Malan@aber.ac.uk) writes:
>
>> The idea of my line-based text widget is that it should only select lines, return the selected line as GET_VALUE, and replace
>> the selected line with SET_VALUE. I do that by capturing events from a text widget, examining the position of the
>> cursor/selection, and then setting the selection to the beginning and end of that line. WIDGET_CONTROL's GET_VALUE and
>> SET_VALUE then uses this selection.
>
> Did I say "user did something wrong" theory? I meant
> "IDL is nuts" theory. Sorry. :-(
>
> I don't see anything at all wrong with the way
> you wrote your compound widget. But I have to
> tell you that it doesn't work so well on Windows
> machines. (We might have been able to predict this.)
>
> As I spent nearly two weeks testing one time, IDL
> makes it difficult (impossible?) to select a line
> of text from a text array in a text widget. There
> must be something about the way lines end in Windows,
> but the counting is WAY off, using the keywords you
> use in your program. I find I have to select the line
> twice to get the program to work properly. The first
> time, it grabs characters from the line above in the
> selection, although it doesn't report these extra
> characters when it does the Get_Value thing.
>
> Anyway, I don't see any of the odd sorts of things
> you report. But if I did, it wouldn't surprise me
> much. :-)
>
> Cheers,
>
> David
>
> P.S. Let's just say I found list widgets handy for
> selecting lines of text. :-)


Am I allowed to say that Niel's widget works
just fine under OpenVMS, IDL v5.4??

In terms of selecting the text anyway. It does produce
an event for every cursor movement, and the associated
print of the Start and End positions and timestamp.

Andrew

------------------------------------------------------------ ---------
Andrew D. Cool .->-.
Electromagnetics & Propagation Group `-<-'
Surveillance Systems Division Transmitted on
Defence Science & Technology Organisation 100% recycled
PO Box 1500, Salisbury electrons
South Australia 5108

Phone : 061 8 8259 5740 Fax : 061 8 8259 6673
Email : andrew.cool@dsto.defence.gov.au
------------------------------------------------------------ ---------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL FFT (spec -> interferogram)
Next Topic: X-windows text events

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

Current Time: Fri Oct 10 01:52:30 PDT 2025

Total time taken to generate the page: 0.24344 seconds