Changeset 57be490 in sasview for src/sas/qtgui/Utilities


Ignore:
Timestamp:
May 17, 2018 4:50:09 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, 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:
085e3c9d
Parents:
976978b
git-author:
Piotr Rozyczko <rozyczko@…> (04/13/18 09:34:43)
git-committer:
Piotr Rozyczko <rozyczko@…> (05/17/18 04:50:09)
Message:

Merged ESS_GUI_reporting

Location:
src/sas/qtgui/Utilities
Files:
3 added
2 edited

Legend:

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

    rd4dac80 r57be490  
     1# -*- coding: utf-8 -*- 
    12""" 
    23Global defaults and various utility functions usable by the general GUI 
     
    248249    sendDataToGridSignal = QtCore.pyqtSignal(list) 
    249250 
     251    # Action Save Analysis triggered 
     252    saveAnalysisSignal = QtCore.pyqtSignal() 
    250253 
    251254def updateModelItemWithPlot(item, update_data, name=""): 
     
    378381                 if str(i.text()) == filename]) 
    379382    return item[0] if len(item)>0 else None 
     383 
     384def plotsFromModel(model_name, model_item): 
     385    """ 
     386    Returns the list of plots for the item with model name in the model 
     387    """ 
     388    assert isinstance(model_item, QtGui.QStandardItem) 
     389    assert isinstance(model_name, str) 
     390 
     391    plot_data = [] 
     392    # Iterate over model looking for named items 
     393    for index in range(model_item.rowCount()): 
     394        item = model_item.child(index) 
     395        if isinstance(item.data(), (Data1D, Data2D)): 
     396            plot_data.append(item.data()) 
     397        if model_name in str(item.text()): 
     398            #plot_data.append(item.child(0).data()) 
     399            # Going 1 level deeper only 
     400            for index_2 in range(item.rowCount()): 
     401                item_2 = item.child(index_2) 
     402                if item_2 and isinstance(item_2.data(), (Data1D, Data2D)): 
     403                    plot_data.append(item_2.data()) 
     404 
     405    return plot_data 
    380406 
    381407def plotsFromFilename(filename, model_item): 
     
    841867    return output.lstrip().rstrip() 
    842868 
     869def replaceHTMLwithUTF8(html): 
     870    """ 
     871    Replace some important HTML-encoded characters 
     872    with their UTF-8 equivalents 
     873    """ 
     874    # Angstrom 
     875    html_out = html.replace("&#x212B;", "à
     876") 
     877    # infinity 
     878    html_out = html_out.replace("&#x221e;", "∞") 
     879    # +/- 
     880    html_out = html_out.replace("&#177;", "±") 
     881 
     882    return html_out 
     883 
     884def replaceHTMLwithASCII(html): 
     885    """ 
     886    Replace some important HTML-encoded characters 
     887    with their ASCII equivalents 
     888    """ 
     889    # Angstrom 
     890    html_out = html.replace("&#x212B;", "Ang") 
     891    # infinity 
     892    html_out = html_out.replace("&#x221e;", "inf") 
     893    # +/- 
     894    html_out = html_out.replace("&#177;", "+/-") 
     895 
     896    return html_out 
     897 
     898def convertUnitToUTF8(unit): 
     899    """ 
     900    Convert ASCII unit display into UTF-8 symbol 
     901    """ 
     902    if unit == "1/A": 
     903        return "à
     904<sup>-1</sup>" 
     905    elif unit == "1/cm": 
     906        return "cm<sup>-1</sup>" 
     907    elif unit == "Ang": 
     908        return "à
     909" 
     910    elif unit == "1e-6/Ang^2": 
     911        return "10<sup>-6</sup>/à
     912<sup>2</sup>" 
     913    elif unit == "inf": 
     914        return "∞" 
     915    elif unit == "-inf": 
     916        return "-∞" 
     917    else: 
     918        return unit 
     919 
    843920def convertUnitToHTML(unit): 
    844921    """ 
  • src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py

    r6cb305a r57be490  
     1# -*- coding: utf-8 -*- 
    12import sys 
    23import unittest 
     
    446447        self.assertEqual(yscale, "log") 
    447448 
     449    def testReplaceHTMLwithUTF8(self): 
     450        ''' test single character replacement ''' 
     451        s = None 
     452        with self.assertRaises(AttributeError): 
     453            result = replaceHTMLwithUTF8(s) 
     454 
     455        s = "" 
     456        self.assertEqual(replaceHTMLwithUTF8(s), s) 
     457 
     458        s = "aaaa" 
     459        self.assertEqual(replaceHTMLwithUTF8(s), s) 
     460 
     461        s = "&#x212B; &#x221e;      &#177;" 
     462        self.assertEqual(replaceHTMLwithUTF8(s), "à
     463 âˆž      ±") 
     464 
     465    def testReplaceHTMLwithASCII(self): 
     466        ''' test single character replacement''' 
     467        s = None 
     468        with self.assertRaises(AttributeError): 
     469            result = replaceHTMLwithASCII(s) 
     470 
     471        s = "" 
     472        self.assertEqual(replaceHTMLwithASCII(s), s) 
     473 
     474        s = "aaaa" 
     475        self.assertEqual(replaceHTMLwithASCII(s), s) 
     476 
     477        s = "&#x212B; &#x221e;      &#177;" 
     478        self.assertEqual(replaceHTMLwithASCII(s), "Ang inf      +/-") 
     479 
     480    def testConvertUnitToUTF8(self): 
     481        ''' test unit string replacement''' 
     482        s = None 
     483        self.assertIsNone(convertUnitToUTF8(s)) 
     484 
     485        s = "" 
     486        self.assertEqual(convertUnitToUTF8(s), s) 
     487 
     488        s = "aaaa" 
     489        self.assertEqual(convertUnitToUTF8(s), s) 
     490 
     491        s = "1/A" 
     492        self.assertEqual(convertUnitToUTF8(s), "à
     493<sup>-1</sup>") 
     494 
     495        s = "Ang" 
     496        self.assertEqual(convertUnitToUTF8(s), "à
     497") 
     498 
     499        s = "1e-6/Ang^2" 
     500        self.assertEqual(convertUnitToUTF8(s), "10<sup>-6</sup>/à
     501<sup>2</sup>") 
     502 
     503        s = "inf" 
     504        self.assertEqual(convertUnitToUTF8(s), "∞") 
     505 
     506        s = "1/cm" 
     507        self.assertEqual(convertUnitToUTF8(s), "cm<sup>-1</sup>") 
     508 
     509    def testConvertUnitToHTML(self): 
     510        ''' test unit string replacement''' 
     511        s = None 
     512        self.assertIsNone(convertUnitToHTML(s)) 
     513 
     514        s = "" 
     515        self.assertEqual(convertUnitToHTML(s), s) 
     516 
     517        s = "aaaa" 
     518        self.assertEqual(convertUnitToHTML(s), s) 
     519 
     520        s = "1/A" 
     521        self.assertEqual(convertUnitToHTML(s), "&#x212B;<sup>-1</sup>") 
     522 
     523        s = "Ang" 
     524        self.assertEqual(convertUnitToHTML(s), "&#x212B;") 
     525 
     526        s = "1e-6/Ang^2" 
     527        self.assertEqual(convertUnitToHTML(s), "10<sup>-6</sup>/&#x212B;<sup>2</sup>") 
     528 
     529        s = "inf" 
     530        self.assertEqual(convertUnitToHTML(s), "&#x221e;") 
     531        s = "-inf" 
     532 
     533        self.assertEqual(convertUnitToHTML(s), "-&#x221e;") 
     534 
     535        s = "1/cm" 
     536        self.assertEqual(convertUnitToHTML(s), "cm<sup>-1</sup>") 
     537 
    448538    def testParseName(self): 
    449539        '''test parse out a string from the beinning of a string''' 
Note: See TracChangeset for help on using the changeset viewer.