Changeset 1209 for trunk/GSASIIgrid.py
- Timestamp:
- Jan 30, 2014 11:45:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIgrid.py ¶
r1208 r1209 211 211 * tc: (*wx.TextCtrl*) the TextCtrl name 212 212 213 The number of keyword arguments may be increased in the future , ifneeds arise,213 The number of keyword arguments may be increased in the future should needs arise, 214 214 so it is best to code these functions with a \*\*kwargs argument so they will 215 215 continue to run without errors … … 301 301 raise Exception,("ValidatedTxtCtrl error: Unknown element ("+str(key)+ 302 302 ") type: "+str(type(val))) 303 # When the mouse is moved away or the widget loses focus 303 # When the mouse is moved away or the widget loses focus, 304 304 # display the last saved value, if an expression 305 305 self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow) … … 332 332 wx.TextCtrl.SetValue(self,str(G2py3.FormatValue(val,self.nDig))) 333 333 else: 334 wx.TextCtrl.SetValue(self,str(G2py3.FormatSigFigs(val)) )334 wx.TextCtrl.SetValue(self,str(G2py3.FormatSigFigs(val)).rstrip('0')) 335 335 else: 336 336 wx.TextCtrl.SetValue(self,str(val)) … … 1374 1374 1375 1375 ################################################################################ 1376 1376 1377 class G2MultiChoiceDialog(wx.Dialog): 1377 1378 '''A dialog similar to MultiChoiceDialog except that buttons are … … 1384 1385 :param bool toggle: If True (default) the toggle and select all buttons 1385 1386 are displayed 1386 1387 :param bool monoFont: If False (default), use a variable-spaced font; 1388 if True use a equally-spaced font. 1389 :param bool filterBox: If True (default) an input widget is placed on 1390 the window and only entries matching the entered text are shown. 1387 1391 :param kw: optional keyword parameters for the wx.Dialog may 1388 1392 be included such as size [which defaults to `(320,310)`] and … … 1392 1396 :returns: the name of the created dialog 1393 1397 ''' 1394 def __init__(self,parent, title, header, ChoiceList, toggle=True, **kw): 1395 # process keyword parameters, notably Style 1398 def __init__(self,parent, title, header, ChoiceList, toggle=True, 1399 monoFont=False, filterBox=True, **kw): 1400 # process keyword parameters, notably style 1396 1401 options = {'size':(320,310), # default Frame keywords 1397 1402 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL, 1398 1403 } 1399 1404 options.update(kw) 1405 self.ChoiceList = ChoiceList 1406 self.filterlist = range(len(self.ChoiceList)) 1400 1407 if options['style'] & wx.OK: 1401 1408 useOK = True … … 1412 1419 # fill the dialog 1413 1420 Sizer = wx.BoxSizer(wx.VERTICAL) 1414 Sizer.Add(wx.StaticText(self,wx.ID_ANY,title),0,wx.ALL,12) 1421 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1422 topSizer.Add(wx.StaticText(self,wx.ID_ANY,title),1,wx.ALL|wx.EXPAND,0) 1423 if filterBox: 1424 self.timer = wx.Timer() 1425 self.timer.Bind(wx.EVT_TIMER,self.Filter) 1426 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Filter: '),0,wx.ALL,1) 1427 self.txt = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1)) 1428 self.txt.Bind(wx.EVT_CHAR,self.onChar) 1429 topSizer.Add(self.txt,0,wx.ALL,0) 1430 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8) 1415 1431 self.clb = wx.CheckListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList) 1432 if monoFont: 1433 font1 = wx.Font(self.clb.GetFont().GetPointSize()-1, 1434 wx.MODERN, wx.NORMAL, wx.NORMAL, False) 1435 self.clb.SetFont(font1) 1416 1436 self.numchoices = len(ChoiceList) 1417 1437 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10) … … 1445 1465 def GetSelections(self): 1446 1466 'Returns a list of the indices for the selected choices' 1447 return [ ifor i in range(self.numchoices) if self.clb.IsChecked(i)]1467 return [self.filterlist[i] for i in range(self.numchoices) if self.clb.IsChecked(i)] 1448 1468 def _SetAll(self,event): 1449 1469 'Set all choices on' … … 1453 1473 for i in range(self.numchoices): 1454 1474 self.clb.Check(i,not self.clb.IsChecked(i)) 1475 def onChar(self,event): 1476 if self.timer.IsRunning(): 1477 self.timer.Stop() 1478 self.timer.Start(1000,oneShot=True) 1479 event.Skip() 1480 def Filter(self,event): 1481 txt = self.txt.GetValue() 1482 self.clb.Clear() 1483 self.Update() 1484 self.filterlist = [] 1485 if txt: 1486 txt = txt.lower() 1487 ChoiceList = [] 1488 for i,item in enumerate(self.ChoiceList): 1489 if item.lower().find(txt) != -1: 1490 ChoiceList.append(item) 1491 self.filterlist.append(i) 1492 else: 1493 self.filterlist = range(len(self.ChoiceList)) 1494 ChoiceList = self.ChoiceList 1495 self.clb.AppendItems(ChoiceList) 1496 1497 ################################################################################ 1498 1499 class G2SingleChoiceDialog(wx.Dialog): 1500 '''A dialog similar to wx.SingleChoiceDialog except that a filter can be 1501 added. 1502 1503 :param wx.Frame ParentFrame: reference to parent frame 1504 :param str title: heading above list of choices 1505 :param str header: Title to place on window frame 1506 :param list ChoiceList: a list of choices where one will be selected 1507 :param bool monoFont: If False (default), use a variable-spaced font; 1508 if True use a equally-spaced font. 1509 :param bool filterBox: If True (default) an input widget is placed on 1510 the window and only entries matching the entered text are shown. 1511 :param kw: optional keyword parameters for the wx.Dialog may 1512 be included such as size [which defaults to `(320,310)`] and 1513 style (which defaults to ``wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.CENTRE | wx.OK | wx.CANCEL``); 1514 note that ``wx.OK`` and ``wx.CANCEL`` controls 1515 the presence of the eponymous buttons in the dialog. 1516 :returns: the name of the created dialog 1517 ''' 1518 def __init__(self,parent, title, header, ChoiceList, 1519 monoFont=False, filterBox=True, **kw): 1520 # process keyword parameters, notably style 1521 options = {'size':(320,310), # default Frame keywords 1522 'style':wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL, 1523 } 1524 options.update(kw) 1525 self.ChoiceList = ChoiceList 1526 self.filterlist = range(len(self.ChoiceList)) 1527 if options['style'] & wx.OK: 1528 useOK = True 1529 options['style'] ^= wx.OK 1530 else: 1531 useOK = False 1532 if options['style'] & wx.CANCEL: 1533 useCANCEL = True 1534 options['style'] ^= wx.CANCEL 1535 else: 1536 useCANCEL = False 1537 # create the dialog frame 1538 wx.Dialog.__init__(self,parent,wx.ID_ANY,header,**options) 1539 # fill the dialog 1540 Sizer = wx.BoxSizer(wx.VERTICAL) 1541 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1542 topSizer.Add(wx.StaticText(self,wx.ID_ANY,title),1,wx.ALL|wx.EXPAND,0) 1543 if filterBox: 1544 self.timer = wx.Timer() 1545 self.timer.Bind(wx.EVT_TIMER,self.Filter) 1546 topSizer.Add(wx.StaticText(self,wx.ID_ANY,'Filter: '),0,wx.ALL,1) 1547 self.txt = wx.TextCtrl(self, wx.ID_ANY, size=(80,-1)) 1548 self.txt.Bind(wx.EVT_CHAR,self.onChar) 1549 topSizer.Add(self.txt,0,wx.ALL,0) 1550 Sizer.Add(topSizer,0,wx.ALL|wx.EXPAND,8) 1551 self.clb = wx.ListBox(self, wx.ID_ANY, (30,30), wx.DefaultSize, ChoiceList) 1552 self.clb.Bind(wx.EVT_LEFT_DCLICK,self.onDoubleClick) 1553 if monoFont: 1554 font1 = wx.Font(self.clb.GetFont().GetPointSize()-1, 1555 wx.MODERN, wx.NORMAL, wx.NORMAL, False) 1556 self.clb.SetFont(font1) 1557 self.numchoices = len(ChoiceList) 1558 Sizer.Add(self.clb,1,wx.LEFT|wx.RIGHT|wx.EXPAND,10) 1559 Sizer.Add((-1,10)) 1560 # OK/Cancel buttons 1561 btnsizer = wx.StdDialogButtonSizer() 1562 if useOK: 1563 OKbtn = wx.Button(self, wx.ID_OK) 1564 OKbtn.SetDefault() 1565 btnsizer.AddButton(OKbtn) 1566 if useCANCEL: 1567 btn = wx.Button(self, wx.ID_CANCEL) 1568 btnsizer.AddButton(btn) 1569 btnsizer.Realize() 1570 Sizer.Add((-1,5)) 1571 Sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50) 1572 Sizer.Add((-1,20)) 1573 # OK done, let's get outa here 1574 self.SetSizer(Sizer) 1575 def GetSelection(self): 1576 'Returns the index of the selected choice' 1577 i = self.clb.GetSelection() 1578 if i < 0 or i >= len(self.filterlist): 1579 return wx.NOT_FOUND 1580 return self.filterlist[i] 1581 def onChar(self,event): 1582 if self.timer.IsRunning(): 1583 self.timer.Stop() 1584 self.timer.Start(1000,oneShot=True) 1585 event.Skip() 1586 def Filter(self,event): 1587 txt = self.txt.GetValue() 1588 self.clb.Clear() 1589 self.Update() 1590 self.filterlist = [] 1591 if txt: 1592 txt = txt.lower() 1593 ChoiceList = [] 1594 for i,item in enumerate(self.ChoiceList): 1595 if item.lower().find(txt) != -1: 1596 ChoiceList.append(item) 1597 self.filterlist.append(i) 1598 else: 1599 self.filterlist = range(len(self.ChoiceList)) 1600 ChoiceList = self.ChoiceList 1601 self.clb.AppendItems(ChoiceList) 1602 def onDoubleClick(self,event): 1603 self.EndModal(wx.ID_OK) 1604 1605 ################################################################################ 1455 1606 1456 1607 def ItemSelector(ChoiceList, ParentFrame=None,
Note: See TracChangeset
for help on using the changeset viewer.