The Tordivel.StopWatch is a high-resolution and simple to use time
measurement component.
This is the GUI created by the following script example
A corresponding profile Dotnet - StopWatch is available on
Scorpion Support Web.
# Central Start
# Python start script goes here
print 'Central Start'
# Create global instance of resultPanelOverlay
resultPanelOverlay = CreateStopWatchPanel(GetResultPanel().handle)
# Central Stop
# Python stop script goes here
try:
resultPanelOverlay.Dispose()
except:
print 'Dispose Failed'
# CreateStopWatchPanel
def CreateStopWatchPanel(hwnd):
import CLR
import CLR.System.Windows.Forms as WinForms
from CLR.System.Drawing import Size, Point, ContentAlignment
# Load custom assemblies
from CLR.System.Reflection import Assembly
Assembly.LoadWithPartialName("OverlayPanel")
Assembly.LoadWithPartialName("StopWatch")
from CLR.Tordivel import OverlayPanel
from CLR.Tordivel import StopWatch
class StopWatchPanel(OverlayPanel):
def __init__(self,nativeParentHandleAsInt32):
# This enables the panel to follow resizing of the parent
self.Dock = WinForms.DockStyle.Fill
# Create stopwatch with name
self.stopWatch = StopWatch("MyStopWatch")
# Default running state is "1" i.e. "true"
#self.stopWatch.Running = 0
# Create the textBox
self.textBox = WinForms.TextBox()
self.textBox.Parent = self
self.textBox.ReadOnly = 1
self.textBox.Size = Size(110,25)
self.textBox.Location = Point(10,10)
self.textBox.Text = ""
# Create the label (after the textBox to avoid hiding)
self.label = WinForms.Label()
self.label.Parent = self
self.label.Size = Size(100,25)
self.label.Location = Point(10,10)
self.label.Text = "Elapsed[s]:"
self.label.TextAlign = ContentAlignment.MiddleLeft
# Create the button
self.button = WinForms.Button()
self.button.Parent = self
self.button.Size = Size(170,30)
self.button.Location = Point(10,10)
self.button.Text = "Start"
# Register event handler for button.Click
self.button.Click += self.button_ClickHandler
self.timer = WinForms.Timer()
self.timer.Tick += self.TimerTickHandler
self.timer.Interval = 1000
self.timer.Enabled = 1
# Register event handler for Resize
self.Resize += self.ResizeHandler
def TimerTickHandler(self, sender, args):
# Handles timer tick
if self.stopWatch.Running:
self.textBox.Text = str(int(self.stopWatch.ElapsedSeconds))
def button_ClickHandler(self, sender, args):
# Handles the button Click event
if self.button.Text == "Start":
running = 1
self.stopWatch.Reset(running)
self.textBox.Text = "Running..."
self.button.Text = "Stop"
elif self.button.Text == "Stop":
# halt the stopwatch
self.stopWatch.Running = 0
# Show elapsed seconds in the text box
self.textBox.Text = str(self.stopWatch.ElapsedSeconds)
print self.stopWatch.ToString()
self.button.Text = "Start"
def ResizeHandler(self, sender, args):
# Handles the Resize event
print 'ResizeHandler'
self.button.Location = Point((self.Width-self.button.Width)/2,(self.Height-self.button.Height)/2)
self.label.Location = Point(self.button.Left,self.button.Bottom+10)
self.textBox.Location = Point(self.button.Right-self.textBox.Width,self.button.Bottom+10)
return StopWatchPanel(hwnd)
|