Changeset 765 for trunk/GSASII.py


Ignore:
Timestamp:
Sep 28, 2012 9:25:04 PM (10 years ago)
Author:
toby
Message:

refactor menus on Mac, clean up main menu generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r762 r765  
    9999    return GSASII(parent)
    100100
    101 [wxID_PATTERNTREE,
    102 ] = [wx.NewId() for _init_ctrls in range(1)]
    103 
    104 [wxID_FILECLOSE, wxID_FILEEXIT, wxID_FILEOPEN,  wxID_FILESAVE, wxID_FILESAVEAS,
    105 wxID_REFINE,  wxID_MAKEPDFS, wxID_VIEWLSPARMS, wxID_SEQREFINE,
    106 ] = [wx.NewId() for _init_coll_File_Items in range(9)]
    107 
    108 [wxID_PWDRREAD,wxID_SNGLREAD,wxID_ADDPHASE,wxID_DELETEPHASE,
    109  wxID_DATADELETE,wxID_READPEAKS,wxID_PWDSUM,wxID_IMGREAD,
    110  wxID_IMSUM, wxID_DATARENAME,
    111 ] = [wx.NewId() for _init_coll_Data_Items in range(10)]
    112 
    113 [wxID_EXPORT, wxID_EXPORTPATTERN, wxID_EXPORTHKL, wxID_EXPORTPHASE,
    114 wxID_EXPORTCIF, wxID_EXPORTPEAKLIST, wxID_EXPORTPDF,
    115 ] = [wx.NewId() for _init_coll_Export_Items in range(7)]
    116 
    117101class GSASII(wx.Frame):
    118102   
    119     def _init_coll_GSASIIMenu_Menus(self, parent):
    120         parent.Append(menu=self.File, title='File')
    121         parent.Append(menu=self.Data, title='Data')
    122         parent.Append(menu=self.Calculate, title='Calculate')
    123         parent.Append(menu=self.Import, title='Import')
    124         parent.Append(menu=self.Export, title='Export')
    125         self.HelpMenu=G2gd.MyHelp(self,helpType='Data tree',
    126             morehelpitems=[('&Tutorials','Tutorials')])
    127         parent.Append(menu=self.HelpMenu,title='&Help')
    128        
    129     def _init_coll_File_Items(self, parent):
    130         parent.Append(help='Open a gsasii project file (*.gpx)', id=wxID_FILEOPEN,
    131              kind=wx.ITEM_NORMAL,text='Open project...')
    132         parent.Append(help='Save project to old file', id=wxID_FILESAVE,
     103    def _Add_FileMenuItems(self, parent):
     104        item = parent.Append(
     105            help='Open a gsasii project file (*.gpx)', id=wx.ID_ANY,
     106            kind=wx.ITEM_NORMAL,text='Open project...')
     107        self.Bind(wx.EVT_MENU, self.OnFileOpen, id=item.GetId())
     108        item = parent.Append(
     109            help='Save project to old file', id=wx.ID_ANY,
    133110            kind=wx.ITEM_NORMAL,text='Save project')
    134         parent.Append(help='Save project to new file', id=wxID_FILESAVEAS,
     111        self.Bind(wx.EVT_MENU, self.OnFileSave, id=item.GetId())
     112        item = parent.Append(
     113            help='Save project to new file', id=wx.ID_ANY,
    135114            kind=wx.ITEM_NORMAL,text='Save As...')
    136         parent.Append(help='Close project, saving is optional', id=wxID_FILECLOSE,
     115        self.Bind(wx.EVT_MENU, self.OnFileSaveas, id=item.GetId())
     116        item = parent.Append(
     117            help='Close project, saving is optional', id=wx.ID_ANY,
    137118            kind=wx.ITEM_NORMAL,text='Close project')
    138         parent.Append(help='Exit from gsasii', id=wxID_FILEEXIT, kind=wx.ITEM_NORMAL,
    139             text='Exit')
    140         self.Bind(wx.EVT_MENU, self.OnFileOpen, id=wxID_FILEOPEN)
    141         self.Bind(wx.EVT_MENU, self.OnFileSave, id=wxID_FILESAVE)
    142         self.Bind(wx.EVT_MENU, self.OnFileSaveas, id=wxID_FILESAVEAS)
    143         self.Bind(wx.EVT_MENU, self.OnFileClose, id=wxID_FILECLOSE)
    144         self.Bind(wx.EVT_MENU, self.OnFileExit, id=wxID_FILEEXIT)
    145        
    146     def _init_coll_Data_Items(self,parent):
    147         parent.Append(help='',id=wxID_IMGREAD, kind=wx.ITEM_NORMAL,
     119        self.Bind(wx.EVT_MENU, self.OnFileClose, id=item.GetId())
     120        item = parent.Append(
     121            help='Exit from gsasii', id=wx.ID_ANY,
     122            kind=wx.ITEM_NORMAL,text='Exit')
     123        self.Bind(wx.EVT_MENU, self.OnFileExit, id=item.GetId())
     124       
     125    def _Add_DataMenuItems(self,parent):
     126        item = parent.Append(
     127            help='',id=wx.ID_ANY,
     128            kind=wx.ITEM_NORMAL,
    148129            text='Read image data...')
    149         parent.Append(help='',id=wxID_READPEAKS, kind=wx.ITEM_NORMAL,
     130        self.Bind(wx.EVT_MENU, self.OnImageRead, id=item.GetId())
     131        item = parent.Append(
     132            help='',id=wx.ID_ANY,
     133            kind=wx.ITEM_NORMAL,
    150134            text='Read Powder Pattern Peaks...')
    151         parent.Append(help='', id=wxID_PWDSUM, kind=wx.ITEM_NORMAL,
     135        self.Bind(wx.EVT_MENU, self.OnReadPowderPeaks, id=item.GetId())
     136        item = parent.Append(
     137            help='',id=wx.ID_ANY,
     138            kind=wx.ITEM_NORMAL,
    152139            text='Sum powder data')
    153         parent.Append(help='',id=wxID_IMSUM, kind=wx.ITEM_NORMAL,
     140        self.Bind(wx.EVT_MENU, self.OnPwdrSum, id=item.GetId())
     141        item = parent.Append(
     142            help='',id=wx.ID_ANY,
     143            kind=wx.ITEM_NORMAL,
    154144            text='Sum image data')
    155         parent.Append(help='', id=wxID_ADDPHASE, kind=wx.ITEM_NORMAL,
     145        self.Bind(wx.EVT_MENU, self.OnImageSum, id=item.GetId())
     146        item = parent.Append(
     147            help='',id=wx.ID_ANY,
     148            kind=wx.ITEM_NORMAL,
    156149            text='Add phase')
    157         parent.Append(help='', id=wxID_DELETEPHASE, kind=wx.ITEM_NORMAL,
     150        self.Bind(wx.EVT_MENU, self.OnAddPhase, id=item.GetId())
     151        item = parent.Append(
     152            help='',id=wx.ID_ANY,
     153            kind=wx.ITEM_NORMAL,
    158154            text='Delete phase')
    159         parent.Append(help='', id=wxID_DATARENAME, kind=wx.ITEM_NORMAL,
     155        self.Bind(wx.EVT_MENU, self.OnDeletePhase, id=item.GetId())
     156        item = parent.Append(
     157            help='',id=wx.ID_ANY,
     158            kind=wx.ITEM_NORMAL,
    160159            text='Rename data')
    161         parent.Append(help='', id=wxID_DATADELETE, kind=wx.ITEM_NORMAL,
     160        self.Bind(wx.EVT_MENU, self.OnRenameData, id=item.GetId())
     161        item = parent.Append(
     162            help='',id=wx.ID_ANY,
     163            kind=wx.ITEM_NORMAL,
    162164            text='Delete data')
    163         self.Bind(wx.EVT_MENU, self.OnPwdrSum, id=wxID_PWDSUM)
    164         self.Bind(wx.EVT_MENU, self.OnReadPowderPeaks, id=wxID_READPEAKS)
    165         self.Bind(wx.EVT_MENU, self.OnImageRead, id=wxID_IMGREAD)
    166         self.Bind(wx.EVT_MENU, self.OnImageSum, id=wxID_IMSUM)
    167         self.Bind(wx.EVT_MENU, self.OnAddPhase, id=wxID_ADDPHASE)
    168         self.Bind(wx.EVT_MENU, self.OnDeletePhase, id=wxID_DELETEPHASE)
    169         self.Bind(wx.EVT_MENU, self.OnRenameData, id=wxID_DATARENAME)
    170         self.Bind(wx.EVT_MENU, self.OnDataDelete, id=wxID_DATADELETE)
     165        self.Bind(wx.EVT_MENU, self.OnDataDelete, id=item.GetId())
    171166               
    172     def _init_coll_Calculate_Items(self,parent):
    173         self.MakePDF = parent.Append(help='Make new PDFs from selected powder patterns',
    174             id=wxID_MAKEPDFS, kind=wx.ITEM_NORMAL,text='Make new PDFs')
    175         self.Bind(wx.EVT_MENU, self.OnMakePDFs, id=wxID_MAKEPDFS)
    176         self.ViewLSParms = parent.Append(help='View least squares parameters',
    177             id=wxID_VIEWLSPARMS, kind=wx.ITEM_NORMAL,text='View LS parms')
    178         self.Bind(wx.EVT_MENU, self.OnViewLSParms, id=wxID_VIEWLSPARMS)
    179         self.Refine = parent.Append(help='', id=wxID_REFINE, kind=wx.ITEM_NORMAL,
     167    def _Add_CalculateMenuItems(self,parent):
     168        item = parent.Append(help='Make new PDFs from selected powder patterns',
     169            id=wx.ID_ANY, kind=wx.ITEM_NORMAL,text='Make new PDFs')
     170        self.MakePDF.append(item)
     171        item.Enable(False)
     172        self.Bind(wx.EVT_MENU, self.OnMakePDFs, id=item.GetId())
     173       
     174        item = parent.Append(help='View least squares parameters',
     175            id=wx.ID_ANY, kind=wx.ITEM_NORMAL,text='View LS parms')
     176        self.Bind(wx.EVT_MENU, self.OnViewLSParms, id=item.GetId())
     177       
     178        item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
    180179            text='Refine')
    181         self.Refine.Enable(False)
    182         self.Bind(wx.EVT_MENU, self.OnRefine, id=wxID_REFINE)
    183         self.SeqRefine = parent.Append(help='', id=wxID_SEQREFINE, kind=wx.ITEM_NORMAL,
     180        self.Refine.append(item)
     181        item.Enable(False)
     182        self.Bind(wx.EVT_MENU, self.OnRefine, id=item.GetId())
     183       
     184        item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
    184185            text='Sequental refine')
    185         self.SeqRefine.Enable(False)
    186         self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=wxID_SEQREFINE)
    187        
    188     def _init_Import_routines(self,parent,prefix,readerlist,errprefix):
     186        self.SeqRefine.append(item)
     187        item.Enable(False)
     188        self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
     189       
     190    def _init_Imports(self):
     191        '''import all the G2phase*.py & G2sfact*.py & G2pwd*.py files that
     192        are found in the path
     193        '''
     194
     195        self.ImportPhaseReaderlist = []
     196        self._init_Import_routines('phase',self.ImportPhaseReaderlist,'Phase')
     197        self.ImportSfactReaderlist = []
     198        self._init_Import_routines('sfact',self.ImportSfactReaderlist,'Struct_Factor')
     199        self.ImportPowderReaderlist = []
     200        self._init_Import_routines('pwd',self.ImportPowderReaderlist,'Powder_Data')
     201        self.ImportMenuId = {}
     202
     203    def _init_Import_routines(self,prefix,readerlist,errprefix):
    189204        '''import all the import readers matching the prefix
    190205        '''
     
    401416        return rd_list
    402417
    403     def _init_Import_Phase(self,parent):
    404         '''import all the G2phase*.py files that are found in the
    405         path and configure the Import Phase menus accordingly
     418    def _Add_ImportMenu_Phase(self,parent):
     419        '''configure the Import Phase menus accord to the readers found in _init_Imports
    406420        '''
    407         self.ImportPhaseReaderlist = []
    408         self._init_Import_routines(parent,'phase',
    409                                    self.ImportPhaseReaderlist,
    410                                    'Phase')
    411421        submenu = wx.Menu()
    412422        item = parent.AppendMenu(wx.ID_ANY, 'Phase',
     
    455465        return # success
    456466       
    457     def _init_Import_Sfact(self,parent):
    458         '''import all the G2sfact*.py files that are found in the
    459         path and configure the Import Structure Factor menus accordingly
     467    def _Add_ImportMenu_Sfact(self,parent):
     468        '''configure the Import Structure Factor menus accord to the readers found in _init_Imports
    460469        '''
    461         self.ImportSfactReaderlist = []
    462         self._init_Import_routines(parent,'sfact',
    463                                    self.ImportSfactReaderlist,
    464                                    'Struct_Factor')
    465470        submenu = wx.Menu()
    466471        item = parent.AppendMenu(wx.ID_ANY, 'Structure Factor',
     
    511516        return # success
    512517
    513     def _init_Import_powder(self,parent):
    514         '''import all the G2pwd*.py files that are found in the
    515         path and configure the Import Powder Data menus accordingly
     518    def _Add_ImportMenu_powder(self,parent):
     519        '''configure the Powder Data menus accord to the readers found in _init_Imports
    516520        '''
    517         self.ImportPowderReaderlist = []
    518         self._init_Import_routines(parent,'pwd',self.ImportPowderReaderlist,
    519             'Powder_Data')
    520521        submenu = wx.Menu()
    521522        item = parent.AppendMenu(wx.ID_ANY, 'Powder Data',
     
    842843
    843844    def _init_Exports(self,parent):
    844         '''
     845        '''This is a place holder for when exports are handled in a manner similar to imports
    845846        '''
    846847#        submenu = wx.Menu()
     
    860861#        G2export.ProjExport(self)
    861862
    862     def _init_coll_Export_Items(self,parent):
    863         self.ExportPattern = parent.Append(help='Select PWDR item to enable',id=wxID_EXPORTPATTERN, kind=wx.ITEM_NORMAL,
     863    def _Add_ExportMenuItems(self,parent):
     864        item = parent.Append(
     865            help='Select PWDR item to enable',id=wx.ID_ANY,
     866            kind=wx.ITEM_NORMAL,
    864867            text='Export Powder Patterns...')
    865         self.ExportPeakList = parent.Append(help='',id=wxID_EXPORTPEAKLIST, kind=wx.ITEM_NORMAL,
     868        self.ExportPattern.append(item)
     869        item.Enable(False)
     870        self.Bind(wx.EVT_MENU, self.OnExportPatterns, id=item.GetId())
     871
     872        item = parent.Append(
     873            help='',id=wx.ID_ANY,
     874            kind=wx.ITEM_NORMAL,
    866875            text='Export All Peak Lists...')
    867         self.ExportHKL = parent.Append(help='',id=wxID_EXPORTHKL, kind=wx.ITEM_NORMAL,
     876        self.ExportPeakList.append(item)
     877        item.Enable(True)
     878        self.Bind(wx.EVT_MENU, self.OnExportPeakList, id=item.GetId())
     879
     880        item = parent.Append(
     881            help='',id=wx.ID_ANY,
     882            kind=wx.ITEM_NORMAL,
    868883            text='Export HKLs...')
    869         self.ExportPDF = parent.Append(help='Select PDF item to enable',id=wxID_EXPORTPDF, kind=wx.ITEM_NORMAL,
     884        self.ExportHKL.append(item)
     885        item.Enable(False)
     886        self.Bind(wx.EVT_MENU, self.OnExportHKL, id=item.GetId())
     887
     888        item = parent.Append(
     889            help='Select PDF item to enable',
     890            id=wx.ID_ANY,
     891            kind=wx.ITEM_NORMAL,
    870892            text='Export PDF...')
    871         self.ExportPhase = parent.Append(help='',id=wxID_EXPORTPHASE, kind=wx.ITEM_NORMAL,
     893        self.ExportPDF.append(item)
     894        item.Enable(False)
     895        self.Bind(wx.EVT_MENU, self.OnExportPDF, id=item.GetId())
     896
     897        item = parent.Append(
     898            help='',id=wx.ID_ANY,
     899            kind=wx.ITEM_NORMAL,
    872900            text='Export Phase...')
    873         self.ExportCIF = parent.Append(help='',id=wxID_EXPORTCIF, kind=wx.ITEM_NORMAL,
     901        self.ExportPhase.append(item)
     902        item.Enable(False)
     903        self.Bind(wx.EVT_MENU, self.OnExportPhase, id=item.GetId())
     904
     905        item = parent.Append(
     906            help='',id=wx.ID_ANY,
     907            kind=wx.ITEM_NORMAL,
    874908            text='Export CIF...')
    875         self.ExportPattern.Enable(False)
    876         self.ExportPeakList.Enable(True)
    877         self.ExportHKL.Enable(False)
    878         self.ExportPDF.Enable(False)
    879         self.ExportPhase.Enable(False)
    880         self.ExportCIF.Enable(False)
    881         self.Bind(wx.EVT_MENU, self.OnExportPatterns, id=wxID_EXPORTPATTERN)
    882         self.Bind(wx.EVT_MENU, self.OnExportPeakList, id=wxID_EXPORTPEAKLIST)
    883         self.Bind(wx.EVT_MENU, self.OnExportHKL, id=wxID_EXPORTHKL)
    884         self.Bind(wx.EVT_MENU, self.OnExportPDF, id=wxID_EXPORTPDF)
    885         self.Bind(wx.EVT_MENU, self.OnExportPhase, id=wxID_EXPORTPHASE)
    886         self.Bind(wx.EVT_MENU, self.OnExportCIF, id=wxID_EXPORTCIF)
     909        self.ExportCIF.append(item)
     910        item.Enable(False)
     911        self.Bind(wx.EVT_MENU, self.OnExportCIF, id=item.GetId())
    887912               
    888     def _init_utils(self):
    889         self.GSASIIMenu = wx.MenuBar()
    890         self.File = wx.Menu(title='')
    891         self.Data = wx.Menu(title='')       
    892         self.Calculate = wx.Menu(title='')       
    893         self.Import = wx.Menu(title='')       
    894         self.Export = wx.Menu(title='')       
    895 
    896         self._init_coll_GSASIIMenu_Menus(self.GSASIIMenu)
    897         self._init_coll_File_Items(self.File)
    898         self._init_coll_Data_Items(self.Data)
    899         self._init_coll_Calculate_Items(self.Calculate)
    900         self.ImportMenuId = {}
    901         self._init_Import_Phase(self.Import)
    902         self._init_Import_powder(self.Import)
    903         self._init_Import_Sfact(self.Import)
    904         self._init_coll_Export_Items(self.Export)
    905         self._init_Exports(self.Export)
    906        
     913    def FillMainMenu(self,menubar):
     914        '''Define contents of the main GSAS-II menu for the (main) data tree window
     915        in the mac, used also for the data item windows as well.
     916        '''
     917        File = wx.Menu(title='')
     918        menubar.Append(menu=File, title='File')
     919        self._Add_FileMenuItems(File)
     920        Data = wx.Menu(title='')
     921        menubar.Append(menu=Data, title='Data')
     922        self._Add_DataMenuItems(Data)
     923        Calculate = wx.Menu(title='')       
     924        menubar.Append(menu=Calculate, title='Calculate')
     925        self._Add_CalculateMenuItems(Calculate)
     926        Import = wx.Menu(title='')       
     927        menubar.Append(menu=Import, title='Import')
     928        self._Add_ImportMenu_Phase(Import)
     929        self._Add_ImportMenu_powder(Import)
     930        self._Add_ImportMenu_Sfact(Import)
     931        Export = wx.Menu(title='')       
     932        menubar.Append(menu=Export, title='Export')
     933        self._Add_ExportMenuItems(Export)
     934        #self._init_Exports(Export)
     935        HelpMenu=G2gd.MyHelp(self,helpType='Data tree',
     936            morehelpitems=[('&Tutorials','Tutorials')])
     937        menubar.Append(menu=HelpMenu,title='&Help')
     938
    907939    def _init_ctrls(self, parent):
    908940        wx.Frame.__init__(self, name='GSASII', parent=parent,
     
    912944        xPos = clientSize[2]-Size[0]
    913945        self.SetPosition(wx.Point(xPos,clientSize[1]))
    914         self._init_utils()
     946        self._init_Imports()
     947        #self._init_utils()
     948        #initialize Menu item objects (these contain lists of menu items that are enabled or disabled)
     949        self.MakePDF = []
     950        self.Refine = []
     951        self.SeqRefine = []
     952        self.ExportPattern = []
     953        self.ExportPeakList = []
     954        self.ExportHKL = []
     955        self.ExportPDF = []
     956        self.ExportPhase = []
     957        self.ExportCIF = []
     958        #
     959        self.GSASIIMenu = wx.MenuBar()
     960        self.FillMainMenu(self.GSASIIMenu)
    915961        self.SetMenuBar(self.GSASIIMenu)
    916962        self.Bind(wx.EVT_SIZE, self.OnSize)
     
    918964        self.mainPanel = wx.Panel(self,-1)
    919965       
     966        wxID_PATTERNTREE = wx.NewId()
    920967        self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE,
    921968            parent=self.mainPanel, pos=wx.Point(0, 0),style=wx.TR_DEFAULT_STYLE )
     
    9881035            G2IO.ProjFileOpen(self)
    9891036            self.PatternTree.Expand(self.root)
    990             self.Refine.Enable(True)
    991             self.SeqRefine.Enable(True)
     1037            for item in self.Refine: item.Enable(True)
     1038            for item in self.SeqRefine: item.Enable(True)
    9921039
    9931040    def OnSize(self,event):
     
    17281775                            data = self.PatternTree.GetItemPyData(item)
    17291776                            if data:
    1730                                 self.Refine.Enable(True)
    1731                                 self.SeqRefine.Enable(True)
     1777                                for item in self.Refine: item.Enable(True)
     1778                                for item in self.SeqRefine: item.Enable(True)
    17321779                        item, cookie = self.PatternTree.GetNextChild(self.root, cookie)               
    17331780                    if Id:
     
    19221969                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='F(Q)'+PWDRname),[])       
    19231970                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='G(R)'+PWDRname),[])       
    1924                 self.ExportPDF.Enable(True)
     1971                for item in self.ExportPDF: item.Enable(True)
    19251972            finally:
    19261973                dlg.Destroy()
Note: See TracChangeset for help on using the changeset viewer.