Changeset 1117 for trunk/GSASIIgrid.py
- Timestamp:
- Oct 21, 2013 1:11:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIgrid.py ¶
r1115 r1117 1289 1289 1290 1290 ################################################################################ 1291 class G2MultiChoiceDialog(wx.Dialog): 1292 '''A dialog similar to MultiChoiceDialog except that buttons are 1293 added to set all choices and to toggle all choices. 1294 1295 :param wx.Frame ParentFrame: reference to parent frame 1296 :param str title: heading above list of choices 1297 :param str header: Title to place on window frame 1298 :param list ChoiceList: a list of choices where one will be selected 1299 1300 :param kw: optional keyword parameters for the wx.Dialog may 1301 be included such as Size [which defaults to `(320,310)`] and 1302 Style (which defaults to `wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL`); 1303 note that `wx.OK` and `wx.CANCEL` controls 1304 the presence of the eponymous buttons in the dialog. 1305 :returns: the name of the created dialog 1306 ''' 1307 def __init__(self,parent, title, header, ChoiceList, **kw): 1308 # process keyword parameters, notably Style 1309 options = {'size':(320,310), # default Frame keywords 1310 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL, 1311 } 1312 options.update(kw) 1313 if options['style'] & wx.OK: 1314 useOK = True 1315 options['style'] ^= wx.OK 1316 else: 1317 useOK = False 1318 if options['style'] & wx.CANCEL: 1319 useCANCEL = True 1320 options['style'] ^= wx.CANCEL 1321 else: 1322 useCANCEL = False 1323 # create the dialog frame 1324 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options) 1325 # fill the dialog 1326 Sizer = wx.BoxSizer(wx.VERTICAL) 1327 Sizer.Add(wx.StaticText(self,wx.ID_ANY,title),0,wx.ALL,12) 1328 self.clb = wx.CheckListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList) 1329 self.numchoices = len(ChoiceList) 1330 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10) 1331 Sizer.Add((-1,10)) 1332 # set/toggle buttons 1333 bSizer = wx.BoxSizer(wx.VERTICAL) 1334 setBut = wx.Button(self,wx.ID_ANY,'Set All') 1335 setBut.Bind(wx.EVT_BUTTON,self._SetAll) 1336 bSizer.Add(setBut,0,wx.ALIGN_CENTER) 1337 bSizer.Add((-1,5)) 1338 togBut = wx.Button(self,wx.ID_ANY,'Toggle All') 1339 togBut.Bind(wx.EVT_BUTTON,self._ToggleAll) 1340 bSizer.Add(togBut,0,wx.ALIGN_CENTER) 1341 Sizer.Add(bSizer,0,wx.LEFT,12) 1342 # OK/Cancel buttons 1343 btnsizer = wx.StdDialogButtonSizer() 1344 if useOK: 1345 OKbtn = wx.Button(self, wx.ID_OK) 1346 OKbtn.SetDefault() 1347 btnsizer.AddButton(OKbtn) 1348 if useCANCEL: 1349 btn = wx.Button(self, wx.ID_CANCEL) 1350 btnsizer.AddButton(btn) 1351 btnsizer.Realize() 1352 Sizer.Add((-1,5)) 1353 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50) 1354 Sizer.Add((-1,20)) 1355 # OK done, let's get outa here 1356 self.SetSizer(Sizer) 1357 def GetSelections(self): 1358 'Returns a list of the indices for the selected choices' 1359 return [i for i in range(self.numchoices) if self.clb.IsChecked(i)] 1360 def _SetAll(self,event): 1361 'Set all choices on' 1362 self.clb.SetChecked(range(self.numchoices)) 1363 def _ToggleAll(self,event): 1364 'flip the state of all choices' 1365 for i in range(self.numchoices): 1366 self.clb.Check(i,not self.clb.IsChecked(i)) 1367 1291 1368 def ItemSelector(ChoiceList, ParentFrame=None, 1292 1369 title='Select an item', … … 1307 1384 if multiple: 1308 1385 if useCancel: 1309 dlg = wx.MultiChoiceDialog(1386 dlg = G2MultiChoiceDialog( 1310 1387 ParentFrame,title, header, ChoiceList) 1311 1388 else: 1312 dlg = wx.MultiChoiceDialog(1389 dlg = G2MultiChoiceDialog( 1313 1390 ParentFrame,title, header, ChoiceList, 1314 1391 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE) 1315 # I would like to add a select all and toggle all button1316 # to this dialog in some manner, but that is going to1317 # require that I recode the entire dialog -- TODO someday1318 1392 else: 1319 1393 if useCancel:
Note: See TracChangeset
for help on using the changeset viewer.