fixed mem leak with adding external qt event processing
This commit is contained in:
parent
7de1019e76
commit
d2b6abbbb5
|
@ -44,7 +44,7 @@ from collections import deque
|
||||||
|
|
||||||
|
|
||||||
from PyQt4.QtCore import QBuffer, QByteArray, QIODevice
|
from PyQt4.QtCore import QBuffer, QByteArray, QIODevice
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from chaosc.osc_lib import *
|
from chaosc.osc_lib import *
|
||||||
|
|
||||||
QtGui.QApplication.setGraphicsSystem('opengl')
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -67,7 +66,6 @@ except ImportError as e:
|
||||||
print(e)
|
print(e)
|
||||||
from chaosc.osc_lib import decode_osc
|
from chaosc.osc_lib import decode_osc
|
||||||
|
|
||||||
QAPP = QtGui.QApplication([])
|
|
||||||
|
|
||||||
|
|
||||||
class PlotWindow(PlotWidget):
|
class PlotWindow(PlotWidget):
|
||||||
|
@ -281,7 +279,7 @@ class EkgPlot(object):
|
||||||
|
|
||||||
def update(self, osc_address, value):
|
def update(self, osc_address, value):
|
||||||
|
|
||||||
print "update", osc_address
|
#print "update", osc_address
|
||||||
res = self.ekg_regex.match(osc_address)
|
res = self.ekg_regex.match(osc_address)
|
||||||
if res:
|
if res:
|
||||||
#print("matched data")
|
#print("matched data")
|
||||||
|
@ -305,30 +303,21 @@ class EkgPlot(object):
|
||||||
if res:
|
if res:
|
||||||
actor_name = res.group(1)
|
actor_name = res.group(1)
|
||||||
actor_obj = self.actors[actor_name]
|
actor_obj = self.actors[actor_name]
|
||||||
#print("matched ctl", value, actor_name, actor_obj.active)
|
|
||||||
if value == 1 and not actor_obj.active:
|
if value == 1 and not actor_obj.active:
|
||||||
print "actor on", actor_name
|
#print "actor on", actor_name
|
||||||
self.plot.addItem(actor_obj)
|
|
||||||
actor_obj.active = True
|
|
||||||
self.active_actors.append(actor_obj)
|
|
||||||
elif value == 0 and not actor_obj.active:
|
|
||||||
print "actor off", actor_name
|
|
||||||
self.plot.removeItem(actor_obj)
|
|
||||||
actor_obj.active = True
|
|
||||||
if actor_obj not in self.active_actors:
|
|
||||||
self.plot.addItem(actor_obj.plotItem)
|
self.plot.addItem(actor_obj.plotItem)
|
||||||
self.plot.addItem(actor_obj.plotPoint)
|
self.plot.addItem(actor_obj.plotPoint)
|
||||||
|
actor_obj.active = True
|
||||||
|
if not actor_obj in self.active_actors:
|
||||||
self.active_actors.append(actor_obj)
|
self.active_actors.append(actor_obj)
|
||||||
assert actor_obj in self.active_actors
|
|
||||||
elif value == 0 and actor_obj.active:
|
elif value == 0 and actor_obj.active:
|
||||||
#print("actor off", actor_name, actor_obj, self.active_actors)
|
#print "actor off", actor_name
|
||||||
actor_obj.active = False
|
actor_obj.active = False
|
||||||
self.plot.removeItem(actor_obj.plotItem)
|
self.plot.removeItem(actor_obj.plotItem)
|
||||||
self.plot.removeItem(actor_obj.plotPoint)
|
self.plot.removeItem(actor_obj.plotPoint)
|
||||||
try:
|
try:
|
||||||
self.active_actors.remove(actor_obj)
|
self.active_actors.remove(actor_obj)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
#print("ctl", e)
|
|
||||||
pass
|
pass
|
||||||
assert actor_obj not in self.active_actors
|
assert actor_obj not in self.active_actors
|
||||||
|
|
||||||
|
@ -365,13 +354,17 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
actor_names = ["bjoern", "merle", "uwe"]
|
actor_names = ["bjoern", "merle", "uwe"]
|
||||||
num_data = 100
|
num_data = 100
|
||||||
colors = ["r", "g", "b"]
|
colors = ["r", "g", "b"]
|
||||||
|
qtapp = QtGui.QApplication([])
|
||||||
plotter = EkgPlot(actor_names, num_data, colors)
|
plotter = EkgPlot(actor_names, num_data, colors)
|
||||||
|
|
||||||
|
|
||||||
self.wfile.write("Content-Type: multipart/x-mixed-replace; boundary=--aaboundary\r\n\r\n")
|
self.wfile.write("Content-Type: multipart/x-mixed-replace; boundary=--aaboundary\r\n\r\n")
|
||||||
#lastTime = time.time()
|
#lastTime = time.time()
|
||||||
#fps = None
|
#fps = None
|
||||||
|
event_loop = QtCore.QEventLoop()
|
||||||
while 1:
|
while 1:
|
||||||
|
event_loop.processEvents()
|
||||||
|
qtapp.sendPostedEvents(None, 0)
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
osc_address, args = queue.get_nowait()
|
osc_address, args = queue.get_nowait()
|
||||||
|
@ -439,8 +432,6 @@ def main():
|
||||||
add_subscriber_group(arg_parser, "ekgplotter")
|
add_subscriber_group(arg_parser, "ekgplotter")
|
||||||
args = finalize_arg_parser(arg_parser)
|
args = finalize_arg_parser(arg_parser)
|
||||||
|
|
||||||
qtapp = QtGui.QApplication([])
|
|
||||||
|
|
||||||
http_host, http_port = resolve_host(args.http_host, args.http_port, args.address_family)
|
http_host, http_port = resolve_host(args.http_host, args.http_port, args.address_family)
|
||||||
|
|
||||||
server = JustAHTTPServer((http_host, http_port), MyHandler)
|
server = JustAHTTPServer((http_host, http_port), MyHandler)
|
||||||
|
|
Loading…
Reference in New Issue