Re: [racket-users] Re: Posting Events To Window Asynchronously From Different Thread?

2018-11-19 Thread Jason Stewart
I tried queue-callback this evening.  Just what I needed!  Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Posting Events To Window Asynchronously From Different Thread?

2018-11-19 Thread Jason Stewart
I tried queue-callback this evening.  Just what I needed!  Thank you.

On Monday, November 19, 2018 at 6:31:04 PM UTC-6, Alex Harsanyi wrote:
>
> The `send-message-to-window` has a corresponding `on-message` method which 
> needs to be implemented in the target control for it to do something useful 
> so it is not a general replacement for `PostMessage`, but it can be used 
> for cases where PostMessage is called with WM_USER, messages.
>
> The Windows `PostMessage` function is used for posting any message, and 
> windows GUI uses messages for everything.  For example, to set the icon for 
> a toplevel window, one can send the WM_SETICON message as in:
>
> PostMessage(aWindow, WM_SETICON, ICON_SMALL, anIcon)
>
> The way to do hat in Racket is to call `set-icon`: 
>
> (send a-frame set-icon an-icon #f 'small)
>
> However, the above call will have unexpected results if called from a 
> thread that is not the event handling thread: the correct way to make the 
> call from another thread is to use `queue-callback` like so:
>
> (queue-callback (lambda () (send a-frame set-icon an-icon #f 'small))
>
> I am not sure which methods on GUI classes are safe to be called from a 
> non-event handling thread, but most of them are not, so I use 
> `queue-callback` for all such cases.  The PostMessage call works from any 
> thread, not just the event handling thread, so this problem does exist in 
> the Win32 API.
>
> Alex.
>
> On Tuesday, November 20, 2018 at 6:32:14 AM UTC+8, Philip McGrath wrote:
>>
>> There is a send-message-to-window function (
>> http://docs.racket-lang.org/gui/Windowing_Functions.html#%28def._%28%28lib._mred%2Fmain..rkt%29._send-message-to-window%29%29),
>>  
>> though I've never used it, and it sounds like it is different from what you 
>> describe.
>>
>> -Philip
>>
>>
>> On Mon, Nov 19, 2018 at 5:22 PM Alex Harsanyi  
>> wrote:
>>
>>>
>>>
>>> I think `queue-callback` is the closest "general" equivalent: it allows 
>>> invoking methods on GUI objects from outside the event handler thread.  It 
>>> can also be used to schedule some work to be done outside a GUI widget's 
>>> callback invocation.
>>>
>>> If you actually want to post specific messages to a window, you will 
>>> have to map "PostMessage" via FFI and you can find the target window handle 
>>> using `get-client-handle`. This will only work on the windows platform.
>>>
>>>
>>> https://docs.racket-lang.org/gui/Windowing_Functions.html?q=ququq-callback#%28def._%28%28lib._mred%2Fmain..rkt%29._queue-callback%29%29
>>>
>>> Alex.
>>>
>>> On Monday, November 19, 2018 at 7:42:12 PM UTC+8, Jason Stewart wrote:

 In Windows, we have a SendMessage() function for dispatching a window 
 event synchronously, and PostMessage() for asynchronously queuing an event 
 to a specified window from any thread.

 Is there a way to do PostMessage() from Racket's GUI library?

 Eventspaces feels warm, but couldn't find what I was looking for in it:


 https://docs.racket-lang.org/gui/windowing-overview.html?q=sleep#%28part._eventspaceinfo%29


 -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to racket-users...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Posting Events To Window Asynchronously From Different Thread?

2018-11-19 Thread Alex Harsanyi
The `send-message-to-window` has a corresponding `on-message` method which 
needs to be implemented in the target control for it to do something useful 
so it is not a general replacement for `PostMessage`, but it can be used 
for cases where PostMessage is called with WM_USER, messages.

The Windows `PostMessage` function is used for posting any message, and 
windows GUI uses messages for everything.  For example, to set the icon for 
a toplevel window, one can send the WM_SETICON message as in:

PostMessage(aWindow, WM_SETICON, ICON_SMALL, anIcon)

The way to do hat in Racket is to call `set-icon`: 

(send a-frame set-icon an-icon #f 'small)

However, the above call will have unexpected results if called from a 
thread that is not the event handling thread: the correct way to make the 
call from another thread is to use `queue-callback` like so:

(queue-callback (lambda () (send a-frame set-icon an-icon #f 'small))

I am not sure which methods on GUI classes are safe to be called from a 
non-event handling thread, but most of them are not, so I use 
`queue-callback` for all such cases.  The PostMessage call works from any 
thread, not just the event handling thread, so this problem does exist in 
the Win32 API.

Alex.

On Tuesday, November 20, 2018 at 6:32:14 AM UTC+8, Philip McGrath wrote:
>
> There is a send-message-to-window function (
> http://docs.racket-lang.org/gui/Windowing_Functions.html#%28def._%28%28lib._mred%2Fmain..rkt%29._send-message-to-window%29%29),
>  
> though I've never used it, and it sounds like it is different from what you 
> describe.
>
> -Philip
>
>
> On Mon, Nov 19, 2018 at 5:22 PM Alex Harsanyi  > wrote:
>
>>
>>
>> I think `queue-callback` is the closest "general" equivalent: it allows 
>> invoking methods on GUI objects from outside the event handler thread.  It 
>> can also be used to schedule some work to be done outside a GUI widget's 
>> callback invocation.
>>
>> If you actually want to post specific messages to a window, you will have 
>> to map "PostMessage" via FFI and you can find the target window handle 
>> using `get-client-handle`. This will only work on the windows platform.
>>
>>
>> https://docs.racket-lang.org/gui/Windowing_Functions.html?q=ququq-callback#%28def._%28%28lib._mred%2Fmain..rkt%29._queue-callback%29%29
>>
>> Alex.
>>
>> On Monday, November 19, 2018 at 7:42:12 PM UTC+8, Jason Stewart wrote:
>>>
>>> In Windows, we have a SendMessage() function for dispatching a window 
>>> event synchronously, and PostMessage() for asynchronously queuing an event 
>>> to a specified window from any thread.
>>>
>>> Is there a way to do PostMessage() from Racket's GUI library?
>>>
>>> Eventspaces feels warm, but couldn't find what I was looking for in it:
>>>
>>>
>>> https://docs.racket-lang.org/gui/windowing-overview.html?q=sleep#%28part._eventspaceinfo%29
>>>
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Posting Events To Window Asynchronously From Different Thread?

2018-11-19 Thread Philip McGrath
There is a send-message-to-window function (
http://docs.racket-lang.org/gui/Windowing_Functions.html#%28def._%28%28lib._mred%2Fmain..rkt%29._send-message-to-window%29%29),
though I've never used it, and it sounds like it is different from what you
describe.

-Philip


On Mon, Nov 19, 2018 at 5:22 PM Alex Harsanyi 
wrote:

>
>
> I think `queue-callback` is the closest "general" equivalent: it allows
> invoking methods on GUI objects from outside the event handler thread.  It
> can also be used to schedule some work to be done outside a GUI widget's
> callback invocation.
>
> If you actually want to post specific messages to a window, you will have
> to map "PostMessage" via FFI and you can find the target window handle
> using `get-client-handle`. This will only work on the windows platform.
>
>
> https://docs.racket-lang.org/gui/Windowing_Functions.html?q=ququq-callback#%28def._%28%28lib._mred%2Fmain..rkt%29._queue-callback%29%29
>
> Alex.
>
> On Monday, November 19, 2018 at 7:42:12 PM UTC+8, Jason Stewart wrote:
>>
>> In Windows, we have a SendMessage() function for dispatching a window
>> event synchronously, and PostMessage() for asynchronously queuing an event
>> to a specified window from any thread.
>>
>> Is there a way to do PostMessage() from Racket's GUI library?
>>
>> Eventspaces feels warm, but couldn't find what I was looking for in it:
>>
>>
>> https://docs.racket-lang.org/gui/windowing-overview.html?q=sleep#%28part._eventspaceinfo%29
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.