Пример #1
0
    def __init__(self, parent=None):
        super(CurveDisplayLeftPanel, self).__init__(parent)
        self.displayed_curve_id = None
        self.setup_plot_widget()
        self.lay = QtGui.QVBoxLayout()

        self.lay.addWidget(self.toolbar)
        self.lay.addWidget(self.plot_widget)
        self.alter_curve_widget = CurveAlterWidget(self)
        self.alter_curve_widget.curve_saved.connect(self.save_pressed)
        self.alter_curve_widget.delete_done.connect(self.delete_done)
        self.lay.addWidget(self.alter_curve_widget)
        self.setLayout(self.lay)
Пример #2
0
 def __init__(self, parent=None):
     super(CurveDisplayLeftPanel, self).__init__(parent)     
     self.displayed_curve_id = None
     self.setup_plot_widget()
     self.lay = QtGui.QVBoxLayout()
     
     self.lay.addWidget(self.toolbar)
     self.sublay = QtGui.QHBoxLayout()
     self.lay.addLayout(self.sublay)
     self.sublay.addWidget(self.data_repr_combobox)
     #self.label_children = QtGui.QLabel('show children?')
     self.children_checkbox.setText('show children?')
     self.sublay.addWidget(self.children_checkbox)
     self.downsample_checkbox.setText('downsample ? (50000 points max)')
     self.sublay.addWidget(self.downsample_checkbox)
     self.label_image = ImageLabel(self)
     self.label_image.setMinimumHeight(500)
     self.lay.addWidget(self.label_image)
     self.label_image.hide()
     #self.label_image.setScaledContents(True)
     #self.sublay.addWidget(self.label_children)
     self.lay.addWidget(self.plot_widget)
     self.alter_curve_widget = CurveAlterWidget(self)
     self.alter_curve_widget.curve_saved.connect(self.save_pressed)
     self.alter_curve_widget.delete_done.connect(self.delete_done)
     self.lay.addWidget(self.alter_curve_widget)
     self.setLayout(self.lay)
Пример #3
0
 def __init__(self, parent=None):
     super(CurveDisplayLeftPanel, self).__init__(parent)     
     self.displayed_curve_id = None
     self.setup_plot_widget()
     self.lay = QtGui.QVBoxLayout()
     
     self.lay.addWidget(self.toolbar)
     self.lay.addWidget(self.plot_widget)
     self.alter_curve_widget = CurveAlterWidget(self)
     self.alter_curve_widget.curve_saved.connect(self.save_pressed)
     self.alter_curve_widget.delete_done.connect(self.delete_done)
     self.lay.addWidget(self.alter_curve_widget)
     self.setLayout(self.lay)
Пример #4
0
class CurveDisplayLeftPanel(QtGui.QWidget):
    delete_done = QtCore.pyqtSignal()
    save_pressed = QtCore.pyqtSignal()
    
    def __init__(self, parent=None):
        super(CurveDisplayLeftPanel, self).__init__(parent)     
        self.displayed_curve_id = None
        self.setup_plot_widget()
        self.lay = QtGui.QVBoxLayout()
        
        self.lay.addWidget(self.toolbar)
        self.sublay = QtGui.QHBoxLayout()
        self.lay.addLayout(self.sublay)
        self.sublay.addWidget(self.data_repr_combobox)
        #self.label_children = QtGui.QLabel('show children?')
        self.children_checkbox.setText('show children?')
        self.sublay.addWidget(self.children_checkbox)
        self.downsample_checkbox.setText('downsample ? (50000 points max)')
        self.sublay.addWidget(self.downsample_checkbox)
        self.label_image = ImageLabel(self)
        self.label_image.setMinimumHeight(500)
        self.lay.addWidget(self.label_image)
        self.label_image.hide()
        #self.label_image.setScaledContents(True)
        #self.sublay.addWidget(self.label_children)
        self.lay.addWidget(self.plot_widget)
        self.alter_curve_widget = CurveAlterWidget(self)
        self.alter_curve_widget.curve_saved.connect(self.save_pressed)
        self.alter_curve_widget.delete_done.connect(self.delete_done)
        self.lay.addWidget(self.alter_curve_widget)
        self.setLayout(self.lay)
        
    @property
    def displayed_curve(self):
        if self.displayed_curve_id:
            try:
                return models.CurveDB.objects.get(id=self.displayed_curve_id)
            except ObjectDoesNotExist:
                return None
    
    def setup_plot_widget(self):
        self.plot_widget = plot.CurveWidget(self, 'curve graph',
                                            show_itemlist=False)
        self.plot_widget.plot.set_antialiasing(False)
        
        #self.plot_widget.register_all_curve_tools()
        #self.plot_widget.add_tool(guiqwt.tools.AntiAliasingTool)
         #---guiqwt plot manager
        self.manager = plot.PlotManager(self)
        #---Register plot to manager
        self.manager.add_plot(self.plot_widget.plot)
        #---
        #---Add toolbar and register manager tools
        #toolbar = self.parent().addToolBar("tools")
        self.toolbar = QtGui.QToolBar("plot tools", self)
        self.autoscale = QtGui.QAction(QtGui.QIcon(
                                    osp.join(osp.dirname(__file__)
                                             ,'autoscale.png'))
                                           ,'',
                                           None)
        self.autoscale.setCheckable(True)
        self.autoscale.changed.connect(self.autoscale_changed)
        
        self.toolbar.addAction(self.autoscale)
        self.manager.add_toolbar(self.toolbar, id(self.toolbar))
        
        self.cursor_button = QtGui.QAction(QtGui.QIcon(
                                    osp.join(osp.dirname(__file__)
                                             ,'xcursor.png'))
                                           ,'',
                                           None)
        
        plot_win = self.plot_widget.plot
        self.cursor1 = make.xcursor(0,0, label='x = %.2f<br>y = %.2f')
        self.cursor1.markerparam.sel_text.textcolor = QtGui.QColor('blue')
        self.cursor1.markerparam.text.textcolor = QtGui.QColor('blue')
        self.cursor1.markerparam.line.color = QtGui.QColor('blue')
        self.cursor1.markerparam.sel_line.color = QtGui.QColor('blue')
        self.cursor1.markerparam.sel_symbol.facecolor = QtGui.QColor('blue')
        self.cursor1.markerparam.symbol.facecolor = QtGui.QColor('blue')
        self.cursor1.itemChanged()
        plot_win.add_item(self.cursor1)
        
        self.cursor2 = make.xcursor(0,0, label='x = %.2f<br>y = %.2f')
        plot_win.add_item(self.cursor2)
        self.cursor_button_clicked()
        
        self.cursor1.label_cb = self.cursor_moved
        self.cursor2.label_cb = self.cursor_delta_moved
        
        self.cursor_button.setCheckable(True)
        self.toolbar.addAction(self.cursor_button)
        self.cursor_button.changed.connect(self.cursor_button_clicked)
        
        self.toolbar.addSeparator()
        
        self.data_repr_combobox = QtGui.QComboBox()
        self.data_repr_combobox.currentIndexChanged.connect(self.refresh)
        self.children_checkbox = QtGui.QCheckBox()
        self.children_checkbox.stateChanged.connect(self.refresh)
        self.downsample_checkbox = QtGui.QCheckBox()
        self.downsample_checkbox.setChecked(True)
        self.downsample_checkbox.stateChanged.connect(self.refresh)
        
    
        self.curve_item = make.curve([], [], "Main Curve")#,
                                      #'b',
                                       #'NoPen',
                                       # linewidth=1,
                                       #  markerfacecolor='b', 
                                       #  marker='.',
                                       #  markeredgecolor='b')
        self.plot_widget.plot.add_item(self.curve_item)
        self.extra_curve_items = []
        
        #self.manager.register_all_curve_tools()
        
        ##
        self.manager.register_standard_tools()
        self.manager.add_tool(CutSignalTool)
#        self.manager.add_tool(DeltaCursorsTool)
        self.manager.add_tool(PrintTool)
#        self.manager.add_tool(AspectRatioTool)
        ##
        #=============================
        # for tools such as CurveStatsTool to work 
        # the curve needs to have been selected at least once.
        self.plot_widget.plot.set_active_item(self.curve_item)
        self.curve_item.unselect()
        #=============================


    def autoscale_changed(self):
        if self.autoscale.isChecked():
            self.plot_widget.plot.do_autoscale()

    def cursor_moved(self, x1, y1):
        return 'x = %.2e<br>y = %.2e'%(x1, y1)

    def cursor_delta_moved(self, x2, y2):
        x1, y1 = self.cursor1.get_pos()
        return 'Dx = %.2e<br>Dy = %.2e'%(x2 - x1, y2 - y1)
        
    def cursor_button_clicked(self):
        plot_win = self.plot_widget.plot
        if self.cursor_button.isChecked():
            (xmin, xmax, ymin, ymax) = plot_win.get_plot_limits()
            self.cursor1.set_pos((xmin + xmax)/2, (ymin + ymax)/2)
            self.cursor2.set_pos((xmin + 2*xmax)/3, (ymin + 2*ymax)/3)

            self.cursor1.show()
            self.cursor2.show()
            self.manager.activate_default_tool()
        else:
            self.cursor1.hide()
            self.cursor2.hide()
        plot_win.replot()
    @property
    def selected_data_repr(self):
        return str(self.data_repr_combobox.currentText())
    
    @property
    def is_display_children(self):
        return self.children_checkbox.checkState()==2

    @property
    def is_downsample(self):
        return self.downsample_checkbox.checkState()==2
        
    def plot_one_curve(self, curvedata, erase_all=True):
        #downsample large files for quick preview
        
        if erase_all:
            for ci in self.extra_curve_items:
                ci.hide()
            self.curve_item.set_data(array(curvedata.index, dtype=float), 
                                 array(curvedata.values, dtype=float))
        else:
            current = None
            for ci in self.extra_curve_items:
                if ci.isVisible():
                    continue
                else:
                    current = ci
                    break
            if current is None:
                current = make.curve([], [], 'child_curve',LIST_COLOR[len(self.extra_curve_items)%len(LIST_COLOR)])
                self.plot_widget.plot.add_item(current)
                self.extra_curve_items.append(current)
            current.set_data(array(curvedata.index, dtype=float), 
                                array(curvedata.values, dtype=float))
            current.show()
            
    def display_curve(self, curve):
        self.displayed_curve_id = curve.id
        if curve:
            self.plot_widget.get_plot().set_title(str(curve.id) + " (" + curve.params["curve_type"] + ")")
            #self.plot_widget.title = str(curve.id)
            
            self.data_repr_combobox.blockSignals(True)
            self.data_repr_combobox.clear()
            self.data_repr_combobox.addItems(curve.data_repr())
            
            if curve.current_data_repr in curve.data_repr():
                index = curve.data_repr().index(curve.current_data_repr)
            else:
                index = 0
            self.data_repr_combobox.setCurrentIndex(index)
            curve.current_data_repr = str(self.data_repr_combobox.currentText())
            self.data_repr_combobox.blockSignals(False)
            
            data_repr = curve.current_data_repr
            
            self.alter_curve_widget.display_curve(curve)
            
            if not curve.params['user_has_read']:
                curve.params['user_has_read'] = True
                curve.save()
            self.alter_curve_widget.save_button.hide()
            
            if data_repr=='image':
                self.plot_widget.hide()
                self.toolbar.hide()
                #self.data_repr_combobox.hide()
                self.children_checkbox.hide()
                self.downsample_checkbox.hide()
                
                filename = curve.get_full_dirname()+'/display'+str(curve.pk)+'.png'
                if not osp.exists(filename):
                    filename = curve.get_full_dirname()+'/display.png'
                self.label_image.setPixmap(QtGui.QPixmap(
                                curve.get_full_dirname()+'/display.png'))
                self.label_image.show()
                return
            
            self.label_image.hide()
            self.plot_widget.show()
            self.toolbar.show()
            #self.data_repr_combobox.show()
            self.children_checkbox.show()
            self.downsample_checkbox.show()
            
            curvedata = curve.get_plottable_data(curve.data, data_repr, self.is_downsample)
            self.plot_one_curve(curvedata, erase_all=True)
    
            if self.is_display_children:
                for child in curve.childs.all():
                    curvedata = curve.get_plottable_data(child.data, data_repr, self.is_downsample)
                    self.plot_one_curve(curvedata, erase_all=False)
            
            if self.autoscale.isChecked():
                self.curve_item.plot().do_autoscale()
            self.curve_item.plot().replot()
        
    def refresh(self):
        if self.displayed_curve:
            self.displayed_curve.__class__.current_data_repr = self.selected_data_repr
            self.display_curve(self.displayed_curve)
    
    def save_curve(self, curve):
        self.alter_curve_widget.save_curve(curve) 
Пример #5
0
class CurveDisplayLeftPanel(QtGui.QWidget):
    delete_done = QtCore.pyqtSignal()
    save_pressed = QtCore.pyqtSignal()
    
    def __init__(self, parent=None):
        super(CurveDisplayLeftPanel, self).__init__(parent)     
        self.displayed_curve_id = None
        self.setup_plot_widget()
        self.lay = QtGui.QVBoxLayout()
        
        self.lay.addWidget(self.toolbar)
        self.lay.addWidget(self.plot_widget)
        self.alter_curve_widget = CurveAlterWidget(self)
        self.alter_curve_widget.curve_saved.connect(self.save_pressed)
        self.alter_curve_widget.delete_done.connect(self.delete_done)
        self.lay.addWidget(self.alter_curve_widget)
        self.setLayout(self.lay)
        
    @property
    def displayed_curve(self):
        if self.displayed_curve_id:
            return models.CurveDB.objects.get(id=self.displayed_curve_id)
    
    def setup_plot_widget(self):
        self.plot_widget = plot.CurveWidget(self, 'curve graph',
                                            show_itemlist=False)
        self.plot_widget.plot.set_antialiasing(True)
        
        #self.plot_widget.register_all_curve_tools()
        #self.plot_widget.add_tool(guiqwt.tools.AntiAliasingTool)
         #---guiqwt plot manager
        self.manager = plot.PlotManager(self)
        #---Register plot to manager
        self.manager.add_plot(self.plot_widget.plot)
        #---
        #---Add toolbar and register manager tools
        #toolbar = self.parent().addToolBar("tools")
        self.toolbar = QtGui.QToolBar("plot tools", self)
        self.autoscale = NamedCheckBox(self, 'autoscale')
        self.autoscale.checked.connect(self.plot_widget.plot.do_autoscale)
        self.toolbar.addWidget(self.autoscale)
        self.manager.add_toolbar(self.toolbar, id(self.toolbar))
    
        self.curve_item = make.curve([], [], color='b')
        self.plot_widget.plot.add_item(self.curve_item)
        
        self.manager.register_all_curve_tools()
        self.manager.add_tool(CutSignalTool)
        #=============================
        # for tools such as CurveStatsTool to work 
        # the curve needs to have been selected at least once.
        self.plot_widget.plot.set_active_item(self.curve_item)
        self.curve_item.unselect()
        #=============================

    def display_curve(self, curve):
        self.displayed_curve_id = curve.id
        if curve:
            self.plot_widget.get_plot().set_title(str(curve.id) + " (" + curve.params["curve_type"] + ")")
            #self.plot_widget.title = str(curve.id)
            curvedata = curve.get_plottable_data()
            #downsample large files for quick preview
            if len(curvedata)>50000:
                dsfactor = len(curvedata)//5000
                curvedata = curvedata[range(0,len(curvedata),dsfactor)]
            self.alter_curve_widget.display_curve(curve)
            self.curve_item.set_data(array(curvedata.index, dtype = float), 
                                    array(curvedata.values, dtype = float))
            
            if self.autoscale:
                self.curve_item.plot().do_autoscale()
            self.curve_item.plot().replot()
        
            if not curve.params['user_has_read']:
                curve.params['user_has_read'] = True
                curve.save()
            self.alter_curve_widget.save_button.hide()
            
    def refresh(self):
        if self.displayed_curve:
            self.display_curve(self.displayed_curve)
    
    def save_curve(self, curve):
        self.alter_curve_widget.save_curve(curve) 
Пример #6
0
class CurveDisplayLeftPanel(QtGui.QWidget):
    delete_done = QtCore.pyqtSignal()
    save_pressed = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        super(CurveDisplayLeftPanel, self).__init__(parent)
        self.displayed_curve_id = None
        self.setup_plot_widget()
        self.lay = QtGui.QVBoxLayout()

        self.lay.addWidget(self.toolbar)
        self.lay.addWidget(self.plot_widget)
        self.alter_curve_widget = CurveAlterWidget(self)
        self.alter_curve_widget.curve_saved.connect(self.save_pressed)
        self.alter_curve_widget.delete_done.connect(self.delete_done)
        self.lay.addWidget(self.alter_curve_widget)
        self.setLayout(self.lay)

    @property
    def displayed_curve(self):
        if self.displayed_curve_id:
            return models.CurveDB.objects.get(id=self.displayed_curve_id)

    def setup_plot_widget(self):
        self.plot_widget = plot.CurveWidget(self,
                                            'curve graph',
                                            show_itemlist=False)
        self.plot_widget.plot.set_antialiasing(True)

        #self.plot_widget.register_all_curve_tools()
        #self.plot_widget.add_tool(guiqwt.tools.AntiAliasingTool)
        #---guiqwt plot manager
        self.manager = plot.PlotManager(self)
        #---Register plot to manager
        self.manager.add_plot(self.plot_widget.plot)
        #---
        #---Add toolbar and register manager tools
        #toolbar = self.parent().addToolBar("tools")
        self.toolbar = QtGui.QToolBar("plot tools", self)
        self.autoscale = NamedCheckBox(self, 'autoscale')
        self.autoscale.checked.connect(self.plot_widget.plot.do_autoscale)
        self.toolbar.addWidget(self.autoscale)
        self.manager.add_toolbar(self.toolbar, id(self.toolbar))

        self.curve_item = make.curve([], [], color='b')
        self.plot_widget.plot.add_item(self.curve_item)

        self.manager.register_all_curve_tools()
        self.manager.add_tool(CutSignalTool)
        #=============================
        # for tools such as CurveStatsTool to work
        # the curve needs to have been selected at least once.
        self.plot_widget.plot.set_active_item(self.curve_item)
        self.curve_item.unselect()
        #=============================

    def display_curve(self, curve):
        self.displayed_curve_id = curve.id
        if curve:
            self.plot_widget.get_plot().set_title(
                str(curve.id) + " (" + curve.params["curve_type"] + ")")
            #self.plot_widget.title = str(curve.id)
            curvedata = curve.get_plottable_data()
            #downsample large files for quick preview
            if len(curvedata) > 50000:
                dsfactor = len(curvedata) // 5000
                curvedata = curvedata[range(0, len(curvedata), dsfactor)]
            self.alter_curve_widget.display_curve(curve)
            self.curve_item.set_data(array(curvedata.index, dtype=float),
                                     array(curvedata.values, dtype=float))

            if self.autoscale:
                self.curve_item.plot().do_autoscale()
            self.curve_item.plot().replot()

            if not curve.params['user_has_read']:
                curve.params['user_has_read'] = True
                curve.save()
            self.alter_curve_widget.save_button.hide()

    def refresh(self):
        if self.displayed_curve:
            self.display_curve(self.displayed_curve)

    def save_curve(self, curve):
        self.alter_curve_widget.save_curve(curve)