Fully implemented proxy settings UI, the settings can be accessed thru settings.ProxySettings
This commit is contained in:
@@ -16,6 +16,15 @@ class PFGlobalPref ( PreferenceView):
|
||||
def populatePanel( self, panel ):
|
||||
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.proxySettings = service.settings.ProxySettings.getInstance()
|
||||
self.dirtySettings = False
|
||||
|
||||
self.nMode = self.proxySettings.getMode()
|
||||
self.nAddr = self.proxySettings.getAddress()
|
||||
self.nPort = self.proxySettings.getPort()
|
||||
self.nType = self.proxySettings.getType()
|
||||
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
self.stTitle = wx.StaticText( panel, wx.ID_ANY, self.title, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
@@ -24,8 +33,8 @@ class PFGlobalPref ( PreferenceView):
|
||||
|
||||
mainSizer.Add( self.stTitle, 0, wx.ALL, 5 )
|
||||
|
||||
self.m_staticline1 = wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
|
||||
mainSizer.Add( self.m_staticline1, 0, wx.EXPAND, 5 )
|
||||
# self.m_staticline1 = wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
|
||||
# mainSizer.Add( self.m_staticline1, 0, wx.EXPAND, 5 )
|
||||
|
||||
self.cbGlobalChar = wx.CheckBox( panel, wx.ID_ANY, u"Use global character", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
mainSizer.Add( self.cbGlobalChar, 0, wx.ALL|wx.EXPAND, 5 )
|
||||
@@ -60,24 +69,24 @@ class PFGlobalPref ( PreferenceView):
|
||||
mainSizer.Add( self.stPTitle, 0, wx.ALL, 5 )
|
||||
|
||||
|
||||
# self.cbProxySettings = wx.CheckBox( panel, wx.ID_ANY, u"Manual proxy settings", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
# mainSizer.Add( self.cbProxySettings, 0, wx.ALL, 5 )
|
||||
|
||||
ptypeSizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||
|
||||
self.stPType = wx.StaticText( panel, wx.ID_ANY, u"Mode:", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.stPType.Wrap( -1 )
|
||||
ptypeSizer.Add( self.stPType, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
|
||||
self.chProxyTypeChoices = [ u"No proxy settings", u"Auto-detected proxy settings", u"Manual proxy settings" ]
|
||||
self.chProxyTypeChoices = [ u"No proxy", u"Auto-detected proxy settings", u"Manual proxy settings" ]
|
||||
self.chProxyType = wx.Choice( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.chProxyTypeChoices, 0 )
|
||||
self.chProxyType.SetSelection( 0 )
|
||||
|
||||
|
||||
self.chProxyType.SetSelection( self.nMode )
|
||||
|
||||
ptypeSizer.Add( self.chProxyType, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
|
||||
mainSizer.Add( ptypeSizer, 0, wx.EXPAND, 5 )
|
||||
|
||||
fgAddrSizer = wx.FlexGridSizer( 2, 2, 0, 0 )
|
||||
fgAddrSizer.AddGrowableCol( 1 )
|
||||
fgAddrSizer.SetFlexibleDirection( wx.BOTH )
|
||||
fgAddrSizer.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
|
||||
|
||||
@@ -86,18 +95,18 @@ class PFGlobalPref ( PreferenceView):
|
||||
self.stPSetAddr.Wrap( -1 )
|
||||
fgAddrSizer.Add( self.stPSetAddr, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
|
||||
self.editProxySettingsAddr = wx.TextCtrl( panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.editProxySettingsAddr = wx.TextCtrl( panel, wx.ID_ANY, self.nAddr, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
|
||||
fgAddrSizer.Add( self.editProxySettingsAddr, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
fgAddrSizer.Add( self.editProxySettingsAddr, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5 )
|
||||
|
||||
self.stPSetPort = wx.StaticText( panel, wx.ID_ANY, u"Port:", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.stPSetPort.Wrap( -1 )
|
||||
|
||||
fgAddrSizer.Add( self.stPSetPort, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
|
||||
self.editProxySettingsPort = wx.TextCtrl( panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.editProxySettingsPort = wx.TextCtrl( panel, wx.ID_ANY, self.nPort, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
|
||||
fgAddrSizer.Add( self.editProxySettingsPort, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
fgAddrSizer.Add( self.editProxySettingsPort, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5 )
|
||||
|
||||
mainSizer.Add( fgAddrSizer, 0, wx.EXPAND, 5)
|
||||
|
||||
@@ -105,15 +114,38 @@ class PFGlobalPref ( PreferenceView):
|
||||
self.stPSAutoDetected.Wrap( -1 )
|
||||
mainSizer.Add( self.stPSAutoDetected, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
|
||||
|
||||
ps = urllib2.ProxyHandler().proxies
|
||||
btnSizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||
btnSizer.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
|
||||
|
||||
self.btnApply = wx.Button( panel, wx.ID_ANY, u"Apply", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
|
||||
btnSizer.Add( self.btnApply, 0, wx.ALL, 5 )
|
||||
|
||||
mainSizer.Add(btnSizer, 0, wx.EXPAND,5)
|
||||
|
||||
proxy = None
|
||||
proxAddr = proxPort = ""
|
||||
proxydict = urllib2.ProxyHandler().proxies
|
||||
txt = "Auto-detected: "
|
||||
|
||||
for type in ps:
|
||||
txt += ps[type]
|
||||
txt += " "
|
||||
validPrefixes = ("https", "http")
|
||||
|
||||
if len(ps) == 0:
|
||||
for prefix in validPrefixes:
|
||||
if not prefix in proxydict:
|
||||
continue
|
||||
proxyline = proxydict[prefix]
|
||||
proto = "{0}://".format(prefix)
|
||||
if proxyline[:len(proto)] == proto:
|
||||
proxyline = proxyline[len(proto):]
|
||||
proxAddr, proxPort = proxyline.split(":")
|
||||
proxPort = int(proxPort.rstrip("/"))
|
||||
proxy = (proxAddr, proxPort)
|
||||
break
|
||||
|
||||
if len(proxAddr) == 0:
|
||||
txt += "None"
|
||||
else:
|
||||
txt += proto + proxAddr + ":" + str(proxPort)
|
||||
|
||||
self.stPSAutoDetected.SetLabel(txt)
|
||||
self.stPSAutoDetected.Disable()
|
||||
@@ -139,23 +171,78 @@ class PFGlobalPref ( PreferenceView):
|
||||
self.cbGlobalDmgPattern.Bind(wx.EVT_CHECKBOX, self.OnCBGlobalDmgPatternStateChange)
|
||||
self.cbGlobalForceReload.Bind(wx.EVT_CHECKBOX, self.OnCBGlobalForceReloadStateChange)
|
||||
|
||||
# self.cbProxySettings.Bind(wx.EVT_CHECKBOX, self.OnCBProxySettingsStateChange)
|
||||
self.chDefaultChar.Disable()
|
||||
self.chDefaultChar.Show(False)
|
||||
self.stDefChar.Show(False)
|
||||
|
||||
# self.ToggleProxySettings(self.cbProxySettings.GetValue())
|
||||
self.chProxyType.Bind(wx.EVT_CHOICE, self.OnCHProxyTypeSelect)
|
||||
self.editProxySettingsAddr.Bind(wx.EVT_TEXT, self.OnEditPSAddrText)
|
||||
self.editProxySettingsPort.Bind(wx.EVT_TEXT, self.OnEditPSPortText)
|
||||
|
||||
|
||||
self.btnApply.Bind(wx.EVT_BUTTON, self.OnBtnApply)
|
||||
|
||||
self.UpdateApplyButtonState()
|
||||
|
||||
if self.nMode is not 2:
|
||||
self.ToggleProxySettings(False)
|
||||
else:
|
||||
self.ToggleProxySettings(True)
|
||||
|
||||
panel.SetSizer( mainSizer )
|
||||
panel.Layout()
|
||||
|
||||
def OnEditPSAddrText(self, event):
|
||||
self.nAddr = self.editProxySettingsAddr.GetValue()
|
||||
self.dirtySettings = True
|
||||
self.UpdateApplyButtonState()
|
||||
|
||||
def OnEditPSPortText(self, event):
|
||||
self.nPort = self.editProxySettingsPort.GetValue()
|
||||
self.dirtySettings = True
|
||||
self.UpdateApplyButtonState()
|
||||
|
||||
def OnBtnApply(self, event):
|
||||
self.dirtySettings = False
|
||||
self.UpdateApplyButtonState()
|
||||
self.SaveSettings()
|
||||
|
||||
def SaveSettings(self):
|
||||
self.proxySettings.setMode(self.nMode)
|
||||
self.proxySettings.setAddress(self.nAddr)
|
||||
self.proxySettings.setPort(self.nPort)
|
||||
self.proxySettings.setType(self.nType)
|
||||
|
||||
def UpdateApplyButtonState(self):
|
||||
if self.dirtySettings:
|
||||
self.btnApply.Enable()
|
||||
else:
|
||||
self.btnApply.Disable()
|
||||
|
||||
def OnCHProxyTypeSelect(self, event):
|
||||
choice = self.chProxyType.GetSelection()
|
||||
|
||||
self.nMode = choice
|
||||
self.dirtySettings = True
|
||||
|
||||
self.UpdateApplyButtonState()
|
||||
|
||||
if choice is not 2:
|
||||
self.ToggleProxySettings(False)
|
||||
else:
|
||||
self.ToggleProxySettings(True)
|
||||
|
||||
def ToggleProxySettings(self, mode):
|
||||
if mode:
|
||||
self.chProxyType.Enable()
|
||||
self.editProxySettings.Enable()
|
||||
self.stPSetAddr.Enable()
|
||||
self.editProxySettingsAddr.Enable()
|
||||
self.stPSetPort.Enable()
|
||||
self.editProxySettingsPort.Enable()
|
||||
else:
|
||||
self.chProxyType.Disable()
|
||||
self.editProxySettings.Disable()
|
||||
self.stPSetAddr.Disable()
|
||||
self.editProxySettingsAddr.Disable()
|
||||
self.stPSetPort.Disable()
|
||||
self.editProxySettingsPort.Disable()
|
||||
|
||||
def OnCBProxySettingsStateChange(self, event):
|
||||
self.ToggleProxySettings(self.cbProxySettings.GetValue())
|
||||
|
||||
@@ -37,7 +37,16 @@ class PreferenceDialog(wx.Dialog):
|
||||
self.imageList = wx.ImageList(64,64)
|
||||
self.listbook.SetImageList(self.imageList)
|
||||
|
||||
mainSizer.Add(self.listbook, 1, wx.EXPAND | wx.ALL, 5)
|
||||
mainSizer.Add(self.listbook, 1, wx.EXPAND | wx.TOP|wx.BOTTOM|wx.LEFT, 5)
|
||||
|
||||
self.m_staticline2 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
|
||||
mainSizer.Add( self.m_staticline2, 0, wx.EXPAND, 5 )
|
||||
|
||||
btnSizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||
btnSizer.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
|
||||
self.btnOK = wx.Button( self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
btnSizer.Add( self.btnOK, 0, wx.ALL, 5 )
|
||||
mainSizer.Add(btnSizer,0 , wx.EXPAND, 5)
|
||||
self.SetSizer(mainSizer)
|
||||
|
||||
self.Centre(wx.BOTH)
|
||||
@@ -53,4 +62,9 @@ class PreferenceDialog(wx.Dialog):
|
||||
self.listbook.AddPage(page, title, imageId = imgID)
|
||||
|
||||
self.Fit()
|
||||
self.Layout()
|
||||
self.Layout()
|
||||
|
||||
self.btnOK.Bind(wx.EVT_BUTTON, self.OnBtnOK)
|
||||
|
||||
def OnBtnOK(self, event):
|
||||
self.Destroy()
|
||||
@@ -104,3 +104,46 @@ class Settings():
|
||||
|
||||
def items(self):
|
||||
return self.info.items()
|
||||
|
||||
class ProxySettings():
|
||||
_instance = None
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls._instance == None:
|
||||
cls._instance = ProxySettings()
|
||||
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
|
||||
# mode
|
||||
# 0 - No proxy
|
||||
# 1 - Auto-detected proxy settings
|
||||
# 2 - Manual proxy settings
|
||||
serviceProxyDefaultSettings = {"mode": 0, "type": "https", "address": "", "port": ""}
|
||||
|
||||
self.serviceProxySettings = SettingsProvider.getInstance().getSettings("pyfaServiceProxySettings", serviceProxyDefaultSettings)
|
||||
|
||||
def getMode(self):
|
||||
return self.serviceProxySettings["mode"]
|
||||
|
||||
def getAddress(self):
|
||||
return self.serviceProxySettings["address"]
|
||||
|
||||
def getPort(self):
|
||||
return self.serviceProxySettings["port"]
|
||||
|
||||
def getType(self):
|
||||
return self.serviceProxySettings["type"]
|
||||
|
||||
def setMode(self, mode):
|
||||
self.serviceProxySettings["mode"] = mode
|
||||
|
||||
def setAddress(self, addr):
|
||||
self.serviceProxySettings["address"] = addr
|
||||
|
||||
def setPort(self, port):
|
||||
self.serviceProxySettings["port"] = port
|
||||
|
||||
def setType(self, type):
|
||||
self.serviceProxySettings["type"] = type
|
||||
Reference in New Issue
Block a user