mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 12:28:08 +01:00
More pylint fixes
This commit is contained in:
@@ -23,10 +23,9 @@ Also recycles a lot of configscript.py, too. :-)
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
|
|
||||||
from wicd import misc
|
|
||||||
from wicd.translations import _
|
from wicd.translations import _
|
||||||
import configscript
|
|
||||||
from configscript import write_scripts, get_script_info, get_val
|
from configscript import write_scripts, get_script_info
|
||||||
from configscript import none_to_blank, blank_to_none
|
from configscript import none_to_blank, blank_to_none
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
@@ -41,6 +40,7 @@ post_entry = None
|
|||||||
pre_disconnect_entry = None
|
pre_disconnect_entry = None
|
||||||
post_disconnect_entry = None
|
post_disconnect_entry = None
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
""" Main function. """
|
""" Main function. """
|
||||||
global ui, frame
|
global ui, frame
|
||||||
@@ -106,7 +106,7 @@ def main(argv):
|
|||||||
frame = urwid.Frame(lbox)
|
frame = urwid.Frame(lbox)
|
||||||
result = ui.run_wrapper(run)
|
result = ui.run_wrapper(run)
|
||||||
|
|
||||||
if result == True:
|
if result:
|
||||||
script_info["pre_entry"] = blank_to_none(pre_entry.get_edit_text())
|
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["post_entry"] = blank_to_none(post_entry.get_edit_text())
|
||||||
script_info["pre_disconnect_entry"] = \
|
script_info["pre_disconnect_entry"] = \
|
||||||
@@ -117,13 +117,22 @@ def main(argv):
|
|||||||
|
|
||||||
OK_PRESSED = False
|
OK_PRESSED = False
|
||||||
CANCEL_PRESSED = False
|
CANCEL_PRESSED = False
|
||||||
|
|
||||||
|
|
||||||
def ok_callback(button_object, user_data=None):
|
def ok_callback(button_object, user_data=None):
|
||||||
|
""" Callback. """
|
||||||
global OK_PRESSED
|
global OK_PRESSED
|
||||||
OK_PRESSED = True
|
OK_PRESSED = True
|
||||||
|
|
||||||
|
|
||||||
def cancel_callback(button_object, user_data=None):
|
def cancel_callback(button_object, user_data=None):
|
||||||
|
""" Callback. """
|
||||||
global CANCEL_PRESSED
|
global CANCEL_PRESSED
|
||||||
CANCEL_PRESSED = True
|
CANCEL_PRESSED = True
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
""" Run the UI. """
|
||||||
dim = ui.get_cols_rows()
|
dim = ui.get_cols_rows()
|
||||||
ui.set_mouse_tracking()
|
ui.set_mouse_tracking()
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import urwid
|
|||||||
|
|
||||||
from wicd.translations import _
|
from wicd.translations import _
|
||||||
|
|
||||||
|
|
||||||
# Uses code that is towards the bottom
|
# Uses code that is towards the bottom
|
||||||
def error(ui, parent, message):
|
def error(ui, parent, message):
|
||||||
"""Shows an error dialog (or something that resembles one)"""
|
"""Shows an error dialog (or something that resembles one)"""
|
||||||
@@ -35,6 +36,7 @@ def error(ui, parent, message):
|
|||||||
dialog = TextDialog(message, 6, 40, ('important', 'ERROR'))
|
dialog = TextDialog(message, 6, 40, ('important', 'ERROR'))
|
||||||
return dialog.run(ui, parent)
|
return dialog.run(ui, parent)
|
||||||
|
|
||||||
|
|
||||||
class SelText(urwid.Text):
|
class SelText(urwid.Text):
|
||||||
"""A selectable text widget. See urwid.Text."""
|
"""A selectable text widget. See urwid.Text."""
|
||||||
|
|
||||||
@@ -46,11 +48,13 @@ class SelText(urwid.Text):
|
|||||||
"""Don't handle any keys."""
|
"""Don't handle any keys."""
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
class NSelListBox(urwid.ListBox):
|
class NSelListBox(urwid.ListBox):
|
||||||
""" Non-selectable ListBox. """
|
""" Non-selectable ListBox. """
|
||||||
def selectable(self):
|
def selectable(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# This class is annoying. :/
|
# This class is annoying. :/
|
||||||
class DynWrap(urwid.AttrWrap):
|
class DynWrap(urwid.AttrWrap):
|
||||||
"""
|
"""
|
||||||
@@ -62,8 +66,8 @@ class DynWrap(urwid.AttrWrap):
|
|||||||
attrs = tuple of (attr_sens,attr_not_sens)
|
attrs = tuple of (attr_sens,attr_not_sens)
|
||||||
attrfoc = attributes when in focus, defaults to nothing
|
attrfoc = attributes when in focus, defaults to nothing
|
||||||
"""
|
"""
|
||||||
|
# pylint: disable-msg=W0231
|
||||||
def __init__(self, w, sensitive=True, attrs=('editbx', 'editnfc'), \
|
def __init__(self, w, sensitive=True, attrs=('editbx', 'editnfc'),
|
||||||
focus_attr='editfc'):
|
focus_attr='editfc'):
|
||||||
self._attrs = attrs
|
self._attrs = attrs
|
||||||
self._sensitive = sensitive
|
self._sensitive = sensitive
|
||||||
@@ -73,11 +77,13 @@ class DynWrap(urwid.AttrWrap):
|
|||||||
else:
|
else:
|
||||||
cur_attr = attrs[1]
|
cur_attr = attrs[1]
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(w, cur_attr, focus_attr)
|
self.__super.__init__(w, cur_attr, focus_attr)
|
||||||
|
|
||||||
def get_sensitive(self):
|
def get_sensitive(self):
|
||||||
""" Getter for sensitive property. """
|
""" Getter for sensitive property. """
|
||||||
return self._sensitive
|
return self._sensitive
|
||||||
|
|
||||||
def set_sensitive(self, state):
|
def set_sensitive(self, state):
|
||||||
""" Setter for sensitive property. """
|
""" Setter for sensitive property. """
|
||||||
if state:
|
if state:
|
||||||
@@ -90,6 +96,7 @@ class DynWrap(urwid.AttrWrap):
|
|||||||
def get_attrs(self):
|
def get_attrs(self):
|
||||||
""" Getter for attrs property. """
|
""" Getter for attrs property. """
|
||||||
return self._attrs
|
return self._attrs
|
||||||
|
|
||||||
def set_attrs(self, attrs):
|
def set_attrs(self, attrs):
|
||||||
""" Setter for attrs property. """
|
""" Setter for attrs property. """
|
||||||
self._attrs = attrs
|
self._attrs = attrs
|
||||||
@@ -98,36 +105,47 @@ class DynWrap(urwid.AttrWrap):
|
|||||||
def selectable(self):
|
def selectable(self):
|
||||||
return self._sensitive
|
return self._sensitive
|
||||||
|
|
||||||
|
|
||||||
class DynEdit(DynWrap):
|
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,
|
def __init__(self, caption='', edit_text='', sensitive=True,
|
||||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||||
caption = ('editcp', caption + ': ')
|
caption = ('editcp', caption + ': ')
|
||||||
edit = urwid.Edit(caption, edit_text)
|
edit = urwid.Edit(caption, edit_text)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
||||||
|
|
||||||
|
|
||||||
class DynIntEdit(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,
|
def __init__(self, caption='', edit_text='', sensitive=True,
|
||||||
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
attrs=('editbx', 'editnfc'), focus_attr='editfc'):
|
||||||
caption = ('editcp', caption + ':')
|
caption = ('editcp', caption + ':')
|
||||||
edit = urwid.IntEdit(caption, edit_text)
|
edit = urwid.IntEdit(caption, edit_text)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
self.__super.__init__(edit, sensitive, attrs, focus_attr)
|
||||||
|
|
||||||
|
|
||||||
class DynRadioButton(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,
|
def __init__(self, group, label, state='first True', on_state_change=None,
|
||||||
user_data=None, sensitive=True, attrs=('body', 'editnfc'),
|
user_data=None, sensitive=True, attrs=('body', 'editnfc'),
|
||||||
focus_attr='body'):
|
focus_attr='body'):
|
||||||
#caption = ('editcp', caption + ':')
|
#caption = ('editcp', caption + ':')
|
||||||
button = urwid.RadioButton(group, label, state, on_state_change,
|
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)
|
self.__super.__init__(button, sensitive, attrs, focus_attr)
|
||||||
|
|
||||||
|
|
||||||
class MaskingEditException(Exception):
|
class MaskingEditException(Exception):
|
||||||
""" Custom exception. """
|
""" Custom exception. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Password-style edit
|
# Password-style edit
|
||||||
class MaskingEdit(urwid.Edit):
|
class MaskingEdit(urwid.Edit):
|
||||||
"""
|
"""
|
||||||
@@ -135,27 +153,36 @@ class MaskingEdit(urwid.Edit):
|
|||||||
"always" : everything is a '*' all of the time
|
"always" : everything is a '*' all of the time
|
||||||
"no_focus" : everything is a '*' only when not in focus
|
"no_focus" : everything is a '*' only when not in focus
|
||||||
"off" : everything is always unmasked
|
"off" : everything is always unmasked
|
||||||
mask_char = the single character that masks all other characters in the field
|
mask_char = the single character that masks all other characters in the
|
||||||
|
field
|
||||||
"""
|
"""
|
||||||
def __init__(self, caption = "", edit_text = "", multiline = False,
|
# pylint: disable-msg=W0231
|
||||||
align = 'left', wrap = 'space', allow_tab = False,
|
def __init__(self, caption="", edit_text="", multiline=False, align='left',
|
||||||
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
|
self.mask_mode = mask_mode
|
||||||
if len(mask_char) > 1:
|
if len(mask_char) > 1:
|
||||||
raise MaskingEditException('Masks of more than one character are' +\
|
raise MaskingEditException('Masks of more than one character are' +
|
||||||
' not supported!')
|
' not supported!')
|
||||||
self.mask_char = mask_char
|
self.mask_char = mask_char
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(caption, edit_text, multiline, align, wrap,
|
self.__super.__init__(caption, edit_text, multiline, align, wrap,
|
||||||
allow_tab, edit_pos, layout)
|
allow_tab, edit_pos, layout)
|
||||||
|
|
||||||
def get_caption(self):
|
def get_caption(self):
|
||||||
|
""" Return caption. """
|
||||||
return self.caption
|
return self.caption
|
||||||
|
|
||||||
def get_mask_mode(self):
|
def get_mask_mode(self):
|
||||||
|
""" Getter for mask_mode property. """
|
||||||
return self.mask_mode
|
return self.mask_mode
|
||||||
|
|
||||||
def set_mask_mode(self, mode):
|
def set_mask_mode(self, mode):
|
||||||
|
""" Setter for mask_mode property."""
|
||||||
self.mask_mode = mode
|
self.mask_mode = mode
|
||||||
|
|
||||||
def get_masked_text(self):
|
def get_masked_text(self):
|
||||||
|
""" Get masked out text. """
|
||||||
return self.mask_char * len(self.get_edit_text())
|
return self.mask_char * len(self.get_edit_text())
|
||||||
|
|
||||||
def render(self, (maxcol, ), focus=False):
|
def render(self, (maxcol, ), focus=False):
|
||||||
@@ -166,6 +193,7 @@ class MaskingEdit(urwid.Edit):
|
|||||||
# If we aren't masking anything ATM, then act like an Edit.
|
# If we aren't masking anything ATM, then act like an Edit.
|
||||||
# No problems.
|
# No problems.
|
||||||
if self.mask_mode == "off" or (self.mask_mode == 'no_focus' and focus):
|
if self.mask_mode == "off" or (self.mask_mode == 'no_focus' and focus):
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
canv = self.__super.render((maxcol, ), focus)
|
canv = self.__super.render((maxcol, ), focus)
|
||||||
# The cache messes this thing up, because I am totally changing what
|
# The cache messes this thing up, because I am totally changing what
|
||||||
# is displayed.
|
# is displayed.
|
||||||
@@ -186,6 +214,7 @@ class MaskingEdit(urwid.Edit):
|
|||||||
|
|
||||||
return canv
|
return canv
|
||||||
|
|
||||||
|
|
||||||
class TabColumns(urwid.WidgetWrap):
|
class TabColumns(urwid.WidgetWrap):
|
||||||
"""
|
"""
|
||||||
Tabbed interface, mostly for use in the Preferences Dialog
|
Tabbed interface, mostly for use in the Preferences Dialog
|
||||||
@@ -195,13 +224,14 @@ class TabColumns(urwid.WidgetWrap):
|
|||||||
attrsel = attribute when active
|
attrsel = attribute when active
|
||||||
"""
|
"""
|
||||||
# FIXME Make the bottom_part optional
|
# FIXME Make the bottom_part optional
|
||||||
|
# pylint: disable-msg=W0231
|
||||||
def __init__(self, tab_str, tab_wid, title, bottom_part=None,
|
def __init__(self, tab_str, tab_wid, title, bottom_part=None,
|
||||||
attr=('body', 'focus'), attrsel='tab active', attrtitle='header'):
|
attr=('body', 'focus'), attrsel='tab active', attrtitle='header'):
|
||||||
#self.bottom_part = bottom_part
|
#self.bottom_part = bottom_part
|
||||||
#title_wid = urwid.Text((attrtitle, title), align='right')
|
#title_wid = urwid.Text((attrtitle, title), align='right')
|
||||||
column_list = []
|
column_list = []
|
||||||
for w in tab_str:
|
for w in tab_str:
|
||||||
text, _ = w.get_text()
|
text, trash = w.get_text()
|
||||||
column_list.append(('fixed', len(text), w))
|
column_list.append(('fixed', len(text), w))
|
||||||
column_list.append(urwid.Text((attrtitle, title), align='right'))
|
column_list.append(urwid.Text((attrtitle, title), align='right'))
|
||||||
|
|
||||||
@@ -212,6 +242,7 @@ class TabColumns(urwid.WidgetWrap):
|
|||||||
#self.listbox = urwid.ListBox(walker)
|
#self.listbox = urwid.ListBox(walker)
|
||||||
self.gen_pile(tab_wid[0], True)
|
self.gen_pile(tab_wid[0], True)
|
||||||
self.frame = urwid.Frame(self.pile)
|
self.frame = urwid.Frame(self.pile)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(self.frame)
|
self.__super.__init__(self.frame)
|
||||||
|
|
||||||
def gen_pile(self, lbox, firstrun=False):
|
def gen_pile(self, lbox, firstrun=False):
|
||||||
@@ -271,6 +302,7 @@ class ComboBoxException(Exception):
|
|||||||
""" Custom exception. """
|
""" Custom exception. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# A "combo box" of SelTexts
|
# A "combo box" of SelTexts
|
||||||
# I based this off of the code found here:
|
# I based this off of the code found here:
|
||||||
# http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py
|
# http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py
|
||||||
@@ -281,6 +313,7 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
"""A ComboBox of text objects"""
|
"""A ComboBox of text objects"""
|
||||||
class ComboSpace(urwid.WidgetWrap):
|
class ComboSpace(urwid.WidgetWrap):
|
||||||
"""The actual menu-like space that comes down from the ComboBox"""
|
"""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),
|
def __init__(self, l, body, ui, show_first, pos=(0, 0),
|
||||||
attr=('body', 'focus')):
|
attr=('body', 'focus')):
|
||||||
"""
|
"""
|
||||||
@@ -305,6 +338,7 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
|
|
||||||
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]),
|
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]),
|
||||||
width + 2, ('fixed top', pos[1]), height)
|
width + 2, ('fixed top', pos[1]), height)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(overlay)
|
self.__super.__init__(overlay)
|
||||||
|
|
||||||
def show(self, ui, display):
|
def show(self, ui, display):
|
||||||
@@ -334,7 +368,8 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
|
|
||||||
#def get_size(self):
|
#def get_size(self):
|
||||||
|
|
||||||
def __init__(self, label='', l=[], attrs=('body', 'editnfc'),
|
# pylint: disable-msg=W0231
|
||||||
|
def __init__(self, label='', l=None, attrs=('body', 'editnfc'),
|
||||||
focus_attr='focus', use_enter=True, focus=0, callback=None,
|
focus_attr='focus', use_enter=True, focus=0, callback=None,
|
||||||
user_args=None):
|
user_args=None):
|
||||||
"""
|
"""
|
||||||
@@ -353,9 +388,11 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
self.label = urwid.Text(label)
|
self.label = urwid.Text(label)
|
||||||
self.attrs = attrs
|
self.attrs = attrs
|
||||||
self.focus_attr = focus_attr
|
self.focus_attr = focus_attr
|
||||||
|
if l is None:
|
||||||
|
l = []
|
||||||
self.list = l
|
self.list = l
|
||||||
|
|
||||||
s, _ = self.label.get_text()
|
s, trash = self.label.get_text()
|
||||||
|
|
||||||
self.overlay = None
|
self.overlay = None
|
||||||
self.cbox = DynWrap(SelText(self.DOWN_ARROW), attrs=attrs,
|
self.cbox = DynWrap(SelText(self.DOWN_ARROW), attrs=attrs,
|
||||||
@@ -368,6 +405,7 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
w = urwid.Columns([self.cbox])
|
w = urwid.Columns([self.cbox])
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(w)
|
self.__super.__init__(w)
|
||||||
|
|
||||||
# We need this to pick our keypresses
|
# We need this to pick our keypresses
|
||||||
@@ -387,9 +425,11 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
self.row = None
|
self.row = None
|
||||||
|
|
||||||
def set_list(self, l):
|
def set_list(self, l):
|
||||||
|
""" Populate widget list. """
|
||||||
self.list = l
|
self.list = l
|
||||||
|
|
||||||
def set_focus(self, index):
|
def set_focus(self, index):
|
||||||
|
""" Set widget focus. """
|
||||||
if urwid.VERSION < (1, 1, 0):
|
if urwid.VERSION < (1, 1, 0):
|
||||||
self.focus = index
|
self.focus = index
|
||||||
else:
|
else:
|
||||||
@@ -407,15 +447,17 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
self.overlay._listbox.set_focus(index)
|
self.overlay._listbox.set_focus(index)
|
||||||
|
|
||||||
def rebuild_combobox(self):
|
def rebuild_combobox(self):
|
||||||
|
""" Rebuild combobox. """
|
||||||
self.build_combobox(self.parent, self.ui, self.row)
|
self.build_combobox(self.parent, self.ui, self.row)
|
||||||
|
|
||||||
def build_combobox(self, parent, ui, row):
|
def build_combobox(self, parent, ui, row):
|
||||||
s, _ = self.label.get_text()
|
""" Build combobox. """
|
||||||
|
s, trash = self.label.get_text()
|
||||||
|
|
||||||
if urwid.VERSION < (1, 1, 0):
|
if urwid.VERSION < (1, 1, 0):
|
||||||
index = self.focus
|
index = self.focus
|
||||||
else:
|
else:
|
||||||
index = self._w.focus_position
|
index = self._w.focus_position # pylint: disable-msg=E1103
|
||||||
|
|
||||||
self.cbox = DynWrap(SelText([self.list[index] + self.DOWN_ARROW]),
|
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)
|
||||||
@@ -437,45 +479,57 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
|
|
||||||
# If we press space or enter, be a combo box!
|
# If we press space or enter, be a combo box!
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
""" Handle keypresses. """
|
||||||
activate = key == ' '
|
activate = key == ' '
|
||||||
if self.use_enter:
|
if self.use_enter:
|
||||||
activate = activate or key == 'enter'
|
activate = activate or key == 'enter'
|
||||||
if activate:
|
if activate:
|
||||||
# Die if the user didn't prepare the combobox overlay
|
# Die if the user didn't prepare the combobox overlay
|
||||||
if self.overlay == None:
|
if self.overlay is None:
|
||||||
raise ComboBoxException('ComboBox must be built before use!')
|
raise ComboBoxException('ComboBox must be built before use!')
|
||||||
retval = self.overlay.show(self.ui, self.parent)
|
retval = self.overlay.show(self.ui, self.parent)
|
||||||
if retval != None:
|
if retval is not None:
|
||||||
self.set_focus(self.list.index(retval))
|
self.set_focus(self.list.index(retval))
|
||||||
#self.cbox.set_w(SelText(retval+' vvv'))
|
#self.cbox.set_w(SelText(retval+' vvv'))
|
||||||
if self.callback != None:
|
if self.callback is not None:
|
||||||
self.callback(self, self.overlay._listbox.get_focus()[1],
|
self.callback(self, self.overlay._listbox.get_focus()[1],
|
||||||
self.user_args)
|
self.user_args)
|
||||||
return self._w.keypress(size, key)
|
return self._w.keypress(size, key)
|
||||||
|
|
||||||
def selectable(self):
|
def selectable(self):
|
||||||
|
""" Return whether the widget is selectable. """
|
||||||
return self.cbox.selectable()
|
return self.cbox.selectable()
|
||||||
|
|
||||||
def get_focus(self):
|
def get_focus(self):
|
||||||
|
""" Return widget focus. """
|
||||||
if self.overlay:
|
if self.overlay:
|
||||||
return self.overlay._listbox.get_focus()
|
return self.overlay._listbox.get_focus()
|
||||||
else:
|
else:
|
||||||
if urwid.VERSION < (1, 1, 0):
|
if urwid.VERSION < (1, 1, 0):
|
||||||
return None, self.focus
|
return None, self.focus
|
||||||
else:
|
else:
|
||||||
return None, self._w.focus_position
|
return None, self._w.focus_position # pylint: disable-msg=E1103
|
||||||
|
|
||||||
def get_sensitive(self):
|
def get_sensitive(self):
|
||||||
|
""" Return widget sensitivity. """
|
||||||
return self.cbox.get_sensitive()
|
return self.cbox.get_sensitive()
|
||||||
|
|
||||||
def set_sensitive(self, state):
|
def set_sensitive(self, state):
|
||||||
|
""" Set widget sensitivity. """
|
||||||
self.cbox.set_sensitive(state)
|
self.cbox.set_sensitive(state)
|
||||||
|
|
||||||
|
|
||||||
# This is a h4x3d copy of some of the code in Ian Ward's dialog.py example.
|
# This is a h4x3d copy of some of the code in Ian Ward's dialog.py example.
|
||||||
class DialogExit(Exception):
|
class DialogExit(Exception):
|
||||||
|
""" Custom exception. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Dialog2(urwid.WidgetWrap):
|
class Dialog2(urwid.WidgetWrap):
|
||||||
|
""" Base class for other dialogs. """
|
||||||
def __init__(self, text, height, width, body=None):
|
def __init__(self, text, height, width, body=None):
|
||||||
|
self.buttons = None
|
||||||
|
|
||||||
self.width = int(width)
|
self.width = int(width)
|
||||||
if width <= 0:
|
if width <= 0:
|
||||||
self.width = ('relative', 80)
|
self.width = ('relative', 80)
|
||||||
@@ -499,6 +553,7 @@ class Dialog2(urwid.WidgetWrap):
|
|||||||
|
|
||||||
# buttons: tuple of name,exitcode
|
# buttons: tuple of name,exitcode
|
||||||
def add_buttons(self, buttons):
|
def add_buttons(self, buttons):
|
||||||
|
""" Add buttons. """
|
||||||
l = []
|
l = []
|
||||||
maxlen = 0
|
maxlen = 0
|
||||||
for name, exitcode in buttons:
|
for name, exitcode in buttons:
|
||||||
@@ -515,9 +570,11 @@ class Dialog2(urwid.WidgetWrap):
|
|||||||
], focus_item=1)
|
], focus_item=1)
|
||||||
|
|
||||||
def button_press(self, button):
|
def button_press(self, button):
|
||||||
|
""" Handle button press. """
|
||||||
raise DialogExit(button.exitcode)
|
raise DialogExit(button.exitcode)
|
||||||
|
|
||||||
def run(self, ui, parent):
|
def run(self, ui, parent):
|
||||||
|
""" Run the UI. """
|
||||||
ui.set_mouse_tracking()
|
ui.set_mouse_tracking()
|
||||||
size = ui.get_cols_rows()
|
size = ui.get_cols_rows()
|
||||||
overlay = urwid.Overlay(
|
overlay = urwid.Overlay(
|
||||||
@@ -553,13 +610,16 @@ class Dialog2(urwid.WidgetWrap):
|
|||||||
return self.on_exit(e.args[0])
|
return self.on_exit(e.args[0])
|
||||||
|
|
||||||
def on_exit(self, exitcode):
|
def on_exit(self, exitcode):
|
||||||
|
""" Handle dialog exit. """
|
||||||
return exitcode, ""
|
return exitcode, ""
|
||||||
|
|
||||||
def unhandled_key(self, size, key):
|
def unhandled_key(self, size, key):
|
||||||
|
""" Handle keypresses. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Simple dialog with text in it and "OK"
|
|
||||||
class TextDialog(Dialog2):
|
class TextDialog(Dialog2):
|
||||||
|
""" Simple dialog with text and "OK" button. """
|
||||||
def __init__(self, text, height, width, header=None, align='left',
|
def __init__(self, text, height, width, header=None, align='left',
|
||||||
buttons=(_('OK'), 1)):
|
buttons=(_('OK'), 1)):
|
||||||
l = [urwid.Text(text)]
|
l = [urwid.Text(text)]
|
||||||
@@ -573,12 +633,15 @@ class TextDialog(Dialog2):
|
|||||||
self.add_buttons([buttons])
|
self.add_buttons([buttons])
|
||||||
|
|
||||||
def unhandled_key(self, size, k):
|
def unhandled_key(self, size, k):
|
||||||
|
""" Handle keys. """
|
||||||
if k in ('up', 'page up', 'down', 'page down'):
|
if k in ('up', 'page up', 'down', 'page down'):
|
||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
self.view.keypress(size, k)
|
self.view.keypress(size, k)
|
||||||
self.frame.set_focus('footer')
|
self.frame.set_focus('footer')
|
||||||
|
|
||||||
|
|
||||||
class InputDialog(Dialog2):
|
class InputDialog(Dialog2):
|
||||||
|
""" Simple dialog with text and entry. """
|
||||||
def __init__(self, text, height, width, ok_name=_('OK'), edit_text=''):
|
def __init__(self, text, height, width, ok_name=_('OK'), edit_text=''):
|
||||||
self.edit = urwid.Edit(wrap='clip', edit_text=edit_text)
|
self.edit = urwid.Edit(wrap='clip', edit_text=edit_text)
|
||||||
body = urwid.ListBox([self.edit])
|
body = urwid.ListBox([self.edit])
|
||||||
@@ -590,6 +653,7 @@ class InputDialog(Dialog2):
|
|||||||
self.add_buttons([(ok_name, 0), (_('Cancel'), -1)])
|
self.add_buttons([(ok_name, 0), (_('Cancel'), -1)])
|
||||||
|
|
||||||
def unhandled_key(self, size, k):
|
def unhandled_key(self, size, k):
|
||||||
|
""" Handle keys. """
|
||||||
if k in ('up', 'page up'):
|
if k in ('up', 'page up'):
|
||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
if k in ('down', 'page down'):
|
if k in ('down', 'page down'):
|
||||||
@@ -600,26 +664,34 @@ class InputDialog(Dialog2):
|
|||||||
self.view.keypress(size, k)
|
self.view.keypress(size, k)
|
||||||
|
|
||||||
def on_exit(self, exitcode):
|
def on_exit(self, exitcode):
|
||||||
|
""" Handle dialog exit. """
|
||||||
return exitcode, self.edit.get_edit_text()
|
return exitcode, self.edit.get_edit_text()
|
||||||
|
|
||||||
|
|
||||||
class ClickCols(urwid.WidgetWrap):
|
class ClickCols(urwid.WidgetWrap):
|
||||||
|
""" Clickable menubar. """
|
||||||
|
# pylint: disable-msg=W0231
|
||||||
def __init__(self, items, callback=None, args=None):
|
def __init__(self, items, callback=None, args=None):
|
||||||
cols = urwid.Columns(items)
|
cols = urwid.Columns(items)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(cols)
|
self.__super.__init__(cols)
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, x, y, focus):
|
def mouse_event(self, size, event, button, x, y, focus):
|
||||||
|
""" Handle mouse events. """
|
||||||
if event == "mouse press":
|
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])
|
self.callback([self.args])
|
||||||
|
|
||||||
# htop-style menu menu-bar on the bottom of the screen
|
|
||||||
class OptCols(urwid.WidgetWrap):
|
class OptCols(urwid.WidgetWrap):
|
||||||
|
""" Htop-style menubar on the bottom of the screen. """
|
||||||
# tuples = [(key,desc)], on_event gets passed a key
|
# tuples = [(key,desc)], on_event gets passed a key
|
||||||
# attrs = (attr_key,attr_desc)
|
# attrs = (attr_key,attr_desc)
|
||||||
# handler = function passed the key of the "button" pressed
|
# handler = function passed the key of the "button" pressed
|
||||||
# mentions of 'left' and right will be converted to <- and -> respectively
|
# 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
|
# Find the longest string. Keys for this bar should be no greater than
|
||||||
# 2 characters long (e.g., -> for left)
|
# 2 characters long (e.g., -> for left)
|
||||||
@@ -635,10 +707,10 @@ class OptCols(urwid.WidgetWrap):
|
|||||||
# callbacks map the text contents to its assigned callback.
|
# callbacks map the text contents to its assigned callback.
|
||||||
self.callbacks = []
|
self.callbacks = []
|
||||||
for cmd in tuples:
|
for cmd in tuples:
|
||||||
key = reduce(lambda s, (f, t): s.replace(f, t), [ \
|
key = reduce(lambda s, (f, t): s.replace(f, t), [
|
||||||
('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'), \
|
('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'),
|
||||||
('left', '<-'), ('right', '->'), \
|
('left', '<-'), ('right', '->'),
|
||||||
('page up', 'Page Up'), ('page down', 'Page Down'), \
|
('page up', 'Page Up'), ('page down', 'Page Down'),
|
||||||
('esc', 'ESC'), ('enter', 'Enter'), ('f10', 'F10')], cmd[0])
|
('esc', 'ESC'), ('enter', 'Enter'), ('f10', 'F10')], cmd[0])
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
@@ -659,10 +731,15 @@ class OptCols(urwid.WidgetWrap):
|
|||||||
textList.append(('fixed', 10, self.debug))
|
textList.append(('fixed', 10, self.debug))
|
||||||
|
|
||||||
cols = urwid.Columns(textList)
|
cols = urwid.Columns(textList)
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(cols)
|
self.__super.__init__(cols)
|
||||||
|
|
||||||
def debugClick(self, args):
|
def debugClick(self, args):
|
||||||
|
""" Debug clicks. """
|
||||||
self.debug.set_text(args)
|
self.debug.set_text(args)
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, x, y, focus):
|
def mouse_event(self, size, event, button, x, y, focus):
|
||||||
|
""" Handle mouse events. """
|
||||||
# Widgets are evenly long (as of current), so...
|
# Widgets are evenly long (as of current), so...
|
||||||
return self._w.mouse_event(size, event, button, x, y, focus)
|
return self._w.mouse_event(size, event, button, x, y, focus)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
from curses_misc import TextDialog,DynWrap,MaskingEdit,ComboBox,error
|
from curses_misc import DynWrap, MaskingEdit, ComboBox, error
|
||||||
import wicd.misc as misc
|
import wicd.misc as misc
|
||||||
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||||
|
|
||||||
@@ -32,19 +32,38 @@ import os
|
|||||||
daemon = None
|
daemon = None
|
||||||
wired = None
|
wired = None
|
||||||
wireless = None
|
wireless = None
|
||||||
|
|
||||||
|
|
||||||
# Call this first!
|
# Call this first!
|
||||||
def dbus_init(dbus_ifaces):
|
def dbus_init(dbus_ifaces):
|
||||||
|
""" Initialize DBus interfaces. """
|
||||||
global daemon, wired, wireless
|
global daemon, wired, wireless
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
wired = dbus_ifaces['wired']
|
wired = dbus_ifaces['wired']
|
||||||
wireless = dbus_ifaces['wireless']
|
wireless = dbus_ifaces['wireless']
|
||||||
|
|
||||||
# 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
|
|
||||||
class AdvancedSettingsDialog(urwid.WidgetWrap):
|
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):
|
def __init__(self):
|
||||||
self.ui = None
|
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')
|
static_ip_t = _('Use Static IPs')
|
||||||
ip_t = ('editcp', _('IP') + ': ')
|
ip_t = ('editcp', _('IP') + ': ')
|
||||||
@@ -71,31 +90,46 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False)
|
self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False)
|
||||||
self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False)
|
self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False)
|
||||||
|
|
||||||
|
self.static_dns_cb = DynWrap(
|
||||||
self.static_dns_cb = DynWrap(urwid.CheckBox(use_static_dns_t,
|
urwid.CheckBox(use_static_dns_t, on_state_change=self.dns_toggle),
|
||||||
on_state_change=self.dns_toggle),True,('body','editnfc'),None)
|
True,
|
||||||
self.global_dns_cb = DynWrap(urwid.CheckBox(use_global_dns_t,
|
('body', 'editnfc'),
|
||||||
on_state_change=self.dns_toggle),False,('body','editnfc'),None)
|
None
|
||||||
self.checkb_cols = urwid.Columns([self.static_dns_cb,
|
)
|
||||||
self.global_dns_cb])
|
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.dns_dom_edit = DynWrap(urwid.Edit(dns_dom_t), False)
|
||||||
self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False)
|
self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False)
|
||||||
self.dns1 = DynWrap(urwid.Edit(dns1_t), False)
|
self.dns1 = DynWrap(urwid.Edit(dns1_t), False)
|
||||||
self.dns2 = DynWrap(urwid.Edit(dns2_t), False)
|
self.dns2 = DynWrap(urwid.Edit(dns2_t), False)
|
||||||
self.dns3 = DynWrap(urwid.Edit(dns3_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.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)
|
self.dhcp_h = DynWrap(urwid.Edit(dhcp_h_t), False)
|
||||||
|
|
||||||
_blank = urwid.Text('')
|
_blank = urwid.Text('')
|
||||||
|
|
||||||
walker = urwid.SimpleListWalker([self.static_ip_cb,
|
walker = urwid.SimpleListWalker([
|
||||||
|
self.static_ip_cb,
|
||||||
self.ip_edit,
|
self.ip_edit,
|
||||||
self.netmask_edit,
|
self.netmask_edit,
|
||||||
self.gateway_edit,
|
self.gateway_edit,
|
||||||
_blank,
|
_blank,
|
||||||
self.checkb_cols,
|
self.checkb_cols,
|
||||||
self.dns_dom_edit,self.search_dom_edit,
|
self.dns_dom_edit,
|
||||||
|
self.search_dom_edit,
|
||||||
self.dns1, self.dns2, self.dns3,
|
self.dns1, self.dns2, self.dns3,
|
||||||
_blank,
|
_blank,
|
||||||
self.use_dhcp_h,
|
self.use_dhcp_h,
|
||||||
@@ -103,16 +137,18 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
_blank
|
_blank
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self._listbox = urwid.ListBox(walker)
|
self._listbox = urwid.ListBox(walker)
|
||||||
self._frame = urwid.Frame(self._listbox)
|
self._frame = urwid.Frame(self._listbox)
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(self._frame)
|
self.__super.__init__(self._frame)
|
||||||
|
|
||||||
def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
|
def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
|
||||||
|
""" Set sensitivity of widget. """
|
||||||
self.dhcp_h.set_sensitive(new_state)
|
self.dhcp_h.set_sensitive(new_state)
|
||||||
|
|
||||||
def static_ip_toggle(self, checkb, new_state, user_data=None):
|
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]:
|
for w in [self.ip_edit, self.netmask_edit, self.gateway_edit]:
|
||||||
w.set_sensitive(new_state)
|
w.set_sensitive(new_state)
|
||||||
self.static_dns_cb.set_state(new_state)
|
self.static_dns_cb.set_state(new_state)
|
||||||
@@ -122,11 +158,16 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
else:
|
else:
|
||||||
self.checkb_cols.set_focus(self.static_dns_cb)
|
self.checkb_cols.set_focus(self.static_dns_cb)
|
||||||
|
|
||||||
|
|
||||||
def dns_toggle(self, checkb, new_state, user_data=None):
|
def dns_toggle(self, checkb, new_state, user_data=None):
|
||||||
|
""" Set sensitivity of widget. """
|
||||||
if checkb == self.static_dns_cb.get_w():
|
if checkb == self.static_dns_cb.get_w():
|
||||||
for w in [ self.dns_dom_edit,self.search_dom_edit,
|
for w in [
|
||||||
self.dns1,self.dns2,self.dns3 ]:
|
self.dns_dom_edit,
|
||||||
|
self.search_dom_edit,
|
||||||
|
self.dns1,
|
||||||
|
self.dns2,
|
||||||
|
self.dns3
|
||||||
|
]:
|
||||||
w.set_sensitive(new_state)
|
w.set_sensitive(new_state)
|
||||||
if not new_state:
|
if not new_state:
|
||||||
self.global_dns_cb.set_state(False, do_callback=False)
|
self.global_dns_cb.set_state(False, do_callback=False)
|
||||||
@@ -137,16 +178,26 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
self.dns1, self.dns2, self.dns3 ]:
|
self.dns1, self.dns2, self.dns3 ]:
|
||||||
w.set_sensitive(not new_state)
|
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
|
# Code totally yanked from netentry.py
|
||||||
def save_settings(self):
|
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():
|
if self.static_ip_cb.get_state():
|
||||||
for i in [self.ip_edit,self.netmask_edit,self.gateway_edit]:
|
for i in [
|
||||||
|
self.ip_edit,
|
||||||
|
self.netmask_edit,
|
||||||
|
self.gateway_edit
|
||||||
|
]:
|
||||||
i.set_edit_text(i.get_edit_text().strip())
|
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("ip", noneToString(self.ip_edit.get_edit_text()))
|
||||||
self.set_net_prop("netmask", noneToString(self.netmask_edit.get_edit_text()))
|
self.set_net_prop("netmask",
|
||||||
self.set_net_prop("gateway", noneToString(self.gateway_edit.get_edit_text()))
|
noneToString(self.netmask_edit.get_edit_text()))
|
||||||
|
self.set_net_prop("gateway",
|
||||||
|
noneToString(self.gateway_edit.get_edit_text()))
|
||||||
else:
|
else:
|
||||||
self.set_net_prop("ip", '')
|
self.set_net_prop("ip", '')
|
||||||
self.set_net_prop("netmask", '')
|
self.set_net_prop("netmask", '')
|
||||||
@@ -157,11 +208,18 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
self.set_net_prop('use_static_dns', True)
|
self.set_net_prop('use_static_dns', True)
|
||||||
self.set_net_prop('use_global_dns', False)
|
self.set_net_prop('use_global_dns', False)
|
||||||
# Strip addressses before checking them in the daemon.
|
# Strip addressses before checking them in the daemon.
|
||||||
for i in [self.dns1, self.dns2,
|
for i in [
|
||||||
self.dns3,self.dns_dom_edit, self.search_dom_edit]:
|
self.dns1,
|
||||||
|
self.dns2,
|
||||||
|
self.dns3,
|
||||||
|
self.dns_dom_edit,
|
||||||
|
self.search_dom_edit
|
||||||
|
]:
|
||||||
i.set_edit_text(i.get_edit_text().strip())
|
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('dns_domain',
|
||||||
self.set_net_prop("search_domain", noneToString(self.search_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()))
|
||||||
self.set_net_prop("dns1", noneToString(self.dns1.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("dns2", noneToString(self.dns2.get_edit_text()))
|
||||||
self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
|
self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
|
||||||
@@ -182,21 +240,25 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
# Prevent comboboxes from dying.
|
# Prevent comboboxes from dying.
|
||||||
def ready_widgets(self, ui, body):
|
def ready_widgets(self, ui, body):
|
||||||
|
""" Build comboboxes. """
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.body = body
|
self.body = body
|
||||||
self.encryption_combo.build_combobox(body, ui, 14)
|
self.encryption_combo.build_combobox(body, ui, 14)
|
||||||
self.change_encrypt_method()
|
self.change_encrypt_method()
|
||||||
|
|
||||||
def combo_on_change(self, combobox, new_index, user_data=None):
|
def combo_on_change(self, combobox, new_index, user_data=None):
|
||||||
|
""" Handle change of item in the combobox. """
|
||||||
self.change_encrypt_method()
|
self.change_encrypt_method()
|
||||||
|
|
||||||
# More or less ripped from netentry.py
|
# More or less ripped from netentry.py
|
||||||
def change_encrypt_method(self):
|
def change_encrypt_method(self):
|
||||||
|
""" Change encrypt method based on combobox. """
|
||||||
#self.lbox_encrypt = urwid.ListBox()
|
#self.lbox_encrypt = urwid.ListBox()
|
||||||
self.encryption_info = {}
|
self.encryption_info = {}
|
||||||
wid, ID = self.encryption_combo.get_focus()
|
wid, ID = self.encryption_combo.get_focus()
|
||||||
methods = self.encrypt_types
|
methods = self.encrypt_types
|
||||||
|
|
||||||
|
# pylint: disable-msg=E0203
|
||||||
if self._w.body.body.__contains__(self.pile_encrypt):
|
if self._w.body.body.__contains__(self.pile_encrypt):
|
||||||
self._w.body.body.pop(self._w.body.body.__len__() - 1)
|
self._w.body.body.pop(self._w.body.body.__len__() - 1)
|
||||||
|
|
||||||
@@ -210,9 +272,10 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
fields = methods[ID][type_]
|
fields = methods[ID][type_]
|
||||||
for field in fields:
|
for field in fields:
|
||||||
try:
|
try:
|
||||||
edit = MaskingEdit(('editcp',language[field[1].lower().replace(' ','_')]+': '))
|
text = language[field[1].lower().replace(' ', '_')]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
edit = MaskingEdit(('editcp',field[1].replace(' ','_')+': '))
|
text = field[1].replace(' ', '_')
|
||||||
|
edit = MaskingEdit(('editcp', text + ': '))
|
||||||
edit.set_mask_mode('no_focus')
|
edit.set_mask_mode('no_focus')
|
||||||
theList.append(edit)
|
theList.append(edit)
|
||||||
# Add the data to any array, so that the information
|
# Add the data to any array, so that the information
|
||||||
@@ -229,7 +292,10 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
#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?
|
# 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.pile_encrypt.set_sensitive(self.encryption_chkbox.get_state())
|
||||||
|
|
||||||
@@ -237,16 +303,20 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
#self._w.body.body.append(self.pile_encrypt)
|
#self._w.body.body.append(self.pile_encrypt)
|
||||||
|
|
||||||
def encryption_toggle(self, chkbox, new_state, user_data=None):
|
def encryption_toggle(self, chkbox, new_state, user_data=None):
|
||||||
|
""" Set sensitivity of widget. """
|
||||||
self.encryption_combo.set_sensitive(new_state)
|
self.encryption_combo.set_sensitive(new_state)
|
||||||
self.pile_encrypt.set_sensitive(new_state)
|
self.pile_encrypt.set_sensitive(new_state)
|
||||||
|
|
||||||
|
|
||||||
class WiredSettingsDialog(AdvancedSettingsDialog):
|
class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||||
|
""" Settings dialog for wired interface. """
|
||||||
def __init__(self, name, parent):
|
def __init__(self, name, parent):
|
||||||
global wired, daemon
|
|
||||||
AdvancedSettingsDialog.__init__(self)
|
AdvancedSettingsDialog.__init__(self)
|
||||||
self.wired = True
|
self.wired = True
|
||||||
|
|
||||||
self.set_default = urwid.CheckBox(_('Use as default profile (overwrites any previous default)'))
|
self.set_default = urwid.CheckBox(
|
||||||
|
_('Use as default profile (overwrites any previous default)')
|
||||||
|
)
|
||||||
#self.cur_default =
|
#self.cur_default =
|
||||||
# Add widgets to listbox
|
# Add widgets to listbox
|
||||||
self._w.body.body.append(self.set_default)
|
self._w.body.body.append(self.set_default)
|
||||||
@@ -254,29 +324,44 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.parent = parent
|
self.parent = parent
|
||||||
encryption_t = _('Use Encryption')
|
encryption_t = _('Use Encryption')
|
||||||
|
|
||||||
self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
|
self.encryption_chkbox = urwid.CheckBox(
|
||||||
|
encryption_t,
|
||||||
|
on_state_change=self.
|
||||||
|
encryption_toggle
|
||||||
|
)
|
||||||
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
||||||
self.pile_encrypt = None
|
self.pile_encrypt = None
|
||||||
# _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
|
# _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)
|
self._listbox.body.append(self.encryption_chkbox)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.encryption_combo)
|
self._listbox.body.append(self.encryption_combo)
|
||||||
self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
|
self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
|
||||||
self.set_values()
|
self.set_values()
|
||||||
|
|
||||||
self.prof_name = name
|
self.prof_name = name
|
||||||
title = _('Configuring preferences for wired profile "$A"').replace('$A',self.prof_name)
|
title = _('Configuring preferences for wired profile "$A"'). \
|
||||||
|
replace('$A', self.prof_name)
|
||||||
self._w.header = urwid.Text(('header', title), align='right')
|
self._w.header = urwid.Text(('header', title), align='right')
|
||||||
|
|
||||||
self.set_values()
|
self.set_values()
|
||||||
|
|
||||||
def set_net_prop(self, option, value):
|
def set_net_prop(self, option, value):
|
||||||
|
""" Set network property. """
|
||||||
wired.SetWiredProperty(option, value)
|
wired.SetWiredProperty(option, value)
|
||||||
|
|
||||||
def set_values(self):
|
def set_values(self):
|
||||||
|
""" Load saved values. """
|
||||||
self.ip_edit.set_edit_text(self.format_entry("ip"))
|
self.ip_edit.set_edit_text(self.format_entry("ip"))
|
||||||
self.netmask_edit.set_edit_text(self.format_entry("netmask"))
|
self.netmask_edit.set_edit_text(self.format_entry("netmask"))
|
||||||
self.gateway_edit.set_edit_text(self.format_entry("gateway"))
|
self.gateway_edit.set_edit_text(self.format_entry("gateway"))
|
||||||
|
|
||||||
self.global_dns_cb.set_state(bool(wired.GetWiredProperty('use_global_dns')))
|
self.global_dns_cb.set_state(
|
||||||
self.static_dns_cb.set_state(bool(wired.GetWiredProperty('use_static_dns')))
|
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.
|
# Set static ip checkbox. Forgot to do this the first time.
|
||||||
if stringToNone(self.ip_edit.get_edit_text()):
|
if stringToNone(self.ip_edit.get_edit_text()):
|
||||||
@@ -290,13 +375,13 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
|
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
|
||||||
|
|
||||||
# Throw the encryption stuff into a list
|
# Throw the encryption stuff into a list
|
||||||
list = []
|
l = []
|
||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
for x, enc_type in enumerate(self.encrypt_types):
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
list.append(enc_type['name'])
|
l.append(enc_type['name'])
|
||||||
if enc_type['type'] == wired.GetWiredProperty("enctype"):
|
if enc_type['type'] == wired.GetWiredProperty("enctype"):
|
||||||
activeID = x
|
activeID = x
|
||||||
self.encryption_combo.set_list(list)
|
self.encryption_combo.set_list(l)
|
||||||
|
|
||||||
self.encryption_combo.set_focus(activeID)
|
self.encryption_combo.set_focus(activeID)
|
||||||
if wired.GetWiredProperty("encryption_enabled"):
|
if wired.GetWiredProperty("encryption_enabled"):
|
||||||
@@ -313,25 +398,33 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
if dhcphname is None:
|
if dhcphname is None:
|
||||||
dhcphname = os.uname()[1]
|
dhcphname = os.uname()[1]
|
||||||
|
|
||||||
self.use_dhcp_h.set_state(bool(wired.GetWiredProperty('usedhcphostname')))
|
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_sensitive(self.use_dhcp_h.get_state())
|
||||||
self.dhcp_h.set_edit_text(unicode(dhcphname))
|
self.dhcp_h.set_edit_text(unicode(dhcphname))
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
|
""" Save settings to disk. """
|
||||||
# Check encryption info
|
# Check encryption info
|
||||||
if self.encryption_chkbox.get_state():
|
if self.encryption_chkbox.get_state():
|
||||||
encrypt_info = self.encryption_info
|
encrypt_info = self.encryption_info
|
||||||
encrypt_methods = self.encrypt_types
|
encrypt_methods = self.encrypt_types
|
||||||
self.set_net_prop("enctype",
|
self.set_net_prop(
|
||||||
|
"enctype",
|
||||||
encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
|
encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
|
||||||
self.set_net_prop("encryption_enabled", True)
|
self.set_net_prop("encryption_enabled", True)
|
||||||
# Make sure all required fields are filled in.
|
# Make sure all required fields are filled in.
|
||||||
for entry_info in encrypt_info.itervalues():
|
for entry_info in encrypt_info.itervalues():
|
||||||
if entry_info[0].get_edit_text() == "" \
|
if entry_info[0].get_edit_text() == "" \
|
||||||
and entry_info[1] == 'required':
|
and entry_info[1] == 'required':
|
||||||
error(self.ui, self.parent,"%s (%s)" \
|
error(
|
||||||
% (_('Required encryption information is missing.'),
|
self.ui,
|
||||||
entry_info[0].get_caption()[0:-2] )
|
self.parent,
|
||||||
|
"%s (%s)" % (
|
||||||
|
_('Required encryption information is missing.'),
|
||||||
|
entry_info[0].get_caption()[0:-2]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -346,55 +439,72 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
if self.set_default.get_state():
|
if self.set_default.get_state():
|
||||||
wired.UnsetWiredDefault()
|
wired.UnsetWiredDefault()
|
||||||
if self.set_default.get_state():
|
if self.set_default.get_state():
|
||||||
bool = True
|
set_default = True
|
||||||
else:
|
else:
|
||||||
bool = False
|
set_default = False
|
||||||
wired.SetWiredProperty("default",bool)
|
wired.SetWiredProperty("default", set_default)
|
||||||
wired.SaveWiredNetworkProfile(self.prof_name)
|
wired.SaveWiredNetworkProfile(self.prof_name)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def format_entry(self, label):
|
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))
|
return noneToBlankString(wired.GetWiredProperty(label))
|
||||||
|
|
||||||
def prerun(self, ui, dim, display):
|
def prerun(self, ui, dim, display):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
########################################
|
|
||||||
|
|
||||||
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||||
|
""" Settings dialog for wireless interfaces. """
|
||||||
def __init__(self, networkID, parent):
|
def __init__(self, networkID, parent):
|
||||||
global wireless, daemon
|
|
||||||
AdvancedSettingsDialog.__init__(self)
|
AdvancedSettingsDialog.__init__(self)
|
||||||
self.wired = False
|
self.wired = False
|
||||||
|
|
||||||
|
self.bitrates = None
|
||||||
|
|
||||||
self.networkid = networkID
|
self.networkid = networkID
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
global_settings_t = _('Use these settings for all networks sharing this essid')
|
global_settings_t = \
|
||||||
|
_('Use these settings for all networks sharing this essid')
|
||||||
encryption_t = _('Use Encryption')
|
encryption_t = _('Use Encryption')
|
||||||
autoconnect_t = _('Automatically connect to this network')
|
autoconnect_t = _('Automatically connect to this network')
|
||||||
bitrate_t = _('Wireless bitrate')
|
bitrate_t = _('Wireless bitrate')
|
||||||
allow_lower_bitrates_t = _('Allow lower bitrates')
|
allow_lower_bitrates_t = _('Allow lower bitrates')
|
||||||
|
|
||||||
self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
|
self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
|
||||||
self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
|
self.encryption_chkbox = urwid.CheckBox(
|
||||||
|
encryption_t,
|
||||||
|
on_state_change=self.
|
||||||
|
encryption_toggle
|
||||||
|
)
|
||||||
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
self.encryption_combo = ComboBox(callback=self.combo_on_change)
|
||||||
self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
|
self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
|
||||||
self.bitrate_combo = ComboBox(bitrate_t)
|
self.bitrate_combo = ComboBox(bitrate_t)
|
||||||
self.allow_lower_bitrates_chkbox = urwid.CheckBox(allow_lower_bitrates_t)
|
self.allow_lower_bitrates_chkbox = \
|
||||||
|
urwid.CheckBox(allow_lower_bitrates_t)
|
||||||
|
|
||||||
self.pile_encrypt = None
|
self.pile_encrypt = None
|
||||||
# _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
|
# _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)
|
self._listbox.body.append(self.bitrate_combo)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.allow_lower_bitrates_chkbox)
|
self._listbox.body.append(self.allow_lower_bitrates_chkbox)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(urwid.Text(''))
|
self._listbox.body.append(urwid.Text(''))
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.global_settings_chkbox)
|
self._listbox.body.append(self.global_settings_chkbox)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.autoconnect_chkbox)
|
self._listbox.body.append(self.autoconnect_chkbox)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.encryption_chkbox)
|
self._listbox.body.append(self.encryption_chkbox)
|
||||||
|
# pylint: disable-msg=E1103
|
||||||
self._listbox.body.append(self.encryption_combo)
|
self._listbox.body.append(self.encryption_combo)
|
||||||
self.encrypt_types = misc.LoadEncryptionMethods()
|
self.encrypt_types = misc.LoadEncryptionMethods()
|
||||||
self.set_values()
|
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')
|
self._w.header = urwid.Text(('header', title), align='right')
|
||||||
|
|
||||||
def set_values(self):
|
def set_values(self):
|
||||||
@@ -404,41 +514,59 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.netmask_edit.set_edit_text(self.format_entry(networkID, "netmask"))
|
self.netmask_edit.set_edit_text(self.format_entry(networkID, "netmask"))
|
||||||
self.gateway_edit.set_edit_text(self.format_entry(networkID, "gateway"))
|
self.gateway_edit.set_edit_text(self.format_entry(networkID, "gateway"))
|
||||||
|
|
||||||
self.global_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
|
self.global_dns_cb.set_state(
|
||||||
'use_global_dns')))
|
bool(wireless.GetWirelessProperty(networkID, 'use_global_dns')))
|
||||||
self.static_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
|
self.static_dns_cb.set_state(
|
||||||
'use_static_dns')))
|
bool(wireless.GetWirelessProperty(networkID, 'use_static_dns')))
|
||||||
|
|
||||||
if stringToNone(self.ip_edit.get_edit_text()):
|
if stringToNone(self.ip_edit.get_edit_text()):
|
||||||
self.static_ip_cb.set_state(True)
|
self.static_ip_cb.set_state(True)
|
||||||
self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
|
self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
|
||||||
self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
|
self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
|
||||||
self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
|
self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
|
||||||
self.dns_dom_edit.set_edit_text(self.format_entry(networkID, "dns_domain"))
|
self.dns_dom_edit.set_edit_text(
|
||||||
self.search_dom_edit.set_edit_text(self.format_entry(networkID, "search_domain"))
|
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.autoconnect_chkbox.set_state(
|
||||||
|
to_bool(self.format_entry(networkID, "automatic"))
|
||||||
|
)
|
||||||
|
|
||||||
self.bitrates = wireless.GetAvailableBitrates()
|
self.bitrates = wireless.GetAvailableBitrates()
|
||||||
self.bitrates.append('auto')
|
self.bitrates.append('auto')
|
||||||
self.bitrate_combo.set_list(self.bitrates)
|
self.bitrate_combo.set_list(self.bitrates)
|
||||||
self.bitrate_combo.set_focus(self.bitrates.index(wireless.GetWirelessProperty(networkID, 'bitrate')))
|
self.bitrate_combo.set_focus(
|
||||||
self.allow_lower_bitrates_chkbox.set_state(to_bool(self.format_entry(networkID, 'allow_lower_bitrates')))
|
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.reset_static_checkboxes()
|
||||||
self.encryption_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID,
|
self.encryption_chkbox.set_state(
|
||||||
'encryption')),do_callback=False)
|
bool(wireless.GetWirelessProperty(networkID, 'encryption')),
|
||||||
self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID
|
do_callback=False)
|
||||||
,'use_settings_globally')))
|
self.global_settings_chkbox.set_state(
|
||||||
|
bool(wireless.GetWirelessProperty(
|
||||||
|
networkID,
|
||||||
|
'use_settings_globally')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Throw the encryption stuff into a list
|
# Throw the encryption stuff into a list
|
||||||
list = []
|
l = []
|
||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
for x, enc_type in enumerate(self.encrypt_types):
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
list.append(enc_type['name'])
|
l.append(enc_type['name'])
|
||||||
if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
|
if enc_type['type'] == \
|
||||||
|
wireless.GetWirelessProperty(networkID, "enctype"):
|
||||||
activeID = x
|
activeID = x
|
||||||
self.encryption_combo.set_list(list)
|
self.encryption_combo.set_list(l)
|
||||||
|
|
||||||
self.encryption_combo.set_focus(activeID)
|
self.encryption_combo.set_focus(activeID)
|
||||||
if activeID != -1:
|
if activeID != -1:
|
||||||
@@ -452,11 +580,12 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
dhcphname = wireless.GetWirelessProperty(networkID, "dhcphostname")
|
dhcphname = wireless.GetWirelessProperty(networkID, "dhcphostname")
|
||||||
if dhcphname is None:
|
if dhcphname is None:
|
||||||
dhcphname = os.uname()[1]
|
dhcphname = os.uname()[1]
|
||||||
self.use_dhcp_h.set_state(bool(wireless.GetWirelessProperty(networkID,'usedhcphostname')))
|
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_sensitive(self.use_dhcp_h.get_state())
|
||||||
self.dhcp_h.set_edit_text(unicode(dhcphname))
|
self.dhcp_h.set_edit_text(unicode(dhcphname))
|
||||||
|
|
||||||
|
|
||||||
def set_net_prop(self, option, value):
|
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)
|
wireless.SetWirelessProperty(self.networkid, option, value)
|
||||||
@@ -467,19 +596,26 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
|
|
||||||
# Ripped from netentry.py
|
# Ripped from netentry.py
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
|
""" Save settings to disk. """
|
||||||
# Check encryption info
|
# Check encryption info
|
||||||
if self.encryption_chkbox.get_state():
|
if self.encryption_chkbox.get_state():
|
||||||
encrypt_info = self.encryption_info
|
encrypt_info = self.encryption_info
|
||||||
encrypt_methods = self.encrypt_types
|
encrypt_methods = self.encrypt_types
|
||||||
self.set_net_prop("enctype",
|
self.set_net_prop(
|
||||||
encrypt_methods[self.encryption_combo.get_focus()[1] ]['type'])
|
"enctype",
|
||||||
|
encrypt_methods[self.encryption_combo.get_focus()[1]]['type']
|
||||||
|
)
|
||||||
# Make sure all required fields are filled in.
|
# Make sure all required fields are filled in.
|
||||||
for entry_info in encrypt_info.itervalues():
|
for entry_info in encrypt_info.itervalues():
|
||||||
if entry_info[0].get_edit_text() == "" \
|
if entry_info[0].get_edit_text() == "" \
|
||||||
and entry_info[1] == 'required':
|
and entry_info[1] == 'required':
|
||||||
error(self.ui, self.parent,"%s (%s)" \
|
error(
|
||||||
% (_('Required encryption information is missing.'),
|
self.ui,
|
||||||
entry_info[0].get_caption()[0:-2] )
|
self.parent,
|
||||||
|
"%s (%s)" % (
|
||||||
|
_('Required encryption information is missing.'),
|
||||||
|
entry_info[0].get_caption()[0:-2]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -489,7 +625,11 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
elif not self.encryption_chkbox.get_state() and \
|
elif not self.encryption_chkbox.get_state() and \
|
||||||
wireless.GetWirelessProperty(self.networkid, "encryption"):
|
wireless.GetWirelessProperty(self.networkid, "encryption"):
|
||||||
# Encrypt checkbox is off, but the network needs it.
|
# 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
|
return False
|
||||||
else:
|
else:
|
||||||
self.set_net_prop("enctype", "None")
|
self.set_net_prop("enctype", "None")
|
||||||
@@ -505,12 +645,19 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.set_net_prop('use_settings_globally', False)
|
self.set_net_prop('use_settings_globally', False)
|
||||||
wireless.RemoveGlobalEssidEntry(self.networkid)
|
wireless.RemoveGlobalEssidEntry(self.networkid)
|
||||||
|
|
||||||
self.set_net_prop('bitrate', self.bitrates[self.bitrate_combo.get_focus()[1]])
|
self.set_net_prop(
|
||||||
self.set_net_prop('allow_lower_bitrates', self.allow_lower_bitrates_chkbox.get_state())
|
'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)
|
wireless.SaveWirelessNetworkProfile(self.networkid)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def ready_widgets(self, ui, body):
|
def ready_widgets(self, ui, body):
|
||||||
|
""" Build comboboxes. """
|
||||||
AdvancedSettingsDialog.ready_widgets(self, ui, body)
|
AdvancedSettingsDialog.ready_widgets(self, ui, body)
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.body = body
|
self.body = body
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import urwid
|
|||||||
import urwid.curses_display
|
import urwid.curses_display
|
||||||
|
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
from wicd import dbusmanager
|
|
||||||
from wicd.translations import _
|
from wicd.translations import _
|
||||||
from curses_misc import SelText, DynWrap, DynRadioButton, ComboBox, TabColumns
|
from curses_misc import SelText, DynWrap, DynRadioButton, ComboBox, TabColumns
|
||||||
|
|
||||||
@@ -31,12 +30,18 @@ daemon = None
|
|||||||
wireless = None
|
wireless = None
|
||||||
wired = None
|
wired = None
|
||||||
|
|
||||||
from wicd.translations import language
|
|
||||||
|
|
||||||
class PrefsDialog(urwid.WidgetWrap):
|
class PrefsDialog(urwid.WidgetWrap):
|
||||||
|
""" Preferences dialog. """
|
||||||
|
# pylint: disable-msg=W0231
|
||||||
def __init__(self, body, pos, ui, dbus=None):
|
def __init__(self, body, pos, ui, dbus=None):
|
||||||
global daemon, wireless, wired
|
global daemon, wireless, wired
|
||||||
|
|
||||||
|
self.thebackends = None
|
||||||
|
self.backends = None
|
||||||
|
self.wpadrivers = None
|
||||||
|
self.thedrivers = None
|
||||||
|
|
||||||
daemon = dbus['daemon']
|
daemon = dbus['daemon']
|
||||||
wireless = dbus['wireless']
|
wireless = dbus['wireless']
|
||||||
wired = dbus['wired']
|
wired = dbus['wired']
|
||||||
@@ -53,7 +58,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
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.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
|
||||||
self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
|
self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
|
||||||
title = _('Preferences')
|
title = ('Preferences')
|
||||||
|
|
||||||
# Blank line
|
# Blank line
|
||||||
_blank = urwid.Text('')
|
_blank = urwid.Text('')
|
||||||
@@ -63,11 +68,11 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
####
|
####
|
||||||
|
|
||||||
# General Settings
|
# General Settings
|
||||||
net_cat_t = ('header', _('Network Interfaces'))
|
net_cat_t = ('header', ('Network Interfaces'))
|
||||||
wired_t = ('editcp', _('Wired Interface')+': ')
|
wired_t = ('editcp', ('Wired Interface') + ': ')
|
||||||
wless_t = ('editcp', _('Wireless Interface')+':')
|
wless_t = ('editcp', ('Wireless Interface') + ':')
|
||||||
always_show_wired_t = _('''Always show wired interface''')
|
always_show_wired_t = _('Always show wired interface')
|
||||||
prefer_wired_t = _('''Always switch to wired connection when available''')
|
prefer_wired_t = _('Always switch to wired connection when available')
|
||||||
|
|
||||||
global_dns_cat_t = ('header', _('Global DNS servers'))
|
global_dns_cat_t = ('header', _('Global DNS servers'))
|
||||||
global_dns_t = ('editcp', _('Use global DNS servers'))
|
global_dns_t = ('editcp', _('Use global DNS servers'))
|
||||||
@@ -77,7 +82,6 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
dns2_t = ('editcp', ' ' + _('DNS server') + ' 2: ')
|
dns2_t = ('editcp', ' ' + _('DNS server') + ' 2: ')
|
||||||
dns3_t = ('editcp', ' ' + _('DNS server') + ' 3: ')
|
dns3_t = ('editcp', ' ' + _('DNS server') + ' 3: ')
|
||||||
|
|
||||||
|
|
||||||
wired_auto_cat_t = ('header', _('Wired Autoconnect Settings'))
|
wired_auto_cat_t = ('header', _('Wired Autoconnect Settings'))
|
||||||
wired_auto_1_t = _('Use default profile on wired autoconnect')
|
wired_auto_1_t = _('Use default profile on wired autoconnect')
|
||||||
wired_auto_2_t = _('Prompt for profile on wired autoconnect')
|
wired_auto_2_t = _('Prompt for profile on wired autoconnect')
|
||||||
@@ -108,7 +112,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
wpa_cat_t = ('header', _('WPA Supplicant'))
|
wpa_cat_t = ('header', _('WPA Supplicant'))
|
||||||
wpa_t = ('editcp', 'Driver:')
|
wpa_t = ('editcp', 'Driver:')
|
||||||
wpa_list = []
|
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_cat_t = ('header', _('Backend'))
|
||||||
backend_t = _('Backend') + ':'
|
backend_t = _('Backend') + ':'
|
||||||
@@ -119,9 +124,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
wless_cat_t = ('header', _('Wireless Interface'))
|
wless_cat_t = ('header', _('Wireless Interface'))
|
||||||
use_dbm_t = _('Use dBm to measure signal strength')
|
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
|
||||||
@@ -129,22 +133,25 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
# General Settings
|
# General Settings
|
||||||
self.net_cat = urwid.Text(net_cat_t)
|
self.net_cat = urwid.Text(net_cat_t)
|
||||||
self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc')
|
self.wired_edit = \
|
||||||
self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc')
|
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.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
|
||||||
self.global_dns_cat = urwid.Text(global_dns_cat_t)
|
self.global_dns_cat = urwid.Text(global_dns_cat_t)
|
||||||
# Default the global DNS settings to off. They will be reenabled later
|
# Default the global DNS settings to off. They will be reenabled later
|
||||||
# if so required.
|
# if so required.
|
||||||
global_dns_state = False
|
global_dns_state = False
|
||||||
self.global_dns_checkb = urwid.CheckBox(global_dns_t, global_dns_state,
|
self.global_dns_checkb = urwid.CheckBox(global_dns_t,
|
||||||
on_state_change=self.global_dns_trigger)
|
global_dns_state,
|
||||||
|
on_state_change=self.global_dns_trigger
|
||||||
|
)
|
||||||
self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
|
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.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
|
||||||
self.dns1 = DynWrap(urwid.Edit(dns1_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.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
|
||||||
self.dns3 = DynWrap(urwid.Edit(dns3_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.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)
|
||||||
|
|
||||||
self.wired_auto_l = []
|
self.wired_auto_l = []
|
||||||
@@ -155,7 +162,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
|
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
|
||||||
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
|
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
|
||||||
generalLB = urwid.ListBox([self.net_cat,
|
generalLB = urwid.ListBox([
|
||||||
|
self.net_cat,
|
||||||
self.wless_edit, # _blank,
|
self.wless_edit, # _blank,
|
||||||
self.wired_edit,
|
self.wired_edit,
|
||||||
self.always_show_wired_checkb,
|
self.always_show_wired_checkb,
|
||||||
@@ -179,14 +187,16 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.dhcp_l = []
|
self.dhcp_l = []
|
||||||
|
|
||||||
# Order of these is flipped in the actual interface,
|
# Order of these is flipped in the actual interface,
|
||||||
# (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
|
# (2, 3, 1 -> dhcpcd, pump, dhclient), because dhclient often doesn't
|
||||||
# to work on several distros.
|
# like to work on several distros.
|
||||||
self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
|
self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
|
||||||
self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
|
self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
|
||||||
self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
|
self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
|
||||||
self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
|
self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
|
||||||
self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
|
self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
|
||||||
self.dhcp_l = [self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,self.dhcp4]
|
self.dhcp_l = [
|
||||||
|
self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
|
||||||
|
]
|
||||||
|
|
||||||
self.wired_l = []
|
self.wired_l = []
|
||||||
self.wired_detect_header = urwid.Text(wired_detect_header_t)
|
self.wired_detect_header = urwid.Text(wired_detect_header_t)
|
||||||
@@ -202,9 +212,9 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.flush2 = DynRadioButton(self.flush_l, flush2_t)
|
self.flush2 = DynRadioButton(self.flush_l, flush2_t)
|
||||||
self.flush_l = [self.flush0, self.flush1, self.flush2]
|
self.flush_l = [self.flush0, self.flush1, self.flush2]
|
||||||
|
|
||||||
externalLB = urwid.ListBox([self.dhcp_header,
|
externalLB = urwid.ListBox([
|
||||||
self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,
|
self.dhcp_header,
|
||||||
self.dhcp4,
|
self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1, self.dhcp4,
|
||||||
_blank,
|
_blank,
|
||||||
self.wired_detect_header,
|
self.wired_detect_header,
|
||||||
self.wired0, self.wired1, self.wired2,
|
self.wired0, self.wired1, self.wired2,
|
||||||
@@ -213,7 +223,6 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.flush0, self.flush1, self.flush2
|
self.flush0, self.flush1, self.flush2
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
#### Advanced settings
|
#### Advanced settings
|
||||||
self.wpa_cat = urwid.Text(wpa_cat_t)
|
self.wpa_cat = urwid.Text(wpa_cat_t)
|
||||||
self.wpa_cbox = ComboBox(wpa_t)
|
self.wpa_cbox = ComboBox(wpa_t)
|
||||||
@@ -229,8 +238,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
|
self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
|
||||||
self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)
|
self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)
|
||||||
|
|
||||||
|
advancedLB = urwid.ListBox([
|
||||||
advancedLB = urwid.ListBox([self.wpa_cat,
|
self.wpa_cat,
|
||||||
self.wpa_cbox, self.wpa_warn, _blank,
|
self.wpa_cbox, self.wpa_warn, _blank,
|
||||||
self.backend_cat,
|
self.backend_cat,
|
||||||
self.backend_cbox, _blank,
|
self.backend_cbox, _blank,
|
||||||
@@ -241,19 +250,21 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.verify_ap_checkb, _blank
|
self.verify_ap_checkb, _blank
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
headerList = [self.header0, self.header1, self.header2]
|
headerList = [self.header0, self.header1, self.header2]
|
||||||
lbList = [generalLB, externalLB, advancedLB]
|
lbList = [generalLB, externalLB, advancedLB]
|
||||||
self.tab_map = {self.header0 : generalLB,
|
self.tab_map = {
|
||||||
|
self.header0: generalLB,
|
||||||
self.header1: externalLB,
|
self.header1: externalLB,
|
||||||
self.header2 : advancedLB}
|
self.header2: advancedLB
|
||||||
|
}
|
||||||
#self.load_settings()
|
#self.load_settings()
|
||||||
|
|
||||||
self.tabs = TabColumns(headerList, lbList, _('Preferences'))
|
self.tabs = TabColumns(headerList, lbList, _('Preferences'))
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(self.tabs)
|
self.__super.__init__(self.tabs)
|
||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
|
""" Load settings to be used in the dialog. """
|
||||||
### General Settings
|
### General Settings
|
||||||
# ComboBox does not like dbus.Strings as text markups. My fault. :/
|
# ComboBox does not like dbus.Strings as text markups. My fault. :/
|
||||||
wless_iface = unicode(daemon.GetWirelessInterface())
|
wless_iface = unicode(daemon.GetWirelessInterface())
|
||||||
@@ -278,6 +289,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
|
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
|
||||||
|
|
||||||
def find_avail(apps):
|
def find_avail(apps):
|
||||||
|
""" Find available apps. """
|
||||||
for app in apps[1:]:
|
for app in apps[1:]:
|
||||||
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
|
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
|
||||||
|
|
||||||
@@ -329,17 +341,25 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
This exact order is found in prefs.py"""
|
This exact order is found in prefs.py"""
|
||||||
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
|
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
|
||||||
|
|
||||||
for i in [self.dns1, self.dns2,
|
for i in [
|
||||||
self.dns3,self.dns_dom, self.search_dom, self.dns_dom]:
|
self.dns1, self.dns2, self.dns3,
|
||||||
|
self.dns_dom, self.search_dom, self.dns_dom
|
||||||
|
]:
|
||||||
i.set_edit_text(i.get_edit_text().strip())
|
i.set_edit_text(i.get_edit_text().strip())
|
||||||
|
|
||||||
daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
|
daemon.SetGlobalDNS(
|
||||||
self.dns3.get_edit_text(), self.dns_dom.get_edit_text(),
|
self.dns1.get_edit_text(),
|
||||||
self.search_dom.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.SetWirelessInterface(self.wless_edit.get_edit_text())
|
||||||
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
|
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
|
||||||
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
|
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
|
||||||
daemon.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state())
|
daemon.SetAlwaysShowWiredInterface(
|
||||||
|
self.always_show_wired_checkb.get_state()
|
||||||
|
)
|
||||||
daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
|
daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
|
||||||
daemon.SetDebugMode(self.debug_mode_checkb.get_state())
|
daemon.SetDebugMode(self.debug_mode_checkb.get_state())
|
||||||
daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
|
daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
|
||||||
@@ -383,11 +403,12 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
flush_tool = misc.ROUTE
|
flush_tool = misc.ROUTE
|
||||||
daemon.SetFlushTool(flush_tool)
|
daemon.SetFlushTool(flush_tool)
|
||||||
|
|
||||||
# DNS CheckBox callback
|
|
||||||
def global_dns_trigger(self, check_box, new_state, user_data=None):
|
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:
|
for w in self.dns1, self.dns2, self.dns3, self.dns_dom, self.search_dom:
|
||||||
w.set_sensitive(new_state)
|
w.set_sensitive(new_state)
|
||||||
|
|
||||||
def ready_widgets(self, ui, body):
|
def ready_widgets(self, ui, body):
|
||||||
|
""" Build comboboxes. """
|
||||||
self.wpa_cbox.build_combobox(body, ui, 4)
|
self.wpa_cbox.build_combobox(body, ui, 4)
|
||||||
self.backend_cbox.build_combobox(body, ui, 8)
|
self.backend_cbox.build_combobox(body, ui, 8)
|
||||||
|
|||||||
@@ -25,24 +25,26 @@ at least get a network connection. Or those who don't like using X and/or GTK.
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
|
|
||||||
"""
|
|
||||||
This contains/will contain A LOT of code from the other parts of wicd.
|
|
||||||
|
|
||||||
This is probably due to the fact that I did not really know what I was doing
|
# This contains/will contain A LOT of code from the other parts of wicd.
|
||||||
when I started writing this. It works, so I guess that's all that matters.
|
#
|
||||||
|
# This is probably due to the fact that I did not really know what I was doing
|
||||||
|
# when I started writing this. It works, so I guess that's all that matters.
|
||||||
|
#
|
||||||
|
# Comments, criticisms, patches, bug reports all welcome!
|
||||||
|
|
||||||
Comments, criticisms, patches, bug reports all welcome!
|
|
||||||
"""
|
|
||||||
# Filter out a confusing urwid warning in python 2.6.
|
# Filter out a confusing urwid warning in python 2.6.
|
||||||
# This is valid as of urwid version 0.9.8.4
|
# This is valid as of urwid version 0.9.8.4
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings("ignore","The popen2 module is deprecated. Use the subprocess module.")
|
warnings.filterwarnings(
|
||||||
|
"ignore",
|
||||||
|
"The popen2 module is deprecated. Use the subprocess module."
|
||||||
|
)
|
||||||
# UI stuff
|
# UI stuff
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
# DBus communication stuff
|
# DBus communication stuff
|
||||||
from dbus import DBusException
|
from dbus import DBusException
|
||||||
from dbus import version as dbus_version
|
|
||||||
# It took me a while to figure out that I have to use this.
|
# It took me a while to figure out that I have to use this.
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
@@ -53,17 +55,16 @@ from wicd import dbusmanager
|
|||||||
|
|
||||||
# Internal Python stuff
|
# Internal Python stuff
|
||||||
import sys
|
import sys
|
||||||
from time import sleep, strftime, ctime
|
|
||||||
|
|
||||||
# Curses UIs for other stuff
|
# Curses UIs for other stuff
|
||||||
from curses_misc import *
|
from curses_misc import ComboBox, Dialog2, NSelListBox, SelText, OptCols
|
||||||
|
from curses_misc import TextDialog, InputDialog, error, DynEdit, DynIntEdit
|
||||||
from prefs_curses import PrefsDialog
|
from prefs_curses import PrefsDialog
|
||||||
import netentry_curses
|
|
||||||
|
|
||||||
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog,AdvancedSettingsDialog
|
import netentry_curses
|
||||||
|
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os import system
|
|
||||||
|
|
||||||
# Stuff about getting the script configurer running
|
# Stuff about getting the script configurer running
|
||||||
#from grp import getgrgid
|
#from grp import getgrgid
|
||||||
@@ -75,14 +76,19 @@ from os import system
|
|||||||
CURSES_REV = wpath.curses_revision
|
CURSES_REV = wpath.curses_revision
|
||||||
|
|
||||||
# Fix strings in wicd-curses
|
# Fix strings in wicd-curses
|
||||||
from wicd.translations import language
|
#from wicd.translations import language
|
||||||
from wicd.translations import _
|
from wicd.translations import _
|
||||||
|
|
||||||
|
ui = None
|
||||||
|
loop = None
|
||||||
|
bus = daemon = wireless = wired = None
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### SUPPORT CLASSES
|
##### SUPPORT CLASSES
|
||||||
########################################
|
########################################
|
||||||
# Yay for decorators!
|
# Yay for decorators!
|
||||||
def wrap_exceptions(func):
|
def wrap_exceptions(func):
|
||||||
|
""" Decorator to wrap exceptions. """
|
||||||
def wrapper(*args, **kargs):
|
def wrapper(*args, **kargs):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kargs)
|
return func(*args, **kargs)
|
||||||
@@ -95,8 +101,9 @@ def wrap_exceptions(func):
|
|||||||
except DBusException:
|
except DBusException:
|
||||||
loop.quit()
|
loop.quit()
|
||||||
ui.stop()
|
ui.stop()
|
||||||
print >> sys.stderr,"\n"+_('DBus failure! '\
|
print >> sys.stderr, "\n" + _('DBus failure! '
|
||||||
'This is most likely caused by the wicd daemon stopping while wicd-curses is running. '\
|
'This is most likely caused by the wicd daemon '
|
||||||
|
'stopping while wicd-curses is running. '
|
||||||
'Please restart the daemon, and then restart wicd-curses.')
|
'Please restart the daemon, and then restart wicd-curses.')
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
@@ -107,7 +114,9 @@ def wrap_exceptions(func):
|
|||||||
ui.stop()
|
ui.stop()
|
||||||
# Print out standard notification:
|
# Print out standard notification:
|
||||||
# This message was far too scary for humans, so it's gone now.
|
# This message was far too scary for humans, so it's gone now.
|
||||||
# print >> sys.stderr, "\n" + _('EXCEPTION! Please report this to the maintainer and file a bug report with the backtrace below:')
|
# print >> sys.stderr, "\n" + _('EXCEPTION! Please report this '
|
||||||
|
# 'to the maintainer and file a bug report with the backtrace '
|
||||||
|
# 'below:')
|
||||||
# Flush the buffer so that the notification is always above the
|
# Flush the buffer so that the notification is always above the
|
||||||
# backtrace
|
# backtrace
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@@ -120,6 +129,7 @@ def wrap_exceptions(func):
|
|||||||
wrapper.__doc__ = func.__doc__
|
wrapper.__doc__ = func.__doc__
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### SUPPORT FUNCTIONS
|
##### SUPPORT FUNCTIONS
|
||||||
########################################
|
########################################
|
||||||
@@ -130,11 +140,14 @@ def wrap_exceptions(func):
|
|||||||
def check_for_wired(wired_ip, set_status):
|
def check_for_wired(wired_ip, set_status):
|
||||||
""" Determine if wired is active, and if yes, set the status. """
|
""" Determine if wired is active, and if yes, set the status. """
|
||||||
if wired_ip and wired.CheckPluggedIn():
|
if wired_ip and wired.CheckPluggedIn():
|
||||||
set_status(_('Connected to wired network (IP: $A)').replace('$A',wired_ip))
|
set_status(
|
||||||
|
_('Connected to wired network (IP: $A)').replace('$A',wired_ip)
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@wrap_exceptions
|
@wrap_exceptions
|
||||||
def check_for_wireless(iwconfig, wireless_ip, set_status):
|
def check_for_wireless(iwconfig, wireless_ip, set_status):
|
||||||
""" Determine if wireless is active, and if yes, set the status. """
|
""" Determine if wireless is active, and if yes, set the status. """
|
||||||
@@ -167,17 +180,23 @@ def check_for_wireless(iwconfig, wireless_ip, set_status):
|
|||||||
# DBUS interfaces do. :P
|
# DBUS interfaces do. :P
|
||||||
# Whatever calls this must be exception-wrapped if it is run if the UI is up
|
# Whatever calls this must be exception-wrapped if it is run if the UI is up
|
||||||
def gen_network_list():
|
def gen_network_list():
|
||||||
|
""" Generate the list of networks. """
|
||||||
wiredL = wired.GetWiredProfileList()
|
wiredL = wired.GetWiredProfileList()
|
||||||
wlessL = []
|
wlessL = []
|
||||||
# This one makes a list of NetLabels
|
# This one makes a list of NetLabels
|
||||||
for network_id in range(0, wireless.GetNumberOfNetworks()):
|
for network_id in range(0, wireless.GetNumberOfNetworks()):
|
||||||
is_active = wireless.GetCurrentSignalStrength("") != 0 and wireless.GetCurrentNetworkID(wireless.GetIwconfig())==network_id and wireless.GetWirelessIP('') != None
|
is_active = \
|
||||||
|
wireless.GetCurrentSignalStrength("") != 0 and \
|
||||||
|
wireless.GetCurrentNetworkID(wireless.GetIwconfig()) == network_id \
|
||||||
|
and wireless.GetWirelessIP('') is not None
|
||||||
|
|
||||||
label = NetLabel(network_id, is_active)
|
label = NetLabel(network_id, is_active)
|
||||||
wlessL.append(label)
|
wlessL.append(label)
|
||||||
return (wiredL, wlessL)
|
return (wiredL, wlessL)
|
||||||
|
|
||||||
|
|
||||||
def about_dialog(body):
|
def about_dialog(body):
|
||||||
|
""" About dialog. """
|
||||||
# This looks A LOT better when it is actually displayed. I promise :-).
|
# This looks A LOT better when it is actually displayed. I promise :-).
|
||||||
# The ASCII Art "Wicd" was made from the "smslant" font on one of those
|
# The ASCII Art "Wicd" was made from the "smslant" font on one of those
|
||||||
# online ASCII big text generators.
|
# online ASCII big text generators.
|
||||||
@@ -190,8 +209,10 @@ def about_dialog(body):
|
|||||||
" ($VERSION) \n".replace("$VERSION", daemon.Hello()),
|
" ($VERSION) \n".replace("$VERSION", daemon.Hello()),
|
||||||
|
|
||||||
('green', "\\|| \\\\"), " |+| ", ('green', "// ||/ \n"),
|
('green', "\\|| \\\\"), " |+| ", ('green', "// ||/ \n"),
|
||||||
('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net\n",
|
('green', " \\\\\\"), " |+| ", ('green', "///"),
|
||||||
('green'," \\\\\\")," |+| ",('green',"///")," ",_('Brought to you by:'),"\n",
|
" http://wicd.net\n",
|
||||||
|
('green', " \\\\\\"), " |+| ", ('green', "///"), " ",
|
||||||
|
_('Brought to you by:'), "\n",
|
||||||
('green', " \\\\\\"), " |+| ", ('green', "///"), " Adam Blackburn\n",
|
('green', " \\\\\\"), " |+| ", ('green', "///"), " Adam Blackburn\n",
|
||||||
" ___|+|___ Dan O'Reilly\n",
|
" ___|+|___ Dan O'Reilly\n",
|
||||||
" ____|+|____ Andrew Psaltis\n",
|
" ____|+|____ Andrew Psaltis\n",
|
||||||
@@ -200,14 +221,21 @@ def about_dialog(body):
|
|||||||
about = TextDialog(theText, 16, 55, header=('header', _('About Wicd')))
|
about = TextDialog(theText, 16, 55, header=('header', _('About Wicd')))
|
||||||
about.run(ui, body)
|
about.run(ui, body)
|
||||||
|
|
||||||
|
|
||||||
# Modeled after htop's help
|
# Modeled after htop's help
|
||||||
def help_dialog(body):
|
def help_dialog(body):
|
||||||
|
""" Help dialog. """
|
||||||
textT = urwid.Text(('header', _('wicd-curses help')), 'right')
|
textT = urwid.Text(('header', _('wicd-curses help')), 'right')
|
||||||
textSH = urwid.Text(['This is ',('blue','wicd-curses-'+CURSES_REV),' using wicd ',unicode(daemon.Hello()),'\n'])
|
textSH = urwid.Text([
|
||||||
|
'This is ', ('blue', 'wicd-curses-' + CURSES_REV),
|
||||||
|
' using wicd ', unicode(daemon.Hello()), '\n'
|
||||||
|
])
|
||||||
|
|
||||||
textH = urwid.Text([
|
textH = urwid.Text([
|
||||||
_('For more detailed help, consult the wicd-curses(8) man page.') + "\n",
|
_('For more detailed help, consult the wicd-curses(8) man page.') + "\n",
|
||||||
('bold','->'),' and ',('bold','<-')," are the right and left arrows respectively.\n"])
|
('bold', '->'), ' and ', ('bold', '<-'),
|
||||||
|
" are the right and left arrows respectively.\n"
|
||||||
|
])
|
||||||
|
|
||||||
text1 = urwid.Text([
|
text1 = urwid.Text([
|
||||||
('bold', ' H h ?'), ": " + _('Display this help dialog') + "\n",
|
('bold', ' H h ?'), ": " + _('Display this help dialog') + "\n",
|
||||||
@@ -258,7 +286,9 @@ _('For more detailed help, consult the wicd-curses(8) man page.')+"\n",
|
|||||||
elif keys:
|
elif keys:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def run_configscript(parent, netname, nettype):
|
def run_configscript(parent, netname, nettype):
|
||||||
|
""" Run configuration script. """
|
||||||
configfile = wpath.etc + netname + '-settings.conf'
|
configfile = wpath.etc + netname + '-settings.conf'
|
||||||
if nettype != 'wired':
|
if nettype != 'wired':
|
||||||
header = 'profile'
|
header = 'profile'
|
||||||
@@ -269,69 +299,76 @@ def run_configscript(parent,netname,nettype):
|
|||||||
else:
|
else:
|
||||||
profname = wireless.GetWirelessProperty(int(netname), 'bssid')
|
profname = wireless.GetWirelessProperty(int(netname), 'bssid')
|
||||||
theText = [
|
theText = [
|
||||||
_('To avoid various complications, wicd-curses does not support directly editing the scripts. '\
|
_('To avoid various complications, wicd-curses does not support directly '
|
||||||
'However, you can edit them manually. First, (as root), open the "$A" config file, and look '\
|
'editing the scripts. However, you can edit them manually. First, (as root), '
|
||||||
'for the section labeled by the $B in question. In this case, this is:').
|
'open the "$A" config file, and look for the section labeled by the $B in '
|
||||||
|
'question. In this case, this is:').
|
||||||
replace('$A', configfile).replace('$B', header),
|
replace('$A', configfile).replace('$B', header),
|
||||||
"\n\n[" + profname + "]\n\n",
|
"\n\n[" + profname + "]\n\n",
|
||||||
_('You can also configure the wireless networks by looking for the "[<ESSID>]" field in the config file.'),
|
_('You can also configure the wireless networks by looking for the "[<ESSID>]" '
|
||||||
_('Once there, you can adjust (or add) the "beforescript", "afterscript", "predisconnectscript" '\
|
'field in the config file.'),
|
||||||
'and "postdisconnectscript" variables as needed, to change the preconnect, postconnect, '\
|
_('Once there, you can adjust (or add) the "beforescript", "afterscript", '
|
||||||
'predisconnect and postdisconnect scripts respectively. Note that you will be specifying '\
|
'"predisconnectscript" and "postdisconnectscript" variables as needed, to '
|
||||||
'the full path to the scripts - not the actual script contents. You will need to add/edit '\
|
'change the preconnect, postconnect, predisconnect and postdisconnect scripts '
|
||||||
'the script contents separately. Refer to the wicd manual page for more information.')
|
'respectively. Note that you will be specifying the full path to the scripts '
|
||||||
|
'- not the actual script contents. You will need to add/edit the script '
|
||||||
|
'contents separately. Refer to the wicd manual page for more information.')
|
||||||
]
|
]
|
||||||
dialog = TextDialog(theText, 20, 80)
|
dialog = TextDialog(theText, 20, 80)
|
||||||
dialog.run(ui, parent)
|
dialog.run(ui, parent)
|
||||||
# This code works with many distributions, but not all of them. So, to
|
# This code works with many distributions, but not all of them. So, to
|
||||||
# limit complications, it has been deactivated. If you want to run it,
|
# limit complications, it has been deactivated. If you want to run it,
|
||||||
# be my guest. Be sure to deactivate the above stuff first.
|
# be my guest. Be sure to deactivate the above stuff first.
|
||||||
"""
|
|
||||||
loop.quit()
|
|
||||||
ui.stop()
|
|
||||||
argv = netname + ' ' +nettype
|
|
||||||
|
|
||||||
#cmd = '/usr/lib/configscript_curses.py '+argv
|
#loop.quit()
|
||||||
cmd = wpath.lib+'configscript_curses.py '+argv
|
#ui.stop()
|
||||||
# Check whether we can sudo. Hopefully this is complete
|
#argv = netname + ' ' +nettype
|
||||||
glist = []
|
|
||||||
for i in getgroups():
|
##cmd = '/usr/lib/configscript_curses.py '+argv
|
||||||
glist.append(getgrgid(i)[0])
|
#cmd = wpath.lib+'configscript_curses.py '+argv
|
||||||
if 'root' in glist:
|
## Check whether we can sudo. Hopefully this is complete
|
||||||
precmd = ''
|
#glist = []
|
||||||
precmdargv = ''
|
#for i in getgroups():
|
||||||
postcmd = ''
|
#glist.append(getgrgid(i)[0])
|
||||||
elif 'admin' in glist or 'wheel' in glist or 'sudo' in glist:
|
#if 'root' in glist:
|
||||||
precmd = 'sudo'
|
#precmd = ''
|
||||||
precmdargv = ''
|
#precmdargv = ''
|
||||||
postcmd = ''
|
#postcmd = ''
|
||||||
else:
|
#elif 'admin' in glist or 'wheel' in glist or 'sudo' in glist:
|
||||||
precmd = 'su'
|
#precmd = 'sudo'
|
||||||
precmdargv = ' -c "'
|
#precmdargv = ''
|
||||||
postcmd = '"'
|
#postcmd = ''
|
||||||
print "Calling command: " + precmd + precmdargv + cmd + postcmd
|
#else:
|
||||||
sys.stdout.flush()
|
#precmd = 'su'
|
||||||
system(precmd+precmdargv+cmd+postcmd)
|
#precmdargv = ' -c "'
|
||||||
raw_input("Press enter!")
|
#postcmd = '"'
|
||||||
main()
|
#print "Calling command: " + precmd + precmdargv + cmd + postcmd
|
||||||
"""
|
#sys.stdout.flush()
|
||||||
|
#system(precmd+precmdargv+cmd+postcmd)
|
||||||
|
#raw_input("Press enter!")
|
||||||
|
#main()
|
||||||
|
|
||||||
|
|
||||||
def gen_list_header():
|
def gen_list_header():
|
||||||
|
""" Generate header. """
|
||||||
if daemon.GetSignalDisplayType() == 0:
|
if daemon.GetSignalDisplayType() == 0:
|
||||||
# Allocate 25 cols for the ESSID name
|
# Allocate 25 cols for the ESSID name
|
||||||
essidgap = 25
|
essidgap = 25
|
||||||
else:
|
else:
|
||||||
# Need 3 more to accomodate dBm strings
|
# Need 3 more to accomodate dBm strings
|
||||||
essidgap = 28
|
essidgap = 28
|
||||||
return 'C %s %*s %9s %17s %6s %s' % ('STR ',essidgap,'ESSID','ENCRYPT','BSSID','MODE','CHNL')
|
return 'C %s %*s %9s %17s %6s %s' % \
|
||||||
|
('STR ', essidgap, 'ESSID', 'ENCRYPT', 'BSSID', 'MODE', 'CHNL')
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### URWID SUPPORT CLASSES
|
##### URWID SUPPORT CLASSES
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
# Wireless network label
|
|
||||||
class NetLabel(urwid.WidgetWrap):
|
class NetLabel(urwid.WidgetWrap):
|
||||||
def __init__(self, id, is_active):
|
""" Wireless network label. """
|
||||||
|
# pylint: disable-msg=W0231
|
||||||
|
def __init__(self, i, is_active):
|
||||||
# Pick which strength measure to use based on what the daemon says
|
# Pick which strength measure to use based on what the daemon says
|
||||||
# gap allocates more space to the first module
|
# gap allocates more space to the first module
|
||||||
if daemon.GetSignalDisplayType() == 0:
|
if daemon.GetSignalDisplayType() == 0:
|
||||||
@@ -340,58 +377,79 @@ class NetLabel(urwid.WidgetWrap):
|
|||||||
else:
|
else:
|
||||||
strenstr = 'strength'
|
strenstr = 'strength'
|
||||||
gap = 7 # -XX dbm = 7
|
gap = 7 # -XX dbm = 7
|
||||||
self.id = id
|
self.id = i
|
||||||
# All of that network property stuff
|
# All of that network property stuff
|
||||||
self.stren = daemon.FormatSignalForPrinting(
|
self.stren = daemon.FormatSignalForPrinting(
|
||||||
str(wireless.GetWirelessProperty(id, strenstr)))
|
str(wireless.GetWirelessProperty(self.id, strenstr)))
|
||||||
self.essid = wireless.GetWirelessProperty(id, 'essid')
|
self.essid = wireless.GetWirelessProperty(self.id, 'essid')
|
||||||
self.bssid = wireless.GetWirelessProperty(id, 'bssid')
|
self.bssid = wireless.GetWirelessProperty(self.id, 'bssid')
|
||||||
|
|
||||||
if wireless.GetWirelessProperty(id, 'encryption'):
|
if wireless.GetWirelessProperty(self.id, 'encryption'):
|
||||||
self.encrypt = wireless.GetWirelessProperty(id,'encryption_method')
|
self.encrypt = \
|
||||||
|
wireless.GetWirelessProperty(self.id, 'encryption_method')
|
||||||
else:
|
else:
|
||||||
self.encrypt = _('Unsecured')
|
self.encrypt = _('Unsecured')
|
||||||
|
|
||||||
self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc
|
self.mode = \
|
||||||
self.channel = wireless.GetWirelessProperty(id, 'channel')
|
wireless.GetWirelessProperty(self.id, 'mode') # Master, Ad-Hoc
|
||||||
theString = ' %-*s %25s %9s %17s %6s %4s' % (gap,
|
self.channel = wireless.GetWirelessProperty(self.id, 'channel')
|
||||||
self.stren,self.essid,self.encrypt,self.bssid,self.mode,self.channel)
|
theString = ' %-*s %25s %9s %17s %6s %4s' % \
|
||||||
|
(gap, self.stren, self.essid, self.encrypt, self.bssid, self.mode,
|
||||||
|
self.channel)
|
||||||
if is_active:
|
if is_active:
|
||||||
theString = '>' + theString[1:]
|
theString = '>' + theString[1:]
|
||||||
w = urwid.AttrWrap(SelText(theString),'connected','connected focus')
|
w = urwid.AttrWrap(
|
||||||
|
SelText(theString),
|
||||||
|
'connected',
|
||||||
|
'connected focus'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
w = urwid.AttrWrap(SelText(theString), 'body', 'focus')
|
w = urwid.AttrWrap(SelText(theString), 'body', 'focus')
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(w)
|
self.__super.__init__(w)
|
||||||
|
|
||||||
def selectable(self):
|
def selectable(self):
|
||||||
|
""" Return whether the widget is selectable. """
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
""" Handle keypresses. """
|
||||||
return self._w.keypress(size, key)
|
return self._w.keypress(size, key)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
""" Execute connection. """
|
||||||
wireless.ConnectWireless(self.id)
|
wireless.ConnectWireless(self.id)
|
||||||
|
|
||||||
|
|
||||||
class WiredComboBox(ComboBox):
|
class WiredComboBox(ComboBox):
|
||||||
"""
|
"""
|
||||||
list : the list of wired network profiles. The rest is self-explanitory.
|
list : the list of wired network profiles. The rest is self-explanitory.
|
||||||
"""
|
"""
|
||||||
def __init__(self,list):
|
# pylint: disable-msg=W0231
|
||||||
|
def __init__(self, l):
|
||||||
self.ADD_PROFILE = '---' + _('Add a new profile') + '---'
|
self.ADD_PROFILE = '---' + _('Add a new profile') + '---'
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.__super.__init__(use_enter=False)
|
self.__super.__init__(use_enter=False)
|
||||||
self.set_list(list)
|
self.theList = []
|
||||||
|
self.set_list(l)
|
||||||
|
|
||||||
def set_list(self,list):
|
def set_list(self, l):
|
||||||
self.theList = list
|
""" Set contents of the combobox. """
|
||||||
id=0
|
self.theList = l
|
||||||
|
i = 0
|
||||||
wiredL = []
|
wiredL = []
|
||||||
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
|
is_active = \
|
||||||
for profile in list:
|
wireless.GetWirelessIP('') is None and \
|
||||||
theString = '%4s %25s' % (id, profile)
|
wired.GetWiredIP('') is not None
|
||||||
|
for profile in l:
|
||||||
|
theString = '%4s %25s' % (i, profile)
|
||||||
# Tag if no wireless IP present, and wired one is
|
# Tag if no wireless IP present, and wired one is
|
||||||
if is_active:
|
if is_active:
|
||||||
theString = '>' + theString[1:]
|
theString = '>' + theString[1:]
|
||||||
|
|
||||||
wiredL.append(theString)
|
wiredL.append(theString)
|
||||||
id+=1
|
i += 1
|
||||||
wiredL.append(self.ADD_PROFILE)
|
wiredL.append(self.ADD_PROFILE)
|
||||||
if is_active:
|
if is_active:
|
||||||
self.attrs = ('connected', 'editnfc')
|
self.attrs = ('connected', 'editnfc')
|
||||||
@@ -404,11 +462,15 @@ class WiredComboBox(ComboBox):
|
|||||||
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
""" Handle keypresses. """
|
||||||
prev_focus = self.get_focus()[1]
|
prev_focus = self.get_focus()[1]
|
||||||
key = ComboBox.keypress(self, size, key)
|
key = ComboBox.keypress(self, size, key)
|
||||||
if key == ' ':
|
if key == ' ':
|
||||||
if self.get_focus()[1] == len(self.list) - 1:
|
if self.get_focus()[1] == len(self.list) - 1:
|
||||||
dialog = InputDialog(('header',_('Add a new wired profile')),7,30)
|
dialog = InputDialog(
|
||||||
|
('header', _('Add a new wired profile')),
|
||||||
|
7, 30
|
||||||
|
)
|
||||||
exitcode, name = dialog.run(ui, self.parent)
|
exitcode, name = dialog.run(ui, self.parent)
|
||||||
if exitcode == 0:
|
if exitcode == 0:
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
@@ -425,21 +487,31 @@ class WiredComboBox(ComboBox):
|
|||||||
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
||||||
if key == 'delete':
|
if key == 'delete':
|
||||||
if len(self.theList) == 1:
|
if len(self.theList) == 1:
|
||||||
error(self.ui,self.parent,_('wicd-curses does not support deleting the last wired profile. Try renaming it ("F2")'))
|
error(
|
||||||
|
self.ui,
|
||||||
|
self.parent,
|
||||||
|
_('wicd-curses does not support deleting the last wired '
|
||||||
|
'profile. Try renaming it ("F2")')
|
||||||
|
)
|
||||||
return key
|
return key
|
||||||
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
|
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
|
||||||
# Return to the top of the list if something is deleted.
|
# Return to the top of the list if something is deleted.
|
||||||
|
|
||||||
if wired.GetDefaultWiredNetwork() != None:
|
if wired.GetDefaultWiredNetwork() is not None:
|
||||||
self.set_focus(self.theList.index(wired.GetDefaultWiredNetwork()))
|
self.set_focus(
|
||||||
|
self.theList.index(wired.GetDefaultWiredNetwork())
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
prev_focus -= 1
|
prev_focus -= 1
|
||||||
self.set_focus(prev_focus)
|
self.set_focus(prev_focus)
|
||||||
self.set_list(wired.GetWiredProfileList())
|
self.set_list(wired.GetWiredProfileList())
|
||||||
self.rebuild_combobox()
|
self.rebuild_combobox()
|
||||||
if key == 'f2':
|
if key == 'f2':
|
||||||
dialog = InputDialog(('header',_('Rename wired profile')),7,30,
|
dialog = InputDialog(
|
||||||
edit_text=unicode(self.get_selected_profile()))
|
('header', _('Rename wired profile')),
|
||||||
|
7, 30,
|
||||||
|
edit_text=unicode(self.get_selected_profile())
|
||||||
|
)
|
||||||
exitcode, name = dialog.run(ui, self.parent)
|
exitcode, name = dialog.run(ui, self.parent)
|
||||||
if exitcode == 0:
|
if exitcode == 0:
|
||||||
# Save the new one, then kill the old one
|
# Save the new one, then kill the old one
|
||||||
@@ -455,8 +527,9 @@ class WiredComboBox(ComboBox):
|
|||||||
loc = self.get_focus()[1]
|
loc = self.get_focus()[1]
|
||||||
return self.theList[loc]
|
return self.theList[loc]
|
||||||
|
|
||||||
# Dialog2 that initiates an Ad-Hoc network connection
|
|
||||||
class AdHocDialog(Dialog2):
|
class AdHocDialog(Dialog2):
|
||||||
|
""" Dialog2 that initiates an Ad-Hoc network connection. """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
essid_t = _('ESSID')
|
essid_t = _('ESSID')
|
||||||
ip_t = _('IP')
|
ip_t = _('IP')
|
||||||
@@ -491,9 +564,11 @@ class AdHocDialog(Dialog2):
|
|||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
|
|
||||||
def encrypt_callback(self, chkbox, new_state, user_info=None):
|
def encrypt_callback(self, chkbox, new_state, user_info=None):
|
||||||
|
""" Set widget sensitivity. """
|
||||||
self.key_edit.set_sensitive(new_state)
|
self.key_edit.set_sensitive(new_state)
|
||||||
|
|
||||||
def unhandled_key(self, size, k):
|
def unhandled_key(self, size, k):
|
||||||
|
""" Handle keypresses. """
|
||||||
if k in ('up', 'page up'):
|
if k in ('up', 'page up'):
|
||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
if k in ('down', 'page down'):
|
if k in ('down', 'page down'):
|
||||||
@@ -503,7 +578,9 @@ class AdHocDialog(Dialog2):
|
|||||||
self.frame.set_focus('footer')
|
self.frame.set_focus('footer')
|
||||||
self.buttons.set_focus(0)
|
self.buttons.set_focus(0)
|
||||||
self.view.keypress(size, k)
|
self.view.keypress(size, k)
|
||||||
|
|
||||||
def on_exit(self, exitcode):
|
def on_exit(self, exitcode):
|
||||||
|
""" Handle dialog exit. """
|
||||||
data = (self.essid_edit.get_edit_text(),
|
data = (self.essid_edit.get_edit_text(),
|
||||||
self.ip_edit.get_edit_text().strip(),
|
self.ip_edit.get_edit_text().strip(),
|
||||||
self.channel_edit.get_edit_text(),
|
self.channel_edit.get_edit_text(),
|
||||||
@@ -512,12 +589,17 @@ class AdHocDialog(Dialog2):
|
|||||||
self.key_edit.get_edit_text())
|
self.key_edit.get_edit_text())
|
||||||
return exitcode, data
|
return exitcode, data
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
class ForgetDialog(Dialog2):
|
class ForgetDialog(Dialog2):
|
||||||
|
""" Dialog2 that removes/forgets a network. """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.to_remove = dict(essid=[], bssid=[])
|
self.to_remove = dict(essid=[], bssid=[])
|
||||||
|
|
||||||
header = urwid.AttrWrap(urwid.Text(' %20s %20s' % ('ESSID', 'BSSID')), 'listbar')
|
header = urwid.AttrWrap(
|
||||||
|
urwid.Text(' %20s %20s' % ('ESSID', 'BSSID')),
|
||||||
|
'listbar'
|
||||||
|
)
|
||||||
title = urwid.Text(_('Please select the networks to forget'))
|
title = urwid.Text(_('Please select the networks to forget'))
|
||||||
l = [title, header]
|
l = [title, header]
|
||||||
for entry in wireless.GetSavedWirelessNetworks():
|
for entry in wireless.GetSavedWirelessNetworks():
|
||||||
@@ -529,7 +611,11 @@ class ForgetDialog(Dialog2):
|
|||||||
label = label % (entry[0], 'global')
|
label = label % (entry[0], 'global')
|
||||||
data = (entry[0], 'essid:' + entry[0])
|
data = (entry[0], 'essid:' + entry[0])
|
||||||
|
|
||||||
cb = urwid.CheckBox(label, on_state_change=self.update_to_remove, user_data=data)
|
cb = urwid.CheckBox(
|
||||||
|
label,
|
||||||
|
on_state_change=self.update_to_remove,
|
||||||
|
user_data=data
|
||||||
|
)
|
||||||
l.append(cb)
|
l.append(cb)
|
||||||
body = urwid.ListBox(l)
|
body = urwid.ListBox(l)
|
||||||
|
|
||||||
@@ -539,6 +625,7 @@ class ForgetDialog(Dialog2):
|
|||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
|
|
||||||
def update_to_remove(self, widget, checked, data):
|
def update_to_remove(self, widget, checked, data):
|
||||||
|
""" Update list of removable networks. """
|
||||||
if checked:
|
if checked:
|
||||||
self.to_remove['essid'].append(data[0])
|
self.to_remove['essid'].append(data[0])
|
||||||
self.to_remove['bssid'].append(data[1])
|
self.to_remove['bssid'].append(data[1])
|
||||||
@@ -547,6 +634,7 @@ class ForgetDialog(Dialog2):
|
|||||||
self.to_remove['bssid'].remove(data[1])
|
self.to_remove['bssid'].remove(data[1])
|
||||||
|
|
||||||
def unhandled_key(self, size, k):
|
def unhandled_key(self, size, k):
|
||||||
|
""" Handle unhandled keys. """
|
||||||
if k in ('up', 'page up'):
|
if k in ('up', 'page up'):
|
||||||
self.frame.set_focus('body')
|
self.frame.set_focus('body')
|
||||||
if k in ('down', 'page down'):
|
if k in ('down', 'page down'):
|
||||||
@@ -558,8 +646,10 @@ class ForgetDialog(Dialog2):
|
|||||||
self.view.keypress(size, k)
|
self.view.keypress(size, k)
|
||||||
|
|
||||||
def on_exit(self, exitcode):
|
def on_exit(self, exitcode):
|
||||||
|
""" Handle dialog exit. """
|
||||||
return exitcode, self.to_remove
|
return exitcode, self.to_remove
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### APPLICATION INTERFACE CLASS
|
##### APPLICATION INTERFACE CLASS
|
||||||
########################################
|
########################################
|
||||||
@@ -567,20 +657,37 @@ class ForgetDialog(Dialog2):
|
|||||||
class appGUI():
|
class appGUI():
|
||||||
"""The UI itself, all glory belongs to it!"""
|
"""The UI itself, all glory belongs to it!"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global loop
|
self.conn_status = False
|
||||||
|
self.tcount = 0 # Counter for connection twirl indicator
|
||||||
|
|
||||||
self.size = ui.get_cols_rows()
|
self.size = ui.get_cols_rows()
|
||||||
# Happy screen saying that you can't do anything because we're scanning
|
# Happy screen saying that you can't do anything because we're scanning
|
||||||
# for networks. :-)
|
# for networks. :-)
|
||||||
self.screen_locker = urwid.Filler(urwid.Text(('important',_('Scanning networks... stand by...')), align='center'))
|
self.screen_locker = urwid.Filler(
|
||||||
self.no_wlan = urwid.Filler(urwid.Text(('important',_('No wireless networks found.')), align='center'))
|
urwid.Text(
|
||||||
|
('important', _('Scanning networks... stand by...')),
|
||||||
|
align='center'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.no_wlan = urwid.Filler(
|
||||||
|
urwid.Text(
|
||||||
|
('important', _('No wireless networks found.')),
|
||||||
|
align='center'
|
||||||
|
)
|
||||||
|
)
|
||||||
self.TITLE = _('Wicd Curses Interface')
|
self.TITLE = _('Wicd Curses Interface')
|
||||||
self.WIRED_IDX = 1
|
self.WIRED_IDX = 1
|
||||||
self.WLESS_IDX = 3
|
self.WLESS_IDX = 3
|
||||||
|
|
||||||
header = urwid.AttrWrap(urwid.Text(self.TITLE, align='right'), 'header')
|
header = urwid.AttrWrap(urwid.Text(self.TITLE, align='right'), 'header')
|
||||||
self.wiredH = urwid.Filler(urwid.Text(_('Wired Networks')))
|
self.wiredH = urwid.Filler(urwid.Text(_('Wired Networks')))
|
||||||
self.list_header=urwid.AttrWrap(urwid.Text(gen_list_header()),'listbar')
|
self.list_header = urwid.AttrWrap(
|
||||||
self.wlessH=NSelListBox([urwid.Text(_('Wireless Networks')),self.list_header])
|
urwid.Text(gen_list_header()), 'listbar'
|
||||||
|
)
|
||||||
|
self.wlessH = NSelListBox([
|
||||||
|
urwid.Text(_('Wireless Networks')),
|
||||||
|
self.list_header
|
||||||
|
])
|
||||||
|
|
||||||
# Init this earlier to make update_status happy
|
# Init this earlier to make update_status happy
|
||||||
self.update_tag = None
|
self.update_tag = None
|
||||||
@@ -642,20 +749,25 @@ class appGUI():
|
|||||||
#self.max_wait = ui.max_wait
|
#self.max_wait = ui.max_wait
|
||||||
|
|
||||||
def doScan(self, sync=False):
|
def doScan(self, sync=False):
|
||||||
|
""" Start wireless scan. """
|
||||||
self.scanning = True
|
self.scanning = True
|
||||||
wireless.Scan(False)
|
wireless.Scan(False)
|
||||||
|
|
||||||
def init_other_optcols(self):
|
def init_other_optcols(self):
|
||||||
# The "tabbed" preferences dialog
|
""" Init "tabbed" preferences dialog. """
|
||||||
self.prefCols = OptCols( [ ('f10',_('OK')),
|
self.prefCols = OptCols([
|
||||||
|
('f10', _('OK')),
|
||||||
('page up', _('Tab Left'), ),
|
('page up', _('Tab Left'), ),
|
||||||
('page down', _('Tab Right')),
|
('page down', _('Tab Right')),
|
||||||
('esc',_('Cancel')) ], self.handle_keys)
|
('esc', _('Cancel'))
|
||||||
self.confCols = OptCols( [ ('f10',_('OK')),
|
], self.handle_keys)
|
||||||
('esc',_('Cancel')) ],self.handle_keys)
|
self.confCols = OptCols([
|
||||||
|
('f10', _('OK')),
|
||||||
|
('esc', _('Cancel'))
|
||||||
|
], self.handle_keys)
|
||||||
|
|
||||||
# Does what it says it does
|
|
||||||
def lock_screen(self):
|
def lock_screen(self):
|
||||||
|
""" Lock the screen. """
|
||||||
if self.diag_type == 'pref':
|
if self.diag_type == 'pref':
|
||||||
self.do_diag_lock = True
|
self.do_diag_lock = True
|
||||||
return True
|
return True
|
||||||
@@ -664,6 +776,7 @@ class appGUI():
|
|||||||
self.update_ui()
|
self.update_ui()
|
||||||
|
|
||||||
def unlock_screen(self):
|
def unlock_screen(self):
|
||||||
|
""" Unlock the screen. """
|
||||||
if self.do_diag_lock:
|
if self.do_diag_lock:
|
||||||
self.do_diag_lock = False
|
self.do_diag_lock = False
|
||||||
return True
|
return True
|
||||||
@@ -674,7 +787,11 @@ class appGUI():
|
|||||||
self.update_ui()
|
self.update_ui()
|
||||||
|
|
||||||
def raise_hidden_network_dialog(self):
|
def raise_hidden_network_dialog(self):
|
||||||
dialog = InputDialog(('header',_('Select Hidden Network ESSID')),7,30,_('Scan'))
|
""" Show hidden network dialog. """
|
||||||
|
dialog = InputDialog(
|
||||||
|
('header', _('Select Hidden Network ESSID')),
|
||||||
|
7, 30, _('Scan')
|
||||||
|
)
|
||||||
exitcode, hidden = dialog.run(ui, self.frame)
|
exitcode, hidden = dialog.run(ui, self.frame)
|
||||||
if exitcode != -1:
|
if exitcode != -1:
|
||||||
# That dialog will sit there for a while if I don't get rid of it
|
# That dialog will sit there for a while if I don't get rid of it
|
||||||
@@ -684,7 +801,11 @@ class appGUI():
|
|||||||
wireless.SetHiddenNetworkESSID("")
|
wireless.SetHiddenNetworkESSID("")
|
||||||
|
|
||||||
def update_focusloc(self):
|
def update_focusloc(self):
|
||||||
# Location of last known focus is remapped to current location.
|
"""
|
||||||
|
Update focus location.
|
||||||
|
|
||||||
|
Location of last known focus is remapped to current location.
|
||||||
|
"""
|
||||||
# This might need to be cleaned up later.
|
# This might need to be cleaned up later.
|
||||||
|
|
||||||
if self.thePile.get_focus() == self.wiredCB:
|
if self.thePile.get_focus() == self.wiredCB:
|
||||||
@@ -702,7 +823,9 @@ class appGUI():
|
|||||||
# Be clunky until I get to a later stage of development.
|
# Be clunky until I get to a later stage of development.
|
||||||
# Update the list of networks. Usually called by DBus.
|
# Update the list of networks. Usually called by DBus.
|
||||||
@wrap_exceptions
|
@wrap_exceptions
|
||||||
def update_netlist(self,state=None, x=None, force_check=False,firstrun=False):
|
def update_netlist(self, state=None, x=None, force_check=False,
|
||||||
|
firstrun=False):
|
||||||
|
""" Update the list of networks. """
|
||||||
# Don't even try to do this if we are running a dialog
|
# Don't even try to do this if we are running a dialog
|
||||||
if self.diag:
|
if self.diag:
|
||||||
return
|
return
|
||||||
@@ -711,9 +834,9 @@ class appGUI():
|
|||||||
if not firstrun:
|
if not firstrun:
|
||||||
self.update_focusloc()
|
self.update_focusloc()
|
||||||
self.list_header.set_text(gen_list_header())
|
self.list_header.set_text(gen_list_header())
|
||||||
""" Updates the overall network list."""
|
# Updates the overall network list.
|
||||||
if not state:
|
if not state:
|
||||||
state, x = daemon.GetConnectionStatus()
|
state, trash = daemon.GetConnectionStatus()
|
||||||
if force_check or self.prev_state != state:
|
if force_check or self.prev_state != state:
|
||||||
wiredL, wlessL = gen_network_list()
|
wiredL, wlessL = gen_network_list()
|
||||||
|
|
||||||
@@ -727,26 +850,32 @@ class appGUI():
|
|||||||
else:
|
else:
|
||||||
self.wlessLB = self.no_wlan
|
self.wlessLB = self.no_wlan
|
||||||
if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
|
if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
|
||||||
self.thePile = urwid.Pile([('fixed',1,self.wiredH),
|
self.thePile = urwid.Pile([
|
||||||
|
('fixed', 1, self.wiredH),
|
||||||
('fixed', 1, self.wiredCB),
|
('fixed', 1, self.wiredCB),
|
||||||
('fixed', 2, self.wlessH),
|
('fixed', 2, self.wlessH),
|
||||||
self.wlessLB] )
|
self.wlessLB]
|
||||||
|
)
|
||||||
if not firstrun:
|
if not firstrun:
|
||||||
self.frame.body = self.thePile
|
self.frame.body = self.thePile
|
||||||
|
|
||||||
self.thePile.set_focus(self.focusloc[0])
|
self.thePile.set_focus(self.focusloc[0])
|
||||||
if self.focusloc[0] == self.WIRED_IDX:
|
if self.focusloc[0] == self.WIRED_IDX:
|
||||||
self.thePile.get_focus().get_body().set_focus(self.focusloc[1])
|
self.thePile.get_focus(). \
|
||||||
|
get_body().set_focus(self.focusloc[1])
|
||||||
else:
|
else:
|
||||||
if self.wlessLB != self.no_wlan:
|
if self.wlessLB != self.no_wlan:
|
||||||
self.thePile.get_focus().set_focus(self.focusloc[1])
|
self.thePile.get_focus().set_focus(self.focusloc[1])
|
||||||
else:
|
else:
|
||||||
self.thePile.set_focus(self.wiredCB)
|
self.thePile.set_focus(self.wiredCB)
|
||||||
else:
|
else:
|
||||||
self.thePile = urwid.Pile([('fixed',2,self.wlessH),self.wlessLB] )
|
self.thePile = urwid.Pile([
|
||||||
|
('fixed', 2, self.wlessH),
|
||||||
|
self.wlessLB
|
||||||
|
])
|
||||||
if not firstrun:
|
if not firstrun:
|
||||||
self.frame.body = self.thePile
|
self.frame.body = self.thePile
|
||||||
if self.focusloc[1] == None:
|
if self.focusloc[1] is None:
|
||||||
self.focusloc[1] = 0
|
self.focusloc[1] = 0
|
||||||
if self.wlessLB != self.no_wlan:
|
if self.wlessLB != self.no_wlan:
|
||||||
self.wlessLB.set_focus(self.focusloc[1])
|
self.wlessLB.set_focus(self.focusloc[1])
|
||||||
@@ -755,13 +884,16 @@ class appGUI():
|
|||||||
if not firstrun:
|
if not firstrun:
|
||||||
self.update_ui()
|
self.update_ui()
|
||||||
if firstrun:
|
if firstrun:
|
||||||
if wired.GetDefaultWiredNetwork() != None:
|
if wired.GetDefaultWiredNetwork() is not None:
|
||||||
self.wiredCB.get_body().set_focus(wired.GetWiredProfileList().index(wired.GetDefaultWiredNetwork()))
|
self.wiredCB.get_body().set_focus(
|
||||||
|
wired.GetWiredProfileList().index(
|
||||||
|
wired.GetDefaultWiredNetwork()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Update the footer/status bar
|
|
||||||
conn_status = False
|
|
||||||
@wrap_exceptions
|
@wrap_exceptions
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
|
""" Update the footer / statusbar. """
|
||||||
wired_connecting = wired.CheckIfWiredConnecting()
|
wired_connecting = wired.CheckIfWiredConnecting()
|
||||||
wireless_connecting = wireless.CheckIfWirelessConnecting()
|
wireless_connecting = wireless.CheckIfWirelessConnecting()
|
||||||
self.connecting = wired_connecting or wireless_connecting
|
self.connecting = wired_connecting or wireless_connecting
|
||||||
@@ -788,6 +920,7 @@ class appGUI():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def set_connecting_status(self, fast):
|
def set_connecting_status(self, fast):
|
||||||
|
""" Set connecting status. """
|
||||||
wired_connecting = wired.CheckIfWiredConnecting()
|
wired_connecting = wired.CheckIfWiredConnecting()
|
||||||
wireless_connecting = wireless.CheckIfWirelessConnecting()
|
wireless_connecting = wireless.CheckIfWirelessConnecting()
|
||||||
if wireless_connecting:
|
if wireless_connecting:
|
||||||
@@ -805,16 +938,18 @@ class appGUI():
|
|||||||
self.conn_status = False
|
self.conn_status = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Cheap little indicator stating that we are actually connecting
|
|
||||||
twirl = ['|','/','-','\\']
|
|
||||||
tcount = 0 # Counter for said indicator
|
|
||||||
def set_status(self, text, from_idle=False):
|
def set_status(self, text, from_idle=False):
|
||||||
|
""" Set the status text. """
|
||||||
# Set the status text, usually called by the update_status method
|
# Set the status text, usually called by the update_status method
|
||||||
# from_idle : a check to see if we are being called directly from the
|
# from_idle : a check to see if we are being called directly from the
|
||||||
# mainloop
|
# mainloop
|
||||||
# If we are being called as the result of trying to connect to
|
# If we are being called as the result of trying to connect to
|
||||||
# something, and we aren't connecting to something, return False
|
# something, and we aren't connecting to something, return False
|
||||||
# immediately.
|
# immediately.
|
||||||
|
|
||||||
|
# Cheap little indicator stating that we are actually connecting
|
||||||
|
twirl = ['|', '/', '-', '\\']
|
||||||
|
|
||||||
if from_idle and not self.connecting:
|
if from_idle and not self.connecting:
|
||||||
self.update_status()
|
self.update_status()
|
||||||
self.conn_status = False
|
self.conn_status = False
|
||||||
@@ -825,12 +960,13 @@ class appGUI():
|
|||||||
if from_idle and self.connecting:
|
if from_idle and self.connecting:
|
||||||
# This is probably the wrong way to do this, but it works for now.
|
# This is probably the wrong way to do this, but it works for now.
|
||||||
self.tcount += 1
|
self.tcount += 1
|
||||||
toAppend=self.twirl[self.tcount % 4]
|
toAppend = twirl[self.tcount % 4]
|
||||||
self.status_label.set_text(text + ' ' + toAppend)
|
self.status_label.set_text(text + ' ' + toAppend)
|
||||||
self.update_ui()
|
self.update_ui()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def dbus_scan_finished(self):
|
def dbus_scan_finished(self):
|
||||||
|
""" Handle DBus scan finish. """
|
||||||
# I'm pretty sure that I'll need this later.
|
# I'm pretty sure that I'll need this later.
|
||||||
#if not self.connecting:
|
#if not self.connecting:
|
||||||
# gobject.idle_add(self.refresh_networks, None, False, None)
|
# gobject.idle_add(self.refresh_networks, None, False, None)
|
||||||
@@ -838,12 +974,14 @@ class appGUI():
|
|||||||
self.scanning = False
|
self.scanning = False
|
||||||
|
|
||||||
def dbus_scan_started(self):
|
def dbus_scan_started(self):
|
||||||
|
""" Handle DBus scan start. """
|
||||||
self.scanning = True
|
self.scanning = True
|
||||||
if self.diag_type == 'conf':
|
if self.diag_type == 'conf':
|
||||||
self.restore_primary()
|
self.restore_primary()
|
||||||
self.lock_screen()
|
self.lock_screen()
|
||||||
|
|
||||||
def restore_primary(self):
|
def restore_primary(self):
|
||||||
|
""" Restore screen. """
|
||||||
self.diag_type = 'none'
|
self.diag_type = 'none'
|
||||||
if self.do_diag_lock or self.scanning:
|
if self.do_diag_lock or self.scanning:
|
||||||
self.frame.set_body(self.screen_locker)
|
self.frame.set_body(self.screen_locker)
|
||||||
@@ -855,6 +993,7 @@ class appGUI():
|
|||||||
self.update_ui()
|
self.update_ui()
|
||||||
|
|
||||||
def handle_keys(self, keys):
|
def handle_keys(self, keys):
|
||||||
|
""" Handle keys. """
|
||||||
if not self.diag:
|
if not self.diag:
|
||||||
# Handle keystrokes
|
# Handle keystrokes
|
||||||
if "f8" in keys or 'Q' in keys or 'q' in keys:
|
if "f8" in keys or 'Q' in keys or 'q' in keys:
|
||||||
@@ -873,14 +1012,19 @@ class appGUI():
|
|||||||
if 'right' in keys:
|
if 'right' in keys:
|
||||||
if not self.scanning:
|
if not self.scanning:
|
||||||
focus = self.thePile.get_focus()
|
focus = self.thePile.get_focus()
|
||||||
self.frame.set_footer(urwid.Pile([self.confCols,self.footer2]))
|
self.frame.set_footer(
|
||||||
|
urwid.Pile([self.confCols, self.footer2])
|
||||||
|
)
|
||||||
if focus == self.wiredCB:
|
if focus == self.wiredCB:
|
||||||
self.diag = WiredSettingsDialog(self.wiredCB.get_body().get_selected_profile(),self.frame)
|
self.diag = WiredSettingsDialog(
|
||||||
|
self.wiredCB.get_body().get_selected_profile(),
|
||||||
|
self.frame
|
||||||
|
)
|
||||||
self.diag.ready_widgets(ui, self.frame)
|
self.diag.ready_widgets(ui, self.frame)
|
||||||
self.frame.set_body(self.diag)
|
self.frame.set_body(self.diag)
|
||||||
else:
|
else:
|
||||||
# wireless list only other option
|
# wireless list only other option
|
||||||
wid,pos = self.thePile.get_focus().get_focus()
|
trash, pos = self.thePile.get_focus().get_focus()
|
||||||
self.diag = WirelessSettingsDialog(pos, self.frame)
|
self.diag = WirelessSettingsDialog(pos, self.frame)
|
||||||
self.diag.ready_widgets(ui, self.frame)
|
self.diag.ready_widgets(ui, self.frame)
|
||||||
self.frame.set_body(self.diag)
|
self.frame.set_body(self.diag)
|
||||||
@@ -904,8 +1048,12 @@ class appGUI():
|
|||||||
daemon.SetForcedDisconnect(True)
|
daemon.SetForcedDisconnect(True)
|
||||||
if "P" in keys:
|
if "P" in keys:
|
||||||
if not self.pref:
|
if not self.pref:
|
||||||
self.pref = PrefsDialog(self.frame,(0,1),ui,
|
self.pref = PrefsDialog(
|
||||||
dbusmanager.get_dbus_ifaces())
|
self.frame,
|
||||||
|
(0, 1),
|
||||||
|
ui,
|
||||||
|
dbusmanager.get_dbus_ifaces()
|
||||||
|
)
|
||||||
self.pref.load_settings()
|
self.pref.load_settings()
|
||||||
self.pref.ready_widgets(ui, self.frame)
|
self.pref.ready_widgets(ui, self.frame)
|
||||||
self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
|
self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
|
||||||
@@ -936,22 +1084,27 @@ class appGUI():
|
|||||||
exitcode, data = AdHocDialog().run(ui, self.frame)
|
exitcode, data = AdHocDialog().run(ui, self.frame)
|
||||||
#data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
|
#data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
|
||||||
if exitcode == 1:
|
if exitcode == 1:
|
||||||
wireless.CreateAdHocNetwork(data[0],
|
wireless.CreateAdHocNetwork(
|
||||||
|
data[0],
|
||||||
data[2],
|
data[2],
|
||||||
data[1], "WEP",
|
data[1],
|
||||||
|
"WEP",
|
||||||
data[5],
|
data[5],
|
||||||
data[4], False)
|
data[4],
|
||||||
|
False
|
||||||
|
)
|
||||||
if 'X' in keys:
|
if 'X' in keys:
|
||||||
exitcode, data = ForgetDialog().run(ui, self.frame)
|
exitcode, data = ForgetDialog().run(ui, self.frame)
|
||||||
if exitcode == 1:
|
if exitcode == 1:
|
||||||
text = _('Are you sure you want to discard settings for ' +
|
text = _('Are you sure you want to discard settings for '
|
||||||
'the selected networks?')
|
'the selected networks?')
|
||||||
text += '\n\n' + '\n'.join(data['essid'])
|
text += '\n\n' + '\n'.join(data['essid'])
|
||||||
confirm, useless = TextDialog(text, 20, 50,
|
confirm, trash = TextDialog(text, 20, 50,
|
||||||
buttons=[(_('OK'), 1), (_('Cancel'), -1)],
|
buttons=[(_('OK'), 1), (_('Cancel'), -1)],
|
||||||
).run(ui, self.frame)
|
).run(ui, self.frame)
|
||||||
if confirm == 1:
|
if confirm == 1:
|
||||||
map(wireless.DeleteWirelessNetwork, data['bssid'])
|
for x in data['bssid']:
|
||||||
|
wireless.DeleteWirelessNetwork(x)
|
||||||
|
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if urwid.VERSION < (1, 0, 0):
|
if urwid.VERSION < (1, 0, 0):
|
||||||
@@ -960,9 +1113,8 @@ class appGUI():
|
|||||||
check_mouse_event = urwid.util.is_mouse_event
|
check_mouse_event = urwid.util.is_mouse_event
|
||||||
if check_mouse_event(k):
|
if check_mouse_event(k):
|
||||||
event, button, col, row = k
|
event, button, col, row = k
|
||||||
self.frame.mouse_event( self.size,
|
self.frame.mouse_event(
|
||||||
event, button, col, row,
|
self.size, event, button, col, row, focus=True)
|
||||||
focus=True)
|
|
||||||
continue
|
continue
|
||||||
k = self.frame.keypress(self.size, k)
|
k = self.frame.keypress(self.size, k)
|
||||||
if self.diag:
|
if self.diag:
|
||||||
@@ -978,12 +1130,14 @@ class appGUI():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
def call_update_ui(self, source, cb_condition):
|
def call_update_ui(self, source, cb_condition):
|
||||||
|
""" Update UI. """
|
||||||
self.update_ui(True)
|
self.update_ui(True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Redraw the screen
|
# Redraw the screen
|
||||||
@wrap_exceptions
|
@wrap_exceptions
|
||||||
def update_ui(self, from_key=False):
|
def update_ui(self, from_key=False):
|
||||||
|
""" Redraw the screen. """
|
||||||
if not ui._started:
|
if not ui._started:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -995,7 +1149,7 @@ class appGUI():
|
|||||||
canvas = self.frame.render((self.size), True)
|
canvas = self.frame.render((self.size), True)
|
||||||
ui.draw_screen((self.size), canvas)
|
ui.draw_screen((self.size), canvas)
|
||||||
# Get the input data
|
# Get the input data
|
||||||
if self.update_tag != None:
|
if self.update_tag is not None:
|
||||||
gobject.source_remove(self.update_tag)
|
gobject.source_remove(self.update_tag)
|
||||||
#if from_key:
|
#if from_key:
|
||||||
return False
|
return False
|
||||||
@@ -1008,16 +1162,16 @@ class appGUI():
|
|||||||
wired.ConnectWired()
|
wired.ConnectWired()
|
||||||
self.update_status()
|
self.update_status()
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### INITIALIZATION FUNCTIONS
|
##### INITIALIZATION FUNCTIONS
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
""" Main function. """
|
||||||
global ui, dlogger
|
global ui, dlogger
|
||||||
# We are not python.
|
# We are not python.
|
||||||
misc.RenameProcess('wicd-curses')
|
misc.RenameProcess('wicd-curses')
|
||||||
|
|
||||||
import urwid.raw_display
|
|
||||||
ui = urwid.raw_display.Screen()
|
ui = urwid.raw_display.Screen()
|
||||||
|
|
||||||
#if options.debug:
|
#if options.debug:
|
||||||
@@ -1048,14 +1202,17 @@ def main():
|
|||||||
('green', 'dark green', 'default'),
|
('green', 'dark green', 'default'),
|
||||||
('blue', 'light blue', 'default'),
|
('blue', 'light blue', 'default'),
|
||||||
('red', 'dark red', 'default'),
|
('red', 'dark red', 'default'),
|
||||||
('bold','white','black','bold')])
|
('bold', 'white', 'black', 'bold')
|
||||||
|
])
|
||||||
# This is a wrapper around a function that calls another a function that
|
# This is a wrapper around a function that calls another a function that
|
||||||
# is a wrapper around a infinite loop. Fun.
|
# is a wrapper around a infinite loop. Fun.
|
||||||
urwid.set_encoding('utf8')
|
urwid.set_encoding('utf8')
|
||||||
ui.run_wrapper(run)
|
ui.run_wrapper(run)
|
||||||
|
|
||||||
|
|
||||||
@wrap_exceptions
|
@wrap_exceptions
|
||||||
def run():
|
def run():
|
||||||
|
""" Run the UI. """
|
||||||
global loop
|
global loop
|
||||||
loop = gobject.MainLoop()
|
loop = gobject.MainLoop()
|
||||||
|
|
||||||
@@ -1080,13 +1237,16 @@ def run():
|
|||||||
app.update_ui()
|
app.update_ui()
|
||||||
loop.run()
|
loop.run()
|
||||||
|
|
||||||
|
|
||||||
# Mostly borrowed from gui.py
|
# Mostly borrowed from gui.py
|
||||||
def setup_dbus(force=True):
|
def setup_dbus(force=True):
|
||||||
|
""" Initialize DBus. """
|
||||||
global bus, daemon, wireless, wired
|
global bus, daemon, wireless, wired
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
print >> sys.stderr, _("Can't connect to the daemon, trying to start it automatically...")
|
print >> sys.stderr, \
|
||||||
|
_("Can't connect to the daemon, trying to start it automatically...")
|
||||||
bus = dbusmanager.get_bus()
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
@@ -1094,7 +1254,8 @@ def setup_dbus(force=True):
|
|||||||
wired = dbus_ifaces['wired']
|
wired = dbus_ifaces['wired']
|
||||||
|
|
||||||
if not daemon:
|
if not daemon:
|
||||||
print 'Error connecting to wicd via D-Bus. Please make sure the wicd service is running.'
|
print 'Error connecting to wicd via D-Bus. ' \
|
||||||
|
'Please make sure the wicd service is running.'
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
netentry_curses.dbus_init(dbus_ifaces)
|
netentry_curses.dbus_init(dbus_ifaces)
|
||||||
@@ -1107,17 +1268,21 @@ setup_dbus()
|
|||||||
########################################
|
########################################
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
parser = OptionParser(version="wicd-curses-%s (using wicd %s)" % (CURSES_REV,daemon.Hello()), prog="wicd-curses")
|
parser = OptionParser(
|
||||||
|
version="wicd-curses-%s (using wicd %s)" %
|
||||||
|
(CURSES_REV, daemon.Hello()),
|
||||||
|
prog="wicd-curses"
|
||||||
|
)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
if "DBus.Error.AccessDenied" in e.get_dbus_name():
|
if "DBus.Error.AccessDenied" in e.get_dbus_name():
|
||||||
print _('ERROR: wicd-curses was denied access to the wicd daemon: '\
|
print _('ERROR: wicd-curses was denied access to the wicd daemon: '
|
||||||
'please check that your user is in the "$A" group.'). \
|
'please check that your user is in the "$A" group.'). \
|
||||||
replace('$A', '\033[1;34m' + wpath.wicd_group + '\033[0m')
|
replace('$A', '\033[1;34m' + wpath.wicd_group + '\033[0m')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
#parser.add_option("-d", "--debug",action="store_true"
|
#parser.add_option("-d", "--debug", action="store_true", dest='debug',
|
||||||
# ,dest='debug',help="enable logging of wicd-curses (currently does nothing)")
|
# help="enable logging of wicd-curses (currently does nothing)")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -72,16 +72,20 @@ def get_script_info(network, network_type):
|
|||||||
if con.has_section(network):
|
if con.has_section(network):
|
||||||
info["pre_entry"] = con.get(network, "beforescript", None)
|
info["pre_entry"] = con.get(network, "beforescript", None)
|
||||||
info["post_entry"] = con.get(network, "afterscript", None)
|
info["post_entry"] = con.get(network, "afterscript", None)
|
||||||
info["pre_disconnect_entry"] = con.get(network, "predisconnectscript", None)
|
info["pre_disconnect_entry"] = con.get(network,
|
||||||
info["post_disconnect_entry"] = con.get(network, "postdisconnectscript", None)
|
"predisconnectscript", None)
|
||||||
|
info["post_disconnect_entry"] = con.get(network,
|
||||||
|
"postdisconnectscript", None)
|
||||||
else:
|
else:
|
||||||
bssid = wireless.GetWirelessProperty(int(network), "bssid")
|
bssid = wireless.GetWirelessProperty(int(network), "bssid")
|
||||||
con = ConfigManager(wireless_conf)
|
con = ConfigManager(wireless_conf)
|
||||||
if con.has_section(bssid):
|
if con.has_section(bssid):
|
||||||
info["pre_entry"] = con.get(bssid, "beforescript", None)
|
info["pre_entry"] = con.get(bssid, "beforescript", None)
|
||||||
info["post_entry"] = con.get(bssid, "afterscript", None)
|
info["post_entry"] = con.get(bssid, "afterscript", None)
|
||||||
info["pre_disconnect_entry"] = con.get(bssid, "predisconnectscript", None)
|
info["pre_disconnect_entry"] = con.get(bssid,
|
||||||
info["post_disconnect_entry"] = con.get(bssid, "postdisconnectscript", None)
|
"predisconnectscript", None)
|
||||||
|
info["post_disconnect_entry"] = con.get(bssid,
|
||||||
|
"postdisconnectscript", None)
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def write_scripts(network, network_type, script_info):
|
def write_scripts(network, network_type, script_info):
|
||||||
@@ -90,8 +94,10 @@ def write_scripts(network, network_type, script_info):
|
|||||||
con = ConfigManager(wired_conf)
|
con = ConfigManager(wired_conf)
|
||||||
con.set(network, "beforescript", script_info["pre_entry"])
|
con.set(network, "beforescript", script_info["pre_entry"])
|
||||||
con.set(network, "afterscript", script_info["post_entry"])
|
con.set(network, "afterscript", script_info["post_entry"])
|
||||||
con.set(network, "predisconnectscript", script_info["pre_disconnect_entry"])
|
con.set(network, "predisconnectscript",
|
||||||
con.set(network, "postdisconnectscript", script_info["post_disconnect_entry"])
|
script_info["pre_disconnect_entry"])
|
||||||
|
con.set(network, "postdisconnectscript",
|
||||||
|
script_info["post_disconnect_entry"])
|
||||||
con.write()
|
con.write()
|
||||||
wired.ReloadConfig()
|
wired.ReloadConfig()
|
||||||
wired.ReadWiredNetworkProfile(network)
|
wired.ReadWiredNetworkProfile(network)
|
||||||
@@ -101,8 +107,10 @@ def write_scripts(network, network_type, script_info):
|
|||||||
con = ConfigManager(wireless_conf)
|
con = ConfigManager(wireless_conf)
|
||||||
con.set(bssid, "beforescript", script_info["pre_entry"])
|
con.set(bssid, "beforescript", script_info["pre_entry"])
|
||||||
con.set(bssid, "afterscript", script_info["post_entry"])
|
con.set(bssid, "afterscript", script_info["post_entry"])
|
||||||
con.set(bssid, "predisconnectscript", script_info["pre_disconnect_entry"])
|
con.set(bssid, "predisconnectscript",
|
||||||
con.set(bssid, "postdisconnectscript", script_info["post_disconnect_entry"])
|
script_info["pre_disconnect_entry"])
|
||||||
|
con.set(bssid, "postdisconnectscript",
|
||||||
|
script_info["post_disconnect_entry"])
|
||||||
con.write()
|
con.write()
|
||||||
wireless.ReloadConfig()
|
wireless.ReloadConfig()
|
||||||
wireless.ReadWirelessNetworkProfile(int(network))
|
wireless.ReadWirelessNetworkProfile(int(network))
|
||||||
@@ -127,10 +135,10 @@ def main (argv):
|
|||||||
dialog = wTree.get_object("configure_script_dialog")
|
dialog = wTree.get_object("configure_script_dialog")
|
||||||
wTree.get_object("pre_label").set_label(_('Pre-connection Script') + ":")
|
wTree.get_object("pre_label").set_label(_('Pre-connection Script') + ":")
|
||||||
wTree.get_object("post_label").set_label(_('Post-connection Script') + ":")
|
wTree.get_object("post_label").set_label(_('Post-connection Script') + ":")
|
||||||
wTree.get_object("pre_disconnect_label").set_label(_('Pre-disconnection Script')
|
wTree.get_object("pre_disconnect_label").\
|
||||||
+ ":")
|
set_label(_('Pre-disconnection Script') + ":")
|
||||||
wTree.get_object("post_disconnect_label").set_label(_('Post-disconnection Script')
|
wTree.get_object("post_disconnect_label").\
|
||||||
+ ":")
|
set_label(_('Post-disconnection Script') + ":")
|
||||||
wTree.get_object("window1").hide()
|
wTree.get_object("window1").hide()
|
||||||
|
|
||||||
pre_entry = wTree.get_object("pre_entry")
|
pre_entry = wTree.get_object("pre_entry")
|
||||||
@@ -140,8 +148,12 @@ def main (argv):
|
|||||||
|
|
||||||
pre_entry.set_text(none_to_blank(script_info.get("pre_entry")))
|
pre_entry.set_text(none_to_blank(script_info.get("pre_entry")))
|
||||||
post_entry.set_text(none_to_blank(script_info.get("post_entry")))
|
post_entry.set_text(none_to_blank(script_info.get("post_entry")))
|
||||||
pre_disconnect_entry.set_text(none_to_blank(script_info.get("pre_disconnect_entry")))
|
pre_disconnect_entry.set_text(
|
||||||
post_disconnect_entry.set_text(none_to_blank(script_info.get("post_disconnect_entry")))
|
none_to_blank(script_info.get("pre_disconnect_entry"))
|
||||||
|
)
|
||||||
|
post_disconnect_entry.set_text(
|
||||||
|
none_to_blank(script_info.get("post_disconnect_entry"))
|
||||||
|
)
|
||||||
|
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
|
|
||||||
@@ -149,8 +161,10 @@ def main (argv):
|
|||||||
if result == 1:
|
if result == 1:
|
||||||
script_info["pre_entry"] = blank_to_none(pre_entry.get_text())
|
script_info["pre_entry"] = blank_to_none(pre_entry.get_text())
|
||||||
script_info["post_entry"] = blank_to_none(post_entry.get_text())
|
script_info["post_entry"] = blank_to_none(post_entry.get_text())
|
||||||
script_info["pre_disconnect_entry"] = blank_to_none(pre_disconnect_entry.get_text())
|
script_info["pre_disconnect_entry"] = \
|
||||||
script_info["post_disconnect_entry"] = blank_to_none(post_disconnect_entry.get_text())
|
blank_to_none(pre_disconnect_entry.get_text())
|
||||||
|
script_info["post_disconnect_entry"] = \
|
||||||
|
blank_to_none(post_disconnect_entry.get_text())
|
||||||
write_scripts(network, network_type, script_info)
|
write_scripts(network, network_type, script_info)
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|||||||
163
gtk/gui.py
163
gtk/gui.py
@@ -27,7 +27,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import gobject
|
import gobject
|
||||||
import pango
|
|
||||||
import gtk
|
import gtk
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from dbus import DBusException
|
from dbus import DBusException
|
||||||
@@ -49,20 +48,28 @@ if __name__ == '__main__':
|
|||||||
proxy_obj = daemon = wireless = wired = bus = None
|
proxy_obj = daemon = wireless = wired = bus = None
|
||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
|
|
||||||
|
|
||||||
def setup_dbus(force=True):
|
def setup_dbus(force=True):
|
||||||
|
""" Initialize DBus. """
|
||||||
global bus, daemon, wireless, wired, DBUS_AVAIL
|
global bus, daemon, wireless, wired, DBUS_AVAIL
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
if force:
|
if force:
|
||||||
print "Can't connect to the daemon, trying to start it automatically..."
|
print "Can't connect to the daemon, ' + \
|
||||||
|
'trying to start it automatically..."
|
||||||
if not misc.PromptToStartDaemon():
|
if not misc.PromptToStartDaemon():
|
||||||
print "Failed to find a graphical sudo program, cannot continue."
|
print "Failed to find a graphical sudo program, ' + \
|
||||||
|
'cannot continue."
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
error(None, _("Could not connect to wicd's D-Bus interface. Check the wicd log for error messages."))
|
error(
|
||||||
|
None,
|
||||||
|
_("Could not connect to wicd's D-Bus interface. "
|
||||||
|
"Check the wicd log for error messages.")
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@@ -77,12 +84,20 @@ def setup_dbus(force=True):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def handle_no_dbus(from_tray=False):
|
def handle_no_dbus(from_tray=False):
|
||||||
|
""" Handle the case where no DBus is available. """
|
||||||
global DBUS_AVAIL
|
global DBUS_AVAIL
|
||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
if from_tray: return False
|
if from_tray:
|
||||||
|
return False
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'), block=False)
|
error(
|
||||||
|
None,
|
||||||
|
_('The wicd daemon has shut down. The UI will not function '
|
||||||
|
'properly until it is restarted.'),
|
||||||
|
block=False
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -94,14 +109,19 @@ class WiredProfileChooser:
|
|||||||
# functions and widgets it uses.
|
# functions and widgets it uses.
|
||||||
wired_net_entry = WiredNetworkEntry()
|
wired_net_entry = WiredNetworkEntry()
|
||||||
|
|
||||||
dialog = gtk.Dialog(title = _('Wired connection detected'),
|
dialog = gtk.Dialog(
|
||||||
|
title=_('Wired connection detected'),
|
||||||
flags=gtk.DIALOG_MODAL,
|
flags=gtk.DIALOG_MODAL,
|
||||||
buttons = (gtk.STOCK_CONNECT, 1,
|
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)
|
||||||
gtk.STOCK_CANCEL, 2))
|
)
|
||||||
dialog.set_has_separator(False)
|
dialog.set_has_separator(False)
|
||||||
dialog.set_size_request(400, 150)
|
dialog.set_size_request(400, 150)
|
||||||
instruct_label = gtk.Label(_('Select or create a wired profile to connect with') + ':\n')
|
instruct_label = gtk.Label(
|
||||||
stoppopcheckbox = gtk.CheckButton(_('Stop Showing Autoconnect pop-up temporarily'))
|
_('Select or create a wired profile to connect with') + ':\n'
|
||||||
|
)
|
||||||
|
stoppopcheckbox = gtk.CheckButton(
|
||||||
|
_('Stop Showing Autoconnect pop-up temporarily')
|
||||||
|
)
|
||||||
|
|
||||||
wired_net_entry.is_full_gui = False
|
wired_net_entry.is_full_gui = False
|
||||||
instruct_label.set_alignment(0, 0)
|
instruct_label.set_alignment(0, 0)
|
||||||
@@ -112,15 +132,19 @@ class WiredProfileChooser:
|
|||||||
wired_net_entry.vbox_top.remove(wired_net_entry.hbox_temp)
|
wired_net_entry.vbox_top.remove(wired_net_entry.hbox_temp)
|
||||||
wired_net_entry.vbox_top.remove(wired_net_entry.profile_help)
|
wired_net_entry.vbox_top.remove(wired_net_entry.profile_help)
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(instruct_label, fill=False, expand=False)
|
dialog.vbox.pack_start(instruct_label, fill=False, expand=False)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(wired_net_entry.profile_help, False, False)
|
dialog.vbox.pack_start(wired_net_entry.profile_help, False, False)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(wired_net_entry.hbox_temp, False, False)
|
dialog.vbox.pack_start(wired_net_entry.hbox_temp, False, False)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(stoppopcheckbox, False, False)
|
dialog.vbox.pack_start(stoppopcheckbox, False, False)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
|
|
||||||
wired_profiles = wired_net_entry.combo_profile_names
|
wired_profiles = wired_net_entry.combo_profile_names
|
||||||
wired_net_entry.profile_help.hide()
|
wired_net_entry.profile_help.hide()
|
||||||
if wired_net_entry.profile_list != None:
|
if wired_net_entry.profile_list is not None:
|
||||||
wired_profiles.set_active(0)
|
wired_profiles.set_active(0)
|
||||||
print "wired profiles found"
|
print "wired profiles found"
|
||||||
else:
|
else:
|
||||||
@@ -139,6 +163,7 @@ class WiredProfileChooser:
|
|||||||
|
|
||||||
|
|
||||||
def get_wireless_prop(net_id, prop):
|
def get_wireless_prop(net_id, prop):
|
||||||
|
""" Get wireless property. """
|
||||||
return wireless.GetWirelessProperty(net_id, prop)
|
return wireless.GetWirelessProperty(net_id, prop)
|
||||||
|
|
||||||
class appGui(object):
|
class appGui(object):
|
||||||
@@ -170,7 +195,8 @@ class appGui(object):
|
|||||||
width = 530
|
width = 530
|
||||||
self.window.resize(width, int(gtk.gdk.screen_height() / 1.7))
|
self.window.resize(width, int(gtk.gdk.screen_height() / 1.7))
|
||||||
|
|
||||||
dic = { "refresh_clicked" : self.refresh_clicked,
|
dic = {
|
||||||
|
"refresh_clicked": self.refresh_clicked,
|
||||||
"quit_clicked": self.exit,
|
"quit_clicked": self.exit,
|
||||||
"rfkill_clicked": self.switch_rfkill,
|
"rfkill_clicked": self.switch_rfkill,
|
||||||
"disconnect_clicked": self.disconnect_all,
|
"disconnect_clicked": self.disconnect_all,
|
||||||
@@ -207,7 +233,9 @@ class appGui(object):
|
|||||||
self.status_area.hide_all()
|
self.status_area.hide_all()
|
||||||
|
|
||||||
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
||||||
self.window.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
self.window.set_icon_from_file(
|
||||||
|
os.path.join(wpath.images, "wicd.png")
|
||||||
|
)
|
||||||
self.statusID = None
|
self.statusID = None
|
||||||
self.first_dialog_load = True
|
self.first_dialog_load = True
|
||||||
self.is_visible = True
|
self.is_visible = True
|
||||||
@@ -250,18 +278,22 @@ class appGui(object):
|
|||||||
self.refresh_clicked()
|
self.refresh_clicked()
|
||||||
|
|
||||||
def handle_connection_results(self, results):
|
def handle_connection_results(self, results):
|
||||||
|
""" Handle connection results. """
|
||||||
if results not in ['success', 'aborted'] and self.is_visible:
|
if results not in ['success', 'aborted'] and self.is_visible:
|
||||||
error(self.window, language[results], block=False)
|
error(self.window, language[results], block=False)
|
||||||
|
|
||||||
def create_adhoc_network(self, widget=None):
|
def create_adhoc_network(self, widget=None):
|
||||||
""" Shows a dialog that creates a new adhoc network. """
|
""" Shows a dialog that creates a new adhoc network. """
|
||||||
print "Starting the Ad-Hoc Network Creation Process..."
|
print "Starting the Ad-Hoc Network Creation Process..."
|
||||||
dialog = gtk.Dialog(title = _('Create an Ad-Hoc Network'),
|
dialog = gtk.Dialog(
|
||||||
|
title=_('Create an Ad-Hoc Network'),
|
||||||
flags=gtk.DIALOG_MODAL,
|
flags=gtk.DIALOG_MODAL,
|
||||||
buttons=(gtk.STOCK_CANCEL, 2, gtk.STOCK_OK, 1))
|
buttons=(gtk.STOCK_CANCEL, 2, gtk.STOCK_OK, 1)
|
||||||
|
)
|
||||||
dialog.set_has_separator(False)
|
dialog.set_has_separator(False)
|
||||||
dialog.set_size_request(400, -1)
|
dialog.set_size_request(400, -1)
|
||||||
self.chkbox_use_encryption = gtk.CheckButton(_('Use Encryption (WEP only)'))
|
self.chkbox_use_encryption = \
|
||||||
|
gtk.CheckButton(_('Use Encryption (WEP only)'))
|
||||||
self.chkbox_use_encryption.set_active(False)
|
self.chkbox_use_encryption.set_active(False)
|
||||||
ip_entry = LabelEntry(_('IP') + ':')
|
ip_entry = LabelEntry(_('IP') + ':')
|
||||||
essid_entry = LabelEntry(_('ESSID') + ':')
|
essid_entry = LabelEntry(_('ESSID') + ':')
|
||||||
@@ -270,7 +302,8 @@ class appGui(object):
|
|||||||
self.key_entry.set_auto_hidden(True)
|
self.key_entry.set_auto_hidden(True)
|
||||||
self.key_entry.set_sensitive(False)
|
self.key_entry.set_sensitive(False)
|
||||||
|
|
||||||
chkbox_use_ics = gtk.CheckButton( _('Activate Internet Connection Sharing'))
|
chkbox_use_ics = \
|
||||||
|
gtk.CheckButton(_('Activate Internet Connection Sharing'))
|
||||||
|
|
||||||
self.chkbox_use_encryption.connect("toggled",
|
self.chkbox_use_encryption.connect("toggled",
|
||||||
self.toggle_encrypt_check)
|
self.toggle_encrypt_check)
|
||||||
@@ -283,22 +316,30 @@ class appGui(object):
|
|||||||
vbox_ah.pack_start(self.chkbox_use_encryption, False, False)
|
vbox_ah.pack_start(self.chkbox_use_encryption, False, False)
|
||||||
vbox_ah.pack_start(self.key_entry, False, False)
|
vbox_ah.pack_start(self.key_entry, False, False)
|
||||||
vbox_ah.show()
|
vbox_ah.show()
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(essid_entry)
|
dialog.vbox.pack_start(essid_entry)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(ip_entry)
|
dialog.vbox.pack_start(ip_entry)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(channel_entry)
|
dialog.vbox.pack_start(channel_entry)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(chkbox_use_ics)
|
dialog.vbox.pack_start(chkbox_use_ics)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(vbox_ah)
|
dialog.vbox.pack_start(vbox_ah)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.set_spacing(5)
|
dialog.vbox.set_spacing(5)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == 1:
|
if response == 1:
|
||||||
wireless.CreateAdHocNetwork(essid_entry.entry.get_text(),
|
wireless.CreateAdHocNetwork(
|
||||||
|
essid_entry.entry.get_text(),
|
||||||
channel_entry.entry.get_text(),
|
channel_entry.entry.get_text(),
|
||||||
ip_entry.entry.get_text().strip(),
|
ip_entry.entry.get_text().strip(),
|
||||||
"WEP",
|
"WEP",
|
||||||
self.key_entry.entry.get_text(),
|
self.key_entry.entry.get_text(),
|
||||||
self.chkbox_use_encryption.get_active(),
|
self.chkbox_use_encryption.get_active(),
|
||||||
False) #chkbox_use_ics.get_active())
|
False # chkbox_use_ics.get_active())
|
||||||
|
)
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def forget_network(self, widget=None):
|
def forget_network(self, widget=None):
|
||||||
@@ -307,9 +348,11 @@ class appGui(object):
|
|||||||
delete them.
|
delete them.
|
||||||
"""
|
"""
|
||||||
wireless.ReloadConfig()
|
wireless.ReloadConfig()
|
||||||
dialog = gtk.Dialog(title = _('List of saved networks'),
|
dialog = gtk.Dialog(
|
||||||
|
title=_('List of saved networks'),
|
||||||
flags=gtk.DIALOG_MODAL,
|
flags=gtk.DIALOG_MODAL,
|
||||||
buttons=(gtk.STOCK_DELETE, 1, gtk.STOCK_OK, 2))
|
buttons=(gtk.STOCK_DELETE, 1, gtk.STOCK_OK, 2)
|
||||||
|
)
|
||||||
dialog.set_has_separator(True)
|
dialog.set_has_separator(True)
|
||||||
dialog.set_size_request(400, 200)
|
dialog.set_size_request(400, 200)
|
||||||
|
|
||||||
@@ -333,7 +376,9 @@ class appGui(object):
|
|||||||
scroll = gtk.ScrolledWindow()
|
scroll = gtk.ScrolledWindow()
|
||||||
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||||
scroll.add(tree)
|
scroll.add(tree)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(scroll)
|
dialog.vbox.pack_start(scroll)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.set_spacing(5)
|
dialog.vbox.set_spacing(5)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
@@ -342,9 +387,11 @@ class appGui(object):
|
|||||||
to_remove = dict(essid=[], bssid=[])
|
to_remove = dict(essid=[], bssid=[])
|
||||||
if pathlist:
|
if pathlist:
|
||||||
for row in pathlist:
|
for row in pathlist:
|
||||||
iter = model.get_iter(path=row)
|
it = model.get_iter(path=row)
|
||||||
to_remove['essid'].append(misc.noneToString(model.get_value(iter, 0)))
|
to_remove['essid'].append(
|
||||||
to_remove['bssid'].append(model.get_value(iter, 1))
|
misc.noneToString(model.get_value(it, 0))
|
||||||
|
)
|
||||||
|
to_remove['bssid'].append(model.get_value(it, 1))
|
||||||
|
|
||||||
confirm = gtk.MessageDialog(
|
confirm = gtk.MessageDialog(
|
||||||
flags=gtk.DIALOG_MODAL,
|
flags=gtk.DIALOG_MODAL,
|
||||||
@@ -356,7 +403,8 @@ class appGui(object):
|
|||||||
confirm.format_secondary_text('\n'.join(to_remove['essid']))
|
confirm.format_secondary_text('\n'.join(to_remove['essid']))
|
||||||
response = confirm.run()
|
response = confirm.run()
|
||||||
if response == gtk.RESPONSE_YES:
|
if response == gtk.RESPONSE_YES:
|
||||||
map(wireless.DeleteWirelessNetwork, to_remove['bssid'])
|
for x in to_remove['bssid']:
|
||||||
|
wireless.DeleteWirelessNetwork(x)
|
||||||
wireless.ReloadConfig()
|
wireless.ReloadConfig()
|
||||||
confirm.destroy()
|
confirm.destroy()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
@@ -388,7 +436,12 @@ class appGui(object):
|
|||||||
dialog = gtk.AboutDialog()
|
dialog = gtk.AboutDialog()
|
||||||
dialog.set_name("Wicd")
|
dialog.set_name("Wicd")
|
||||||
dialog.set_version(daemon.Hello())
|
dialog.set_version(daemon.Hello())
|
||||||
dialog.set_authors([ "Adam Blackburn", "Dan O'Reilly", "Andrew Psaltis", "David Paleino"])
|
dialog.set_authors([
|
||||||
|
"Adam Blackburn",
|
||||||
|
"Dan O'Reilly",
|
||||||
|
"Andrew Psaltis",
|
||||||
|
"David Paleino"
|
||||||
|
])
|
||||||
dialog.set_website("http://wicd.sourceforge.net")
|
dialog.set_website("http://wicd.sourceforge.net")
|
||||||
dialog.run()
|
dialog.run()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
@@ -411,13 +464,17 @@ class appGui(object):
|
|||||||
|
|
||||||
def connect_hidden(self, widget):
|
def connect_hidden(self, widget):
|
||||||
""" Prompts the user for a hidden network, then scans for it. """
|
""" Prompts the user for a hidden network, then scans for it. """
|
||||||
dialog = gtk.Dialog(title=('Hidden Network'),
|
dialog = gtk.Dialog(
|
||||||
|
title=('Hidden Network'),
|
||||||
flags=gtk.DIALOG_MODAL,
|
flags=gtk.DIALOG_MODAL,
|
||||||
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2))
|
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)
|
||||||
|
)
|
||||||
dialog.set_has_separator(False)
|
dialog.set_has_separator(False)
|
||||||
lbl = gtk.Label(_('Hidden Network ESSID'))
|
lbl = gtk.Label(_('Hidden Network ESSID'))
|
||||||
textbox = gtk.Entry()
|
textbox = gtk.Entry()
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(lbl)
|
dialog.vbox.pack_start(lbl)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_start(textbox)
|
dialog.vbox.pack_start(textbox)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
button = dialog.run()
|
button = dialog.run()
|
||||||
@@ -463,6 +520,7 @@ class appGui(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _do_statusbar_update(self, state, info):
|
def _do_statusbar_update(self, state, info):
|
||||||
|
""" Actually perform the statusbar update. """
|
||||||
if not self.is_visible:
|
if not self.is_visible:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -477,13 +535,17 @@ class appGui(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def set_wired_state(self, info):
|
def set_wired_state(self, info):
|
||||||
|
""" Set wired state. """
|
||||||
if self.connecting:
|
if self.connecting:
|
||||||
# Adjust our state from connecting->connected.
|
# Adjust our state from connecting->connected.
|
||||||
self._set_not_connecting_state()
|
self._set_not_connecting_state()
|
||||||
self.set_status(_('Connected to wired network (IP: $A)').replace('$A', info[0]))
|
self.set_status(
|
||||||
|
_('Connected to wired network (IP: $A)').replace('$A', info[0])
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_wireless_state(self, info):
|
def set_wireless_state(self, info):
|
||||||
|
""" Set wireless state. """
|
||||||
if self.connecting:
|
if self.connecting:
|
||||||
# Adjust our state from connecting->connected.
|
# Adjust our state from connecting->connected.
|
||||||
self._set_not_connecting_state()
|
self._set_not_connecting_state()
|
||||||
@@ -494,6 +556,7 @@ class appGui(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def set_not_connected_state(self, info):
|
def set_not_connected_state(self, info):
|
||||||
|
""" Set not connected state. """
|
||||||
if self.connecting:
|
if self.connecting:
|
||||||
# Adjust our state from connecting->not-connected.
|
# Adjust our state from connecting->not-connected.
|
||||||
self._set_not_connecting_state()
|
self._set_not_connecting_state()
|
||||||
@@ -501,6 +564,7 @@ class appGui(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _set_not_connecting_state(self):
|
def _set_not_connecting_state(self):
|
||||||
|
""" Set not-connecting state. """
|
||||||
if self.connecting:
|
if self.connecting:
|
||||||
if self.update_cb:
|
if self.update_cb:
|
||||||
gobject.source_remove(self.update_cb)
|
gobject.source_remove(self.update_cb)
|
||||||
@@ -514,6 +578,7 @@ class appGui(object):
|
|||||||
gobject.idle_add(self.status_bar.remove_message, 1, self.statusID)
|
gobject.idle_add(self.status_bar.remove_message, 1, self.statusID)
|
||||||
|
|
||||||
def set_connecting_state(self, info):
|
def set_connecting_state(self, info):
|
||||||
|
""" Set connecting state. """
|
||||||
if not self.connecting:
|
if not self.connecting:
|
||||||
if self.update_cb:
|
if self.update_cb:
|
||||||
gobject.source_remove(self.update_cb)
|
gobject.source_remove(self.update_cb)
|
||||||
@@ -531,7 +596,7 @@ class appGui(object):
|
|||||||
stat = wireless.CheckWirelessConnectingMessage()
|
stat = wireless.CheckWirelessConnectingMessage()
|
||||||
gobject.idle_add(self.set_status, "%s: %s" % (info[1], stat))
|
gobject.idle_add(self.set_status, "%s: %s" % (info[1], stat))
|
||||||
elif info[0] == "wired":
|
elif info[0] == "wired":
|
||||||
gobject.idle_add(self.set_status, _('Wired Network') + ': ' \
|
gobject.idle_add(self.set_status, _('Wired Network') + ': '
|
||||||
+ wired.CheckWiredConnectingMessage())
|
+ wired.CheckWiredConnectingMessage())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -542,7 +607,8 @@ class appGui(object):
|
|||||||
current network state is the same as the previous.
|
current network state is the same as the previous.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not DBUS_AVAIL: return
|
if not DBUS_AVAIL:
|
||||||
|
return
|
||||||
if not state:
|
if not state:
|
||||||
state, x = daemon.GetConnectionStatus()
|
state, x = daemon.GetConnectionStatus()
|
||||||
|
|
||||||
@@ -563,24 +629,27 @@ class appGui(object):
|
|||||||
This method is called after a wireless scan is completed.
|
This method is called after a wireless scan is completed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not DBUS_AVAIL: return
|
if not DBUS_AVAIL:
|
||||||
|
return
|
||||||
gobject.idle_add(self.refresh_networks, None, False, None)
|
gobject.idle_add(self.refresh_networks, None, False, None)
|
||||||
|
|
||||||
def dbus_scan_started(self):
|
def dbus_scan_started(self):
|
||||||
""" Called when a wireless scan starts. """
|
""" Called when a wireless scan starts. """
|
||||||
if not DBUS_AVAIL: return
|
if not DBUS_AVAIL:
|
||||||
|
return
|
||||||
self.network_list.set_sensitive(False)
|
self.network_list.set_sensitive(False)
|
||||||
|
|
||||||
def _remove_items_from_vbox(self, vbox):
|
def _remove_items_from_vbox(self, vbox):
|
||||||
|
""" Remove items fro a VBox. """
|
||||||
for z in vbox:
|
for z in vbox:
|
||||||
vbox.remove(z)
|
vbox.remove(z)
|
||||||
z.destroy()
|
z.destroy()
|
||||||
del z
|
del z
|
||||||
|
|
||||||
|
|
||||||
def refresh_clicked(self, widget=None):
|
def refresh_clicked(self, widget=None):
|
||||||
""" Kick off an asynchronous wireless scan. """
|
""" Kick off an asynchronous wireless scan. """
|
||||||
if not DBUS_AVAIL or self.connecting: return
|
if not DBUS_AVAIL or self.connecting:
|
||||||
|
return
|
||||||
self.refreshing = True
|
self.refreshing = True
|
||||||
|
|
||||||
# Remove stuff already in there.
|
# Remove stuff already in there.
|
||||||
@@ -637,7 +706,9 @@ class appGui(object):
|
|||||||
skip_never_connect = not daemon.GetShowNeverConnect()
|
skip_never_connect = not daemon.GetShowNeverConnect()
|
||||||
instruct_label.show()
|
instruct_label.show()
|
||||||
for x in xrange(0, num_networks):
|
for x in xrange(0, num_networks):
|
||||||
if skip_never_connect and misc.to_bool(get_wireless_prop(x,'never')): continue
|
if skip_never_connect and \
|
||||||
|
misc.to_bool(get_wireless_prop(x, 'never')):
|
||||||
|
continue
|
||||||
if printLine:
|
if printLine:
|
||||||
sep = gtk.HSeparator()
|
sep = gtk.HSeparator()
|
||||||
self.network_list.pack_start(sep, padding=10, fill=False,
|
self.network_list.pack_start(sep, padding=10, fill=False,
|
||||||
@@ -751,18 +822,25 @@ class appGui(object):
|
|||||||
for entry_info in encryption_info.itervalues():
|
for entry_info in encryption_info.itervalues():
|
||||||
if entry_info[0].entry.get_text() == "" and \
|
if entry_info[0].entry.get_text() == "" and \
|
||||||
entry_info[1] == 'required':
|
entry_info[1] == 'required':
|
||||||
error(self.window, "%s (%s)" % (_('Required encryption information is missing.'),
|
error(
|
||||||
|
self.window,
|
||||||
|
"%s (%s)" %
|
||||||
|
(_('Required encryption information is missing.'),
|
||||||
entry_info[0].label.get_label())
|
entry_info[0].label.get_label())
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
# Make sure the checkbox is checked when it should be
|
# Make sure the checkbox is checked when it should be
|
||||||
elif not entry.chkbox_encryption.get_active() and \
|
elif not entry.chkbox_encryption.get_active() and \
|
||||||
wireless.GetWirelessProperty(networkid, "encryption"):
|
wireless.GetWirelessProperty(networkid, "encryption"):
|
||||||
error(self.window, _('This network requires encryption to be enabled.'))
|
error(
|
||||||
|
self.window,
|
||||||
|
_('This network requires encryption to be enabled.')
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _wait_for_connect_thread_start(self):
|
def _wait_for_connect_thread_start(self):
|
||||||
|
""" Wait for the connect thread to start. """
|
||||||
self.wTree.get_object("progressbar").pulse()
|
self.wTree.get_object("progressbar").pulse()
|
||||||
if not self._connect_thread_started:
|
if not self._connect_thread_started:
|
||||||
return True
|
return True
|
||||||
@@ -777,12 +855,15 @@ class appGui(object):
|
|||||||
self._connect_thread_started = True
|
self._connect_thread_started = True
|
||||||
|
|
||||||
def setup_interface_for_connection():
|
def setup_interface_for_connection():
|
||||||
|
""" Initialize interface for connection. """
|
||||||
cancel_button = self.wTree.get_object("cancel_button")
|
cancel_button = self.wTree.get_object("cancel_button")
|
||||||
cancel_button.set_sensitive(True)
|
cancel_button.set_sensitive(True)
|
||||||
self.all_network_list.set_sensitive(False)
|
self.all_network_list.set_sensitive(False)
|
||||||
if self.statusID:
|
if self.statusID:
|
||||||
gobject.idle_add(self.status_bar.remove_message, 1, self.statusID)
|
gobject.idle_add(
|
||||||
gobject.idle_add(self.set_status, _('Disconnecting active connections...'))
|
self.status_bar.remove_message, 1, self.statusID)
|
||||||
|
gobject.idle_add(
|
||||||
|
self.set_status, _('Disconnecting active connections...'))
|
||||||
gobject.idle_add(self.status_area.show_all)
|
gobject.idle_add(self.status_area.show_all)
|
||||||
self.wait_for_events()
|
self.wait_for_events()
|
||||||
self._connect_thread_started = False
|
self._connect_thread_started = False
|
||||||
|
|||||||
@@ -36,16 +36,21 @@ print "Has notifications support", HAS_NOTIFY
|
|||||||
if wpath.no_use_notifications:
|
if wpath.no_use_notifications:
|
||||||
print 'Notifications disabled during setup.py configure'
|
print 'Notifications disabled during setup.py configure'
|
||||||
|
|
||||||
|
|
||||||
def can_use_notify():
|
def can_use_notify():
|
||||||
|
""" Check whether WICD is allowed to use notifications. """
|
||||||
use_notify = os.path.exists(os.path.join(os.path.expanduser('~/.wicd'),
|
use_notify = os.path.exists(os.path.join(os.path.expanduser('~/.wicd'),
|
||||||
'USE_NOTIFICATIONS')
|
'USE_NOTIFICATIONS')
|
||||||
)
|
)
|
||||||
return use_notify and HAS_NOTIFY and not wpath.no_use_notifications
|
return use_notify and HAS_NOTIFY and not wpath.no_use_notifications
|
||||||
|
|
||||||
|
|
||||||
def error(parent, message, block=True):
|
def error(parent, message, block=True):
|
||||||
""" Shows an error dialog. """
|
""" Shows an error dialog. """
|
||||||
def delete_event(dialog, id):
|
def delete_event(dialog, i):
|
||||||
|
""" Handle dialog destroy. """
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
if can_use_notify() and not block:
|
if can_use_notify() and not block:
|
||||||
notification = pynotify.Notification("ERROR", message, "error")
|
notification = pynotify.Notification("ERROR", message, "error")
|
||||||
notification.show()
|
notification.show()
|
||||||
@@ -60,10 +65,13 @@ def error(parent, message, block=True):
|
|||||||
dialog.run()
|
dialog.run()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
def alert(parent, message, block=True):
|
def alert(parent, message, block=True):
|
||||||
""" Shows an warning dialog. """
|
""" Shows an warning dialog. """
|
||||||
def delete_event(dialog, id):
|
def delete_event(dialog, i):
|
||||||
|
""" Handle dialog destroy. """
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
|
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
|
||||||
gtk.BUTTONS_OK)
|
gtk.BUTTONS_OK)
|
||||||
dialog.set_markup(message)
|
dialog.set_markup(message)
|
||||||
@@ -74,11 +82,14 @@ def alert(parent, message, block=True):
|
|||||||
dialog.run()
|
dialog.run()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
def string_input(prompt, secondary, textbox_label):
|
def string_input(prompt, secondary, textbox_label):
|
||||||
|
""" Dialog with a label and an entry. """
|
||||||
# based on a version of a PyGTK text entry from
|
# based on a version of a PyGTK text entry from
|
||||||
# http://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/
|
# http://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/
|
||||||
|
|
||||||
def dialog_response(entry, dialog, response):
|
def dialog_response(entry, dialog, response):
|
||||||
|
""" Handle dialog response. """
|
||||||
dialog.response(response)
|
dialog.response(response)
|
||||||
|
|
||||||
dialog = gtk.MessageDialog(
|
dialog = gtk.MessageDialog(
|
||||||
@@ -103,6 +114,7 @@ def string_input(prompt, secondary, textbox_label):
|
|||||||
hbox.pack_start(entry)
|
hbox.pack_start(entry)
|
||||||
|
|
||||||
# pack the boxes and show the dialog
|
# pack the boxes and show the dialog
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
dialog.vbox.pack_end(hbox, True, True, 0)
|
dialog.vbox.pack_end(hbox, True, True, 0)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
|
|
||||||
@@ -114,16 +126,21 @@ def string_input(prompt, secondary, textbox_label):
|
|||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class SmallLabel(gtk.Label):
|
class SmallLabel(gtk.Label):
|
||||||
|
""" Small GtkLabel. """
|
||||||
def __init__(self, text=''):
|
def __init__(self, text=''):
|
||||||
gtk.Label.__init__(self, text)
|
gtk.Label.__init__(self, text)
|
||||||
self.set_size_request(50, -1)
|
self.set_size_request(50, -1)
|
||||||
|
|
||||||
|
|
||||||
class LeftAlignedLabel(gtk.Label):
|
class LeftAlignedLabel(gtk.Label):
|
||||||
|
"""GtkLabel with text aligned to left. """
|
||||||
def __init__(self, label=None):
|
def __init__(self, label=None):
|
||||||
gtk.Label.__init__(self, label)
|
gtk.Label.__init__(self, label)
|
||||||
self.set_alignment(0.0, 0.5)
|
self.set_alignment(0.0, 0.5)
|
||||||
|
|
||||||
|
|
||||||
class LabelEntry(gtk.HBox):
|
class LabelEntry(gtk.HBox):
|
||||||
""" A label on the left with a textbox on the right. """
|
""" A label on the left with a textbox on the right. """
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
@@ -143,27 +160,31 @@ class LabelEntry(gtk.HBox):
|
|||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
|
""" Set text of the GtkEntry. """
|
||||||
# For compatibility...
|
# For compatibility...
|
||||||
self.entry.set_text(text)
|
self.entry.set_text(text)
|
||||||
|
|
||||||
def get_text(self):
|
def get_text(self):
|
||||||
|
""" Get text of the GtkEntry. """
|
||||||
return self.entry.get_text()
|
return self.entry.get_text()
|
||||||
|
|
||||||
def set_auto_hidden(self, value):
|
def set_auto_hidden(self, value):
|
||||||
|
""" Set auto-hide of the text of GtkEntry. """
|
||||||
self.entry.set_visibility(False)
|
self.entry.set_visibility(False)
|
||||||
self.auto_hide_text = value
|
self.auto_hide_text = value
|
||||||
|
|
||||||
def show_characters(self, widget=None, event=None):
|
def show_characters(self, widget=None, event=None):
|
||||||
# When the box has focus, show the characters
|
""" When the box has focus, show the characters. """
|
||||||
if self.auto_hide_text and widget:
|
if self.auto_hide_text and widget:
|
||||||
self.entry.set_visibility(True)
|
self.entry.set_visibility(True)
|
||||||
|
|
||||||
def set_sensitive(self, value):
|
def set_sensitive(self, value):
|
||||||
|
""" Set sensitivity of the widget. """
|
||||||
self.entry.set_sensitive(value)
|
self.entry.set_sensitive(value)
|
||||||
self.label.set_sensitive(value)
|
self.label.set_sensitive(value)
|
||||||
|
|
||||||
def hide_characters(self, widget=None, event=None):
|
def hide_characters(self, widget=None, event=None):
|
||||||
# When the box looses focus, hide them
|
""" When the box looses focus, hide them. """
|
||||||
if self.auto_hide_text and widget:
|
if self.auto_hide_text and widget:
|
||||||
self.entry.set_visibility(False)
|
self.entry.set_visibility(False)
|
||||||
|
|
||||||
@@ -202,23 +223,29 @@ class ProtectedLabelEntry(gtk.HBox):
|
|||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def set_entry_text(self, text):
|
def set_entry_text(self, text):
|
||||||
|
""" Set text of the GtkEntry. """
|
||||||
# For compatibility...
|
# For compatibility...
|
||||||
self.entry.set_text(text)
|
self.entry.set_text(text)
|
||||||
|
|
||||||
def get_entry_text(self):
|
def get_entry_text(self):
|
||||||
|
""" Get text of the GtkEntry. """
|
||||||
return self.entry.get_text()
|
return self.entry.get_text()
|
||||||
|
|
||||||
def set_sensitive(self, value):
|
def set_sensitive(self, value):
|
||||||
|
""" Set sensitivity of the widget. """
|
||||||
self.entry.set_sensitive(value)
|
self.entry.set_sensitive(value)
|
||||||
self.label.set_sensitive(value)
|
self.label.set_sensitive(value)
|
||||||
self.check.set_sensitive(value)
|
self.check.set_sensitive(value)
|
||||||
|
|
||||||
def click_handler(self, widget=None, event=None):
|
def click_handler(self, widget=None, event=None):
|
||||||
|
""" Handle clicks. """
|
||||||
active = self.check.get_active()
|
active = self.check.get_active()
|
||||||
self.entry.set_visibility(active)
|
self.entry.set_visibility(active)
|
||||||
|
|
||||||
|
|
||||||
class LabelCombo(gtk.HBox):
|
class LabelCombo(gtk.HBox):
|
||||||
""" A label on the left with a combobox on the right. """
|
""" A label on the left with a combobox on the right. """
|
||||||
|
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
gtk.HBox.__init__(self)
|
gtk.HBox.__init__(self)
|
||||||
self.combo = gtk.ComboBox()
|
self.combo = gtk.ComboBox()
|
||||||
@@ -236,20 +263,26 @@ class LabelCombo(gtk.HBox):
|
|||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def get_active(self):
|
def get_active(self):
|
||||||
|
""" Return the selected item in the GtkComboBox. """
|
||||||
return self.combo.get_active()
|
return self.combo.get_active()
|
||||||
|
|
||||||
def set_active(self, index):
|
def set_active(self, index):
|
||||||
|
""" Set given item in the GtkComboBox. """
|
||||||
self.combo.set_active(index)
|
self.combo.set_active(index)
|
||||||
|
|
||||||
def get_active_text(self):
|
def get_active_text(self):
|
||||||
|
""" Return the selected item's text in the GtkComboBox. """
|
||||||
return self.combo.get_active_text()
|
return self.combo.get_active_text()
|
||||||
|
|
||||||
def get_model(self):
|
def get_model(self):
|
||||||
|
""" Return the GtkComboBox's model. """
|
||||||
return self.combo.get_model()
|
return self.combo.get_model()
|
||||||
|
|
||||||
def set_model(self, model=None):
|
def set_model(self, model=None):
|
||||||
|
""" Set the GtkComboBox's model. """
|
||||||
self.combo.set_model(model)
|
self.combo.set_model(model)
|
||||||
|
|
||||||
def set_sensitive(self, value):
|
def set_sensitive(self, value):
|
||||||
|
""" Set sensitivity of the widget. """
|
||||||
self.combo.set_sensitive(value)
|
self.combo.set_sensitive(value)
|
||||||
self.label.set_sensitive(value)
|
self.label.set_sensitive(value)
|
||||||
|
|||||||
324
gtk/netentry.py
324
gtk/netentry.py
@@ -31,7 +31,8 @@ import wicd.misc as misc
|
|||||||
import wicd.wpath as wpath
|
import wicd.wpath as wpath
|
||||||
import wicd.dbusmanager as dbusmanager
|
import wicd.dbusmanager as dbusmanager
|
||||||
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||||
from guiutil import error, LabelEntry, GreyLabel, LeftAlignedLabel, string_input, ProtectedLabelEntry, LabelCombo
|
from guiutil import error, LabelEntry, GreyLabel, LeftAlignedLabel
|
||||||
|
from guiutil import string_input, ProtectedLabelEntry, LabelCombo
|
||||||
|
|
||||||
from wicd.translations import language, _
|
from wicd.translations import language, _
|
||||||
|
|
||||||
@@ -40,13 +41,17 @@ daemon = None
|
|||||||
wired = None
|
wired = None
|
||||||
wireless = None
|
wireless = None
|
||||||
|
|
||||||
|
|
||||||
def setup_dbus():
|
def setup_dbus():
|
||||||
|
""" Initialize DBus. """
|
||||||
global daemon, wireless, wired
|
global daemon, wireless, wired
|
||||||
daemon = dbusmanager.get_interface('daemon')
|
daemon = dbusmanager.get_interface('daemon')
|
||||||
wireless = dbusmanager.get_interface('wireless')
|
wireless = dbusmanager.get_interface('wireless')
|
||||||
wired = dbusmanager.get_interface('wired')
|
wired = dbusmanager.get_interface('wired')
|
||||||
|
|
||||||
|
|
||||||
class AdvancedSettingsDialog(gtk.Dialog):
|
class AdvancedSettingsDialog(gtk.Dialog):
|
||||||
|
""" Advanced settings dialog. """
|
||||||
def __init__(self, network_name=None):
|
def __init__(self, network_name=None):
|
||||||
""" Build the base advanced settings dialog.
|
""" Build the base advanced settings dialog.
|
||||||
|
|
||||||
@@ -60,11 +65,17 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
else:
|
else:
|
||||||
title = _('Properties')
|
title = _('Properties')
|
||||||
|
|
||||||
gtk.Dialog.__init__(self, title=title,
|
gtk.Dialog.__init__(
|
||||||
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL,
|
self,
|
||||||
|
title=title,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=(
|
||||||
|
gtk.STOCK_CANCEL,
|
||||||
gtk.RESPONSE_REJECT,
|
gtk.RESPONSE_REJECT,
|
||||||
gtk.STOCK_OK,
|
gtk.STOCK_OK,
|
||||||
gtk.RESPONSE_ACCEPT))
|
gtk.RESPONSE_ACCEPT
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.set_default_size()
|
self.set_default_size()
|
||||||
|
|
||||||
@@ -83,7 +94,8 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
dhcp_hostname_hbox = gtk.HBox(False, 0)
|
dhcp_hostname_hbox = gtk.HBox(False, 0)
|
||||||
self.chkbox_use_dhcp_hostname = gtk.CheckButton()
|
self.chkbox_use_dhcp_hostname = gtk.CheckButton()
|
||||||
self.txt_dhcp_hostname = LabelEntry("DHCP Hostname")
|
self.txt_dhcp_hostname = LabelEntry("DHCP Hostname")
|
||||||
dhcp_hostname_hbox.pack_start(self.chkbox_use_dhcp_hostname, fill=False, expand=False)
|
dhcp_hostname_hbox.pack_start(
|
||||||
|
self.chkbox_use_dhcp_hostname, fill=False, expand=False)
|
||||||
dhcp_hostname_hbox.pack_start(self.txt_dhcp_hostname)
|
dhcp_hostname_hbox.pack_start(self.txt_dhcp_hostname)
|
||||||
self.chkbox_static_ip = gtk.CheckButton(_('Use Static IPs'))
|
self.chkbox_static_ip = gtk.CheckButton(_('Use Static IPs'))
|
||||||
self.chkbox_static_dns = gtk.CheckButton(_('Use Static DNS'))
|
self.chkbox_static_dns = gtk.CheckButton(_('Use Static DNS'))
|
||||||
@@ -102,7 +114,8 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.script_button.set_label(_('Scripts'))
|
self.script_button.set_label(_('Scripts'))
|
||||||
|
|
||||||
self.button_hbox = gtk.HBox(False, 2)
|
self.button_hbox = gtk.HBox(False, 2)
|
||||||
self.button_hbox.pack_start(self.script_button, fill=False, expand=False)
|
self.button_hbox.pack_start(
|
||||||
|
self.script_button, fill=False, expand=False)
|
||||||
self.button_hbox.show()
|
self.button_hbox.show()
|
||||||
|
|
||||||
self.swindow = gtk.ScrolledWindow()
|
self.swindow = gtk.ScrolledWindow()
|
||||||
@@ -112,6 +125,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.cvbox = gtk.VBox()
|
self.cvbox = gtk.VBox()
|
||||||
self.viewport.add(self.cvbox)
|
self.viewport.add(self.cvbox)
|
||||||
self.swindow.add(self.viewport)
|
self.swindow.add(self.viewport)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
self.vbox.pack_start(self.swindow)
|
self.vbox.pack_start(self.swindow)
|
||||||
|
|
||||||
assert(isinstance(self.cvbox, gtk.VBox))
|
assert(isinstance(self.cvbox, gtk.VBox))
|
||||||
@@ -126,21 +140,25 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.cvbox.pack_start(self.txt_dns_2, fill=False, expand=False)
|
self.cvbox.pack_start(self.txt_dns_2, fill=False, expand=False)
|
||||||
self.cvbox.pack_start(self.txt_dns_3, fill=False, expand=False)
|
self.cvbox.pack_start(self.txt_dns_3, fill=False, expand=False)
|
||||||
self.cvbox.pack_start(dhcp_hostname_hbox, fill=False, expand=False)
|
self.cvbox.pack_start(dhcp_hostname_hbox, fill=False, expand=False)
|
||||||
self.cvbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5)
|
self.cvbox.pack_end(
|
||||||
|
self.button_hbox, fill=False, expand=False, padding=5)
|
||||||
|
|
||||||
# Connect the events to the actions
|
# Connect the events to the actions
|
||||||
self.chkbox_static_ip.connect("toggled", self.toggle_ip_checkbox)
|
self.chkbox_static_ip.connect("toggled", self.toggle_ip_checkbox)
|
||||||
self.chkbox_static_dns.connect("toggled", self.toggle_dns_checkbox)
|
self.chkbox_static_dns.connect("toggled", self.toggle_dns_checkbox)
|
||||||
self.chkbox_global_dns.connect("toggled", self.toggle_global_dns_checkbox)
|
self.chkbox_global_dns.connect(
|
||||||
self.chkbox_use_dhcp_hostname.connect('toggled',
|
"toggled", self.toggle_global_dns_checkbox)
|
||||||
self.toggle_dhcp_hostname_checkbox)
|
self.chkbox_use_dhcp_hostname.connect(
|
||||||
|
'toggled',
|
||||||
|
self.toggle_dhcp_hostname_checkbox
|
||||||
|
)
|
||||||
|
|
||||||
# Start with all disabled, then they will be enabled later.
|
# Start with all disabled, then they will be enabled later.
|
||||||
self.chkbox_static_ip.set_active(False)
|
self.chkbox_static_ip.set_active(False)
|
||||||
self.chkbox_static_dns.set_active(False)
|
self.chkbox_static_dns.set_active(False)
|
||||||
|
|
||||||
|
|
||||||
def set_default_size(self):
|
def set_default_size(self):
|
||||||
|
""" Set default window size. """
|
||||||
width, height = self.get_size()
|
width, height = self.get_size()
|
||||||
s_height = gtk.gdk.screen_height()
|
s_height = gtk.gdk.screen_height()
|
||||||
if s_height < 768:
|
if s_height < 768:
|
||||||
@@ -158,17 +176,20 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
if misc.IsValidIP(ip):
|
if misc.IsValidIP(ip):
|
||||||
# Only do these things if it's IPv4
|
# Only do these things if it's IPv4
|
||||||
if misc.IsValidIPv4(ip):
|
if misc.IsValidIPv4(ip):
|
||||||
if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank
|
# Make sure the gateway box is blank
|
||||||
|
if stringToNone(gateway.get_text()) is None:
|
||||||
# Fill it in with a .1 at the end
|
# Fill it in with a .1 at the end
|
||||||
gateway.set_text(ip[:ip.rindex('.')] + '.1')
|
gateway.set_text(ip[:ip.rindex('.')] + '.1')
|
||||||
|
|
||||||
if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank
|
# Make sure the netmask is blank
|
||||||
netmask.set_text('255.255.255.0') # Fill in the most common one
|
if stringToNone(netmask.get_text()) is None:
|
||||||
|
# Fill in the most common one
|
||||||
|
netmask.set_text('255.255.255.0')
|
||||||
elif ip != '':
|
elif ip != '':
|
||||||
error(None, _('Invalid IP address entered.'))
|
error(None, _('Invalid IP address entered.'))
|
||||||
|
|
||||||
def reset_static_checkboxes(self):
|
def reset_static_checkboxes(self):
|
||||||
# Enable the right stuff
|
""" Enable the right stuff. """
|
||||||
if stringToNone(self.txt_ip.get_text()):
|
if stringToNone(self.txt_ip.get_text()):
|
||||||
self.chkbox_static_ip.set_active(True)
|
self.chkbox_static_ip.set_active(True)
|
||||||
self.chkbox_static_dns.set_active(True)
|
self.chkbox_static_dns.set_active(True)
|
||||||
@@ -224,6 +245,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.chkbox_global_dns.set_active(False)
|
self.chkbox_global_dns.set_active(False)
|
||||||
|
|
||||||
def toggle_dhcp_hostname_checkbox(self, widget=None):
|
def toggle_dhcp_hostname_checkbox(self, widget=None):
|
||||||
|
""" Set widget sensitivity. """
|
||||||
self.txt_dhcp_hostname.set_sensitive(
|
self.txt_dhcp_hostname.set_sensitive(
|
||||||
self.chkbox_use_dhcp_hostname.get_active())
|
self.chkbox_use_dhcp_hostname.get_active())
|
||||||
|
|
||||||
@@ -231,7 +253,10 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
""" Set the DNS entries' sensitivity based on the Global checkbox. """
|
""" Set the DNS entries' sensitivity based on the Global checkbox. """
|
||||||
global_dns_active = daemon.GetUseGlobalDNS()
|
global_dns_active = daemon.GetUseGlobalDNS()
|
||||||
if not global_dns_active and self.chkbox_global_dns.get_active():
|
if not global_dns_active and self.chkbox_global_dns.get_active():
|
||||||
error(None, _('Global DNS has not been enabled in general preferences.'))
|
error(
|
||||||
|
None,
|
||||||
|
_('Global DNS has not been enabled in general preferences.')
|
||||||
|
)
|
||||||
self.chkbox_global_dns.set_active(False)
|
self.chkbox_global_dns.set_active(False)
|
||||||
if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active():
|
if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active():
|
||||||
for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
|
for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
|
||||||
@@ -250,12 +275,14 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.destroy()
|
self.destroy()
|
||||||
del self
|
del self
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self, networkid=None):
|
||||||
""" Save settings common to wired and wireless settings dialogs. """
|
""" Save settings common to wired and wireless settings dialogs. """
|
||||||
if self.chkbox_static_ip.get_active():
|
if self.chkbox_static_ip.get_active():
|
||||||
self.set_net_prop("ip", noneToString(self.txt_ip.get_text()))
|
self.set_net_prop("ip", noneToString(self.txt_ip.get_text()))
|
||||||
self.set_net_prop("netmask", noneToString(self.txt_netmask.get_text()))
|
self.set_net_prop(
|
||||||
self.set_net_prop("gateway", noneToString(self.txt_gateway.get_text()))
|
"netmask", noneToString(self.txt_netmask.get_text()))
|
||||||
|
self.set_net_prop(
|
||||||
|
"gateway", noneToString(self.txt_gateway.get_text()))
|
||||||
else:
|
else:
|
||||||
self.set_net_prop("ip", '')
|
self.set_net_prop("ip", '')
|
||||||
self.set_net_prop("netmask", '')
|
self.set_net_prop("netmask", '')
|
||||||
@@ -265,8 +292,10 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
not self.chkbox_global_dns.get_active():
|
not self.chkbox_global_dns.get_active():
|
||||||
self.set_net_prop('use_static_dns', True)
|
self.set_net_prop('use_static_dns', True)
|
||||||
self.set_net_prop('use_global_dns', False)
|
self.set_net_prop('use_global_dns', False)
|
||||||
self.set_net_prop('dns_domain', noneToString(self.txt_domain.get_text()))
|
self.set_net_prop(
|
||||||
self.set_net_prop("search_domain", noneToString(self.txt_search_dom.get_text()))
|
'dns_domain', noneToString(self.txt_domain.get_text()))
|
||||||
|
self.set_net_prop(
|
||||||
|
"search_domain", noneToString(self.txt_search_dom.get_text()))
|
||||||
self.set_net_prop("dns1", noneToString(self.txt_dns_1.get_text()))
|
self.set_net_prop("dns1", noneToString(self.txt_dns_1.get_text()))
|
||||||
self.set_net_prop("dns2", noneToString(self.txt_dns_2.get_text()))
|
self.set_net_prop("dns2", noneToString(self.txt_dns_2.get_text()))
|
||||||
self.set_net_prop("dns3", noneToString(self.txt_dns_3.get_text()))
|
self.set_net_prop("dns3", noneToString(self.txt_dns_3.get_text()))
|
||||||
@@ -284,7 +313,8 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
self.set_net_prop("dns3", '')
|
self.set_net_prop("dns3", '')
|
||||||
self.set_net_prop('usedhcphostname',
|
self.set_net_prop('usedhcphostname',
|
||||||
self.chkbox_use_dhcp_hostname.get_active())
|
self.chkbox_use_dhcp_hostname.get_active())
|
||||||
self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))
|
self.set_net_prop(
|
||||||
|
"dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))
|
||||||
|
|
||||||
def change_encrypt_method(self, widget=None):
|
def change_encrypt_method(self, widget=None):
|
||||||
""" Load all the entries for a given encryption method. """
|
""" Load all the entries for a given encryption method. """
|
||||||
@@ -328,20 +358,24 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
|
|
||||||
|
|
||||||
class WiredSettingsDialog(AdvancedSettingsDialog):
|
class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||||
|
""" Wired settings dialog. """
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
""" Build the wired settings dialog. """
|
""" Build the wired settings dialog. """
|
||||||
AdvancedSettingsDialog.__init__(self, _('Wired Network'))
|
AdvancedSettingsDialog.__init__(self, _('Wired Network'))
|
||||||
|
|
||||||
# So we can test if we are wired or wireless (for change_encrypt_method())
|
# So we can test if we are wired or wireless (for
|
||||||
|
# change_encrypt_method())
|
||||||
self.wired = True
|
self.wired = True
|
||||||
|
|
||||||
## This section is largely copied from WirelessSettingsDialog, but with some changes
|
## This section is largely copied from WirelessSettingsDialog, but with
|
||||||
|
## some changes
|
||||||
# Set up encryption stuff
|
# Set up encryption stuff
|
||||||
self.combo_encryption = gtk.combo_box_new_text()
|
self.combo_encryption = gtk.combo_box_new_text()
|
||||||
self.chkbox_encryption = gtk.CheckButton(_('Use Encryption'))
|
self.chkbox_encryption = gtk.CheckButton(_('Use Encryption'))
|
||||||
# Make the vbox to hold the encryption stuff.
|
# Make the vbox to hold the encryption stuff.
|
||||||
self.vbox_encrypt_info = gtk.VBox(False, 0)
|
self.vbox_encrypt_info = gtk.VBox(False, 0)
|
||||||
self.chkbox_encryption.set_active(bool(wired.GetWiredProperty('encryption_enabled')))
|
self.chkbox_encryption.set_active(
|
||||||
|
bool(wired.GetWiredProperty('encryption_enabled')))
|
||||||
self.combo_encryption.set_sensitive(False)
|
self.combo_encryption.set_sensitive(False)
|
||||||
self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
|
self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
|
||||||
|
|
||||||
@@ -373,12 +407,17 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
profile = self.prof_name
|
profile = self.prof_name
|
||||||
cmdend = [os.path.join(wpath.gtk, "configscript.py"), profile, "wired"]
|
cmdend = [os.path.join(wpath.gtk, "configscript.py"), profile, "wired"]
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
cmdbase = misc.get_sudo_cmd(_('You must enter your password to configure scripts'),
|
cmdbase = misc.get_sudo_cmd(
|
||||||
prog_num=daemon.GetSudoApp())
|
_('You must enter your password to configure scripts'),
|
||||||
|
prog_num=daemon.GetSudoApp()
|
||||||
|
)
|
||||||
if not cmdbase:
|
if not cmdbase:
|
||||||
error(None, _('Could not find a graphical sudo program. '\
|
error(None,
|
||||||
'The script editor could not be launched. '\
|
_('Could not find a graphical sudo program. '
|
||||||
"You'll have to edit scripts directly your configuration file."))
|
'The script editor could not be launched. '
|
||||||
|
"You'll have to edit scripts directly your configuration "
|
||||||
|
"file.")
|
||||||
|
)
|
||||||
return
|
return
|
||||||
cmdbase.extend(cmdend)
|
cmdbase.extend(cmdend)
|
||||||
misc.LaunchAndWait(cmdbase)
|
misc.LaunchAndWait(cmdbase)
|
||||||
@@ -396,7 +435,8 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.txt_dns_3.set_text(self.format_entry("dns3"))
|
self.txt_dns_3.set_text(self.format_entry("dns3"))
|
||||||
self.txt_domain.set_text(self.format_entry("dns_domain"))
|
self.txt_domain.set_text(self.format_entry("dns_domain"))
|
||||||
self.txt_search_dom.set_text(self.format_entry("search_domain"))
|
self.txt_search_dom.set_text(self.format_entry("search_domain"))
|
||||||
self.chkbox_global_dns.set_active(bool(wired.GetWiredProperty("use_global_dns")))
|
self.chkbox_global_dns.set_active(
|
||||||
|
bool(wired.GetWiredProperty("use_global_dns")))
|
||||||
|
|
||||||
dhcphname = wired.GetWiredProperty("dhcphostname")
|
dhcphname = wired.GetWiredProperty("dhcphostname")
|
||||||
if dhcphname is None:
|
if dhcphname is None:
|
||||||
@@ -405,36 +445,42 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.txt_dhcp_hostname.set_text(dhcphname)
|
self.txt_dhcp_hostname.set_text(dhcphname)
|
||||||
self.reset_static_checkboxes()
|
self.reset_static_checkboxes()
|
||||||
|
|
||||||
self.chkbox_encryption.set_active(bool(wired.GetWiredProperty('encryption_enabled')))
|
self.chkbox_encryption.set_active(
|
||||||
|
bool(wired.GetWiredProperty('encryption_enabled')))
|
||||||
self.change_encrypt_method()
|
self.change_encrypt_method()
|
||||||
self.toggle_encryption()
|
self.toggle_encryption()
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self, networkid=None):
|
||||||
|
""" Save settings to disk. """
|
||||||
# Check encryption info
|
# Check encryption info
|
||||||
encrypt_info = self.encryption_info
|
encrypt_info = self.encryption_info
|
||||||
self.set_net_prop("encryption_enabled", self.chkbox_encryption.get_active())
|
self.set_net_prop(
|
||||||
|
"encryption_enabled",
|
||||||
|
self.chkbox_encryption.get_active()
|
||||||
|
)
|
||||||
if self.chkbox_encryption.get_active():
|
if self.chkbox_encryption.get_active():
|
||||||
print "setting encryption info..."
|
print "setting encryption info..."
|
||||||
encrypt_methods = self.encrypt_types
|
encrypt_methods = self.encrypt_types
|
||||||
self.set_net_prop("enctype",
|
self.set_net_prop(
|
||||||
encrypt_methods[self.combo_encryption.get_active()]['type'])
|
"enctype",
|
||||||
|
encrypt_methods[self.combo_encryption.get_active()]['type']
|
||||||
|
)
|
||||||
# Make sure all required fields are filled in.
|
# Make sure all required fields are filled in.
|
||||||
for entry_info in encrypt_info.itervalues():
|
for entry_info in encrypt_info.itervalues():
|
||||||
if entry_info[0].entry.get_text() == "" and \
|
if entry_info[0].entry.get_text() == "" and \
|
||||||
entry_info[1] == 'required':
|
entry_info[1] == 'required':
|
||||||
error(self, "%s (%s)" % (_('Required encryption information is missing.'),
|
error(
|
||||||
entry_info[0].label.get_label())
|
self,
|
||||||
|
"%s (%s)" % (
|
||||||
|
_('Required encryption information is missing.'),
|
||||||
|
entry_info[0].label.get_label()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
# Now save all the entries.
|
# Now save all the entries.
|
||||||
for entry_key, entry_info in encrypt_info.iteritems():
|
for entry_key, entry_info in encrypt_info.iteritems():
|
||||||
self.set_net_prop(entry_key,
|
self.set_net_prop(entry_key,
|
||||||
noneToString(entry_info[0].entry.get_text()))
|
noneToString(entry_info[0].entry.get_text()))
|
||||||
elif not wired and not self.chkbox_encryption.get_active() and \
|
|
||||||
wireless.GetWirelessProperty(networkid, "encryption"):
|
|
||||||
# Encrypt checkbox is off, but the network needs it.
|
|
||||||
error(self, _('This network requires encryption to be enabled.'))
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
print "no encryption specified..."
|
print "no encryption specified..."
|
||||||
self.set_net_prop("enctype", "None")
|
self.set_net_prop("enctype", "None")
|
||||||
@@ -455,17 +501,21 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
|
|
||||||
|
|
||||||
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||||
|
""" Wireless settings dialog. """
|
||||||
def __init__(self, networkID):
|
def __init__(self, networkID):
|
||||||
""" Build the wireless settings dialog. """
|
""" Build the wireless settings dialog. """
|
||||||
AdvancedSettingsDialog.__init__(self, wireless.GetWirelessProperty(networkID, 'essid'))
|
AdvancedSettingsDialog.__init__(
|
||||||
# So we can test if we are wired or wireless (for change_encrypt_method())
|
self, wireless.GetWirelessProperty(networkID, 'essid'))
|
||||||
|
# So we can test if we are wired or wireless (for
|
||||||
|
# change_encrypt_method())
|
||||||
self.wired = False
|
self.wired = False
|
||||||
|
|
||||||
# Set up encryption stuff
|
# Set up encryption stuff
|
||||||
self.networkID = networkID
|
self.networkID = networkID
|
||||||
self.combo_encryption = gtk.combo_box_new_text()
|
self.combo_encryption = gtk.combo_box_new_text()
|
||||||
self.chkbox_encryption = gtk.CheckButton(_('Use Encryption'))
|
self.chkbox_encryption = gtk.CheckButton(_('Use Encryption'))
|
||||||
self.chkbox_global_settings = gtk.CheckButton(_('Use these settings for all networks sharing this essid'))
|
self.chkbox_global_settings = gtk.CheckButton(
|
||||||
|
_('Use these settings for all networks sharing this essid'))
|
||||||
|
|
||||||
rate_vbox = gtk.VBox(False, 0)
|
rate_vbox = gtk.VBox(False, 0)
|
||||||
|
|
||||||
@@ -489,14 +539,18 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
|
|
||||||
information_button = gtk.Button(stock=gtk.STOCK_INFO)
|
information_button = gtk.Button(stock=gtk.STOCK_INFO)
|
||||||
self.button_hbox.pack_start(information_button, False, False)
|
self.button_hbox.pack_start(information_button, False, False)
|
||||||
information_button.connect('clicked', lambda *a, **k: WirelessInformationDialog(networkID, self))
|
information_button.connect(
|
||||||
|
'clicked',
|
||||||
|
lambda *a, **k: WirelessInformationDialog(networkID, self)
|
||||||
|
)
|
||||||
information_button.show()
|
information_button.show()
|
||||||
|
|
||||||
# Build the encryption menu
|
# Build the encryption menu
|
||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
for x, enc_type in enumerate(self.encrypt_types):
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
self.combo_encryption.append_text(enc_type['name'])
|
self.combo_encryption.append_text(enc_type['name'])
|
||||||
if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
|
if enc_type['type'] == \
|
||||||
|
wireless.GetWirelessProperty(networkID, "enctype"):
|
||||||
activeID = x
|
activeID = x
|
||||||
self.combo_encryption.set_active(activeID)
|
self.combo_encryption.set_active(activeID)
|
||||||
if activeID != -1:
|
if activeID != -1:
|
||||||
@@ -531,12 +585,18 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
cmdend = [os.path.join(wpath.gtk, "configscript.py"),
|
cmdend = [os.path.join(wpath.gtk, "configscript.py"),
|
||||||
str(self.networkID), "wireless"]
|
str(self.networkID), "wireless"]
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
cmdbase = misc.get_sudo_cmd(_('You must enter your password to configure scripts'),
|
cmdbase = misc.get_sudo_cmd(
|
||||||
prog_num=daemon.GetSudoApp())
|
_('You must enter your password to configure scripts'),
|
||||||
|
prog_num=daemon.GetSudoApp()
|
||||||
|
)
|
||||||
if not cmdbase:
|
if not cmdbase:
|
||||||
error(None, _('Could not find a graphical sudo program. '\
|
error(
|
||||||
'The script editor could not be launched. '\
|
None,
|
||||||
"You'll have to edit scripts directly your configuration file."))
|
_('Could not find a graphical sudo program. '
|
||||||
|
'The script editor could not be launched. '
|
||||||
|
"You'll have to edit scripts directly your "
|
||||||
|
"configuration file.")
|
||||||
|
)
|
||||||
return
|
return
|
||||||
cmdbase.extend(cmdend)
|
cmdbase.extend(cmdend)
|
||||||
misc.LaunchAndWait(cmdbase)
|
misc.LaunchAndWait(cmdbase)
|
||||||
@@ -554,22 +614,26 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.txt_netmask.set_text(self.format_entry(networkID, "netmask"))
|
self.txt_netmask.set_text(self.format_entry(networkID, "netmask"))
|
||||||
self.txt_gateway.set_text(self.format_entry(networkID, "gateway"))
|
self.txt_gateway.set_text(self.format_entry(networkID, "gateway"))
|
||||||
|
|
||||||
self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
|
self.chkbox_global_dns.set_active(
|
||||||
'use_global_dns')))
|
bool(wireless.GetWirelessProperty(networkID, 'use_global_dns')))
|
||||||
self.chkbox_static_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
|
self.chkbox_static_dns.set_active(
|
||||||
'use_static_dns')))
|
bool(wireless.GetWirelessProperty(networkID, 'use_static_dns')))
|
||||||
|
|
||||||
self.txt_dns_1.set_text(self.format_entry(networkID, "dns1"))
|
self.txt_dns_1.set_text(self.format_entry(networkID, "dns1"))
|
||||||
self.txt_dns_2.set_text(self.format_entry(networkID, "dns2"))
|
self.txt_dns_2.set_text(self.format_entry(networkID, "dns2"))
|
||||||
self.txt_dns_3.set_text(self.format_entry(networkID, "dns3"))
|
self.txt_dns_3.set_text(self.format_entry(networkID, "dns3"))
|
||||||
self.txt_domain.set_text(self.format_entry(networkID, "dns_domain"))
|
self.txt_domain.set_text(self.format_entry(networkID, "dns_domain"))
|
||||||
self.txt_search_dom.set_text(self.format_entry(networkID, "search_domain"))
|
self.txt_search_dom.set_text(
|
||||||
|
self.format_entry(networkID, "search_domain"))
|
||||||
|
|
||||||
self.reset_static_checkboxes()
|
self.reset_static_checkboxes()
|
||||||
self.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID,
|
self.chkbox_encryption.set_active(
|
||||||
'encryption')))
|
bool(wireless.GetWirelessProperty(networkID, 'encryption')))
|
||||||
self.chkbox_global_settings.set_active(bool(wireless.GetWirelessProperty(networkID,
|
self.chkbox_global_settings.set_active(
|
||||||
'use_settings_globally')))
|
bool(
|
||||||
|
wireless.GetWirelessProperty(networkID, 'use_settings_globally')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.chkbox_use_dhcp_hostname.set_active(
|
self.chkbox_use_dhcp_hostname.set_active(
|
||||||
bool(wireless.GetWirelessProperty(networkID, 'usedhcphostname')))
|
bool(wireless.GetWirelessProperty(networkID, 'usedhcphostname')))
|
||||||
@@ -587,8 +651,11 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
if chosen_bitrate not in self.bitrates:
|
if chosen_bitrate not in self.bitrates:
|
||||||
chosen_bitrate = 'auto'
|
chosen_bitrate = 'auto'
|
||||||
self.combo_rate.set_active(self.bitrates.index(chosen_bitrate))
|
self.combo_rate.set_active(self.bitrates.index(chosen_bitrate))
|
||||||
self.chkbox_lower_rate.set_active(bool(wireless.GetWirelessProperty(networkID,
|
self.chkbox_lower_rate.set_active(
|
||||||
'allow_lower_bitrates')))
|
bool(
|
||||||
|
wireless.GetWirelessProperty(networkID, 'allow_lower_bitrates')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
|
user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
|
||||||
@@ -605,20 +672,26 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.combo_encryption.set_active(0)
|
self.combo_encryption.set_active(0)
|
||||||
self.change_encrypt_method()
|
self.change_encrypt_method()
|
||||||
|
|
||||||
def save_settings(self, networkid):
|
def save_settings(self, networkid=None):
|
||||||
# Check encryption info
|
# Check encryption info
|
||||||
encrypt_info = self.encryption_info
|
encrypt_info = self.encryption_info
|
||||||
if self.chkbox_encryption.get_active():
|
if self.chkbox_encryption.get_active():
|
||||||
print "setting encryption info..."
|
print "setting encryption info..."
|
||||||
encrypt_methods = self.encrypt_types
|
encrypt_methods = self.encrypt_types
|
||||||
self.set_net_prop("enctype",
|
self.set_net_prop(
|
||||||
encrypt_methods[self.combo_encryption.get_active()]['type'])
|
"enctype",
|
||||||
|
encrypt_methods[self.combo_encryption.get_active()]['type']
|
||||||
|
)
|
||||||
# Make sure all required fields are filled in.
|
# Make sure all required fields are filled in.
|
||||||
for entry_info in encrypt_info.itervalues():
|
for entry_info in encrypt_info.itervalues():
|
||||||
if entry_info[0].entry.get_text() == "" and \
|
if entry_info[0].entry.get_text() == "" and \
|
||||||
entry_info[1] == 'required':
|
entry_info[1] == 'required':
|
||||||
error(self, "%s (%s)" % (_('Required encryption information is missing.'),
|
error(
|
||||||
entry_info[0].label.get_label())
|
self,
|
||||||
|
"%s (%s)" % (
|
||||||
|
_('Required encryption information is missing.'),
|
||||||
|
entry_info[0].label.get_label()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
# Now save all the entries.
|
# Now save all the entries.
|
||||||
@@ -644,8 +717,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
if self.combo_rate.get_active() == -1:
|
if self.combo_rate.get_active() == -1:
|
||||||
self.set_net_prop('bitrate', 'auto')
|
self.set_net_prop('bitrate', 'auto')
|
||||||
else:
|
else:
|
||||||
self.set_net_prop('bitrate', self.bitrates[self.combo_rate.get_active()])
|
self.set_net_prop(
|
||||||
self.set_net_prop('allow_lower_bitrates', bool(self.chkbox_lower_rate.get_active()))
|
'bitrate',
|
||||||
|
self.bitrates[self.combo_rate.get_active()]
|
||||||
|
)
|
||||||
|
self.set_net_prop(
|
||||||
|
'allow_lower_bitrates',
|
||||||
|
bool(self.chkbox_lower_rate.get_active())
|
||||||
|
)
|
||||||
wireless.SaveWirelessNetworkProfile(networkid)
|
wireless.SaveWirelessNetworkProfile(networkid)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -655,6 +734,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
|
|
||||||
|
|
||||||
class NetworkEntry(gtk.HBox):
|
class NetworkEntry(gtk.HBox):
|
||||||
|
""" Network entry. """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Base network entry class.
|
""" Base network entry class.
|
||||||
|
|
||||||
@@ -714,6 +794,7 @@ class NetworkEntry(gtk.HBox):
|
|||||||
|
|
||||||
|
|
||||||
class WiredNetworkEntry(NetworkEntry):
|
class WiredNetworkEntry(NetworkEntry):
|
||||||
|
""" Wired network entry. """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Load the wired network entry. """
|
""" Load the wired network entry. """
|
||||||
NetworkEntry.__init__(self)
|
NetworkEntry.__init__(self)
|
||||||
@@ -732,8 +813,13 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
self.button_add = gtk.Button(stock=gtk.STOCK_ADD)
|
self.button_add = gtk.Button(stock=gtk.STOCK_ADD)
|
||||||
self.button_delete = gtk.Button(stock=gtk.STOCK_DELETE)
|
self.button_delete = gtk.Button(stock=gtk.STOCK_DELETE)
|
||||||
self.profile_help = gtk.Label(_('To connect to a wired network, you must create a network profile. To create a network profile, type a name that describes this network, and press Add.'))
|
self.profile_help = gtk.Label(
|
||||||
self.chkbox_default_profile = gtk.CheckButton(_('Use as default profile (overwrites any previous default)'))
|
_('To connect to a wired network, you must create a network '
|
||||||
|
'profile. To create a network profile, type a name that describes '
|
||||||
|
'this network, and press Add.')
|
||||||
|
)
|
||||||
|
self.chkbox_default_profile = gtk.CheckButton(
|
||||||
|
_('Use as default profile (overwrites any previous default)'))
|
||||||
self.combo_profile_names = gtk.combo_box_new_text()
|
self.combo_profile_names = gtk.combo_box_new_text()
|
||||||
|
|
||||||
# Format the profile help label.
|
# Format the profile help label.
|
||||||
@@ -772,7 +858,8 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
print "no wired profiles found"
|
print "no wired profiles found"
|
||||||
self.profile_help.show()
|
self.profile_help.show()
|
||||||
|
|
||||||
self.advanced_dialog = WiredSettingsDialog(self.combo_profile_names.get_active_text())
|
self.advanced_dialog = \
|
||||||
|
WiredSettingsDialog(self.combo_profile_names.get_active_text())
|
||||||
|
|
||||||
# Show everything, but hide the profile help label.
|
# Show everything, but hide the profile help label.
|
||||||
self.show_all()
|
self.show_all()
|
||||||
@@ -819,11 +906,12 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
def add_profile(self, widget):
|
def add_profile(self, widget):
|
||||||
""" Add a profile to the profile list. """
|
""" Add a profile to the profile list. """
|
||||||
response = string_input("Enter a profile name", "The profile name " +
|
response = string_input(
|
||||||
"will not be used by the computer. It " +
|
"Enter a profile name", "The profile name will not be used by the "
|
||||||
"allows you to " +
|
"computer. It allows you to easily distinguish between different "
|
||||||
"easily distinguish between different network " +
|
"network profiles.",
|
||||||
"profiles.", "Profile name:").strip()
|
"Profile name:"
|
||||||
|
).strip()
|
||||||
|
|
||||||
# if response is "" or None
|
# if response is "" or None
|
||||||
if not response:
|
if not response:
|
||||||
@@ -854,7 +942,8 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
self.combo_profile_names.remove_text(self.combo_profile_names.
|
self.combo_profile_names.remove_text(self.combo_profile_names.
|
||||||
get_active())
|
get_active())
|
||||||
self.combo_profile_names.set_active(0)
|
self.combo_profile_names.set_active(0)
|
||||||
self.advanced_dialog.prof_name = self.combo_profile_names.get_active_text()
|
self.advanced_dialog.prof_name = \
|
||||||
|
self.combo_profile_names.get_active_text()
|
||||||
if not wired.GetWiredProfileList():
|
if not wired.GetWiredProfileList():
|
||||||
self.profile_help.show()
|
self.profile_help.show()
|
||||||
entry = self.combo_profile_names.child
|
entry = self.combo_profile_names.child
|
||||||
@@ -873,7 +962,8 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
wired.UnsetWiredDefault()
|
wired.UnsetWiredDefault()
|
||||||
wired.SetWiredProperty("default",
|
wired.SetWiredProperty("default",
|
||||||
self.chkbox_default_profile.get_active())
|
self.chkbox_default_profile.get_active())
|
||||||
wired.SaveWiredNetworkProfile(self.combo_profile_names.get_active_text())
|
wired.SaveWiredNetworkProfile(
|
||||||
|
self.combo_profile_names.get_active_text())
|
||||||
|
|
||||||
def change_profile(self, widget):
|
def change_profile(self, widget):
|
||||||
""" Called when a new profile is chosen from the list. """
|
""" Called when a new profile is chosen from the list. """
|
||||||
@@ -898,6 +988,7 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
|
|
||||||
class WirelessNetworkEntry(NetworkEntry):
|
class WirelessNetworkEntry(NetworkEntry):
|
||||||
|
""" Wireless network entry. """
|
||||||
def __init__(self, networkID):
|
def __init__(self, networkID):
|
||||||
""" Build the wireless network entry. """
|
""" Build the wireless network entry. """
|
||||||
NetworkEntry.__init__(self)
|
NetworkEntry.__init__(self)
|
||||||
@@ -907,27 +998,31 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
self.image.set_alignment(.5, .5)
|
self.image.set_alignment(.5, .5)
|
||||||
self.image.set_size_request(60, -1)
|
self.image.set_size_request(60, -1)
|
||||||
self.image.show()
|
self.image.show()
|
||||||
self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID,
|
self.essid = noneToBlankString(
|
||||||
"essid"))
|
wireless.GetWirelessProperty(networkID, "essid"))
|
||||||
self.lbl_strength = GreyLabel()
|
self.lbl_strength = GreyLabel()
|
||||||
self.lbl_encryption = GreyLabel()
|
self.lbl_encryption = GreyLabel()
|
||||||
self.lbl_channel = GreyLabel()
|
self.lbl_channel = GreyLabel()
|
||||||
|
|
||||||
print "ESSID : " + self.essid
|
print "ESSID : " + self.essid
|
||||||
self.chkbox_autoconnect = gtk.CheckButton(_('Automatically connect to this network'))
|
self.chkbox_autoconnect = gtk.CheckButton(
|
||||||
self.chkbox_neverconnect = gtk.CheckButton(_('Never connect to this network'))
|
_('Automatically connect to this network'))
|
||||||
|
self.chkbox_neverconnect = gtk.CheckButton(
|
||||||
|
_('Never connect to this network'))
|
||||||
|
|
||||||
self.set_signal_strength(wireless.GetWirelessProperty(networkID,
|
self.set_signal_strength(
|
||||||
'quality'),
|
wireless.GetWirelessProperty(networkID, 'quality'),
|
||||||
wireless.GetWirelessProperty(networkID,
|
wireless.GetWirelessProperty(networkID, 'strength')
|
||||||
'strength'))
|
)
|
||||||
self.set_encryption(wireless.GetWirelessProperty(networkID,
|
self.set_encryption(
|
||||||
'encryption'),
|
wireless.GetWirelessProperty(networkID, 'encryption'),
|
||||||
wireless.GetWirelessProperty(networkID,
|
wireless.GetWirelessProperty(networkID, 'encryption_method')
|
||||||
'encryption_method'))
|
)
|
||||||
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
|
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
|
||||||
self.name_label.set_use_markup(True)
|
self.name_label.set_use_markup(True)
|
||||||
self.name_label.set_label("<b>%s</b> %s %s %s" % (self._escape(self.essid),
|
self.name_label.set_label(
|
||||||
|
"<b>%s</b> %s %s %s" % (
|
||||||
|
self._escape(self.essid),
|
||||||
self.lbl_strength.get_label(),
|
self.lbl_strength.get_label(),
|
||||||
self.lbl_encryption.get_label(),
|
self.lbl_encryption.get_label(),
|
||||||
self.lbl_channel.get_label(),
|
self.lbl_channel.get_label(),
|
||||||
@@ -961,8 +1056,11 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
def _escape(self, val):
|
def _escape(self, val):
|
||||||
""" Escapes special characters so they're displayed correctly. """
|
""" Escapes special characters so they're displayed correctly. """
|
||||||
return val.replace("&", "&").replace("<", "<").\
|
return val.replace("&", "&"). \
|
||||||
replace(">",">").replace("'", "'").replace('"', """)
|
replace("<", "<"). \
|
||||||
|
replace(">", ">"). \
|
||||||
|
replace("'", "'"). \
|
||||||
|
replace('"', """)
|
||||||
|
|
||||||
def save_wireless_settings(self, networkid):
|
def save_wireless_settings(self, networkid):
|
||||||
""" Save wireless network settings. """
|
""" Save wireless network settings. """
|
||||||
@@ -970,15 +1068,20 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
def update_autoconnect(self, widget=None):
|
def update_autoconnect(self, widget=None):
|
||||||
""" Called when the autoconnect checkbox is toggled. """
|
""" Called when the autoconnect checkbox is toggled. """
|
||||||
wireless.SetWirelessProperty(self.networkID, "automatic",
|
wireless.SetWirelessProperty(
|
||||||
noneToString(self.chkbox_autoconnect.
|
self.networkID,
|
||||||
get_active()))
|
"automatic",
|
||||||
|
noneToString(self.chkbox_autoconnect. get_active())
|
||||||
|
)
|
||||||
wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")
|
wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")
|
||||||
|
|
||||||
def update_neverconnect(self, widget=None):
|
def update_neverconnect(self, widget=None):
|
||||||
""" Called when the neverconnect checkbox is toggled. """
|
""" Called when the neverconnect checkbox is toggled. """
|
||||||
wireless.SetWirelessProperty(self.networkID, "never",
|
wireless.SetWirelessProperty(
|
||||||
noneToString(self.chkbox_neverconnect.get_active()))
|
self.networkID,
|
||||||
|
"never",
|
||||||
|
noneToString(self.chkbox_neverconnect.get_active())
|
||||||
|
)
|
||||||
wireless.SaveWirelessNetworkProperty(self.networkID, "never")
|
wireless.SaveWirelessNetworkProperty(self.networkID, "never")
|
||||||
if self.chkbox_neverconnect.get_active():
|
if self.chkbox_neverconnect.get_active():
|
||||||
self.chkbox_autoconnect.set_sensitive(False)
|
self.chkbox_autoconnect.set_sensitive(False)
|
||||||
@@ -1071,6 +1174,7 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
|
|
||||||
class WirelessInformationDialog(gtk.Dialog):
|
class WirelessInformationDialog(gtk.Dialog):
|
||||||
|
""" Wireless information dialog. """
|
||||||
def __init__(self, networkID, parent):
|
def __init__(self, networkID, parent):
|
||||||
gtk.Dialog.__init__(self, parent=parent)
|
gtk.Dialog.__init__(self, parent=parent)
|
||||||
|
|
||||||
@@ -1088,23 +1192,24 @@ class WirelessInformationDialog(gtk.Dialog):
|
|||||||
self.hbox_status = gtk.HBox(False, 5)
|
self.hbox_status = gtk.HBox(False, 5)
|
||||||
|
|
||||||
# Set the values of the network info labels.
|
# Set the values of the network info labels.
|
||||||
self.set_signal_strength(wireless.GetWirelessProperty(networkID,
|
self.set_signal_strength(
|
||||||
'quality'),
|
wireless.GetWirelessProperty(networkID, 'quality'),
|
||||||
wireless.GetWirelessProperty(networkID,
|
wireless.GetWirelessProperty(networkID, 'strength')
|
||||||
'strength'))
|
)
|
||||||
self.set_mac_address(wireless.GetWirelessProperty(networkID, 'bssid'))
|
self.set_mac_address(wireless.GetWirelessProperty(networkID, 'bssid'))
|
||||||
self.set_mode(wireless.GetWirelessProperty(networkID, 'mode'))
|
self.set_mode(wireless.GetWirelessProperty(networkID, 'mode'))
|
||||||
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
|
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
|
||||||
self.set_encryption(wireless.GetWirelessProperty(networkID,
|
self.set_encryption(
|
||||||
'encryption'),
|
wireless.GetWirelessProperty(networkID, 'encryption'),
|
||||||
wireless.GetWirelessProperty(networkID,
|
wireless.GetWirelessProperty(networkID, 'encryption_method')
|
||||||
'encryption_method'))
|
)
|
||||||
|
|
||||||
self.set_title('Network Information')
|
self.set_title('Network Information')
|
||||||
vbox = self.vbox
|
vbox = self.vbox
|
||||||
self.set_has_separator(False)
|
self.set_has_separator(False)
|
||||||
table = gtk.Table(5, 2)
|
table = gtk.Table(5, 2)
|
||||||
table.set_col_spacings(12)
|
table.set_col_spacings(12)
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
vbox.pack_start(table)
|
vbox.pack_start(table)
|
||||||
|
|
||||||
# Pack the network status HBox.
|
# Pack the network status HBox.
|
||||||
@@ -1123,6 +1228,7 @@ class WirelessInformationDialog(gtk.Dialog):
|
|||||||
table.attach(LeftAlignedLabel('Channel:'), 0, 1, 4, 5)
|
table.attach(LeftAlignedLabel('Channel:'), 0, 1, 4, 5)
|
||||||
table.attach(self.lbl_channel, 1, 2, 4, 5)
|
table.attach(self.lbl_channel, 1, 2, 4, 5)
|
||||||
|
|
||||||
|
# pylint: disable-msg=E1101
|
||||||
vbox.show_all()
|
vbox.show_all()
|
||||||
|
|
||||||
self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
|
self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
|
||||||
|
|||||||
162
gtk/prefs.py
162
gtk/prefs.py
@@ -26,7 +26,6 @@ handles recieving/sendings the settings from/to the daemon.
|
|||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
#import pango
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
@@ -39,22 +38,72 @@ daemon = None
|
|||||||
wireless = None
|
wireless = None
|
||||||
wired = None
|
wired = None
|
||||||
|
|
||||||
from wicd.translations import language
|
|
||||||
|
|
||||||
USER_SETTINGS_DIR = os.path.expanduser('~/.wicd/')
|
USER_SETTINGS_DIR = os.path.expanduser('~/.wicd/')
|
||||||
|
|
||||||
|
|
||||||
def setup_dbus():
|
def setup_dbus():
|
||||||
|
""" Initialize DBus. """
|
||||||
global daemon, wireless, wired
|
global daemon, wireless, wired
|
||||||
daemon = dbusmanager.get_interface('daemon')
|
daemon = dbusmanager.get_interface('daemon')
|
||||||
wireless = dbusmanager.get_interface('wireless')
|
wireless = dbusmanager.get_interface('wireless')
|
||||||
wired = dbusmanager.get_interface('wired')
|
wired = dbusmanager.get_interface('wired')
|
||||||
|
|
||||||
|
|
||||||
class PreferencesDialog(object):
|
class PreferencesDialog(object):
|
||||||
""" Class for handling the wicd preferences dialog window. """
|
""" Class for handling the wicd preferences dialog window. """
|
||||||
def __init__(self, parent, wTree):
|
def __init__(self, parent, wTree):
|
||||||
setup_dbus()
|
setup_dbus()
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.wTree = wTree
|
self.wTree = wTree
|
||||||
|
|
||||||
|
self.ethtoolradio = None
|
||||||
|
self.miitoolradio = None
|
||||||
|
|
||||||
|
self.wpadrivercombo = None
|
||||||
|
self.wpadrivers = None
|
||||||
|
self.backends = None
|
||||||
|
self.backendcombo = None
|
||||||
|
self.be_descriptions = None
|
||||||
|
self.preferwiredcheckbox = None
|
||||||
|
self.useGlobalDNSCheckbox = None
|
||||||
|
self.displaytypecheckbox = None
|
||||||
|
self.verifyapcheckbox = None
|
||||||
|
self.debugmodecheckbox = None
|
||||||
|
self.wiredcheckbox = None
|
||||||
|
self.showneverconnectcheckbox = None
|
||||||
|
self.reconnectcheckbox = None
|
||||||
|
self.notificationscheckbox = None
|
||||||
|
|
||||||
|
self.usedefaultradiobutton = None
|
||||||
|
self.lastusedradiobutton = None
|
||||||
|
self.showlistradiobutton = None
|
||||||
|
|
||||||
|
self.kdesuradio = None
|
||||||
|
self.gksudoradio = None
|
||||||
|
self.sudoautoradio = None
|
||||||
|
self.ktsussradio = None
|
||||||
|
|
||||||
|
self.dhclientradio = None
|
||||||
|
self.dhcpautoradio = None
|
||||||
|
self.pumpradio = None
|
||||||
|
self.udhcpcradio = None
|
||||||
|
self.dhcpcdradio = None
|
||||||
|
|
||||||
|
self.linkautoradio = None
|
||||||
|
self.routeflushradio = None
|
||||||
|
self.ipflushradio = None
|
||||||
|
self.flushautoradio = None
|
||||||
|
|
||||||
|
self.dialog = None
|
||||||
|
self.entryWiredInterface = None
|
||||||
|
self.entryWirelessInterface = None
|
||||||
|
|
||||||
|
self.dns1Entry = None
|
||||||
|
self.dns2Entry = None
|
||||||
|
self.dns3Entry = None
|
||||||
|
self.searchDomEntry = None
|
||||||
|
self.dnsDomEntry = None
|
||||||
|
|
||||||
self.prep_settings_diag()
|
self.prep_settings_diag()
|
||||||
self.load_preferences_diag()
|
self.load_preferences_diag()
|
||||||
|
|
||||||
@@ -85,24 +134,26 @@ class PreferencesDialog(object):
|
|||||||
|
|
||||||
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
||||||
self.pumpradio, self.udhcpcradio]
|
self.pumpradio, self.udhcpcradio]
|
||||||
self._setup_external_app_radios(dhcp_list, daemon.GetDHCPClient,
|
self._setup_external_app_radios(
|
||||||
daemon.SetDHCPClient)
|
dhcp_list, daemon.GetDHCPClient, daemon.SetDHCPClient)
|
||||||
|
|
||||||
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
||||||
self.miitoolradio]
|
self.miitoolradio]
|
||||||
self._setup_external_app_radios(wired_link_list,
|
self._setup_external_app_radios(
|
||||||
|
wired_link_list,
|
||||||
daemon.GetLinkDetectionTool,
|
daemon.GetLinkDetectionTool,
|
||||||
daemon.SetLinkDetectionTool)
|
daemon.SetLinkDetectionTool
|
||||||
|
)
|
||||||
|
|
||||||
flush_list = [self.flushautoradio, self.ipflushradio,
|
flush_list = [self.flushautoradio, self.ipflushradio,
|
||||||
self.routeflushradio]
|
self.routeflushradio]
|
||||||
self._setup_external_app_radios(flush_list, daemon.GetFlushTool,
|
self._setup_external_app_radios(
|
||||||
daemon.SetFlushTool)
|
flush_list, daemon.GetFlushTool, daemon.SetFlushTool)
|
||||||
|
|
||||||
sudo_list = [self.sudoautoradio, self.gksudoradio, self.kdesuradio,
|
sudo_list = [self.sudoautoradio, self.gksudoradio, self.kdesuradio,
|
||||||
self.ktsussradio]
|
self.ktsussradio]
|
||||||
self._setup_external_app_radios(sudo_list, daemon.GetSudoApp,
|
self._setup_external_app_radios(
|
||||||
daemon.SetSudoApp)
|
sudo_list, daemon.GetSudoApp, daemon.SetSudoApp)
|
||||||
|
|
||||||
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
|
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
|
||||||
if auto_conn_meth == 1:
|
if auto_conn_meth == 1:
|
||||||
@@ -121,10 +172,14 @@ class PreferencesDialog(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
self.wpadrivercombo.set_active(0)
|
self.wpadrivercombo.set_active(0)
|
||||||
|
|
||||||
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
|
self.useGlobalDNSCheckbox.connect(
|
||||||
(self.dns1Entry, self.dns2Entry,
|
"toggled",
|
||||||
self.dns3Entry, self.dnsDomEntry,
|
checkboxTextboxToggle,
|
||||||
self.searchDomEntry))
|
(
|
||||||
|
self.dns1Entry, self.dns2Entry, self.dns3Entry,
|
||||||
|
self.dnsDomEntry, self.searchDomEntry
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
dns_addresses = daemon.GetGlobalDNSAddresses()
|
dns_addresses = daemon.GetGlobalDNSAddresses()
|
||||||
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
||||||
@@ -176,6 +231,7 @@ class PreferencesDialog(object):
|
|||||||
self.dialog.hide()
|
self.dialog.hide()
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
|
""" Destroy dialog. """
|
||||||
self.dialog.destroy()
|
self.dialog.destroy()
|
||||||
|
|
||||||
def show_all(self):
|
def show_all(self):
|
||||||
@@ -189,9 +245,13 @@ class PreferencesDialog(object):
|
|||||||
for i in [self.dns1Entry, self.dns2Entry, self.dns3Entry,
|
for i in [self.dns1Entry, self.dns2Entry, self.dns3Entry,
|
||||||
self.dnsDomEntry, self.searchDomEntry]:
|
self.dnsDomEntry, self.searchDomEntry]:
|
||||||
i.set_text(i.get_text().strip())
|
i.set_text(i.get_text().strip())
|
||||||
daemon.SetGlobalDNS(self.dns1Entry.get_text(), self.dns2Entry.get_text(),
|
daemon.SetGlobalDNS(
|
||||||
self.dns3Entry.get_text(), self.dnsDomEntry.get_text(),
|
self.dns1Entry.get_text(),
|
||||||
self.searchDomEntry.get_text())
|
self.dns2Entry.get_text(),
|
||||||
|
self.dns3Entry.get_text(),
|
||||||
|
self.dnsDomEntry.get_text(),
|
||||||
|
self.searchDomEntry.get_text()
|
||||||
|
)
|
||||||
daemon.SetWirelessInterface(self.entryWirelessInterface.get_text())
|
daemon.SetWirelessInterface(self.entryWirelessInterface.get_text())
|
||||||
daemon.SetWiredInterface(self.entryWiredInterface.get_text())
|
daemon.SetWiredInterface(self.entryWiredInterface.get_text())
|
||||||
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
|
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
|
||||||
@@ -200,8 +260,10 @@ class PreferencesDialog(object):
|
|||||||
daemon.SetDebugMode(self.debugmodecheckbox.get_active())
|
daemon.SetDebugMode(self.debugmodecheckbox.get_active())
|
||||||
daemon.SetSignalDisplayType(int(self.displaytypecheckbox.get_active()))
|
daemon.SetSignalDisplayType(int(self.displaytypecheckbox.get_active()))
|
||||||
daemon.SetShouldVerifyAp(bool(self.verifyapcheckbox.get_active()))
|
daemon.SetShouldVerifyAp(bool(self.verifyapcheckbox.get_active()))
|
||||||
daemon.SetPreferWiredNetwork(bool(self.preferwiredcheckbox.get_active()))
|
daemon.SetPreferWiredNetwork(
|
||||||
daemon.SetShowNeverConnect(bool(self.showneverconnectcheckbox.get_active()))
|
bool(self.preferwiredcheckbox.get_active()))
|
||||||
|
daemon.SetShowNeverConnect(
|
||||||
|
bool(self.showneverconnectcheckbox.get_active()))
|
||||||
if self.showlistradiobutton.get_active():
|
if self.showlistradiobutton.get_active():
|
||||||
daemon.SetWiredAutoConnectMethod(2)
|
daemon.SetWiredAutoConnectMethod(2)
|
||||||
elif self.lastusedradiobutton.get_active():
|
elif self.lastusedradiobutton.get_active():
|
||||||
@@ -317,46 +379,65 @@ class PreferencesDialog(object):
|
|||||||
self.dialog = self.wTree.get_object("pref_dialog")
|
self.dialog = self.wTree.get_object("pref_dialog")
|
||||||
self.dialog.set_title(_('Preferences'))
|
self.dialog.set_title(_('Preferences'))
|
||||||
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
||||||
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
self.dialog.set_icon_from_file(
|
||||||
|
os.path.join(wpath.images, "wicd.png"))
|
||||||
width = int(gtk.gdk.screen_width() / 2.4)
|
width = int(gtk.gdk.screen_width() / 2.4)
|
||||||
if width > 450:
|
if width > 450:
|
||||||
width = 450
|
width = 450
|
||||||
self.dialog.resize(width, int(gtk.gdk.screen_height() / 2))
|
self.dialog.resize(width, int(gtk.gdk.screen_height() / 2))
|
||||||
|
|
||||||
self.wiredcheckbox = setup_label("pref_always_check", _('''Always show wired interface'''))
|
self.wiredcheckbox = setup_label(
|
||||||
|
"pref_always_check",
|
||||||
|
_('''Always show wired interface''')
|
||||||
|
)
|
||||||
self.preferwiredcheckbox = setup_label("pref_prefer_wired_check",
|
self.preferwiredcheckbox = setup_label("pref_prefer_wired_check",
|
||||||
"prefer_wired")
|
"prefer_wired")
|
||||||
|
|
||||||
self.reconnectcheckbox = setup_label("pref_auto_check",
|
self.reconnectcheckbox = setup_label("pref_auto_check",
|
||||||
_('Automatically reconnect on connection loss'))
|
_('Automatically reconnect on connection loss'))
|
||||||
self.showneverconnectcheckbox = setup_label("pref_show_never_connect_check",
|
self.showneverconnectcheckbox = setup_label(
|
||||||
_('Show never connect networks'))
|
"pref_show_never_connect_check",
|
||||||
|
_('Show never connect networks')
|
||||||
|
)
|
||||||
self.debugmodecheckbox = setup_label("pref_debug_check",
|
self.debugmodecheckbox = setup_label("pref_debug_check",
|
||||||
_('Enable debug mode'))
|
_('Enable debug mode'))
|
||||||
self.displaytypecheckbox = setup_label("pref_dbm_check",
|
self.displaytypecheckbox = setup_label(
|
||||||
_('Use dBm to measure signal strength'))
|
"pref_dbm_check",
|
||||||
self.verifyapcheckbox = setup_label("pref_verify_ap_check",
|
_('Use dBm to measure signal strength')
|
||||||
_('Ping static gateways after connecting to verify association'))
|
)
|
||||||
self.usedefaultradiobutton = setup_label("pref_use_def_radio",
|
self.verifyapcheckbox = setup_label(
|
||||||
_('Use default profile on wired autoconnect'))
|
"pref_verify_ap_check",
|
||||||
self.showlistradiobutton = setup_label("pref_prompt_radio",
|
_('Ping static gateways after connecting to verify association')
|
||||||
_('Prompt for profile on wired autoconnect'))
|
)
|
||||||
self.lastusedradiobutton = setup_label("pref_use_last_radio",
|
self.usedefaultradiobutton = setup_label(
|
||||||
_('Use last used profile on wired autoconnect'))
|
"pref_use_def_radio",
|
||||||
|
_('Use default profile on wired autoconnect')
|
||||||
|
)
|
||||||
|
self.showlistradiobutton = setup_label(
|
||||||
|
"pref_prompt_radio",
|
||||||
|
_('Prompt for profile on wired autoconnect')
|
||||||
|
)
|
||||||
|
self.lastusedradiobutton = setup_label(
|
||||||
|
"pref_use_last_radio",
|
||||||
|
_('Use last used profile on wired autoconnect')
|
||||||
|
)
|
||||||
|
|
||||||
|
self.notificationscheckbox = setup_label(
|
||||||
self.notificationscheckbox = setup_label("pref_use_libnotify",
|
"pref_use_libnotify",
|
||||||
_('Display notifications about connection status'))
|
_('Display notifications about connection status')
|
||||||
|
)
|
||||||
|
|
||||||
# DHCP Clients
|
# DHCP Clients
|
||||||
self.dhcpautoradio = setup_label("dhcp_auto_radio", _('Automatic (recommended)'))
|
self.dhcpautoradio = setup_label(
|
||||||
|
"dhcp_auto_radio", _('Automatic (recommended)'))
|
||||||
self.dhclientradio = self.wTree.get_object("dhclient_radio")
|
self.dhclientradio = self.wTree.get_object("dhclient_radio")
|
||||||
self.pumpradio = self.wTree.get_object("pump_radio")
|
self.pumpradio = self.wTree.get_object("pump_radio")
|
||||||
self.dhcpcdradio = self.wTree.get_object("dhcpcd_radio")
|
self.dhcpcdradio = self.wTree.get_object("dhcpcd_radio")
|
||||||
self.udhcpcradio = self.wTree.get_object("udhcpc_radio")
|
self.udhcpcradio = self.wTree.get_object("udhcpc_radio")
|
||||||
|
|
||||||
# Wired Link Detection Apps
|
# Wired Link Detection Apps
|
||||||
self.linkautoradio = setup_label("link_auto_radio", _('Automatic (recommended)'))
|
self.linkautoradio = setup_label(
|
||||||
|
"link_auto_radio", _('Automatic (recommended)'))
|
||||||
self.linkautoradio = setup_label("link_auto_radio")
|
self.linkautoradio = setup_label("link_auto_radio")
|
||||||
self.ethtoolradio = setup_label("ethtool_radio")
|
self.ethtoolradio = setup_label("ethtool_radio")
|
||||||
self.miitoolradio = setup_label("miitool_radio")
|
self.miitoolradio = setup_label("miitool_radio")
|
||||||
@@ -368,7 +449,8 @@ class PreferencesDialog(object):
|
|||||||
self.routeflushradio = setup_label("route_flush_radio")
|
self.routeflushradio = setup_label("route_flush_radio")
|
||||||
|
|
||||||
# Graphical Sudo Apps
|
# Graphical Sudo Apps
|
||||||
self.sudoautoradio = setup_label("sudo_auto_radio", _('Automatic (recommended)'))
|
self.sudoautoradio = setup_label(
|
||||||
|
"sudo_auto_radio", _('Automatic (recommended)'))
|
||||||
self.gksudoradio = setup_label("gksudo_radio")
|
self.gksudoradio = setup_label("gksudo_radio")
|
||||||
self.kdesuradio = setup_label("kdesu_radio")
|
self.kdesuradio = setup_label("kdesu_radio")
|
||||||
self.ktsussradio = setup_label("ktsuss_radio")
|
self.ktsussradio = setup_label("ktsuss_radio")
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import gobject
|
|||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
import pango
|
import pango
|
||||||
import time
|
|
||||||
import atexit
|
import atexit
|
||||||
from dbus import DBusException
|
from dbus import DBusException
|
||||||
|
|
||||||
@@ -74,7 +73,8 @@ if not hasattr(gtk, "StatusIcon"):
|
|||||||
import egg.trayicon
|
import egg.trayicon
|
||||||
USE_EGG = True
|
USE_EGG = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
|
print 'Unable to load tray icon: Missing both egg.trayicon and ' + \
|
||||||
|
'gtk.StatusIcon modules.'
|
||||||
ICON_AVAIL = False
|
ICON_AVAIL = False
|
||||||
|
|
||||||
misc.RenameProcess("wicd-client")
|
misc.RenameProcess("wicd-client")
|
||||||
@@ -88,13 +88,22 @@ DBUS_AVAIL = False
|
|||||||
theme = gtk.icon_theme_get_default()
|
theme = gtk.icon_theme_get_default()
|
||||||
theme.append_search_path(wpath.images)
|
theme.append_search_path(wpath.images)
|
||||||
|
|
||||||
|
|
||||||
def catchdbus(func):
|
def catchdbus(func):
|
||||||
|
""" Decorator to catch DBus exceptions. """
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except DBusException, e:
|
except DBusException, e:
|
||||||
if e.get_dbus_name() != None and "DBus.Error.AccessDenied" in e.get_dbus_name():
|
if e.get_dbus_name() is not None and \
|
||||||
error(None, _('Unable to contact the Wicd daemon due to an access denied error from DBus. Please check that your user is in the $A group.').replace("$A","<b>"+wpath.wicd_group+"</b>"))
|
"DBus.Error.AccessDenied" in e.get_dbus_name():
|
||||||
|
error(
|
||||||
|
None,
|
||||||
|
_('Unable to contact the Wicd daemon due to an access '
|
||||||
|
'denied error from DBus. Please check that your user is '
|
||||||
|
'in the $A group.').
|
||||||
|
replace("$A", "<b>" + wpath.wicd_group + "</b>")
|
||||||
|
)
|
||||||
#raise
|
#raise
|
||||||
raise DBusException(e)
|
raise DBusException(e)
|
||||||
else:
|
else:
|
||||||
@@ -108,6 +117,7 @@ def catchdbus(func):
|
|||||||
|
|
||||||
|
|
||||||
class NetworkMenuItem(gtk.ImageMenuItem):
|
class NetworkMenuItem(gtk.ImageMenuItem):
|
||||||
|
""" Network menu item. """
|
||||||
def __init__(self, lbl, is_active=False):
|
def __init__(self, lbl, is_active=False):
|
||||||
gtk.ImageMenuItem.__init__(self)
|
gtk.ImageMenuItem.__init__(self)
|
||||||
self.label = gtk.Label(lbl)
|
self.label = gtk.Label(lbl)
|
||||||
@@ -150,7 +160,7 @@ class TrayIcon(object):
|
|||||||
if USE_EGG:
|
if USE_EGG:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
else:
|
else:
|
||||||
return self.tr.is_embedded()
|
return self.tr.is_embedded() # pylint: disable-msg=E1103
|
||||||
|
|
||||||
def get_bandwidth_bytes(self):
|
def get_bandwidth_bytes(self):
|
||||||
""" Gets the amount of byte sent sine the last time I checked """
|
""" Gets the amount of byte sent sine the last time I checked """
|
||||||
@@ -163,9 +173,11 @@ class TrayIcon(object):
|
|||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur_rcvbytes = int(open(dev_dir + "rx_bytes", "r").read().strip())
|
self.cur_rcvbytes = int(
|
||||||
self.cur_sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip())
|
open(dev_dir + "rx_bytes", "r").read().strip())
|
||||||
except:
|
self.cur_sndbytes = int(
|
||||||
|
open(dev_dir + "tx_bytes", "r").read().strip())
|
||||||
|
except (IOError, OSError, ValueError):
|
||||||
self.cur_sndbytes = -1
|
self.cur_sndbytes = -1
|
||||||
self.cur_rcvbytes = -1
|
self.cur_rcvbytes = -1
|
||||||
|
|
||||||
@@ -234,8 +246,8 @@ class TrayIcon(object):
|
|||||||
if self.should_notify:
|
if self.should_notify:
|
||||||
try:
|
try:
|
||||||
if not self._last_bubble:
|
if not self._last_bubble:
|
||||||
self._last_bubble = pynotify.Notification(title, details,
|
self._last_bubble = pynotify.Notification(
|
||||||
image)
|
title, details, image)
|
||||||
self._last_bubble.show()
|
self._last_bubble.show()
|
||||||
else:
|
else:
|
||||||
self._last_bubble.clear_actions()
|
self._last_bubble.clear_actions()
|
||||||
@@ -265,8 +277,8 @@ class TrayIcon(object):
|
|||||||
self.network_addr = str(info[0])
|
self.network_addr = str(info[0])
|
||||||
self.network_type = "wired"
|
self.network_type = "wired"
|
||||||
self.tr.set_from_name('wired')
|
self.tr.set_from_name('wired')
|
||||||
# status_string = _('Connected to wired network (IP: $A)').replace('$A',
|
#status_string = _('Connected to wired network (IP: $A)'). \
|
||||||
#wired_ip)
|
# replace('$A',wired_ip)
|
||||||
#self.tr.set_tooltip(status_string)
|
#self.tr.set_tooltip(status_string)
|
||||||
self._show_notification(_('Wired Network'),
|
self._show_notification(_('Wired Network'),
|
||||||
_('Connection established'),
|
_('Connection established'),
|
||||||
@@ -302,7 +314,6 @@ class TrayIcon(object):
|
|||||||
_('Connection established'),
|
_('Connection established'),
|
||||||
'network-wireless')
|
'network-wireless')
|
||||||
|
|
||||||
|
|
||||||
self.update_tooltip()
|
self.update_tooltip()
|
||||||
|
|
||||||
def set_connecting_state(self, info):
|
def set_connecting_state(self, info):
|
||||||
@@ -327,7 +338,6 @@ class TrayIcon(object):
|
|||||||
_('Establishing connection...'),
|
_('Establishing connection...'),
|
||||||
'network-wireless')
|
'network-wireless')
|
||||||
|
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def set_not_connected_state(self, info=None):
|
def set_not_connected_state(self, info=None):
|
||||||
""" Set the icon info for the not connected state. """
|
""" Set the icon info for the not connected state. """
|
||||||
@@ -346,7 +356,8 @@ class TrayIcon(object):
|
|||||||
@catchdbus
|
@catchdbus
|
||||||
def update_tray_icon(self, state=None, info=None):
|
def update_tray_icon(self, state=None, info=None):
|
||||||
""" Updates the tray icon and current connection status. """
|
""" Updates the tray icon and current connection status. """
|
||||||
if not DBUS_AVAIL: return False
|
if not DBUS_AVAIL:
|
||||||
|
return False
|
||||||
|
|
||||||
if not state or not info:
|
if not state or not info:
|
||||||
[state, info] = daemon.GetConnectionStatus()
|
[state, info] = daemon.GetConnectionStatus()
|
||||||
@@ -473,7 +484,6 @@ class TrayIcon(object):
|
|||||||
max_gain = gain
|
max_gain = gain
|
||||||
return (active, max_gain, last_bytes)
|
return (active, max_gain, last_bytes)
|
||||||
|
|
||||||
|
|
||||||
class TrayIconGUI(object):
|
class TrayIconGUI(object):
|
||||||
""" Base Tray Icon UI class.
|
""" Base Tray Icon UI class.
|
||||||
|
|
||||||
@@ -482,6 +492,10 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
self.list = []
|
||||||
|
self.label = None
|
||||||
|
self.data = None
|
||||||
|
|
||||||
menu = """
|
menu = """
|
||||||
<ui>
|
<ui>
|
||||||
<menubar name="Menubar">
|
<menubar name="Menubar">
|
||||||
@@ -501,8 +515,8 @@ class TrayIcon(object):
|
|||||||
('Info', gtk.STOCK_INFO, _('_Connection Info'), None,
|
('Info', gtk.STOCK_INFO, _('_Connection Info'), None,
|
||||||
_('Information about the current connection'),
|
_('Information about the current connection'),
|
||||||
self.on_conn_info),
|
self.on_conn_info),
|
||||||
('Quit',gtk.STOCK_QUIT,_('_Quit'),None,_('Quit wicd-tray-icon'),
|
('Quit', gtk.STOCK_QUIT, _('_Quit'), None,
|
||||||
self.on_quit),
|
_('Quit wicd-tray-icon'), self.on_quit),
|
||||||
]
|
]
|
||||||
actg = gtk.ActionGroup('Actions')
|
actg = gtk.ActionGroup('Actions')
|
||||||
actg.add_actions(actions)
|
actg.add_actions(actions)
|
||||||
@@ -524,13 +538,15 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def tray_scan_started(self):
|
def tray_scan_started(self):
|
||||||
""" Callback for when a wireless scan is started. """
|
""" Callback for when a wireless scan is started. """
|
||||||
if not DBUS_AVAIL: return
|
if not DBUS_AVAIL:
|
||||||
|
return
|
||||||
self._is_scanning = True
|
self._is_scanning = True
|
||||||
self.init_network_menu()
|
self.init_network_menu()
|
||||||
|
|
||||||
def tray_scan_ended(self):
|
def tray_scan_ended(self):
|
||||||
""" Callback for when a wireless scan finishes. """
|
""" Callback for when a wireless scan finishes. """
|
||||||
if not DBUS_AVAIL: return
|
if not DBUS_AVAIL:
|
||||||
|
return
|
||||||
self._is_scanning = False
|
self._is_scanning = False
|
||||||
self.populate_network_menu()
|
self.populate_network_menu()
|
||||||
|
|
||||||
@@ -539,7 +555,9 @@ class TrayIcon(object):
|
|||||||
if DBUS_AVAIL:
|
if DBUS_AVAIL:
|
||||||
self.toggle_wicd_gui()
|
self.toggle_wicd_gui()
|
||||||
else:
|
else:
|
||||||
# error(None, _('The wicd daemon is unavailable, so your request cannot be completed'))
|
#error(None,
|
||||||
|
#_('The wicd daemon is unavailable, so your request '
|
||||||
|
# 'cannot be completed'))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_quit(self, widget=None):
|
def on_quit(self, widget=None):
|
||||||
@@ -558,7 +576,12 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def on_conn_info(self, data=None):
|
def on_conn_info(self, data=None):
|
||||||
""" Opens the Connection Information Dialog """
|
""" Opens the Connection Information Dialog """
|
||||||
window = gtk.Dialog("Wicd Connection Info", None, 0, (gtk.STOCK_OK, gtk.RESPONSE_CLOSE))
|
window = gtk.Dialog(
|
||||||
|
"Wicd Connection Info",
|
||||||
|
None,
|
||||||
|
0,
|
||||||
|
(gtk.STOCK_OK, gtk.RESPONSE_CLOSE)
|
||||||
|
)
|
||||||
|
|
||||||
# Create labels
|
# Create labels
|
||||||
self.label = gtk.Label()
|
self.label = gtk.Label()
|
||||||
@@ -592,7 +615,7 @@ class TrayIcon(object):
|
|||||||
window.destroy()
|
window.destroy()
|
||||||
self.cont = 'Stop'
|
self.cont = 'Stop'
|
||||||
|
|
||||||
def update_conn_info_win(self, list):
|
def update_conn_info_win(self, l):
|
||||||
""" Updates the information in the connection summary window """
|
""" Updates the information in the connection summary window """
|
||||||
if (self.cont == "Stop"):
|
if (self.cont == "Stop"):
|
||||||
return False
|
return False
|
||||||
@@ -618,7 +641,8 @@ $F KB/s''')
|
|||||||
.replace('$A', str(info[1])) # SSID
|
.replace('$A', str(info[1])) # SSID
|
||||||
.replace('$B', str(info[4])) # Speed
|
.replace('$B', str(info[4])) # Speed
|
||||||
.replace('$C', str(info[0])) # IP
|
.replace('$C', str(info[0])) # IP
|
||||||
.replace('$D', daemon.FormatSignalForPrinting(str(info[2])))
|
.replace('$D',
|
||||||
|
daemon.FormatSignalForPrinting(str(info[2])))
|
||||||
.replace('$E', str(rx))
|
.replace('$E', str(rx))
|
||||||
.replace('$F', str(tx)))
|
.replace('$F', str(tx)))
|
||||||
else:
|
else:
|
||||||
@@ -734,7 +758,8 @@ TX:'''))
|
|||||||
mousing past the menu to select another menu item.
|
mousing past the menu to select another menu item.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def dummy(x=None): pass
|
def dummy(x=None):
|
||||||
|
pass
|
||||||
|
|
||||||
if self._is_scanning:
|
if self._is_scanning:
|
||||||
return True
|
return True
|
||||||
@@ -784,7 +809,9 @@ TX:'''))
|
|||||||
if num_networks > 0:
|
if num_networks > 0:
|
||||||
skip_never_connect = not daemon.GetShowNeverConnect()
|
skip_never_connect = not daemon.GetShowNeverConnect()
|
||||||
for x in xrange(0, num_networks):
|
for x in xrange(0, num_networks):
|
||||||
if skip_never_connect and misc.to_bool(get_prop(x,"never")): continue
|
if skip_never_connect and \
|
||||||
|
misc.to_bool(get_prop(x,"never")):
|
||||||
|
continue
|
||||||
essid = get_prop(x, "essid")
|
essid = get_prop(x, "essid")
|
||||||
if status == misc.WIRELESS and info[1] == essid:
|
if status == misc.WIRELESS and info[1] == essid:
|
||||||
is_active = True
|
is_active = True
|
||||||
@@ -829,7 +856,6 @@ TX:'''))
|
|||||||
self.gui_win.exit()
|
self.gui_win.exit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if USE_EGG:
|
if USE_EGG:
|
||||||
class EggTrayIconGUI(TrayIconGUI):
|
class EggTrayIconGUI(TrayIconGUI):
|
||||||
""" Tray Icon for gtk < 2.10.
|
""" Tray Icon for gtk < 2.10.
|
||||||
@@ -864,7 +890,11 @@ TX:'''))
|
|||||||
|
|
||||||
def set_from_file(self, val=None):
|
def set_from_file(self, val=None):
|
||||||
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
||||||
self.pic.set_from_file(os.path.join(wpath.images, 'hicolor/22x22/status/%s.png' % val))
|
self.pic.set_from_file(
|
||||||
|
os.path.join(
|
||||||
|
wpath.images, 'hicolor/22x22/status/%s.png' % val
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def set_tooltip(self, val):
|
def set_tooltip(self, val):
|
||||||
""" Set the tooltip for this tray icon.
|
""" Set the tooltip for this tray icon.
|
||||||
@@ -887,7 +917,6 @@ TX:'''))
|
|||||||
else:
|
else:
|
||||||
self.tray.hide_all()
|
self.tray.hide_all()
|
||||||
|
|
||||||
|
|
||||||
if hasattr(gtk, "StatusIcon"):
|
if hasattr(gtk, "StatusIcon"):
|
||||||
class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
|
class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
|
||||||
""" Class for creating the wicd tray icon on gtk > 2.10.
|
""" Class for creating the wicd tray icon on gtk > 2.10.
|
||||||
@@ -941,19 +970,25 @@ Arguments:
|
|||||||
\t-o\t--only-notifications\tDon't display anything except notifications.
|
\t-o\t--only-notifications\tDon't display anything except notifications.
|
||||||
""" % wpath.version
|
""" % wpath.version
|
||||||
|
|
||||||
|
|
||||||
def setup_dbus(force=True):
|
def setup_dbus(force=True):
|
||||||
|
""" Initialize DBus. """
|
||||||
global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
|
global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
|
||||||
print "Connecting to daemon..."
|
print "Connecting to daemon..."
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
if force:
|
if force:
|
||||||
print "Can't connect to the daemon, trying to start it automatically..."
|
print "Can't connect to the daemon, trying to start it " + \
|
||||||
|
"automatically..."
|
||||||
misc.PromptToStartDaemon()
|
misc.PromptToStartDaemon()
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
error(None, _("Could not connect to wicd's D-Bus interface. Check the wicd log for error messages."))
|
error(None,
|
||||||
|
_("Could not connect to wicd's D-Bus interface. Check "
|
||||||
|
"the wicd log for error messages.")
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@@ -969,23 +1004,32 @@ def setup_dbus(force=True):
|
|||||||
print "Connected."
|
print "Connected."
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def on_exit():
|
def on_exit():
|
||||||
|
""" Handle GUI exit. """
|
||||||
if DBUS_AVAIL:
|
if DBUS_AVAIL:
|
||||||
try:
|
try:
|
||||||
daemon.SetGUIOpen(False)
|
daemon.SetGUIOpen(False)
|
||||||
except DBusException:
|
except DBusException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def handle_no_dbus():
|
def handle_no_dbus():
|
||||||
""" Called when dbus announces its shutting down. """
|
""" Called when dbus announces its shutting down. """
|
||||||
global DBUS_AVAIL, lost_dbus_id
|
global DBUS_AVAIL, lost_dbus_id
|
||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
gui.handle_no_dbus(from_tray=True)
|
gui.handle_no_dbus(from_tray=True)
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
lost_dbus_id = misc.timeout_add(5, lambda:error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'),
|
lost_dbus_id = misc.timeout_add(5,
|
||||||
block=False))
|
lambda: error(None,
|
||||||
|
_('The wicd daemon has shut down. The UI will not function '
|
||||||
|
'properly until it is restarted.'),
|
||||||
|
block=False
|
||||||
|
)
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def main(argv):
|
def main(argv):
|
||||||
""" The main frontend program.
|
""" The main frontend program.
|
||||||
@@ -995,10 +1039,11 @@ def main(argv):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'tnhao', ['help', 'no-tray',
|
opts, args = getopt.getopt(
|
||||||
'tray',
|
sys.argv[1:],
|
||||||
'no-animate',
|
'tnhao',
|
||||||
'only-notifications'])
|
['help', 'no-tray', 'tray', 'no-animate', 'only-notifications']
|
||||||
|
)
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
# Print help information and exit
|
# Print help information and exit
|
||||||
usage()
|
usage()
|
||||||
@@ -1030,7 +1075,7 @@ def main(argv):
|
|||||||
atexit.register(on_exit)
|
atexit.register(on_exit)
|
||||||
|
|
||||||
if display_app and not use_tray or not ICON_AVAIL:
|
if display_app and not use_tray or not ICON_AVAIL:
|
||||||
the_gui = gui.appGui(standalone=True)
|
gui.appGui(standalone=True)
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@@ -1053,9 +1098,13 @@ def main(argv):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
||||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(lambda: (handle_no_dbus() or
|
bus.add_signal_receiver(
|
||||||
tray_icon.icon_info.set_not_connected_state()),
|
lambda: (
|
||||||
"DaemonClosing", 'org.wicd.daemon')
|
handle_no_dbus() or tray_icon.icon_info.set_not_connected_state()
|
||||||
|
),
|
||||||
|
"DaemonClosing",
|
||||||
|
'org.wicd.daemon'
|
||||||
|
)
|
||||||
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
||||||
"org.wicd.daemon")
|
"org.wicd.daemon")
|
||||||
print 'Done loading.'
|
print 'Done loading.'
|
||||||
|
|||||||
Reference in New Issue
Block a user