# File system event?

**URL:** <https://www.ruby-forum.com/t/file-system-event/190956>\
**Category:** wxRuby\
**Created:** [July 1, 2010, 5:00pm UTC](https://www.ruby-forum.com/t/file-system-event/190956 "2010-07-01T17:00:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [July 1, 2010, 5:00pm UTC](https://www.ruby-forum.com/t/file-system-event/190956/1 "2010-07-01T17:00:24Z")

</div>

Hey.

I am making a little TaskBar app, whos task it is to monitor a file and  
change icon when the file is updated.

First is there any way to catch a file change event direct in WxRuby?  
Does WxRuby have a way to catch system event directly?

If I can’t do it in WxRuby, how do I then combine the RInotify package  
with WxRuby.

Exactly where do I put the rinotify.wait\_for\_events call ?

Is there some way to a it to the App.main\_loop ?

Or should put it in a evt\_idle? This might slow down UI.

Or should I try to figure out how to make a separate thread that  
could wait and then generate a custom event.

So what do you think, have any of you tried any thing like it before?

PS. I am working on a linux box.

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [July 2, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/file-system-event/190956/2 "2010-07-02T18:23:37Z")

</div>

On 01/07/2010 15:59, Svend Haugaard Sørensen wrote:

> I am making a little TaskBar app, whos task it is to monitor a file and  
> change icon when the file is updated.
> 
> First is there any way to catch a file change event direct in WxRuby?  
> Does WxRuby have a way to catch system event directly?

No, not in the version of wxWidgets we’re based on. I think there’s been  
a recent GSOC project to add file system notifications to wxWidgets.

> If I can’t do it in WxRuby, how do I then combine the RInotify package  
> with WxRuby.
> 
> Exactly where do I put the rinotify.wait\_for\_events call ?

I don’t know RInotify, but I think you may need to use threads if it’s  
the kind of call that waits and hands to a block (similar to TCP servers  
in Ruby).

> Is there some way to a it to the App.main\_loop ?

Not if the execution stops in wait\_for\_events - your whole UI will stop.

> Or should put it in a evt\_idle? This might slow down UI.

evt\_idle are intended to do a short something then return.

> Or should I try to figure out how to make a separate thread that  
> could wait and then generate a custom event.
> 
> So what do you think, have any of you tried any thing like it before?

Yes, this is the way to go I’d think. It’s perfectly do-able but needs  
more care. If using 1.8, you need to manually nudge Ruby’s thread  
scheduler to give time to the RInotify thread. If using 1.9, this won’t  
be needed, but you must not call GUI update code in the non-wx thread.  
GUI updates must be signalled by posting a Wx::Event to the GUI loop.

a
