Changeset 1042dba in sasview for src/sas/qtgui/GuiUtils.py


Ignore:
Timestamp:
Jun 17, 2016 9:56:01 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:
9e426c1
Parents:
a281ab8
Message:

Plottables support in the data object. Additional menu items.

File:
1 edited

Legend:

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

    ra281ab8 r1042dba  
    2626#from sas.sasgui.guiframe.events import NewPlotEvent 
    2727from sas.sasgui.guiframe.dataFitting import Data1D 
     28from sas.sasgui.guiframe.dataFitting import Data2D 
    2829 
    2930 
     
    209210def updateModelItem(item, update_data, name=""): 
    210211    """ 
    211     Updates QStandardItem with a checkboxed row named 'name' 
    212     and containing QVariant 'update_data' 
     212    Adds a checkboxed row named "name" to QStandardItem 
     213    Adds QVariant 'update_data' to that row. 
    213214    """ 
    214215    assert type(item) == QtGui.QStandardItem 
     
    221222 
    222223    # Add "Info" item 
    223     info_item = QtGui.QStandardItem("Info") 
     224    py_update_data = update_data.toPyObject() 
     225    if type(py_update_data) == (Data1D or Data2D): 
     226        # If Data1/2D added - extract Info from it 
     227        info_item = infoFromData(py_update_data) 
     228    else: 
     229        # otherwise just add a naked item 
     230        info_item = QtGui.QStandardItem("Info")         
    224231 
    225232    # Add the actual Data1D/Data2D object 
     
    227234    object_item.setData(update_data) 
    228235 
     236    # Set the data object as the first child 
    229237    checkbox_item.setChild(0, object_item) 
    230238 
    231     # Set info_item as the only child 
     239    # Set info_item as the second child 
    232240    checkbox_item.setChild(1, info_item) 
    233241 
    234242    # Append the new row to the main item 
    235243    item.appendRow(checkbox_item) 
     244 
     245def plotsFromCheckedItems(model_item): 
     246    """ 
     247    Returns the list of plots for items in the model which are checked 
     248    """ 
     249    assert type(model_item) == QtGui.QStandardItemModel 
     250 
     251    checkbox_item = QtGui.QStandardItem(True) 
     252    plot_data = [] 
     253 
     254    # Iterate over model looking for items with checkboxes 
     255    for index in range(model_item.rowCount()): 
     256        item = model_item.item(index) 
     257        if item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 
     258            # TODO: assure item type is correct (either data1/2D or Plotter) 
     259            plot_data.append(item.child(0).data().toPyObject()) 
     260        # Going 1 level deeper only 
     261        for index_2 in range(item.rowCount()): 
     262            item_2 = item.child(index_2) 
     263            if item_2 and item_2.isCheckable() and item_2.checkState() == QtCore.Qt.Checked: 
     264                # TODO: assure item type is correct (either data1/2D or Plotter) 
     265                plot_data.append(item_2.child(0).data().toPyObject()) 
     266   
     267    return plot_data 
     268 
     269def infoFromData(data): 
     270    """ 
     271    Given Data1D/Data2D object, extract relevant Info elements 
     272    and add them to a model item 
     273    """ 
     274    assert type(data) in [Data1D, Data2D] 
     275 
     276    info_item = QtGui.QStandardItem("Info") 
     277 
     278    title_item   = QtGui.QStandardItem("Title: "      + data.title) 
     279    info_item.appendRow(title_item) 
     280    run_item     = QtGui.QStandardItem("Run: "        + str(data.run)) 
     281    info_item.appendRow(run_item) 
     282    type_item    = QtGui.QStandardItem("Type: "       + str(data.__class__.__name__)) 
     283    info_item.appendRow(type_item) 
     284 
     285    if data.path: 
     286        path_item    = QtGui.QStandardItem("Path: "       + data.path) 
     287        info_item.appendRow(path_item) 
     288 
     289    if data.instrument: 
     290        instr_item   = QtGui.QStandardItem("Instrument: " + data.instrument) 
     291        info_item.appendRow(instr_item) 
     292 
     293    process_item = QtGui.QStandardItem("Process") 
     294    if isinstance(data.process, list) and data.process: 
     295        for process in data.process: 
     296            process_date = process.date 
     297            process_date_item = QtGui.QStandardItem("Date: " + process_date) 
     298            process_item.appendRow(process_date_item) 
     299 
     300            process_descr = process.description 
     301            process_descr_item = QtGui.QStandardItem("Description: " + process_descr) 
     302            process_item.appendRow(process_descr_item) 
     303 
     304            process_name = process.name 
     305            process_name_item = QtGui.QStandardItem("Name: " + process_name) 
     306            process_item.appendRow(process_name_item) 
     307 
     308    info_item.appendRow(process_item) 
     309 
     310    return info_item 
     311 
Note: See TracChangeset for help on using the changeset viewer.