Changeset 133812c7 in sasview


Ignore:
Timestamp:
Nov 12, 2018 4:47:59 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
e5ae812
Parents:
ebcdb02
git-author:
Piotr Rozyczko <piotr.rozyczko@…> (10/31/18 04:34:14)
git-committer:
Piotr Rozyczko <piotr.rozyczko@…> (11/12/18 04:47:59)
Message:

Merged ESS_GUI

Location:
src/sas/qtgui
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Calculators/GenericScatteringCalculator.py

    r30e0be0 r133812c7  
    3333    trigger_plot_3d = QtCore.pyqtSignal() 
    3434    calculationFinishedSignal = QtCore.pyqtSignal() 
     35    loadingFinishedSignal = QtCore.pyqtSignal(list) 
    3536 
    3637    def __init__(self, parent=None): 
     
    104105        # plots - 3D in real space 
    105106        self.calculationFinishedSignal.connect(self.plot_1_2d) 
     107 
     108        # notify main thread about file load complete 
     109        self.loadingFinishedSignal.connect(self.complete_loading) 
    106110 
    107111        # TODO the option Ellipsoid has not been implemented 
     
    167171                        str(self.datafile)))) 
    168172                self.reader = GenReader(path=str(self.datafile), loader=loader, 
    169                                         completefn=self.complete_loading, 
     173                                        completefn=self.complete_loading_ex, 
    170174                                        updatefn=self.load_update) 
    171175                self.reader.queue() 
     
    184188        logging.info(status_type) 
    185189 
     190    def complete_loading_ex(self, data=None): 
     191        """ 
     192        Send the finish message from calculate threads to main thread 
     193        """ 
     194        self.loadingFinishedSignal.emit(data) 
     195 
    186196    def complete_loading(self, data=None): 
    187197        """ Function used in GenRead""" 
     198        assert isinstance(data, list) 
     199        assert len(data)==1 
     200        data = data[0] 
    188201        self.cbShape.setEnabled(False) 
    189202        try: 
  • src/sas/qtgui/MainWindow/DataExplorer.py

    rebcdb02 r133812c7  
    4949        self.parent = guimanager 
    5050        self.loader = Loader() 
     51 
     52        # Read in default locations 
     53        self.default_save_location = None 
     54        self.default_load_location = GuiUtils.DEFAULT_OPEN_FOLDER 
     55        self.default_project_location = None 
     56 
    5157        self.manager = manager if manager is not None else DataManager() 
    5258        self.txt_widget = QtWidgets.QTextEdit(None) 
     
    99105        self.communicator.extMaskEditorSignal.connect(self.extShowEditDataMask) 
    100106        self.communicator.changeDataExplorerTabSignal.connect(self.changeTabs) 
     107        self.communicator.forcePlotDisplaySignal.connect(self.displayData) 
     108        self.communicator.updateModelFromPerspectiveSignal.connect(self.updateModelFromPerspective) 
    101109 
    102110        self.cbgraph.editTextChanged.connect(self.enableGraphCombo) 
     
    205213        Opens the Qt "Open Folder..." dialog 
    206214        """ 
    207         folder = QtWidgets.QFileDialog.getExistingDirectory(self, "Choose a directory", "", 
    208               QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontUseNativeDialog) 
     215        kwargs = { 
     216            'parent'    : self, 
     217            'caption'   : 'Choose a directory', 
     218            'options'   : QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontUseNativeDialog, 
     219            'directory' : self.default_load_location 
     220        } 
     221        folder = QtWidgets.QFileDialog.getExistingDirectory(**kwargs) 
     222 
    209223        if folder is None: 
    210224            return 
    211225 
    212226        folder = str(folder) 
    213  
    214227        if not os.path.isdir(folder): 
    215228            return 
    216  
     229        self.default_load_location = folder 
    217230        # get content of dir into a list 
    218231        path_str = [os.path.join(os.path.abspath(folder), filename) 
     
    251264        filename = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0] 
    252265        if filename: 
     266            self.default_project_location = os.path.dirname(filename) 
    253267            self.deleteAllItems() 
    254268            self.readProject(filename) 
     
    276290            'caption'   : 'Save Project', 
    277291            'filter'    : 'Project (*.json)', 
    278             'options'   : QtWidgets.QFileDialog.DontUseNativeDialog 
     292            'options'   : QtWidgets.QFileDialog.DontUseNativeDialog, 
     293            'directory' : self.default_project_location 
    279294        } 
    280295        name_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     
    282297        if not filename: 
    283298            return 
     299        self.default_project_location = os.path.dirname(filename) 
    284300        _, extension = os.path.splitext(filename) 
    285301        if not extension: 
     
    616632        Send selected item data to the current perspective and set the relevant notifiers 
    617633        """ 
    618         # Set the signal handlers 
    619         self.communicator.updateModelFromPerspectiveSignal.connect(self.updateModelFromPerspective) 
    620  
    621634        def isItemReady(index): 
    622635            item = self.model.item(index) 
     
    903916            # Try the current item 
    904917            main_data = GuiUtils.dataFromItem(plot_item) 
     918        # 1D dependent plots of 2D sets - special treatment 
     919        if isinstance(main_data, Data2D) and isinstance(plot_to_show, Data1D): 
     920            main_data = None 
    905921 
    906922        # Make sure main data for 2D is always displayed 
    907         if main_data and not self.isPlotShown(main_data): 
     923        if main_data is not None and not self.isPlotShown(main_data): 
    908924            if isinstance(main_data, Data2D): 
    909925                self.plotData([(plot_item, main_data)]) 
     
    923939            # Plots with main data points on the same chart 
    924940            # Get the main data plot 
    925             if main_data and not self.isPlotShown(main_data): 
     941            if main_data is not None and not self.isPlotShown(main_data): 
    926942                new_plots.append((plot_item, main_data)) 
    927943            new_plots.append((plot_item, plot_to_show)) 
     
    10831099        # List of known extensions 
    10841100        wlist = self.getWlist() 
    1085  
    10861101        # Location is automatically saved - no need to keep track of the last dir 
    10871102        # But only with Qt built-in dialog (non-platform native) 
    1088         paths = QtWidgets.QFileDialog.getOpenFileNames(self, "Choose a file", "", 
    1089                 wlist, None, QtWidgets.QFileDialog.DontUseNativeDialog)[0] 
     1103        kwargs = { 
     1104            'parent'    : self, 
     1105            'caption'   : 'Choose files', 
     1106            'filter'    : wlist, 
     1107            'options'   : QtWidgets.QFileDialog.DontUseNativeDialog, 
     1108            'directory' : self.default_load_location 
     1109        } 
     1110        paths = QtWidgets.QFileDialog.getOpenFileNames(**kwargs)[0] 
    10901111        if not paths: 
    10911112            return 
     
    10941115            paths = [paths] 
    10951116 
     1117        self.default_load_location = os.path.dirname(paths[0]) 
    10961118        return paths 
    10971119 
     
    17291751            raise AttributeError(msg) 
    17301752 
    1731         # TODO: Assert other properties 
    1732  
    1733         # Reset the view 
    1734         ##self.model.reset() 
    1735         # Pass acting as a debugger anchor 
     1753        # send in the new item 
     1754        self.model.appendRow(model_item) 
    17361755        pass 
    17371756 
  • src/sas/qtgui/MainWindow/GuiManager.py

    rebcdb02 r133812c7  
    5151 
    5252from sas.qtgui.Utilities.AddMultEditor import AddMultEditor 
     53from sas.qtgui.Utilities.ImageViewer import ImageViewer 
    5354 
    5455logger = logging.getLogger(__name__) 
     
    352353        # Exit if yes 
    353354        if reply == QMessageBox.Yes: 
     355            # save the paths etc. 
     356            self.saveCustomConfig() 
    354357            reactor.callFromThread(reactor.stop) 
    355358            return True 
     
    457460        self._workspace.actionReset.setVisible(False) 
    458461        self._workspace.actionStartup_Settings.setVisible(False) 
    459         self._workspace.actionImage_Viewer.setVisible(False) 
     462        #self._workspace.actionImage_Viewer.setVisible(False) 
    460463        self._workspace.actionCombine_Batch_Fit.setVisible(False) 
    461464        # orientation viewer set to invisible SASVIEW-1132 
     
    825828        """ 
    826829        """ 
    827         print("actionImage_Viewer TRIGGERED") 
    828         pass 
     830        try: 
     831            self.image_viewer = ImageViewer(self) 
     832            if sys.platform == "darwin": 
     833                self.image_viewer.menubar.setNativeMenuBar(False) 
     834            self.image_viewer.show() 
     835        except Exception as ex: 
     836            logging.error(str(ex)) 
     837            return 
    829838 
    830839    #============ FITTING ================= 
     
    11141123        elif isinstance(perspective, Perspectives.PERSPECTIVES["Corfunc"]): 
    11151124            self.checkAnalysisOption(self._workspace.actionCorfunc) 
     1125 
     1126    def saveCustomConfig(self): 
     1127        """ 
     1128        Save the config file based on current session values 
     1129        """ 
     1130        # Load the current file 
     1131        config_content = GuiUtils.custom_config 
     1132 
     1133        changed = self.customSavePaths(config_content) 
     1134        changed = changed or self.customSaveOpenCL(config_content) 
     1135 
     1136        if changed: 
     1137            self.writeCustomConfig(config_content) 
     1138 
     1139    def customSavePaths(self, config_content): 
     1140        """ 
     1141        Update the config module with current session paths 
     1142        Returns True if update was done, False, otherwise 
     1143        """ 
     1144        changed = False 
     1145        # Find load path 
     1146        open_path = GuiUtils.DEFAULT_OPEN_FOLDER 
     1147        defined_path = self.filesWidget.default_load_location 
     1148        if open_path != defined_path: 
     1149            # Replace the load path 
     1150            config_content.DEFAULT_OPEN_FOLDER = defined_path 
     1151            changed = True 
     1152        return changed 
     1153 
     1154    def customSaveOpenCL(self, config_content): 
     1155        """ 
     1156        Update the config module with current session OpenCL choice 
     1157        Returns True if update was done, False, otherwise 
     1158        """ 
     1159        changed = False 
     1160        # Find load path 
     1161        file_value = GuiUtils.SAS_OPENCL 
     1162        session_value = os.environ.get("SAS_OPENCL", "") 
     1163        if file_value != session_value: 
     1164            # Replace the load path 
     1165            config_content.SAS_OPENCL = session_value 
     1166            changed = True 
     1167        return changed 
     1168 
     1169    def writeCustomConfig(self, config): 
     1170        """ 
     1171        Write custom configuration 
     1172        """ 
     1173        from sas import make_custom_config_path 
     1174        path = make_custom_config_path() 
     1175        # Just clobber the file - we already have its content read in 
     1176        with open(path, 'w') as out_f: 
     1177            out_f.write("#Application appearance custom configuration\n") 
     1178            for key, item in config.__dict__.items(): 
     1179                if key[:2] != "__": 
     1180                    if isinstance(item, str): 
     1181                        item = '"' + item + '"' 
     1182                    out_f.write("%s = %s\n" % (key, str(item))) 
     1183        pass # debugger anchor 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r17e2d502 r133812c7  
    24482448 
    24492449        # If multiple rows selected - toggle all of them, filtering uncheckable 
    2450         # Switch off signaling from the model to avoid recursion 
    2451         self._model_model.blockSignals(True) 
    24522450        # Convert to proper indices and set requested enablement 
    24532451        self.setParameterSelection(status) 
    2454         self._model_model.blockSignals(False) 
    24552452 
    24562453        # update the list of parameters to fit 
  • src/sas/qtgui/Perspectives/Fitting/GPUOptions.py

    rdb05c44 r133812c7  
    22import os 
    33import sys 
    4 import sasmodels 
    54import json 
    65import platform 
    76import webbrowser 
     7import logging 
     8 
     9import sasmodels 
     10import sasmodels.model_test 
     11import sasmodels.kernelcl 
    812 
    913import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     
    2630        return QtWidgets.QApplication.translate(context, text, disambig) 
    2731 
     32logger = logging.getLogger(__name__) 
    2833 
    2934class GPUOptions(QtWidgets.QDialog, Ui_GPUOptions): 
     
    106111                del os.environ["SAS_OPENCL"] 
    107112        # Sasmodels kernelcl doesn't exist when initiated with None 
    108         if 'sasmodels.kernelcl' in sys.modules: 
    109             sasmodels.kernelcl.ENV = None 
    110         from importlib import reload # assumed Python > 3.3 
    111         reload(sasmodels.core) 
     113        sasmodels.kernelcl.reset_environment() 
    112114        return no_opencl_msg 
    113115 
     
    123125 
    124126        try: 
    125             from sasmodels.kernelcl import environment 
    126             env = environment() 
     127            env = sasmodels.kernelcl.environment() 
    127128            clinfo = [(ctx.devices[0].platform.vendor, 
    128129                       ctx.devices[0].platform.version, 
     
    131132                       ctx.devices[0].version) 
    132133                      for ctx in env.context] 
    133         except ImportError: 
     134        except Exception: 
    134135            clinfo = None 
    135136 
     
    222223    clinfo = [] 
    223224    cl_platforms = [] 
     225 
    224226    try: 
    225227        import pyopencl as cl 
    226         cl_platforms = cl.get_platforms() 
    227228    except ImportError: 
    228         print("pyopencl import failed. Using only CPU computations") 
    229     except cl.LogicError as e: 
    230         print(e.value) 
     229        cl = None 
     230 
     231    if cl is None: 
     232        logger.warn("Unable to import the pyopencl package.  It may not " 
     233                    "have been installed.  If you wish to use OpenCL, try " 
     234                    "running pip install --user pyopencl") 
     235    else: 
     236        try: 
     237            cl_platforms = cl.get_platforms() 
     238        except cl.LogicError as err: 
     239            logger.warn("Unable to fetch the OpenCL platforms.  This likely " 
     240                        "means that the opencl drivers for your system are " 
     241                        "not installed.") 
     242            logger.warn(err) 
    231243 
    232244    p_index = 0 
  • src/sas/qtgui/Plotting/MaskEditor.py

    rdce68f6 r133812c7  
    4242        layout.setContentsMargins(0, 0, 0, 0) 
    4343        self.frame.setLayout(layout) 
     44 
     45        self.plotter.plot() 
    4446        layout.addWidget(self.plotter) 
    45  
    46         self.plotter.plot() 
    4747        self.subplot = self.plotter.ax 
    4848 
  • src/sas/qtgui/Plotting/Plotter2D.py

    rf5cec7c r133812c7  
    281281        new_plot.id = "Circ avg " + self.data.name 
    282282        new_plot.is_data = True 
     283        item = self._item 
    283284        if self._item.parent() is not None: 
    284285            item = self._item.parent() 
     
    286287 
    287288        self.manager.communicator.plotUpdateSignal.emit([new_plot]) 
     289 
     290        self.manager.communicator.forcePlotDisplaySignal.emit([item, new_plot]) 
     291 
     292        # Show the plot 
    288293 
    289294    def setSlicer(self, slicer): 
     
    508513            self.figure.canvas.draw() 
    509514 
     515    def imageShow(self, img, origin=None): 
     516        """ 
     517        Show background image 
     518        :Param img: [imread(path) from matplotlib.pyplot] 
     519        """ 
     520        if origin is not None: 
     521            im = self.ax.imshow(img, origin=origin) 
     522        else: 
     523            im = self.ax.imshow(img) 
     524 
    510525    def update(self): 
    511526        self.figure.canvas.draw() 
  • src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py

    r63467b6 r133812c7  
    148148        GuiUtils.updateModelItemWithPlot(item, new_plot, new_plot.id) 
    149149        self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 
     150        self.base.manager.communicator.forcePlotDisplaySignal.emit([item, new_plot]) 
    150151 
    151152        if self.update_model: 
  • src/sas/qtgui/Plotting/Slicers/BoxSlicer.py

    r63467b6 r133812c7  
    188188        new_plot.id = (self.averager.__name__) + self.base.data.name 
    189189        new_plot.is_data = True 
     190        item = self._item 
    190191        if self._item.parent() is not None: 
    191192            item = self._item.parent() 
    192193        GuiUtils.updateModelItemWithPlot(item, new_plot, new_plot.id) 
     194        self.base.manager.communicator.forcePlotDisplaySignal.emit([item, new_plot]) 
    193195 
    194196        if self.update_model: 
  • src/sas/qtgui/Plotting/Slicers/SectorSlicer.py

    r63467b6 r133812c7  
    167167        new_plot.id = "SectorQ" + self.base.data.name 
    168168        new_plot.is_data = True 
     169        item = self._item 
    169170        if self._item.parent() is not None: 
    170171            item = self._item.parent() 
     
    172173 
    173174        self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 
     175        self.base.manager.communicator.forcePlotDisplaySignal.emit([item, new_plot]) 
    174176 
    175177        if self.update_model: 
  • src/sas/qtgui/Plotting/UI/MaskEditorUI.ui

    re20870bc r133812c7  
    77    <x>0</x> 
    88    <y>0</y> 
    9     <width>687</width> 
    10     <height>507</height> 
     9    <width>824</width> 
     10    <height>453</height> 
    1111   </rect> 
    1212  </property> 
  • src/sas/qtgui/Utilities/GenericReader.py

    re7a0b2f r133812c7  
    4141        try: 
    4242            data = self.loader.read(self.path) 
    43             self.complete(data=data) 
     43            self.complete(data=[data]) 
    4444        except: 
    4545            # Thread was interrupted, just proceed and re-raise. 
  • src/sas/qtgui/Utilities/GuiUtils.py

    r17e2d502 r133812c7  
    162162    DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE 
    163163    CLEANUP_PLOT = custom_config.CLEANUP_PLOT 
     164    SAS_OPENCL = custom_config.SAS_OPENCL 
    164165    # custom open_path 
    165166    open_folder = custom_config.DEFAULT_OPEN_FOLDER 
     
    182183    CLEANUP_PLOT = False 
    183184    DEFAULT_OPEN_FOLDER = PATH_APP 
     185    SAS_OPENCL = config.SAS_OPENCL 
    184186 
    185187#DEFAULT_STYLE = config.DEFAULT_STYLE 
     
    294296    # Plot fitting results (FittingWidget->GuiManager) 
    295297    resultPlotUpdateSignal = QtCore.pyqtSignal(list) 
     298 
     299    # show the plot as a regular in-workspace object 
     300    forcePlotDisplaySignal = QtCore.pyqtSignal(list) 
    296301 
    297302def updateModelItemWithPlot(item, update_data, name="", checkbox_state=None): 
  • src/sas/qtgui/Utilities/ReportDialog.py

    rcb90b65 r133812c7  
    1010 
    1111import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     12import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary 
    1213 
    1314from sas.qtgui.Utilities.UI.ReportDialogUI import Ui_ReportDialogUI 
     
    2728 
    2829        self.data_html, self.data_txt, self.data_images = report_list 
     30        #self.save_location = None 
     31        #if 'ReportDialog_directory' in ObjectLibrary.listObjects(): 
     32        self.save_location = ObjectLibrary.getObject('ReportDialog_directory') 
    2933 
    3034        # Fill in the table from input data 
     
    7074        """ 
    7175        # Choose user's home directory 
    72         location = os.path.expanduser('~') 
     76        if self.save_location is None: 
     77            location = os.path.expanduser('~') 
     78        else: 
     79            location = self.save_location 
    7380        # Use a sensible filename default 
    7481        default_name = os.path.join(location, 'fit_report.pdf') 
     
    7885            'caption'  : 'Save Report', 
    7986            # don't use 'directory' in order to remember the previous user choice 
    80             #'directory': default_name, 
     87            'directory': default_name, 
    8188            'filter'   : 'PDF file (*.pdf);;HTML file (*.html);;Text file (*.txt)', 
    8289            'options'  : QtWidgets.QFileDialog.DontUseNativeDialog} 
     
    8794            return 
    8895        extension = filename_tuple[1] 
     96        self.save_location = os.path.dirname(filename) 
     97        # lifetime of this widget is short - keep the reference elsewhere 
     98        ObjectLibrary.addObject('ReportDialog_directory', self.save_location) 
    8999 
    90100        try: 
Note: See TracChangeset for help on using the changeset viewer.