[Kde-bindings] The useless Progressbar

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Sep 29 08:28:56 UTC 2005


Hi Andy

On Thursday 29 September 2005 01:44, Andreas Zuber wrote:
> I tried to create a GUI application with ruby and korundum. To keep the UI
> updated the other stuff should run in a seperate thread. I think this is a
> standard design for a GUI application. It seams there is a problem with the
> ruby-threads if korundum is in use. I created an example to show the bug.
> It seems that the thread runs if the mousefocus changes. Any ideas how i
> can make the progressbar usefull ?
Ruby threads don't know anything about the Qt event loop. So the easiest way 
to periodically update the ProgressBar is to use a Qt::Timer connected to a 
slot. Add this code to the constructor of MyApp:

@progress.totalSteps = 100

timer = Qt::Timer.new(self)
connect(timer, SIGNAL('timeout()'), self, SLOT('doIt()'))
timer.start(1000)

The about code will call the slot 'doIt()' once a second where you can update 
the progress bar according to the value whose change it is showing. So you 
would normally have a value in an instance variable, say '@myvalue' which 
ranges from 0 to 100 in this case:

def doIt
    @progress.progress = @myvalue
end

-- Richard

>
> Andy
>
> ------------------------------------8><----------------------------------
>
> require 'Korundum'
>
> class MyApp < Qt::Dialog
>
>     slots 'languageChange()',
>     'doIt()'
>
>     attr_reader :progress
>     attr_reader :button
>
>
>     def initialize(*k)
>         super(*k)
>
>         if name.nil?
>         	setName("MyApp")
>         end
>
>         @MyAppLayout = Qt::GridLayout.new(self, 1, 1, 11, 6, 'MyAppLayout')
>
>         @layout1 = Qt::VBoxLayout.new(nil, 0, 6, 'layout1')
>
>         @progress = KDE::Progress.new(self, "progress")
>         @layout1.addWidget(@progress)
>
>         @button = Qt::PushButton.new(self, "button")
>         @layout1.addWidget(@button)
>
>         @MyAppLayout.addLayout(@layout1, 0, 0)
>         languageChange()
>         resize( Qt::Size.new(132, 79).expandedTo(minimumSizeHint()) )
>         clearWState( WState_Polished )
>
>         Qt::Object.connect(@button, SIGNAL("pressed()"), self,
> SLOT("doIt()") )
>     end
>
>     #
>     #  Sets the strings of the subwidgets using the current
>     #  language.
>     #
>     def languageChange()
>         setCaption(trUtf8("MyApp"))
>         @button.setText( trUtf8("do it") )
>     end
>     protected :languageChange
>
>
>     def doIt(*k)
> 	thread = Thread.new {
> 		@progress.setTotalSteps(100)
> 		10000.times { |n|
> 			@progress.setProgress((n + 1) / 100)
> 			puts "I'm a useless progressbar"
> 		}
> 	}
>     end
>
> end
>
> if $0 == __FILE__
>     about = KDE::AboutData.new("myapp", "MyApp", "0.1")
>     KDE::CmdLineArgs.init(ARGV, about)
>     a = KDE::Application.new
>     w = MyApp.new
>     a.mainWidget = w
>     w.show
>     a.exec
> end
>
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings



More information about the Kde-bindings mailing list