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

curses/wicd-curses.py: ListBox focus-maintaining code completely debugged

This commit is contained in:
Andrew Psaltis
2009-01-15 21:46:35 -05:00
parent 2685a49779
commit 6e9eb1cd65

View File

@@ -104,6 +104,7 @@ class wrap_exceptions:
# Zap the screen # Zap the screen
ui.stop() ui.stop()
# Print out standard notification: # Print out standard notification:
print "\nEXCEPTION!" print "\nEXCEPTION!"
print "Please report this to the maintainer and/or file a bug report with the backtrace below:" print "Please report this to the maintainer and/or file a bug report with the backtrace below:"
print redraw_tag print redraw_tag
@@ -400,7 +401,6 @@ class appGUI():
self.screen_locked = False self.screen_locked = False
#self.always_show_wired = daemon.GetAlwaysShowWiredInterface() #self.always_show_wired = daemon.GetAlwaysShowWiredInterface()
self.pref = None self.pref = None
self.update_status() self.update_status()
@@ -432,24 +432,24 @@ class appGUI():
# Location of last known focus is remapped to current 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() is self.wiredCB: #self.set_status(str(self.frame.get_body().get_focus())+ ' '+ str(self.wiredCB))
if self.thePile.get_focus() == self.wiredCB:
wlessorwired = self.WIRED_IDX wlessorwired = self.WIRED_IDX
else :
wlessorwired = self.WLESS_IDX
if self.thePile.get_focus() == self.no_wlan:
where = 0
elif self.thePile.get_focus() == self.wiredCB:
where = self.thePile.get_focus().get_body().get_focus()[1] where = self.thePile.get_focus().get_body().get_focus()[1]
else: else:#self.thePile.get_focus() == self.wlessLB :
where = self.thePile.get_focus().get_focus()[1] wlessorwired = self.WLESS_IDX
if self.wlessLB == self.no_wlan:
where = None
else:
where = self.frame.get_body().get_focus().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.
# Update the list of networks. Usually called by DBus. # Update the list of networks. Usually called by DBus.
# TODO: Preserve current focus when updating the list. # TODO: Preserve current focus when updating the list.
@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):
# Run focus-collecting code if we are not running this for the first time
if not firstrun: if not firstrun:
self.update_focusloc() self.update_focusloc()
""" Updates the overall network list.""" """ Updates the overall network list."""
@@ -462,31 +462,42 @@ class appGUI():
self.wiredCB.get_body().set_list(wiredL) self.wiredCB.get_body().set_list(wiredL)
self.wiredCB.get_body().build_combobox(self.frame,ui,3) self.wiredCB.get_body().build_combobox(self.frame,ui,3)
if len(wlessL) != 0: if len(wlessL) != 0:
self.wlessLB = urwid.ListBox(wlessL) if self.wlessLB == self.no_wlan:
#self.wlessLB.body = urwid.SimpleListWalker(wlessL) self.wlessLB = urwid.ListBox(wlessL)
else:
self.wlessLB.body = urwid.SimpleListWalker(wlessL)
else: else:
self.wlessLB = self.no_wlan self.wlessLB = self.no_wlan
#self.wlessLB.body = urwid.SimpleListWalker([self.no_wlan])
if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn(): if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
#if daemon.GetAlwaysShowWiredInterface(): #if daemon.GetAlwaysShowWiredInterface():
#if firstrun:
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',1,self.wlessH), ('fixed',1,self.wlessH),
self.wlessLB] ) self.wlessLB] )
if not firstrun:
self.frame.body = self.thePile
#self.focusloc = (self.thePile.get_focus(), #self.focusloc = (self.thePile.get_focus(),
# self.thePile.get_focus().get_focus()[1]) # self.thePile.get_focus().get_focus()[1])
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:
self.thePile.get_focus().set_focus(self.focusloc[1]) if self.wlessLB is not self.no_wlan:
self.thePile.get_focus().set_focus(self.focusloc[1])
else:
self.thePile.set_focus(self.wiredCB)
else: else:
self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] ) self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] )
self.frame.body = self.thePile if not firstrun:
if self.focusloc[0] == self.wlessLB: self.frame.body = self.thePile
self.wlessLB.set_focus(self.focusloc[1]) #if self.focusloc[0] == self.wlessLB:
self.wlessLB.set_focus(self.focusloc[1])
#self.thePile.get_focus().set_focus(self.focusloc[1])
#self.always_show_wired = not self.always_show_wired #self.always_show_wired = not self.always_show_wired
self.prev_state = state self.prev_state = state
if not firstrun:
self.update_ui()
# Update the footer/status bar # Update the footer/status bar
@wrap_exceptions() @wrap_exceptions()
@@ -529,6 +540,7 @@ class appGUI():
return True return True
else: else:
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
self.update_ui()
return True return True
@@ -542,6 +554,8 @@ class appGUI():
# something, and we aren't connecting to something, return False # something, and we aren't connecting to something, return False
# immediately. # immediately.
if from_idle and not self.connecting: if from_idle and not self.connecting:
self.update_netlist()
self.update_ui()
return False return False
toAppend = '' toAppend = ''
# If we are connecting and being called from the idle function, spin # If we are connecting and being called from the idle function, spin
@@ -558,12 +572,15 @@ class appGUI():
# Not necessary in the end, but I will be using footer1 for stuff in # Not necessary in the end, but I will be using footer1 for stuff in
# the long run, so I might as well put something there. # the long run, so I might as well put something there.
incr = 0 incr = 0
@wrap_exceptions()
def idle_incr(self): def idle_incr(self):
theText = "" theText = " "
#if self.special != None:
# theText += self.special
if self.connecting: if self.connecting:
theText = "-- Connecting -- Press ESC to cancel " theText += "-- Connecting -- Press ESC to cancel "
quit_note = "-- Press F8 or Q to quit." quit_note = "-- Press F8 or Q to quit."
self.footer1 = urwid.Text(str(self.incr) + ' '+theText+quit_note) self.footer1 = urwid.Text(str(self.incr) + theText+quit_note,wrap='clip')
self.incr+=1 self.incr+=1
return True return True
@@ -612,8 +629,9 @@ class appGUI():
# Guess what! I actually need to put this here, else I'll have tons of # Guess what! I actually need to put this here, else I'll have tons of
# references to self.frame lying around. ^_^ # references to self.frame lying around. ^_^
if "enter" in keys: if "enter" in keys:
focus = self.thePile.get_focus() focus = self.frame.body.get_focus()
if focus is self.wiredCB: if focus == self.wiredCB:
self.special = focus
self.connect("wired",0) self.connect("wired",0)
else: else:
# wless list only other option # wless list only other option