forum-msg-id-132198-edit

Original date:2018-03-14 14:04:00 Edited by: irv Subject: Re: Adding a GUI

So... Kat's text-mode code used the following to wait for user input (just 'q' for quit, here):

--- 
--- main loop here  
--- this is the default task #0  
--- all i have it do is see if i press 'q' to quit 
--- 
while 1 do 
  task_delay(1) 
  if equal(get_key(),'q') then 
    exit -- leave the while-loop, do cleanup and quit 
  end if 
end while 

We'll remove that, and add a Quit button to our window. - But wait, she also allows the other tasks to work while waiting:

junk = task_create(routine_id("listen"), {}) -- haveto listen to the irc server! 
task_schedule(junk,1) -- run it once, it will sleep itself  
 
junk = task_create(routine_id("keepaliveping"), {}) -- optional ping to keep track of lag 
task_schedule(junk,10) -- run it once, it will sleep itself  

Nowhere in these tasks does the user-interface get a chance to do its thing. We could perhaps add another task to check on the user-interface to see if anything needs attention, but that code could get complex real quick. We could, perhaps, add a check inside each of the tasks to poll the user-interface (same complexity).

Better, it seems, is to let GTK do the tasking:

tick = gtk:create(GIdle,call_back(routine_id("IRC_Listen"))) -- "listens" whenever the user isn't doing anything; 
tock = gtk:create(GTimeout,1000,call_back(routine_id("keep_alive_ping"))) -- called once per second (or whatever); 

(Note: I change the names of the routines being called slightly, so that I don't have to remove or modify Kat's code until my version of the routine is working ok.)

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu