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

curses/curses_misc.py:

meta+right or meta+left now move the selected tab right and left respectively.  Focus goes back to the tabs, though.
  Fixed a bug in ComboBox where show_first does nothing
  Restored get_selected to its original state
curses/prefs_curses.py:
  Moved the automatic reconnect category to "General Settings"
  Made the backend selector actually select the selected backend at first
  Reset the button statuses each time we load the settings
  meta+enter now saves+closes the preferences dialog
curses/wicd-curses.py:
  Turned the wired list into a list of custom SelTexts, so that they can do the connecting/script-choosing/configuring/etc, instead of the dialog itself
  Offset the version in the about dialog a little less
  Recycle the old preferences dialog instead of making a new one if we run it more than once
This commit is contained in:
Andrew Psaltis
2009-01-02 22:12:58 -05:00
parent 8ed394abf3
commit 0b0f3e0968
3 changed files with 115 additions and 62 deletions

View File

@@ -120,6 +120,10 @@ class TabColumns(urwid.WidgetWrap):
def keypress(self,size,key):
self._w.keypress(size,key)
if key == "meta left" or key == "meta right":
self._w.get_body().set_focus(0)
self.keypress(size,key[5:])
else:
wid = self.pile.get_focus().get_body()
if wid == self.columns:
# lw = self.listbox.body
@@ -144,7 +148,7 @@ class ComboBox(urwid.WidgetWrap):
"""A ComboBox of text objects"""
class ComboSpace(urwid.WidgetWrap):
"""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
list : stuff to include in the combobox
@@ -163,6 +167,7 @@ class ComboBox(urwid.WidgetWrap):
content = [urwid.AttrWrap(SelText(w), attr[0], attr[1])
for w in list]
self._listbox = urwid.ListBox(content)
self._listbox.set_focus(show_first)
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]),
width + 2, ('fixed top', pos[1]), height)
@@ -233,9 +238,9 @@ class ComboBox(urwid.WidgetWrap):
def set_show_first(self,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()
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])
if str != '':
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
def get_selected(self):
wid,pos = self.overlay._listbox.get_focus()
return pos
return (wid,pos)
# 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_3_t = language['use_last_used_profile']
auto_reconn_cat_t = ('header','Automatic Reconnection')
auto_reconn_t = 'Automatically reconnect on connection loss'
#### External Programs
automatic_t = language['wicd_auto_config']
@@ -113,8 +116,6 @@ class PrefsDialog(urwid.WidgetWrap):
wless_cat_t = ('header','Wireless Interface')
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_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.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
generalLB = urwid.ListBox([self.net_cat,
self.wless_edit,#_blank,
self.wired_edit,
@@ -156,7 +160,9 @@ class PrefsDialog(urwid.WidgetWrap):
self.wired_auto_cat,
self.wired_auto_1,
self.wired_auto_2,
self.wired_auto_3
self.wired_auto_3, _blank,
self.auto_reconn_cat,
self.auto_reconn_checkb
])
#### External Programs tab
@@ -207,8 +213,6 @@ class PrefsDialog(urwid.WidgetWrap):
self.wless_cat = urwid.Text(wless_cat_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,
self.wpa_cbox,self.wpa_warn,_blank,
@@ -217,9 +221,8 @@ class PrefsDialog(urwid.WidgetWrap):
self.debug_cat,
self.debug_mode_checkb, _blank,
self.wless_cat,
self.use_dbm_checkb, _blank,
self.auto_reconn_cat,
self.auto_reconn_checkb])
self.use_dbm_checkb, _blank
])
headerList = [self.header0,self.header1,self.header2]
@@ -260,6 +263,10 @@ class PrefsDialog(urwid.WidgetWrap):
self.__super.__init__(self.tabs)
def load_settings(self):
# Reset the buttons
self.CANCEL_PRESSED = False
self.OK_PRESSED = False
### General Settings
# Urwid does not like dbus.Strings as text markups
wless_iface = unicode(daemon.GetWirelessInterface())
@@ -282,6 +289,8 @@ class PrefsDialog(urwid.WidgetWrap):
# Wired Automatic Connection
self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1]
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
### External Programs
dhcp_method = daemon.GetDHCPClient()
self.dhcp_l[dhcp_method].set_state(True)
@@ -314,11 +323,15 @@ class PrefsDialog(urwid.WidgetWrap):
self.backends.remove('')
self.thebackends= [unicode(w) for w in self.backends]
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.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
def save_results(self):
""" Pushes the selected settings to the daemon.
@@ -329,7 +342,7 @@ class PrefsDialog(urwid.WidgetWrap):
self.search_dom.get_edit_text())
daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_selected()])
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_selected()[1]])
daemon.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state())
daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
daemon.SetDebugMode(self.debug_mode_checkb.get_state())
@@ -341,7 +354,7 @@ class PrefsDialog(urwid.WidgetWrap):
else:
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
if self.dhcp0.get_state():
@@ -410,9 +423,10 @@ class PrefsDialog(urwid.WidgetWrap):
for k in keys:
#Send key to underlying widget:
overlay.keypress(dim, k)
# Check if buttons are pressed.
if self.CANCEL_PRESSED:
return False
if self.OK_PRESSED in keys:
if self.OK_PRESSED or 'meta enter' in keys:
return True

View File

@@ -185,24 +185,10 @@ def gen_network_list():
wlessL = []
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
if is_active:
theString = '>'+theString[1:]
wlessL.append(urwid.AttrWrap(SelText(theString),'connected','connected focus'))
else:
wlessL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
label = NetLabel(network_id,is_active)
wlessL.append(label)
return (wiredL,wlessL)
def about_dialog(body):
@@ -242,6 +228,50 @@ def about_dialog(body):
if about.b_pressed == 'OK':
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
########################################
@@ -299,8 +329,10 @@ class appGUI():
self.prev_state = False
self.connecting = False
self.screen_locked = False
self.connecting = False
self.always_show_wired = daemon.GetAlwaysShowWiredInterface()
self.pref = None
self.update_status()
#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
# the wheel.
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]
self.footer2 = urwid.AttrWrap(urwid.Text(text+' '+toAppend),'important')
self.frame.set_footer(urwid.BoxAdapter(
@@ -463,6 +495,7 @@ class appGUI():
if "f5" in keys:
wireless.Scan()
if "enter" in keys:
# TODO: Make this totally go away by superclassing ComboBox
# Should be a function of the labels, I think.
self.call_connect()
if "D" in keys:
@@ -476,11 +509,11 @@ class appGUI():
# Prevents automatic reconnecting if that option is enabled
daemon.SetForcedDisconnect(True)
if "P" in keys:
dialog = PrefsDialog(self.frame,(0,1),ui,
if not self.pref:
self.pref = PrefsDialog(self.frame,(0,1),ui,
dbusmanager.get_dbus_ifaces())
# There is some lag in using the buttons. Not my fault.
if dialog.run(ui,self.size,self.frame):
dialog.save_results()
if self.pref.run(ui,self.size,self.frame):
self.pref.save_results()
self.update_ui()
if "A" in keys:
about_dialog(self.frame)
@@ -491,13 +524,15 @@ class appGUI():
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_selected()
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()
#self.wiredCB = self.thePile.get_focus()
return True
@@ -510,9 +545,8 @@ class appGUI():
self.connect(self,'wired',0)
#return "Wired network %i" % pos
elif wid is self.wlessLB:
#self.footer1 = urwid.Text("Wireless!")
wid2,pos = self.wlessLB.get_focus()
self.connect(self,'wireless',pos)
# Do nothing
pass
else:
self.set_status("call_connect() failed! This is definitely a bug!")
#return "Failure!"
@@ -602,7 +636,7 @@ def setup_dbus(force=True):
# Suggestions as to what should go here
print "Can't connect to the daemon. Are you sure it is running?"
print "Please check the wicd log for error messages."
raise
#raise
# return False # <- Will need soon.
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()