Changeset 1770
- Timestamp:
- Mar 30, 2015 1:39:46 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r1769 r1770 2855 2855 # if ifHKLF: TextList.insert(1,'All HKLF') 2856 2856 # if ifPDF: TextList.insert(1,'All PDF') 2857 dlg = G2 gd.G2MultiChoiceDialog(self, 'Which data to delete?', 'Delete data', TextList, wx.CHOICEDLG_STYLE)2857 dlg = G2G.G2MultiChoiceDialog(self, 'Which data to delete?', 'Delete data', TextList, wx.CHOICEDLG_STYLE) 2858 2858 try: 2859 2859 if dlg.ShowModal() == wx.ID_OK: -
trunk/GSASIIIO.py
r1762 r1770 1394 1394 # select one or more from a from list 1395 1395 choices = [i.filename for i in zinfo] 1396 dlg = G2 gd.G2MultiChoiceDialog(parent,'Select file(s) to extract from zip file '+str(filename),1396 dlg = G2G.G2MultiChoiceDialog(parent,'Select file(s) to extract from zip file '+str(filename), 1397 1397 'Choose file(s)',choices) 1398 1398 if dlg.ShowModal() == wx.ID_OK: -
trunk/GSASIIconstrGUI.py
r1657 r1770 445 445 fmt = "{:"+str(l1)+"s} {:"+str(l2)+"s} {:s}" 446 446 atchoice = [fmt.format(*i) for i in choices] 447 dlg = G2 gd.G2MultiChoiceDialog(447 dlg = G2G.G2MultiChoiceDialog( 448 448 G2frame.dataFrame,legend, 449 449 'Constrain '+str(FrstVarb)+' with...',atchoice, … … 650 650 #varListlbl = ["("+i+") "+G2obj.fmtVarDescr(i) for i in varList] 651 651 legend = "Select variables to hold (Will not be varied, even if vary flag is set)" 652 dlg = G2 gd.G2MultiChoiceDialog(652 dlg = G2G.G2MultiChoiceDialog( 653 653 G2frame.dataFrame, 654 654 legend,title1,varListlbl,toggle=False,size=(625,400),monoFont=True) … … 715 715 fmt = "{:"+str(l1)+"s} {:"+str(l2)+"s} {:s}" 716 716 varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in varList] 717 dlg = G2 gd.G2SingleChoiceDialog(G2frame.dataFrame,'Select 1st variable:',717 dlg = G2G.G2SingleChoiceDialog(G2frame.dataFrame,'Select 1st variable:', 718 718 title1,varListlbl, 719 719 monoFont=True,size=(625,400)) -
trunk/GSASIIctrls.py
r1729 r1770 1008 1008 1009 1009 ################################################################################ 1010 #### 1011 ################################################################################ 1010 #### Multichoice Dialog with set all, toggle & filter options 1011 ################################################################################ 1012 class G2MultiChoiceDialog(wx.Dialog): 1013 '''A dialog similar to MultiChoiceDialog except that buttons are 1014 added to set all choices and to toggle all choices. 1015 1016 :param wx.Frame ParentFrame: reference to parent frame 1017 :param str title: heading above list of choices 1018 :param str header: Title to place on window frame 1019 :param list ChoiceList: a list of choices where one will be selected 1020 :param bool toggle: If True (default) the toggle and select all buttons 1021 are displayed 1022 :param bool monoFont: If False (default), use a variable-spaced font; 1023 if True use a equally-spaced font. 1024 :param bool filterBox: If True (default) an input widget is placed on 1025 the window and only entries matching the entered text are shown. 1026 :param kw: optional keyword parameters for the wx.Dialog may 1027 be included such as size [which defaults to `(320,310)`] and 1028 style (which defaults to `wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL`); 1029 note that `wx.OK` and `wx.CANCEL` controls 1030 the presence of the eponymous buttons in the dialog. 1031 :returns: the name of the created dialog 1032 ''' 1033 def __init__(self,parent, title, header, ChoiceList, toggle=True, 1034 monoFont=False, filterBox=True, **kw): 1035 # process keyword parameters, notably style 1036 options = {'size':(320,310), # default Frame keywords 1037 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL, 1038 } 1039 options.update(kw) 1040 self.ChoiceList = ChoiceList # list of choices (list of str values) 1041 self.Selections = len(self.ChoiceList) * [False,] # selection status for each choice (list of bools) 1042 self.filterlist = range(len(self.ChoiceList)) # list of the choice numbers that have been filtered (list of int indices) 1043 if options['style'] & wx.OK: 1044 useOK = True 1045 options['style'] ^= wx.OK 1046 else: 1047 useOK = False 1048 if options['style'] & wx.CANCEL: 1049 useCANCEL = True 1050 options['style'] ^= wx.CANCEL 1051 else: 1052 useCANCEL = False 1053 # create the dialog frame 1054 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options) 1055 # fill the dialog 1056 Sizer = wx.BoxSizer(wx.VERTICAL) 1057 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1058 topSizer.Add( 1059 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)), 1060 1,wx.ALL|wx.EXPAND|WACV,1) 1061 if filterBox: 1062 self.timer = wx.Timer() 1063 self.timer.Bind(wx.EVT_TIMER,self.Filter) 1064 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Name \nFilter: '),0,wx.ALL|WACV,1) 1065 self.filterBox = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1),style=wx.TE_PROCESS_ENTER) 1066 self.filterBox.Bind(wx.EVT_CHAR,self.onChar) 1067 self.filterBox.Bind(wx.EVT_TEXT_ENTER,self.Filter) 1068 topSizer.Add(self.filterBox,0,wx.ALL|WACV,0) 1069 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8) 1070 self.trigger = False 1071 self.clb = wx.CheckListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList) 1072 self.clb.Bind(wx.EVT_CHECKLISTBOX,self.OnCheck) 1073 if monoFont: 1074 font1 = wx.Font(self.clb.GetFont().GetPointSize(), 1075 wx.MODERN, wx.NORMAL, wx.NORMAL, False) 1076 self.clb.SetFont(font1) 1077 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10) 1078 Sizer.Add((-1,10)) 1079 # set/toggle buttons 1080 if toggle: 1081 bSizer = wx.BoxSizer(wx.VERTICAL) 1082 setBut = wx.Button(self,wx.ID_ANY,'Set All') 1083 setBut.Bind(wx.EVT_BUTTON,self._SetAll) 1084 bSizer.Add(setBut,0,wx.ALIGN_CENTER) 1085 bSizer.Add((-1,5)) 1086 togBut = wx.Button(self,wx.ID_ANY,'Toggle All') 1087 togBut.Bind(wx.EVT_BUTTON,self._ToggleAll) 1088 bSizer.Add(togBut,0,wx.ALIGN_CENTER) 1089 Sizer.Add(bSizer,0,wx.LEFT,12) 1090 # OK/Cancel buttons 1091 btnsizer = wx.StdDialogButtonSizer() 1092 if useOK: 1093 self.OKbtn = wx.Button(self, wx.ID_OK) 1094 self.OKbtn.SetDefault() 1095 btnsizer.AddButton(self.OKbtn) 1096 if useCANCEL: 1097 btn = wx.Button(self, wx.ID_CANCEL) 1098 btnsizer.AddButton(btn) 1099 btnsizer.Realize() 1100 Sizer.Add((-1,5)) 1101 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50) 1102 Sizer.Add((-1,20)) 1103 # OK done, let's get outa here 1104 self.SetSizer(Sizer) 1105 self.CenterOnParent() 1106 1107 def GetSelections(self): 1108 'Returns a list of the indices for the selected choices' 1109 # update self.Selections with settings for displayed items 1110 for i in range(len(self.filterlist)): 1111 self.Selections[self.filterlist[i]] = self.clb.IsChecked(i) 1112 # return all selections, shown or hidden 1113 return [i for i in range(len(self.Selections)) if self.Selections[i]] 1114 1115 def SetSelections(self,selList): 1116 '''Sets the selection indices in selList as selected. Resets any previous 1117 selections for compatibility with wx.MultiChoiceDialog. Note that 1118 the state for only the filtered items is shown. 1119 1120 :param list selList: indices of items to be selected. These indices 1121 are referenced to the order in self.ChoiceList 1122 ''' 1123 self.Selections = len(self.ChoiceList) * [False,] # reset selections 1124 for sel in selList: 1125 self.Selections[sel] = True 1126 self._ShowSelections() 1127 1128 def _ShowSelections(self): 1129 'Show the selection state for displayed items' 1130 self.clb.SetChecked( 1131 [i for i in range(len(self.filterlist)) if self.Selections[self.filterlist[i]]] 1132 ) # Note anything previously checked will be cleared. 1133 1134 def _SetAll(self,event): 1135 'Set all viewed choices on' 1136 self.clb.SetChecked(range(len(self.filterlist))) 1137 1138 def _ToggleAll(self,event): 1139 'flip the state of all viewed choices' 1140 for i in range(len(self.filterlist)): 1141 self.clb.Check(i,not self.clb.IsChecked(i)) 1142 1143 def onChar(self,event): 1144 'for keyboard events. self.trigger is used in self.OnCheck below' 1145 self.OKbtn.Enable(False) 1146 if event.GetKeyCode() == wx.WXK_SHIFT: 1147 self.trigger = True 1148 if self.timer.IsRunning(): 1149 self.timer.Stop() 1150 self.timer.Start(1000,oneShot=True) 1151 event.Skip() 1152 1153 def OnCheck(self,event): 1154 '''for CheckListBox events; if Shift key down this sets all unset 1155 entries below the selected one''' 1156 if self.trigger: 1157 id = event.GetSelection() 1158 name = self.clb.GetString(id) 1159 iB = id-1 1160 if iB < 0: 1161 return 1162 while not self.clb.IsChecked(iB): 1163 self.clb.Check(iB) 1164 iB -= 1 1165 if iB < 0: 1166 break 1167 self.trigger = not self.trigger 1168 1169 def Filter(self,event): 1170 if self.timer.IsRunning(): 1171 self.timer.Stop() 1172 self.GetSelections() # record current selections 1173 txt = self.filterBox.GetValue() 1174 self.clb.Clear() 1175 1176 self.Update() 1177 self.filterlist = [] 1178 if txt: 1179 txt = txt.lower() 1180 ChoiceList = [] 1181 for i,item in enumerate(self.ChoiceList): 1182 if item.lower().find(txt) != -1: 1183 ChoiceList.append(item) 1184 self.filterlist.append(i) 1185 else: 1186 self.filterlist = range(len(self.ChoiceList)) 1187 ChoiceList = self.ChoiceList 1188 self.clb.AppendItems(ChoiceList) 1189 self._ShowSelections() 1190 self.OKbtn.Enable(True) 1191 1012 1192 def SelectEdit1Var(G2frame,array,labelLst,elemKeysLst,dspLst,refFlgElem): 1013 1193 '''Select a variable from a list, then edit it and select histograms … … 1183 1363 array.update(saveArray) 1184 1364 dlg.Destroy() 1365 1366 ################################################################################ 1367 #### Single choice Dialog with set all, toggle & filter options 1368 ################################################################################ 1369 class G2SingleChoiceDialog(wx.Dialog): 1370 '''A dialog similar to wx.SingleChoiceDialog except that a filter can be 1371 added. 1372 1373 :param wx.Frame ParentFrame: reference to parent frame 1374 :param str title: heading above list of choices 1375 :param str header: Title to place on window frame 1376 :param list ChoiceList: a list of choices where one will be selected 1377 :param bool monoFont: If False (default), use a variable-spaced font; 1378 if True use a equally-spaced font. 1379 :param bool filterBox: If True (default) an input widget is placed on 1380 the window and only entries matching the entered text are shown. 1381 :param kw: optional keyword parameters for the wx.Dialog may 1382 be included such as size [which defaults to `(320,310)`] and 1383 style (which defaults to ``wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.CENTRE | wx.OK | wx.CANCEL``); 1384 note that ``wx.OK`` and ``wx.CANCEL`` controls 1385 the presence of the eponymous buttons in the dialog. 1386 :returns: the name of the created dialog 1387 ''' 1388 def __init__(self,parent, title, header, ChoiceList, 1389 monoFont=False, filterBox=True, **kw): 1390 # process keyword parameters, notably style 1391 options = {'size':(320,310), # default Frame keywords 1392 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL, 1393 } 1394 options.update(kw) 1395 self.ChoiceList = ChoiceList 1396 self.filterlist = range(len(self.ChoiceList)) 1397 if options['style'] & wx.OK: 1398 useOK = True 1399 options['style'] ^= wx.OK 1400 else: 1401 useOK = False 1402 if options['style'] & wx.CANCEL: 1403 useCANCEL = True 1404 options['style'] ^= wx.CANCEL 1405 else: 1406 useCANCEL = False 1407 # create the dialog frame 1408 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options) 1409 # fill the dialog 1410 Sizer = wx.BoxSizer(wx.VERTICAL) 1411 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1412 topSizer.Add( 1413 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)), 1414 1,wx.ALL|wx.EXPAND|WACV,1) 1415 if filterBox: 1416 self.timer = wx.Timer() 1417 self.timer.Bind(wx.EVT_TIMER,self.Filter) 1418 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Filter: '),0,wx.ALL,1) 1419 self.filterBox = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1), 1420 style=wx.TE_PROCESS_ENTER) 1421 self.filterBox.Bind(wx.EVT_CHAR,self.onChar) 1422 self.filterBox.Bind(wx.EVT_TEXT_ENTER,self.Filter) 1423 topSizer.Add(self.filterBox,0,wx.ALL,0) 1424 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8) 1425 self.clb = wx.ListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList) 1426 self.clb.Bind(wx.EVT_LEFT_DCLICK,self.onDoubleClick) 1427 if monoFont: 1428 font1 = wx.Font(self.clb.GetFont().GetPointSize(), 1429 wx.MODERN, wx.NORMAL, wx.NORMAL, False) 1430 self.clb.SetFont(font1) 1431 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10) 1432 Sizer.Add((-1,10)) 1433 # OK/Cancel buttons 1434 btnsizer = wx.StdDialogButtonSizer() 1435 if useOK: 1436 self.OKbtn = wx.Button(self, wx.ID_OK) 1437 self.OKbtn.SetDefault() 1438 btnsizer.AddButton(self.OKbtn) 1439 if useCANCEL: 1440 btn = wx.Button(self, wx.ID_CANCEL) 1441 btnsizer.AddButton(btn) 1442 btnsizer.Realize() 1443 Sizer.Add((-1,5)) 1444 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50) 1445 Sizer.Add((-1,20)) 1446 # OK done, let's get outa here 1447 self.SetSizer(Sizer) 1448 def GetSelection(self): 1449 'Returns the index of the selected choice' 1450 i = self.clb.GetSelection() 1451 if i < 0 or i >= len(self.filterlist): 1452 return wx.NOT_FOUND 1453 return self.filterlist[i] 1454 def onChar(self,event): 1455 self.OKbtn.Enable(False) 1456 if self.timer.IsRunning(): 1457 self.timer.Stop() 1458 self.timer.Start(1000,oneShot=True) 1459 event.Skip() 1460 def Filter(self,event): 1461 if self.timer.IsRunning(): 1462 self.timer.Stop() 1463 txt = self.filterBox.GetValue() 1464 self.clb.Clear() 1465 self.Update() 1466 self.filterlist = [] 1467 if txt: 1468 txt = txt.lower() 1469 ChoiceList = [] 1470 for i,item in enumerate(self.ChoiceList): 1471 if item.lower().find(txt) != -1: 1472 ChoiceList.append(item) 1473 self.filterlist.append(i) 1474 else: 1475 self.filterlist = range(len(self.ChoiceList)) 1476 ChoiceList = self.ChoiceList 1477 self.clb.AppendItems(ChoiceList) 1478 self.OKbtn.Enable(True) 1479 def onDoubleClick(self,event): 1480 self.EndModal(wx.ID_OK) 1185 1481 1186 1482 ################################################################################ -
trunk/GSASIIddataGUI.py
r1731 r1770 34 34 import GSASIIpwd as G2pwd 35 35 import GSASIIphsGUI as G2phsGUI 36 import GSASIIctrls as G2G 36 37 import numpy as np 37 38 … … 166 167 keyList = sorted(UseList.keys()) 167 168 if UseList: 168 dlg = G2 gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Copy parameters',169 dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Copy parameters', 169 170 'Copy parameters to which histograms?', 170 171 keyList) … … 211 212 keyList = sorted(UseList.keys()) 212 213 if UseList: 213 dlg = G2 gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Copy parameters',214 dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Copy parameters', 214 215 'Copy parameters to which histograms?', 215 216 keyList) -
trunk/GSASIIexprGUI.py
r1627 r1770 573 573 varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in parmList] 574 574 575 dlg = G2 gd.G2SingleChoiceDialog(575 dlg = G2G.G2SingleChoiceDialog( 576 576 self,'Select GSAS-II variable for '+str(var)+':', 577 577 'Select variable', -
trunk/GSASIIgrid.py
r1699 r1770 14 14 Note that a number of routines here should be moved to GSASIIctrls eventually, such as 15 15 G2LoggedButton, EnumSelector, G2ChoiceButton, SingleFloatDialog, SingleStringDialog, 16 MultiStringDialog, G2 MultiChoiceDialog, G2SingleChoiceDialog, G2ColumnIDDialog, ItemSelector, GridFractionEditor16 MultiStringDialog, G2ColumnIDDialog, ItemSelector, GridFractionEditor 17 17 18 18 Probably SGMessageBox, SymOpDialog, DisAglDialog, too. … … 746 746 ''' 747 747 return self.values 748 749 ################################################################################750 751 class G2MultiChoiceDialog(wx.Dialog):752 '''A dialog similar to MultiChoiceDialog except that buttons are753 added to set all choices and to toggle all choices.754 755 :param wx.Frame ParentFrame: reference to parent frame756 :param str title: heading above list of choices757 :param str header: Title to place on window frame758 :param list ChoiceList: a list of choices where one will be selected759 :param bool toggle: If True (default) the toggle and select all buttons760 are displayed761 :param bool monoFont: If False (default), use a variable-spaced font;762 if True use a equally-spaced font.763 :param bool filterBox: If True (default) an input widget is placed on764 the window and only entries matching the entered text are shown.765 :param kw: optional keyword parameters for the wx.Dialog may766 be included such as size [which defaults to `(320,310)`] and767 style (which defaults to `wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL`);768 note that `wx.OK` and `wx.CANCEL` controls769 the presence of the eponymous buttons in the dialog.770 :returns: the name of the created dialog771 '''772 def __init__(self,parent, title, header, ChoiceList, toggle=True,773 monoFont=False, filterBox=True, **kw):774 # process keyword parameters, notably style775 options = {'size':(320,310), # default Frame keywords776 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL,777 }778 options.update(kw)779 self.ChoiceList = ChoiceList # list of choices (list of str values)780 self.Selections = len(self.ChoiceList) * [False,] # selection status for each choice (list of bools)781 self.filterlist = range(len(self.ChoiceList)) # list of the choice numbers that have been filtered (list of int indices)782 if options['style'] & wx.OK:783 useOK = True784 options['style'] ^= wx.OK785 else:786 useOK = False787 if options['style'] & wx.CANCEL:788 useCANCEL = True789 options['style'] ^= wx.CANCEL790 else:791 useCANCEL = False792 # create the dialog frame793 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options)794 # fill the dialog795 Sizer = wx.BoxSizer(wx.VERTICAL)796 topSizer = wx.BoxSizer(wx.HORIZONTAL)797 topSizer.Add(798 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)),799 1,wx.ALL|wx.EXPAND|WACV,1)800 if filterBox:801 self.timer = wx.Timer()802 self.timer.Bind(wx.EVT_TIMER,self.Filter)803 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Name \nFilter: '),0,wx.ALL|WACV,1)804 self.filterBox = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1),style=wx.TE_PROCESS_ENTER)805 self.filterBox.Bind(wx.EVT_CHAR,self.onChar)806 self.filterBox.Bind(wx.EVT_TEXT_ENTER,self.Filter)807 topSizer.Add(self.filterBox,0,wx.ALL|WACV,0)808 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8)809 self.trigger = False810 self.clb = wx.CheckListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList)811 self.clb.Bind(wx.EVT_CHECKLISTBOX,self.OnCheck)812 if monoFont:813 font1 = wx.Font(self.clb.GetFont().GetPointSize(),814 wx.MODERN, wx.NORMAL, wx.NORMAL, False)815 self.clb.SetFont(font1)816 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10)817 Sizer.Add((-1,10))818 # set/toggle buttons819 if toggle:820 bSizer = wx.BoxSizer(wx.VERTICAL)821 setBut = wx.Button(self,wx.ID_ANY,'Set All')822 setBut.Bind(wx.EVT_BUTTON,self._SetAll)823 bSizer.Add(setBut,0,wx.ALIGN_CENTER)824 bSizer.Add((-1,5))825 togBut = wx.Button(self,wx.ID_ANY,'Toggle All')826 togBut.Bind(wx.EVT_BUTTON,self._ToggleAll)827 bSizer.Add(togBut,0,wx.ALIGN_CENTER)828 Sizer.Add(bSizer,0,wx.LEFT,12)829 # OK/Cancel buttons830 btnsizer = wx.StdDialogButtonSizer()831 if useOK:832 self.OKbtn = wx.Button(self, wx.ID_OK)833 self.OKbtn.SetDefault()834 btnsizer.AddButton(self.OKbtn)835 if useCANCEL:836 btn = wx.Button(self, wx.ID_CANCEL)837 btnsizer.AddButton(btn)838 btnsizer.Realize()839 Sizer.Add((-1,5))840 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50)841 Sizer.Add((-1,20))842 # OK done, let's get outa here843 self.SetSizer(Sizer)844 self.CenterOnParent()845 846 def GetSelections(self):847 'Returns a list of the indices for the selected choices'848 # update self.Selections with settings for displayed items849 for i in range(len(self.filterlist)):850 self.Selections[self.filterlist[i]] = self.clb.IsChecked(i)851 # return all selections, shown or hidden852 return [i for i in range(len(self.Selections)) if self.Selections[i]]853 854 def SetSelections(self,selList):855 '''Sets the selection indices in selList as selected. Resets any previous856 selections for compatibility with wx.MultiChoiceDialog. Note that857 the state for only the filtered items is shown.858 859 :param list selList: indices of items to be selected. These indices860 are referenced to the order in self.ChoiceList861 '''862 self.Selections = len(self.ChoiceList) * [False,] # reset selections863 for sel in selList:864 self.Selections[sel] = True865 self._ShowSelections()866 867 def _ShowSelections(self):868 'Show the selection state for displayed items'869 self.clb.SetChecked(870 [i for i in range(len(self.filterlist)) if self.Selections[self.filterlist[i]]]871 ) # Note anything previously checked will be cleared.872 873 def _SetAll(self,event):874 'Set all viewed choices on'875 self.clb.SetChecked(range(len(self.filterlist)))876 877 def _ToggleAll(self,event):878 'flip the state of all viewed choices'879 for i in range(len(self.filterlist)):880 self.clb.Check(i,not self.clb.IsChecked(i))881 882 def onChar(self,event):883 'for keyboard events. self.trigger is used in self.OnCheck below'884 self.OKbtn.Enable(False)885 if event.GetKeyCode() == wx.WXK_SHIFT:886 self.trigger = True887 if self.timer.IsRunning():888 self.timer.Stop()889 self.timer.Start(1000,oneShot=True)890 event.Skip()891 892 def OnCheck(self,event):893 '''for CheckListBox events; if Shift key down this sets all unset894 entries below the selected one'''895 if self.trigger:896 id = event.GetSelection()897 name = self.clb.GetString(id)898 iB = id-1899 if iB < 0:900 return901 while not self.clb.IsChecked(iB):902 self.clb.Check(iB)903 iB -= 1904 if iB < 0:905 break906 self.trigger = not self.trigger907 908 def Filter(self,event):909 if self.timer.IsRunning():910 self.timer.Stop()911 self.GetSelections() # record current selections912 txt = self.filterBox.GetValue()913 self.clb.Clear()914 915 self.Update()916 self.filterlist = []917 if txt:918 txt = txt.lower()919 ChoiceList = []920 for i,item in enumerate(self.ChoiceList):921 if item.lower().find(txt) != -1:922 ChoiceList.append(item)923 self.filterlist.append(i)924 else:925 self.filterlist = range(len(self.ChoiceList))926 ChoiceList = self.ChoiceList927 self.clb.AppendItems(ChoiceList)928 self._ShowSelections()929 self.OKbtn.Enable(True)930 931 ################################################################################932 933 class G2SingleChoiceDialog(wx.Dialog):934 '''A dialog similar to wx.SingleChoiceDialog except that a filter can be935 added.936 937 :param wx.Frame ParentFrame: reference to parent frame938 :param str title: heading above list of choices939 :param str header: Title to place on window frame940 :param list ChoiceList: a list of choices where one will be selected941 :param bool monoFont: If False (default), use a variable-spaced font;942 if True use a equally-spaced font.943 :param bool filterBox: If True (default) an input widget is placed on944 the window and only entries matching the entered text are shown.945 :param kw: optional keyword parameters for the wx.Dialog may946 be included such as size [which defaults to `(320,310)`] and947 style (which defaults to ``wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.CENTRE | wx.OK | wx.CANCEL``);948 note that ``wx.OK`` and ``wx.CANCEL`` controls949 the presence of the eponymous buttons in the dialog.950 :returns: the name of the created dialog951 '''952 def __init__(self,parent, title, header, ChoiceList,953 monoFont=False, filterBox=True, **kw):954 # process keyword parameters, notably style955 options = {'size':(320,310), # default Frame keywords956 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL,957 }958 options.update(kw)959 self.ChoiceList = ChoiceList960 self.filterlist = range(len(self.ChoiceList))961 if options['style'] & wx.OK:962 useOK = True963 options['style'] ^= wx.OK964 else:965 useOK = False966 if options['style'] & wx.CANCEL:967 useCANCEL = True968 options['style'] ^= wx.CANCEL969 else:970 useCANCEL = False971 # create the dialog frame972 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options)973 # fill the dialog974 Sizer = wx.BoxSizer(wx.VERTICAL)975 topSizer = wx.BoxSizer(wx.HORIZONTAL)976 topSizer.Add(977 wx.StaticText(self,wx.ID_ANY,title,size=(-1,35)),978 1,wx.ALL|wx.EXPAND|WACV,1)979 if filterBox:980 self.timer = wx.Timer()981 self.timer.Bind(wx.EVT_TIMER,self.Filter)982 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Filter: '),0,wx.ALL,1)983 self.filterBox = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1),984 style=wx.TE_PROCESS_ENTER)985 self.filterBox.Bind(wx.EVT_CHAR,self.onChar)986 self.filterBox.Bind(wx.EVT_TEXT_ENTER,self.Filter)987 topSizer.Add(self.filterBox,0,wx.ALL,0)988 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8)989 self.clb = wx.ListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList)990 self.clb.Bind(wx.EVT_LEFT_DCLICK,self.onDoubleClick)991 if monoFont:992 font1 = wx.Font(self.clb.GetFont().GetPointSize(),993 wx.MODERN, wx.NORMAL, wx.NORMAL, False)994 self.clb.SetFont(font1)995 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10)996 Sizer.Add((-1,10))997 # OK/Cancel buttons998 btnsizer = wx.StdDialogButtonSizer()999 if useOK:1000 self.OKbtn = wx.Button(self, wx.ID_OK)1001 self.OKbtn.SetDefault()1002 btnsizer.AddButton(self.OKbtn)1003 if useCANCEL:1004 btn = wx.Button(self, wx.ID_CANCEL)1005 btnsizer.AddButton(btn)1006 btnsizer.Realize()1007 Sizer.Add((-1,5))1008 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50)1009 Sizer.Add((-1,20))1010 # OK done, let's get outa here1011 self.SetSizer(Sizer)1012 def GetSelection(self):1013 'Returns the index of the selected choice'1014 i = self.clb.GetSelection()1015 if i < 0 or i >= len(self.filterlist):1016 return wx.NOT_FOUND1017 return self.filterlist[i]1018 def onChar(self,event):1019 self.OKbtn.Enable(False)1020 if self.timer.IsRunning():1021 self.timer.Stop()1022 self.timer.Start(1000,oneShot=True)1023 event.Skip()1024 def Filter(self,event):1025 if self.timer.IsRunning():1026 self.timer.Stop()1027 txt = self.filterBox.GetValue()1028 self.clb.Clear()1029 self.Update()1030 self.filterlist = []1031 if txt:1032 txt = txt.lower()1033 ChoiceList = []1034 for i,item in enumerate(self.ChoiceList):1035 if item.lower().find(txt) != -1:1036 ChoiceList.append(item)1037 self.filterlist.append(i)1038 else:1039 self.filterlist = range(len(self.ChoiceList))1040 ChoiceList = self.ChoiceList1041 self.clb.AppendItems(ChoiceList)1042 self.OKbtn.Enable(True)1043 def onDoubleClick(self,event):1044 self.EndModal(wx.ID_OK)1045 748 1046 749 ################################################################################ … … 1199 902 if multiple: 1200 903 if useCancel: 1201 dlg = G2 MultiChoiceDialog(904 dlg = G2G.G2MultiChoiceDialog( 1202 905 ParentFrame,title, header, ChoiceList) 1203 906 else: 1204 dlg = G2 MultiChoiceDialog(907 dlg = G2G.G2MultiChoiceDialog( 1205 908 ParentFrame,title, header, ChoiceList, 1206 909 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE) … … 2573 2276 sel.append(choices.index(item)) 2574 2277 sel = [choices.index(item) for item in data['Seq Data']] 2575 dlg = G2 MultiChoiceDialog(G2frame.dataFrame, 'Sequential refinement',2278 dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential refinement', 2576 2279 'Select dataset to include', 2577 2280 choices) … … 2994 2697 ncols = G2frame.SeqTable.GetNumberCols() 2995 2698 colNames = [G2frame.SeqTable.GetColLabelValue(r) for r in range(ncols)] 2996 dlg = G2 SingleChoiceDialog(2699 dlg = G2G.G2SingleChoiceDialog( 2997 2700 G2frame.dataDisplay, 2998 2701 'Select x-axis parameter for plot or Cancel for sequence number', -
trunk/GSASIIimgGUI.py
r1764 r1770 1569 1569 return 1570 1570 sel = [] 1571 dlg = G2 gd.G2MultiChoiceDialog(G2frame,'Stress/Strain fitting','Select images to fit:',choices)1571 dlg = G2G.G2MultiChoiceDialog(G2frame,'Stress/Strain fitting','Select images to fit:',choices) 1572 1572 dlg.SetSelections(sel) 1573 1573 names = [] -
trunk/GSASIIphsGUI.py
r1762 r1770 709 709 710 710 def OnRefList(event): 711 dlg = G2 gd.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use',711 dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use', 712 712 'Use data',refsList,filterBox=False) 713 713 try: … … 780 780 781 781 def OnRefList(event): 782 dlg = G2 gd.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use',782 dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use', 783 783 'Use data',refsList,filterBox=False) 784 784 try: … … 2226 2226 2227 2227 def OnRefList(event): 2228 dlg = G2 gd.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use',2228 dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select reflection sets to use', 2229 2229 'Use data',refsList,filterBox=False) 2230 2230 try: -
trunk/GSASIIpwdGUI.py
r1765 r1770 223 223 G2frame.PatternTree.SetItemPyData(G2frame.PatternId,sourceData) 224 224 225 dlg = G2 gd.G2MultiChoiceDialog(225 dlg = G2G.G2MultiChoiceDialog( 226 226 G2frame.dataFrame, 227 227 'Copy plot controls from\n'+str(hst[5:])+' to...', … … 255 255 return 256 256 choices = ['Limits','Background','Instrument Parameters','Sample Parameters'] 257 dlg = G2 gd.G2MultiChoiceDialog(257 dlg = G2G.G2MultiChoiceDialog( 258 258 G2frame.dataFrame, 259 259 'Copy which histogram sections from\n'+str(hst[5:]), … … 265 265 if not choiceList: return 266 266 267 dlg = G2 gd.G2MultiChoiceDialog(267 dlg = G2G.G2MultiChoiceDialog( 268 268 G2frame.dataFrame, 269 269 'Copy parameters from\n'+str(hst[5:])+' to...', … … 377 377 return 378 378 copyList = [] 379 dlg = G2 gd.G2MultiChoiceDialog(379 dlg = G2G.G2MultiChoiceDialog( 380 380 G2frame.dataFrame, 381 381 'Copy peak list from\n'+str(hst[5:])+' to...', … … 436 436 return 437 437 sel = [] 438 dlg = G2 gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential peak fits',438 dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential peak fits', 439 439 'Select dataset to include',histList) 440 440 dlg.SetSelections(sel) … … 744 744 G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) 745 745 return 746 dlg = G2 gd.G2MultiChoiceDialog(746 dlg = G2G.G2MultiChoiceDialog( 747 747 G2frame.dataFrame, 748 748 'Copy bkg ref. flags from\n'+str(hst[5:])+' to...', … … 774 774 return 775 775 copyList = [] 776 dlg = G2 gd.G2MultiChoiceDialog(776 dlg = G2G.G2MultiChoiceDialog( 777 777 G2frame.dataFrame, 778 778 'Copy bkg params from\n'+str(hst[5:])+' to...', … … 1036 1036 return 1037 1037 copyList = [] 1038 dlg = G2 gd.G2MultiChoiceDialog(1038 dlg = G2G.G2MultiChoiceDialog( 1039 1039 G2frame.dataFrame, 1040 1040 'Copy limits from\n'+str(hst[5:])+' to...', … … 1219 1219 instType = data['Type'][0] 1220 1220 copyList = [] 1221 dlg = G2 gd.G2MultiChoiceDialog(1221 dlg = G2G.G2MultiChoiceDialog( 1222 1222 G2frame.dataFrame, 1223 1223 'Copy inst ref. flags from\n'+hst[5:], … … 1247 1247 copyList = [] 1248 1248 instType = data['Type'][0] 1249 dlg = G2 gd.G2MultiChoiceDialog(1249 dlg = G2G.G2MultiChoiceDialog( 1250 1250 G2frame.dataFrame, 1251 1251 'Copy inst params from\n'+hst, … … 1753 1753 G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) 1754 1754 return 1755 dlg = G2 gd.G2MultiChoiceDialog(1755 dlg = G2G.G2MultiChoiceDialog( 1756 1756 G2frame.dataFrame, 1757 1757 'Copy sample params from\n'+str(hst[5:])+' to...', … … 1796 1796 keyText, keyList = zip(*sorted(zip(keyText,keyList))) # sort lists 1797 1797 selectedKeys = [] 1798 dlg = G2 gd.G2MultiChoiceDialog(1798 dlg = G2G.G2MultiChoiceDialog( 1799 1799 G2frame.dataFrame, 1800 1800 'Select which sample parameters\nto copy', … … 1809 1809 for parm in selectedKeys: 1810 1810 copyDict[parm] = data[parm] 1811 dlg = G2 gd.G2MultiChoiceDialog(1811 dlg = G2G.G2MultiChoiceDialog( 1812 1812 G2frame.dataFrame, 1813 1813 'Copy sample params from\n'+str(hst[5:])+' to...', … … 1835 1835 G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) 1836 1836 return 1837 dlg = G2 gd.G2MultiChoiceDialog(1837 dlg = G2G.G2MultiChoiceDialog( 1838 1838 G2frame.dataFrame, 1839 1839 'Copy sample ref. flags from\n'+str(hst[5:])+' to...', … … 3142 3142 return 3143 3143 copyList = [] 3144 dlg = G2 gd.G2MultiChoiceDialog(3144 dlg = G2G.G2MultiChoiceDialog( 3145 3145 G2frame.dataFrame, 3146 3146 'Copy substances from\n'+hst[5:]+' to...', … … 3431 3431 return 3432 3432 copyList = [] 3433 dlg = G2 gd.G2MultiChoiceDialog(3433 dlg = G2G.G2MultiChoiceDialog( 3434 3434 G2frame.dataFrame, 3435 3435 'Copy models from\n'+hst[5:]+' to...', … … 3459 3459 G2frame.ErrorDialog('No match','No histograms match '+hst,G2frame.dataFrame) 3460 3460 return 3461 dlg = G2 gd.G2MultiChoiceDialog(3461 dlg = G2G.G2MultiChoiceDialog( 3462 3462 G2frame.dataFrame, 3463 3463 'Copy sample ref. flags from\n'+str(hst[5:])+' to...', … … 3493 3493 choices = G2gd.GetPatternTreeDataNames(G2frame,['SASD',]) 3494 3494 sel = [] 3495 dlg = G2 gd.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential SASD refinement',3495 dlg = G2G.G2MultiChoiceDialog(G2frame.dataFrame, 'Sequential SASD refinement', 3496 3496 'Select dataset to include',choices) 3497 3497 dlg.SetSelections(sel) -
trunk/GSASIIstrMain.py
r1688 r1770 42 42 43 43 ateln2 = 8.0*math.log(2.0) 44 DEBUG = False44 DEBUG = True 45 45 46 46 def RefineCore(Controls,Histograms,Phases,restraintDict,rigidbodyDict,parmDict,varyList, -
trunk/GSASIIstrMath.py
r1767 r1770 1365 1365 Icorr *= G2pwd.Polarization(parmDict[hfx+'Polariz.'],refl[5+im],parmDict[hfx+'Azimuth'])[0] 1366 1366 POcorr = 1.0 1367 if pfx+'SHorder' in parmDict: #generalized spherical harmonics texture 1367 if pfx+'SHorder' in parmDict: #generalized spherical harmonics texture - takes precidence 1368 1368 POcorr = SHTXcal(refl,im,g,pfx,hfx,SGData,calcControls,parmDict) 1369 1369 elif calcControls[phfx+'poType'] == 'MD': #March-Dollase
Note: See TracChangeset
for help on using the changeset viewer.