Changeset 3352
- Timestamp:
- Apr 19, 2018 11:24:13 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIctrlGUI.py
r3345 r3352 54 54 :class:`MultiIntegerDialog` Dialog to obtain multiple integer values from user, 55 55 with a description for each value and optional 56 defaults. 56 defaults. 57 :class:`MultiColumnSelection` A dialog that builds a multicolumn table, word wrapping 58 is used for the 2nd, 3rd,... columns. 57 59 :class:`G2ColumnIDDialog` A dialog for matching column data to desired items; some 58 60 columns may be ignored. … … 2807 2809 self.EndModal(wx.ID_CANCEL) 2808 2810 2811 ################################################################################ 2812 class MultiColumnSelection(wx.Dialog): 2813 '''Defines a Dialog widget that can be used to select an item from a multicolumn list. 2814 The first column should be short, but remaining columns are word-wrapped if the 2815 length of the information extends beyond the column. 2816 2817 When created, the dialog will be shown and <dlg>.Selection will be set to the index 2818 of the selected row, or -1. Be sure to use <dlg>.Destroy() to remove the window 2819 after reading the selection. If the dialog cannot be shown because a very old 2820 version of wxPython is in use, <dlg>.Selection will be None. 2821 2822 :param wx.Frame parent: the parent frame (or None) 2823 :param str title: A title for the dialog window 2824 :param list colLabels: labels for each column 2825 :param list choices: a nested list with a value for each row in the table. Within each value 2826 should be a list of values for each column. There must be at least one value, but it is 2827 OK to have more or fewer values than there are column labels (colLabels). Extra are ignored 2828 and unspecified columns are left blank. 2829 :param list colWidths: a list of int values specifying the column width for each 2830 column in the table (pixels). There must be a value for every column label (colLabels). 2831 :param int height: an optional height (pixels) for the table (defaults to 400) 2832 2833 Example use:: 2834 lbls = ('col 1','col 2','col 3') 2835 choices=(['test1','explanation of test 1'], 2836 ['b', 'a really really long line that will be word-wrapped'], 2837 ['test3','more explanation text','optional 3rd column text']) 2838 colWidths=[200,400,100] 2839 dlg = MultiColumnSelection(frm,'select tutorial',lbls,choices,colWidths) 2840 value = choices[dlg.Selection][0] 2841 dlg.Destroy() 2842 2843 ''' 2844 def __init__(self, parent, title, colLabels, choices, colWidths, height=400, *args, **kw): 2845 if len(colLabels) != len(colWidths): 2846 raise ValueError('Length of colLabels) != colWidths') 2847 sizex = 20 # extra room for borders, etc. 2848 for i in colWidths: sizex += i 2849 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, *args, 2850 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, 2851 size=(sizex,height), **kw) 2852 try: 2853 from wx.lib.wordwrap import wordwrap 2854 import wx.lib.agw.ultimatelistctrl as ULC 2855 except ImportError: 2856 self.Selection = None 2857 return 2858 mainSizer = wx.BoxSizer(wx.VERTICAL) 2859 self.list = ULC.UltimateListCtrl(self, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT 2860 |ULC.ULC_HRULES|ULC.ULC_SINGLE_SEL) 2861 for i,(lbl,wid) in enumerate(zip(colLabels, colWidths)): 2862 self.list.InsertColumn(i, lbl, width=wid) 2863 for i,item in enumerate(choices): 2864 self.list.InsertStringItem(i, item[0]) 2865 for j,item in enumerate(item[1:len(colLabels)]): 2866 item = wordwrap(StripIndents(item,True), colWidths[j+1], wx.ClientDC(self)) 2867 self.list.SetStringItem(i,1+j, item) 2868 # make buttons 2869 mainSizer.Add(self.list, 1, wx.EXPAND|wx.ALL, 1) 2870 btnsizer = wx.BoxSizer(wx.HORIZONTAL) 2871 OKbtn = wx.Button(self, wx.ID_OK) 2872 OKbtn.SetDefault() 2873 btnsizer.Add(OKbtn) 2874 btn = wx.Button(self, wx.ID_CLOSE,"Cancel") 2875 btnsizer.Add(btn) 2876 mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5) 2877 # bindings for close of window, double-click,... 2878 OKbtn.Bind(wx.EVT_BUTTON,self._onSelect) 2879 btn.Bind(wx.EVT_BUTTON,self._onClose) 2880 self.Bind(wx.EVT_CLOSE, self._onClose) 2881 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._onSelect) 2882 self.SetSizer(mainSizer) 2883 self.Selection = -1 2884 self.ShowModal() 2885 def _onClose(self,event): 2886 event.Skip() 2887 self.EndModal(wx.ID_CANCEL) 2888 def _onSelect(self,event): 2889 if self.list.GetNextSelected(-1) == -1: return 2890 self.Selection = self.list.GetNextSelected(-1) 2891 self.EndModal(wx.ID_OK) 2892 2809 2893 ################################################################################ 2810 2894 class OrderBox(wxscroll.ScrolledPanel): … … 4185 4269 4186 4270 ################################################################################ 4187 def StripIndents(msg ):4271 def StripIndents(msg,singleLine=False): 4188 4272 'Strip indentation from multiline strings' 4189 4273 msg1 = msg.replace('\n ','\n') … … 4191 4275 msg = msg1 4192 4276 msg1 = msg.replace('\n ','\n') 4193 return msg.replace('\n\t','\n') 4277 msg = msg.replace('\n\t','\n') 4278 if singleLine: 4279 return msg.replace('\n',' ') 4280 return msg 4194 4281 4195 4282 def StripUnicode(string,subs='.'): … … 4705 4792 G2BaseURL = "https://subversion.xray.aps.anl.gov/pyGSAS" 4706 4793 tutorialIndex = ( 4707 # tutorial dir, web page file name, title for page 4794 # tutorial dir, web page file name, title for page, description 4708 4795 ['Getting started'], 4709 4796 ['StartingGSASII', 'Starting GSAS.htm', 'Starting GSAS-II'], … … 4880 4967 choices = [tutorialCatalog[i][2] for i in indices] 4881 4968 selected = self.ChooseTutorial(choices) 4969 #choices2 = [tutorialCatalog[i][2:4] for i in indices] 4970 #selected = self.ChooseTutorial2(choices2) 4882 4971 if selected is None: return 4883 4972 j = indices[selected] … … 4904 4993 choices = [tutorialCatalog[i][2] for i in indices] 4905 4994 selected = self.ChooseTutorial(choices) 4995 #choices2 = [tutorialCatalog[i][2:4] for i in indices] 4996 #selected = self.ChooseTutorial2(choices2) 4906 4997 if selected is None: return 4907 4998 j = indices[selected] … … 4916 5007 choices = [i[2] for i in tutorialCatalog] 4917 5008 selected = self.ChooseTutorial(choices) 5009 #choices2 = [i[2:4] for i in tutorialCatalog] 5010 #selected = self.ChooseTutorial2(choices2) 4918 5011 if selected is None: return 4919 5012 tutdir = tutorialCatalog[selected][0] … … 4924 5017 ShowWebPage(URL,self.frame) 4925 5018 5019 def ChooseTutorial2(self,choices): 5020 '''Select tutorials from a two-column table, when possible 5021 ''' 5022 lbls = ('tutorial name','description') 5023 colWidths=[400,400] 5024 dlg = MultiColumnSelection(self,'select tutorial',lbls,choices,colWidths) 5025 selection = dlg.Selection 5026 dlg.Destroy() 5027 if selection is not None: # wx from EPD Python 5028 if selection == -1: return 5029 return selection 5030 else: 5031 return self.ChooseTutorial([i[0] for i in choices]) 5032 4926 5033 def ChooseTutorial(self,choices): 4927 'choose a tutorial from a list' 5034 '''choose a tutorial from a list 5035 (will eventually only be used with very old wxPython 5036 ''' 4928 5037 def onDoubleClick(event): 4929 5038 'double-click closes the dialog' … … 5056 5165 # test Tutorial access 5057 5166 #====================================================================== 5058 #dlg = OpenTutorial(frm)5059 #if dlg.ShowModal() == wx.ID_OK:5060 #print("OK")5061 #else:5062 #print("Cancel")5063 #dlg.Destroy()5064 #sys.exit()5167 dlg = OpenTutorial(frm) 5168 if dlg.ShowModal() == wx.ID_OK: 5169 print("OK") 5170 else: 5171 print("Cancel") 5172 dlg.Destroy() 5173 sys.exit() 5065 5174 #====================================================================== 5066 5175 # test ScrolledMultiEditor -
trunk/GSASIIdataGUI.py
r3350 r3352 7325 7325 # wtSizer.Add(comp,0,WACV) 7326 7326 mainSizer.Add(wtSizer) 7327 wtSizer = wx.BoxSizer(wx.HORIZONTAL) 7328 wtSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Histogram label: '),0,WACV) 7329 if 'histTitle' not in data[0]: data[0]['histTitle'] = '' 7330 wtval = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data[0],'histTitle',typeHint=str,notBlank=False, 7331 size=(300,-1)) 7332 wtSizer.Add(wtval,1,WACV) 7333 mainSizer.Add(wtSizer,0,WACV|wx.EXPAND,1) 7327 7334 if data[0].get('Dummy',False): 7328 7335 simSizer = wx.BoxSizer(wx.HORIZONTAL) … … 7425 7432 mSizer.Add(addmag,1,wx.ALIGN_CENTER,1) 7426 7433 mainSizer.Add(mSizer) 7427 7434 7428 7435 G2frame.GPXtree.SetItemPyData(item,data) 7429 7436 G2frame.PatternId = item -
trunk/GSASIIplot.py
r3351 r3352 2424 2424 ParmList = [Parms,] 2425 2425 SampleList = [Sample,] 2426 Title = Pattern[-1] 2426 Title = data[0].get('histTitle') 2427 if not Title: 2428 Title = Pattern[-1] 2427 2429 else: #G2frame.selection 2428 2430 Title = os.path.split(G2frame.GSASprojectfile)[1]
Note: See TracChangeset
for help on using the changeset viewer.