home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / proxydialog.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  8.9 KB  |  194 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from wx import WHITE, HORIZONTAL, VERTICAL, ALIGN_RIGHT, ALIGN_CENTER_VERTICAL, EXPAND, ALIGN_LEFT, ALL
  6. from cgui import SimplePanel
  7. from gui.uberwidgets.PrefPanel import PrefPanel
  8. from gui.validators import NumericLimit
  9. import util.proxy_settings as util
  10. ID_NONPROX = wx.NewId()
  11. ID_SYSPROX = wx.NewId()
  12. ID_SETPROX = wx.NewId()
  13. ID_HTTP = wx.NewId()
  14. ID_HTTPS = wx.NewId()
  15. ID_SOCKS4 = wx.NewId()
  16. ID_SOCKS5 = wx.NewId()
  17. from config import platformName
  18.  
  19. class ProxyPanel(SimplePanel):
  20.     
  21.     def __init__(self, parent):
  22.         SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE)
  23.         if platformName != 'mac':
  24.             self.BackgroundColour = WHITE
  25.         
  26.         sz = self.Sizer = wx.BoxSizer(VERTICAL)
  27.         top = wx.BoxSizer(HORIZONTAL)
  28.         radpanel = wx.Panel(self)
  29.         rs = radpanel.Sizer = wx.BoxSizer(VERTICAL)
  30.         RADIO = wx.RadioButton
  31.         overrads = self.overrads = dict(NONPROX = RADIO(radpanel, ID_NONPROX, _('&No proxy'), style = wx.RB_GROUP, name = 'override'), SYSPROX = RADIO(radpanel, ID_SYSPROX, _('Use &default system settings'), name = 'override'), SETPROX = RADIO(radpanel, ID_SETPROX, _('&Specify proxy settings'), name = 'override'))
  32.         rs.Add(overrads['NONPROX'], 0, ALL, 2)
  33.         rs.Add(overrads['SYSPROX'], 0, ALL, 2)
  34.         rs.Add(overrads['SETPROX'], 0, ALL, 2)
  35.         proxyp = wx.Panel(self)
  36.         ps = proxyp.Sizer = wx.FlexGridSizer(2, 2)
  37.         
  38.         TEXT = lambda s: wx.StaticText(proxyp, -1, s)
  39.         
  40.         INPUT = lambda d, v = (wx.DefaultValidator,): wx.TextCtrl(proxyp, -1, d, validator = v)
  41.         ps.Add(TEXT(_('&Host:')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 2)
  42.         ps.Add(hosti, 0, ALIGN_LEFT | ALIGN_CENTER_VERTICAL | EXPAND | ALL, 2)
  43.         ps.Add(TEXT(_('P&ort:')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 2)
  44.         ps.Add(porti, 0, ALIGN_LEFT | ALIGN_CENTER_VERTICAL | ALL, 2)
  45.         ps.AddGrowableCol(1, 1)
  46.         protop = wx.Panel(self)
  47.         prs.Add(protorads['HTTP'], 0, ALL, 2)
  48.         prs.Add(protorads['SOCKS4'], 0, ALL, 2)
  49.         prs.Add(protorads['SOCKS5'], 0, ALL, 2)
  50.         authp = wx.Panel(self)
  51.         
  52.         TEXT = lambda s: wx.StaticText(authp, -1, s)
  53.         
  54.         INPUT = lambda d, style = (0,): wx.TextCtrl(authp, -1, d, style = style)
  55.         aus.Add(TEXT(_('&Username:')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 2)
  56.         aus.Add(useri, 0, ALIGN_LEFT | ALIGN_CENTER_VERTICAL | EXPAND | ALL, 2)
  57.         aus.Add(TEXT(_('&Password:')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 2)
  58.         aus.Add(passi, 0, ALIGN_LEFT | ALIGN_CENTER_VERTICAL | EXPAND | ALL, 2)
  59.         aus.AddGrowableCol(1, 1)
  60.         top.Add(PrefPanel(self, proxyp, _('Proxy Server')), 1, EXPAND | ALL, 2)
  61.         top.Add(PrefPanel(self, protop, _('Protocol')), 0, EXPAND | ALL, 2)
  62.         sz.Add(PrefPanel(self, radpanel, _('How to Connect')), 0, EXPAND | ALL, 2)
  63.         sz.Add(top, 1, EXPAND)
  64.         sz.Add(PrefPanel(self, authp, _('Authentication')), 1, EXPAND | ALL, 2)
  65.         pd = self.proxy_dict
  66.         override = pd.get('override', 'SYSPROX')
  67.         
  68.         try:
  69.             override = int(override)
  70.         except:
  71.             passi = self.passwordi = INPUT('', wx.TE_PASSWORD)
  72.             useri = self.usernamei = INPUT('')
  73.             (aus = authp.Sizer = wx.FlexGridSizer(2, 2),)
  74.  
  75.         override = [
  76.             'SYSPROX',
  77.             'SETPROX'][override]
  78.         self.override = override
  79.         self.overrads[self.override].Value = True
  80.         self.addr = pd.get('addr', '')
  81.         self.port = pd.get('port', '')
  82.         self.proxytype = pd.get('proxytype', 'HTTP')
  83.         self.protorads[self.proxytype].Value = True
  84.         self.username = pd.get('username', '')
  85.         self.password = pd.get('password', '')
  86.         self.Enablement()
  87.         Bind = self.Bind
  88.         Bind(wx.EVT_RADIOBUTTON, self.OnRadio)
  89.  
  90.     
  91.     def proxy_dict(self):
  92.         return util.proxy_settings.get_proxy_dict()
  93.  
  94.     proxy_dict = property(proxy_dict)
  95.     
  96.     def OnOK(self, event = None):
  97.         pd = self.proxy_dict
  98.         keys = [
  99.             'override',
  100.             'addr',
  101.             'port',
  102.             'proxytype',
  103.             'username',
  104.             'password']
  105.         for key in keys:
  106.             pd[key] = str(getattr(self, key))
  107.         
  108.         pd.save()
  109.  
  110.     addr = property((lambda self: self.hosti.Value), (lambda self, address: self.hosti.SetValue(address)))
  111.     port = property((lambda self: self.porti.Value), (lambda self, address: self.porti.SetValue(address)))
  112.     username = property((lambda self: self.usernamei.Value), (lambda self, address: self.usernamei.SetValue(address)))
  113.     password = property((lambda self: self.passwordi.Value), (lambda self, address: self.passwordi.SetValue(address)))
  114.     
  115.     def OnRadio(self, event):
  116.         rad = event.GetEventObject()
  117.         if rad.GetName() == 'proxytype':
  118.             setattr(self, 'proxytype', rad.GetLabelText().replace(' ', ''))
  119.         elif rad.GetName() == 'override':
  120.             for key in self.overrads:
  121.                 if self.overrads[key].Value:
  122.                     setattr(self, 'override', key)
  123.                     continue
  124.             
  125.             self.Enablement()
  126.         
  127.  
  128.     
  129.     def Enablement(self):
  130.         switch = self.overrads['SETPROX'].Value
  131.         self.hosti.Enable(switch)
  132.         self.porti.Enable(switch)
  133.         for rad in self.protorads:
  134.             self.protorads[rad].Enable(switch)
  135.         
  136.         hasproxy = not (self.overrads['NONPROX'].Value)
  137.         self.usernamei.Enable(hasproxy)
  138.         self.passwordi.Enable(hasproxy)
  139.  
  140.     
  141.     def OnPaint(self, event):
  142.         dc = wx.PaintDC(self)
  143.         rect = wx.RectS(self.ClientSize)
  144.         dc.Brush = wx.WHITE_BRUSH
  145.         dc.Pen = wx.TRANSPARENT_PEN
  146.         dc.DrawRectangleRect(rect)
  147.  
  148.  
  149.  
  150. class ProxyDialog(wx.Dialog):
  151.     
  152.     def __init__(self, parent = None):
  153.         wx.Dialog.__init__(self, parent, title = _('Connection Settings'))
  154.         if not platformName == 'mac':
  155.             self.SetBackgroundColour(wx.WHITE)
  156.         
  157.         self.Sizer = wx.BoxSizer(VERTICAL)
  158.         self.pp = ProxyPanel(self)
  159.         self.Sizer.Add(self.pp, 1, EXPAND | ALL, 5)
  160.         bsz = wx.BoxSizer(wx.HORIZONTAL)
  161.         okb = wx.Button(self, wx.ID_OK, _('&OK'))
  162.         okb.SetDefault()
  163.         canb = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
  164.         bsz.Add(okb, 0, ALL, 4)
  165.         bsz.Add(canb, 0, ALL, 4)
  166.         self.Sizer.Add(bsz, 0, ALIGN_RIGHT)
  167.         okb.Bind(wx.EVT_BUTTON, self.OnOK)
  168.         canb.Bind((wx.EVT_BUTTON,), (lambda e: self.Close()))
  169.         self.Fit()
  170.         self.Size = wx.Size(400, self.Size.height)
  171.         self.Layout()
  172.         self.Bind(wx.EVT_CLOSE, self.OnClose)
  173.  
  174.     
  175.     def OnClose(self, event):
  176.         self.Show(False)
  177.         self.pp = None
  178.  
  179.     
  180.     def OnOK(self, event):
  181.         res = self.pp.OnOK(event)
  182.         self.SetReturnCode(wx.ID_OK)
  183.         self.Close()
  184.         return res
  185.  
  186.  
  187. if __name__ == '__main__':
  188.     from tests.testapp import testapp
  189.     app = testapp()
  190.     f = ProxyDialog()
  191.     f.Show(True)
  192.     app.MainLoop()
  193.  
  194.