Skip to content

Commit 48b7251

Browse files
authored
Merge pull request #2906 from markotoplak/proxies_setting
[ENH] Settings for HTTP and HTTPS proxies in the canvas
2 parents f05be54 + 9bc371e commit 48b7251

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

Orange/canvas/__main__.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
pyqtgraph.setConfigOption("exitCleanup", False)
5353

5454

55+
default_proxies = None
56+
57+
5558
def fix_osx_10_9_private_font():
5659
# Fix fonts on Os X (QTBUG 47206, 40833, 32789)
5760
if sys.platform == "darwin":
@@ -88,10 +91,26 @@ def fix_win_pythonw_std_stream():
8891
def fix_set_proxy_env():
8992
"""
9093
Set http_proxy/https_proxy environment variables (for requests, pip, ...)
91-
from system settings on OS X and from registry on Windos. On unix, no-op.
94+
from user-specified settings or, if none, from system settings on OS X
95+
and from registry on Windos.
9296
"""
93-
for scheme, proxy in getproxies().items():
94-
os.environ[scheme + '_proxy'] = proxy
97+
# save default proxies so that setting can be reset
98+
global default_proxies
99+
if default_proxies is None:
100+
default_proxies = getproxies() # can also read windows and macos settings
101+
102+
settings = QSettings()
103+
proxies = getproxies()
104+
for scheme in set(["http", "https"]) | set(proxies):
105+
from_settings = settings.value("network/" + scheme + "-proxy", "", type=str)
106+
from_default = default_proxies.get(scheme, "")
107+
env_scheme = scheme + '_proxy'
108+
if from_settings:
109+
os.environ[env_scheme] = from_settings
110+
elif from_default:
111+
os.environ[env_scheme] = from_default # crucial for windows/macos support
112+
else:
113+
os.environ.pop(env_scheme, "")
95114

96115

97116
def make_sql_logger(level=logging.INFO):
@@ -247,9 +266,6 @@ def main(argv=None):
247266
# Try to fix fonts on OSX Mavericks
248267
fix_osx_10_9_private_font()
249268

250-
# Set http_proxy environment variable(s) for some clients
251-
fix_set_proxy_env()
252-
253269
# File handler should always be at least INFO level so we need
254270
# the application root level to be at least at INFO.
255271
root_level = min(levels[options.log_level], logging.INFO)
@@ -313,6 +329,9 @@ def main(argv=None):
313329
config.widget_settings_dir(),
314330
ignore_errors=True)
315331

332+
# Set http_proxy environment variables, after (potentially) clearing settings
333+
fix_set_proxy_env()
334+
316335
file_handler = logging.FileHandler(
317336
filename=os.path.join(config.log_dir(), "canvas.log"),
318337
mode="w"

Orange/canvas/application/settings.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
log = logging.getLogger(__name__)
2727

2828

29+
def refresh_proxies():
30+
from Orange.canvas.__main__ import fix_set_proxy_env
31+
fix_set_proxy_env()
32+
33+
2934
class UserDefaultsPropertyBinding(AbstractBoundProperty):
3035
"""
3136
A Property binding for a setting in a
@@ -399,6 +404,20 @@ def __setupUi(self):
399404

400405
tab.setLayout(form)
401406

407+
# Network Tab
408+
tab = QWidget()
409+
self.addTab(tab, self.tr("Network"),
410+
toolTip="Settings related to networking")
411+
412+
form = QFormLayout()
413+
line_edit_http_proxy = QLineEdit()
414+
self.bind(line_edit_http_proxy, "text", "network/http-proxy")
415+
form.addRow("HTTP proxy:", line_edit_http_proxy)
416+
line_edit_https_proxy = QLineEdit()
417+
self.bind(line_edit_https_proxy, "text", "network/https-proxy")
418+
form.addRow("HTTPS proxy:", line_edit_https_proxy)
419+
tab.setLayout(form)
420+
402421
if self.__macUnified:
403422
# Need some sensible size otherwise mac unified toolbar 'takes'
404423
# the space that should be used for layout of the contents
@@ -461,6 +480,7 @@ def exec_(self):
461480
self.show()
462481
status = self.__loop.exec_()
463482
self.__loop = None
483+
refresh_proxies()
464484
return status
465485

466486
def hideEvent(self, event):

Orange/canvas/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def init():
127127

128128
("add-ons/pip-install-arguments", str, '',
129129
'Arguments to pass to "pip install" when installing add-ons.'),
130+
131+
("network/http-proxy", str, '', 'HTTP proxy.'),
132+
133+
("network/https-proxy", str, '', 'HTTPS proxy.'),
130134
]
131135

132136
spec = [config_slot(*t) for t in spec]

0 commit comments

Comments
 (0)