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

curses/curses_misc.py: Added a tabbed interface widget for use in the preferences dialog.

curses/prefs_curses.py: Converted the code to use the tabbed interface found in curses_misc.py.  The dialog now fills up the terminal, but it still does nothing.
curses/wicd-curses.py: Turned the "list" wired section of the interface to a combo box.
This commit is contained in:
Andrew Psaltis
2008-12-27 22:35:58 -05:00
parent 0d4811b129
commit 689d31b098
3 changed files with 135 additions and 74 deletions

View File

@@ -72,16 +72,42 @@ class ToggleEdit(urwid.WidgetWrap):
def keypress(self,size,key): def keypress(self,size,key):
return self._w.keypress(size,key) return self._w.keypress(size,key)
# Would seem to complicate things a little bit, but could be very useful. ^_^ # Tabbed interface
# Not used yet. Will be used very shortly, as a superclass of some future
# overlays
class TabColumns(urwid.WidgetWrap): class TabColumns(urwid.WidgetWrap):
def __init__(self): """
pass titles_dict = dictionary of tab_contents (a SelText) : tab_widget (box)
attr = normal attributes
attrsel = attribute when active
"""
def __init__(self,tab_str,tab_wid,title,attr=('body','focus'),attrsel='tab active',
attrtitle='header'):
#title_wid = urwid.Text((attrtitle,title),align='right')
column_list = []
for w in tab_str:
text,trash = w.get_text()
column_list.append(('fixed',len(text),w))
column_list.append(urwid.Text((attrtitle,title),align='right'))
self.tab_map = dict(zip(tab_str,tab_wid))
self.active_tab = tab_str[0]
self.columns = urwid.Columns(column_list,dividechars=1)
walker = urwid.SimpleListWalker([self.columns,tab_wid[0]])
self.listbox = urwid.ListBox(walker)
self.__super.__init__(self.listbox)
def selectable(self): def selectable(self):
return True return True
def keypress(self,size,key): def keypress(self,size,key):
pass self._w.keypress(size,key)
(wid,pos) = self.listbox.get_focus()
if wid is self.columns:
lw = self.listbox.body
lw.pop(1)
self.active_tab.set_attr('body')
self.columns.get_focus().set_attr('tab active')
self.active_tab = self.columns.get_focus()
lw.append(self.tab_map[self.columns.get_focus()])
self.listbox.body = lw
# 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:
@@ -106,7 +132,7 @@ class ComboText(urwid.WidgetWrap):
for entry in list: for entry in list:
if len(entry) > width: if len(entry) > width:
width = len(entry) width = len(entry)
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)
@@ -141,9 +167,11 @@ class ComboText(urwid.WidgetWrap):
#def get_size(self): #def get_size(self):
def __init__(self,label,list,body,ui,row = 0,show_first=0,attr=('body','focus')): def __init__(self,label,list,body,ui,row = 0,show_first=0,attr=('body','focus'),
use_enter=True):
""" """
label : bit of text that preceeds the combobox label : bit of text that preceeds the combobox. If it is "", then
ignore it
list : stuff to include in the combobox list : stuff to include in the combobox
body : parent widget body : parent widget
ui : the screen ui : the screen
@@ -154,23 +182,35 @@ class ComboText(urwid.WidgetWrap):
self.label = urwid.Text(label) self.label = urwid.Text(label)
str,trash = self.label.get_text() str,trash = self.label.get_text()
self.cbox = urwid.AttrWrap(SelText(list[show_first]),attr[0],attr[1]) self.cbox = urwid.AttrWrap(SelText([list[show_first]+' vvv']),attr[0],attr[1])
self.overlay = self.ComboSpace(list,body,ui,show_first,pos=(len(str)+1,row))
# Unicode will kill me sooner or later. ^_^ # Unicode will kill me sooner or later. ^_^
w = urwid.Columns([('fixed',len(str),self.label),self.cbox,('fixed',3,urwid.Text("vvv"))],dividechars=1) if label != '':
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
self.overlay = self.ComboSpace(list,body,ui,show_first,pos=(len(str)+1,row))
else:
w = urwid.Columns([self.cbox])
self.overlay = self.ComboSpace(list,body,ui,show_first,pos=(0,row))
self.__super.__init__(w) self.__super.__init__(w)
# We need this to control the keypress # We need this to control the keypress
self.body = body self.body = body
self.ui = ui self.ui = ui
self.use_enter = use_enter
# 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):
if key == ' ' or key == 'enter': activate = key == ' '
if self.use_enter:
activate = activate or key == 'enter'
if activate:
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)) self.cbox.set_w(SelText(retval+' vvv'))
return self._w.keypress(size,key) return self._w.keypress(size,key)
# Most obvious thing ever. :-) # Most obvious thing ever. :-)
def selectable(self): def selectable(self):
return True return True
# Return a tuple of (widget,position)
def get_selected(self):
return self.overlay._listbox.get_focus()

View File

@@ -20,7 +20,7 @@
import urwid import urwid
from wicd import misc from wicd import misc
from curses_misc import SelText,ToggleEdit,ComboText from curses_misc import SelText,ToggleEdit,ComboText,TabColumns
# Will work for now, I guess. # Will work for now, I guess.
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
@@ -28,9 +28,11 @@ language = misc.get_language_list_gui()
class PrefOverlay(urwid.WidgetWrap): class PrefOverlay(urwid.WidgetWrap):
def __init__(self,body,pos,ui): def __init__(self,body,pos,ui):
self.ui = ui self.ui = ui
# We are on a VT100, I presume.
width = 80 width,height = ui.get_cols_rows()
height = 20 height -= 3
#width = 80
#height = 20
# Stuff that goes at the top # Stuff that goes at the top
header0_t = language["gen_settings"] header0_t = language["gen_settings"]
header1_t = language["ext_programs"] header1_t = language["ext_programs"]
@@ -205,48 +207,53 @@ class PrefOverlay(urwid.WidgetWrap):
self.auto_reconn_cat, self.auto_reconn_cat,
self.auto_reconn]) self.auto_reconn])
headerList = [self.header0,self.header1,self.header2]
pileList = [generalPile,externalPile,advancedPile]
self.tab_map = {self.header0 : generalPile, self.tab_map = {self.header0 : generalPile,
self.header1 : externalPile, self.header1 : externalPile,
self.header2 : advancedPile} self.header2 : advancedPile}
self.active_tab = self.header0 #self.active_tab = self.header0
self.columns = urwid.Columns([('fixed',len(header0_t),self.header0), #self.columns = urwid.Columns([('fixed',len(header0_t),self.header0),
('fixed',len(header1_t),self.header1), # ('fixed',len(header1_t),self.header1),
('fixed',len(header2_t),self.header2), # ('fixed',len(header2_t),self.header2),
urwid.Text(('header',title),align='right')], # urwid.Text(('header',title),align='right')],
dividechars=1) # dividechars=1)
content = [self.columns,generalPile] #content = [self.columns,generalPile]
#self._label = urwid.AttrWrap(SelText(titles),attr[0],attr[1]) #self._label = urwid.AttrWrap(SelText(titles),attr[0],attr[1])
self.walker = urwid.SimpleListWalker(content) #self.walker = urwid.SimpleListWalker(content)
self._listbox = urwid.ListBox(self.walker) #self.listbox = urwid.ListBox(self.walker)
#self._linebox = urwid.LineBox(self._listbox) #self._linebox = urwid.LineBox(self._listbox)
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]), self.tabs = TabColumns(headerList,pileList,'Preferences')
overlay = urwid.Overlay(self.tabs, body, ('fixed left', pos[0]),
width + 2, ('fixed top', pos[1]), height) width + 2, ('fixed top', pos[1]), height)
self.__super.__init__(overlay) self.__super.__init__(overlay)
def global_dns_trigger(self,check_box,new_state,user_data=None): def global_dns_trigger(self,check_box,new_state,user_data=None):
for w in self.search_dom,self.dns1,self.dns2,self.dns3: for w in self.search_dom,self.dns1,self.dns2,self.dns3:
w.set_sensitive(new_state) w.set_sensitive(new_state)
# Normal keypress, but if we are at the top, then be "tabbish" instead # Normal keypress, but if we are at the top, then be "tabbish" instead
def keypress(self,size,ui): #def keypress(self,size,ui):
self._w.keypress(size,ui) # self._w.keypress(size,ui)
(wid,pos) = self._listbox.get_focus() # (wid,pos) = self._listbox.get_focus()
if wid is self.columns: # if wid is self.columns:
lw = self._listbox.body # lw = self.listbox.body
lw.pop(1) # lw.pop(1)
self.active_tab.set_attr('body') # self.active_tab.set_attr('body')
self.columns.get_focus().set_attr('tab active') # self.columns.get_focus().set_attr('tab active')
self.active_tab = self.columns.get_focus() # self.active_tab = self.columns.get_focus()
lw.append(self.tab_map[self.columns.get_focus()]) # lw.append(self.tab_map[self.columns.get_focus()])
self._listbox.body = lw # self.listbox.body = lw
#@wrap_exceptions() #@wrap_exceptions()
# Put the widget into an overlay, and run!
def run(self,ui, dim, display): def run(self,ui, dim, display):
# If we are small, "tabbify" the interface
# Else, pile it together
global app
#dialog = TabbedOverlay(["Foo", "Bar", "Quit"], #dialog = TabbedOverlay(["Foo", "Bar", "Quit"],
# ('body', 'focus'), (1, 1), display) # ('body', 'focus'), (1, 1), display)

View File

@@ -53,9 +53,10 @@ from wicd import dbusmanager
# Internal Python stuff # Internal Python stuff
import sys import sys
from time import sleep
# Curses UIs for other stuff # Curses UIs for other stuff
from curses_misc import SelText from curses_misc import SelText,ComboText
import prefs_curses import prefs_curses
from prefs_curses import PrefOverlay from prefs_curses import PrefOverlay
@@ -106,6 +107,7 @@ class wrap_exceptions:
# backtrace # backtrace
sys.stdout.flush() sys.stdout.flush()
# Raise the exception # Raise the exception
#sleep(2)
raise raise
return wrap_exceptions return wrap_exceptions
@@ -182,10 +184,12 @@ def gen_network_list():
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
if is_active: if is_active:
theString = '>'+theString[1:] theString = '>'+theString[1:]
wiredL.append(urwid.AttrWrap(SelText(theString),'connected',
'connected focus')) #wiredL.append(urwid.AttrWrap(SelText(theString),'connected',
else: # 'connected focus'))
wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) #else:
# wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
wiredL.append(theString)
id+=1 id+=1
wlessL = [] wlessL = []
@@ -232,8 +236,21 @@ class appGUI():
self.wiredH=urwid.Filler(urwid.Text("Wired Network(s)")) self.wiredH=urwid.Filler(urwid.Text("Wired Network(s)"))
self.wlessH=urwid.Filler(urwid.Text("Wireless Network(s)")) self.wlessH=urwid.Filler(urwid.Text("Wireless Network(s)"))
self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body')
self.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important')
self.footerList = urwid.ListBox([self.footer1,self.footer2])
# Pop takes a number!
#walker.pop(1)
nothingness = urwid.Filler(urwid.Text('Hello, world!'))
self.frame = urwid.Frame(nothingness,
header=header,
footer=urwid.BoxAdapter(self.footerList,2))
self.frame.set_focus('body')
# Miiiiiiiiiiight be changing this back to something like how it was
# originally
wiredL,wlessL = gen_network_list() wiredL,wlessL = gen_network_list()
self.wiredLB = urwid.ListBox(wiredL) self.wiredCB = urwid.Filler(ComboText('',wiredL,self.frame,ui,3,use_enter=False))
self.wlessLB = urwid.ListBox(wlessL) self.wlessLB = urwid.ListBox(wlessL)
# Stuff I used to simulate large lists # Stuff I used to simulate large lists
#spam = SelText('spam') #spam = SelText('spam')
@@ -244,19 +261,11 @@ class appGUI():
# spam,spam,spam,spam] ] # spam,spam,spam,spam] ]
#self.spamLB = urwid.ListBox(spamL) #self.spamLB = urwid.ListBox(spamL)
self.thePile = urwid.Pile([('fixed',1,self.wiredH), self.thePile = urwid.Pile([('fixed',1,self.wiredH),
('fixed',1,self.wiredLB), ('fixed',1,self.wiredCB),
('fixed',1,self.wlessH), ('fixed',1,self.wlessH),
self.wlessLB] ) self.wlessLB] )
self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body')
self.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important')
self.footerList = urwid.ListBox([self.footer1,self.footer2])
# Pop takes a number!
#walker.pop(1)
self.frame = urwid.Frame(self.thePile,
header=header,
footer=urwid.BoxAdapter(self.footerList,2))
self.frame.set_focus('body')
self.frame.set_body(self.thePile)
# Booleans gallore! # Booleans gallore!
self.prev_state = False self.prev_state = False
self.connecting = False self.connecting = False
@@ -291,7 +300,8 @@ class appGUI():
state, x = daemon.GetConnectionStatus() state, x = daemon.GetConnectionStatus()
if self.prev_state != state or force_check: if self.prev_state != state or force_check:
wiredL,wlessL = gen_network_list() wiredL,wlessL = gen_network_list()
self.wiredLB.body = urwid.SimpleListWalker(wiredL) self.wiredCB = urwid.Filler(ComboText('',wiredL,self.frame,ui,3,
use_enter=False))
self.wlessLB.body = urwid.SimpleListWalker(wlessL) self.wlessLB.body = urwid.SimpleListWalker(wlessL)
self.prev_state = state self.prev_state = state
@@ -410,7 +420,6 @@ class appGUI():
self.update_netlist() self.update_netlist()
if "esc" in keys: if "esc" in keys:
# Force disconnect here if connection in progress # Force disconnect here if connection in progress
if self.connecting:
daemon.CancelConnect() daemon.CancelConnect()
# Prevents automatic reconnecting if that option is enabled # Prevents automatic reconnecting if that option is enabled
daemon.SetForcedDisconnect(True) daemon.SetForcedDisconnect(True)
@@ -422,18 +431,23 @@ 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 )
return True
# Terminate the loop, used as the glib mainloop's idle function if " " in keys:
def stop_loop(self): # I can't really tell if this works ^_^.
loop.quit() if self.thePile.get_focus() == self.wiredCB:
wid,pos = self.wiredCB.get_body().get_selected()
text,attr = wid.get_text()
wired.ReadWiredNetworkProfile(text)
return True
# Bring back memories, anyone? # Bring back memories, anyone?
def call_connect(self): def call_connect(self):
wid = self.thePile.get_focus() wid = self.thePile.get_focus()
if wid is self.wiredLB: if wid is self.wiredCB:
wid2,pos = self.wiredLB.get_focus() #wid2,pos = self.wiredCB.get_focus()
self.connect(self,'wired',pos) # Apparently, connect() doesn't care about the networkid
self.connect(self,'wired',0)
#return "Wired network %i" % pos #return "Wired network %i" % pos
if wid is self.wlessLB: if wid is self.wlessLB:
#self.footer1 = urwid.Text("Wireless!") #self.footer1 = urwid.Text("Wireless!")
@@ -472,7 +486,7 @@ def main():
# Other potential color schemes can be found at: # Other potential color schemes can be found at:
# http://excess.org/urwid/wiki/RecommendedPalette # http://excess.org/urwid/wiki/RecommendedPalette
# Note: the current palette below is optimized for the linux console. # Note: the current palette below is optimized for the linux console.
# For example, this will look like crap on a default-colored XTerm. # For example, this looks particularly bad on a default-colored XTerm.
# NB: To find current terminal background use variable COLORFGBG # NB: To find current terminal background use variable COLORFGBG
ui.register_palette([ ui.register_palette([
('body','light gray','default'), ('body','light gray','default'),