Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ it is overwritten.
Requirements
------------
- Numpy
- [PyQt4](http://www.riverbankcomputing.com/software/pyqt/download)
- [PyQt5](http://www.riverbankcomputing.com/software/pyqt/download)
- [pyqtgraph](http://www.pyqtgraph.org)

pyqtgraph will be installed automatically from PyPI if not found
Expand Down
2 changes: 1 addition & 1 deletion liveplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from client import LivePlotClient
from .client import LivePlotClient
2 changes: 1 addition & 1 deletion liveplot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from window import main
from .window import main
main()
12 changes: 6 additions & 6 deletions liveplot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import warnings
import numpy as np
import logging
from PyQt4.QtNetwork import QLocalSocket
from PyQt4.QtCore import QCoreApplication, QSharedMemory
from PyQt5.QtNetwork import QLocalSocket
from PyQt5.QtCore import QCoreApplication, QSharedMemory

__author__ = 'phil'

logging.root.setLevel(logging.WARNING)

class LivePlotClient(object):
def __init__(self, timeout=2000, size=2**20):
def __init__(self, timeout=2000, size=2**28):
self.app = QCoreApplication.instance()
if self.app is None:
self.app = QCoreApplication([])
Expand All @@ -27,7 +27,7 @@ def __init__(self, timeout=2000, size=2**20):
if not self.shared_mem.create(size):
raise Exception("Couldn't create shared memory %s" % self.shared_mem.errorString())
logging.debug('Memory created with key %s and size %s' % (key, self.shared_mem.size()))
self.sock.write(key)
self.sock.write(key.encode())
self.sock.waitForBytesWritten()

self.is_connected = True
Expand Down Expand Up @@ -59,13 +59,13 @@ def send_to_plotter(self, meta, arr=None):
raise ValueError("meta object is too large (> 200 char)")

if arr is None:
self.sock.write(meta_bytes)
self.sock.write(meta_bytes.encode())
else:
if not self.sock.bytesAvailable():
self.sock.waitForReadyRead()
self.sock.read(2)
self.shared_mem.lock()
self.sock.write(meta_bytes)
self.sock.write(meta_bytes.encode())
region = self.shared_mem.data()
region[:arrsize] = arrbytes
self.shared_mem.unlock()
Expand Down
26 changes: 13 additions & 13 deletions liveplot/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt4 import QtGui, QtCore
from PyQt5 import QtWidgets, QtCore
import warnings
import pyqtgraph as pg
import numpy as np
Expand All @@ -14,16 +14,16 @@ class CloseableDock(Dock):
docklist = []
def __init__(self, *args, **kwargs):
super(CloseableDock, self).__init__(*args, **kwargs)
style = QtGui.QStyleFactory().create("windows")
close_icon = style.standardIcon(QtGui.QStyle.SP_TitleBarCloseButton)
close_button = QtGui.QPushButton(close_icon, "", self)
style = QtWidgets.QStyleFactory().create("windows")
close_icon = style.standardIcon(QtWidgets.QStyle.SP_TitleBarCloseButton)
close_button = QtWidgets.QPushButton(close_icon, "", self)
close_button.clicked.connect(self.close)
close_button.setGeometry(0, 0, 20, 20)
close_button.raise_()
self.closeClicked = close_button.clicked

max_icon = style.standardIcon(QtGui.QStyle.SP_TitleBarMaxButton)
max_button = QtGui.QPushButton(max_icon, "", self)
max_icon = style.standardIcon(QtWidgets.QStyle.SP_TitleBarMaxButton)
max_button = QtWidgets.QPushButton(max_icon, "", self)
max_button.clicked.connect(self.maximize)
max_button.setGeometry(20, 0, 20, 20)
max_button.raise_()
Expand Down Expand Up @@ -77,7 +77,7 @@ def handle_mouse_move(self, mouse_event):
xdata, ydata = data_item.xData, data_item.yData
index_distance = lambda i: (xdata[i]-view_x)**2 + (ydata[i] - view_y)**2
if self.parametric:
index = min(range(len(xdata)), key=index_distance)
index = min(list(range(len(xdata))), key=index_distance)
else:
index = min(np.searchsorted(xdata, view_x), len(xdata)-1)
if index and xdata[index] - view_x > view_x - xdata[index - 1]:
Expand Down Expand Up @@ -163,19 +163,19 @@ def __init__(self, trace_size=80, **kwargs):
self.search_mode = False
self.signals_connected = False
self.set_histogram(False)
histogram_action = QtGui.QAction('Histogram', self)
histogram_action = QtWidgets.QAction('Histogram', self)
histogram_action.setCheckable(True)
histogram_action.triggered.connect(self.set_histogram)
self.img_view.scene.contextMenu.append(histogram_action)

self.autolevels_action = QtGui.QAction('Autoscale Levels', self)
self.autolevels_action = QtWidgets.QAction('Autoscale Levels', self)
self.autolevels_action.setCheckable(True)
self.autolevels_action.setChecked(True)
self.autolevels_action.triggered.connect(self.redraw)
self.ui.histogram.item.sigLevelChangeFinished.connect(lambda: self.autolevels_action.setChecked(False))
self.img_view.scene.contextMenu.append(self.autolevels_action)

self.clear_action = QtGui.QAction('Clear Contents', self)
self.clear_action = QtWidgets.QAction('Clear Contents', self)
self.clear_action.triggered.connect(self.clear)
self.img_view.scene.contextMenu.append(self.clear_action)

Expand All @@ -200,7 +200,7 @@ def __init__(self, trace_size=80, **kwargs):
self.v_cross_section_widget_data = self.v_cross_section_widget.plot([0,0])

def setLabels(self, xlabel="X", ylabel="Y", zlabel="Z"):
print self.h_cross_dock.label
print(self.h_cross_dock.label)
self.plot_item.setLabels(bottom=(xlabel,), left=(ylabel,))
self.h_cross_section_widget.plotItem.setLabels(bottom=xlabel, left=zlabel)
self.v_cross_section_widget.plotItem.setLabels(bottom=ylabel, left=zlabel)
Expand Down Expand Up @@ -341,8 +341,8 @@ def __init__(self, array, *args, **kwargs):
super(MoviePlotDock, self).__init__(*args, **kwargs)
self.setImage(array)
self.tpts = len(array)
play_button = QtGui.QPushButton("Play")
stop_button = QtGui.QPushButton("Stop")
play_button = QtWidgets.QPushButton("Play")
stop_button = QtWidgets.QPushButton("Stop")
stop_button.hide()
self.addWidget(play_button)
self.addWidget(stop_button)
Expand Down
32 changes: 16 additions & 16 deletions liveplot/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import json
import logging
import signal
import widgets
from . import widgets
import numpy as np
from PyQt4.QtCore import QSharedMemory, QSize
from PyQt4.QtGui import QMainWindow, QApplication, QStandardItem, QDockWidget, QStandardItemModel, QListView, QAction, \
QIcon
from PyQt4.QtNetwork import QLocalServer
from PyQt4.Qt import Qt as QtConst
from PyQt5.QtCore import QSharedMemory, QSize
from PyQt5.QtWidgets import QMainWindow, QApplication, QDockWidget, QListView, QAction
from PyQt5.QtGui import QStandardItem,QStandardItemModel, QIcon
from PyQt5.QtNetwork import QLocalServer
from PyQt5.Qt import Qt as QtConst
from pyqtgraph.dockarea import DockArea

logging.root.setLevel(logging.WARNING)
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(self):


def close(self, sig=None, frame=None):
print 'closing'
print('closing')
for conn in self.conns:
conn.close()
for shm in self.shared_mems:
Expand All @@ -50,7 +50,7 @@ def accept(self):
logging.debug('connection accepted')
conn = self.server.nextPendingConnection()
conn.waitForReadyRead()
key = str(conn.read(36))
key = str(conn.read(36).decode())
memory = QSharedMemory()
memory.setKey(key)
memory.attach()
Expand All @@ -60,18 +60,18 @@ def accept(self):
self.shared_mems.append(memory)
conn.readyRead.connect(lambda: self.read_from(conn, memory))
conn.disconnected.connect(memory.detach)
conn.write('ok')
conn.write(b'ok')

# noinspection PyNoneFunctionAssignment
def read_from(self, conn, memory):
logging.debug('reading data')
self.meta = json.loads(conn.read(200))
self.meta = json.loads(conn.read(200).decode())
if self.meta['arrsize'] != 0:
memory.lock()
ba = memory.data()[0:self.meta['arrsize']]
arr = np.frombuffer(buffer(ba))
arr = np.frombuffer(memoryview(ba))
memory.unlock()
conn.write('ok')
conn.write(b'ok')
arr = arr.reshape(self.meta['shape']).copy()
else:
arr = None
Expand Down Expand Up @@ -126,11 +126,11 @@ def remove(name):

elif name == "*":
if operation == 'clear':
map(clear, self.namelist.keys())
list(map(clear, list(self.namelist.keys())))
elif operation == 'close':
map(close, self.namelist.keys())
list(map(close, list(self.namelist.keys())))
elif operation == 'remove':
map(remove, self.namelist.keys())
list(map(remove, list(self.namelist.keys())))
return
else:
if operation in ('clear', 'close', 'remove'):
Expand Down Expand Up @@ -266,7 +266,7 @@ def __delitem__(self, name):
del self.plot_dict[name]

def keys(self):
return self.plot_dict.keys();
return list(self.plot_dict.keys());


def main():
Expand Down
10 changes: 5 additions & 5 deletions liveplot_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from PyQt4.QtCore import QTimer
from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, QSpinBox, QHBoxLayout, QLabel, QPushButton, \
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSpinBox, QHBoxLayout, QLabel, QPushButton, \
QPlainTextEdit, QProgressBar
import numpy as np
import sys
Expand Down Expand Up @@ -124,7 +124,7 @@ def set_iterator():
self.timer.start()
return set_iterator

for name, iter in tests.items():
for name, iter in list(tests.items()):
button = QPushButton(name)
button.clicked.connect(make_set_iterator(iter))
button_layout.addWidget(button)
Expand All @@ -137,15 +137,15 @@ def set_iterator():

def iterate(self):
try:
self.iterator.next()
next(self.iterator)
self.progress_bar.setValue(self.progress_bar.value() + 1)
except StopIteration:
self.timer.stop()
self.progress_bar.setValue(0)

if __name__ == "__main__":
app = QApplication([])
c = LivePlotClient(size=2**20)
c = LivePlotClient(size=2**28)
win = TestWindow()
win.show()
def clean():
Expand Down