From f2963a938d7663d83842b052346b6488e1289352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Thu, 29 May 2014 10:22:04 +0200 Subject: [PATCH] polished --- dump_grabber/dump_grabber/main.py | 9 ------- ekgplotter/ekgplotter/main_qt.py | 23 ++++++++++------- psylib/psylib/mjpeg_streaming_server.py | 3 +++ psylib/psylib/psyqt_base.py | 7 +++-- texter/texter/edit_dialog.ui | 2 +- texter/texter/edit_dialog_ui.py | 4 +-- texter/texter/main.py | 34 ++++++++++++++++++------- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/dump_grabber/dump_grabber/main.py b/dump_grabber/dump_grabber/main.py index 535cab3..396da28 100644 --- a/dump_grabber/dump_grabber/main.py +++ b/dump_grabber/dump_grabber/main.py @@ -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): diff --git a/ekgplotter/ekgplotter/main_qt.py b/ekgplotter/ekgplotter/main_qt.py index ce03886..5f75b32 100644 --- a/ekgplotter/ekgplotter/main_qt.py +++ b/ekgplotter/ekgplotter/main_qt.py @@ -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(): diff --git a/psylib/psylib/mjpeg_streaming_server.py b/psylib/psylib/mjpeg_streaming_server.py index 9cadd99..2146b3d 100644 --- a/psylib/psylib/mjpeg_streaming_server.py +++ b/psylib/psylib/mjpeg_streaming_server.py @@ -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() diff --git a/psylib/psylib/psyqt_base.py b/psylib/psylib/psyqt_base.py index 4d5506e..e429024 100644 --- a/psylib/psylib/psyqt_base.py +++ b/psylib/psylib/psyqt_base.py @@ -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() diff --git a/texter/texter/edit_dialog.ui b/texter/texter/edit_dialog.ui index 64b71c4..4c5c3a9 100644 --- a/texter/texter/edit_dialog.ui +++ b/texter/texter/edit_dialog.ui @@ -17,7 +17,7 @@ - + diff --git a/texter/texter/edit_dialog_ui.py b/texter/texter/edit_dialog_ui.py index 9dfbd4f..6760f15 100644 --- a/texter/texter/edit_dialog_ui.py +++ b/texter/texter/edit_dialog_ui.py @@ -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) diff --git a/texter/texter/main.py b/texter/texter/main.py index 923642c..c084596 100644 --- a/texter/texter/main.py +++ b/texter/texter/main.py @@ -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() @@ -719,7 +726,7 @@ class MainWindow(KMainWindow, Ui_MainWindow, MjpegStreamingConsumerInterface, Ps return try: - self.model.text_db = [list(i) for i in cPickle.load(db_file)] + self.model.text_db = [list(i) for i in cPickle.load(db_file)] except ValueError, error: logger.exception(error) @@ -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")