This commit is contained in:
Stefan Kögl 2014-05-29 10:22:04 +02:00
parent 80d6aea666
commit f2963a938d
7 changed files with 50 additions and 32 deletions

View File

@ -119,15 +119,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterfa
self.text_storage = ExclusiveTextStorage(columns, self.default_font, self.column_width, self.line_height, self.graphics_scene)
self.text_storage.init_columns()
msg = OSCMessage("/subscribe")
msg.appendTypedArg("localhost", "s")
msg.appendTypedArg(args.client_port, "i")
msg.appendTypedArg(self.args.authenticate, "s")
if self.args.subscriber_label is not None:
msg.appendTypedArg(self.args.subscriber_label, "s")
self.osc_sock.writeDatagram(QByteArray(msg.encode_osc()), QHostAddress("127.0.0.1"), 7110)
#self.add_text(0, "foo bar")
self.regex = re.compile("^/(uwe|merle|bjoern)/(.*?)$")
def pubdir(self):

View File

@ -75,7 +75,7 @@ class Generator(object):
if self.count < int(self.steps / 100. * 30):
value = random.randint(30, 35)
elif self.count == int(self.steps / 100. * 30):
value = random.randint(random.randint(50,60), random.randint(60, 70))
value = random.randint(55, 66)
elif self.count < int(self.steps / 100. * 45):
value = random.randint(30, 35)
elif self.count < int(self.steps / 2.):
@ -83,11 +83,11 @@ class Generator(object):
elif self.count == int(self.steps / 2.):
value = 255
elif self.count < int(self.steps / 100. * 60):
value = random.randint(random.randint(25,30), random.randint(30, 35))
value = random.randint(25, 35)
elif self.count < int(self.steps / 100. * 70):
value = random.randint(random.randint(10,25), random.randint(25, 30))
value = random.randint(10, 30)
elif self.count < self.steps:
value = random.randint(random.randint(15,25), random.randint(25, 30))
value = random.randint(15, 30)
else:
self.count = 0
value = 30
@ -152,11 +152,11 @@ class Actor(object):
self.plotPoint.setData(x=[self.pre_head], y=[self.data[self.pre_head]])
class EkgPlotWidget(PlotWidget, MjpegStreamingConsumerInterface, PsyQtChaoscClientBase):
class EkgPlotWidget(PlotWidget, PsyQtChaoscClientBase, MjpegStreamingConsumerInterface):
def __init__(self, args, parent=None):
self.args = args
PsyQtChaoscClientBase.__init__(self)
super(EkgPlotWidget, self).__init__()
PsyQtChaoscClientBase.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.fps = 12.5
@ -193,6 +193,10 @@ class EkgPlotWidget(PlotWidget, MjpegStreamingConsumerInterface, PsyQtChaoscClie
self.set_positions()
self.heartbeat_regex = re.compile("^/(.*?)/heartbeat$")
self.pull_timer = QtCore.QTimer()
self.pull_timer.timeout.connect(self.slot_pull_ekg)
self.pull_timer.start(40)
def pubdir(self):
return os.path.dirname(os.path.abspath(__file__))
@ -228,9 +232,6 @@ class EkgPlotWidget(PlotWidget, MjpegStreamingConsumerInterface, PsyQtChaoscClie
def render_image(self):
for actor_obj in self.active_actors:
osc = actor_obj.osci
for i in range(actor_obj.osci_obj.multiplier):
actor_obj.add_value(osc.next())
actor_obj.render()
exporter = pg.exporters.ImageExporter.ImageExporter(self.plotItem)
exporter.parameters()['width'] = 768
@ -251,6 +252,10 @@ class EkgPlotWidget(PlotWidget, MjpegStreamingConsumerInterface, PsyQtChaoscClie
else:
self.update(osc_address, args)
def slot_pull_ekg(self):
for actor_obj in self.active_actors:
actor_obj.add_value(actor_obj.osci.next())
def main():

View File

@ -205,6 +205,9 @@ class MjpegStreamingServer(QTcpServer):
def stop(self):
self.stream_clients = list()
for sock in self.sockets:
sock.close()
sock.deleteLater()
self.sockets = list()
self.html_map = dict()
self.close()

View File

@ -21,6 +21,7 @@
from __future__ import absolute_import
import sys
import traceback
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QBuffer, QByteArray
@ -64,17 +65,19 @@ class PsyQtChaoscClientBase(PsyQtClientBase):
self.osc_sock.error.connect(self.handle_osc_error)
self.subscribe()
def sigint_handler(self, ex_cls, ex, traceback):
def sigint_handler(self, ex_cls, ex, tb):
"""Handler for the SIGINT signal."""
logger.info("sigint_handler")
if ex_cls == KeyboardInterrupt:
logger.info("found KeyboardInterrupt")
self.unsubscribe()
QtGui.QApplication.exit()
else:
logger.critical(''.join(traceback.format_tb(traceback)))
logger.critical(''.join(traceback.format_tb(tb)))
logger.critical('{0}: {1}'.format(ex_cls, ex))
def sigterm_handler(self, *args):
logger.info("sigterm_handler")
self.unsubscribe()
QtGui.QApplication.exit()

View File

@ -17,7 +17,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTableView" name="text_list"/>
<widget class="QListView" name="text_list"/>
</item>
<item>
<widget class="QTextEdit" name="text_preview">

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'edit_dialog.ui'
#
# Created: Sat May 17 16:15:38 2014
# Created: Tue May 27 18:18:57 2014
# by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!
@ -31,7 +31,7 @@ class Ui_EditDialog(object):
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.text_list = QtGui.QTableView(EditDialog)
self.text_list = QtGui.QListView(EditDialog)
self.text_list.setObjectName(_fromUtf8("text_list"))
self.horizontalLayout_2.addWidget(self.text_list)
self.text_preview = QtGui.QTextEdit(EditDialog)

View File

@ -25,6 +25,7 @@ import cPickle
import os.path
import re
import sys
import traceback
from PyQt4 import QtCore, QtGui
@ -123,7 +124,7 @@ class EditDialog(QtGui.QWidget, Ui_EditDialog):
def slot_show_text(self, model_index):
try:
self.text_preview.setTextOrHtml(self.parent().parent().model.text_db[model_index.row()][1])
self.text_preview.setHtml(self.parent().parent().model.text_db[model_index.row()][1])
except IndexError:
pass
@ -232,10 +233,12 @@ class TextAnimation(QtCore.QObject):
self.count += 1
class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, PsyQtClientBase):
class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface):
def __init__(self, args, parent=None):
self.args = args
super(MainWindow, self).__init__()
#super(MainWindow, self).__init__()
#PsyQtClientBase.__init__(self)
KMainWindow.__init__(self, parent)
self.is_streaming = False
self.live_center_action = None
@ -257,12 +260,11 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
self.dialog = None
self.current_object = None
self.current_index = -1
self.win_id = self.winId()
self.is_auto_publish = False
self.setupUi(self)
self.coords = self.live_text_rect()
self.win_id = self.live_text.winId()
self.fps = 12.5
self.http_server = MjpegStreamingServer((args.http_host, args.http_port), self, self.fps)
@ -307,6 +309,9 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
self.start_streaming()
self.show()
timer = QtCore.QTimer()
timer.start(2000)
timer.timeout.connect(lambda: None)
def pubdir(self):
return os.path.dirname(os.path.abspath(__file__))
@ -317,9 +322,10 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()), self.mapToGlobal(public_rect.bottomRight()))
return global_rect.x(), global_rect.y()
def render_image(self):
pixmap = QPixmap.grabWindow(self.win_id, self.coords.x() + 10, self.coords.y() + 10, 768, 576)
public_rect = self.live_text_rect()
#global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()), self.mapToGlobal(public_rect.bottomRight()))
pixmap = QPixmap.grabWindow(self.win_id, public_rect.x() + 1, public_rect.y() + 1, 768, 576)
buf = QBuffer()
buf.open(QIODevice.WriteOnly)
pixmap.save(buf, "JPG", 75)
@ -505,6 +511,7 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
self.streaming_action.setChecked(True)
def closeEvent(self, event):
logger.info("closeEvent")
if self.db_dirty:
self.dialog = KDialog(self)
self.dialog.setCaption("4.48 texter - text db not saved")
@ -513,7 +520,7 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
self.dialog.setButtons(KDialog.ButtonCodes(KDialog.Ok | KDialog.Cancel))
self.dialog.okClicked.connect(self.slot_save)
self.dialog.exec_()
super(self, MainWindow).closeEvent(event)
event.accept()
def live_text_rect(self):
return self.live_text.geometry()
@ -727,6 +734,15 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps
self.text_combo.setCurrentItem(0)
self.slot_load_preview_text(0)
def sigint_handler(self, ex_cls, ex, tb):
"""Handler for the SIGINT signal."""
if ex_cls == KeyboardInterrupt:
logger.info("found KeyboardInterrupt")
QtGui.QApplication.exit()
else:
logger.critical(''.join(traceback.format_tb(tb)))
logger.critical('{0}: {1}'.format(ex_cls, ex))
def main():
arg_parser = ArgParser("texter")