Changeset 4908
- Timestamp:
- May 19, 2021 2:22:22 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIrestrGUI.py
r4905 r4908 43 43 WACV = wx.ALIGN_CENTER_VERTICAL 44 44 VERY_LIGHT_GREY = wx.Colour(235,235,235) 45 VERY_RED = wx.Colour(255,0,0) 45 46 TabSelectionIdDict = {} 46 47 … … 48 49 ##### Restraints 49 50 ################################################################################ 50 def GetSelectedRows(widget ):51 def GetSelectedRows(widget,lbl='edit',G2frame=None): 51 52 '''Returns a list of selected rows. Rows can be selected, blocks of cells 52 53 or individual cells can be selected. The column for selected cells is ignored. … … 54 55 try: 55 56 rows = widget.GetSelectedRows() 56 except: 57 return 58 if not rows: 57 if rows: return rows 58 59 59 top = widget.GetSelectionBlockTopLeft() 60 60 bot = widget.GetSelectionBlockBottomRight() 61 61 if top and bot: 62 62 rows = range(top[0][0],bot[0][0]+1) 63 if not rows: 63 if rows: return rows 64 64 65 rows = sorted(list(set([cell[0] for cell in widget.GetSelectedCells()]))) 65 return rows 66 66 if rows: return rows 67 68 choices = ["{}: {}".format(widget.GetRowLabelValue(i),widget.GetCellValue(i,0)) 69 for i in range(widget.GetNumberRows())] 70 try: 71 dlg = G2G.G2MultiChoiceDialog(G2frame,'Restraints to '+lbl, 72 'Select restraints',choices) 73 if dlg.ShowModal() != wx.ID_OK: return 74 return dlg.GetSelections() 75 finally: 76 dlg.Destroy() 77 except: 78 return 79 67 80 def UpdateRestraints(G2frame,data,phaseName): 68 81 '''Respond to selection of the Restraints item on the … … 946 959 947 960 def OnDeleteRestraint(event): 948 rows = GetSelectedRows(Bonds )961 rows = GetSelectedRows(Bonds,'delete',G2frame) 949 962 G2frame.GetStatusBar().SetStatusText('',1) 950 963 if not rows: … … 963 976 mainSizer.Add(WtBox(BondRestr,bondRestData),0) 964 977 978 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 979 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 965 980 bondList = bondRestData['Bonds'] 966 981 if len(bondList) and len(bondList[0]) == 6: #patch … … 1020 1035 else: 1021 1036 Bonds.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1037 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1038 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1022 1039 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1023 1040 G2frame.Bind(wx.EVT_MENU, OnChangeValue, id=G2G.wxID_RESRCHANGEVAL) … … 1078 1095 1079 1096 def OnDeleteRestraint(event): 1080 rows = GetSelectedRows(Angles )1097 rows = GetSelectedRows(Angles,'delete',G2frame) 1081 1098 G2frame.GetStatusBar().SetStatusText('',1) 1082 1099 if not rows: … … 1095 1112 mainSizer.Add(WtBox(AngleRestr,angleRestData),0) 1096 1113 1114 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1115 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1097 1116 angleList = angleRestData['Angles'] 1098 1117 if len(angleList): … … 1152 1171 else: 1153 1172 Angles.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1173 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1174 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1154 1175 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1155 1176 G2frame.Bind(wx.EVT_MENU, OnChangeValue, id=G2G.wxID_RESRCHANGEVAL) … … 1200 1221 1201 1222 def OnDeleteRestraint(event): 1202 rows = GetSelectedRows(Planes )1223 rows = GetSelectedRows(Planes,'delete',G2frame) 1203 1224 G2frame.GetStatusBar().SetStatusText('',1) 1204 1225 if not rows: … … 1217 1238 mainSizer.Add(WtBox(PlaneRestr,planeRestData),0) 1218 1239 1240 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1241 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1219 1242 planeList = planeRestData['Planes'] 1220 1243 if len(planeList): … … 1280 1303 else: 1281 1304 Planes.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1305 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESTCHANGEESD): 1306 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1282 1307 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1283 1308 G2frame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2G.wxID_RESTCHANGEESD) … … 1309 1334 1310 1335 def OnDeleteRestraint(event): 1311 rows = GetSelectedRows(Volumes )1336 rows = GetSelectedRows(Volumes,'delete',G2frame) 1312 1337 G2frame.GetStatusBar().SetStatusText('',1) 1313 1338 if not rows: … … 1353 1378 mainSizer.Add(WtBox(ChiralRestr,chiralRestData),0) 1354 1379 1380 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1381 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1355 1382 volumeList = chiralRestData['Volumes'] 1356 1383 if len(volumeList): … … 1410 1437 else: 1411 1438 Volumes.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1439 for i in (G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1440 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1412 1441 G2frame.Bind(wx.EVT_MENU, OnChangeValue, id=G2G.wxID_RESRCHANGEVAL) 1413 1442 G2frame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2G.wxID_RESTCHANGEESD) … … 1439 1468 1440 1469 def OnDeleteRestraint(event): 1441 rows = GetSelectedRows(TorsionRestr.Torsions )1470 rows = GetSelectedRows(TorsionRestr.Torsions,'delete',G2frame) 1442 1471 G2frame.GetStatusBar().SetStatusText('',1) 1443 1472 if not rows: 1473 G2frame.GetStatusBar().SetStatusText('First select restraints to be deleted',1) 1444 1474 return 1445 G2frame.GetStatusBar().SetStatusText('First select restraints to be deleted',1)1446 1475 rows.sort() 1447 1476 rows.reverse() … … 1496 1525 mainSizer.Add(coeffSizer(),1,wx.EXPAND,1) 1497 1526 1527 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1528 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1498 1529 if len(torsionList): 1499 1530 mainSizer.Add(wx.StaticText(TorsionRestr,-1,'Torsion restraints:'),0) … … 1537 1568 else: 1538 1569 TorsionRestr.Torsions.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1570 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESTCHANGEESD): 1571 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1539 1572 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1540 1573 G2frame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2G.wxID_RESTCHANGEESD) … … 1565 1598 1566 1599 def OnDeleteRestraint(event): 1567 rows = GetSelectedRows(RamaRestr.Ramas )1600 rows = GetSelectedRows(RamaRestr.Ramas,'delete',G2frame) 1568 1601 G2frame.GetStatusBar().SetStatusText('',1) 1569 1602 if not rows: … … 1649 1682 for ibad in bad: 1650 1683 del ramaList[ibad] 1684 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1685 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1651 1686 if len(ramaList): 1652 1687 ramaTable = G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) … … 1663 1698 else: 1664 1699 RamaRestr.Ramas.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1700 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESTCHANGEESD): 1701 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=True) 1665 1702 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1666 1703 G2frame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2G.wxID_RESTCHANGEESD) … … 1698 1735 1699 1736 def OnDeleteRestraint(event): 1700 #rows = GetSelectedRows()1701 rows = ChemComps.GetSelectedRows()1737 rows = GetSelectedRows(ChemComps,'delete',G2frame) 1738 #rows = ChemComps.GetSelectedRows() 1702 1739 G2frame.GetStatusBar().SetStatusText('',1) 1703 1740 if not rows: 1704 1741 G2frame.GetStatusBar().SetStatusText('First select restraints to be deleted',1) 1705 1742 return 1706 rowLabl = ChemComps.GetRowLabelValue(r) 1707 row = int(rowLabl.split(':')[1]) 1708 if 'Restr' in rowLabl: 1709 del chemcompList[row] 1710 else: 1711 term = int(rowLabl.split(':')[2]) 1743 terms = [] 1744 restrs = [] 1745 for r in sorted(rows,reverse=True): 1746 rowLabl = ChemComps.GetRowLabelValue(r) 1747 if 'Restr' in rowLabl: 1748 restrs.append(int(rowLabl.split(':')[1])) 1749 else: 1750 terms.append([int(i) for i in rowLabl.split(':')[1:]]) 1751 # delete terms first in case someone deletes a term in a restraint to be deleted 1752 for row,term in terms: 1712 1753 del chemcompList[row][0][term] 1713 1754 del chemcompList[row][1][term] 1755 for row in restrs: 1756 del chemcompList[row] 1714 1757 UpdateChemcompRestr(chemcompRestData) 1715 1758 1716 def OnChangeValue(event):1717 rows = GetSelectedRows(ChemComps)1718 if not rows:1719 return1720 ChemComps.ClearSelection()1721 dlg = G2G.SingleFloatDialog(G2frame,'New value',1722 'Enter new value for restraint multiplier',1.0,[-1.e6,1.e6],'%.2f')1723 if dlg.ShowModal() == wx.ID_OK:1724 parm = dlg.GetValue()1725 for r in rows:1726 rowLabl = ChemComps.GetRowLabelValue(r)1727 if 'term' in rowLabl:1728 items = rowLabl.split(':')1729 chemcompRestData['Sites'][int(items[1])][1][int(items[2])] = parm1730 dlg.Destroy()1731 UpdateChemcompRestr(chemcompRestData)1759 # def OnChangeValue(event): 1760 # rows = GetSelectedRows(ChemComps) 1761 # if not rows: 1762 # return 1763 # ChemComps.ClearSelection() 1764 # dlg = G2G.SingleFloatDialog(G2frame,'New value', 1765 # 'Enter new value for restraint multiplier',1.0,[-1.e6,1.e6],'%.2f') 1766 # if dlg.ShowModal() == wx.ID_OK: 1767 # parm = dlg.GetValue() 1768 # for r in rows: 1769 # rowLabl = ChemComps.GetRowLabelValue(r) 1770 # if 'term' in rowLabl: 1771 # items = rowLabl.split(':') 1772 # chemcompRestData['Sites'][int(items[1])][1][int(items[2])] = parm 1773 # dlg.Destroy() 1774 # UpdateChemcompRestr(chemcompRestData) 1732 1775 1733 1776 if ChemCompRestr.GetSizer(): ChemCompRestr.GetSizer().Clear(True) … … 1739 1782 mainSizer.Add((5,5),0) 1740 1783 1784 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1785 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1741 1786 chemcompList = chemcompRestData['Sites'] 1742 1787 if len(chemcompList): … … 1777 1822 ChemComps.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1778 1823 if 'Restr' in ChemComps.GetRowLabelValue(r): 1824 ChemComps.SetCellTextColour(r,0,VERY_LIGHT_GREY) 1825 ChemComps.SetCellTextColour(r,1,VERY_RED) # make spurious #'s disappear 1826 ChemComps.SetCellTextColour(r,2,VERY_RED) 1827 ChemComps.SetCellTextColour(r,3,VERY_LIGHT_GREY) 1779 1828 for c in range(4): 1780 1829 ChemComps.SetReadOnly(r,c,True) 1781 ChemComps.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 1782 for c in [1,2]: 1783 ChemComps.SetCellTextColour(r,c,VERY_LIGHT_GREY) 1830 ChemComps.SetCellStyle(r,c,VERY_RED,True) 1784 1831 else: 1785 1832 for c in [3,4,5]: … … 1794 1841 else: 1795 1842 ChemComps.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1843 G2frame.dataWindow.RestraintEdit.Enable(id=G2G.wxID_RESTDELETE,enable=True) 1796 1844 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1797 G2frame.Bind(wx.EVT_MENU, OnChangeValue, id=G2G.wxID_RESRCHANGEVAL)1845 #G2frame.Bind(wx.EVT_MENU, OnChangeValue, id=G2G.wxID_RESRCHANGEVAL) 1798 1846 mainSizer.Add(wx.StaticText(ChemCompRestr,-1, 1799 1847 'Chemical composition restraints: sum(wt*(delt/sig)^2) = %.2f, mean(wt*(delt/sig)^2) = %.2f' \ 1800 %(chisq,chisq/len(chemcompList))) ,0,WACV)1801 mainSizer.Add(ChemComps ,0,)1848 %(chisq,chisq/len(chemcompList)))) 1849 mainSizer.Add(ChemComps) 1802 1850 else: 1803 1851 mainSizer.Add(wx.StaticText(ChemCompRestr,-1,'No chemical composition restraints for this phase'),0,) … … 1810 1858 1811 1859 def OnDeleteRestraint(event): 1812 rows = GetSelectedRows(Textures )1860 rows = GetSelectedRows(Textures,'delete',G2frame) 1813 1861 G2frame.GetStatusBar().SetStatusText('',1) 1814 1862 if not rows: … … 1848 1896 mainSizer.Add((5,5),0) 1849 1897 1898 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1899 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1850 1900 textureList = textureRestData['HKLs'] 1851 1901 if len(textureList): … … 1874 1924 else: 1875 1925 Textures.Bind(wg.EVT_GRID_CELL_CHANGE, OnCellChange) 1926 G2frame.dataWindow.RestraintEdit.Enable(id=G2G.wxID_RESTDELETE,enable=True) 1876 1927 G2frame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2G.wxID_RESTDELETE) 1877 1928 mainSizer.Add(Textures,0,) … … 1917 1968 mainSizer.Add(hSizer,0) 1918 1969 mainSizer.Add((5,5),0) 1970 for i in (G2G.wxID_RESTDELETE,G2G.wxID_RESRCHANGEVAL,G2G.wxID_RESTCHANGEESD): 1971 G2frame.dataWindow.RestraintEdit.Enable(id=i,enable=False) 1919 1972 if generalRestData['General']: 1920 1973 parmDict = SetupParmDict(G2frame)
Note: See TracChangeset
for help on using the changeset viewer.