mirror of
https://github.com/gryf/wicd.git
synced 2026-02-20 08:55:45 +01:00
Style changes for python files
This commit is contained in:
@@ -23,16 +23,17 @@ Also recycles a lot of configscript.py, too. :-)
|
||||
# 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
|
||||
|
||||
import urwid
|
||||
import urwid.curses_display
|
||||
import sys
|
||||
import os
|
||||
|
||||
ui = None
|
||||
frame = None
|
||||
pre_entry = None
|
||||
@@ -42,20 +43,18 @@ post_disconnect_entry = None
|
||||
|
||||
|
||||
def main(argv):
|
||||
""" Main function. """
|
||||
"""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'),
|
||||
])
|
||||
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]
|
||||
@@ -70,69 +69,69 @@ def main(argv):
|
||||
|
||||
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')
|
||||
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')
|
||||
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'))),
|
||||
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'))),
|
||||
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'
|
||||
)
|
||||
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', 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')
|
||||
])
|
||||
# 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())
|
||||
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. """
|
||||
"""Callback."""
|
||||
global OK_PRESSED
|
||||
OK_PRESSED = True
|
||||
|
||||
|
||||
def cancel_callback(button_object, user_data=None):
|
||||
""" Callback. """
|
||||
"""Callback."""
|
||||
global CANCEL_PRESSED
|
||||
CANCEL_PRESSED = True
|
||||
|
||||
|
||||
def run():
|
||||
""" Run the UI. """
|
||||
"""Run the UI."""
|
||||
dim = ui.get_cols_rows()
|
||||
ui.set_mouse_tracking()
|
||||
|
||||
@@ -147,7 +146,7 @@ def run():
|
||||
if "esc" in keys or 'Q' in keys:
|
||||
return False
|
||||
for k in keys:
|
||||
#Send key to underlying widget:
|
||||
# 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)
|
||||
@@ -159,6 +158,7 @@ def run():
|
||||
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.")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -* coding: utf-8 -*-
|
||||
|
||||
""" curses_misc.py: Module for various widgets that are used throughout
|
||||
"""curses_misc.py: Module for various widgets that are used throughout
|
||||
wicd-curses.
|
||||
"""
|
||||
|
||||
@@ -51,7 +51,7 @@ class SelText(urwid.Text):
|
||||
|
||||
|
||||
class NSelListBox(urwid.ListBox):
|
||||
""" Non-selectable ListBox. """
|
||||
"""Non-selectable ListBox."""
|
||||
def selectable(self):
|
||||
return False
|
||||
|
||||
@@ -69,7 +69,7 @@ class DynWrap(urwid.AttrWrap):
|
||||
"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, w, sensitive=True, attrs=('editbx', 'editnfc'),
|
||||
focus_attr='editfc'):
|
||||
focus_attr='editfc'):
|
||||
self._attrs = attrs
|
||||
self._sensitive = sensitive
|
||||
|
||||
@@ -82,11 +82,11 @@ class DynWrap(urwid.AttrWrap):
|
||||
self.__super.__init__(w, cur_attr, focus_attr)
|
||||
|
||||
def get_sensitive(self):
|
||||
""" Getter for sensitive property. """
|
||||
"""Getter for sensitive property."""
|
||||
return self._sensitive
|
||||
|
||||
def set_sensitive(self, state):
|
||||
""" Setter for sensitive property. """
|
||||
"""Setter for sensitive property."""
|
||||
if state:
|
||||
self.set_attr(self._attrs[0])
|
||||
else:
|
||||
@@ -95,11 +95,11 @@ class DynWrap(urwid.AttrWrap):
|
||||
property(get_sensitive, set_sensitive)
|
||||
|
||||
def get_attrs(self):
|
||||
""" Getter for attrs property. """
|
||||
"""Getter for attrs property."""
|
||||
return self._attrs
|
||||
|
||||
def set_attrs(self, attrs):
|
||||
""" Setter for attrs property. """
|
||||
"""Setter for attrs property."""
|
||||
self._attrs = attrs
|
||||
property(get_attrs, set_attrs)
|
||||
|
||||
@@ -108,10 +108,10 @@ class DynWrap(urwid.AttrWrap):
|
||||
|
||||
|
||||
class DynEdit(DynWrap):
|
||||
""" Edit DynWrap'ed to the most common specifications. """
|
||||
"""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'):
|
||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||
caption = ('editcp', caption + ': ')
|
||||
edit = urwid.Edit(caption, edit_text)
|
||||
# pylint: disable-msg=E1101
|
||||
@@ -119,10 +119,10 @@ class DynEdit(DynWrap):
|
||||
|
||||
|
||||
class DynIntEdit(DynWrap):
|
||||
""" IntEdit DynWrap'ed to the most common specifications. """
|
||||
"""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'):
|
||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||
caption = ('editcp', caption + ':')
|
||||
edit = urwid.IntEdit(caption, edit_text)
|
||||
# pylint: disable-msg=E1101
|
||||
@@ -130,20 +130,20 @@ class DynIntEdit(DynWrap):
|
||||
|
||||
|
||||
class DynRadioButton(DynWrap):
|
||||
""" RadioButton DynWrap'ed to the most common specifications. """
|
||||
"""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 + ':')
|
||||
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)
|
||||
user_data)
|
||||
# pylint: disable-msg=E1101
|
||||
self.__super.__init__(button, sensitive, attrs, focus_attr)
|
||||
|
||||
|
||||
class MaskingEditException(Exception):
|
||||
""" Custom exception. """
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
@@ -159,31 +159,31 @@ class MaskingEdit(urwid.Edit):
|
||||
"""
|
||||
# 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='*'):
|
||||
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!')
|
||||
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)
|
||||
allow_tab, edit_pos, layout)
|
||||
|
||||
def get_caption(self):
|
||||
""" Return caption. """
|
||||
"""Return caption."""
|
||||
return self.caption
|
||||
|
||||
def get_mask_mode(self):
|
||||
""" Getter for mask_mode property. """
|
||||
"""Getter for mask_mode property."""
|
||||
return self.mask_mode
|
||||
|
||||
def set_mask_mode(self, mode):
|
||||
""" Setter for mask_mode property."""
|
||||
"""Setter for mask_mode property."""
|
||||
self.mask_mode = mode
|
||||
|
||||
def get_masked_text(self):
|
||||
""" Get masked out text. """
|
||||
"""Get masked out text."""
|
||||
return self.mask_char * len(self.get_edit_text())
|
||||
|
||||
def render(self, xxx_todo_changeme, focus=False):
|
||||
@@ -195,8 +195,8 @@ class MaskingEdit(urwid.Edit):
|
||||
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.
|
||||
# The cache messes this thing up, because I am totally changing
|
||||
# what is displayed.
|
||||
self._invalidate()
|
||||
return canv
|
||||
|
||||
@@ -226,9 +226,10 @@ class TabColumns(urwid.WidgetWrap):
|
||||
# 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')
|
||||
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()
|
||||
@@ -238,31 +239,31 @@ class TabColumns(urwid.WidgetWrap):
|
||||
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)
|
||||
# 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'))
|
||||
])
|
||||
"""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 whether the widget is selectable."""
|
||||
return True
|
||||
|
||||
def keypress(self, size, key):
|
||||
""" Handle keypresses. """
|
||||
"""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":
|
||||
@@ -285,7 +286,7 @@ class TabColumns(urwid.WidgetWrap):
|
||||
return key
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
""" Handle mouse events. """
|
||||
"""Handle mouse events."""
|
||||
wid = self.pile.get_focus().get_body()
|
||||
if wid == self.columns:
|
||||
self.active_tab.set_attr('body')
|
||||
@@ -299,7 +300,7 @@ class TabColumns(urwid.WidgetWrap):
|
||||
|
||||
|
||||
class ComboBoxException(Exception):
|
||||
""" Custom exception. """
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
@@ -314,39 +315,40 @@ class ComboBox(urwid.WidgetWrap):
|
||||
class ComboSpace(urwid.WidgetWrap):
|
||||
"""The actual menu-like space that comes down from the ComboBox"""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, l, body, ui, show_first, pos=(0, 0),
|
||||
attr=('body', 'focus')):
|
||||
def __init__(self, data, body, ui, show_first, pos=(0, 0),
|
||||
attr=('body', 'focus')):
|
||||
"""
|
||||
body : parent widget
|
||||
l : stuff to include in the combobox
|
||||
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(l)
|
||||
# Calculate width and height of the menu widget:
|
||||
height = len(data)
|
||||
width = 0
|
||||
for entry in l:
|
||||
for entry in data:
|
||||
if len(entry) > width:
|
||||
width = len(entry)
|
||||
content = [urwid.AttrWrap(SelText(w), attr[0], attr[1])
|
||||
for w in l]
|
||||
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)
|
||||
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. """
|
||||
"""Show widget."""
|
||||
dim = ui.get_cols_rows()
|
||||
keys = True
|
||||
|
||||
#Event loop:
|
||||
# Event loop:
|
||||
while True:
|
||||
if keys:
|
||||
ui.draw_screen(dim, self.render(dim, True))
|
||||
@@ -363,19 +365,19 @@ class ComboBox(urwid.WidgetWrap):
|
||||
return text
|
||||
|
||||
for k in keys:
|
||||
#Send key to underlying widget:
|
||||
# Send key to underlying widget:
|
||||
self._w.keypress(dim, k)
|
||||
|
||||
#def get_size(self):
|
||||
# def get_size(self):
|
||||
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, label='', l=None, attrs=('body', 'editnfc'),
|
||||
focus_attr='focus', use_enter=True, focus=0, callback=None,
|
||||
user_args=None):
|
||||
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
|
||||
l : stuff to include in the combobox
|
||||
data : stuff to include in the combobox
|
||||
body : parent widget
|
||||
ui : the screen
|
||||
row : where this object is to be found onscreen
|
||||
@@ -388,15 +390,15 @@ class ComboBox(urwid.WidgetWrap):
|
||||
self.label = urwid.Text(label)
|
||||
self.attrs = attrs
|
||||
self.focus_attr = focus_attr
|
||||
if l is None:
|
||||
l = []
|
||||
self.list = l
|
||||
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)
|
||||
focus_attr=focus_attr)
|
||||
# Unicode will kill me sooner or later.
|
||||
if label != '':
|
||||
w = urwid.Columns(
|
||||
@@ -424,12 +426,12 @@ class ComboBox(urwid.WidgetWrap):
|
||||
self.ui = None
|
||||
self.row = None
|
||||
|
||||
def set_list(self, l):
|
||||
""" Populate widget list. """
|
||||
self.list = l
|
||||
def set_list(self, data):
|
||||
"""Populate widget list."""
|
||||
self.list = data
|
||||
|
||||
def set_focus(self, index):
|
||||
""" Set widget focus. """
|
||||
"""Set widget focus."""
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
self.focus = index
|
||||
else:
|
||||
@@ -447,11 +449,11 @@ class ComboBox(urwid.WidgetWrap):
|
||||
self.overlay._listbox.set_focus(index)
|
||||
|
||||
def rebuild_combobox(self):
|
||||
""" Rebuild combobox. """
|
||||
"""Rebuild combobox."""
|
||||
self.build_combobox(self.parent, self.ui, self.row)
|
||||
|
||||
def build_combobox(self, parent, ui, row):
|
||||
""" Build combobox. """
|
||||
"""Build combobox."""
|
||||
s, trash = self.label.get_text()
|
||||
|
||||
if urwid.VERSION < (1, 1, 0):
|
||||
@@ -460,16 +462,16 @@ class ComboBox(urwid.WidgetWrap):
|
||||
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)
|
||||
attrs=self.attrs, focus_attr=self.focus_attr)
|
||||
if str != '':
|
||||
w = urwid.Columns([('fixed', len(s), self.label), self.cbox],
|
||||
dividechars=1)
|
||||
dividechars=1)
|
||||
self.overlay = self.ComboSpace(self.list, parent, ui, index,
|
||||
pos=(len(s) + 1, row))
|
||||
pos=(len(s) + 1, row))
|
||||
else:
|
||||
w = urwid.Columns([self.cbox])
|
||||
self.overlay = self.ComboSpace(self.list, parent, ui, index,
|
||||
pos=(0, row))
|
||||
pos=(0, row))
|
||||
|
||||
self._w = w
|
||||
self._invalidate()
|
||||
@@ -479,7 +481,7 @@ class ComboBox(urwid.WidgetWrap):
|
||||
|
||||
# If we press space or enter, be a combo box!
|
||||
def keypress(self, size, key):
|
||||
""" Handle keypresses. """
|
||||
"""Handle keypresses."""
|
||||
activate = key == ' '
|
||||
if self.use_enter:
|
||||
activate = activate or key == 'enter'
|
||||
@@ -490,43 +492,43 @@ class ComboBox(urwid.WidgetWrap):
|
||||
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'))
|
||||
# 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)
|
||||
self.user_args)
|
||||
return self._w.keypress(size, key)
|
||||
|
||||
def selectable(self):
|
||||
""" Return whether the widget is selectable. """
|
||||
"""Return whether the widget is selectable."""
|
||||
return self.cbox.selectable()
|
||||
|
||||
def get_focus(self):
|
||||
""" Return widget focus. """
|
||||
"""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 # pylint: disable-msg=E1103
|
||||
return None, self._w.focus_position
|
||||
|
||||
def get_sensitive(self):
|
||||
""" Return widget sensitivity. """
|
||||
"""Return widget sensitivity."""
|
||||
return self.cbox.get_sensitive()
|
||||
|
||||
def set_sensitive(self, state):
|
||||
""" Set widget sensitivity. """
|
||||
"""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. """
|
||||
"""Custom exception."""
|
||||
pass
|
||||
|
||||
|
||||
class Dialog2(urwid.WidgetWrap):
|
||||
""" Base class for other dialogs. """
|
||||
"""Base class for other dialogs."""
|
||||
def __init__(self, text, height, width, body=None):
|
||||
self.buttons = None
|
||||
|
||||
@@ -553,28 +555,28 @@ class Dialog2(urwid.WidgetWrap):
|
||||
|
||||
# buttons: tuple of name,exitcode
|
||||
def add_buttons(self, buttons):
|
||||
""" Add buttons. """
|
||||
l = []
|
||||
"""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')
|
||||
l.append(b)
|
||||
data.append(b)
|
||||
maxlen = max(len(name), maxlen)
|
||||
maxlen += 4 # because of '< ... >'
|
||||
self.buttons = urwid.GridFlow(l, maxlen, 3, 1, 'center')
|
||||
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. """
|
||||
"""Handle button press."""
|
||||
raise DialogExit(button.exitcode)
|
||||
|
||||
def run(self, ui, parent):
|
||||
""" Run the UI. """
|
||||
"""Run the UI."""
|
||||
ui.set_mouse_tracking()
|
||||
size = ui.get_cols_rows()
|
||||
overlay = urwid.Overlay(
|
||||
@@ -597,7 +599,7 @@ class Dialog2(urwid.WidgetWrap):
|
||||
if check_mouse_event(k):
|
||||
event, button, col, row = k
|
||||
overlay.mouse_event(size, event, button, col, row,
|
||||
focus=True)
|
||||
focus=True)
|
||||
else:
|
||||
if k == 'window resize':
|
||||
size = ui.get_cols_rows()
|
||||
@@ -610,20 +612,20 @@ class Dialog2(urwid.WidgetWrap):
|
||||
return self.on_exit(e.args[0])
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
""" Handle dialog exit. """
|
||||
"""Handle dialog exit."""
|
||||
return exitcode, ""
|
||||
|
||||
def unhandled_key(self, size, key):
|
||||
""" Handle keypresses. """
|
||||
"""Handle keypresses."""
|
||||
pass
|
||||
|
||||
|
||||
class TextDialog(Dialog2):
|
||||
""" Simple dialog with text and "OK" button. """
|
||||
"""Simple dialog with text and "OK" button."""
|
||||
def __init__(self, text, height, width, header=None, align='left',
|
||||
buttons=(_('OK'), 1)):
|
||||
l = [urwid.Text(text)]
|
||||
body = urwid.ListBox(l)
|
||||
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)
|
||||
@@ -633,7 +635,7 @@ class TextDialog(Dialog2):
|
||||
self.add_buttons([buttons])
|
||||
|
||||
def unhandled_key(self, size, k):
|
||||
""" Handle keys. """
|
||||
"""Handle keys."""
|
||||
if k in ('up', 'page up', 'down', 'page down'):
|
||||
self.frame.set_focus('body')
|
||||
self.view.keypress(size, k)
|
||||
@@ -641,7 +643,7 @@ class TextDialog(Dialog2):
|
||||
|
||||
|
||||
class InputDialog(Dialog2):
|
||||
""" Simple dialog with text and entry. """
|
||||
"""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])
|
||||
@@ -653,7 +655,7 @@ class InputDialog(Dialog2):
|
||||
self.add_buttons([(ok_name, 0), (_('Cancel'), -1)])
|
||||
|
||||
def unhandled_key(self, size, k):
|
||||
""" Handle keys. """
|
||||
"""Handle keys."""
|
||||
if k in ('up', 'page up'):
|
||||
self.frame.set_focus('body')
|
||||
if k in ('down', 'page down'):
|
||||
@@ -664,12 +666,12 @@ class InputDialog(Dialog2):
|
||||
self.view.keypress(size, k)
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
""" Handle dialog exit. """
|
||||
"""Handle dialog exit."""
|
||||
return exitcode, self.edit.get_edit_text()
|
||||
|
||||
|
||||
class ClickCols(urwid.WidgetWrap):
|
||||
""" Clickable menubar. """
|
||||
"""Clickable menubar."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, items, callback=None, args=None):
|
||||
cols = urwid.Columns(items)
|
||||
@@ -679,27 +681,29 @@ class ClickCols(urwid.WidgetWrap):
|
||||
self.args = args
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
""" Handle mouse events. """
|
||||
"""Handle mouse events."""
|
||||
if event == "mouse press":
|
||||
# The keypress dealie in wicd-curses.py expects a list of keystrokes
|
||||
# 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. """
|
||||
"""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):
|
||||
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
|
||||
# maxlen = 6
|
||||
# for i in tuples:
|
||||
# newmax = len(i[0])+len(i[1])
|
||||
# if newmax > maxlen:
|
||||
# maxlen = newmax
|
||||
|
||||
# Construct the texts
|
||||
textList = []
|
||||
@@ -719,7 +723,7 @@ class OptCols(urwid.WidgetWrap):
|
||||
else:
|
||||
callback = handler
|
||||
args = cmd[0]
|
||||
#self.callbacks.append(cmd[2])
|
||||
# self.callbacks.append(cmd[2])
|
||||
col = ClickCols([
|
||||
('fixed', len(key) + 1, urwid.Text((attrs[0], key + ':'))),
|
||||
urwid.AttrWrap(urwid.Text(cmd[1]), attrs[1])],
|
||||
@@ -736,10 +740,10 @@ class OptCols(urwid.WidgetWrap):
|
||||
self.__super.__init__(cols)
|
||||
|
||||
def debugClick(self, args):
|
||||
""" Debug clicks. """
|
||||
"""Debug clicks."""
|
||||
self.debug.set_text(args)
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
""" Handle mouse events. """
|
||||
"""Handle mouse events."""
|
||||
# Widgets are evenly long (as of current), so...
|
||||
return self._w.mouse_event(size, event, button, x, y, focus)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
netentry_curses -- everyone's favorite networks settings dialogs... in text
|
||||
form!
|
||||
netentry_curses -- everyone's favorite networks settings dialogs... in text
|
||||
form!
|
||||
"""
|
||||
|
||||
# Copyright (C) 2009 Andrew Psaltis
|
||||
@@ -20,6 +20,7 @@
|
||||
# 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
|
||||
@@ -27,7 +28,6 @@ import wicd.misc as misc
|
||||
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||
|
||||
from wicd.translations import language, _
|
||||
import os
|
||||
|
||||
daemon = None
|
||||
wired = None
|
||||
@@ -36,7 +36,7 @@ wireless = None
|
||||
|
||||
# Call this first!
|
||||
def dbus_init(dbus_ifaces):
|
||||
""" Initialize DBus interfaces. """
|
||||
"""Initialize DBus interfaces."""
|
||||
global daemon, wired, wireless
|
||||
daemon = dbus_ifaces['daemon']
|
||||
wired = dbus_ifaces['wired']
|
||||
@@ -47,10 +47,10 @@ 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.
|
||||
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):
|
||||
@@ -84,28 +84,20 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
cancel_t = _('Cancel')
|
||||
ok_t = _('OK')
|
||||
|
||||
self.static_ip_cb = urwid.CheckBox(static_ip_t,
|
||||
on_state_change=self.static_ip_toggle)
|
||||
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
|
||||
)
|
||||
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
|
||||
])
|
||||
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)
|
||||
@@ -113,10 +105,8 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
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
|
||||
)
|
||||
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('')
|
||||
@@ -144,11 +134,11 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
self.__super.__init__(self._frame)
|
||||
|
||||
def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
|
||||
""" Set sensitivity of widget. """
|
||||
"""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. """
|
||||
"""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)
|
||||
@@ -159,7 +149,7 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
self.checkb_cols.set_focus(self.static_dns_cb)
|
||||
|
||||
def dns_toggle(self, checkb, new_state, user_data=None):
|
||||
""" Set sensitivity of widget. """
|
||||
"""Set sensitivity of widget."""
|
||||
if checkb == self.static_dns_cb.get_w():
|
||||
for w in [
|
||||
self.dns_dom_edit,
|
||||
@@ -174,17 +164,17 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
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 ]:
|
||||
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. """
|
||||
"""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. """
|
||||
"""Save settings common to wired and wireless settings dialogs."""
|
||||
if self.static_ip_cb.get_state():
|
||||
for i in [
|
||||
self.ip_edit,
|
||||
@@ -195,9 +185,9 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
|
||||
self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
|
||||
self.set_net_prop("netmask",
|
||||
noneToString(self.netmask_edit.get_edit_text()))
|
||||
noneToString(self.netmask_edit.get_edit_text()))
|
||||
self.set_net_prop("gateway",
|
||||
noneToString(self.gateway_edit.get_edit_text()))
|
||||
noneToString(self.gateway_edit.get_edit_text()))
|
||||
else:
|
||||
self.set_net_prop("ip", '')
|
||||
self.set_net_prop("netmask", '')
|
||||
@@ -217,14 +207,15 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
]:
|
||||
i.set_edit_text(i.get_edit_text().strip())
|
||||
self.set_net_prop('dns_domain',
|
||||
noneToString(self.dns_dom_edit.get_edit_text()))
|
||||
noneToString(self.dns_dom_edit.get_edit_text()))
|
||||
self.set_net_prop("search_domain",
|
||||
noneToString(self.search_dom_edit.get_edit_text()))
|
||||
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():
|
||||
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:
|
||||
@@ -240,20 +231,20 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
|
||||
# Prevent comboboxes from dying.
|
||||
def ready_widgets(self, ui, body):
|
||||
""" Build comboboxes. """
|
||||
"""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. """
|
||||
"""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()
|
||||
"""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
|
||||
@@ -288,36 +279,35 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
||||
wired.GetWiredProperty(field[0])))
|
||||
else:
|
||||
edit.set_edit_text(noneToBlankString(
|
||||
wireless.GetWirelessProperty(self.networkid, field[0])))
|
||||
wireless.GetWirelessProperty(self.networkid,
|
||||
field[0])))
|
||||
|
||||
#FIXME: This causes the entire pile to light up upon use.
|
||||
# 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 = 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)
|
||||
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. """
|
||||
"""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. """
|
||||
"""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 =
|
||||
_('Use as default profile (overwrites any previous default)'))
|
||||
# self.cur_default =
|
||||
# Add widgets to listbox
|
||||
self._w.body.body.append(self.set_default)
|
||||
|
||||
@@ -347,11 +337,11 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
self.set_values()
|
||||
|
||||
def set_net_prop(self, option, value):
|
||||
""" Set network property. """
|
||||
"""Set network property."""
|
||||
wired.SetWiredProperty(option, value)
|
||||
|
||||
def set_values(self):
|
||||
""" Load saved values. """
|
||||
"""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"))
|
||||
@@ -375,19 +365,19 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
|
||||
|
||||
# Throw the encryption stuff into a list
|
||||
l = []
|
||||
combo_items = []
|
||||
activeID = -1 # Set the menu to this item when we are done
|
||||
for x, enc_type in enumerate(self.encrypt_types):
|
||||
l.append(enc_type['name'])
|
||||
combo_items.append(enc_type['name'])
|
||||
if enc_type['type'] == wired.GetWiredProperty("enctype"):
|
||||
activeID = x
|
||||
self.encryption_combo.set_list(l)
|
||||
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)
|
||||
# self.lbox_encrypt_info.set_sensitive(True)
|
||||
else:
|
||||
self.encryption_combo.set_focus(0)
|
||||
self.encryption_combo.set_sensitive(False)
|
||||
@@ -405,7 +395,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
self.dhcp_h.set_edit_text(str(dhcphname))
|
||||
|
||||
def save_settings(self):
|
||||
""" Save settings to disk. """
|
||||
"""Save settings to disk."""
|
||||
# Check encryption info
|
||||
if self.encryption_chkbox.get_state():
|
||||
encrypt_info = self.encryption_info
|
||||
@@ -430,7 +420,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
|
||||
for entry_key, entry_info in list(encrypt_info.items()):
|
||||
self.set_net_prop(entry_key, noneToString(entry_info[0].
|
||||
get_edit_text()))
|
||||
get_edit_text()))
|
||||
else:
|
||||
self.set_net_prop("enctype", "None")
|
||||
self.set_net_prop("encryption_enabled", False)
|
||||
@@ -447,7 +437,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
return True
|
||||
|
||||
def format_entry(self, label):
|
||||
""" Helper method to fetch and format wired properties. """
|
||||
"""Helper method to fetch and format wired properties."""
|
||||
return noneToBlankString(wired.GetWiredProperty(label))
|
||||
|
||||
def prerun(self, ui, dim, display):
|
||||
@@ -455,7 +445,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
|
||||
|
||||
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
""" Settings dialog for wireless interfaces. """
|
||||
"""Settings dialog for wireless interfaces."""
|
||||
def __init__(self, networkID, parent):
|
||||
AdvancedSettingsDialog.__init__(self)
|
||||
self.wired = False
|
||||
@@ -502,17 +492,21 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
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'))
|
||||
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. """
|
||||
"""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.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')))
|
||||
@@ -547,32 +541,29 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
to_bool(self.format_entry(networkID, 'allow_lower_bitrates'))
|
||||
)
|
||||
|
||||
#self.reset_static_checkboxes()
|
||||
# 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')
|
||||
)
|
||||
)
|
||||
bool(wireless.GetWirelessProperty(networkID,
|
||||
'use_settings_globally')))
|
||||
|
||||
# Throw the encryption stuff into a list
|
||||
l = []
|
||||
combo_items = []
|
||||
activeID = -1 # Set the menu to this item when we are done
|
||||
for x, enc_type in enumerate(self.encrypt_types):
|
||||
l.append(enc_type['name'])
|
||||
if enc_type['type'] == \
|
||||
wireless.GetWirelessProperty(networkID, "enctype"):
|
||||
combo_items.append(enc_type['name'])
|
||||
if enc_type['type'] == wireless.GetWirelessProperty(networkID,
|
||||
"enctype"):
|
||||
activeID = x
|
||||
self.encryption_combo.set_list(l)
|
||||
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)
|
||||
# self.lbox_encrypt_info.set_sensitive(True)
|
||||
else:
|
||||
self.encryption_combo.set_focus(0)
|
||||
|
||||
@@ -587,16 +578,17 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
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. """
|
||||
"""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))
|
||||
"""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. """
|
||||
"""Save settings to disk."""
|
||||
# Check encryption info
|
||||
if self.encryption_chkbox.get_state():
|
||||
encrypt_info = self.encryption_info
|
||||
@@ -607,29 +599,21 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
)
|
||||
# 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]
|
||||
)
|
||||
)
|
||||
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"):
|
||||
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.')
|
||||
)
|
||||
error(self.ui, self.parent,
|
||||
_('This network requires encryption to be enabled.'))
|
||||
return False
|
||||
else:
|
||||
self.set_net_prop("enctype", "None")
|
||||
@@ -657,7 +641,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
return True
|
||||
|
||||
def ready_widgets(self, ui, body):
|
||||
""" Build comboboxes. """
|
||||
"""Build comboboxes."""
|
||||
AdvancedSettingsDialog.ready_widgets(self, ui, body)
|
||||
self.ui = ui
|
||||
self.body = body
|
||||
|
||||
@@ -32,7 +32,7 @@ wired = None
|
||||
|
||||
|
||||
class PrefsDialog(urwid.WidgetWrap):
|
||||
""" Preferences dialog. """
|
||||
"""Preferences dialog."""
|
||||
# pylint: disable-msg=W0231
|
||||
def __init__(self, body, pos, ui, dbus=None):
|
||||
global daemon, wireless, wired
|
||||
@@ -48,14 +48,15 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
|
||||
width, height = ui.get_cols_rows()
|
||||
height -= 3
|
||||
#width = 80
|
||||
#height = 20
|
||||
# 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.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')
|
||||
@@ -63,9 +64,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
# Blank line
|
||||
_blank = urwid.Text('')
|
||||
|
||||
####
|
||||
#### Text in the widgets
|
||||
####
|
||||
# Text in the widgets
|
||||
|
||||
# General Settings
|
||||
net_cat_t = ('header', ('Network Interfaces'))
|
||||
@@ -90,7 +89,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
auto_reconn_cat_t = ('header', _('Automatic Reconnection'))
|
||||
auto_reconn_t = _('Automatically reconnect on connection loss')
|
||||
|
||||
#### External Programs
|
||||
# External Programs
|
||||
automatic_t = _('Automatic (recommended)')
|
||||
|
||||
dhcp_header_t = ('header', _('DHCP Client'))
|
||||
@@ -108,12 +107,12 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
flush1_t = 'ip'
|
||||
flush2_t = 'route'
|
||||
|
||||
#### Advanced Settings
|
||||
# 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'))
|
||||
wpa_warn_t = ('important', _('You should almost always use wext as '
|
||||
'the WPA supplicant driver'))
|
||||
|
||||
backend_cat_t = ('header', _('Backend'))
|
||||
backend_t = _('Backend') + ':'
|
||||
@@ -124,12 +123,10 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
|
||||
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')
|
||||
verify_ap_t = _('Ping static gateways after connecting to verify '
|
||||
'association')
|
||||
|
||||
####
|
||||
#### UI Widgets
|
||||
####
|
||||
# UI Widgets
|
||||
|
||||
# General Settings
|
||||
self.net_cat = urwid.Text(net_cat_t)
|
||||
@@ -142,10 +139,9 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
# 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.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)
|
||||
@@ -156,9 +152,12 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
|
||||
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_3_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)
|
||||
@@ -180,7 +179,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
self.auto_reconn_checkb
|
||||
])
|
||||
|
||||
#### External Programs tab
|
||||
# External Programs tab
|
||||
|
||||
automatic_t = _('Automatic (recommended)')
|
||||
|
||||
self.dhcp_header = urwid.Text(dhcp_header_t)
|
||||
@@ -223,7 +223,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
self.flush0, self.flush1, self.flush2
|
||||
])
|
||||
|
||||
#### Advanced settings
|
||||
# Advanced settings
|
||||
|
||||
self.wpa_cat = urwid.Text(wpa_cat_t)
|
||||
self.wpa_cbox = ComboBox(wpa_t)
|
||||
self.wpa_warn = urwid.Text(wpa_warn_t)
|
||||
@@ -257,15 +258,16 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
self.header1: externalLB,
|
||||
self.header2: advancedLB
|
||||
}
|
||||
#self.load_settings()
|
||||
|
||||
# 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
|
||||
"""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())
|
||||
@@ -280,7 +282,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
theDNS = daemon.GetGlobalDNSAddresses()
|
||||
|
||||
i = 0
|
||||
for w in self.dns1, self.dns2, self.dns3, self.dns_dom, self.search_dom:
|
||||
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
|
||||
|
||||
@@ -289,11 +292,11 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
|
||||
|
||||
def find_avail(apps):
|
||||
""" Find available apps. """
|
||||
"""Find available apps."""
|
||||
for app in apps[1:]:
|
||||
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
|
||||
|
||||
### External Programs
|
||||
# External Programs
|
||||
find_avail(self.dhcp_l)
|
||||
dhcp_method = daemon.GetDHCPClient()
|
||||
self.dhcp_l[dhcp_method].set_state(True)
|
||||
@@ -306,7 +309,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
flush_method = daemon.GetFlushTool()
|
||||
self.flush_l[flush_method].set_state(True)
|
||||
|
||||
### Advanced settings
|
||||
# Advanced settings
|
||||
# wpa_supplicant janx
|
||||
self.wpadrivers = wireless.GetWpaSupplicantDrivers()
|
||||
self.wpadrivers.append("ralink_legacy")
|
||||
@@ -337,7 +340,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
self.verify_ap_checkb.set_state(daemon.GetShouldVerifyAp())
|
||||
|
||||
def save_settings(self):
|
||||
""" Pushes the selected settings to the daemon.
|
||||
"""Pushes the selected settings to the daemon.
|
||||
This exact order is found in prefs.py"""
|
||||
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
|
||||
|
||||
@@ -404,11 +407,12 @@ class PrefsDialog(urwid.WidgetWrap):
|
||||
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:
|
||||
"""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. """
|
||||
"""Build comboboxes."""
|
||||
self.wpa_cbox.build_combobox(body, ui, 4)
|
||||
self.backend_cbox.build_combobox(body, ui, 8)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user