Popup:
    id: nd
    title: _('Proxy')
    BoxLayout:
        orientation: 'vertical'
        padding: '10dp'
        spacing: '10dp'
        GridLayout:
            cols: 2
            Label:
                text: _('Proxy mode')
            Spinner:
                id: mode
                height: '48dp'
                size_hint_y: None
                text: app.proxy_config.get('mode', 'none')
                values: ['none', 'socks4', 'socks5']
            Label:
                text: _('Host')
            TextInput:
                id: host
                multiline: False
                height: '48dp'
                size_hint_y: None
                text: app.proxy_config.get('host', '')
                disabled: mode.text == 'none'
            Label:
                text: _('Port')
            TextInput:
                id: port
                multiline: False
                input_type: 'number'
                height: '48dp'
                size_hint_y: None
                text: app.proxy_config.get('port', '')
                disabled: mode.text == 'none'
            Label:
                text: _('Username')
            TextInput:
                id: user
                multiline: False
                height: '48dp'
                size_hint_y: None
                text: app.proxy_config.get('user', '')
                disabled: mode.text == 'none'
            Label:
                text: _('Password')
            TextInput:
                id: password
                multiline: False
                password: True
                height: '48dp'
                size_hint_y: None
                text: app.proxy_config.get('password', '')
                disabled: mode.text == 'none'
        Widget:
            size_hint: 1, 0.1
        BoxLayout:
            Widget:
                size_hint: 0.5, None
            Button:
                size_hint: 0.5, None
                height: '48dp'
                text: _('OK')
                on_release:
                    net_params = app.network.get_parameters()
                    proxy = {}
                    proxy['mode']=str(root.ids.mode.text).lower()
                    proxy['host']=str(root.ids.host.text)
                    proxy['port']=str(root.ids.port.text)
                    proxy['user']=str(root.ids.user.text)
                    proxy['password']=str(root.ids.password.text)
                    if proxy['mode']=='none': proxy = None
                    net_params = net_params._replace(proxy=proxy)
                    app.network.run_from_another_thread(app.network.set_parameters(net_params))
                    nd.dismiss()
