Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pedro Henrique Kopper
SADAPMAP
Commits
0b486126
Commit
0b486126
authored
Apr 20, 2018
by
Alisson Claudino
Browse files
ADD: Code comments
parent
3a506e94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Interface/InterfaceTimer.py
View file @
0b486126
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Classe InterfaceTimer #
# Autor: Alisson Claudino (alisson.claudino@ufrgs.br) #
# Licença: GNU GPLv2 #
# Propósito: Controlar os timers das interfaces gráficas do sistema (Contadores, relógicos e #
# marcadores) #
# #
# #
# Observações: #
# #
# Um objeto dessa classe é instanciado por uma das classes de interface, então os botões e labels #
# que compõem as ações de timer, são criados nessa classe e passados diretamente para a interface. #
# Dessa forma, serão instanciados 3 objetos dessa classe, sendo um para cada uma das telas da interface #
# gráfica. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from
datetime
import
datetime
from
PyQt5
import
QtWidgets
,
QtCore
,
QtGui
...
...
@@ -21,7 +38,7 @@ class InterfaceTimer(object):
self
.
timeValue
=
0
self
.
regTimerValue
=
1000
def
linkActions
(
self
):
def
linkActions
(
self
):
#Função para associar ações aos botões da interface
self
.
startTimerButton
.
pressed
.
connect
(
self
.
startScreenTimer
)
self
.
stopTimerButton
.
pressed
.
connect
(
self
.
stopScreenTimer
)
self
.
currentTimer
.
timeout
.
connect
(
self
.
updateCurrentTime
)
...
...
@@ -30,7 +47,7 @@ class InterfaceTimer(object):
self
.
currentTimer
.
start
(
500
)
self
.
screenTimerFlag
=
False
def
startRegressiveTimer
(
self
):
def
startRegressiveTimer
(
self
):
#Função para iniciar o contador regressivo com um tempo configurado via interface
try
:
if
(
self
.
regTimerLabel
.
text
().
split
(
" "
,
3
)[
1
]
==
"s"
):
self
.
regTimerValue
=
self
.
regTimerLabel
.
text
().
split
(
" "
,
3
)[
0
]
...
...
@@ -43,14 +60,14 @@ class InterfaceTimer(object):
except
(
IndexError
):
self
.
regTimerValue
=
self
.
regTimerLabel
.
text
()
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
#Uma exceção é lançada caso um valor de tempo inválido seja colocado no contador.
error
=
QtWidgets
.
QMessageBox
(
self
.
MainWindow
)
error
.
setText
(
"Valor Inválido! Definindo valor padrão de 1000 segundos"
)
error
.
setWindowTitle
(
"ERRO!"
)
error
.
exec
()
self
.
regTimerValue
=
1000
print
(
self
.
regTimerValue
)
print
(
self
.
regTimerValue
)
self
.
regTimerValue
=
float
(
self
.
regTimerValue
)
...
...
@@ -61,26 +78,26 @@ class InterfaceTimer(object):
self
.
startRegTimerButton
.
setText
(
"Pausar"
)
self
.
startRegTimerButton
.
pressed
.
connect
(
self
.
pauseRegressiveTimer
)
def
pauseRegressiveTimer
(
self
):
def
pauseRegressiveTimer
(
self
):
#Função para pausar o contador regressivo da interface
self
.
regTimer
.
stop
()
self
.
startRegTimerButton
.
setText
(
"Continuar"
)
self
.
startRegTimerButton
.
pressed
.
disconnect
()
self
.
startRegTimerButton
.
pressed
.
connect
(
self
.
startRegressiveTimer
)
def
stopRegressiveTimer
(
self
):
def
stopRegressiveTimer
(
self
):
#Função para parar e resetar o contador regressivo
self
.
regTimer
.
stop
()
self
.
startRegTimerButton
.
setText
(
"Iniciar"
)
self
.
startRegTimerButton
.
pressed
.
disconnect
()
self
.
startRegTimerButton
.
pressed
.
connect
(
self
.
startRegressiveTimer
)
self
.
regTimerLabel
.
setText
(
"0.00 s"
)
def
updateRegTimer
(
self
):
def
updateRegTimer
(
self
):
#Função para atualizar a exibição da contagem na interface com amostragem de 0.1seg
if
(
self
.
regTimerValue
>=
0.1
):
self
.
regTimerValue
-=
0.1
self
.
regTimerLabel
.
setText
(
"%.1f s"
%
self
.
regTimerValue
)
def
startScreenTimer
(
self
):
def
startScreenTimer
(
self
):
#Função para iniciar o cronômetro da interface
self
.
screenTimer
=
QtCore
.
QTimer
()
self
.
screenTimer
.
timeout
.
connect
(
self
.
updateScreenTimer
)
self
.
screenTimer
.
start
(
100
)
...
...
@@ -88,24 +105,24 @@ class InterfaceTimer(object):
self
.
startTimerButton
.
pressed
.
connect
(
self
.
pauseScreenTimer
)
self
.
startTimerButton
.
setText
(
"Pausar"
)
def
pauseScreenTimer
(
self
):
def
pauseScreenTimer
(
self
):
#Função para pausar cronômetro da interface
self
.
screenTimer
.
stop
()
self
.
startTimerButton
.
setText
(
"Continuar"
)
self
.
startTimerButton
.
pressed
.
disconnect
()
self
.
startTimerButton
.
pressed
.
connect
(
self
.
startScreenTimer
)
def
stopScreenTimer
(
self
):
def
stopScreenTimer
(
self
):
#Função para parar e resetar o cronômetro da interface
self
.
screenTimer
.
stop
()
self
.
timerLabel
.
setText
(
"0.00 s"
)
self
.
timeValue
=
0
self
.
screenTimerFlag
=
False
self
.
startTimerButton
.
setText
(
"Iniciar"
)
def
updateScreenTimer
(
self
):
def
updateScreenTimer
(
self
):
#Função para atualizar o cronômetro da interface com amostragem de 0.1seg
self
.
timeValue
+=
0.1
self
.
timerLabel
.
setText
(
"%.1f s"
%
self
.
timeValue
)
def
updateCurrentTime
(
self
):
def
updateCurrentTime
(
self
):
#Função para sincronizar e atualizar o relógio na interface com o horário local
self
.
currentTime
=
(
str
(
datetime
.
now
().
time
()))
self
.
currentTime
=
self
.
currentTime
.
split
(
":"
,
4
)
self
.
currentTime
[
2
]
=
self
.
currentTime
[
2
].
split
(
"."
,
3
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment