Changeset 8cb6cd6 in sasview for src/sas/qtgui/DataExplorer.py


Ignore:
Timestamp:
Jul 12, 2016 8:44:53 AM (8 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
e3ae090
Parents:
a95260d
Message:

Plot handler prototype + append plot functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/DataExplorer.py

    r0cd8612 r8cb6cd6  
    1313 
    1414# SAS 
    15 import GuiUtils 
    16 from Plotter import Plotter 
    1715from sas.sascalc.dataloader.loader import Loader 
    1816from sas.sasgui.guiframe.data_manager import DataManager 
     
    2018from sas.sasgui.guiframe.dataFitting import Data2D 
    2119 
     20import GuiUtils 
     21import PlotHelper 
     22from Plotter import Plotter 
    2223from DroppableDataLoadWidget import DroppableDataLoadWidget 
    2324 
     
    4647        # Be careful with twisted threads. 
    4748        self.mutex = QMutex() 
     49 
     50        # Active plots 
     51        self.active_plots = [] 
    4852 
    4953        # Connect the buttons 
     
    5458        self.cmdSendTo.clicked.connect(self.sendData) 
    5559        self.cmdNew.clicked.connect(self.newPlot) 
     60        self.cmdAppend.clicked.connect(self.appendPlot) 
    5661        self.cmdHelp.clicked.connect(self.displayHelp) 
    5762        self.cmdHelp_2.clicked.connect(self.displayHelp) 
     
    7681        self.communicator = self.parent.communicator() 
    7782        self.communicator.fileReadSignal.connect(self.loadFromURL) 
     83        self.communicator.activeGraphsSignal.connect(self.updateGraphCombo) 
     84        self.cbgraph.editTextChanged.connect(self.enableGraphCombo) 
     85        self.cbgraph.currentIndexChanged.connect(self.enableGraphCombo) 
    7886 
    7987        # Proxy model for showing a subset of Data1D/Data2D content 
     
    97105        self.freezeView.setModel(self.theory_proxy) 
    98106 
     107        self.enableGraphCombo(None) 
     108 
    99109    def closeEvent(self, event): 
    100110        """ 
     
    110120        self._helpView.load(QtCore.QUrl(_TreeLocation)) 
    111121        self._helpView.show() 
     122 
     123    def enableGraphCombo(self, combo_text): 
     124        """ 
     125        Enables/disables "Assign Plot" elements 
     126        """ 
     127        self.cbgraph.setEnabled(len(PlotHelper.currentPlots()) > 0) 
     128        self.cmdAppend.setEnabled(len(PlotHelper.currentPlots()) > 0) 
    112129 
    113130    def loadFromURL(self, url): 
     
    187204        delete_msg = "This operation will delete the checked data sets and all the dependents." +\ 
    188205                     "\nDo you want to continue?" 
    189         reply = QtGui.QMessageBox.question(self, 'Warning', delete_msg, 
    190                 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) 
     206        reply = QtGui.QMessageBox.question(self, 
     207                                           'Warning', 
     208                                           delete_msg, 
     209                                           QtGui.QMessageBox.Yes, 
     210                                           QtGui.QMessageBox.No) 
    191211 
    192212        if reply == QtGui.QMessageBox.No: 
     
    263283            if not outer_item: 
    264284                continue 
    265             for inner_index in xrange(outer_item.rowCount()): # Should be just two rows: data and Info 
     285            # Should be just two rows: data and Info 
     286            for inner_index in xrange(outer_item.rowCount()): 
    266287                subitem = outer_item.child(inner_index) 
    267                 if subitem and subitem.isCheckable() and subitem.checkState() == QtCore.Qt.Checked: 
     288                if subitem and \ 
     289                   subitem.isCheckable() and \ 
     290                   subitem.checkState() == QtCore.Qt.Checked: 
    268291                    theories_copied += 1 
    269292                    new_item = self.recursivelyCloneItem(subitem) 
    270293                    # Append a "unique" descriptor to the name 
    271                     time_bit = str(time.time())[7:-1].replace('.','') 
     294                    time_bit = str(time.time())[7:-1].replace('.', '') 
    272295                    new_name = new_item.text() + '_@' + time_bit 
    273296                    new_item.setText(new_name) 
     
    300323        return new_item 
    301324 
     325    def updateGraphCombo(self, graph_list): 
     326        """ 
     327        Modify Graph combo box on graph add/delete 
     328        """ 
     329        orig_text = self.cbgraph.currentText() 
     330        self.cbgraph.clear() 
     331        graph_titles = [] 
     332        for graph in graph_list: 
     333            graph_titles.append("Graph"+str(graph)) 
     334        self.cbgraph.insertItems(0, graph_titles) 
     335        ind = self.cbgraph.findText(orig_text) 
     336        if ind > 0: 
     337            self.cbgraph.setCurrentIndex(ind) 
     338        pass 
     339 
    302340    def newPlot(self): 
    303341        """ 
     
    306344        TODO: Add 2D-functionality 
    307345        """ 
    308  
    309346        plots = GuiUtils.plotsFromCheckedItems(self.model) 
    310347 
    311348        # Call show on requested plots 
    312         new_plot = Plotter() 
     349        new_plot = Plotter(self) 
    313350        for plot_set in plots: 
    314351            new_plot.data(plot_set) 
    315352            new_plot.plot() 
    316353 
     354        # Update the global plot counter 
     355        title = "Graph"+str(PlotHelper.idOfPlot(new_plot)) 
     356        new_plot.setWindowTitle(title) 
     357 
     358        # Add the plot to the workspace 
     359        self.parent.workspace().addWindow(new_plot) 
     360 
     361        # Show the plot 
    317362        new_plot.show() 
     363 
     364        # Update the active chart list 
     365        self.active_plots.append(title) 
     366 
     367    def appendPlot(self): 
     368        """ 
     369        Add data set(s) to the existing matplotlib chart 
     370 
     371        TODO: Add 2D-functionality 
     372        """ 
     373        # new plot data 
     374        new_plots = GuiUtils.plotsFromCheckedItems(self.model) 
     375 
     376        # old plot data 
     377        plot_id = self.cbgraph.currentText() 
     378        plot_id = int(plot_id[5:]) 
     379 
     380        assert plot_id in PlotHelper.currentPlots(), "No such plot: Graph%s"%str(plot_id) 
     381 
     382        old_plot = PlotHelper.plotById(plot_id) 
     383 
     384        # Add new data to the old plot 
     385        for plot_set in new_plots: 
     386            old_plot.data(plot_set) 
     387            old_plot.plot() 
    318388 
    319389    def chooseFiles(self): 
     
    424494                else: 
    425495                    error_message += "%s\n" % str(p_file) 
    426                 info = "error" 
    427496 
    428497            current_percentage = int(100.0* index/number_of_files) 
     
    563632        Post message to status bar and update the data manager 
    564633        """ 
    565         assert type(output) == tuple 
     634        assert isinstance(output, tuple) 
    566635 
    567636        # Reset the model so the view gets updated. 
Note: See TracChangeset for help on using the changeset viewer.