Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Jakimow
EO Time Series Viewer
Commits
fac29dc9
Commit
fac29dc9
authored
Jul 27, 2010
by
Luke Campagnola
Browse files
added signalproxy class
parent
cd344c34
Changes
1
Hide whitespace changes
Inline
Side-by-side
SignalProxy.py
0 → 100644
View file @
fac29dc9
# -*- coding: utf-8 -*-
from
PyQt4
import
QtCore
from
ptime
import
time
def
proxyConnect
(
source
,
signal
,
slot
,
delay
=
0.3
):
"""Connect a signal to a slot with delay. Returns the SignalProxy
object that was created. Be sure to store this object so it is not
garbage-collected immediately."""
sp
=
SignalProxy
(
source
,
signal
,
delay
)
sp
.
connect
(
sp
,
signal
,
slot
)
return
sp
class
SignalProxy
(
QtCore
.
QObject
):
"""Object which collects rapid-fire signals and condenses them
into a single signal. Used, for example, to prevent a SpinBox
from generating multiple signals when the mouse wheel is rolled
over it."""
def
__init__
(
self
,
source
,
signal
,
delay
=
0.3
):
QtCore
.
QObject
.
__init__
(
self
)
source
.
connect
(
source
,
signal
,
self
.
signal
)
self
.
delay
=
delay
self
.
waitUntil
=
0
self
.
args
=
None
self
.
timers
=
0
self
.
signal
=
signal
def
setDelay
(
self
,
delay
):
self
.
delay
=
delay
def
flush
(
self
):
"""If there is a signal queued up, send it now."""
if
self
.
args
is
None
:
return
False
self
.
emit
(
self
.
signal
,
*
self
.
args
)
self
.
args
=
None
return
True
def
signal
(
self
,
*
args
):
"""Received signal, queue to be forwarded later."""
self
.
waitUntil
=
time
()
+
self
.
delay
self
.
args
=
args
self
.
timers
+=
1
QtCore
.
QTimer
.
singleShot
((
self
.
delay
*
1000
)
+
1
,
self
.
tryEmit
)
def
tryEmit
(
self
):
"""Emit signal if it has been long enougn since receiving the last signal."""
if
self
.
args
is
None
:
return
False
self
.
timers
-=
1
t
=
time
()
if
t
>=
self
.
waitUntil
:
return
self
.
flush
()
else
:
if
self
.
timers
==
0
:
self
.
timers
+=
1
QtCore
.
QTimer
.
singleShot
((
self
.
waitUntil
-
t
)
*
1000
,
self
.
tryEmit
)
return
True
\ No newline at end of file
Write
Preview
Supports
Markdown
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