Skip to content

Commit

Permalink
Merge pull request #2906 from markotoplak/proxies_setting
Browse files Browse the repository at this point in the history
[ENH] Settings for HTTP and HTTPS proxies in the canvas
  • Loading branch information
lanzagar authored Feb 14, 2018
2 parents f05be54 + 9bc371e commit 48b7251
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
pyqtgraph.setConfigOption("exitCleanup", False)


default_proxies = None


def fix_osx_10_9_private_font():
# Fix fonts on Os X (QTBUG 47206, 40833, 32789)
if sys.platform == "darwin":
Expand Down Expand Up @@ -88,10 +91,26 @@ def fix_win_pythonw_std_stream():
def fix_set_proxy_env():
"""
Set http_proxy/https_proxy environment variables (for requests, pip, ...)
from system settings on OS X and from registry on Windos. On unix, no-op.
from user-specified settings or, if none, from system settings on OS X
and from registry on Windos.
"""
for scheme, proxy in getproxies().items():
os.environ[scheme + '_proxy'] = proxy
# save default proxies so that setting can be reset
global default_proxies
if default_proxies is None:
default_proxies = getproxies() # can also read windows and macos settings

settings = QSettings()
proxies = getproxies()
for scheme in set(["http", "https"]) | set(proxies):
from_settings = settings.value("network/" + scheme + "-proxy", "", type=str)
from_default = default_proxies.get(scheme, "")
env_scheme = scheme + '_proxy'
if from_settings:
os.environ[env_scheme] = from_settings
elif from_default:
os.environ[env_scheme] = from_default # crucial for windows/macos support
else:
os.environ.pop(env_scheme, "")


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

# Set http_proxy environment variable(s) for some clients
fix_set_proxy_env()

# File handler should always be at least INFO level so we need
# the application root level to be at least at INFO.
root_level = min(levels[options.log_level], logging.INFO)
Expand Down Expand Up @@ -313,6 +329,9 @@ def main(argv=None):
config.widget_settings_dir(),
ignore_errors=True)

# Set http_proxy environment variables, after (potentially) clearing settings
fix_set_proxy_env()

file_handler = logging.FileHandler(
filename=os.path.join(config.log_dir(), "canvas.log"),
mode="w"
Expand Down
20 changes: 20 additions & 0 deletions Orange/canvas/application/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
log = logging.getLogger(__name__)


def refresh_proxies():
from Orange.canvas.__main__ import fix_set_proxy_env
fix_set_proxy_env()


class UserDefaultsPropertyBinding(AbstractBoundProperty):
"""
A Property binding for a setting in a
Expand Down Expand Up @@ -399,6 +404,20 @@ def __setupUi(self):

tab.setLayout(form)

# Network Tab
tab = QWidget()
self.addTab(tab, self.tr("Network"),
toolTip="Settings related to networking")

form = QFormLayout()
line_edit_http_proxy = QLineEdit()
self.bind(line_edit_http_proxy, "text", "network/http-proxy")
form.addRow("HTTP proxy:", line_edit_http_proxy)
line_edit_https_proxy = QLineEdit()
self.bind(line_edit_https_proxy, "text", "network/https-proxy")
form.addRow("HTTPS proxy:", line_edit_https_proxy)
tab.setLayout(form)

if self.__macUnified:
# Need some sensible size otherwise mac unified toolbar 'takes'
# the space that should be used for layout of the contents
Expand Down Expand Up @@ -461,6 +480,7 @@ def exec_(self):
self.show()
status = self.__loop.exec_()
self.__loop = None
refresh_proxies()
return status

def hideEvent(self, event):
Expand Down
4 changes: 4 additions & 0 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def init():

("add-ons/pip-install-arguments", str, '',
'Arguments to pass to "pip install" when installing add-ons.'),

("network/http-proxy", str, '', 'HTTP proxy.'),

("network/https-proxy", str, '', 'HTTPS proxy.'),
]

spec = [config_slot(*t) for t in spec]
Expand Down

0 comments on commit 48b7251

Please sign in to comment.