mirror of
https://github.com/gryf/wicd.git
synced 2026-01-29 11:55:45 +01:00
Move clients to the main wicd module.
This commit is contained in:
51
wicd/curses/README.curses
Normal file
51
wicd/curses/README.curses
Normal file
@@ -0,0 +1,51 @@
|
||||
This is a curses-based client for wicd. It is designed to imitate wicd-client
|
||||
as much as can be done with a console-based interface. It is written using the
|
||||
Urwid (http://excess.org/urwid) toolkit, and thus requires it.
|
||||
|
||||
That's all there is to it, really. It installs unless you disable it when you
|
||||
call setup.py.
|
||||
|
||||
Right now, it lists current available networks, and whether you are connected
|
||||
to anything or not, all of which is updated in real time. Other features
|
||||
include the ability to connect to networks, global preferences controls, and
|
||||
per-network settings for wireless networks.
|
||||
|
||||
Controls (most of these should be viewable in wicd-curses itself):
|
||||
|
||||
F5 : refresh wireless networks
|
||||
F8 Q q : quit
|
||||
D : disconnect from all active networks
|
||||
ESC : if connecting to a network, stop doing so
|
||||
ENTER C : Attempt connection to selected network
|
||||
P : Display preferences dialog
|
||||
right arrow : Display network configuration for selected network
|
||||
A : Display "About" dialog
|
||||
I : Raise the "Scan for hidden networks" dialog
|
||||
H or h or ? : Raise help dialog
|
||||
S : Provide instructions for configuring scripts
|
||||
delete : Delete selected wired network profile (from the wired ComboBox)
|
||||
F2 : Rename selected wired network profile (from the wired ComboBox)
|
||||
O : Raise ad-hoc network dialog
|
||||
|
||||
IN DIALOGS (Meta usually is "Alt"):
|
||||
ESC or Q or q: Quit dialog without saving information (if present)
|
||||
Meta+[ / Meta+]: Change tabs Left/Right (if tabs present)
|
||||
Meta+Enter : Quit dialog and save information
|
||||
|
||||
FAQ (WIP):
|
||||
|
||||
What is wicd-curses?
|
||||
See above. :-)
|
||||
|
||||
Why didn't you call it wicd-urwid? There is a hachoir-urwid package out there.
|
||||
I first called this "urwicd". However, due to the relative obscurity of
|
||||
the urwid package, and the fact that many more people know what "curses"
|
||||
is, I named it wicd-curses.
|
||||
|
||||
Why don't you support lower-case keybindings for most of the commands?
|
||||
I was trying to prevent mass chaos from happening because of mashing keys.
|
||||
Of course, if you unwittingly have caps-lock on, that's going to cause mass
|
||||
chaos, too, so you might want to check that (or ask me about changing the
|
||||
keymaps to ctrl/meta+KEY)
|
||||
|
||||
~NaCl
|
||||
166
wicd/curses/configscript_curses.py
Normal file
166
wicd/curses/configscript_curses.py
Normal file
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""configscript_curses.py
|
||||
Kind of like configscript.py, except written using urwid.
|
||||
|
||||
Also recycles a lot of configscript.py, too. :-)
|
||||
"""
|
||||
|
||||
# Copyright (C) 2009 Andrew Psaltis
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import urwid
|
||||
import urwid.curses_display
|
||||
|
||||
from wicd.translations import _
|
||||
|
||||
from configscript import write_scripts, get_script_info
|
||||
from configscript import none_to_blank, blank_to_none
|
||||
|
||||
ui = None
|
||||
frame = None
|
||||
pre_entry = None
|
||||
post_entry = None
|
||||
pre_disconnect_entry = None
|
||||
post_disconnect_entry = None
|
||||
|
||||
|
||||
def main(argv):
|
||||
"""Main function."""
|
||||
global ui, frame
|
||||
if len(argv) < 2:
|
||||
print('Network id to configure is missing, aborting.')
|
||||
sys.exit(1)
|
||||
|
||||
ui = urwid.curses_display.Screen()
|
||||
ui.register_palette([('body', 'default', 'default'),
|
||||
('focus', 'dark magenta', 'light gray'),
|
||||
('editcp', 'default', 'default', 'standout'),
|
||||
('editbx', 'light gray', 'dark blue'),
|
||||
('editfc', 'white', 'dark blue', 'bold')])
|
||||
|
||||
network = argv[1]
|
||||
network_type = argv[2]
|
||||
|
||||
script_info = get_script_info(network, network_type)
|
||||
|
||||
blank = urwid.Text('')
|
||||
pre_entry_t = ('body', _('Pre-connection Script') + ': ')
|
||||
post_entry_t = ('body', _('Post-connection Script') + ': ')
|
||||
pre_disconnect_entry_t = ('body', _('Pre-disconnection Script') + ': ')
|
||||
post_disconnect_entry_t = ('body', _('Post-disconnection Script') + ': ')
|
||||
|
||||
global pre_entry, post_entry, pre_disconnect_entry, post_disconnect_entry
|
||||
pre_entry = urwid.AttrWrap(urwid.Edit(pre_entry_t,
|
||||
none_to_blank(script_info.
|
||||
get('pre_entry'))),
|
||||
'editbx', 'editfc')
|
||||
post_entry = urwid.AttrWrap(urwid.Edit(post_entry_t,
|
||||
none_to_blank(script_info.
|
||||
get('post_entry'))),
|
||||
'editbx', 'editfc')
|
||||
|
||||
pre_disconnect_entry = urwid.AttrWrap(
|
||||
urwid.Edit(pre_disconnect_entry_t,
|
||||
none_to_blank(script_info.get('pre_disconnect_entry'))),
|
||||
'editbx', 'editfc')
|
||||
post_disconnect_entry = urwid.AttrWrap(
|
||||
urwid.Edit(post_disconnect_entry_t,
|
||||
none_to_blank(script_info.get('post_disconnect_entry'))),
|
||||
'editbx', 'editfc')
|
||||
|
||||
# The buttons
|
||||
ok_button = urwid.AttrWrap(urwid.Button(_('OK'), ok_callback), 'body',
|
||||
'focus')
|
||||
cancel_button = urwid.AttrWrap(urwid.Button(_('Cancel'), cancel_callback),
|
||||
'body', 'focus')
|
||||
|
||||
button_cols = urwid.Columns([ok_button, cancel_button], dividechars=1)
|
||||
|
||||
lbox = urwid.Pile([('fixed', 2, urwid.Filler(pre_entry)),
|
||||
# ('fixed', urwid.Filler(blank), 1),
|
||||
('fixed', 2, urwid.Filler(post_entry)),
|
||||
('fixed', 2, urwid.Filler(pre_disconnect_entry)),
|
||||
('fixed', 2, urwid.Filler(post_disconnect_entry)),
|
||||
# blank, blank, blank, blank, blank,
|
||||
urwid.Filler(button_cols, 'bottom')])
|
||||
frame = urwid.Frame(lbox)
|
||||
result = ui.run_wrapper(run)
|
||||
|
||||
if result:
|
||||
script_info["pre_entry"] = blank_to_none(pre_entry.get_edit_text())
|
||||
script_info["post_entry"] = blank_to_none(post_entry.get_edit_text())
|
||||
script_info["pre_disconnect_entry"] = blank_to_none(
|
||||
pre_disconnect_entry.get_edit_text())
|
||||
script_info["post_disconnect_entry"] = blank_to_none(
|
||||
post_disconnect_entry.get_edit_text())
|
||||
write_scripts(network, network_type, script_info)
|
||||
|
||||
|
||||
OK_PRESSED = False
|
||||
CANCEL_PRESSED = False
|
||||
|
||||
|
||||
def ok_callback(button_object, user_data=None):
|
||||
"""Callback."""
|
||||
global OK_PRESSED
|
||||
OK_PRESSED = True
|
||||
|
||||
|
||||
def cancel_callback(button_object, user_data=None):
|
||||
"""Callback."""
|
||||
global CANCEL_PRESSED
|
||||
CANCEL_PRESSED = True
|
||||
|
||||
|
||||
def run():
|
||||
"""Run the UI."""
|
||||
dim = ui.get_cols_rows()
|
||||
ui.set_mouse_tracking()
|
||||
|
||||
keys = True
|
||||
while True:
|
||||
if keys:
|
||||
ui.draw_screen(dim, frame.render(dim, True))
|
||||
keys = ui.get_input()
|
||||
|
||||
if "window resize" in keys:
|
||||
dim = ui.get_cols_rows()
|
||||
if "esc" in keys or 'Q' in keys:
|
||||
return False
|
||||
for k in keys:
|
||||
# Send key to underlying widget:
|
||||
if urwid.is_mouse_event(k):
|
||||
event, button, col, row = k
|
||||
frame.mouse_event(dim, event, button, col, row, focus=True)
|
||||
else:
|
||||
frame.keypress(dim, k)
|
||||
# Check if buttons are pressed.
|
||||
if CANCEL_PRESSED:
|
||||
return False
|
||||
if OK_PRESSED or 'meta enter' in keys:
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if os.getuid() != 0:
|
||||
print("Root privileges are required to configure scripts. Exiting.")
|
||||
sys.exit(0)
|
||||
main(sys.argv)
|
||||
749
wicd/curses/curses_misc.py
Normal file
749
wicd/curses/curses_misc.py
Normal file
@@ -0,0 +1,749 @@
|
||||
#!/usr/bin/env python3
|
||||
# -* coding: utf-8 -*-
|
||||
|
||||
"""curses_misc.py: Module for various widgets that are used throughout
|
||||
wicd-curses.
|
||||
"""
|
||||
|
||||
# Copyright (C) 2008-2009 Andrew Psaltis
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
import urwid
|
||||
|
||||
from wicd.translations import _
|
||||
from functools import reduce
|
||||
|
||||
|
||||
# Uses code that is towards the bottom
|
||||
def error(ui, parent, message):
|
||||
"""Shows an error dialog (or something that resembles one)"""
|
||||
# /\
|
||||
# /!!\
|
||||
# /____\
|
||||
dialog = TextDialog(message, 6, 40, ('important', 'ERROR'))
|
||||
return dialog.run(ui, parent)
|
||||
|
||||
|
||||
class SelText(urwid.Text):
|
||||
"""A selectable text widget. See urwid.Text."""
|
||||
|
||||
def selectable(self):
|
||||
"""Make widget selectable."""
|
||||
return True
|
||||
|
||||
def keypress(self, size, key):
|
||||
"""Don't handle any keys."""
|
||||
return key
|
||||
|
||||
|
||||
class NSelListBox(urwid.ListBox):
|
||||
"""Non-selectable ListBox."""
|
||||
def selectable(self):
|
||||
return False
|
||||
|
||||
|
||||
# This class is annoying. :/
|
||||
class DynWrap(urwid.AttrWrap):
|
||||
"""
|
||||
Makes an object have mutable selectivity. Attributes will change like
|
||||
those in an AttrWrap
|
||||
|
||||
w = widget to wrap
|
||||
sensitive = current selectable state
|
||||
attrs = tuple of (attr_sens,attr_not_sens)
|
||||
attrfoc = attributes when in focus, defaults to nothing
|
||||
"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, w, sensitive=True, attrs=('editbx', 'editnfc'),
|
||||
focus_attr='editfc'):
|
||||
self._attrs = attrs
|
||||
self._sensitive = sensitive
|
||||
|
||||
if sensitive:
|
||||
cur_attr = attrs[0]
|
||||
else:
|
||||
cur_attr = attrs[1]
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(w, cur_attr, focus_attr)
|
||||
|
||||
def get_sensitive(self):
|
||||
"""Getter for sensitive property."""
|
||||
return self._sensitive
|
||||
|
||||
def set_sensitive(self, state):
|
||||
"""Setter for sensitive property."""
|
||||
if state:
|
||||
self.set_attr(self._attrs[0])
|
||||
else:
|
||||
self.set_attr(self._attrs[1])
|
||||
self._sensitive = state
|
||||
property(get_sensitive, set_sensitive)
|
||||
|
||||
def get_attrs(self):
|
||||
"""Getter for attrs property."""
|
||||
return self._attrs
|
||||
|
||||
def set_attrs(self, attrs):
|
||||
"""Setter for attrs property."""
|
||||
self._attrs = attrs
|
||||
property(get_attrs, set_attrs)
|
||||
|
||||
def selectable(self):
|
||||
return self._sensitive
|
||||
|
||||
|
||||
class DynEdit(DynWrap):
|
||||
"""Edit DynWrap'ed to the most common specifications."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, caption='', edit_text='', sensitive=True,
|
||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||
caption = ('editcp', caption + ': ')
|
||||
edit = urwid.Edit(caption, edit_text)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
||||
|
||||
|
||||
class DynIntEdit(DynWrap):
|
||||
"""IntEdit DynWrap'ed to the most common specifications."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, caption='', edit_text='', sensitive=True,
|
||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||
caption = ('editcp', caption + ':')
|
||||
edit = urwid.IntEdit(caption, edit_text)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
||||
|
||||
|
||||
class DynRadioButton(DynWrap):
|
||||
"""RadioButton DynWrap'ed to the most common specifications."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, group, label, state='first True', on_state_change=None,
|
||||
user_data=None, sensitive=True, attrs=('body', 'editnfc'),
|
||||
focus_attr='body'):
|
||||
# caption = ('editcp', caption + ':')
|
||||
button = urwid.RadioButton(group, label, state, on_state_change,
|
||||
user_data)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(button, sensitive, attrs, focus_attr)
|
||||
|
||||
|
||||
class MaskingEditException(Exception):
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
# Password-style edit
|
||||
class MaskingEdit(urwid.Edit):
|
||||
"""
|
||||
mask_mode = one of:
|
||||
"always" : everything is a '*' all of the time
|
||||
"no_focus" : everything is a '*' only when not in focus
|
||||
"off" : everything is always unmasked
|
||||
mask_char = the single character that masks all other characters in the
|
||||
field
|
||||
"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, caption="", edit_text="", multiline=False, align='left',
|
||||
wrap='space', allow_tab=False, edit_pos=None, layout=None,
|
||||
mask_mode="always", mask_char='*'):
|
||||
self.mask_mode = mask_mode
|
||||
if len(mask_char) > 1:
|
||||
raise MaskingEditException('Masks of more than one character are '
|
||||
'not supported!')
|
||||
self.mask_char = mask_char
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(caption, edit_text, multiline, align, wrap,
|
||||
allow_tab, edit_pos, layout)
|
||||
|
||||
def get_caption(self):
|
||||
"""Return caption."""
|
||||
return self.caption
|
||||
|
||||
def get_mask_mode(self):
|
||||
"""Getter for mask_mode property."""
|
||||
return self.mask_mode
|
||||
|
||||
def set_mask_mode(self, mode):
|
||||
"""Setter for mask_mode property."""
|
||||
self.mask_mode = mode
|
||||
|
||||
def get_masked_text(self):
|
||||
"""Get masked out text."""
|
||||
return self.mask_char * len(self.get_edit_text())
|
||||
|
||||
def render(self, xxx_todo_changeme, focus=False):
|
||||
"""
|
||||
Render edit widget and return canvas. Include cursor when in
|
||||
focus.
|
||||
"""
|
||||
(maxcol, ) = xxx_todo_changeme
|
||||
if self.mask_mode == "off" or (self.mask_mode == 'no_focus' and focus):
|
||||
# pylint: disable-msg=E1101
|
||||
canv = self.__super.render((maxcol, ), focus)
|
||||
# The cache messes this thing up, because I am totally changing
|
||||
# what is displayed.
|
||||
self._invalidate()
|
||||
return canv
|
||||
|
||||
# Else, we have a slight mess to deal with...
|
||||
self._shift_view_to_cursor = not not focus # force bool
|
||||
|
||||
text, attr = self.get_text()
|
||||
text = text[:len(self.caption)] + self.get_masked_text()
|
||||
trans = self.get_line_translation(maxcol, (text, attr))
|
||||
canv = urwid.canvas.apply_text_layout(text, attr, trans, maxcol)
|
||||
|
||||
if focus:
|
||||
canv = urwid.CompositeCanvas(canv)
|
||||
canv.cursor = self.get_cursor_coords((maxcol, ))
|
||||
|
||||
return canv
|
||||
|
||||
|
||||
class TabColumns(urwid.WidgetWrap):
|
||||
"""
|
||||
Tabbed interface, mostly for use in the Preferences Dialog
|
||||
|
||||
titles_dict = dictionary of tab_contents (a SelText) : tab_widget (box)
|
||||
attr = normal attributes
|
||||
attrsel = attribute when active
|
||||
"""
|
||||
# FIXME Make the bottom_part optional
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, tab_str, tab_wid, title, bottom_part=None,
|
||||
attr=('body', 'focus'), attrsel='tab active',
|
||||
attrtitle='header'):
|
||||
# self.bottom_part = bottom_part
|
||||
# title_wid = urwid.Text((attrtitle, title), align='right')
|
||||
column_list = []
|
||||
for w in tab_str:
|
||||
text, trash = w.get_text()
|
||||
column_list.append(('fixed', len(text), w))
|
||||
column_list.append(urwid.Text((attrtitle, title), align='right'))
|
||||
|
||||
self.tab_map = dict(list(zip(tab_str, tab_wid)))
|
||||
self.active_tab = tab_str[0]
|
||||
self.columns = urwid.Columns(column_list, dividechars=1)
|
||||
# walker = urwid.SimpleListWalker([self.columns, tab_wid[0]])
|
||||
# self.listbox = urwid.ListBox(walker)
|
||||
self.gen_pile(tab_wid[0], True)
|
||||
self.frame = urwid.Frame(self.pile)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(self.frame)
|
||||
|
||||
def gen_pile(self, lbox, firstrun=False):
|
||||
"""Make the pile in the middle."""
|
||||
self.pile = urwid.Pile([('fixed', 1,
|
||||
urwid.Filler(self.columns, 'top')),
|
||||
urwid.Filler(lbox, 'top',
|
||||
height=('relative', 99))])
|
||||
# ('fixed', 1, urwid.Filler(self.bottom_part, 'bottom'))])
|
||||
if not firstrun:
|
||||
self.frame.set_body(self.pile)
|
||||
self._w = self.frame
|
||||
self._invalidate()
|
||||
|
||||
def selectable(self):
|
||||
"""Return whether the widget is selectable."""
|
||||
return True
|
||||
|
||||
def keypress(self, size, key):
|
||||
"""Handle keypresses."""
|
||||
# If the key is page up or page down, move focus to the tabs and call
|
||||
# left or right on the tabs.
|
||||
if key == "page up" or key == "page down":
|
||||
self._w.get_body().set_focus(0)
|
||||
if key == "page up":
|
||||
newK = 'left'
|
||||
else:
|
||||
newK = 'right'
|
||||
self.keypress(size, newK)
|
||||
self._w.get_body().set_focus(1)
|
||||
else:
|
||||
key = self._w.keypress(size, key)
|
||||
wid = self.pile.get_focus().get_body()
|
||||
if wid == self.columns:
|
||||
self.active_tab.set_attr('body')
|
||||
self.columns.get_focus().set_attr('tab active')
|
||||
self.active_tab = self.columns.get_focus()
|
||||
self.gen_pile(self.tab_map[self.active_tab])
|
||||
|
||||
return key
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
"""Handle mouse events."""
|
||||
wid = self.pile.get_focus().get_body()
|
||||
if wid == self.columns:
|
||||
self.active_tab.set_attr('body')
|
||||
|
||||
self._w.mouse_event(size, event, button, x, y, focus)
|
||||
if wid == self.columns:
|
||||
self.active_tab.set_attr('body')
|
||||
self.columns.get_focus().set_attr('tab active')
|
||||
self.active_tab = self.columns.get_focus()
|
||||
self.gen_pile(self.tab_map[self.active_tab])
|
||||
|
||||
|
||||
class ComboBoxException(Exception):
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
# A "combo box" of SelTexts
|
||||
# I based this off of the code found here:
|
||||
# http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py
|
||||
# This is a hack/kludge. It isn't without quirks, but it more or less works.
|
||||
# We need to wait for changes in urwid's Canvas API before we can actually
|
||||
# make a real ComboBox.
|
||||
class ComboBox(urwid.WidgetWrap):
|
||||
"""A ComboBox of text objects"""
|
||||
class ComboSpace(urwid.WidgetWrap):
|
||||
"""The actual menu-like space that comes down from the ComboBox"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, data, body, ui, show_first, pos=(0, 0),
|
||||
attr=('body', 'focus')):
|
||||
"""
|
||||
body : parent widget
|
||||
data : stuff to include in the combobox
|
||||
ui : the screen
|
||||
show_first: index of the element in the list to pick first
|
||||
pos : a tuple of (row,col) where to put the list
|
||||
attr : a tuple of (attr_no_focus,attr_focus)
|
||||
"""
|
||||
|
||||
# Calculate width and height of the menu widget:
|
||||
height = len(data)
|
||||
width = 0
|
||||
for entry in data:
|
||||
if len(entry) > width:
|
||||
width = len(entry)
|
||||
content = [urwid.AttrWrap(SelText(w), attr[0], attr[1])
|
||||
for w in data]
|
||||
self._listbox = urwid.ListBox(content)
|
||||
self._listbox.set_focus(show_first)
|
||||
|
||||
overlay = urwid.Overlay(self._listbox, body,
|
||||
('fixed left', pos[0]), width + 2,
|
||||
('fixed top', pos[1]), height)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(overlay)
|
||||
|
||||
def show(self, ui, display):
|
||||
"""Show widget."""
|
||||
dim = ui.get_cols_rows()
|
||||
keys = True
|
||||
|
||||
# Event loop:
|
||||
while True:
|
||||
if keys:
|
||||
ui.draw_screen(dim, self.render(dim, True))
|
||||
|
||||
keys = ui.get_input()
|
||||
|
||||
if "window resize" in keys:
|
||||
dim = ui.get_cols_rows()
|
||||
if "esc" in keys:
|
||||
return None
|
||||
if "enter" in keys:
|
||||
(wid, pos) = self._listbox.get_focus()
|
||||
(text, attr) = wid.get_text()
|
||||
return text
|
||||
|
||||
for k in keys:
|
||||
# Send key to underlying widget:
|
||||
self._w.keypress(dim, k)
|
||||
|
||||
# def get_size(self):
|
||||
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, label='', data=None, attrs=('body', 'editnfc'),
|
||||
focus_attr='focus', use_enter=True, focus=0, callback=None,
|
||||
user_args=None):
|
||||
"""
|
||||
label : bit of text that preceeds the combobox. If it is "", then
|
||||
ignore it
|
||||
data : stuff to include in the combobox
|
||||
body : parent widget
|
||||
ui : the screen
|
||||
row : where this object is to be found onscreen
|
||||
focus : index of the element in the list to pick first
|
||||
callback : function that takes (combobox,sel_index,user_args=None)
|
||||
user_args : user_args in the callback
|
||||
"""
|
||||
|
||||
self.DOWN_ARROW = ' vvv'
|
||||
self.label = urwid.Text(label)
|
||||
self.attrs = attrs
|
||||
self.focus_attr = focus_attr
|
||||
if data is None:
|
||||
data = []
|
||||
self.list = data
|
||||
|
||||
s, trash = self.label.get_text()
|
||||
|
||||
self.overlay = None
|
||||
self.cbox = DynWrap(SelText(self.DOWN_ARROW), attrs=attrs,
|
||||
focus_attr=focus_attr)
|
||||
# Unicode will kill me sooner or later.
|
||||
if label != '':
|
||||
w = urwid.Columns(
|
||||
[('fixed', len(s), self.label), self.cbox],
|
||||
dividechars=1
|
||||
)
|
||||
else:
|
||||
w = urwid.Columns([self.cbox])
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(w)
|
||||
|
||||
# We need this to pick our keypresses
|
||||
self.use_enter = use_enter
|
||||
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
self.focus = focus
|
||||
else:
|
||||
self._w.focus_position = focus
|
||||
|
||||
self.callback = callback
|
||||
self.user_args = user_args
|
||||
|
||||
# Widget references to simplify some things
|
||||
self.parent = None
|
||||
self.ui = None
|
||||
self.row = None
|
||||
|
||||
def set_list(self, data):
|
||||
"""Populate widget list."""
|
||||
self.list = data
|
||||
|
||||
def set_focus(self, index):
|
||||
"""Set widget focus."""
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
self.focus = index
|
||||
else:
|
||||
try:
|
||||
self._w.focus_position = index
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# API changed between urwid 0.9.8.4 and 0.9.9
|
||||
try:
|
||||
self.cbox.set_w(SelText(self.list[index] + self.DOWN_ARROW))
|
||||
except AttributeError:
|
||||
self.cbox._w = SelText(self.list[index] + self.DOWN_ARROW)
|
||||
if self.overlay:
|
||||
self.overlay._listbox.set_focus(index)
|
||||
|
||||
def rebuild_combobox(self):
|
||||
"""Rebuild combobox."""
|
||||
self.build_combobox(self.parent, self.ui, self.row)
|
||||
|
||||
def build_combobox(self, parent, ui, row):
|
||||
"""Build combobox."""
|
||||
s, trash = self.label.get_text()
|
||||
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
index = self.focus
|
||||
else:
|
||||
index = self._w.focus_position # pylint: disable-msg=E1103
|
||||
|
||||
self.cbox = DynWrap(SelText([self.list[index] + self.DOWN_ARROW]),
|
||||
attrs=self.attrs, focus_attr=self.focus_attr)
|
||||
if str != '':
|
||||
w = urwid.Columns([('fixed', len(s), self.label), self.cbox],
|
||||
dividechars=1)
|
||||
self.overlay = self.ComboSpace(self.list, parent, ui, index,
|
||||
pos=(len(s) + 1, row))
|
||||
else:
|
||||
w = urwid.Columns([self.cbox])
|
||||
self.overlay = self.ComboSpace(self.list, parent, ui, index,
|
||||
pos=(0, row))
|
||||
|
||||
self._w = w
|
||||
self._invalidate()
|
||||
self.parent = parent
|
||||
self.ui = ui
|
||||
self.row = row
|
||||
|
||||
# If we press space or enter, be a combo box!
|
||||
def keypress(self, size, key):
|
||||
"""Handle keypresses."""
|
||||
activate = key == ' '
|
||||
if self.use_enter:
|
||||
activate = activate or key == 'enter'
|
||||
if activate:
|
||||
# Die if the user didn't prepare the combobox overlay
|
||||
if self.overlay is None:
|
||||
raise ComboBoxException('ComboBox must be built before use!')
|
||||
retval = self.overlay.show(self.ui, self.parent)
|
||||
if retval is not None:
|
||||
self.set_focus(self.list.index(retval))
|
||||
# self.cbox.set_w(SelText(retval+' vvv'))
|
||||
if self.callback is not None:
|
||||
self.callback(self, self.overlay._listbox.get_focus()[1],
|
||||
self.user_args)
|
||||
return self._w.keypress(size, key)
|
||||
|
||||
def selectable(self):
|
||||
"""Return whether the widget is selectable."""
|
||||
return self.cbox.selectable()
|
||||
|
||||
def get_focus(self):
|
||||
"""Return widget focus."""
|
||||
if self.overlay:
|
||||
return self.overlay._listbox.get_focus()
|
||||
else:
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
return None, self.focus
|
||||
else:
|
||||
return None, self._w.focus_position
|
||||
|
||||
def get_sensitive(self):
|
||||
"""Return widget sensitivity."""
|
||||
return self.cbox.get_sensitive()
|
||||
|
||||
def set_sensitive(self, state):
|
||||
"""Set widget sensitivity."""
|
||||
self.cbox.set_sensitive(state)
|
||||
|
||||
|
||||
# This is a h4x3d copy of some of the code in Ian Ward's dialog.py example.
|
||||
class DialogExit(Exception):
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
class Dialog2(urwid.WidgetWrap):
|
||||
"""Base class for other dialogs."""
|
||||
def __init__(self, text, height, width, body=None):
|
||||
self.buttons = None
|
||||
|
||||
self.width = int(width)
|
||||
if width <= 0:
|
||||
self.width = ('relative', 80)
|
||||
self.height = int(height)
|
||||
if height <= 0:
|
||||
self.height = ('relative', 80)
|
||||
|
||||
self.body = body
|
||||
if body is None:
|
||||
# fill space with nothing
|
||||
body = urwid.Filler(urwid.Divider(), 'top')
|
||||
|
||||
self.frame = urwid.Frame(body, focus_part='footer')
|
||||
if text is not None:
|
||||
self.frame.header = urwid.Pile([
|
||||
urwid.Text(text, align='right'),
|
||||
urwid.Divider()
|
||||
])
|
||||
w = self.frame
|
||||
self.view = w
|
||||
|
||||
# buttons: tuple of name,exitcode
|
||||
def add_buttons(self, buttons):
|
||||
"""Add buttons."""
|
||||
data = []
|
||||
maxlen = 0
|
||||
for name, exitcode in buttons:
|
||||
b = urwid.Button(name, self.button_press)
|
||||
b.exitcode = exitcode
|
||||
b = urwid.AttrWrap(b, 'body', 'focus')
|
||||
data.append(b)
|
||||
maxlen = max(len(name), maxlen)
|
||||
maxlen += 4 # because of '< ... >'
|
||||
self.buttons = urwid.GridFlow(data, maxlen, 3, 1, 'center')
|
||||
self.frame.footer = urwid.Pile([
|
||||
urwid.Divider(),
|
||||
self.buttons
|
||||
], focus_item=1)
|
||||
|
||||
def button_press(self, button):
|
||||
"""Handle button press."""
|
||||
raise DialogExit(button.exitcode)
|
||||
|
||||
def run(self, ui, parent):
|
||||
"""Run the UI."""
|
||||
ui.set_mouse_tracking()
|
||||
size = ui.get_cols_rows()
|
||||
overlay = urwid.Overlay(
|
||||
urwid.LineBox(self.view),
|
||||
parent, 'center', self.width,
|
||||
'middle', self.height
|
||||
)
|
||||
try:
|
||||
while True:
|
||||
canvas = overlay.render(size, focus=True)
|
||||
ui.draw_screen(size, canvas)
|
||||
keys = None
|
||||
while not keys:
|
||||
keys = ui.get_input()
|
||||
for k in keys:
|
||||
if urwid.VERSION < (1, 0, 0):
|
||||
check_mouse_event = urwid.is_mouse_event
|
||||
else:
|
||||
check_mouse_event = urwid.util.is_mouse_event
|
||||
if check_mouse_event(k):
|
||||
event, button, col, row = k
|
||||
overlay.mouse_event(size, event, button, col, row,
|
||||
focus=True)
|
||||
else:
|
||||
if k == 'window resize':
|
||||
size = ui.get_cols_rows()
|
||||
k = self.view.keypress(size, k)
|
||||
if k == 'esc':
|
||||
raise DialogExit(-1)
|
||||
if k:
|
||||
self.unhandled_key(size, k)
|
||||
except DialogExit as e:
|
||||
return self.on_exit(e.args[0])
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
"""Handle dialog exit."""
|
||||
return exitcode, ""
|
||||
|
||||
def unhandled_key(self, size, key):
|
||||
"""Handle keypresses."""
|
||||
pass
|
||||
|
||||
|
||||
class TextDialog(Dialog2):
|
||||
"""Simple dialog with text and "OK" button."""
|
||||
def __init__(self, text, height, width, header=None, align='left',
|
||||
buttons=(_('OK'), 1)):
|
||||
data = [urwid.Text(text)]
|
||||
body = urwid.ListBox(data)
|
||||
body = urwid.AttrWrap(body, 'body')
|
||||
|
||||
Dialog2.__init__(self, header, height + 2, width + 2, body)
|
||||
if type(buttons) == list:
|
||||
self.add_buttons(buttons)
|
||||
else:
|
||||
self.add_buttons([buttons])
|
||||
|
||||
def unhandled_key(self, size, k):
|
||||
"""Handle keys."""
|
||||
if k in ('up', 'page up', 'down', 'page down'):
|
||||
self.frame.set_focus('body')
|
||||
self.view.keypress(size, k)
|
||||
self.frame.set_focus('footer')
|
||||
|
||||
|
||||
class InputDialog(Dialog2):
|
||||
"""Simple dialog with text and entry."""
|
||||
def __init__(self, text, height, width, ok_name=_('OK'), edit_text=''):
|
||||
self.edit = urwid.Edit(wrap='clip', edit_text=edit_text)
|
||||
body = urwid.ListBox([self.edit])
|
||||
body = urwid.AttrWrap(body, 'editbx', 'editfc')
|
||||
|
||||
Dialog2.__init__(self, text, height, width, body)
|
||||
|
||||
self.frame.set_focus('body')
|
||||
self.add_buttons([(ok_name, 0), (_('Cancel'), -1)])
|
||||
|
||||
def unhandled_key(self, size, k):
|
||||
"""Handle keys."""
|
||||
if k in ('up', 'page up'):
|
||||
self.frame.set_focus('body')
|
||||
if k in ('down', 'page down'):
|
||||
self.frame.set_focus('footer')
|
||||
if k == 'enter':
|
||||
# pass enter to the "ok" button
|
||||
self.frame.set_focus('footer')
|
||||
self.view.keypress(size, k)
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
"""Handle dialog exit."""
|
||||
return exitcode, self.edit.get_edit_text()
|
||||
|
||||
|
||||
class ClickCols(urwid.WidgetWrap):
|
||||
"""Clickable menubar."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, items, callback=None, args=None):
|
||||
cols = urwid.Columns(items)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(cols)
|
||||
self.callback = callback
|
||||
self.args = args
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
"""Handle mouse events."""
|
||||
if event == "mouse press":
|
||||
# The keypress dealie in wicd-curses.py expects a list of
|
||||
# keystrokes
|
||||
self.callback([self.args])
|
||||
|
||||
|
||||
class OptCols(urwid.WidgetWrap):
|
||||
"""Htop-style menubar on the bottom of the screen."""
|
||||
# tuples = [(key,desc)], on_event gets passed a key
|
||||
# attrs = (attr_key,attr_desc)
|
||||
# handler = function passed the key of the "button" pressed
|
||||
# mentions of 'left' and right will be converted to <- and -> respectively
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, tuples, handler, attrs=('body', 'infobar'),
|
||||
debug=False):
|
||||
# Find the longest string. Keys for this bar should be no greater than
|
||||
# 2 characters long (e.g., -> for left)
|
||||
# maxlen = 6
|
||||
# for i in tuples:
|
||||
# newmax = len(i[0])+len(i[1])
|
||||
# if newmax > maxlen:
|
||||
# maxlen = newmax
|
||||
|
||||
# Construct the texts
|
||||
textList = []
|
||||
i = 0
|
||||
# callbacks map the text contents to its assigned callback.
|
||||
self.callbacks = []
|
||||
for cmd in tuples:
|
||||
key = reduce(lambda s, tuple: s.replace(tuple[0], tuple[1]), [
|
||||
('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'),
|
||||
('left', '<-'), ('right', '->'),
|
||||
('page up', 'Page Up'), ('page down', 'Page Down'),
|
||||
('esc', 'ESC'), ('enter', 'Enter'), ('s', 'S')], cmd[0])
|
||||
|
||||
if debug:
|
||||
callback = self.debugClick
|
||||
args = cmd[1]
|
||||
else:
|
||||
callback = handler
|
||||
args = cmd[0]
|
||||
# self.callbacks.append(cmd[2])
|
||||
col = ClickCols([
|
||||
('fixed', len(key) + 1, urwid.Text((attrs[0], key + ':'))),
|
||||
urwid.AttrWrap(urwid.Text(cmd[1]), attrs[1])],
|
||||
callback, args)
|
||||
textList.append(col)
|
||||
i += 1
|
||||
if debug:
|
||||
self.debug = urwid.Text("DEBUG_MODE")
|
||||
textList.append(('fixed', 10, self.debug))
|
||||
|
||||
cols = urwid.Columns(textList)
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(cols)
|
||||
|
||||
def debugClick(self, args):
|
||||
"""Debug clicks."""
|
||||
self.debug.set_text(args)
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
"""Handle mouse events."""
|
||||
# Widgets are evenly long (as of current), so...
|
||||
return self._w.mouse_event(size, event, button, x, y, focus)
|
||||
648
wicd/curses/netentry_curses.py
Normal file
648
wicd/curses/netentry_curses.py
Normal file
@@ -0,0 +1,648 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
netentry_curses -- everyone's favorite networks settings dialogs... in text
|
||||
form!
|
||||
"""
|
||||
|
||||
# Copyright (C) 2009 Andrew Psaltis
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
import os
|
||||
|
||||
import urwid
|
||||
from curses_misc import DynWrap, MaskingEdit, ComboBox, error
|
||||
import wicd.misc as misc
|
||||
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||
|
||||
from wicd.translations import language, _
|
||||
|
||||
daemon = None
|
||||
wired = None
|
||||
wireless = None
|
||||
|
||||
|
||||
# Call this first!
|
||||
def dbus_init(dbus_ifaces):
|
||||
"""Initialize DBus interfaces."""
|
||||
global daemon, wired, wireless
|
||||
daemon = dbus_ifaces['daemon']
|
||||
wired = dbus_ifaces['wired']
|
||||
wireless = dbus_ifaces['wireless']
|
||||
|
||||
|
||||
class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
"""
|
||||
Settings dialog.
|
||||
|
||||
Both the wired and the wireless settings preferences dialogs use some of
|
||||
the same fields.
|
||||
This will be used to produce the individual network settings dialogs way
|
||||
far below.
|
||||
"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self):
|
||||
self.ui = None
|
||||
self.body = None
|
||||
|
||||
self.wired = None
|
||||
self.networkid = None
|
||||
|
||||
self.encryption_info = None
|
||||
self.encryption_combo = None
|
||||
self.encrypt_types = None
|
||||
self.encryption_chkbox = None
|
||||
|
||||
static_ip_t = _('Use Static IPs')
|
||||
ip_t = ('editcp', _('IP') + ': ')
|
||||
netmask_t = ('editcp', _('Netmask') + ':')
|
||||
gateway_t = ('editcp', _('Gateway') + ':')
|
||||
|
||||
use_static_dns_t = _('Use Static DNS')
|
||||
use_global_dns_t = _('Use global DNS servers')
|
||||
dns_dom_t = ('editcp', _('DNS domain') + ': ')
|
||||
search_dom_t = ('editcp', _('Search domain') + ':')
|
||||
dns1_t = ('editcp', _('DNS server') + ' 1' + ':' + ' ' * 8)
|
||||
dns2_t = ('editcp', _('DNS server') + ' 2' + ':' + ' ' * 8)
|
||||
dns3_t = ('editcp', _('DNS server') + ' 3' + ':' + ' ' * 8)
|
||||
|
||||
use_dhcp_h_t = _('Use DHCP Hostname')
|
||||
dhcp_h_t = ('editcp', _('DHCP Hostname') + ': ')
|
||||
|
||||
cancel_t = _('Cancel')
|
||||
ok_t = _('OK')
|
||||
|
||||
self.static_ip_cb = urwid.CheckBox(
|
||||
static_ip_t, on_state_change=self.static_ip_toggle)
|
||||
self.ip_edit = DynWrap(urwid.Edit(ip_t), False)
|
||||
self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False)
|
||||
self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False)
|
||||
|
||||
self.static_dns_cb = DynWrap(
|
||||
urwid.CheckBox(use_static_dns_t, on_state_change=self.dns_toggle),
|
||||
True, ('body', 'editnfc'), None)
|
||||
self.global_dns_cb = DynWrap(
|
||||
urwid.CheckBox(use_global_dns_t, on_state_change=self.dns_toggle),
|
||||
False, ('body', 'editnfc'), None)
|
||||
self.checkb_cols = urwid.Columns([self.static_dns_cb,
|
||||
self.global_dns_cb])
|
||||
self.dns_dom_edit = DynWrap(urwid.Edit(dns_dom_t), False)
|
||||
self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False)
|
||||
self.dns1 = DynWrap(urwid.Edit(dns1_t), False)
|
||||
self.dns2 = DynWrap(urwid.Edit(dns2_t), False)
|
||||
self.dns3 = DynWrap(urwid.Edit(dns3_t), False)
|
||||
|
||||
self.use_dhcp_h = urwid.CheckBox(
|
||||
use_dhcp_h_t, False,
|
||||
on_state_change=self.use_dhcp_h_toggle)
|
||||
self.dhcp_h = DynWrap(urwid.Edit(dhcp_h_t), False)
|
||||
|
||||
_blank = urwid.Text('')
|
||||
|
||||
walker = urwid.SimpleListWalker([
|
||||
self.static_ip_cb,
|
||||
self.ip_edit,
|
||||
self.netmask_edit,
|
||||
self.gateway_edit,
|
||||
_blank,
|
||||
self.checkb_cols,
|
||||
self.dns_dom_edit,
|
||||
self.search_dom_edit,
|
||||
self.dns1, self.dns2, self.dns3,
|
||||
_blank,
|
||||
self.use_dhcp_h,
|
||||
self.dhcp_h,
|
||||
_blank
|
||||
])
|
||||
|
||||
self._listbox = urwid.ListBox(walker)
|
||||
self._frame = urwid.Frame(self._listbox)
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(self._frame)
|
||||
|
||||
def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
|
||||
"""Set sensitivity of widget."""
|
||||
self.dhcp_h.set_sensitive(new_state)
|
||||
|
||||
def static_ip_toggle(self, checkb, new_state, user_data=None):
|
||||
"""Set sensitivity of widget."""
|
||||
for w in [self.ip_edit, self.netmask_edit, self.gateway_edit]:
|
||||
w.set_sensitive(new_state)
|
||||
self.static_dns_cb.set_state(new_state)
|
||||
self.static_dns_cb.set_sensitive(not new_state)
|
||||
if new_state:
|
||||
self.checkb_cols.set_focus(self.global_dns_cb)
|
||||
else:
|
||||
self.checkb_cols.set_focus(self.static_dns_cb)
|
||||
|
||||
def dns_toggle(self, checkb, new_state, user_data=None):
|
||||
"""Set sensitivity of widget."""
|
||||
if checkb == self.static_dns_cb.get_w():
|
||||
for w in [
|
||||
self.dns_dom_edit,
|
||||
self.search_dom_edit,
|
||||
self.dns1,
|
||||
self.dns2,
|
||||
self.dns3
|
||||
]:
|
||||
w.set_sensitive(new_state)
|
||||
if not new_state:
|
||||
self.global_dns_cb.set_state(False, do_callback=False)
|
||||
self.global_dns_cb.set_sensitive(new_state)
|
||||
# use_global_dns_cb is DynWrapped
|
||||
if checkb == self.global_dns_cb.get_w():
|
||||
for w in [self.dns_dom_edit, self.search_dom_edit, self.dns1,
|
||||
self.dns2, self.dns3]:
|
||||
w.set_sensitive(not new_state)
|
||||
|
||||
def set_net_prop(self, option, value):
|
||||
"""Set network property. MUST BE OVERRIDEN."""
|
||||
raise NotImplementedError
|
||||
|
||||
# Code totally yanked from netentry.py
|
||||
def save_settings(self):
|
||||
"""Save settings common to wired and wireless settings dialogs."""
|
||||
if self.static_ip_cb.get_state():
|
||||
for i in [
|
||||
self.ip_edit,
|
||||
self.netmask_edit,
|
||||
self.gateway_edit
|
||||
]:
|
||||
i.set_edit_text(i.get_edit_text().strip())
|
||||
|
||||
self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
|
||||
self.set_net_prop("netmask",
|
||||
noneToString(self.netmask_edit.get_edit_text()))
|
||||
self.set_net_prop("gateway",
|
||||
noneToString(self.gateway_edit.get_edit_text()))
|
||||
else:
|
||||
self.set_net_prop("ip", '')
|
||||
self.set_net_prop("netmask", '')
|
||||
self.set_net_prop("gateway", '')
|
||||
|
||||
if self.static_dns_cb.get_state() and \
|
||||
not self.global_dns_cb.get_state():
|
||||
self.set_net_prop('use_static_dns', True)
|
||||
self.set_net_prop('use_global_dns', False)
|
||||
# Strip addressses before checking them in the daemon.
|
||||
for i in [
|
||||
self.dns1,
|
||||
self.dns2,
|
||||
self.dns3,
|
||||
self.dns_dom_edit,
|
||||
self.search_dom_edit
|
||||
]:
|
||||
i.set_edit_text(i.get_edit_text().strip())
|
||||
self.set_net_prop('dns_domain',
|
||||
noneToString(self.dns_dom_edit.get_edit_text()))
|
||||
self.set_net_prop("search_domain",
|
||||
noneToString(self.search_dom_edit
|
||||
.get_edit_text()))
|
||||
self.set_net_prop("dns1", noneToString(self.dns1.get_edit_text()))
|
||||
self.set_net_prop("dns2", noneToString(self.dns2.get_edit_text()))
|
||||
self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
|
||||
elif (self.static_dns_cb.get_state() and
|
||||
self.global_dns_cb.get_state()):
|
||||
self.set_net_prop('use_static_dns', True)
|
||||
self.set_net_prop('use_global_dns', True)
|
||||
else:
|
||||
self.set_net_prop('use_static_dns', False)
|
||||
self.set_net_prop('use_global_dns', False)
|
||||
self.set_net_prop('dns_domain', '')
|
||||
self.set_net_prop("search_domain", '')
|
||||
self.set_net_prop("dns1", '')
|
||||
self.set_net_prop("dns2", '')
|
||||
self.set_net_prop("dns3", '')
|
||||
self.set_net_prop('dhcphostname', self.dhcp_h.get_edit_text())
|
||||
self.set_net_prop('usedhcphostname', self.use_dhcp_h.get_state())
|
||||
|
||||
# Prevent comboboxes from dying.
|
||||
def ready_widgets(self, ui, body):
|
||||
"""Build comboboxes."""
|
||||
self.ui = ui
|
||||
self.body = body
|
||||
self.encryption_combo.build_combobox(body, ui, 14)
|
||||
self.change_encrypt_method()
|
||||
|
||||
def combo_on_change(self, combobox, new_index, user_data=None):
|
||||
"""Handle change of item in the combobox."""
|
||||
self.change_encrypt_method()
|
||||
|
||||
# More or less ripped from netentry.py
|
||||
def change_encrypt_method(self):
|
||||
"""Change encrypt method based on combobox."""
|
||||
# self.lbox_encrypt = urwid.ListBox()
|
||||
self.encryption_info = {}
|
||||
wid, ID = self.encryption_combo.get_focus()
|
||||
methods = self.encrypt_types
|
||||
|
||||
# pylint: disable-msg=E0203
|
||||
if self._w.body.body.__contains__(self.pile_encrypt):
|
||||
self._w.body.body.pop(self._w.body.body.__len__() - 1)
|
||||
|
||||
# If nothing is selected, select the first entry.
|
||||
if ID == -1:
|
||||
self.encryption_combo.set_focus(0)
|
||||
ID = 0
|
||||
|
||||
theList = []
|
||||
for type_ in ['required', 'optional']:
|
||||
fields = methods[ID][type_]
|
||||
for field in fields:
|
||||
try:
|
||||
text = language[field[1].lower().replace(' ', '_')]
|
||||
except KeyError:
|
||||
text = field[1].replace(' ', '_')
|
||||
edit = MaskingEdit(('editcp', text + ': '))
|
||||
edit.set_mask_mode('no_focus')
|
||||
theList.append(edit)
|
||||
# Add the data to any array, so that the information
|
||||
# can be easily accessed by giving the name of the wanted
|
||||
# data.
|
||||
self.encryption_info[field[0]] = [edit, type_]
|
||||
|
||||
if self.wired:
|
||||
edit.set_edit_text(noneToBlankString(
|
||||
wired.GetWiredProperty(field[0])))
|
||||
else:
|
||||
edit.set_edit_text(noneToBlankString(
|
||||
wireless.GetWirelessProperty(self.networkid,
|
||||
field[0])))
|
||||
|
||||
# FIXME: This causes the entire pile to light up upon use.
|
||||
# Make this into a listbox?
|
||||
self.pile_encrypt = DynWrap(urwid.Pile(theList),
|
||||
attrs=('editbx', 'editnfc'))
|
||||
|
||||
self.pile_encrypt.set_sensitive(self.encryption_chkbox.get_state())
|
||||
|
||||
self._w.body.body.insert(self._w.body.body.__len__(),
|
||||
self.pile_encrypt)
|
||||
# self._w.body.body.append(self.pile_encrypt)
|
||||
|
||||
def encryption_toggle(self, chkbox, new_state, user_data=None):
|
||||
"""Set sensitivity of widget."""
|
||||
self.encryption_combo.set_sensitive(new_state)
|
||||
self.pile_encrypt.set_sensitive(new_state)
|
||||
|
||||
|
||||
class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
"""Settings dialog for wired interface."""
|
||||
def __init__(self, name, parent):
|
||||
AdvancedSettingsDialog.__init__(self)
|
||||
self.wired = True
|
||||
|
||||
self.set_default = urwid.CheckBox(
|
||||
_('Use as default profile (overwrites any previous default)'))
|
||||
# self.cur_default =
|
||||
# Add widgets to listbox
|
||||
self._w.body.body.append(self.set_default)
|
||||
|
||||
self.parent = parent
|
||||
encryption_t = _('Use Encryption')
|
||||
|
||||
self.encryption_chkbox = urwid.CheckBox(
|
||||
encryption_t,
|
||||
on_state_change=self.
|
||||
encryption_toggle
|
||||
)
|
||||
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
||||
self.pile_encrypt = None
|
||||
# _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.encryption_chkbox)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.encryption_combo)
|
||||
self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
|
||||
self.set_values()
|
||||
|
||||
self.prof_name = name
|
||||
title = _('Configuring preferences for wired profile "$A"'). \
|
||||
replace('$A', self.prof_name)
|
||||
self._w.header = urwid.Text(('header', title), align='right')
|
||||
|
||||
self.set_values()
|
||||
|
||||
def set_net_prop(self, option, value):
|
||||
"""Set network property."""
|
||||
wired.SetWiredProperty(option, value)
|
||||
|
||||
def set_values(self):
|
||||
"""Load saved values."""
|
||||
self.ip_edit.set_edit_text(self.format_entry("ip"))
|
||||
self.netmask_edit.set_edit_text(self.format_entry("netmask"))
|
||||
self.gateway_edit.set_edit_text(self.format_entry("gateway"))
|
||||
|
||||
self.global_dns_cb.set_state(
|
||||
bool(wired.GetWiredProperty('use_global_dns'))
|
||||
)
|
||||
self.static_dns_cb.set_state(
|
||||
bool(wired.GetWiredProperty('use_static_dns'))
|
||||
)
|
||||
|
||||
# Set static ip checkbox. Forgot to do this the first time.
|
||||
if stringToNone(self.ip_edit.get_edit_text()):
|
||||
self.static_ip_cb.set_state(True)
|
||||
self.dns1.set_edit_text(self.format_entry("dns1"))
|
||||
self.dns2.set_edit_text(self.format_entry("dns2"))
|
||||
self.dns3.set_edit_text(self.format_entry("dns3"))
|
||||
self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain"))
|
||||
self.search_dom_edit.set_edit_text(self.format_entry("search_domain"))
|
||||
|
||||
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
|
||||
|
||||
# Throw the encryption stuff into a list
|
||||
combo_items = []
|
||||
activeID = -1 # Set the menu to this item when we are done
|
||||
for x, enc_type in enumerate(self.encrypt_types):
|
||||
combo_items.append(enc_type['name'])
|
||||
if enc_type['type'] == wired.GetWiredProperty("enctype"):
|
||||
activeID = x
|
||||
self.encryption_combo.set_list(combo_items)
|
||||
|
||||
self.encryption_combo.set_focus(activeID)
|
||||
if wired.GetWiredProperty("encryption_enabled"):
|
||||
self.encryption_chkbox.set_state(True, do_callback=False)
|
||||
self.encryption_combo.set_sensitive(True)
|
||||
# self.lbox_encrypt_info.set_sensitive(True)
|
||||
else:
|
||||
self.encryption_combo.set_focus(0)
|
||||
self.encryption_combo.set_sensitive(False)
|
||||
|
||||
self.change_encrypt_method()
|
||||
|
||||
dhcphname = wired.GetWiredProperty("dhcphostname")
|
||||
if dhcphname is None:
|
||||
dhcphname = os.uname()[1]
|
||||
|
||||
self.use_dhcp_h.set_state(
|
||||
bool(wired.GetWiredProperty('usedhcphostname'))
|
||||
)
|
||||
self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
|
||||
self.dhcp_h.set_edit_text(str(dhcphname))
|
||||
|
||||
def save_settings(self):
|
||||
"""Save settings to disk."""
|
||||
# Check encryption info
|
||||
if self.encryption_chkbox.get_state():
|
||||
encrypt_info = self.encryption_info
|
||||
encrypt_methods = self.encrypt_types
|
||||
self.set_net_prop(
|
||||
"enctype",
|
||||
encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
|
||||
self.set_net_prop("encryption_enabled", True)
|
||||
# Make sure all required fields are filled in.
|
||||
for entry_info in list(encrypt_info.values()):
|
||||
if entry_info[0].get_edit_text() == "" \
|
||||
and entry_info[1] == 'required':
|
||||
error(
|
||||
self.ui,
|
||||
self.parent,
|
||||
"%s (%s)" % (
|
||||
_('Required encryption information is missing.'),
|
||||
entry_info[0].get_caption()[0:-2]
|
||||
)
|
||||
)
|
||||
return False
|
||||
|
||||
for entry_key, entry_info in list(encrypt_info.items()):
|
||||
self.set_net_prop(entry_key, noneToString(entry_info[0].
|
||||
get_edit_text()))
|
||||
else:
|
||||
self.set_net_prop("enctype", "None")
|
||||
self.set_net_prop("encryption_enabled", False)
|
||||
|
||||
AdvancedSettingsDialog.save_settings(self)
|
||||
if self.set_default.get_state():
|
||||
wired.UnsetWiredDefault()
|
||||
if self.set_default.get_state():
|
||||
set_default = True
|
||||
else:
|
||||
set_default = False
|
||||
wired.SetWiredProperty("default", set_default)
|
||||
wired.SaveWiredNetworkProfile(self.prof_name)
|
||||
return True
|
||||
|
||||
def format_entry(self, label):
|
||||
"""Helper method to fetch and format wired properties."""
|
||||
return noneToBlankString(wired.GetWiredProperty(label))
|
||||
|
||||
def prerun(self, ui, dim, display):
|
||||
pass
|
||||
|
||||
|
||||
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
"""Settings dialog for wireless interfaces."""
|
||||
def __init__(self, networkID, parent):
|
||||
AdvancedSettingsDialog.__init__(self)
|
||||
self.wired = False
|
||||
|
||||
self.bitrates = None
|
||||
|
||||
self.networkid = networkID
|
||||
self.parent = parent
|
||||
global_settings_t = \
|
||||
_('Use these settings for all networks sharing this essid')
|
||||
encryption_t = _('Use Encryption')
|
||||
autoconnect_t = _('Automatically connect to this network')
|
||||
bitrate_t = _('Wireless bitrate')
|
||||
allow_lower_bitrates_t = _('Allow lower bitrates')
|
||||
|
||||
self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
|
||||
self.encryption_chkbox = urwid.CheckBox(
|
||||
encryption_t,
|
||||
on_state_change=self.
|
||||
encryption_toggle
|
||||
)
|
||||
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
||||
self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
|
||||
self.bitrate_combo = ComboBox(bitrate_t)
|
||||
self.allow_lower_bitrates_chkbox = \
|
||||
urwid.CheckBox(allow_lower_bitrates_t)
|
||||
|
||||
self.pile_encrypt = None
|
||||
# _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.bitrate_combo)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.allow_lower_bitrates_chkbox)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(urwid.Text(''))
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.global_settings_chkbox)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.autoconnect_chkbox)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.encryption_chkbox)
|
||||
# pylint: disable-msg=E1103
|
||||
self._listbox.body.append(self.encryption_combo)
|
||||
self.encrypt_types = misc.LoadEncryptionMethods()
|
||||
self.set_values()
|
||||
|
||||
title = (_('Configuring preferences for wireless network "$A" ($B)')
|
||||
.replace('$A', wireless.GetWirelessProperty(networkID,
|
||||
'essid'))
|
||||
.replace('$B', wireless.GetWirelessProperty(networkID,
|
||||
'bssid')))
|
||||
self._w.header = urwid.Text(('header', title), align='right')
|
||||
|
||||
def set_values(self):
|
||||
"""Set the various network settings to the right values."""
|
||||
networkID = self.networkid
|
||||
self.ip_edit.set_edit_text(self.format_entry(networkID, "ip"))
|
||||
self.netmask_edit.set_edit_text(self.format_entry(networkID,
|
||||
"netmask"))
|
||||
self.gateway_edit.set_edit_text(self.format_entry(networkID,
|
||||
"gateway"))
|
||||
|
||||
self.global_dns_cb.set_state(
|
||||
bool(wireless.GetWirelessProperty(networkID, 'use_global_dns')))
|
||||
self.static_dns_cb.set_state(
|
||||
bool(wireless.GetWirelessProperty(networkID, 'use_static_dns')))
|
||||
|
||||
if stringToNone(self.ip_edit.get_edit_text()):
|
||||
self.static_ip_cb.set_state(True)
|
||||
self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
|
||||
self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
|
||||
self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
|
||||
self.dns_dom_edit.set_edit_text(
|
||||
self.format_entry(networkID, "dns_domain")
|
||||
)
|
||||
self.search_dom_edit.set_edit_text(
|
||||
self.format_entry(networkID, "search_domain")
|
||||
)
|
||||
|
||||
self.autoconnect_chkbox.set_state(
|
||||
to_bool(self.format_entry(networkID, "automatic"))
|
||||
)
|
||||
|
||||
self.bitrates = wireless.GetAvailableBitrates()
|
||||
self.bitrates.append('auto')
|
||||
self.bitrate_combo.set_list(self.bitrates)
|
||||
self.bitrate_combo.set_focus(
|
||||
self.bitrates.index(
|
||||
wireless.GetWirelessProperty(networkID, 'bitrate')
|
||||
)
|
||||
)
|
||||
self.allow_lower_bitrates_chkbox.set_state(
|
||||
to_bool(self.format_entry(networkID, 'allow_lower_bitrates'))
|
||||
)
|
||||
|
||||
# self.reset_static_checkboxes()
|
||||
self.encryption_chkbox.set_state(
|
||||
bool(wireless.GetWirelessProperty(networkID, 'encryption')),
|
||||
do_callback=False)
|
||||
self.global_settings_chkbox.set_state(
|
||||
bool(wireless.GetWirelessProperty(networkID,
|
||||
'use_settings_globally')))
|
||||
|
||||
# Throw the encryption stuff into a list
|
||||
combo_items = []
|
||||
activeID = -1 # Set the menu to this item when we are done
|
||||
for x, enc_type in enumerate(self.encrypt_types):
|
||||
combo_items.append(enc_type['name'])
|
||||
if enc_type['type'] == wireless.GetWirelessProperty(networkID,
|
||||
"enctype"):
|
||||
activeID = x
|
||||
self.encryption_combo.set_list(combo_items)
|
||||
|
||||
self.encryption_combo.set_focus(activeID)
|
||||
if activeID != -1:
|
||||
self.encryption_chkbox.set_state(True, do_callback=False)
|
||||
self.encryption_combo.set_sensitive(True)
|
||||
# self.lbox_encrypt_info.set_sensitive(True)
|
||||
else:
|
||||
self.encryption_combo.set_focus(0)
|
||||
|
||||
self.change_encrypt_method()
|
||||
dhcphname = wireless.GetWirelessProperty(networkID, "dhcphostname")
|
||||
if dhcphname is None:
|
||||
dhcphname = os.uname()[1]
|
||||
self.use_dhcp_h.set_state(
|
||||
bool(wireless.GetWirelessProperty(networkID, 'usedhcphostname'))
|
||||
)
|
||||
self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
|
||||
self.dhcp_h.set_edit_text(str(dhcphname))
|
||||
|
||||
def set_net_prop(self, option, value):
|
||||
"""Sets the given option to the given value for this network."""
|
||||
wireless.SetWirelessProperty(self.networkid, option, value)
|
||||
|
||||
def format_entry(self, networkid, label):
|
||||
"""Helper method for fetching/formatting wireless properties."""
|
||||
return noneToBlankString(wireless.GetWirelessProperty(networkid,
|
||||
label))
|
||||
|
||||
# Ripped from netentry.py
|
||||
def save_settings(self):
|
||||
"""Save settings to disk."""
|
||||
# Check encryption info
|
||||
if self.encryption_chkbox.get_state():
|
||||
encrypt_info = self.encryption_info
|
||||
encrypt_methods = self.encrypt_types
|
||||
self.set_net_prop(
|
||||
"enctype",
|
||||
encrypt_methods[self.encryption_combo.get_focus()[1]]['type']
|
||||
)
|
||||
# Make sure all required fields are filled in.
|
||||
for entry_info in list(encrypt_info.values()):
|
||||
if (entry_info[0].get_edit_text() == "" and
|
||||
entry_info[1] == 'required'):
|
||||
error(self.ui, self.parent, "%s (%s)" %
|
||||
(_('Required encryption information is missing.'),
|
||||
entry_info[0].get_caption()[0:-2]))
|
||||
return False
|
||||
|
||||
for entry_key, entry_info in list(encrypt_info.items()):
|
||||
self.set_net_prop(entry_key, noneToString(entry_info[0].
|
||||
get_edit_text()))
|
||||
elif (not self.encryption_chkbox.get_state() and
|
||||
wireless.GetWirelessProperty(self.networkid, "encryption")):
|
||||
# Encrypt checkbox is off, but the network needs it.
|
||||
error(self.ui, self.parent,
|
||||
_('This network requires encryption to be enabled.'))
|
||||
return False
|
||||
else:
|
||||
self.set_net_prop("enctype", "None")
|
||||
AdvancedSettingsDialog.save_settings(self)
|
||||
|
||||
# Save the autoconnect setting. This is not where it originally was
|
||||
# in the GTK UI.
|
||||
self.set_net_prop("automatic", self.autoconnect_chkbox.get_state())
|
||||
|
||||
if self.global_settings_chkbox.get_state():
|
||||
self.set_net_prop('use_settings_globally', True)
|
||||
else:
|
||||
self.set_net_prop('use_settings_globally', False)
|
||||
wireless.RemoveGlobalEssidEntry(self.networkid)
|
||||
|
||||
self.set_net_prop(
|
||||
'bitrate',
|
||||
self.bitrates[self.bitrate_combo.get_focus()[1]]
|
||||
)
|
||||
self.set_net_prop(
|
||||
'allow_lower_bitrates',
|
||||
self.allow_lower_bitrates_chkbox.get_state()
|
||||
)
|
||||
wireless.SaveWirelessNetworkProfile(self.networkid)
|
||||
return True
|
||||
|
||||
def ready_widgets(self, ui, body):
|
||||
"""Build comboboxes."""
|
||||
AdvancedSettingsDialog.ready_widgets(self, ui, body)
|
||||
self.ui = ui
|
||||
self.body = body
|
||||
self.bitrate_combo.build_combobox(body, ui, 17)
|
||||
418
wicd/curses/prefs_curses.py
Normal file
418
wicd/curses/prefs_curses.py
Normal file
@@ -0,0 +1,418 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""prefs_curses.py -- Pretty, tabbable, console preferences dialog"""
|
||||
|
||||
# Copyright (C) 2008-2009 Andrew Psaltis
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
import urwid
|
||||
import urwid.curses_display
|
||||
|
||||
from wicd import misc
|
||||
from wicd.translations import _
|
||||
from curses_misc import SelText, DynWrap, DynRadioButton, ComboBox, TabColumns
|
||||
|
||||
daemon = None
|
||||
wireless = None
|
||||
wired = None
|
||||
|
||||
|
||||
class PrefsDialog(urwid.WidgetWrap):
|
||||
"""Preferences dialog."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, body, pos, ui, dbus=None):
|
||||
global daemon, wireless, wired
|
||||
|
||||
self.thebackends = None
|
||||
self.backends = None
|
||||
self.wpadrivers = None
|
||||
self.thedrivers = None
|
||||
|
||||
daemon = dbus['daemon']
|
||||
wireless = dbus['wireless']
|
||||
wired = dbus['wired']
|
||||
|
||||
width, height = ui.get_cols_rows()
|
||||
height -= 3
|
||||
# width = 80
|
||||
# height = 20
|
||||
# Stuff that goes at the top
|
||||
|
||||
header0_t = _('General Settings')
|
||||
header1_t = _('External Programs')
|
||||
header2_t = _('Advanced Settings')
|
||||
self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active',
|
||||
'focus')
|
||||
self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
|
||||
self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
|
||||
title = ('Preferences')
|
||||
|
||||
# Blank line
|
||||
_blank = urwid.Text('')
|
||||
|
||||
# Text in the widgets
|
||||
|
||||
# General Settings
|
||||
net_cat_t = ('header', ('Network Interfaces'))
|
||||
wired_t = ('editcp', ('Wired Interface') + ': ')
|
||||
wless_t = ('editcp', ('Wireless Interface') + ':')
|
||||
always_show_wired_t = _('Always show wired interface')
|
||||
prefer_wired_t = _('Always switch to wired connection when available')
|
||||
|
||||
global_dns_cat_t = ('header', _('Global DNS servers'))
|
||||
global_dns_t = ('editcp', _('Use global DNS servers'))
|
||||
dns_dom_t = ('editcp', ' ' + _('DNS domain') + ': ')
|
||||
search_dom_t = ('editcp', ' ' + _('Search domain') + ':')
|
||||
dns1_t = ('editcp', ' ' + _('DNS server') + ' 1: ')
|
||||
dns2_t = ('editcp', ' ' + _('DNS server') + ' 2: ')
|
||||
dns3_t = ('editcp', ' ' + _('DNS server') + ' 3: ')
|
||||
|
||||
wired_auto_cat_t = ('header', _('Wired Autoconnect Settings'))
|
||||
wired_auto_1_t = _('Use default profile on wired autoconnect')
|
||||
wired_auto_2_t = _('Prompt for profile on wired autoconnect')
|
||||
wired_auto_3_t = _('Use last used profile on wired autoconnect')
|
||||
|
||||
auto_reconn_cat_t = ('header', _('Automatic Reconnection'))
|
||||
auto_reconn_t = _('Automatically reconnect on connection loss')
|
||||
|
||||
# External Programs
|
||||
automatic_t = _('Automatic (recommended)')
|
||||
|
||||
dhcp_header_t = ('header', _('DHCP Client'))
|
||||
# Automatic
|
||||
dhcp1_t = 'dhclient'
|
||||
dhcp2_t = 'dhcpcd'
|
||||
dhcp3_t = 'pump'
|
||||
dhcp4_t = 'udhcpc'
|
||||
|
||||
wired_detect_header_t = ('header', _('Wired Link Detection'))
|
||||
wired1_t = 'ethtool'
|
||||
wired2_t = 'mii-tool'
|
||||
|
||||
flush_header_t = ('header', _('Route Table Flushing'))
|
||||
flush1_t = 'ip'
|
||||
flush2_t = 'route'
|
||||
|
||||
# Advanced Settings
|
||||
wpa_cat_t = ('header', _('WPA Supplicant'))
|
||||
wpa_t = ('editcp', 'Driver:')
|
||||
wpa_list = []
|
||||
wpa_warn_t = ('important', _('You should almost always use wext as '
|
||||
'the WPA supplicant driver'))
|
||||
|
||||
backend_cat_t = ('header', _('Backend'))
|
||||
backend_t = _('Backend') + ':'
|
||||
backend_list = []
|
||||
|
||||
debug_cat_t = ('header', _('Debugging'))
|
||||
debug_mode_t = _('Enable debug mode')
|
||||
|
||||
wless_cat_t = ('header', _('Wireless Interface'))
|
||||
use_dbm_t = _('Use dBm to measure signal strength')
|
||||
verify_ap_t = _('Ping static gateways after connecting to verify '
|
||||
'association')
|
||||
|
||||
# UI Widgets
|
||||
|
||||
# General Settings
|
||||
self.net_cat = urwid.Text(net_cat_t)
|
||||
self.wired_edit = \
|
||||
urwid.AttrWrap(urwid.Edit(wired_t), 'editbx', 'editfc')
|
||||
self.wless_edit = \
|
||||
urwid.AttrWrap(urwid.Edit(wless_t), 'editbx', 'editfc')
|
||||
self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
|
||||
self.global_dns_cat = urwid.Text(global_dns_cat_t)
|
||||
# Default the global DNS settings to off. They will be reenabled later
|
||||
# if so required.
|
||||
global_dns_state = False
|
||||
self.global_dns_checkb = urwid.CheckBox(global_dns_t, global_dns_state,
|
||||
on_state_change=self.
|
||||
global_dns_trigger)
|
||||
self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
|
||||
self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
|
||||
self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state)
|
||||
self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
|
||||
self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state)
|
||||
|
||||
self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)
|
||||
|
||||
self.wired_auto_l = []
|
||||
self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
|
||||
self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,
|
||||
wired_auto_1_t)
|
||||
self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,
|
||||
wired_auto_2_t)
|
||||
self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,
|
||||
wired_auto_2_t)
|
||||
|
||||
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
|
||||
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
|
||||
generalLB = urwid.ListBox([
|
||||
self.net_cat,
|
||||
self.wless_edit, # _blank,
|
||||
self.wired_edit,
|
||||
self.always_show_wired_checkb,
|
||||
self.prefer_wired_chkbx, _blank,
|
||||
self.global_dns_cat,
|
||||
self.global_dns_checkb, # _blank,
|
||||
self.search_dom, self.dns_dom,
|
||||
self.dns1, self.dns2, self.dns3, _blank,
|
||||
self.wired_auto_cat,
|
||||
self.wired_auto_1,
|
||||
self.wired_auto_2,
|
||||
self.wired_auto_3, _blank,
|
||||
self.auto_reconn_cat,
|
||||
self.auto_reconn_checkb
|
||||
])
|
||||
|
||||
# External Programs tab
|
||||
|
||||
automatic_t = _('Automatic (recommended)')
|
||||
|
||||
self.dhcp_header = urwid.Text(dhcp_header_t)
|
||||
self.dhcp_l = []
|
||||
|
||||
# Order of these is flipped in the actual interface,
|
||||
# (2, 3, 1 -> dhcpcd, pump, dhclient), because dhclient often doesn't
|
||||
# like to work on several distros.
|
||||
self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
|
||||
self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
|
||||
self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
|
||||
self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
|
||||
self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
|
||||
self.dhcp_l = [
|
||||
self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
|
||||
]
|
||||
|
||||
self.wired_l = []
|
||||
self.wired_detect_header = urwid.Text(wired_detect_header_t)
|
||||
self.wired0 = urwid.RadioButton(self.wired_l, automatic_t)
|
||||
self.wired1 = DynRadioButton(self.wired_l, wired1_t)
|
||||
self.wired2 = DynRadioButton(self.wired_l, wired2_t)
|
||||
self.wired_l = [self.wired0, self.wired1, self.wired2]
|
||||
|
||||
self.flush_l = []
|
||||
self.flush_header = urwid.Text(flush_header_t)
|
||||
self.flush0 = urwid.RadioButton(self.flush_l, automatic_t)
|
||||
self.flush1 = DynRadioButton(self.flush_l, flush1_t)
|
||||
self.flush2 = DynRadioButton(self.flush_l, flush2_t)
|
||||
self.flush_l = [self.flush0, self.flush1, self.flush2]
|
||||
|
||||
externalLB = urwid.ListBox([
|
||||
self.dhcp_header,
|
||||
self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1, self.dhcp4,
|
||||
_blank,
|
||||
self.wired_detect_header,
|
||||
self.wired0, self.wired1, self.wired2,
|
||||
_blank,
|
||||
self.flush_header,
|
||||
self.flush0, self.flush1, self.flush2
|
||||
])
|
||||
|
||||
# Advanced settings
|
||||
|
||||
self.wpa_cat = urwid.Text(wpa_cat_t)
|
||||
self.wpa_cbox = ComboBox(wpa_t)
|
||||
self.wpa_warn = urwid.Text(wpa_warn_t)
|
||||
|
||||
self.backend_cat = urwid.Text(backend_cat_t)
|
||||
self.backend_cbox = ComboBox(backend_t)
|
||||
|
||||
self.debug_cat = urwid.Text(debug_cat_t)
|
||||
self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)
|
||||
|
||||
self.wless_cat = urwid.Text(wless_cat_t)
|
||||
self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
|
||||
self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)
|
||||
|
||||
advancedLB = urwid.ListBox([
|
||||
self.wpa_cat,
|
||||
self.wpa_cbox, self.wpa_warn, _blank,
|
||||
self.backend_cat,
|
||||
self.backend_cbox, _blank,
|
||||
self.debug_cat,
|
||||
self.debug_mode_checkb, _blank,
|
||||
self.wless_cat,
|
||||
self.use_dbm_checkb, _blank,
|
||||
self.verify_ap_checkb, _blank
|
||||
])
|
||||
|
||||
headerList = [self.header0, self.header1, self.header2]
|
||||
lbList = [generalLB, externalLB, advancedLB]
|
||||
self.tab_map = {
|
||||
self.header0: generalLB,
|
||||
self.header1: externalLB,
|
||||
self.header2: advancedLB
|
||||
}
|
||||
|
||||
# self.load_settings()
|
||||
|
||||
self.tabs = TabColumns(headerList, lbList, _('Preferences'))
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(self.tabs)
|
||||
|
||||
def load_settings(self):
|
||||
"""Load settings to be used in the dialog."""
|
||||
# General Settings
|
||||
# ComboBox does not like dbus.Strings as text markups. My fault. :/
|
||||
wless_iface = str(daemon.GetWirelessInterface())
|
||||
wired_iface = str(daemon.GetWiredInterface())
|
||||
self.wless_edit.set_edit_text(wless_iface)
|
||||
self.wired_edit.set_edit_text(wired_iface)
|
||||
|
||||
self.always_show_wired_checkb.set_state(
|
||||
daemon.GetAlwaysShowWiredInterface())
|
||||
self.prefer_wired_chkbx.set_state(daemon.GetPreferWiredNetwork())
|
||||
# DNS
|
||||
self.global_dns_checkb.set_state(daemon.GetUseGlobalDNS())
|
||||
theDNS = daemon.GetGlobalDNSAddresses()
|
||||
|
||||
i = 0
|
||||
for w in (self.dns1, self.dns2, self.dns3, self.dns_dom,
|
||||
self.search_dom):
|
||||
w.set_edit_text(misc.noneToBlankString(theDNS[i]))
|
||||
i += 1
|
||||
|
||||
# Wired Automatic Connection
|
||||
self.wired_auto_l[daemon.GetWiredAutoConnectMethod() - 1]
|
||||
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
|
||||
|
||||
def find_avail(apps):
|
||||
"""Find available apps."""
|
||||
for app in apps[1:]:
|
||||
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
|
||||
|
||||
# External Programs
|
||||
find_avail(self.dhcp_l)
|
||||
dhcp_method = daemon.GetDHCPClient()
|
||||
self.dhcp_l[dhcp_method].set_state(True)
|
||||
|
||||
find_avail(self.wired_l)
|
||||
wired_link_method = daemon.GetLinkDetectionTool()
|
||||
self.wired_l[wired_link_method].set_state(True)
|
||||
|
||||
find_avail(self.flush_l)
|
||||
flush_method = daemon.GetFlushTool()
|
||||
self.flush_l[flush_method].set_state(True)
|
||||
|
||||
# Advanced settings
|
||||
# wpa_supplicant janx
|
||||
self.wpadrivers = wireless.GetWpaSupplicantDrivers()
|
||||
self.wpadrivers.append("ralink_legacy")
|
||||
self.wpadrivers.append('none')
|
||||
# Same as above with the dbus.String
|
||||
self.thedrivers = [str(w) for w in self.wpadrivers]
|
||||
self.wpa_cbox.set_list(self.thedrivers)
|
||||
|
||||
# Pick where to begin first:
|
||||
def_driver = daemon.GetWPADriver()
|
||||
try:
|
||||
self.wpa_cbox.set_focus(self.wpadrivers.index(def_driver))
|
||||
except ValueError:
|
||||
pass # It defaults to 0 anyway (I hope)
|
||||
|
||||
self.backends = daemon.GetBackendList()
|
||||
self.thebackends = [str(w) for w in self.backends]
|
||||
self.backend_cbox.set_list(self.thebackends)
|
||||
cur_backend = daemon.GetSavedBackend()
|
||||
try:
|
||||
self.backend_cbox.set_focus(self.thebackends.index(cur_backend))
|
||||
except ValueError:
|
||||
self.backend_cbox.set_focus(0)
|
||||
|
||||
# Three last checkboxes
|
||||
self.debug_mode_checkb.set_state(daemon.GetDebugMode())
|
||||
self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
|
||||
self.verify_ap_checkb.set_state(daemon.GetShouldVerifyAp())
|
||||
|
||||
def save_settings(self):
|
||||
"""Pushes the selected settings to the daemon.
|
||||
This exact order is found in prefs.py"""
|
||||
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
|
||||
|
||||
for i in [
|
||||
self.dns1, self.dns2, self.dns3,
|
||||
self.dns_dom, self.search_dom, self.dns_dom
|
||||
]:
|
||||
i.set_edit_text(i.get_edit_text().strip())
|
||||
|
||||
daemon.SetGlobalDNS(
|
||||
self.dns1.get_edit_text(),
|
||||
self.dns2.get_edit_text(),
|
||||
self.dns3.get_edit_text(),
|
||||
self.dns_dom.get_edit_text(),
|
||||
self.search_dom.get_edit_text()
|
||||
)
|
||||
daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
|
||||
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
|
||||
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
|
||||
daemon.SetAlwaysShowWiredInterface(
|
||||
self.always_show_wired_checkb.get_state()
|
||||
)
|
||||
daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
|
||||
daemon.SetDebugMode(self.debug_mode_checkb.get_state())
|
||||
daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
|
||||
daemon.SetShouldVerifyAp(int(self.verify_ap_checkb.get_state()))
|
||||
daemon.SetPreferWiredNetwork(bool(self.prefer_wired_chkbx.get_state()))
|
||||
if self.wired_auto_2.get_state():
|
||||
daemon.SetWiredAutoConnectMethod(2)
|
||||
elif self.wired_auto_3.get_state():
|
||||
daemon.SetWiredAutoConnectMethod(3)
|
||||
else:
|
||||
daemon.SetWiredAutoConnectMethod(1)
|
||||
|
||||
daemon.SetBackend(self.backends[self.backend_cbox.get_focus()[1]])
|
||||
|
||||
# External Programs Tab
|
||||
if self.dhcp0.get_state():
|
||||
dhcp_client = misc.AUTO
|
||||
elif self.dhcp1.get_state():
|
||||
dhcp_client = misc.DHCLIENT
|
||||
elif self.dhcp2.get_state():
|
||||
dhcp_client = misc.DHCPCD
|
||||
elif self.dhcp3.get_state():
|
||||
dhcp_client = misc.PUMP
|
||||
else:
|
||||
dhcp_client = misc.UDHCPC
|
||||
daemon.SetDHCPClient(dhcp_client)
|
||||
|
||||
if self.wired0.get_state():
|
||||
link_tool = misc.AUTO
|
||||
elif self.wired1.get_state():
|
||||
link_tool = misc.ETHTOOL
|
||||
else:
|
||||
link_tool = misc.MIITOOL
|
||||
daemon.SetLinkDetectionTool(link_tool)
|
||||
|
||||
if self.flush0.get_state():
|
||||
flush_tool = misc.AUTO
|
||||
elif self.flush1.get_state():
|
||||
flush_tool = misc.IP
|
||||
else:
|
||||
flush_tool = misc.ROUTE
|
||||
daemon.SetFlushTool(flush_tool)
|
||||
|
||||
def global_dns_trigger(self, check_box, new_state, user_data=None):
|
||||
"""DNS CheckBox callback."""
|
||||
for w in (self.dns1, self.dns2, self.dns3, self.dns_dom,
|
||||
self.search_dom):
|
||||
w.set_sensitive(new_state)
|
||||
|
||||
def ready_widgets(self, ui, body):
|
||||
"""Build comboboxes."""
|
||||
self.wpa_cbox.build_combobox(body, ui, 4)
|
||||
self.backend_cbox.build_combobox(body, ui, 8)
|
||||
1298
wicd/curses/wicd_curses.py
Normal file
1298
wicd/curses/wicd_curses.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user