[Kde-bindings] The useless Progressbar

Andreas Zuber andreas.zuber at fhso.ch
Wed Sep 28 23:44:40 UTC 2005


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 ?


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




More information about the Kde-bindings mailing list