Progress Bar

From IronPython Cookbook

(Difference between revisions)
Line 1: Line 1:
 +
 +
[[Image:Progress_Bar_Example.png|A Windows Forms Progress Bar]]
<pre>
<pre>

Revision as of 16:58, 23 August 2007

A Windows Forms Progress Bar

import clr

clr.AddReference('System.Windows.Forms')

from System.Windows.Forms import Form, ProgressBar
from IronPython.Runtime.Calls import CallTarget0

from System.Threading import ThreadStart, Thread

class ProgressBarDialog(Form):
    def __init__(self):
        self.Text = 'Progress Bar Example'
        pb = ProgressBar()
        pb.Minimum = 1
        pb.Maximum = 100
        pb.Step = 1
        pb.Value = 1
        
        pb.Width = 400
        self.Controls.Add(pb)
        self.prog = pb
        
        self.Shown += self.startProgress
        
        
    def startProgress(self, s, e):
        def update():
            x = 1
            while True:
                print x
                def step():
                    self.prog.Value = x
                self.Invoke(CallTarget0(step))
                Thread.Sleep(30)
                x += 1
                if x > 100:
                    break
                    
            print 'Done'
        t = Thread(ThreadStart(update))
        t.Start()


f = ProgressBarDialog()
f.ShowDialog()


Back to Contents.

TOOLBOX
LANGUAGES