I have a python script that is working great. It takes in live data from a 
Qt C++ app, and displays it in the graph.

The problem is, I have to manually start the script. I cannot get the Qt 
app to start the script, I can't get other python scripts to start it. I 
have no means by which to automate it's opening for the end user. It will 
only run if I manually click on it or type in the command prompt for it. 
What is causing this?

import pyqtgraph as pg
> from pyqtgraph.Qt import QtCore, QtGui
> import numpy as np
> import math
> import socket
>
> vis_socket = socket.socket()
> host = socket.gethostname()
> port = 5040
>
> vis_socket.connect((host, port))
>
> frame = 0
> position = []
>
> TIME_SIZE = 300
>
> torque_mag = []
> force_mag = []
>
> main_window = pg.GraphicsWindow()
> main_window.setWindowTitle('Bracelet Motion')
>
> mag_labels = {"left":("Newtons"),"bottom":("Frames")}
> magnitude_plot = main_window.addPlot()
> magnitude_plot.setYRange(-5,50)
> magnitude_plot.setLabel('left', 'Newtons')
> magnitude_plot.setLabel('bottom', 'Number of Displayed Frames')
> magnitude_plot.addLegend()
> magnitude_plot.setTitle('Loadcell Magnitudes')
> # plot2 = mainWindow.addPlot()
>
> curve_f_mag = magnitude_plot.plot(force_mag, pen='g', name=' Force')
> curve_tq_mag = magnitude_plot.plot(torque_mag, pen='r', name=' Torque')
>
>
> def inc_frame():
>     global frame, position
>     if len(position) < TIME_SIZE:
>         position.append(frame)
>     # else:
>     #     position[:-1] = position[1:]
>     #     position[-1] = frame
>         frame += 1
>
> def plot_force_mag(data):
>     # incFrame()
>     global force_mag, curve_f_mag, position
>     magnitude = calc_magnitude(data)
>     if len(force_mag) < TIME_SIZE:
>         force_mag.append(magnitude)  # build the list to desired size
>     else:
>         force_mag[:-1] = force_mag[1:]  # shift data in the array one 
> sample left
>         force_mag[-1] = magnitude  # set the last duplicate value to the 
> new value
>     curve_f_mag.setData(position, force_mag)
>
> def plot_torque_mag(data):
>     # incFrame()
>     global torque_mag, curve_tq_mag, position
>     magnitude = calc_magnitude(data)
>     if len(torque_mag) < TIME_SIZE:
>         torque_mag.append(magnitude)  # build the list to desired size
>     else:
>         torque_mag[:-1] = torque_mag[1:]  # shift data in the array one 
> sample left
>         torque_mag[-1] = magnitude  # set the last duplicate value to the 
> new value
>     curve_tq_mag.setData(position, torque_mag)
>     # curveTqMag.setPos(frames, 0)
>
> def calc_magnitude(data):
>     val_x = float(data[0])
>     val_y = float(data[1])
>     val_z = float(data[2])
>     return round(math.sqrt((val_x*val_x) + (val_y*val_y) + 
> (val_z*val_z)),3)
>
> def parse_data(data):
>     data_list = data.split()
>     if len(data_list) > 0:
>         inc_frame()
>     for d in data_list:
>         i = data_list.index(d)
>         # if d == "tipPos":
>         #     getTipPos(dataList[i:i + 4])
>         if d == "force":
>             plot_force_mag(data_list[i+1 : i+4])
>         if d == "torque":
>             plot_torque_mag(data_list[i+1 : i+4])
>
> def main():
>     incoming = vis_socket.recv(8192).decode()
>     stream_list = incoming.split(':')
>     for chunk in stream_list:
>         parse_data(chunk)
>
> timer = pg.QtCore.QTimer()
> timer.timeout.connect(main)
> timer.start(50)
>
> if __name__ == '__main__':
>     import sys
>
>     if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
>         QtGui.QApplication.instance().exec_()
>


-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/cb943810-f464-4ea3-bafd-4169e3a35d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to