Changeset 1512 for trunk/GSASII.py
- Timestamp:
- Oct 1, 2014 10:35:23 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r1508 r1512 77 77 import GSASIIobj as G2obj 78 78 import GSASIIlattice as G2lat 79 import GSASIIlog as log 79 80 80 81 #wx inspector - use as needed … … 116 117 '''Define the main GSAS-II frame and its associated menu items 117 118 ''' 119 def MenuBinding(self,event): 120 '''Called when a menu is clicked upon; looks up the binding in table 121 ''' 122 log.InvokeMenuCommand(event.GetId(),self,event) 123 124 def Bind(self,eventtype,handler,*args,**kwargs): 125 '''Override the Bind function so that we can wrap calls that will be logged. 126 127 N.B. This is a bit kludgy. Menu bindings with an id are wrapped and 128 menu bindings with an object and no id are not. 129 ''' 130 if eventtype == wx.EVT_MENU and 'id' in kwargs: 131 menulabels = log.SaveMenuCommand(kwargs['id'],self,handler) 132 if menulabels: 133 wx.Frame.Bind(self,eventtype,self.MenuBinding,*args,**kwargs) 134 return 135 wx.Frame.Bind(self,eventtype,handler,*args,**kwargs) 118 136 119 137 def _Add_FileMenuItems(self, parent): … … 1642 1660 return # success 1643 1661 1662 def OnMacroRecordStatus(self,event,setvalue=None): 1663 '''Called when the record macro menu item is used which toggles the 1664 value. Alternately a value to be set can be provided. Note that this 1665 routine is made more complex because on the Mac there are lots of menu 1666 items (listed in self.MacroStatusList) and this loops over all of them. 1667 ''' 1668 nextvalue = log.ShowLogStatus() != True 1669 if setvalue is not None: 1670 nextvalue = setvalue 1671 if nextvalue: 1672 log.LogOn() 1673 set2 = True 1674 else: 1675 log.LogOff() 1676 set2 = False 1677 for menuitem in self.MacroStatusList: 1678 menuitem.Check(set2) 1679 1680 def _init_Macro(self): 1681 '''Define the items in the macro menu. 1682 ''' 1683 menu = self.MacroMenu 1684 item = menu.Append( 1685 help='Start or stop recording of menu actions, etc.', id=wx.ID_ANY, 1686 kind=wx.ITEM_CHECK,text='Record actions') 1687 self.MacroStatusList.append(item) 1688 item.Check(log.ShowLogStatus()) 1689 self.Bind(wx.EVT_MENU, self.OnMacroRecordStatus, item) 1690 1691 # this may only be of value for development work 1692 item = menu.Append( 1693 help='Show logged commands', id=wx.ID_ANY, 1694 kind=wx.ITEM_NORMAL,text='Show log') 1695 def OnShowLog(event): 1696 print 70*'=' 1697 print 'List of logged actions' 1698 for i,line in enumerate(log.G2logList): 1699 if line: print i,line 1700 print 70*'=' 1701 self.Bind(wx.EVT_MENU, OnShowLog, item) 1702 1703 item = menu.Append( 1704 help='Clear logged commands', id=wx.ID_ANY, 1705 kind=wx.ITEM_NORMAL,text='Clear log') 1706 def OnClearLog(event): log.G2logList=[None] 1707 self.Bind(wx.EVT_MENU, OnClearLog, item) 1708 1709 item = menu.Append( 1710 help='Save logged commands to file', id=wx.ID_ANY, 1711 kind=wx.ITEM_NORMAL,text='Save log') 1712 def OnSaveLog(event): 1713 import cPickle 1714 defnam = os.path.splitext( 1715 os.path.split(self.GSASprojectfile)[1] 1716 )[0]+'.gcmd' 1717 dlg = wx.FileDialog(self, 1718 'Choose an file to save past actions', '.', defnam, 1719 'GSAS-II cmd output (*.gcmd)|*.gcmd', 1720 wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR) 1721 dlg.CenterOnParent() 1722 try: 1723 if dlg.ShowModal() == wx.ID_OK: 1724 filename = dlg.GetPath() 1725 # make sure extension is correct 1726 filename = os.path.splitext(filename)[0]+'.gcmd' 1727 else: 1728 filename = None 1729 finally: 1730 dlg.Destroy() 1731 if filename: 1732 fp = open(filename,'wb') 1733 fp.write(str(len(log.G2logList)-1)+'\n') 1734 for item in log.G2logList: 1735 if item: cPickle.dump(item,fp) 1736 fp.close() 1737 self.Bind(wx.EVT_MENU, OnSaveLog, item) 1738 1739 item = menu.Append( 1740 help='Load logged commands from file', id=wx.ID_ANY, 1741 kind=wx.ITEM_NORMAL,text='Load log') 1742 def OnLoadLog(event): 1743 # this appends. Perhaps we should ask to clear? 1744 import cPickle 1745 defnam = os.path.splitext( 1746 os.path.split(self.GSASprojectfile)[1] 1747 )[0]+'.gcmd' 1748 dlg = wx.FileDialog(self, 1749 'Choose an file to read saved actions', '.', defnam, 1750 'GSAS-II cmd output (*.gcmd)|*.gcmd', 1751 wx.OPEN|wx.CHANGE_DIR) 1752 dlg.CenterOnParent() 1753 try: 1754 if dlg.ShowModal() == wx.ID_OK: 1755 filename = dlg.GetPath() 1756 # make sure extension is correct 1757 filename = os.path.splitext(filename)[0]+'.gcmd' 1758 else: 1759 filename = None 1760 finally: 1761 dlg.Destroy() 1762 if filename and os.path.exists(filename): 1763 fp = open(filename,'rb') 1764 lines = fp.readline() 1765 for i in range(int(lines)): 1766 log.G2logList.append(cPickle.load(fp)) 1767 fp.close() 1768 self.Bind(wx.EVT_MENU, OnLoadLog, item) 1769 1770 item = menu.Append( 1771 help='Replay saved commands', id=wx.ID_ANY, 1772 kind=wx.ITEM_NORMAL,text='Replay log') 1773 self.Bind(wx.EVT_MENU, log.ReplayLog, item) 1774 1644 1775 def _init_Exports(self,menu): 1645 1776 '''Find exporter routines and add them into menus … … 1792 1923 1793 1924 def FillMainMenu(self,menubar): 1794 '''Define contents of the main GSAS-II menu for the (main) data tree window 1795 in the mac, used also for the data item windows as well. 1925 '''Define contents of the main GSAS-II menu for the (main) data tree window. 1926 For the mac, this is also called for the data item windows as well so that 1927 the main menu items are data menu as well. 1796 1928 ''' 1797 1929 File = wx.Menu(title='') … … 1849 1981 self._init_Exports(self.ExportMenu) 1850 1982 self._Add_ExportMenuItems(self.ExportMenu) 1983 if GSASIIpath.GetConfigValue('Enable_logging'): 1984 self.MacroMenu = wx.Menu(title='') 1985 menubar.Append(menu=self.MacroMenu, title='Macro') 1986 self._init_Macro() 1851 1987 HelpMenu=G2gd.MyHelp(self,helpType='Data tree', 1852 1988 morehelpitems=[('&Tutorials','Tutorials')]) … … 1873 2009 # 1874 2010 self.GSASIIMenu = wx.MenuBar() 2011 # create a list of all dataframe menus (appended in PrefillDataMenu) 2012 self.dataMenuBars = [self.GSASIIMenu] 2013 self.MacroStatusList = [] 1875 2014 self.FillMainMenu(self.GSASIIMenu) 1876 2015 self.SetMenuBar(self.GSASIIMenu) … … 1880 2019 1881 2020 wxID_PATTERNTREE = wx.NewId() 1882 self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE, 2021 #self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE, # replaced for logging 2022 self.PatternTree = G2gd.G2TreeCtrl(id=wxID_PATTERNTREE, 1883 2023 parent=self.mainPanel, pos=wx.Point(0, 0),style=wx.TR_DEFAULT_STYLE ) 1884 self.PatternTree.Bind(wx.EVT_TREE_SEL_CHANGED, 1885 self.OnPatternTreeSelChanged, id=wxID_PATTERNTREE) 2024 self.PatternTree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnPatternTreeSelChanged) 1886 2025 self.PatternTree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, 1887 2026 self.OnPatternTreeItemCollapsed, id=wxID_PATTERNTREE) … … 1896 2035 self.PatternTree.Bind(wx.EVT_TREE_END_DRAG, 1897 2036 self.OnPatternTreeEndDrag, id=wxID_PATTERNTREE) 1898 self.root = self.PatternTree.AddRoot('Loaded Data: ') 2037 #self.root = self.PatternTree.AddRoot('Loaded Data: ') 2038 self.root = self.PatternTree.root 1899 2039 plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \ 1900 2040 style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
Note: See TracChangeset
for help on using the changeset viewer.