RemoteGraphicsView, adding items, and signals/slots

99 views
Skip to first unread message

Geoffrey Barrett

unread,
Dec 8, 2017, 11:10:53 AM12/8/17
to pyqtgraph
Hello,

I am trying to do something similar to the crosshair.py example but with RemoteGraphicsView. 

Hypothetically if I have something similar to this:

from PyQt4 import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import pyqtgraph.widgets.RemoteGraphicsView
import sys

class main_window(QtGui.QWidget):
   
"""class that will serve as main window"""
   
def __init__(self):
       
super(main_window, self).__init__()

       
# view 1
       self.view1 = pg.widgets.RemoteGraphicsView.RemoteGraphicsView()
       self.plot1 = self.view1.pg.PlotItem()
       self.view1.setCentralItem(self.plot1)

       # view 2
       self.view2 = pg.widgets.RemoteGraphicsView.RemoteGraphicsView()
       self.plot2 = self.view2.pg.PlotItem()
       self.view2.setCentralItem(self.plot2)
        
       # add Layout to widget
       layout = QtGui.QVBoxLayout()
       layout.addWidget(self.view1)
       layout
.addWidget(self.view2)

       self.setLayout(layout)

       
self.show()

       
self.plot()

   
def plot(self):
       """Plot random stuff for test"""
       t = np.arange(10000)/500
       data = np.random.rand(1, len(t))
       self.plot1.plot(t, data.flatten())
       
self.plot2.plot(t, data.flatten())
    
       
# add linear region item
       
# self.lr = pg.LinearRegionItem()  # this doesn't work it seems
       
# self.plot1.addItem(self.lr)
       # RuntimeError: super-class __init__() of type InfiniteLine was never called

       
self.lr = self.view2.pg.LinearRegionItem()  # this appears to work
       
self.plot2.addItem(self.lr)
       
       
self.lr_proxy = pg.multiprocess.proxy(self.update_view1, callSync='off', autoProxy=True)
       
self.lr.sigRegionChanged.connect(self.lr_proxy)



   
def update_view1(self):
       # This doesn't appear to be called at all
       minX, maxX, = self.lr.getRegion()
       
self.view2.vb.setXRange(minX, maxX)

def run():

    app
= pg.mkQApp()
    win
= main_window()
    sys
.exit(app.exec_())


if __name__ == '__main__':
    run
()


When you move the linear region nothing happens so there's something wrong. I used a proxy to connect the update_view1 slot to the sigRegionChanged signal because I was getting a pickling error otherwise. Any advice would be appreciated.

-Geoff
Message has been deleted

Geoffrey Barrett

unread,
Dec 8, 2017, 11:22:56 AM12/8/17
to pyqtgraph

Also should be the following (I mistakenly put view2 instead of view1:

def update_view1(self):
       
# This doesn't appear to be called at all
       minX
, maxX, = self.lr.getRegion()

       
self.plot1.vb.setXRange(minX, maxX)

Geoffrey Barrett

unread,
Mar 2, 2018, 1:55:41 PM3/2/18
to pyqtgraph
Still working on this issue if anyone has tried to remotely plot the crosshair example.


On Friday, December 8, 2017 at 11:10:53 AM UTC-5, Geoffrey Barrett wrote:
Reply all
Reply to author
Forward
0 new messages