tests/tools/test_CustomIntCtrl.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 20:01:21 +0300
changeset 1811 4e3c78a84c64
child 1832 0f1081928d65
permissions -rw-r--r--
add custom TextCtrl allowed to enter long integer with bounds checking

It's needed because wx.SpinCtrl supports only 'int' type. For UDINT
and (U)LINT long type is necessary.
1811
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
#
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Copyright (C) 2017: Andrey Skvortsov
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
#
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
# See COPYING file for copyrights details.
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
#
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
# This program is free software; you can redistribute it and/or
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# modify it under the terms of the GNU General Public License
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
# as published by the Free Software Foundation; either version 2
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# of the License, or (at your option) any later version.
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
#
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
# This program is distributed in the hope that it will be useful,
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# GNU General Public License for more details.
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
#
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
# You should have received a copy of the GNU General Public License
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# along with this program; if not, write to the Free Software
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
import unittest
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    26
import wx
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    27
import time
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    28
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
import conftest
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
import controls.CustomIntCtrl
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
class TestCustomIntCtrl(unittest.TestCase):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
    def setUp(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    35
        self.app = wx.App()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
        self.frame = wx.Frame(None)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    38
    def tearDown(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    39
        self.frame.Destroy()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
        wx.CallAfter(self.app.Exit)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
        self.app.MainLoop()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
    def testMaxLimit(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
        """Test working upper bound"""
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
        self.AddControls()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
        self.int_ctrl.SetValue(self.max_val + 100)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
        self.assertEqual(self.int_ctrl.GetValue(), self.max_val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
    def testMinLimit(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
        """Test working lower bound"""
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
        self.AddControls()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
        self.int_ctrl.SetValue(self.min_val - 100)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
        self.assertEqual(self.int_ctrl.GetValue(), self.min_val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
    def testCorrectValue(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
        """Test case if no limiting is necessary"""
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
        self.AddControls()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
        val = (self.max_val + self.min_val) / 2
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
        self.int_ctrl.SetValue(val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    71
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
        self.assertEqual(self.int_ctrl.GetValue(), val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
    def testEventBinding(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
        """Test event sending after edit and bound checks are done"""
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    78
        self.AddControls()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    79
        self.event_happend = False
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    80
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
        def EventHandler(event):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
            self.event_happend = True
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    83
            event.Skip()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    84
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
        self.int_ctrl.Bind(controls.CustomIntCtrl.EVT_CUSTOM_INT, EventHandler)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    87
        val = (self.max_val + self.min_val) / 2
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
        self.int_ctrl.SetValue(val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    91
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    92
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
        self.assertEqual(self.int_ctrl.GetValue(), val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
        self.assertTrue(self.event_happend)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
    def testLongNumbers(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
        """Test support of long integer"""
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
        self.AddControls()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
        val = 40000000000
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
        self.int_ctrl.SetMax(val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
        self.int_ctrl.SetValue(val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   107
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   108
        self.txt_ctrl.SetFocus()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   109
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   111
        self.assertEqual(val, val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   113
    def ProcessEvents(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
        for i in range(0, 10):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
            wx.Yield()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
            time.sleep(0.01)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
    def AddControls(self):
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   119
        vs = wx.BoxSizer(wx.VERTICAL)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
        self.int_ctrl = controls.CustomIntCtrl(self.frame)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
        self.txt_ctrl = wx.TextCtrl(self.frame)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
        vs.Add(self.int_ctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
        vs.Add(self.txt_ctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
        self.frame.SetSizer(vs)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
        vs.Fit(self.frame)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   126
        self.frame.Show()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   127
        self.frame.Raise()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   129
        self.min_val = 50
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   130
        self.max_val = 100
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
        self.int_ctrl.SetBounds(self.min_val, self.max_val)
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
        self.ProcessEvents()
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
if __name__ == '__main__':
4e3c78a84c64 add custom TextCtrl allowed to enter long integer with bounds checking
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
    unittest.main()