WPF Progress Bar
import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore");
clr.AddReference('System.Data')
clr.AddReference('System.Windows.Forms')
import System
from System import *
from System.Data import *
from System.Type import GetType
from System.Threading.Tasks import Task
from System.Windows import *
from System.Windows.Controls import *
from System.Windows.Controls.Primitives import *
from System.Windows.Media import *
from System.Windows.Media.Imaging import *
from System.Windows.Media.Effects import *
from System.Windows.Shapes import Rectangle
from System.Windows.Shapes import Rectangle
from System.Windows.Data import Binding
from System.Windows.Ink import Stroke
from System.Windows.Forms import ( FolderBrowserDialog, DialogResult )
from Microsoft.Win32 import ( OpenFileDialog, SaveFileDialog )
import ctrl
import vbox
class WpfProgress(ctrl.WpfCtrl):
def __init__(self,**kwargs):
self.ctrl = ProgressBar()
#self.ctrl.IsIndeterminate = True
#self.ctrl.Margin = new Thickness(10,0,10,10);
self.init(**kwargs)
self.ctrl.Visibility = Visibility.Visible;
self.ctrl.Width = 100;
self.ctrl.Height = 16;
#self.ctrl.Foreground = System.Windows.Media.Brushes.Green;
#self.ctrl.Background = System.Windows.Media.Brushes.Red;
#self.ctrl.Style = ProgressBarStyle.Continuous #Marquee
self.ctrl.Maximum = 100
self.ctrl.Value = 0
#self.ctrl.FlowDirection = FlowDirection.LeftToRight
def get_value(self):
return self.ctrl.Value
def set_value(self,v):
self.ctrl.Value = v
def StartTimer(handler,msec):
tmr = System.Timers.Timer(msec)
tmr.Elapsed += handler
tmr.AutoReset = True
#tmr.Enabled = True
tmr.Start()
#tmr.Stop();
#tmr.Dispose();
def StartTask(handler):
Task.Factory.StartNew(handler)
def RunLater(ctrl,handler):
ctrl.Dispatcher.BeginInvoke(System.Action(handler))
def Delay(msec):
#Thread.Sleep() make GUI stuck
ThisMoment = DateTime.Now;
duration = TimeSpan(0, 0, 0, 0, msec);
AfterWards = ThisMoment.Add(duration);
while AfterWards >= ThisMoment:
System.Windows.Forms.Application.DoEvents()
ThisMoment = DateTime.Now
return DateTime.Now;
prog_value = 0
if __name__ == "__main__":
global p1
global p2
def taskHandler():
for i in range(100):
RunLater(p1.ctrl, lambda : p1.set_value(i))
Delay(100)
def timerHandler(sender,args):
global prog_value
prog_value += 10
RunLater(p2.ctrl, lambda : p2.set_value(prog_value))
import win
app = win.Win("Button Demo",320,240)
p1 = WpfProgress()
p2 = WpfProgress()
vb = vbox.WpfVBox();
vb.add_item(p1.ctrl)
vb.add_item(p2.ctrl)
app.set_content(vb.ctrl)
StartTask(taskHandler)
StartTimer(timerHandler,1000)
app.run()
댓글 없음:
댓글 쓰기