Hook user loop into program
- From: Marco <netuse lavabit com>
- To: gtk-app-devel-list gnome org
- Subject: Hook user loop into program
- Date: Sat, 16 Apr 2011 13:04:02 +0200
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()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]