Sign up

example gtkd program that has a timeout

Can somebody point me to an example gtkd program that has an object of class Timeout in it?

I want to code up an action to repeatedly take place (under some conditions) and i think a Timeout would be ideal. (Something like a button gets pressed, it creates a timeout, and then does the action at the end of the timeout, and repeats until the button is released.)

I can sort of guess around about how it might be done, but if there's an existing gtkd program that does it, then i would prefer to take a look at that first. And this is so common, i'm sure there must be one, but i can't seem to google around well enough to find it.

TIA for any pointers or other advice!

dan

Re: example gtkd program that has a timeout

On Tue, 21 Jun 2016 20:51:10 GMT, dan hitt wrote:

Can somebody point me to an example gtkd program that has an object of class Timeout in it?

I want to code up an action to repeatedly take place (under some conditions) and i think a Timeout would be ideal. (Something like a button gets pressed, it creates a timeout, and then does the action at the end of the timeout, and repeats until the button is released.)

I can sort of guess around about how it might be done, but if there's an existing gtkd program that does it, then i would prefer to take a look at that first. And this is so common, i'm sure there must be one, but i can't seem to google around well enough to find it.

TIA for any pointers or other advice!

dan

I use a timeout in but it's a fairly large code base rather then a simple example, hopefully it's of use anyway.

https://github.com/gnunn1/terminix/blob/master/source/gx/terminix/terminal/terminal.d

Re: example gtkd program that has a timeout

On Wed, 22 Jun 2016 13:43:00 GMT, Gerald Nunn wrote:

On Tue, 21 Jun 2016 20:51:10 GMT, dan hitt wrote:

Can somebody point me to an example gtkd program that has an object of class Timeout in it?

.....

I use a timeout in but it's a fairly large code base rather then a simple example, hopefully it's of use anyway.

https://github.com/gnunn1/terminix/blob/master/source/gx/terminix/terminal/terminal.d

Thanks Gerald.

Your reference is very helpful, and i was able to imitate it nearly successfully.

I have one residual problem that i know of:
I tend to get messages of this form:

GLib-CRITICAL **: Source ID NNN was not found when attempting to remove it

and i'm not sure what to attribute it to, since d does its own garbage collection
(so i guess i'm already assuming this is a GC issue).

In the course of your development, did you ever run into this?

(Note that i'm using gdc not dmd.)

TIA for any info, and thanks again for your help.

dan

Re: example gtkd program that has a timeout

On 06/26/2016 01:35 AM, dan hitt wrote:

On Wed, 22 Jun 2016 13:43:00 GMT, Gerald Nunn wrote:

On Tue, 21 Jun 2016 20:51:10 GMT, dan hitt wrote:

Can somebody point me to an example gtkd program that has an object of class Timeout in it?
.....

I use a timeout in but it's a fairly large code base rather then a simple example, hopefully it's of use anyway.

https://github.com/gnunn1/terminix/blob/master/source/gx/terminix/terminal/terminal.d

Thanks Gerald.

Your reference is very helpful, and i was able to imitate it nearly successfully.

I have one residual problem that i know of:
I tend to get messages of this form:

GLib-CRITICAL **: Source ID NNN was not found when attempting to remove it

and i'm not sure what to attribute it to, since d does its own garbage collection
(so i guess i'm already assuming this is a GC issue).

In the course of your development, did you ever run into this?

(Note that i'm using gdc not dmd.)

TIA for any info, and thanks again for your help.

dan

probably because this change:

https://github.com/gtkd-developers/GtkD/commit/1f2d06b4e9b7614a2da13f74f30f6db5fbb7bf75

hasn't made it into a release yet.

Re: example gtkd program that has a timeout

On Sat, 25 Jun 2016 23:35:11 GMT, dan hitt wrote:

On Wed, 22 Jun 2016 13:43:00 GMT, Gerald Nunn wrote:

On Tue, 21 Jun 2016 20:51:10 GMT, dan hitt wrote:

Can somebody point me to an example gtkd program that has an object of class Timeout in it?
.....

I use a timeout in but it's a fairly large code base rather then a simple example, hopefully it's of use anyway.

https://github.com/gnunn1/terminix/blob/master/source/gx/terminix/terminal/terminal.d

.....

I have one residual problem that i know of:
I tend to get messages of this form:

GLib-CRITICAL **: Source ID NNN was not found when attempting to remove it

and i'm not sure what to attribute it to, since d does its own garbage collection
(so i guess i'm already assuming this is a GC issue).

Just a little follow up on this:

First, the code i imitated from Gerald works perfectly as he presented it (earlier i was not being careful enough).

I do have the residual problem when i aggressively nest the Timeouts.

Ideally, i would like to be able to modify the timeout period of the Timeout when it fires, but it's not so clear how to do this: If i get recursive, and let each timer fire only once and start a new one with a different period, then, when i terminate the program i get a huge pile of these 'Source ID *** was not found when attempting to remove it' messages.

So what i did instead was to set the timeout period to be very short, but just not do my action each time. That is, i hacked in a little automaton that counts the number of times we've timed out, and does the action only each n times, where n gets smaller and smaller as time wears on.

This complete avoids the 'Source ID was not found ...' messages, but it is undesirable as it is polling behavior. Not polling in a tight loop, but nevertheless polling every 20 milliseconds or so.

So if anybody knows of a way to change the timeout period of a Timeout when it executes its delegate, please let me know.

And Gerald, thanks again for your help and showing your code. It puts my code in a much, much better state.

Re: example gtkd program that has a timeout

On Sun, 26 Jun 2016 11:36:09 +0200, Mike Wey wrote:

On 06/26/2016 01:35 AM, dan hitt wrote:

On Wed, 22 Jun 2016 13:43:00 GMT, Gerald Nunn wrote:

On Tue, 21 Jun 2016 20:51:10 GMT, dan hitt wrote:

Can somebody point me to an example gtkd program that has an object of class Timeout in it?
.....

.......

I have one residual problem that i know of:
I tend to get messages of this form:

GLib-CRITICAL **: Source ID NNN was not found when attempting to remove it

........

probably because this change:

https://github.com/gtkd-developers/GtkD/commit/1f2d06b4e9b7614a2da13f74f30f6db5fbb7bf75

hasn't made it into a release yet.

Thanks Mike, somehow i didn't see your reply earlier.

For simple enough usage i don't have this problem --- i do get it when i create timers within timers, but it's certainly possible that those are my bugs and no-one else's.

What would be extremely useful, imvho, would be some means to change the timeout period when the delegate gets executed. Of course if there's not underlying support for this in gtk it would not be reasonable to add it at the d-level.

I would like to say though that i really appreciate the work you've put in on gtkd.

I think it gtkd fills in a very big and important hole.

dan