Re: Hook user loop into program
- From: Maklakov Andrey <anmaklakov gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: Hook user loop into program
- Date: Sun, 17 Apr 2011 10:15:26 +0400
Hello.
I'm not experienced in gtk+ too. But I think you should connect
call of your function to some gtk event (g_signal_connect). Updating
progress bar you should connect to timeout or idle event (read about
g_timeout_add, g_idle_add). And in your function call:
while (gtk_events_pending ())
gtk_main_iteration ();
On 16.04.2011 15:04, Marco wrote:
Hi,
I'm a novice in gtk and I face some problems getting
started. I don't find a solution in the manual (although
I'm pretty sure it's in there) because I don't know what
to look for.
I create a main window (top level window) with a progress
bar. What I want is to display the window and then execute
a loop that does some tasks and updates the progress bar
after every iteration.
My problem is that I don't know how to hook my Âworking
loop into all this. When I put my working loop before the
gtk.main() call the loop is executed before the main
window is shown, the point after the loop is not reached
because gtk.main() is an endless loop. Where should I put the function
DoSomeStuff()? I attached a minimal example, it's written in lua.
Marco
Mainwin = {}
Mainwin.__index = Mainwin
function Mainwin.new()
local self = {}
setmetatable(self, Mainwin)
self.w = gtk.window_new(gtk.WINDOW_TOPLEVEL)
self.w:set_title("Program")
self.w:connect('destroy', gtk.main_quit)
progress = gtk.progress_bar_new()
gtk.progress_bar_set_text(progress, "Processingâ")
gtk.progress_bar_set_fraction(progress, 0)
self.w:add(progress)
self.w:show_all()
return self
end
function DoSomeStuff()
for i=1, 10 do
-- do some work and
-- update progress bar
gtk.progress_bar_set_fraction(progress, i*.1)
end
return true
end
require "gtk"
mainwin = Mainwin.new()
gtk.main()
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]