Changeset b10cf92 in sasview for src/sas/qtgui/Utilities
- Timestamp:
- May 17, 2018 3:49:28 PM (7 years ago)
- 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:
- 3aa3351, a0ed202
- Parents:
- 6459916 (diff), 57be490 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/qtgui/Utilities
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Utilities/CategoryInstaller.py
rcee5c78 rc889a3e 174 174 model_enabled_dict) 175 175 176 json.dump(master_category_dict, open(serialized_file, 'wb'))176 json.dump(master_category_dict, open(serialized_file, "w", encoding="utf8")) 177 177 -
src/sas/qtgui/Utilities/GuiUtils.py
rd4dac80 r57be490 1 # -*- coding: utf-8 -*- 1 2 """ 2 3 Global defaults and various utility functions usable by the general GUI … … 248 249 sendDataToGridSignal = QtCore.pyqtSignal(list) 249 250 251 # Action Save Analysis triggered 252 saveAnalysisSignal = QtCore.pyqtSignal() 250 253 251 254 def updateModelItemWithPlot(item, update_data, name=""): … … 378 381 if str(i.text()) == filename]) 379 382 return item[0] if len(item)>0 else None 383 384 def 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 380 406 381 407 def plotsFromFilename(filename, model_item): … … 841 867 return output.lstrip().rstrip() 842 868 869 def replaceHTMLwithUTF8(html): 870 """ 871 Replace some important HTML-encoded characters 872 with their UTF-8 equivalents 873 """ 874 # Angstrom 875 html_out = html.replace("Å", "à 876 ") 877 # infinity 878 html_out = html_out.replace("∞", "â") 879 # +/- 880 html_out = html_out.replace("±", "±") 881 882 return html_out 883 884 def replaceHTMLwithASCII(html): 885 """ 886 Replace some important HTML-encoded characters 887 with their ASCII equivalents 888 """ 889 # Angstrom 890 html_out = html.replace("Å", "Ang") 891 # infinity 892 html_out = html_out.replace("∞", "inf") 893 # +/- 894 html_out = html_out.replace("±", "+/-") 895 896 return html_out 897 898 def 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 843 920 def convertUnitToHTML(unit): 844 921 """ -
src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py
r6cb305a r57be490 1 # -*- coding: utf-8 -*- 1 2 import sys 2 3 import unittest … … 446 447 self.assertEqual(yscale, "log") 447 448 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 = "Å ∞ ±" 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 = "Å ∞ ±" 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), "Å<sup>-1</sup>") 522 523 s = "Ang" 524 self.assertEqual(convertUnitToHTML(s), "Å") 525 526 s = "1e-6/Ang^2" 527 self.assertEqual(convertUnitToHTML(s), "10<sup>-6</sup>/Å<sup>2</sup>") 528 529 s = "inf" 530 self.assertEqual(convertUnitToHTML(s), "∞") 531 s = "-inf" 532 533 self.assertEqual(convertUnitToHTML(s), "-∞") 534 535 s = "1/cm" 536 self.assertEqual(convertUnitToHTML(s), "cm<sup>-1</sup>") 537 448 538 def testParseName(self): 449 539 '''test parse out a string from the beinning of a string'''
Note: See TracChangeset
for help on using the changeset viewer.