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

Merged in latest from NaCl's branch.

This commit is contained in:
Robby Workman
2009-01-02 21:22:17 -06:00
3 changed files with 115 additions and 62 deletions

31
curses/curses_misc.py Executable file → Normal file
View File

@@ -120,15 +120,19 @@ class TabColumns(urwid.WidgetWrap):
def keypress(self,size,key): def keypress(self,size,key):
self._w.keypress(size,key) self._w.keypress(size,key)
wid = self.pile.get_focus().get_body() if key == "meta left" or key == "meta right":
if wid == self.columns: self._w.get_body().set_focus(0)
# lw = self.listbox.body self.keypress(size,key[5:])
# lw.pop(1) else:
self.active_tab.set_attr('body') wid = self.pile.get_focus().get_body()
self.columns.get_focus().set_attr('tab active') if wid == self.columns:
self.active_tab = self.columns.get_focus() # lw = self.listbox.body
self.gen_pile(self.tab_map[self.active_tab]) # lw.pop(1)
return key self.active_tab.set_attr('body')
self.columns.get_focus().set_attr('tab active')
self.active_tab = self.columns.get_focus()
self.gen_pile(self.tab_map[self.active_tab])
return key
# self.listbox.body = lw # self.listbox.body = lw
@@ -144,7 +148,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 ComboText""" """The actual menu-like space that comes down from the ComboText"""
def __init__(self,list,body,ui,show_first=0,pos=(0,0),attr=('body','focus')): def __init__(self,list,body,ui,show_first,pos=(0,0),attr=('body','focus')):
""" """
body : parent widget body : parent widget
list : stuff to include in the combobox list : stuff to include in the combobox
@@ -163,6 +167,7 @@ class ComboBox(urwid.WidgetWrap):
content = [urwid.AttrWrap(SelText(w), attr[0], attr[1]) content = [urwid.AttrWrap(SelText(w), attr[0], attr[1])
for w in list] for w in list]
self._listbox = urwid.ListBox(content) self._listbox = urwid.ListBox(content)
self._listbox.set_focus(show_first)
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)
@@ -233,9 +238,9 @@ class ComboBox(urwid.WidgetWrap):
def set_show_first(self,show_first): def set_show_first(self,show_first):
self.show_first = show_first self.show_first = show_first
def build_combobox(self,body,ui,row,show_first=0): def build_combobox(self,body,ui,row):
str,trash = self.label.get_text() str,trash = self.label.get_text()
self.cbox = urwid.AttrWrap(SelText([self.list[show_first]+' vvv']), self.cbox = urwid.AttrWrap(SelText([self.list[self.show_first]+' vvv']),
self.attr[0],self.attr[1]) self.attr[0],self.attr[1])
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)
@@ -271,7 +276,7 @@ class ComboBox(urwid.WidgetWrap):
# Return the index of the selected element # Return the index of the selected element
def get_selected(self): def get_selected(self):
wid,pos = self.overlay._listbox.get_focus() wid,pos = self.overlay._listbox.get_focus()
return pos return (wid,pos)
# Almost completely ripped from rbreu_filechooser.py: # Almost completely ripped from rbreu_filechooser.py:

View File

@@ -79,6 +79,9 @@ class PrefsDialog(urwid.WidgetWrap):
wired_auto_2_t = language['show_wired_list'] wired_auto_2_t = language['show_wired_list']
wired_auto_3_t = language['use_last_used_profile'] wired_auto_3_t = language['use_last_used_profile']
auto_reconn_cat_t = ('header','Automatic Reconnection')
auto_reconn_t = 'Automatically reconnect on connection loss'
#### External Programs #### External Programs
automatic_t = language['wicd_auto_config'] automatic_t = language['wicd_auto_config']
@@ -113,8 +116,6 @@ class PrefsDialog(urwid.WidgetWrap):
wless_cat_t = ('header','Wireless Interface') wless_cat_t = ('header','Wireless Interface')
use_dbm_t = language['display_type_dialog'] use_dbm_t = language['display_type_dialog']
auto_reconn_cat_t = ('header','Automatic Reconnect')
auto_reconn_t = 'Automatically reconnect on connection loss'
#### ####
@@ -145,6 +146,9 @@ class PrefsDialog(urwid.WidgetWrap):
self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,wired_auto_1_t) self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,wired_auto_1_t)
self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,wired_auto_2_t) self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,wired_auto_2_t)
self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,wired_auto_3_t) self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,wired_auto_3_t)
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
generalLB = urwid.ListBox([self.net_cat, generalLB = urwid.ListBox([self.net_cat,
self.wless_edit,#_blank, self.wless_edit,#_blank,
self.wired_edit, self.wired_edit,
@@ -156,7 +160,9 @@ class PrefsDialog(urwid.WidgetWrap):
self.wired_auto_cat, self.wired_auto_cat,
self.wired_auto_1, self.wired_auto_1,
self.wired_auto_2, self.wired_auto_2,
self.wired_auto_3 self.wired_auto_3, _blank,
self.auto_reconn_cat,
self.auto_reconn_checkb
]) ])
#### External Programs tab #### External Programs tab
@@ -207,8 +213,6 @@ class PrefsDialog(urwid.WidgetWrap):
self.wless_cat = urwid.Text(wless_cat_t) self.wless_cat = urwid.Text(wless_cat_t)
self.use_dbm_checkb = urwid.CheckBox(use_dbm_t) self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
advancedLB = urwid.ListBox([self.wpa_cat, advancedLB = urwid.ListBox([self.wpa_cat,
self.wpa_cbox,self.wpa_warn,_blank, self.wpa_cbox,self.wpa_warn,_blank,
@@ -217,9 +221,8 @@ class PrefsDialog(urwid.WidgetWrap):
self.debug_cat, self.debug_cat,
self.debug_mode_checkb, _blank, self.debug_mode_checkb, _blank,
self.wless_cat, self.wless_cat,
self.use_dbm_checkb, _blank, self.use_dbm_checkb, _blank
self.auto_reconn_cat, ])
self.auto_reconn_checkb])
headerList = [self.header0,self.header1,self.header2] headerList = [self.header0,self.header1,self.header2]
@@ -260,6 +263,10 @@ class PrefsDialog(urwid.WidgetWrap):
self.__super.__init__(self.tabs) self.__super.__init__(self.tabs)
def load_settings(self): def load_settings(self):
# Reset the buttons
self.CANCEL_PRESSED = False
self.OK_PRESSED = False
### General Settings ### General Settings
# Urwid does not like dbus.Strings as text markups # Urwid does not like dbus.Strings as text markups
wless_iface = unicode(daemon.GetWirelessInterface()) wless_iface = unicode(daemon.GetWirelessInterface())
@@ -282,6 +289,8 @@ class PrefsDialog(urwid.WidgetWrap):
# Wired Automatic Connection # Wired Automatic Connection
self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1] self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1]
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
### External Programs ### External Programs
dhcp_method = daemon.GetDHCPClient() dhcp_method = daemon.GetDHCPClient()
self.dhcp_l[dhcp_method].set_state(True) self.dhcp_l[dhcp_method].set_state(True)
@@ -314,11 +323,15 @@ class PrefsDialog(urwid.WidgetWrap):
self.backends.remove('') self.backends.remove('')
self.thebackends= [unicode(w) for w in self.backends] self.thebackends= [unicode(w) for w in self.backends]
self.backend_cbox.set_list(self.thebackends) self.backend_cbox.set_list(self.thebackends)
cur_backend = daemon.GetSavedBackend()
try:
self.backend_cbox.set_show_first(self.thebackends.index(cur_backend))
except ValueError:
self.backend_cbox.set_show_first(0)
# Three last checkboxes # Two last checkboxes
self.debug_mode_checkb.set_state(daemon.GetDebugMode()) self.debug_mode_checkb.set_state(daemon.GetDebugMode())
self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType()) self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
def save_results(self): def save_results(self):
""" Pushes the selected settings to the daemon. """ Pushes the selected settings to the daemon.
@@ -329,7 +342,7 @@ class PrefsDialog(urwid.WidgetWrap):
self.search_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_selected()]) daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_selected()[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())
@@ -341,7 +354,7 @@ class PrefsDialog(urwid.WidgetWrap):
else: else:
daemon.SetWiredAutoConnectMethod(1) daemon.SetWiredAutoConnectMethod(1)
daemon.SetBackend(self.backends[self.backend_cbox.get_selected()]) daemon.SetBackend(self.backends[self.backend_cbox.get_selected()[1]])
# External Programs Tab # External Programs Tab
if self.dhcp0.get_state(): if self.dhcp0.get_state():
@@ -410,9 +423,10 @@ class PrefsDialog(urwid.WidgetWrap):
for k in keys: for k in keys:
#Send key to underlying widget: #Send key to underlying widget:
overlay.keypress(dim, k) overlay.keypress(dim, k)
# Check if buttons are pressed.
if self.CANCEL_PRESSED: if self.CANCEL_PRESSED:
return False return False
if self.OK_PRESSED: if self.OK_PRESSED or 'meta enter' in keys:
return True return True

106
curses/wicd-curses.py Executable file → Normal file
View File

@@ -185,24 +185,10 @@ def gen_network_list():
wlessL = [] wlessL = []
for network_id in range(0, wireless.GetNumberOfNetworks()): for network_id in range(0, wireless.GetNumberOfNetworks()):
# ?: in python
encryption = wireless.GetWirelessProperty(network_id, 'encryption_method') if wireless.GetWirelessProperty(network_id, 'encryption') else 'Unsecured'
theString = ' %*s %25s %9s %17s %6s: %s' % ( gap,
daemon.FormatSignalForPrinting(
str(wireless.GetWirelessProperty(network_id, strenstr))),
wireless.GetWirelessProperty(network_id, 'essid'),
#wireless.GetWirelessProperty(network_id, 'encryption_method'),
encryption,
wireless.GetWirelessProperty(network_id, 'bssid'),
wireless.GetWirelessProperty(network_id, 'mode'), # Master, Ad-Hoc
wireless.GetWirelessProperty(network_id, 'channel')
)
is_active = wireless.GetCurrentSignalStrength("") != 0 and wireless.GetCurrentNetworkID(wireless.GetIwconfig())==network_id is_active = wireless.GetCurrentSignalStrength("") != 0 and wireless.GetCurrentNetworkID(wireless.GetIwconfig())==network_id
if is_active:
theString = '>'+theString[1:] label = NetLabel(network_id,is_active)
wlessL.append(urwid.AttrWrap(SelText(theString),'connected','connected focus')) wlessL.append(label)
else:
wlessL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
return (wiredL,wlessL) return (wiredL,wlessL)
def about_dialog(body): def about_dialog(body):
@@ -215,7 +201,7 @@ def about_dialog(body):
('green'," /// \\\\\\")," | |/ |/ / / __/ _ / \n", ('green'," /// \\\\\\")," | |/ |/ / / __/ _ / \n",
('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ \n", ('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ \n",
('green',"||| ||"),"(|^|)",('green',"|| |||"), ('green',"||| ||"),"(|^|)",('green',"|| |||"),
" ($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',"///")," http://wicd.net \n",
@@ -242,6 +228,50 @@ def about_dialog(body):
if about.b_pressed == 'OK': if about.b_pressed == 'OK':
return False return False
class NetLabel(urwid.WidgetWrap):
def __init__(self, id, is_active):
# Pick which strength measure to use based on what the daemon says
if daemon.GetSignalDisplayType() == 0:
strenstr = 'quality'
gap = 3
else:
strenstr = 'strength'
gap = 5
self.id = id
# All of that network property stuff
self.stren = daemon.FormatSignalForPrinting(
str(wireless.GetWirelessProperty(id, strenstr)))
self.essid = wireless.GetWirelessProperty(id, 'essid')
self.bssid = wireless.GetWirelessProperty(id, 'bssid')
self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') if wireless.GetWirelessProperty(id, 'encryption') else 'Unsecured'
self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc
self.channel = wireless.GetWirelessProperty(id, 'channel')
theString = ' %*s %25s %9s %17s %6s: %s' % (gap,
self.stren,self.essid,self.encrypt,self.bssid,self.mode,self.channel)
if is_active:
theString = '>'+theString[1:]
w = urwid.AttrWrap(SelText(theString),'connected','connected focus')
else:
w = urwid.AttrWrap(SelText(theString),'body','focus')
self.__super.__init__(w)
def selectable(self):
return True
def keypress(self,size,key):
self._w.keypress(size,key)
if key == 'C':
# Configure the network
pass
elif key == 'S':
# Configure scripts
pass
elif key == 'enter':
self.connect()
return key
def connect(self):
# This should work.
wireless.ConnectWireless(self.id)
######################################## ########################################
##### APPLICATION INTERFACE CLASS ##### APPLICATION INTERFACE CLASS
######################################## ########################################
@@ -299,8 +329,10 @@ class appGUI():
self.prev_state = False self.prev_state = False
self.connecting = False self.connecting = False
self.screen_locked = False self.screen_locked = False
self.connecting = False
self.always_show_wired = daemon.GetAlwaysShowWiredInterface() self.always_show_wired = daemon.GetAlwaysShowWiredInterface()
self.pref = None
self.update_status() self.update_status()
#self.dialog = PrefOverlay(self.frame,self.size) #self.dialog = PrefOverlay(self.frame,self.size)
@@ -406,7 +438,7 @@ class appGUI():
# If we are connecting and being called from the idle function, spin # If we are connecting and being called from the idle function, spin
# the wheel. # the wheel.
if from_idle and self.connecting: if from_idle and self.connecting:
# This is probably the wrong way to do this, but ir works for now. # This is probably the wrong way to do this, but it works for now.
toAppend=self.twirl[self.incr % 4] toAppend=self.twirl[self.incr % 4]
self.footer2 = urwid.AttrWrap(urwid.Text(text+' '+toAppend),'important') self.footer2 = urwid.AttrWrap(urwid.Text(text+' '+toAppend),'important')
self.frame.set_footer(urwid.BoxAdapter( self.frame.set_footer(urwid.BoxAdapter(
@@ -463,6 +495,7 @@ class appGUI():
if "f5" in keys: if "f5" in keys:
wireless.Scan() wireless.Scan()
if "enter" in keys: if "enter" in keys:
# TODO: Make this totally go away by superclassing ComboBox
# Should be a function of the labels, I think. # Should be a function of the labels, I think.
self.call_connect() self.call_connect()
if "D" in keys: if "D" in keys:
@@ -476,11 +509,11 @@ class appGUI():
# Prevents automatic reconnecting if that option is enabled # Prevents automatic reconnecting if that option is enabled
daemon.SetForcedDisconnect(True) daemon.SetForcedDisconnect(True)
if "P" in keys: if "P" in keys:
dialog = PrefsDialog(self.frame,(0,1),ui, if not self.pref:
dbusmanager.get_dbus_ifaces()) self.pref = PrefsDialog(self.frame,(0,1),ui,
# There is some lag in using the buttons. Not my fault. dbusmanager.get_dbus_ifaces())
if dialog.run(ui,self.size,self.frame): if self.pref.run(ui,self.size,self.frame):
dialog.save_results() self.pref.save_results()
self.update_ui() self.update_ui()
if "A" in keys: if "A" in keys:
about_dialog(self.frame) about_dialog(self.frame)
@@ -491,13 +524,15 @@ class appGUI():
self.frame.keypress( self.size, k ) self.frame.keypress( self.size, k )
if " " in keys: if " " in keys:
#self.set_status('space pressed on wiredCB!') focus = self.thePile.get_focus()
wid,pos = self.wiredCB.get_body().get_selected() if focus == self.wiredCB:
text,attr = wid.get_text() #self.set_status('space pressed on wiredCB!')
wired.ReadWiredNetworkProfile(text) wid,pos = self.wiredCB.get_body().get_selected()
# Make sure our internal reference to the combobox matches the text,attr = wid.get_text()
# one found in the pile. wired.ReadWiredNetworkProfile(text)
self.wiredCB = self.thePile.get_focus() # 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
@@ -510,9 +545,8 @@ class appGUI():
self.connect(self,'wired',0) self.connect(self,'wired',0)
#return "Wired network %i" % pos #return "Wired network %i" % pos
elif wid is self.wlessLB: elif wid is self.wlessLB:
#self.footer1 = urwid.Text("Wireless!") # Do nothing
wid2,pos = self.wlessLB.get_focus() pass
self.connect(self,'wireless',pos)
else: else:
self.set_status("call_connect() failed! This is definitely a bug!") self.set_status("call_connect() failed! This is definitely a bug!")
#return "Failure!" #return "Failure!"
@@ -602,7 +636,7 @@ def setup_dbus(force=True):
# Suggestions as to what should go here # Suggestions as to what should go here
print "Can't connect to the daemon. Are you sure it is running?" print "Can't connect to the daemon. Are you sure it is running?"
print "Please check the wicd log for error messages." print "Please check the wicd log for error messages."
raise #raise
# return False # <- Will need soon. # return False # <- Will need soon.
bus = dbusmanager.get_bus() bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces() dbus_ifaces = dbusmanager.get_dbus_ifaces()