Timer, TimeOut

Linux specific forum
frederic
User
User
Posts: 56
Joined: Thu Jan 05, 2006 11:22 pm

Timer, TimeOut

Post by frederic »

An example of a function called every second

Code: Select all

; http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add

Global stoptimer = #False

Procedure MyTimeOutFunction(*pdata.l)
  Debug "hello"
  If stoptimer = #False
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 300, 50, "TimeOut example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  If CreateGadgetList(WindowID(0))
    ButtonGadget(1, 10, 10, 280, 30, "Stop timer")
  EndIf 
  
  g_timeout_add_(1000, @MyTimeOutFunction(), #Null)
  
  Repeat
  
  If EventGadget() = 1
    stoptimer = #True
    DisableGadget(1, 1)
  EndIf
  
  Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
08/03/08 - change gtk_timeout_add to g_timeout_add
Last edited by frederic on Sat Mar 08, 2008 1:48 pm, edited 1 time in total.
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Hey thats cool... thanks! :)
-Beach
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

The GTK+ Reference Manual says gtk_timeout_add has been deprecated since version 2.4.
frederic
User
User
Posts: 56
Joined: Thu Jan 05, 2006 11:22 pm

Post by frederic »

Thanks for this precision dhouston, changes made
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Post by flaith »

Very usefull, thanks
“Fear is a reaction. Courage is a decision.” - WC
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

I'm using PureBasic 4.10 and getting an invalid memory access on this line:

Code: Select all

Procedure MyTimeOutFunction(*pdata.l)
  Debug "hello"
  If stoptimer = #False
-->    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure
Any ideas?
Image Image
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

I guess you haven't opened a window before this error occurs... so simply use gtk_init_(0,0) at the top of you pgm( it doesn't hurt anything) and it will work...

EDIT:
:oops: didn't read your post correctly... you're using the example from the first post?
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Thanks walker.

Yes, I am using the example code at the top, guess I didn't make that clear.

I did try your suggestion, however, still getting the invalid memory access.

I am using Ubuntu Breezy, and will upgrade real soon, but could that be a factor?

Thanks.
Image Image
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

UPDATE: Found the solution:

Changed "Procedure" to "ProcedureC" and voila.

Thanks for your help.
Image Image
Post Reply