Ignore:
Timestamp:
Apr 19, 2018 11:24:13 PM (5 years ago)
Author:
toby
Message:

add optional histogram label (shown only as plot title so far); set up for 2-column tutorial selection, but not yet in use

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r3345 r3352  
    5454:class:`MultiIntegerDialog`        Dialog to obtain multiple integer values from user,
    5555                                   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.
    5759:class:`G2ColumnIDDialog`          A dialog for matching column data to desired items; some
    5860                                   columns may be ignored.
     
    28072809        self.EndModal(wx.ID_CANCEL)
    28082810
     2811################################################################################
     2812class 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       
    28092893################################################################################
    28102894class OrderBox(wxscroll.ScrolledPanel):
     
    41854269
    41864270################################################################################
    4187 def StripIndents(msg):
     4271def StripIndents(msg,singleLine=False):
    41884272    'Strip indentation from multiline strings'
    41894273    msg1 = msg.replace('\n ','\n')
     
    41914275        msg = msg1
    41924276        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
    41944281
    41954282def StripUnicode(string,subs='.'):
     
    47054792G2BaseURL = "https://subversion.xray.aps.anl.gov/pyGSAS"
    47064793tutorialIndex = (
    4707     # tutorial dir,      web page file name,      title for page
     4794    # tutorial dir,      web page file name,      title for page,  description
    47084795    ['Getting started'],
    47094796    ['StartingGSASII', 'Starting GSAS.htm', 'Starting GSAS-II'],
     
    48804967        choices = [tutorialCatalog[i][2] for i in indices]
    48814968        selected = self.ChooseTutorial(choices)
     4969        #choices2 = [tutorialCatalog[i][2:4] for i in indices]
     4970        #selected = self.ChooseTutorial2(choices2)
    48824971        if selected is None: return
    48834972        j = indices[selected]
     
    49044993        choices = [tutorialCatalog[i][2] for i in indices]
    49054994        selected = self.ChooseTutorial(choices)
     4995        #choices2 = [tutorialCatalog[i][2:4] for i in indices]
     4996        #selected = self.ChooseTutorial2(choices2)
    49064997        if selected is None: return
    49074998        j = indices[selected]
     
    49165007        choices = [i[2] for i in tutorialCatalog]
    49175008        selected = self.ChooseTutorial(choices)
     5009        #choices2 = [i[2:4] for i in tutorialCatalog]
     5010        #selected = self.ChooseTutorial2(choices2)
    49185011        if selected is None: return       
    49195012        tutdir = tutorialCatalog[selected][0]
     
    49245017        ShowWebPage(URL,self.frame)
    49255018       
     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       
    49265033    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        '''
    49285037        def onDoubleClick(event):
    49295038            'double-click closes the dialog'
     
    50565165    # test Tutorial access
    50575166    #======================================================================
    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()
    50655174    #======================================================================
    50665175    # test ScrolledMultiEditor
Note: See TracChangeset for help on using the changeset viewer.