#-*-Coding: UTF-8 -*-
# Python: 2.x
_ Author _ = 'admin'
From pyqt4.qtgui import *
From pyqt4.qt import *
From pyqt4.qtcore import *
From start import ui_form
Import sys
Class Example (qdialog, ui_form ):
Def _ init _ (self, parent = none ):
Super (example, self). _ init _ (parent)
Self. setupui (Self)
# Border Style
Self. timenum. setframestyle (qframe. styledpanel |
Qframe. Plain)
Self. Time = qtimers ()
Self. Start. clicked. Connect (self. start1)
Self. Stop. clicked. Connect (self. Stop1)
Self. Connect (self. Time, signal ("updatetime ()")
, Self. updatetime)
Self. setwindowflags (QT. windowminimizebuttonhint) # Do not change the window size.
Def updatetime (Self ):
Self. timenum. settext (U' time is {0} '. Format (qstring. Number (self. Num )))
Self. Num + = 1
Def Stop1 (Self ):
Self. Time. Stop1 ()
Self. Stop. setenabled (false)
Self. Start. setenabled (true)
Self. timenum. settext (U' enter the time 0 second ')
Def start1 (Self ):
Self. num = 0
Self. Start. setenabled (false)
Self. Stop. setenabled (true)
Self. Time. Start ()
From time import *
Class qtimers (qthread ):
Def _ init _ (self, parent = none ):
Super (qtimers, self). _ init _ (parent)
Self. stoped = false
Self. mutex = qmutex () # provides sequential access between threads
Def run (Self ):
With qmutexlocker (self. mutex): # qmutexlocker (qmutex * mutex)
Self. stoped = false
While true:
If self. stoped:
Return
Self. emit (signal ('updatetime () ') # Send signal
Sleep (1)
Def Stop1 (Self ):
With qmutexlocker (self. mutex ):
Self. stoped = true
Def isstoped (Self ):
With qmutexlocker (self. mutex ):
Return self. stoped
APP = qapplication (SYS. argv)
Qapplication. setquitonlastwindowclosed (false)
X = example ()
X. Show ()
Sys.exit(app.exe C _())
: