- Timestamp:
- Jul 23, 2016 8:40:14 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 29 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIctrls.py ¶
r2374 r2378 3835 3835 # empty directories (.../MT/* .../trunk/GSASII/* *=[help,Exercises]) 3836 3836 tutorialCatalog = ( 3837 # tutorial dir, exercise dir, web page file name, title for page 3838 3839 ['StartingGSASII', 'StartingGSASII', 'Starting GSAS.htm', 3840 'Starting GSAS-II'], 3837 # tutorial dir, web page file name, title for page 3838 3839 ['StartingGSASII', 'Starting GSAS.htm', 'Starting GSAS-II'], 3841 3840 3842 ['FitPeaks', 'FitPeaks', 'Fit Peaks.htm', 3843 'Fitting individual peaks & autoindexing'], 3844 ['BkgFit', 'BkgFit', 'FitBkgTut.htm', 3845 'Fitting the Starting Background using Fixed Points'], 3841 ['FitPeaks', 'Fit Peaks.htm', 'Fitting individual peaks & autoindexing'], 3842 ['BkgFit', 'FitBkgTut.htm', 'Fitting the Starting Background using Fixed Points'], 3846 3843 3847 ['CWNeutron', 'CWNeutron', 'Neutron CW Powder Data.htm', 3848 'CW Neutron Powder fit for Yttrium-Iron Garnet'], 3849 ['LabData', 'LabData', 'Laboratory X.htm', 3850 'Fitting laboratory X-ray powder data for fluoroapatite'], 3851 ['CWCombined', 'CWCombined', 'Combined refinement.htm', 3852 'Combined X-ray/CW-neutron refinement of PbSO4'], 3853 ['TOF-CW Joint Refinement', 'TOF-CW Joint Refinement', 'TOF combined XN Rietveld refinement in GSAS.htm', 3854 'Combined X-ray/TOF-neutron Rietveld refinement'], 3855 ['SeqRefine', 'SeqRefine', 'SequentialTutorial.htm', 3856 'Sequential refinement of multiple datasets'], 3857 ['SeqParametric', 'SeqParametric', 'ParametricFitting.htm', 3858 'Parametric Fitting and Pseudo Variables for Sequential Fits'], 3859 3860 ['StackingFaults-I', 'StackingFaults-I', 'Stacking Faults-I.htm', 3861 'Stacking fault simulations for diamond'], 3862 ['StackingFaults-II', 'StackingFaults-II', 'Stacking Faults II.htm', 3863 'Stacking fault simulations for Keokuk kaolinite'], 3864 ['StackingFaults-III', 'StackingFaults-III', 'Stacking Faults-III.htm', 3865 'Stacking fault simulations for Georgia kaolinite'], 3866 3867 ['CFXraySingleCrystal','CFXraySingleCrystal','CFSingleCrystal.htm', 3868 'Charge Flipping structure solution with Xray single crystal data'], 3869 ['CFjadarite', 'CFjadarite', 'Charge Flipping in GSAS.htm', 3870 'Charge Flipping structure solution for jadarite'], 3871 ['CFsucrose', 'CFsucrose', 'Charge Flipping - sucrose.htm', 3872 'Charge Flipping structure solution for sucrose'], 3873 ['TOF Charge Flipping', 'TOF Charge Flipping', 'Charge Flipping with TOF single crystal data in GSASII.htm', 3874 'Charge flipping with neutron TOF single crystal data'], 3875 ['MCsimanneal', 'MCsimanneal', 'MCSA in GSAS.htm', 3876 'Monte-Carlo simulated annealing structure'], 3877 3878 ['MerohedralTwins', 'MerohedralTwins','Merohedral twin refinement in GSAS.htm', 3879 'Merohedral twin refinements'], 3880 3881 ['2DCalibration', '2DCalibration', 'Calibration of an area detector in GSAS.htm', 3882 'Calibration of an area detector'], 3883 ['2DIntegration', '2DIntegration', 'Integration of area detector data in GSAS.htm', 3884 'Integration of area detector data'], 3885 ['TOF Calibration', 'TOF Calibration', 'Calibration of a TOF powder diffractometer.htm', 3886 'Calibration of a Neutron TOF diffractometer'], 3887 ['TOF Single Crystal Refinement', 'TOF Single Crystal Refinement', 'TOF single crystal refinement in GSAS.htm', 3888 'Single crystal refinement from TOF data'], 3844 ['CWNeutron', 'Neutron CW Powder Data.htm', 'CW Neutron Powder fit for Yttrium-Iron Garnet'], 3845 ['LabData', 'Laboratory X.htm', 'Fitting laboratory X-ray powder data for fluoroapatite'], 3846 ['CWCombined', 'Combined refinement.htm', 'Combined X-ray/CW-neutron refinement of PbSO4'], 3847 ['TOF-CW Joint Refinement', 'TOF combined XN Rietveld refinement in GSAS.htm', 'Combined X-ray/TOF-neutron Rietveld refinement'], 3848 ['SeqRefine', 'SequentialTutorial.htm', 'Sequential refinement of multiple datasets'], 3849 ['SeqParametric', 'ParametricFitting.htm', 'Parametric Fitting and Pseudo Variables for Sequential Fits'], 3850 3851 ['StackingFaults-I', 'Stacking Faults-I.htm', 'Stacking fault simulations for diamond'], 3852 ['StackingFaults-II', 'Stacking Faults II.htm', 'Stacking fault simulations for Keokuk kaolinite'], 3853 ['StackingFaults-III', 'Stacking Faults-III.htm', 'Stacking fault simulations for Georgia kaolinite'], 3854 3855 ['CFXraySingleCrystal', 'CFSingleCrystal.htm', 'Charge Flipping structure solution with Xray single crystal data'], 3856 ['CFjadarite', 'Charge Flipping in GSAS.htm', 'Charge Flipping structure solution for jadarite'], 3857 ['CFsucrose', 'Charge Flipping - sucrose.htm', 'Charge Flipping structure solution for sucrose'], 3858 ['TOF Charge Flipping', 'Charge Flipping with TOF single crystal data in GSASII.htm', 'Charge flipping with neutron TOF single crystal data'], 3859 ['MCsimanneal', 'MCSA in GSAS.htm', 'Monte-Carlo simulated annealing structure'], 3860 3861 ['MerohedralTwins', 'Merohedral twin refinement in GSAS.htm', 'Merohedral twin refinements'], 3862 3863 ['2DCalibration', 'Calibration of an area detector in GSAS.htm', 'Calibration of an area detector'], 3864 ['2DIntegration', 'Integration of area detector data in GSAS.htm', 'Integration of area detector data'], 3865 ['TOF Calibration', 'Calibration of a TOF powder diffractometer.htm', 'Calibration of a Neutron TOF diffractometer'], 3866 ['TOF Single Crystal Refinement', 'TOF single crystal refinement in GSAS.htm', 'Single crystal refinement from TOF data'], 3889 3867 3890 ['2DStrain', '2DStrain', 'Strain fitting of 2D data in GSAS-II.htm', 3891 'Strain fitting of 2D data'], 3892 ['2DTexture', '2DTexture', 'Texture analysis of 2D data in GSAS-II.htm', 3893 'Texture analysis of 2D data'], 3868 ['2DStrain', 'Strain fitting of 2D data in GSAS-II.htm', 'Strain fitting of 2D data'], 3869 ['2DTexture', 'Texture analysis of 2D data in GSAS-II.htm', 'Texture analysis of 2D data'], 3894 3870 3895 ['SAimages', 'SAimages', 'Small Angle Image Processing.htm', 3896 'Image Processing of small angle x-ray data'], 3897 ['SAfit', 'SAfit', 'Fitting Small Angle Scattering Data.htm', 3898 'Fitting small angle x-ray data (alumina powder)'], 3899 ['SAsize', 'SAsize', 'Small Angle Size Distribution.htm', 3900 'Small angle x-ray data size distribution (alumina powder)'], 3901 ['SAseqref', 'SAseqref', 'Sequential Refinement of Small Angle Scattering Data.htm', 3902 'Sequential refinement with small angle scattering data'], 3871 ['SAimages', 'Small Angle Image Processing.htm', 'Image Processing of small angle x-ray data'], 3872 ['SAfit', 'Fitting Small Angle Scattering Data.htm', 'Fitting small angle x-ray data (alumina powder)'], 3873 ['SAsize', 'Small Angle Size Distribution.htm', 'Small angle x-ray data size distribution (alumina powder)'], 3874 ['SAseqref', 'Sequential Refinement of Small Angle Scattering Data.htm', 'Sequential refinement with small angle scattering data'], 3903 3875 3904 #[' TOF Sequential Single Peak Fit', 'TOF Sequential Single Peak Fit', '', ''],3876 #['ExampleDir', 'ExamplePage.html', 'Example Tutorial Title'], 3905 3877 ) 3878 # Get the tutorial location if set; if not pick a default directory in a logical place 3906 3879 if GSASIIpath.GetConfigValue('Tutorial_location'): 3907 3880 tutorialPath = os.path.abspath(GSASIIpath.GetConfigValue('Tutorial_location')) 3881 elif sys.platform.lower().startswith('win') and os.path.exists(os.path.abspath(os.path.expanduser('~/My Documents'))): 3882 tutorialPath = os.path.abspath(os.path.expanduser('~/My Documents/G2tutorials')) 3883 elif sys.platform.lower().startswith('win') and os.path.exists(os.path.abspath(os.path.expanduser('~/Documents'))): 3884 tutorialPath = os.path.abspath(os.path.expanduser('~/Documents/G2tutorials')) 3908 3885 else: 3909 # pick a default directory in a logical place 3910 if sys.platform.lower().startswith('win') and os.path.exists(os.path.abspath(os.path.expanduser('~/My Documents'))): 3911 tutorialPath = os.path.abspath(os.path.expanduser('~/My Documents/G2tutorials')) 3912 else: 3913 tutorialPath = os.path.abspath(os.path.expanduser('~/G2tutorials')) 3886 tutorialPath = os.path.abspath(os.path.expanduser('~/G2tutorials')) 3914 3887 3915 3888 class OpenTutorial(wx.Dialog): … … 3921 3894 who don't have write access to the GSAS-II source code location. 3922 3895 ''' 3923 # TODO: set default input-file open location to the download location3896 3924 3897 def __init__(self,parent=None): 3925 3898 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER … … 3933 3906 'Select the tutorial to be run and the mode of access' 3934 3907 ) 3935 msg = '''To save download time for GSAS-II tutorials and their 3936 sample data files are being moved out of the standard 3937 distribution. This dialog allows users to load selected 3938 tutorials to their computer. 3939 3940 Tutorials can be viewed over the internet or downloaded 3941 to this computer. The sample data can be downloaded or not, 3942 (but it is not possible to run the tutorial without the 3943 data). If no web access is available, tutorials that were 3944 previously downloaded can be viewed. 3945 3946 By default, files are downloaded into the location used 3947 for the GSAS-II distribution, but this may not be possible 3948 if the software is installed by a administrator. The 3949 download location can be changed using the "Set data 3950 location" or the "Tutorial_location" configuration option 3951 (see config_example.py). 3908 msg = '''GSAS-II tutorials and their sample data files 3909 require a fair amount of storage space; few users will 3910 use all of them. This dialog allows users to load selected 3911 tutorials (along with their sample data) to their computer; 3912 optionally all tutorials can be downloaded. 3913 3914 Downloaded tutorials can be viewed and run without internet 3915 access. Tutorials can also be viewed without download, but 3916 users will need to download the sample data files manually. 3917 3918 The location used to download tutorials is set using the 3919 "Set download location" which is saved as the "Tutorial_location" 3920 configuration option see File/Preference or the 3921 config_example.py file. System managers can select to have 3922 tutorial files installed at a shared location. 3952 3923 ''' 3953 3924 hlp = HelpButton(pnl,msg) … … 3958 3929 sizer.Add(sizer1,0,wx.EXPAND|wx.ALL,0) 3959 3930 sizer.Add((10,10)) 3960 self.BrowseMode = 1 3961 choices = [ 3962 'make local copy of tutorial and data, then open', 3963 'run from web (copy data locally)', 3964 'browse on web (data not loaded)', 3965 'open from local tutorial copy', 3966 ] 3967 self.mode = wx.RadioBox(pnl,wx.ID_ANY,'access mode:', 3968 wx.DefaultPosition, wx.DefaultSize, 3969 choices, 1, wx.RA_SPECIFY_COLS) 3970 self.mode.SetSelection(self.BrowseMode) 3971 self.mode.Bind(wx.EVT_RADIOBOX, self.OnModeSelect) 3972 sizer.Add(self.mode,0,WACV) 3973 sizer.Add((10,10)) 3974 label = wx.StaticText(pnl, wx.ID_ANY,'Click on tutorial to be opened:') 3975 sizer.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 2) 3976 self.listbox = wx.ListBox(pnl, wx.ID_ANY, size=(450, 100), style=wx.LB_SINGLE) 3977 self.listbox.Bind(wx.EVT_LISTBOX, self.OnTutorialSelected) 3978 sizer.Add(self.listbox,1,WACV|wx.EXPAND|wx.ALL,1) 3931 sizer0 = wx.BoxSizer(wx.HORIZONTAL) 3932 sizer1a = wx.BoxSizer(wx.VERTICAL) 3933 sizer1b = wx.BoxSizer(wx.VERTICAL) 3934 btn = wx.Button(pnl, wx.ID_ANY, "Download a tutorial and view") 3935 btn.Bind(wx.EVT_BUTTON, self.SelectAndDownload) 3936 sizer1a.Add(btn,0,WACV) 3937 btn = wx.Button(pnl, wx.ID_ANY, "Select from downloaded tutorials") 3938 btn.Bind(wx.EVT_BUTTON, self.onSelectDownloaded) 3939 sizer1a.Add(btn,0,WACV) 3940 btn = wx.Button(pnl, wx.ID_ANY, "Browse tutorial on web") 3941 btn.Bind(wx.EVT_BUTTON, self.onWebBrowse) 3942 sizer1a.Add(btn,0,WACV) 3943 btn = wx.Button(pnl, wx.ID_ANY, "Update downloaded tutorials") 3944 btn.Bind(wx.EVT_BUTTON, self.UpdateDownloaded) 3945 sizer1b.Add(btn,0,WACV) 3946 btn = wx.Button(pnl, wx.ID_ANY, "Download all tutorials") 3947 btn.Bind(wx.EVT_BUTTON, self.DownloadAll) 3948 sizer1b.Add(btn,0,WACV) 3949 sizer0.Add(sizer1a,0,wx.EXPAND|wx.ALL,0) 3950 sizer0.Add(sizer1b,0,wx.EXPAND|wx.ALL,0) 3951 sizer.Add(sizer0,5,wx.EXPAND|wx.ALL,5) 3952 3979 3953 sizer.Add((10,10)) 3980 3954 sizer1 = wx.BoxSizer(wx.HORIZONTAL) … … 3985 3959 sizer1.Add(self.dataLoc,0,WACV) 3986 3960 sizer.Add(sizer1) 3987 label = wx.StaticText(3988 pnl, wx.ID_ANY,3989 'Tutorials and Exercise files will be downloaded to:'3990 )3991 sizer.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 1)3992 self.TutorialLabel = wx.StaticText(pnl,wx.ID_ANY,'')3993 sizer.Add(self.TutorialLabel, 0, wx.ALIGN_LEFT|wx.EXPAND, 5)3994 self.ExerciseLabel = wx.StaticText(pnl,wx.ID_ANY,'')3995 sizer.Add(self.ExerciseLabel, 0, wx.ALIGN_LEFT|wx.EXPAND, 5)3996 self.ShowTutorialPath()3997 self.OnModeSelect(None)3998 3961 3999 3962 btnsizer = wx.StdDialogButtonSizer() … … 4006 3969 self.topsizer=sizer 4007 3970 self.CenterOnParent() 4008 # def OpenOld(self,event): 4009 # '''Open old tutorials. This is needed only until we get all the tutorials items moved 4010 # ''' 4011 # self.EndModal(wx.ID_OK) 4012 # ShowHelp('Tutorials',self.frame) 4013 def OnModeSelect(self,event): 4014 '''Respond when the mode is changed 3971 3972 def SelectAndDownload(self,event): 3973 '''Make a list of all tutorials on web and allow user to choose one to 3974 download and then view 4015 3975 ''' 4016 self.BrowseMode = self.mode.GetSelection() 4017 if self.BrowseMode == 3: 4018 import glob 4019 filelist = glob.glob(os.path.join(tutorialPath,'help','*','*.htm')) 4020 taillist = [os.path.split(f)[1] for f in filelist] 4021 itemlist = [tut[-1] for tut in tutorialCatalog if tut[2] in taillist] 4022 else: 4023 itemlist = [tut[-1] for tut in tutorialCatalog if tut[-1]] 4024 self.listbox.Clear() 4025 self.listbox.AppendItems(itemlist) 4026 def OnTutorialSelected(self,event): 4027 '''Respond when a tutorial is selected. Load tutorials and data locally, 4028 as needed and then display the page 3976 indices = [j for j,i in enumerate(tutorialCatalog) 3977 if not os.path.exists(os.path.join(tutorialPath,i[0],i[1]))] 3978 if not indices: 3979 G2MessageBox(self,'All tutorials are downloaded','None to download') 3980 return 3981 choices = [tutorialCatalog[i][2] for i in indices] 3982 print len(tutorialCatalog),len(choices) 3983 selected = self.ChooseTutorial(choices) 3984 if selected is None: return 3985 j = indices[selected] 3986 fullpath = os.path.join(tutorialPath,tutorialCatalog[j][0],tutorialCatalog[j][1]) 3987 fulldir = os.path.join(tutorialPath,tutorialCatalog[j][0]) 3988 URL = G2BaseURL+'/Tutorials/'+tutorialCatalog[j][0]+'/' 3989 if GSASIIpath.svnInstallDir(URL,fulldir): 3990 ShowWebPage(fullpath,self.frame) 3991 else: 3992 G2MessageBox(self,'Error downloading tutorial','Download error') 3993 self.EndModal(wx.ID_OK) 3994 3995 def onSelectDownloaded(self,event): 3996 '''Select a previously downloaded tutorial 4029 3997 ''' 4030 for tutdir,exedir,htmlname,title in tutorialCatalog: 4031 if title == event.GetString(): break 4032 else: 4033 raise Exception("Match to file not found") 4034 if self.BrowseMode == 0 or self.BrowseMode == 1: 4035 try: 4036 self.ValidateTutorialDir(tutorialPath,G2BaseURL) 4037 except: 4038 G2MessageBox(self.frame, 4039 '''The selected directory is not valid. 4040 4041 You must use a directory that you have write access 4042 to. You can reuse a directory previously used for 4043 downloads, but the help and Tutorials subdirectories 4044 must be created by this routine. 4045 ''') 4046 return 4047 #self.dataLoc.SetLabel(tutorialPath) 3998 indices = [j for j,i in enumerate(tutorialCatalog) 3999 if os.path.exists(os.path.join(tutorialPath,i[0],i[1]))] 4000 if not indices: 4001 G2MessageBox(self,'There are no downloaded tutorials','None downloaded') 4002 return 4003 choices = [tutorialCatalog[i][2] for i in indices] 4004 selected = self.ChooseTutorial(choices) 4005 if selected is None: return 4006 j = indices[selected] 4007 fullpath = os.path.join(tutorialPath,tutorialCatalog[j][0],tutorialCatalog[j][1]) 4048 4008 self.EndModal(wx.ID_OK) 4049 wx.BeginBusyCursor() 4050 if self.BrowseMode == 0: 4051 # xfer data & web page locally, then open web page 4052 self.LoadTutorial(tutdir,tutorialPath,G2BaseURL) 4053 self.LoadExercise(exedir,tutorialPath,G2BaseURL) 4054 URL = os.path.join(tutorialPath,'help',tutdir,htmlname) 4055 self.frame.TutorialImportDir = os.path.join(tutorialPath,'Exercises',exedir) 4056 ShowWebPage(URL,self.frame) 4057 elif self.BrowseMode == 1: 4058 # xfer data locally, open web page remotely 4059 self.LoadExercise(exedir,tutorialPath,G2BaseURL) 4060 URL = os.path.join(G2BaseURL,'Tutorials',tutdir,htmlname) 4061 self.frame.TutorialImportDir = os.path.join(tutorialPath,'Exercises',exedir) 4062 ShowWebPage(URL,self.frame) 4063 elif self.BrowseMode == 2: 4064 # open web page remotely, don't worry about data 4065 URL = os.path.join(G2BaseURL,'Tutorials',tutdir,htmlname) 4066 ShowWebPage(URL,self.frame) 4067 elif self.BrowseMode == 3: 4068 # open web page that has already been transferred 4069 URL = os.path.join(tutorialPath,'help',tutdir,htmlname) 4070 self.frame.TutorialImportDir = os.path.join(tutorialPath,'Exercises',exedir) 4071 ShowWebPage(URL,self.frame) 4072 else: 4073 wx.EndBusyCursor() 4074 raise Exception("How did this happen!") 4075 wx.EndBusyCursor() 4076 def ShowTutorialPath(self): 4077 'Show the help and exercise directory names' 4078 self.TutorialLabel.SetLabel('\t'+ 4079 os.path.join(tutorialPath,"help") + 4080 ' (tutorials)') 4081 self.ExerciseLabel.SetLabel('\t'+ 4082 os.path.join(tutorialPath,"Exercises") + 4083 ' (exercises)') 4084 def ValidateTutorialDir(self,fullpath=tutorialPath,baseURL=G2BaseURL): 4085 '''Load help to new directory or make sure existing directory looks correctly set up 4086 throws an exception if there is a problem. 4009 ShowWebPage(fullpath,self.frame) 4010 4011 def onWebBrowse(self,event): 4012 '''Make a list of all tutorials on web and allow user to view one. 4087 4013 ''' 4088 wx.BeginBusyCursor() 4089 wx.Yield() 4090 if os.path.exists(fullpath): 4091 if os.path.exists(os.path.join(fullpath,"help")): 4092 if not GSASIIpath.svnGetRev(os.path.join(fullpath,"help")): 4093 print("Problem with "+fullpath+" dir help exists but is not in SVN") 4094 wx.EndBusyCursor() 4095 raise Exception 4096 if os.path.exists(os.path.join(fullpath,"Exercises")): 4097 if not GSASIIpath.svnGetRev(os.path.join(fullpath,"Exercises")): 4098 print("Problem with "+fullpath+" dir Exercises exists but is not in SVN") 4099 wx.EndBusyCursor() 4100 raise Exception 4101 if (os.path.exists(os.path.join(fullpath,"help")) and 4102 os.path.exists(os.path.join(fullpath,"Exercises"))): 4103 if self.BrowseMode != 3: 4104 print('Checking for directory updates') 4105 GSASIIpath.svnUpdateDir(os.path.join(fullpath,"help")) 4106 GSASIIpath.svnUpdateDir(os.path.join(fullpath,"Exercises")) 4107 wx.EndBusyCursor() 4108 return True # both good 4109 elif (os.path.exists(os.path.join(fullpath,"help")) or 4110 os.path.exists(os.path.join(fullpath,"Exercises"))): 4111 print("Problem: dir "+fullpath+" exists has either help or Exercises, not both") 4112 wx.EndBusyCursor() 4113 raise Exception 4114 if not GSASIIpath.svnInstallDir(baseURL+"/MT",fullpath): #this could load specific requested tutorial directory 4115 wx.EndBusyCursor() 4116 print("Problem transferring empty directory from web") 4117 raise Exception 4118 wx.EndBusyCursor() 4119 return True 4120 4121 def LoadTutorial(self,tutorialname,fullpath=tutorialPath,baseURL=G2BaseURL): 4122 'Load a Tutorial to the selected location' 4123 if GSASIIpath.svnSwitchDir("help",tutorialname,baseURL+"/Tutorials",fullpath): 4124 return True 4125 print("Problem transferring Tutorial from web") 4126 raise Exception 4127 4128 def LoadExercise(self,tutorialname,fullpath=tutorialPath,baseURL=G2BaseURL): 4129 'Load Exercise file(s) for a Tutorial to the selected location' 4130 if GSASIIpath.svnSwitchDir("Exercises",tutorialname,baseURL+"/Exercises",fullpath): 4131 return True 4132 print ("Problem transferring Exercise from web") 4133 raise Exception 4134 4014 choices = [i[2] for i in tutorialCatalog] 4015 selected = self.ChooseTutorial(choices) 4016 if selected is None: return 4017 tutdir = tutorialCatalog[selected][0] 4018 tutfil = tutorialCatalog[selected][1] 4019 # open web page remotely, don't worry about data 4020 URL = G2BaseURL+'/Tutorials/'+tutdir+'/'+tutfil 4021 self.EndModal(wx.ID_OK) 4022 ShowWebPage(URL,self.frame) 4023 4024 def ChooseTutorial(self,choices): 4025 'choose a tutorial from a list' 4026 def onDoubleClick(event): 4027 'double-click closes the dialog' 4028 dlg.EndModal(wx.ID_OK) 4029 dlg = wx.Dialog(self,wx.ID_ANY, 4030 'Select a tutorial to view', 4031 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) 4032 pnl = wx.Panel(dlg) 4033 sizer = wx.BoxSizer(wx.VERTICAL) 4034 listbox = wx.ListBox(pnl, wx.ID_ANY, choices=choices, 4035 size=(450, 100), 4036 style=wx.LB_SINGLE) 4037 sizer.Add(listbox,1,WACV|wx.EXPAND|wx.ALL,1) 4038 listbox.Bind(wx.EVT_LISTBOX_DCLICK, onDoubleClick) 4039 sizer.Add((10,10)) 4040 btnsizer = wx.StdDialogButtonSizer() 4041 btn = wx.Button(pnl, wx.ID_CANCEL) 4042 btnsizer.AddButton(btn) 4043 OKbtn = wx.Button(pnl, wx.ID_OK) 4044 OKbtn.SetDefault() 4045 btnsizer.AddButton(OKbtn) 4046 btnsizer.Realize() 4047 sizer.Add((-1,5)) 4048 sizer.Add(btnsizer,0,wx.ALIGN_RIGHT,50) 4049 4050 pnl.SetSizer(sizer) 4051 sizer.Fit(dlg) 4052 self.CenterOnParent() 4053 if dlg.ShowModal() != wx.ID_OK: 4054 dlg.Destroy() 4055 return 4056 selected = listbox.GetSelection() 4057 dlg.Destroy() 4058 if selected < 0: return 4059 return selected 4060 4061 def UpdateDownloaded(self,event): 4062 'Find the downloaded tutorials and run an svn update on them' 4063 updated = 0 4064 for i in tutorialCatalog: 4065 if not os.path.exists(os.path.join(tutorialPath,i[0],i[1])): continue 4066 print('Updating '+i[0]) 4067 GSASIIpath.svnUpdateDir(os.path.join(tutorialPath,i[0])) 4068 updated += 0 4069 if not updated: 4070 G2MessageBox(self,'Warning, you have no downloaded tutorials','None Downloaded') 4071 self.EndModal(wx.ID_OK) 4072 4073 def DownloadAll(self,event): 4074 'Download or update all tutorials' 4075 fail = '' 4076 for i in tutorialCatalog: 4077 if os.path.exists(os.path.join(tutorialPath,i[0],i[1])): 4078 print('Updating '+i[0]) 4079 GSASIIpath.svnUpdateDir(os.path.join(tutorialPath,i[0])) 4080 else: 4081 fullpath = os.path.join(tutorialPath,i[0],i[1]) 4082 fulldir = os.path.join(tutorialPath,i[0]) 4083 URL = G2BaseURL+'/Tutorials/'+i[0]+'/' 4084 if not GSASIIpath.svnInstallDir(URL,fulldir): 4085 if fail: fail += ', ' 4086 fail += i[0] 4087 if fail: 4088 G2MessageBox(self,'Error downloading tutorial(s)\n\t'+fail,'Download error') 4089 self.EndModal(wx.ID_OK) 4090 4135 4091 def SelectDownloadLoc(self,event): 4136 4092 '''Select a download location, … … 4138 4094 ''' 4139 4095 global tutorialPath 4140 dlg = wx.DirDialog(self, "Choose a directory for downloads:",4096 dlg = wx.DirDialog(self, "Choose a directory for tutorial downloads:", 4141 4097 defaultPath=tutorialPath)#,style=wx.DD_DEFAULT_STYLE) 4142 4098 #) … … 4157 4113 G2MessageBox(self.frame,msg) 4158 4114 return 4115 if os.path.exists(os.path.join(pth,"help")) and os.path.exists(os.path.join(pth,"Exercises")): 4116 print("Note that you may have old tutorial files in the following directories") 4117 print('\t'+os.path.join(pth,"help")) 4118 print('\t'+os.path.join(pth,"Exercises")) 4119 print('Subdirectories in the above can be deleted to save space\n\n') 4120 tutorialPath = pth 4121 self.dataLoc.SetLabel(tutorialPath) 4122 if GSASIIpath.GetConfigValue('Tutorial_location') == pth: return 4123 vars = GetConfigValsDocs() 4159 4124 try: 4160 self.ValidateTutorialDir(pth,G2BaseURL) 4161 tutorialPath = pth 4162 except: 4163 G2MessageBox(self.frame, 4164 '''Error downloading to the selected directory 4165 4166 Are you connected to the internet? If not, you can 4167 only view previously downloaded tutorials (select 4168 "open from local...") 4125 vars['Tutorial_location'][1] = pth 4126 if GSASIIpath.GetConfigValue('debug'): print('Saving Tutorial_location: '+pth) 4127 SaveConfigVars(vars) 4128 except KeyError: 4129 pass 4169 4130 4170 You must use a directory that you have write access4171 to. You can reuse a directory previously used for4172 downloads, but the help and Tutorials subdirectories4173 must have been created by this routine.4174 ''')4175 self.dataLoc.SetLabel(tutorialPath)4176 self.ShowTutorialPath()4177 self.OnModeSelect(None)4178 4179 4131 if __name__ == '__main__': 4180 4132 app = wx.PySimpleApp() … … 4182 4134 frm = wx.Frame(None) # create a frame 4183 4135 frm.Show(True) 4184 #dlg = OpenTutorial(frm)4185 #if dlg.ShowModal() == wx.ID_OK:4186 # print "OK"4187 #else:4188 # print "Cancel"4189 #dlg.Destroy()4190 #import sys4191 #sys.exit()4136 4137 dlg = OpenTutorial(frm) 4138 if dlg.ShowModal() == wx.ID_OK: 4139 print "OK" 4140 else: 4141 print "Cancel" 4142 dlg.Destroy() 4143 import sys; sys.exit() 4192 4144 #====================================================================== 4193 4145 # test ScrolledMultiEditor -
TabularUnified trunk/GSASIIpath.py ¶
r2347 r2378 392 392 def svnSwitchDir(rpath,filename,baseURL,loadpath=None): 393 393 '''This performs a switch command to move files between subversion trees. 394 395 This is currently used for moving tutorial web pages and demo files396 into the GSAS-II source tree. Note that if the files were previously downloaded397 the switch command will update the files to the newest version.394 Note that if the files were previously downloaded, 395 the switch command will update the files to the newest version. 396 397 This routine is no longer used. 398 398 399 399 :param str rpath: path to locate files, relative to the GSAS-II … … 433 433 '''Load a subversion tree into a specified directory 434 434 435 :param str rpath: path to locate files, relative to the GSAS-II436 installation path (defaults to path2GSAS2)437 435 :param str URL: the repository URL 436 :param str loadpath: path to locate files 437 438 438 ''' 439 439 import subprocess
Note: See TracChangeset
for help on using the changeset viewer.