Up | Example 01 - ComboBox | Example 02 - ListBox | Example 03 - Labels class derived from Winforms.Panel | Example 04 - Button with Resize Event | Example 05 - CheckBox | Example 06 - GroupBox | Example 07 - Modeless Status Dialog | Example 08 -Timer | Example 09 -TextBox | Example 10 - Custom Button Class | Example 11 - Product Selection ComboBox | Example 12 - Simple ListView

 

  

 
Example 07 - Modeless Status Dialog
This example creates a modeless dialog owned by Scorpion.

Pressing the button activates a timer and changes button and status text.

The dialog is created in Central Start and lives until Scorpion is terminated. The Status window is visible while Scorpion is in running mode. The form denies closing in the Closing event.

Central Start

print ' Central Start '

# Import Section
import CLR
import CLR.System.Windows.Forms as WinForms
from CLR.System.Drawing import Size, Point

import CLR.System
from CLR.System.Reflection import Assembly

Assembly.LoadWithPartialName("OwnedForm")
from CLR.Tordivel import OwnedForm
# Class definition
class MyForm( OwnedForm):

  INTERVAL_SEC = 1 #interval for reading data and performing calculations
  NOOFINTERVALS = 10
  # constructor
  def __init__(self,hwnd):
  
    # Set window style
    self.Text = "Status Window"
    self.MaximizeBox = 0
    self.MinimizeBox = 0
    self.ShowInTaskbar = 0
    self.Closing += self.ClosingHandler

    self.AutoScaleBaseSize = Size(5, 13)
    self.ClientSize = Size(400, 64);
    h = WinForms.SystemInformation.CaptionHeight
    self.MinimumSize = Size(400, (64 + h))

    # Create timer
    self.resetTimer = WinForms.Timer()
    self.resetTimer.Interval = self.INTERVAL_SEC*1000

    # Register the event handlers
    self.resetTimer.Tick += self.resetTimer_Tick

    # Create the Start button
    self.startStopButton = WinForms.Button()
    self.startStopButton.Location = Point( 312, 8 )
    self.startStopButton.Size = Size( 80, 25 )
    self.startStopButton.TabIndex = 1
    self.startStopButton.Text = "Start test"
 
    # Register the Start button event handler
    self.startStopButton.Click += self.startStopButton_Click

    #  Create the textbox
    self.textBox = WinForms.TextBox()
    self.textBox.TabIndex = 2
    self.textBox.Size = Size(296, 25)
    self.textBox.Location = Point(8, 10)
    self.textBox.ReadOnly = True
    self.textBox.Text = "Test not running";

    # Add the controls to the form
    self.AcceptButton = self.startStopButton
    self.Controls.Add( self.startStopButton );
    self.Controls.Add( self.textBox );

    def startStopButton_Click(self, sender, args):
      # Start Button click event handler
      if self.startStopButton.Text == "Start test":
        self.resetTimer.Enabled = True # activate timer
        self.startStopButton.Text = "Stop test"
        self.textBox.Text = "Scorpion running";
        ExecuteCmd('LogMsg','Msg=Start;Level=2') # show trace in Scorpion System Log
      elif 
        self.startStopButton.Text == "Stop test":
        self.resetTimer.Enabled = False # deactivate timer
        self.startStopButton.Text = "Start test"
        self.textBox.Text = "Scorpion not running"; # show trace in Scorpion System Log
        ExecuteCmd('LogMsg','Msg=Stop;Level=2')

  def ClosingHandler(self, sender, args):
    # Handles the Resize event
    args.Cancel = 1 # deny close request


  def resetTimer_Tick(self, sender, args):
    t = self.textBox.Text + "."
    if len(t) == 80:
      self.textBox.Text = "Test running";
    else:
     self.textBox.Text = t;

  def run(self):
    WinForms.Application.Run(self)


# create  MyForm class
print ' create testform '
dTestForm = MyForm(GetResultPanel().handle) # create a from with Scorpion as owner
dTestForm.Show() # show dialog 
dTestForm.Visible=0 # hide dialog


Action.BeforeStart

Script;dTestForm.Visible=1 # show dialog while running

Action.AfterStop

Script;dTestForm.Visible=0 # hide dialog while not running
 
 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.