1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 20:38:00 +01:00

Wired network control support is now more-or-less complete

curses/curses_misc.py:
  Made set_focus() actually set the focus
  Added ability for combobox to rebuild itself
curses/netentry_curses:
    Added WiredSettingsDialog.  Sometimes, the "Defaultness" of the network
      takes a little while to show up in the dialog.  Don't know why yet.
    Reorganized some of the AdvancedSettingsDialog code
curses/wicd-curses.py:
    Reactivated WiredComboBox
    Added support for WiredSettingsDialog
    Added ability to create and delete wired network profiles
    Fixed bug where the program could crash on the end of scanning networks if
      timing is slightly off
    Display the screen locker immediately after initiating a scan
curses/README,TODO: Wired network support is complete
in/man=wicd-curses.8.in:
  Wired network support is now complete
  Added revision information to the bottom of the man page
This commit is contained in:
Andrew Psaltis
2009-01-17 15:13:53 -05:00
parent bb0d43c222
commit be30004f0f
7 changed files with 167 additions and 67 deletions

View File

@@ -22,11 +22,11 @@ D : disconnect from all active networks
ESC : if connecting to a network, stop doing so ESC : if connecting to a network, stop doing so
ENTER : Attempt connection to selected network ENTER : Attempt connection to selected network
P : Display preferences dialog P : Display preferences dialog
C : Display network configuration for selected network (only works for C : Display network configuration for selected network
wireless at the moment)
A : Display "About" dialog A : Display "About" dialog
I : Raise the "Scan for hidden networks" dialog I : Raise the "Scan for hidden networks" dialog
H : Raise help dialog H : Raise help dialog
delete : Delete selected wired network profile (from the wired ComboBox)
IN DIALOGS (Meta usually is "Alt"): IN DIALOGS (Meta usually is "Alt"):
ESC or Q: Quit dialog without saving information (if present) ESC or Q: Quit dialog without saving information (if present)

View File

@@ -1,6 +1,5 @@
Things to do (in no particular order): Things to do (in no particular order):
* Make a network config dialog for wired interfaces
* Implement a keyhandler function for the overall frame * Implement a keyhandler function for the overall frame
* Make keystrokes customizable * Make keystrokes customizable
* Make color schemes customizable * Make color schemes customizable

View File

@@ -295,17 +295,28 @@ class ComboBox(urwid.WidgetWrap):
self.use_enter = use_enter self.use_enter = use_enter
# The Focus # The Focus
self.focus = focus self.focus = focus
# The callback and friends # The callback and friends
self.callback = callback self.callback = callback
self.user_args = user_args self.user_args = user_args
# Widget references to simplify some things
self.body = None
self.ui = None
self.row = None
def set_list(self,list): def set_list(self,list):
self.list = list self.list = list
def set_focus(self,index): def set_focus(self,index):
self.focus = index self.focus = index
self.cbox.set_w(SelText(self.list[index]+' vvv'))
def rebuild_combobox(self):
self.build_combobox(self.body,self.ui,self.row)
def build_combobox(self,body,ui,row): def build_combobox(self,body,ui,row):
str,trash = self.label.get_text() str,trash = self.label.get_text()
self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr) self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr)
if str != '': if str != '':
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1) w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
@@ -319,6 +330,7 @@ class ComboBox(urwid.WidgetWrap):
self.set_w(w) self.set_w(w)
self.body = body self.body = body
self.ui = ui self.ui = ui
self.row = row
# 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):
@@ -331,7 +343,8 @@ class ComboBox(urwid.WidgetWrap):
raise ComboBoxException('ComboBox must be built before use!') raise ComboBoxException('ComboBox must be built before use!')
retval = self.overlay.show(self.ui,self.body) retval = self.overlay.show(self.ui,self.body)
if retval != None: if retval != None:
self.cbox.set_w(SelText(retval+' vvv')) self.set_focus(self.list.index(retval))
#self.cbox.set_w(SelText(retval+' vvv'))
if self.callback != None: if self.callback != None:
self.callback(self,self.overlay._listbox.get_focus()[1],self.user_args) self.callback(self,self.overlay._listbox.get_focus()[1],self.user_args)
return self._w.keypress(size,key) return self._w.keypress(size,key)

View File

@@ -136,7 +136,7 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.global_dns_cb.set_sensitive(new_state) self.global_dns_cb.set_sensitive(new_state)
# use_global_dns_cb is DynWrapped # use_global_dns_cb is DynWrapped
if checkb == self.global_dns_cb.get_w(): if checkb == self.global_dns_cb.get_w():
for w in [ self.dns_dom_edit,self.search_dom_edit, for w in [self.dns_dom_edit,self.search_dom_edit,
self.dns1,self.dns2,self.dns3 ]: self.dns1,self.dns2,self.dns3 ]:
w.set_sensitive(not new_state) w.set_sensitive(not new_state)
@@ -174,31 +174,93 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.set_net_prop("dns2", '') self.set_net_prop("dns2", '')
self.set_net_prop("dns3", '') self.set_net_prop("dns3", '')
def prerun(self,ui,dim,display):
pass
def run(self,ui,dim,display): def run(self,ui,dim,display):
self.ui = ui
self.parent = display
width,height = ui.get_cols_rows() width,height = ui.get_cols_rows()
overlay = urwid.Overlay(self, display, ('fixed left', 0),width self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width
, ('fixed top',1), height-3) , ('fixed top',1), height-3)
self.prerun(ui,dim,display)
#self.ready_comboboxes(ui,overlay) #self.ready_comboboxes(ui,overlay)
keys = True keys = True
while True: while True:
if keys: if keys:
ui.draw_screen(dim, overlay.render(dim, True)) ui.draw_screen(dim, self.overlay.render(dim, True))
keys = ui.get_input() keys = ui.get_input()
for k in keys:
#Send key to underlying widget:
if urwid.is_mouse_event(k):
event, button, col, row = k
self.overlay.mouse_event( dim,
event, button, col, row,
focus=True)
self.overlay.keypress(dim, k)
if "window resize" in keys: if "window resize" in keys:
dim = ui.get_cols_rows() dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys: if "esc" in keys or 'Q' in keys:
return False return False
for k in keys: if "meta enter" in keys or self.OK_PRESSED:
#Send key to underlying widget: self.OK_PRESSED = False
overlay.keypress(dim, k) if self.save_settings():
# Check if buttons are pressed. return True
#if self.CANCEL_PRESSED: if self.CANCEL_PRESSED:
# return False return False
#if self.OK_PRESSED or 'meta enter' in keys:
# return True class WiredSettingsDialog(AdvancedSettingsDialog):
def __init__(self,name):
global wired, daemon
AdvancedSettingsDialog.__init__(self)
self.set_default = urwid.CheckBox(language['default_wired'])
#self.cur_default =
# Add widgets to listbox
self._w.body.body.append(self.set_default)
self._w.body.body.append(self.button_cols)
self.prof_name = name
self._w.header = urwid.Text( ('header',">Configuring preferences for wired profile \"%s\"" % self.prof_name),align='right' )
self.set_values()
def set_net_prop(self,option,value):
wired.SetWiredProperty(option,value)
def set_values(self):
self.ip_edit.set_edit_text(self.format_entry("ip"))
self.netmask_edit.set_edit_text(self.format_entry("netmask"))
self.gateway_edit.set_edit_text(self.format_entry("gateway"))
self.global_dns_cb.set_state(bool(wired.GetWiredProperty('use_global_dns')))
self.static_dns_cb.set_state(bool(wired.GetWiredProperty('use_static_dns')))
self.dns1.set_edit_text(self.format_entry( "dns1"))
self.dns2.set_edit_text(self.format_entry( "dns2"))
self.dns3.set_edit_text(self.format_entry( "dns3"))
self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain"))
self.search_dom_edit.set_edit_text(self.format_entry("search_domain"))
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
def save_settings(self):
AdvancedSettingsDialog.save_settings(self)
if self.set_default.get_state():
wired.UnsetWiredDefault()
print self.set_default.get_state()
if self.set_default.get_state():
bool = True
else:
bool = False
wired.SetWiredProperty("default",bool)
wired.SaveWiredNetworkProfile(self.prof_name)
return True
def format_entry(self, label):
""" Helper method to fetch and format wired properties. """
return noneToBlankString(wired.GetWiredProperty(label))
def prerun(self,ui,dim,display):
pass
######################################## ########################################
@@ -257,6 +319,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID
,'use_settings_globally'))) ,'use_settings_globally')))
# Throw the encryption stuff into a list
list = []
for x, enc_type in enumerate(self.encrypt_types):
list.append(enc_type[0])
self.encryption_combo.set_list(list)
self.change_encrypt_method()
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")
for x, enc_type in enumerate(self.encrypt_types): for x, enc_type in enumerate(self.encrypt_types):
@@ -270,12 +339,6 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
#self.lbox_encrypt_info.set_sensitive(True) #self.lbox_encrypt_info.set_sensitive(True)
else: else:
self.encryption_combo.set_focus(0) self.encryption_combo.set_focus(0)
# Throw the encryption stuff into a list
list = []
for x, enc_type in enumerate(self.encrypt_types):
list.append(enc_type[0])
self.encryption_combo.set_list(list)
self.change_encrypt_method()
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. """
@@ -363,7 +426,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width
, ('fixed top',1), height-3) , ('fixed top',1), height-3)
self.encryption_combo.build_combobox(self.overlay,ui,14) self.encryption_combo.build_combobox(self.overlay,ui,14)
#self.change_encrypt_method() self.change_encrypt_method()
#self._w.body.body.append(self.pile_encrypt) #self._w.body.body.append(self.pile_encrypt)
keys = True keys = True

View File

@@ -56,7 +56,7 @@ from time import sleep
from curses_misc import SelText,ComboBox,TextDialog,InputDialog from curses_misc import SelText,ComboBox,TextDialog,InputDialog
from prefs_curses import PrefsDialog from prefs_curses import PrefsDialog
import netentry_curses import netentry_curses
from netentry_curses import WirelessSettingsDialog, error from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog,error
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
@@ -181,10 +181,10 @@ def gen_network_list():
id = 0 id = 0
wiredL = [] wiredL = []
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None #is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
# This one makes a list of strings to put in a combo box. # This one makes a list of strings to put in a combo box.
for profile in wired.GetWiredProfileList(): #for profile in wired.GetWiredProfileList():
theString = '%4s %25s' % (id, profile) #theString = '%4s %25s' % (id, profile)
#### THIS IS wired.blah() in experimental #### THIS IS wired.blah() in experimental
#print config.GetLastUsedWiredNetwork() #print config.GetLastUsedWiredNetwork()
# Tag if no wireless IP present, and wired one is # Tag if no wireless IP present, and wired one is
@@ -195,9 +195,9 @@ def gen_network_list():
# 'connected focus')) # 'connected focus'))
#else: #else:
#wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) #wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
wiredL.append(theString) #wiredL.append(theString)
id+=1 #id+=1
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()):
@@ -298,10 +298,16 @@ 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): def __init__(self,list):
self.ADD_PROFILE = '---Add a new profile---'
self.__super.__init__(use_enter=False)
self.set_list(list)
#self.set_focus(self.theList.index(wired.GetDefaultProfile()))
def set_list(self,list):
self.theList = list self.theList = list
id = 0 id=0
wiredL = [] wiredL=[]
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
for profile in list: for profile in list:
theString = '%4s %25s' % (id, profile) theString = '%4s %25s' % (id, profile)
@@ -317,11 +323,37 @@ class WiredComboBox(ComboBox):
# wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) # wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
wiredL.append(theString) wiredL.append(theString)
id+=1 id+=1
self.__super.__init__(list=wiredL,use_enter=False) wiredL.append(self.ADD_PROFILE)
self.set_focus(theList.index(wired.GetDefaultWiredProfile())) if is_active:
self.attrs = ('connected','editnfc')
self.focus_attr = 'connected focus'
else :
self.attrs = ('body','editnfc')
self.focus_attr = 'focus'
self.list = wiredL
if self.theList != []:
wired.ReadWiredNetworkProfile(self.get_selected_profile())
def keypress(self,size,key): def keypress(self,size,key):
self.__super.keypress(size,key) prev_focus = self.get_focus()[1]
key = self.__super.keypress(size,key)
if self.get_focus()[1] == len(self.list)-1:
dialog = InputDialog(('header',"Add new wired profile"),7,30)
exitcode,name = dialog.run(ui,self.body)
if exitcode == 0:
wired.CreateWiredNetworkProfile(name,False)
self.set_list(wired.GetWiredProfileList())
self.rebuild_combobox()
self.set_focus(prev_focus)
self.overlay._listbox.set_focus(prev_focus)
else:
wired.ReadWiredNetworkProfile(self.get_selected_profile())
if key == 'delete':
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
self.set_list(wired.GetWiredProfileList())
self.rebuild_combobox()
return key
#if key == 'C': #if key == 'C':
# Configure the network # Configure the network
# pass # pass
@@ -332,11 +364,9 @@ class WiredComboBox(ComboBox):
# self.connect() # self.connect()
#return key #return key
def connect(self):
wired.ConnectWired()
def get_selected_profile(self): def get_selected_profile(self):
"""Get the selected wired profile""" """Get the selected wired profile"""
return self.theList[self._w.get_selected()[1]] return self.theList[self.get_focus()[1]]
######################################## ########################################
##### APPLICATION INTERFACE CLASS ##### APPLICATION INTERFACE CLASS
@@ -370,7 +400,7 @@ class appGUI():
wiredL,wlessL = [],[]# = gen_network_list() wiredL,wlessL = [],[]# = gen_network_list()
self.frame = None self.frame = None
self.wiredCB = urwid.Filler(ComboBox(list=wiredL,use_enter=False)) self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
self.wlessLB = urwid.ListBox(wlessL) self.wlessLB = urwid.ListBox(wlessL)
self.update_netlist(force_check=True,firstrun=True) self.update_netlist(force_check=True,firstrun=True)
@@ -411,11 +441,12 @@ class appGUI():
def lock_screen(self): def lock_screen(self):
self.frame.set_body(self.screen_locker) self.frame.set_body(self.screen_locker)
self.screen_locked = True self.screen_locked = True
self.update_ui()
def unlock_screen(self): def unlock_screen(self):
self.update_netlist(force_check=True)
self.frame.set_body(self.thePile) self.frame.set_body(self.thePile)
self.screen_locked = False self.screen_locked = False
self.update_netlist(force_check=True)
self.update_ui() self.update_ui()
def raise_hidden_network_dialog(self): def raise_hidden_network_dialog(self):
@@ -436,12 +467,12 @@ class appGUI():
if self.thePile.get_focus() == self.wiredCB: if self.thePile.get_focus() == self.wiredCB:
wlessorwired = self.WIRED_IDX wlessorwired = self.WIRED_IDX
where = self.thePile.get_focus().get_body().get_focus()[1] where = self.thePile.get_focus().get_body().get_focus()[1]
else:#self.thePile.get_focus() == self.wlessLB : else: #self.thePile.get_focus() == self.wlessLB :
wlessorwired = self.WLESS_IDX wlessorwired = self.WLESS_IDX
if self.wlessLB == self.no_wlan: if self.wlessLB == self.no_wlan:
where = None where = None
else: else:
where = self.frame.get_body().get_focus().get_focus()[1] where = self.thePile.get_focus().get_focus()[1]
#where = self.wlessLB.get_focus()[1] #where = self.wlessLB.get_focus()[1]
self.focusloc = (wlessorwired,where) self.focusloc = (wlessorwired,where)
# Be clunky until I get to a later stage of development. # Be clunky until I get to a later stage of development.
@@ -498,6 +529,9 @@ class appGUI():
self.prev_state = state self.prev_state = state
if not firstrun: if not firstrun:
self.update_ui() self.update_ui()
if firstrun:
if wired.GetDefaultWiredNetwork() != None:
self.wiredCB.get_body().set_focus(wired.GetWiredProfileList().index(wired.GetDefaultWiredNetwork()))
# Update the footer/status bar # Update the footer/status bar
@wrap_exceptions() @wrap_exceptions()
@@ -591,16 +625,11 @@ class appGUI():
#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)
self.unlock_screen() self.unlock_screen()
# I'm hoping that this will resolve Adam's problem with the screen lock
# remaining onscreen until a key is pressed. It goes away perfectly well
# here.
self.update_ui()
# Same, same, same, same, same, same # Same, same, same, same, same, same
#@wrap_exceptions() #@wrap_exceptions()
def dbus_scan_started(self): def dbus_scan_started(self):
self.lock_screen() self.lock_screen()
self.update_ui()
# Redraw the screen # Redraw the screen
@wrap_exceptions() @wrap_exceptions()
@@ -621,6 +650,7 @@ class appGUI():
loop.quit() loop.quit()
return False return False
if "f5" in keys: if "f5" in keys:
self.lock_screen()
wireless.Scan() wireless.Scan()
if "D" in keys: if "D" in keys:
# Disconnect from all networks. # Disconnect from all networks.
@@ -656,7 +686,8 @@ class appGUI():
if "C" in keys: if "C" in keys:
focus = self.thePile.get_focus() focus = self.thePile.get_focus()
if focus == self.wiredCB: if focus == self.wiredCB:
pass WiredSettingsDialog(self.wiredCB.get_body().
get_selected_profile()).run(ui,self.size,self.frame)
else: else:
# wireless list only other option # wireless list only other option
wid,pos = self.thePile.get_focus().get_focus() wid,pos = self.thePile.get_focus().get_focus()
@@ -677,18 +708,6 @@ class appGUI():
self.size = ui.get_cols_rows() self.size = ui.get_cols_rows()
continue continue
self.frame.keypress( self.size, k ) self.frame.keypress( self.size, k )
if " " in keys:
focus = self.thePile.get_focus()
if focus == self.wiredCB:
#self.set_status('space pressed on wiredCB!')
wid,pos = self.wiredCB.get_body().get_focus()
text,attr = wid.get_text()
wired.ReadWiredNetworkProfile(text)
# Make sure our internal reference to the combobox matches the
# one found in the pile.
#self.wiredCB = self.thePile.get_focus()
return True return True
# TODO: Update this to use the networkentry stuff # TODO: Update this to use the networkentry stuff
def connect(self, nettype, networkid, networkentry=None): def connect(self, nettype, networkid, networkentry=None):

View File

@@ -1,4 +1,5 @@
.TH WICD-CURSES "8" "January 2009" "wicd-curses" .\" First revision was r203
.TH WICD-CURSES "8" "January 2009" "wicd-curses-r247"
.SH NAME .SH NAME
.B wicd-curses .B wicd-curses
\- curses-based wicd(8) controller \- curses-based wicd(8) controller
@@ -39,11 +40,14 @@ Bring up hidden network scanning dialog
.TP .TP
.BR H .BR H
Bring up a rather simplistic help dialog. Of course, it mentions this man page first. :-) Bring up a rather simplistic help dialog. Of course, it mentions this man page first. :-)
.PP .\".PP
The following is a work in progress and might not be fully functional as of yet. .\"The following is a work in progress and might not be fully functional as of yet.
.TP .TP
.BR C .BR C
Bring up network configuration controller for the selected network Bring up network configuration controller for the selected network
.TP
.BR delete
Delete the selected wired network profile (from the wired combo box at the top)
.PP .PP
The following are not implemented yet: The following are not implemented yet:
.TP .TP

View File

@@ -1,8 +1,10 @@
If you are reading this, you are probably wondering why your Wicd configuration WHERE ARE MY FILES?!
files are not here. What follows is a summary of the folders that wicd uses.
For a more detailed (and complete) description what is in each directory, consult the If you are reading this, you are probably wondering why your Wicd configuration
man pages for wicd(8) and wicd-curses(8). files are not here. What follows is a summary of the folders that Wicd uses.
For a more detailed (and complete) description what is in each directory,
consult the man pages for wicd(8) and wicd-curses(8).
~/.wicd ~/.wicd
User-dependent configuration files, only used by wicd-curses User-dependent configuration files, only used by wicd-curses