Changeset 4352


Ignore:
Timestamp:
Mar 9, 2020 4:49:58 PM (4 years ago)
Author:
toby
Message:

expand proxy GUI for more lines

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r4345 r4352  
    24462446    :param str values: default input values, if any
    24472447    :param int size: length of the input box in pixels
     2448    :param bool addRows: if True, users can add rows to the table
     2449      (default is False)
     2450    :param str hlp: if supplied, a help button is added to the dialog that
     2451      can be used to display the supplied help text in this variable.
    24482452    '''
    2449     def __init__(self,parent,title,prompts,values=[],size=-1):
    2450        
     2453    def __init__(self,parent,title,prompts,values=[],size=-1,
     2454                     addRows=False,hlp=None):
    24512455        wx.Dialog.__init__(self,parent,wx.ID_ANY,title,
    24522456                           pos=wx.DefaultPosition,
    24532457                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    2454         self.values = values
    2455         self.prompts = prompts
     2458        self.values = list(values)
     2459        self.prompts = list(prompts)
     2460        self.addRows = addRows
     2461        self.size = size
     2462        self.hlp = hlp
    24562463        self.CenterOnParent()
     2464        self.Paint()
     2465
     2466    def Paint(self):
     2467        if self.GetSizer():
     2468            self.GetSizer().Clear(True)
    24572469        mainSizer = wx.BoxSizer(wx.VERTICAL)
     2470        if self.hlp:
     2471            btnsizer = wx.BoxSizer(wx.HORIZONTAL)
     2472            hlp = HelpButton(self,self.hlp)
     2473            btnsizer.Add((-1,-1),1, wx.EXPAND, 1)
     2474            btnsizer.Add(hlp,0,wx.ALIGN_RIGHT|wx.ALL)
     2475            mainSizer.Add(btnsizer,0,wx.ALIGN_CENTER|wx.EXPAND)
    24582476        promptSizer = wx.FlexGridSizer(0,2,5,5)
     2477        promptSizer.AddGrowableCol(1,1)
    24592478        self.Indx = {}
    2460         for prompt,value in zip(prompts,values):
    2461             promptSizer.Add(wx.StaticText(self,-1,prompt),0,WACV)
    2462             valItem = wx.TextCtrl(self,-1,value=value,style=wx.TE_PROCESS_ENTER,size=(size,-1))
     2479        for prompt,value in zip(self.prompts,self.values):
     2480            promptSizer.Add(wx.StaticText(self,-1,prompt),0,WACV,0)
     2481            valItem = wx.TextCtrl(self,-1,value=value,style=wx.TE_PROCESS_ENTER,size=(self.size,-1))
    24632482            self.Indx[valItem.GetId()] = prompt
    24642483            valItem.Bind(wx.EVT_TEXT,self.newValue)
    24652484            promptSizer.Add(valItem,1,WACV|wx.EXPAND,1)
    24662485        mainSizer.Add(promptSizer,1,wx.ALL|wx.EXPAND,1)
    2467         btnsizer = wx.StdDialogButtonSizer()
     2486        btnsizer = wx.BoxSizer(wx.HORIZONTAL)
    24682487        OKbtn = wx.Button(self, wx.ID_OK)
    24692488        OKbtn.SetDefault()
    2470         btnsizer.AddButton(OKbtn)
     2489        btnsizer.Add((1,1),1,wx.EXPAND,1)
     2490        btnsizer.Add(OKbtn)
    24712491        btn = wx.Button(self, wx.ID_CANCEL)
    2472         btnsizer.AddButton(btn)
    2473         btnsizer.Realize()
    2474         mainSizer.Add(btnsizer,0,wx.ALIGN_CENTER)
     2492        btnsizer.Add(btn)
     2493        btnsizer.Add((1,1),1,wx.EXPAND,1)
     2494        if self.addRows:
     2495            btn = wx.Button(self, wx.ID_ANY,'+',style=wx.BU_EXACTFIT)
     2496            btn.Bind(wx.EVT_BUTTON,self.onExpand)
     2497            btnsizer.Add(btn,0,wx.ALIGN_RIGHT)
     2498        mainSizer.Add(btnsizer,0,wx.ALIGN_CENTER|wx.EXPAND)
    24752499        self.SetSizer(mainSizer)
    24762500        self.Fit()
     2501
     2502    def onExpand(self,event):
     2503        self.values.append('')
     2504        self.prompts.append('item '+str(len(self.values)))
     2505        self.Paint()
    24772506       
    24782507    def newValue(self,event):
  • trunk/GSASIIdataGUI.py

    r4346 r4352  
    21242124        '''
    21252125        h,p,e = host,port,etc = GSASIIpath.getsvnProxy()
    2126         if e:
    2127             proxyinfo = os.path.join(GSASIIpath.path2GSAS2,"proxyinfo.txt")
    2128             G2G.G2MessageBox(self,'File {} has manually-'.format(proxyinfo)+
    2129                 'entered information. Please edit this by hand',
    2130                                  'Unable to edit')
    2131             return
     2126        labels = ['Proxy address','proxy port']
     2127        values = [host,port]
     2128        i = 1
     2129        for item in etc:
     2130            i += 1
     2131            labels.append('extra svn arg #'+str(i))
     2132            values.append(item)
     2133        msg = '''This dialog allows customization of the subversion (svn)
     2134        command. If a proxy server is needed, the address/host and port
     2135        can be added supplied here. This will generate command-line options
     2136
     2137        --config-option servers:global:http-proxy-host=*host*
     2138        --config-option servers:global:http-proxy-port=*port*
     2139
     2140        Additional subversion command line options can be supplied here
     2141        by pressing the '+' button. As examples of options that might be of
     2142        value, use two extra lines to add:
     2143
     2144        --config-dir
     2145        DIR
     2146
     2147        to specify an alternate configuration location.
     2148
     2149        Or, use four extra lines to add
     2150
     2151        --config-option
     2152        servers:global:http-proxy-username=*account*
     2153        --config-option
     2154        servers:global:http-proxy-password=*password*
     2155
     2156        to specify a proxy user name and password.
     2157
     2158        Note that strings marked *value* are items that will be configured
     2159        by the user. See http://svnbook.red-bean.com for more information on
     2160        subversion.
     2161        '''
    21322162        dlg = G2G.MultiStringDialog(self,'Enter proxy values',
    2133                                         ['Proxy address','proxy port'],
    2134                                         [host,port],size=300)
     2163                            labels,values,size=300,addRows=True,hlp=msg)
    21352164        if dlg.Show():
    2136             h,p = dlg.GetValues()
     2165            values = dlg.GetValues()
     2166            h,p = values[:2]
     2167            e = values[2:]
    21372168        dlg.Destroy()
    2138         if h != host or p != port:
    2139             proxyinfo = os.path.join(GSASIIpath.path2GSAS2,"proxyinfo.txt")
    2140             GSASIIpath.setsvnProxy(h,p)
    2141             if not h.strip():
    2142                 os.remove(proxyinfo)
     2169        if h != host or p != port or etc != e:
     2170            localproxy = proxyinfo = os.path.join(
     2171                os.path.expanduser('~/.G2local/'),
     2172                "proxyinfo.txt")
     2173            if not os.path.exists(proxyinfo):
     2174                proxyinfo = os.path.join(GSASIIpath.path2GSAS2,"proxyinfo.txt")
     2175            GSASIIpath.setsvnProxy(h,p,e)
     2176            if not h.strip() and not e:
     2177                if os.path.exists(localproxy): os.remove(localproxy)
     2178                if os.path.exists(proxyinfo): os.remove(proxyinfo)
    21432179                return
    21442180            try:
    21452181                fp = open(proxyinfo,'w')
     2182            except:
     2183                fp = open(localproxy,'w')
     2184                proxyinfo = localproxy
     2185            try:
    21462186                fp.write(h.strip()+'\n')
    21472187                fp.write(p.strip()+'\n')
     2188                for i in e:
     2189                    if i.strip():
     2190                        fp.write(i.strip()+'\n')
    21482191                fp.close()
    21492192            except Exception as err:
    21502193                print('Error writing file {}:\n{}'.format(proxyinfo,err))
     2194            print('File {} written'.format(proxyinfo))
     2195               
    21512196    def _Add_ImportMenu_smallangle(self,parent):
    21522197        '''configure the Small Angle Data menus accord to the readers found in _init_Imports
  • trunk/GSASIIpath.py

    r4346 r4352  
    164164    '''Loads a proxy for subversion from the file created by bootstrap.py
    165165    '''
    166     proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
    167     if os.path.exists(proxyinfo):
    168         global proxycmds
    169         proxycmds = []
    170         fp = open(proxyinfo,'r')
     166    global proxycmds
     167    proxycmds = []
     168    proxyinfo = os.path.join(os.path.expanduser('~/.G2local/'),"proxyinfo.txt")
     169    if not os.path.exists(proxyinfo):
     170        proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
     171    if not os.path.exists(proxyinfo):
     172        return '','',''
     173    fp = open(proxyinfo,'r')
     174    host = fp.readline().strip()
     175    # allow file to begin with comments
     176    while host.startswith('#'):
    171177        host = fp.readline().strip()
    172         # allow file to begin with comments
    173         while host.startswith('#'):
    174             host = fp.readline().strip()
    175         port = fp.readline().strip()
    176         etc = []
     178    port = fp.readline().strip()
     179    etc = []
     180    line = fp.readline()
     181    while line:
     182        etc.append(line.strip())
    177183        line = fp.readline()
    178         while line:
    179             etc.append(line.strip())
    180             line = fp.readline()
    181         fp.close()
    182         setsvnProxy(host,port,etc)
    183         if not host.strip(): return '',''
    184         return host,port,etc
    185     return '','',''
     184    fp.close()
     185    setsvnProxy(host,port,etc)
     186    return host,port,etc
    186187
    187188def setsvnProxy(host,port,etc=[]):
     
    195196        proxycmds.append('--config-option')
    196197        proxycmds.append('servers:global:http-proxy-host='+host)
    197     if port:
    198         proxycmds.append('--config-option')
    199         proxycmds.append('servers:global:http-proxy-port='+port)
     198        if port:
     199            proxycmds.append('--config-option')
     200            proxycmds.append('servers:global:http-proxy-port='+port)
    200201    for item in etc:
    201202        proxycmds.append(item)
Note: See TracChangeset for help on using the changeset viewer.