Progress Bar

From IronPython Cookbook

(Difference between revisions)
(New page: <pre> import clr clr.AddReference('System.Windows.Forms') from System.Windows.Forms import Form, ProgressBar from IronPython.Runtime.Calls import CallTarget0 from System.Threading imp...)
Line 1: Line 1:
-
 
<pre>
<pre>
Line 13: Line 12:
class ProgressBarDialog(Form):
class ProgressBarDialog(Form):
     def __init__(self):
     def __init__(self):
 +
        self.Text = 'Progress Bar Example'
         pb = ProgressBar()
         pb = ProgressBar()
         pb.Minimum = 1
         pb.Minimum = 1

Revision as of 16:48, 23 August 2007

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