示例#1
0
 def initialize_chart(self, restart=0):
     if restart == 1:
         self.timer2.stop()
         self.cax1.cla()
         self.ax3.cla()
         self.fig3.delaxes(self.cax3)
         divider = make_axes_locatable(self.ax3)
         self.cax3 = divider.append_axes('right', size='3%', pad=0)
         self.index3 = 0
         self.timer2.start()
     else:
         self.fig3, self.ax3 = plt.subplots()
         self.divider1 = make_axes_locatable(self.ax3)
         self.cax1 = self.divider1.append_axes('right', size='3%', pad=0)
         plotWidget = FigureCanvas(self.fig3)
         self.ui.bar_layout.addWidget(plotWidget)
         self.index3 = 0
         self.save_bar_v = save_video(self, self.index3, 2,
                                      self.ui.save_li[2],
                                      self.ui.prpgress_li[2])
         self.timer2 = QtCore.QTimer()
         self.timer2.setInterval(15)
         self.timer2.timeout.connect(self.update_chart)
         self.timer_li.append(self.timer2)
         self.timer2.start()
示例#2
0
    def __init__(self, parent: Optional[Any] = None) -> None:
        """ TODO: Write documentation.
        """
        # Initialize Qt widget
        super(QtWidgets.QWidget, self).__init__(parent=parent)

        # Initialize Panda3D app
        super(Panda3dViewer, self).__init__(window_type='offscreen')

        # Only accept focus by clicking on widget
        self.setFocusPolicy(Qt.ClickFocus)

        # Enable mouse control
        self.setMouseTracking(True)
        self._app.getMousePos = self.getMousePos
        self._app.taskMgr.add(self._app.move_orbital_camera_task,
                              "move_camera_task",
                              sort=2)

        # Create painter to render "screenshot" from panda3d
        self.paint_surface = QtGui.QPainter()

        # Start event loop
        self.clock = QtCore.QTimer()
        self.clock.setInterval(1000.0 / FRAMERATE)
        self.clock.timeout.connect(self.update)
        self.clock.start()
示例#3
0
    def __init__(self, *args, **kwargs):
        TimerBase.__init__(self, *args, **kwargs)

        # Create a new timer and connect the timeout() signal to the
        # _on_timer method.
        self._timer = QtCore.QTimer()
        self._timer.timeout.connect(self._on_timer)
        self._timer_set_interval()
示例#4
0
    def __init__(self):
        self.blocksr80comm = False
        self.blockv80comm = False  #True
        self.blockmotorcomm = False
        super().__init__()
        #
        #
        self.title = 'Ny-Ålesund Emission Measurements'
        self.setWindowTitle(self.title)
        #
        self.checkbox = False
        #
        self.emailsent = 0
        #
        self.initUI()
        #
        #        self._update_canvas()
        #
        self.bck = QtCore.QTimer()
        self.bck.setInterval(1000)
        self.bck.timeout.connect(self.Update_StatusBox)
        self.bck.start()

        self.rseq = QtCore.QTimer()
        self.rseq.setInterval(1000)
        self.rseq.timeout.connect(self.run_sequence)
        self.rseq.start()

        self.check_cond = QtCore.QTimer()
        self.check_cond.setInterval(1000)
        self.check_cond.timeout.connect(self.check_conditions)
        self.check_cond.start()

        self.timer_al = QtCore.QTimer()
        self.timer_al.setInterval(100)
        self.timer_al.timeout.connect(self._update_actual_line)
        self.timer_al.start()
示例#5
0
    def __init__(self,
                 wib_server='127.0.0.1',
                 config='femb0.json',
                 grid=False):
        super().__init__()

        self.wib = WIB(wib_server)
        self.config = config

        self._main = QtWidgets.QWidget()
        self._main.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setCentralWidget(self._main)
        layout = QtWidgets.QVBoxLayout(self._main)

        self.grid = QtWidgets.QGridLayout()
        if grid:
            self.views = [Hist2DView(), FFTView(), MeanView(), RMSView()]
            for i, v in enumerate(self.views):
                self.grid.addWidget(v, i % 2, i // 2)
        else:
            self.views = [Hist2DView(), MeanRMSView(), FFTView()]
            for i, v in enumerate(self.views):
                self.grid.addWidget(v, 0, i)
        layout.addLayout(self.grid)

        nav_layout = QtWidgets.QHBoxLayout()

        button = QtWidgets.QPushButton('Configure')
        nav_layout.addWidget(button)
        button.setToolTip('Configure WIB and front end')
        button.clicked.connect(self.configure_wib)

        button = QtWidgets.QPushButton('Acquire')
        nav_layout.addWidget(button)
        button.setToolTip('Read WIB Spy Buffer')
        button.clicked.connect(self.acquire_data)

        button = QtWidgets.QPushButton('Continuous')
        nav_layout.addWidget(button)
        button.setToolTip('Repeat acquisitions until stopped')
        button.clicked.connect(self.toggle_continuous)
        self.continuious_button = button

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.acquire_data)

        layout.addLayout(nav_layout)

        self.plot()
示例#6
0
 def save(self):
     self.frame_no = self.frame_no - np.int(self.frame_no != 0)
     self.save_btns.setText("Saving Progressing")
     self.directory = self.get_video_directory()
     if self.directory == None:
         self.directory = "kimo"
     frame = cv2.imread(f"imgs/img{self.graph_index}_0.jpeg")
     height, width, layers = frame.shape
     self.save_progress.show()
     self.video = cv2.VideoWriter(f"{self.directory}.avi", 0, 5,
                                  (width, height))
     self.index = 0
     self.timer = QtCore.QTimer()
     self.timer.setInterval(20)
     self.timer.timeout.connect(
         lambda: self.save_video_iterate(width, height))
     self.timer.start()
示例#7
0
    def initialize_map(self, restart=0):
        if restart == 1:
            if self.index > 0:
                self.timer.stop()
                self.pc.remove()
                self.cax.cla()
                self.index = 0
                self.fig.delaxes(self.cax)
                divider = make_axes_locatable(self.ax)
                self.cax = divider.append_axes('right', size='3%', pad=0)
                self.timer.start()

        else:
            self.fig, self.ax = plt.subplots()
            self.divider = make_axes_locatable(self.ax)
            self.cax = self.divider.append_axes('right', size='3%', pad=0)

            self.map = Basemap(projection='cyl',
                               resolution='h',
                               llcrnrlat=-90,
                               urcrnrlat=90,
                               llcrnrlon=-180,
                               urcrnrlon=180,
                               ax=self.ax)
            self.map.drawmapboundary(fill_color='aqua')
            self.map.fillcontinents(color='darkblue', lake_color='aqua')
            self.map.drawcoastlines()
            self.map.readshapefile(
                'ne_10m_admin_0_countries/ne_10m_admin_0_countries',
                'countries')
            plotWidget = FigureCanvas(self.fig)
            cid = self.fig.canvas.mpl_connect('button_press_event',
                                              self.on_press)
            self.index = 0
            self.ui.map_layout.addWidget(plotWidget)
            self.save_map_v = save_video(self, self.index, 0,
                                         self.ui.save_li[0],
                                         self.ui.prpgress_li[0])
            self.timer = QtCore.QTimer()
            self.timer.setInterval(80)
            self.timer.timeout.connect(self.update_map)
            self.timer_li.append(self.timer)
            self.timer.start()
示例#8
0
 def initialize_bubble(self, restart=0):
     if restart == 1:
         self.timer1.stop()
         self.ax1.cla()
         self.index1 = 0
         self.timer1.start()
     else:
         self.fig1, self.ax1 = plt.subplots()
         plotWidget = FigureCanvas(self.fig1)
         self.ui.buble_layout.addWidget(plotWidget)
         self.index1 = 0
         self.last_values = [[0] * self.countries_no] * 3
         self.save_buble_v = save_video(self, self.index1, 1,
                                        self.ui.save_li[1],
                                        self.ui.prpgress_li[1])
         self.timer1 = QtCore.QTimer()
         self.timer1.setInterval(15)
         self.timer1.timeout.connect(self.update_bubble)
         self.timer_li.append(self.timer1)
         self.timer1.start()
示例#9
0
    def __init__(self, publisher, *args, **kwargs):
        self.pub = publisher

        # Initialise the different maps for the display of the mems surface
        self.map_index, self.map_index_h = fits.getdata(FCTRLV2_PATH + MEMS_INDEX_NAME, header=True)
        self.map_height, self.map_width = np.shape(self.map_index)
        self.map_opd = np.ones((self.map_height, self.map_width))
        self.map_opd[self.map_index == 0] = 0
        self.map_centers = np.loadtxt(FCTRLV2_PATH + MEMS_CENTERS_NAME, dtype=np.int)
        self.map_radius_x = np.ones((self.map_height, self.map_width))
        self.map_radius_y = np.ones((self.map_height, self.map_width))
        self.compute_radii()

        # Initialise the figure (canvas)
        MyMplCanvas.__init__(self, *args, **kwargs)
        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.update_figure)
        timer.start(100)

        self.mems = Mems(self.pub)
        self.mems.connect()
        self.mems.flat()
示例#10
0
    def __init__(self, model, interactive, data=None):
        """
        :param model: model.Model
        :param interactive: bool
            Boolean indicating if we are running in an interactive setting
            such as an ipython session. Helpful for deciding to parse CLI args,
            or not.
        :param data:
            Some type of array container, e.g. pandas.DataFrame,
            see `View.load_seria`

        """
        super(View, self).__init__()
        self.actions = {}
        self.model = model

        self.avail_slots_by_signal = {}
        self.avail_slots_by_signal['sig_new_data'] = [self.model.add_dataitem]
        self.avail_slots_by_signal['sig_new_markings'] = [
            self.model.new_markings_from_description
        ]
        self.avail_slots_by_signal['sig_apply_on_visible'] = [
            self.model.apply_on_visible,
        ]

        self.avail_signals = {}
        # Populate initially with signals from model
        for k, v in self.model.signals.items():
            self.avail_signals[k] = v

        self.draw_timer = QtCore.QTimer()
        self.init_ui()
        self.canvas_redraw()

        if not interactive:
            QtCore.QTimer.singleShot(0, self.parse_sysargs)
        if data is not None:
            logger.debug('Scheduling load-data callback')
            QtCore.QTimer.singleShot(0, lambda: self.load_seria(data))
示例#11
0
 def __init__(self,wib_server='127.0.0.1',config='default.json',rows=1,cols=1,layout=None):
     super().__init__()
     plot_layout = layout
     
     self.context = zmq.Context()
     self.socket = self.context.socket(zmq.REQ)
     self.socket.connect('tcp://%s:1234'%wib_server)
     self.config = config
     
     self.samples = None
     self.timestamps = None
     
     self._main = QtWidgets.QWidget()
     self._main.setFocusPolicy(QtCore.Qt.StrongFocus)
     self.setCentralWidget(self._main)
     layout = QtWidgets.QVBoxLayout(self._main)
     
     button_layout = QtWidgets.QHBoxLayout()
     
     button = QtWidgets.QPushButton('Reshape')
     button_layout.addWidget(button)
     button.setToolTip('Change the plot grid shape')
     button.clicked.connect(self.reshape_prompt)
     
     button = QtWidgets.QPushButton('Load Layout')
     button_layout.addWidget(button)
     button.setToolTip('Save plot layout and selected signals')
     button.clicked.connect(self.load_layout)
     
     button = QtWidgets.QPushButton('Save Layout')
     button_layout.addWidget(button)
     button.setToolTip('Load plot layout and selected signals')
     button.clicked.connect(self.save_layout)
     
     layout.addLayout(button_layout)
     
     self.grid = QtWidgets.QGridLayout()
     self.views = []
     self.reshape(rows,cols)
     layout.addLayout(self.grid)
     
     nav_layout = QtWidgets.QHBoxLayout()
     
     button = QtWidgets.QPushButton('Configure')
     nav_layout.addWidget(button)
     button.setToolTip('Configure WIB and front end')
     button.clicked.connect(self.configure_wib)
     
     button = QtWidgets.QPushButton('Enable Pulser')
     nav_layout.addWidget(button)
     button.setToolTip('Toggle calibration pulser')
     button.clicked.connect(self.toggle_pulser)
     self.pulser_button = button
     
     button = QtWidgets.QPushButton('Acquire')
     nav_layout.addWidget(button)
     button.setToolTip('Read WIB Spy Buffer')
     button.clicked.connect(self.acquire_data)
     
     button = QtWidgets.QPushButton('Continuous')
     nav_layout.addWidget(button)
     button.setToolTip('Repeat acquisitions until stopped')
     button.clicked.connect(self.toggle_continuious)
     self.continuious_button = button
     
     self.timer = QtCore.QTimer(self)
     self.timer.timeout.connect(self.acquire_data)
     
     layout.addLayout(nav_layout)
     
     if plot_layout:
         self.load_layout(plot_layout)
     self.plot_selected()
示例#12
0
 def __init__(self, *args, **kwargs):
     MyMplCanvas.__init__(self, *args, **kwargs)
     timer = QtCore.QTimer(self)
     timer.timeout.connect(self.update_figure)
     timer.start(20)
示例#13
0
def default_during_task(blocking_event):
    """
    The default setting for the RunEngine's during_task parameter.

    This makes it possible for plots that use matplotlib's Qt backend to update
    live during data acquisition.

    It solves the problem that Qt must be run from the main thread.
    If matplotlib and a known Qt binding are already imported, run the
    matplotlib qApp until the task completes. If not, there is no need to
    handle qApp: just wait on the task.
    """
    global _qapp
    if 'matplotlib' not in sys.modules:
        # We are not using matplotlib + Qt. Just wait on the Event.
        blocking_event.wait()
    # Figure out if we are using matplotlib with which backend
    # without importing anything that is not already imported.
    else:
        import matplotlib
        backend = matplotlib.get_backend().lower()
        # if with a Qt backend, do the scary thing
        if 'qt' in backend:
            from matplotlib.backends.qt_compat import QtCore, QtWidgets
            app = QtWidgets.QApplication.instance()
            if app is None:
                _qapp = app = QtWidgets.QApplication([b'bluesky'])
            assert app is not None
            event_loop = QtCore.QEventLoop()

            def start_killer_thread():
                def exit_loop():
                    blocking_event.wait()
                    # If the above wait ends quickly, we need to avoid the race
                    # condition where this thread might try to exit the qApp
                    # before it even starts.  Therefore, we use QTimer, below,
                    # which will not start running until the qApp event loop is
                    # running.
                    event_loop.exit()

                threading.Thread(target=exit_loop).start()

            # https://www.riverbankcomputing.com/pipermail/pyqt/2015-March/035674.html
            # adapted from code at
            # https://bitbucket.org/tortoisehg/thg/commits/550e1df5fbad
            if os.name == 'posix' and hasattr(signal, 'set_wakeup_fd'):
                # Wake up Python interpreter via pipe so that SIGINT
                # can be handled immediately.
                # (http://qt-project.org/doc/qt-4.8/unix-signals.html)
                # Updated docs:
                # https://doc.qt.io/qt-5/unix-signals.html
                import fcntl
                rfd, wfd = os.pipe()
                for fd in (rfd, wfd):
                    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
                    fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
                wakeupsn = QtCore.QSocketNotifier(rfd,
                                                  QtCore.QSocketNotifier.Read)
                origwakeupfd = signal.set_wakeup_fd(wfd)

                def cleanup():
                    wakeupsn.setEnabled(False)
                    rfd = wakeupsn.socket()
                    wfd = signal.set_wakeup_fd(origwakeupfd)
                    os.close(int(rfd))
                    os.close(wfd)

                def handleWakeup(inp):
                    # here Python signal handler will be invoked
                    # this book-keeping is to drain the pipe
                    wakeupsn.setEnabled(False)
                    rfd = wakeupsn.socket()
                    try:
                        os.read(int(rfd), 4096)
                    except OSError as inst:
                        print('failed to read wakeup fd: %s\n' % inst)

                    wakeupsn.setEnabled(True)

                wakeupsn.activated.connect(handleWakeup)

            else:
                # On Windows, non-blocking anonymous pipe or socket is
                # not available.

                def null():
                    ...

                # we need to 'kick' the python interpreter so it sees
                # system signals
                # https://stackoverflow.com/a/4939113/380231
                kick_timer = QtCore.QTimer()
                kick_timer.timeout.connect(null)
                kick_timer.start(50)

                cleanup = kick_timer.stop

            # we also need to make sure that the qApp never sees
            # exceptions raised by python inside of a c++ callback (as
            # it will segfault its self because due to the way the
            # code is called there is no clear way to propgate that
            # back to the python code.
            vals = (None, None, None)

            old_sys_handler = sys.excepthook

            def my_exception_hook(exctype, value, traceback):
                nonlocal vals
                vals = (exctype, value, traceback)
                event_loop.exit()
                old_sys_handler(exctype, value, traceback)

            # this kill the Qt event loop when the plan is finished
            killer_timer = QtCore.QTimer()
            killer_timer.setSingleShot(True)
            killer_timer.timeout.connect(start_killer_thread)
            killer_timer.start(0)

            try:
                sys.excepthook = my_exception_hook
                event_loop.exec_()
                # make sure any pending signals are processed
                event_loop.processEvents()
                if vals[1] is not None:
                    raise vals[1]
            finally:
                try:
                    cleanup()
                finally:
                    sys.excepthook = old_sys_handler
        elif 'ipympl' in backend or 'nbagg' in backend:
            Gcf = matplotlib._pylab_helpers.Gcf
            while True:
                done = blocking_event.wait(.1)
                for f_mgr in Gcf.get_all_fig_managers():
                    if f_mgr.canvas.figure.stale:
                        f_mgr.canvas.draw()
                if done:
                    return
        else:
            # We are not using matplotlib + Qt. Just wait on the Event.
            blocking_event.wait()
示例#14
0
 def alarm_timers(self, period=500):
     self.alarm = QtCore.QTimer(self)
     self.alarm.setInterval(period)
     self.alarm.timeout.connect(self.read_adc_channels)
     self.alarm.start()