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

Checkpoint in getting the Preferences dialog functional. There's still some tweaking left to do.

curses/curses_misc.py: Changed the internal layout of the widgets to allow me to stick buttons on the bottom.
curses/prefs_curses.py: Added rudimentary Dbus support to the dialog.
Started getting the config settings to save to wicd.
Added buttons (which don't do anything yet).
The PrefOverlay has been renamed to PrefsDialog.  The PrefsDialog widget is wrapped around a TabColumns widget.
Added a main entry point into the file to allow for somewhat easier testing.  It can now be called indepentently of wicd-curses, if needed.
curses/wicd-curses.py: Undid a change that caused the ESC key to disconnect from the current network, in addition to its current function.
This commit is contained in:
Andrew Psaltis
2008-12-29 22:04:40 -05:00
parent 5c4266f2f2
commit 2db3b3e60d
3 changed files with 163 additions and 89 deletions

View File

@@ -79,8 +79,9 @@ class TabColumns(urwid.WidgetWrap):
attr = normal attributes
attrsel = attribute when active
"""
def __init__(self,tab_str,tab_wid,title,attr=('body','focus'),attrsel='tab active',
attrtitle='header'):
def __init__(self,tab_str,tab_wid,title,bottom_part,attr=('body','focus'),
attrsel='tab active', attrtitle='header'):
self.bottom_part = bottom_part
#title_wid = urwid.Text((attrtitle,title),align='right')
column_list = []
for w in tab_str:
@@ -91,23 +92,38 @@ class TabColumns(urwid.WidgetWrap):
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)
#walker = urwid.SimpleListWalker([self.columns,tab_wid[0]])
#self.listbox = urwid.ListBox(walker)
self.gen_pile(tab_wid[0],True)
self.frame = urwid.Frame(self.pile)
self.__super.__init__(self.frame)
# Make the pile in the middle
def gen_pile(self,lbox,firstrun=False):
self.pile = urwid.Pile([
('fixed',1,urwid.Filler(self.columns,'top')),
urwid.Filler(lbox,'top',height=('relative',99)),
('fixed',1,urwid.Filler(self.bottom_part,'bottom'))
])
if not firstrun:
self.frame.set_body(self.pile)
self.set_w(self.frame)
def selectable(self):
return True
def keypress(self,size,key):
self._w.keypress(size,key)
(wid,pos) = self.listbox.get_focus()
if wid is self.columns:
lw = self.listbox.body
lw.pop(1)
wid = self.pile.get_focus().get_body()
if wid == 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
self.gen_pile(self.tab_map[self.active_tab])
return key
# self.listbox.body = lw
# A "combo box" of SelTexts
# I based this off of the code found here:
@@ -182,7 +198,8 @@ class ComboText(urwid.WidgetWrap):
self.label = urwid.Text(label)
str,trash = self.label.get_text()
self.cbox = urwid.AttrWrap(SelText([list[show_first]+' vvv']),attr[0],attr[1])
self.cbox = urwid.AttrWrap(SelText([list[show_first]+' vvv']),
attr[0],attr[1])
# Unicode will kill me sooner or later. ^_^
if label != '':
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)

View File

@@ -18,17 +18,27 @@
# MA 02110-1301, USA.
import urwid
import urwid.curses_display
from wicd import misc
from wicd import dbusmanager
from curses_misc import SelText,ToggleEdit,ComboText,TabColumns
daemon = None
wireless = None
wired = None
# Will work for now, I guess.
language = misc.get_language_list_gui()
class PrefOverlay(urwid.WidgetWrap):
def __init__(self,body,pos,ui):
class PrefsDialog(urwid.WidgetWrap):
def __init__(self,body,pos,ui,dbus=None):
global daemon, wireless, wired
self.ui = ui
daemon = dbus['daemon']
wireless = dbus['wireless']
wired = dbus['wired']
width,height = ui.get_cols_rows()
height -= 3
#width = 80
@@ -117,26 +127,26 @@ class PrefOverlay(urwid.WidgetWrap):
self.global_dns_cat = urwid.Text(global_dns_cat_t)
global_dns_state = False
self.global_dns = urwid.CheckBox(global_dns_t,global_dns_state,
self.global_dns_checkb = urwid.CheckBox(global_dns_t,global_dns_state,
on_state_change=self.global_dns_trigger)
self.search_dom = ToggleEdit(search_dom_t,global_dns_state)
self.dns1 = ToggleEdit(dns1_t,global_dns_state)
self.dns2 = ToggleEdit(dns2_t,global_dns_state)
self.dns3 = ToggleEdit(dns3_t,global_dns_state)
self.always_show_wired = urwid.CheckBox(always_show_wired_t)
self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)
wired_auto_l = []
self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
self.wired_auto_1 = urwid.RadioButton(wired_auto_l,wired_auto_1_t)
self.wired_auto_2 = urwid.RadioButton(wired_auto_l,wired_auto_2_t)
self.wired_auto_3 = urwid.RadioButton(wired_auto_l,wired_auto_3_t)
generalPile = urwid.Pile([self.net_cat,
generalLB = urwid.ListBox([self.net_cat,
self.wless_iface,#self._blank,
self.wired_iface,
self.always_show_wired,self._blank,
self.always_show_wired_checkb,self._blank,
self.global_dns_cat,
self.global_dns,#self._blank,
self.global_dns_checkb,#self._blank,
self.search_dom,
self.dns1,self.dns2,self.dns3,self._blank,
self.wired_auto_cat,
@@ -168,7 +178,7 @@ class PrefOverlay(urwid.WidgetWrap):
self.route1 = urwid.RadioButton(route_l,route1_t)
self.route2 = urwid.RadioButton(route_l,route2_t)
externalPile = urwid.Pile([self.dhcp_header,
externalLB = urwid.ListBox([self.dhcp_header,
self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,
self._blank,
self.wired_detect_header,
@@ -188,31 +198,43 @@ class PrefOverlay(urwid.WidgetWrap):
self.backend_cbox = ComboText(backend_t,backend_list,self,ui,8)
self.debug_cat = urwid.Text(debug_cat_t)
self.debug_mode = urwid.CheckBox(debug_mode_t)
self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)
self.wless_cat = urwid.Text(wless_cat_t)
self.use_dbm = 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 = urwid.CheckBox(auto_reconn_t)
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
advancedPile = urwid.Pile([self.wpa_cat,
advancedLB = urwid.ListBox([self.wpa_cat,
self.wpa_cbox,self.wpa_warn,self._blank,
self.backend_cat,
self.backend_cbox,self._blank,
self.debug_cat,
self.debug_mode, self._blank,
self.debug_mode_checkb, self._blank,
self.wless_cat,
self.use_dbm, self._blank,
self.use_dbm_checkb, self._blank,
self.auto_reconn_cat,
self.auto_reconn])
self.auto_reconn_checkb])
headerList = [self.header0,self.header1,self.header2]
pileList = [generalPile,externalPile,advancedPile]
self.tab_map = {self.header0 : generalPile,
self.header1 : externalPile,
self.header2 : advancedPile}
lbList = [generalLB,externalLB,advancedLB]
self.tab_map = {self.header0 : generalLB,
self.header1 : externalLB,
self.header2 : advancedLB}
self.load_settings()
# Now for the buttons:
ok_t = 'OK'
cancel_t = 'Cancel'
ok_button = urwid.AttrWrap(urwid.Button('OK'),'body','focus')
cancel_button = urwid.AttrWrap(urwid.Button('Cancel'),'body','focus')
self.button_cols = urwid.Columns([ok_button,cancel_button])
#self.active_tab = self.header0
#self.columns = urwid.Columns([('fixed',len(header0_t),self.header0),
@@ -226,10 +248,20 @@ class PrefOverlay(urwid.WidgetWrap):
#self.walker = urwid.SimpleListWalker(content)
#self.listbox = urwid.ListBox(self.walker)
#self._linebox = urwid.LineBox(self._listbox)
self.tabs = TabColumns(headerList,pileList,'Preferences')
overlay = urwid.Overlay(self.tabs, body, ('fixed left', pos[0]),
width + 2, ('fixed top', pos[1]), height)
self.__super.__init__(overlay)
self.tabs = TabColumns(headerList,lbList,'Preferences',self.button_cols)
#overlay = urwid.Overlay(self.tabs, body, ('fixed left', pos[0]),
# width, ('fixed top', pos[1]), height)
self.__super.__init__(self.tabs)
def load_settings(self):
self.always_show_wired_checkb.set_state(
daemon.GetAlwaysShowWiredInterface())
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
self.debug_mode_checkb.set_state(daemon.GetDebugMode())
self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
def store_results(self):
daemon.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state())
def global_dns_trigger(self,check_box,new_state,user_data=None):
for w in self.search_dom,self.dns1,self.dns2,self.dns3:
@@ -250,9 +282,12 @@ class PrefOverlay(urwid.WidgetWrap):
#@wrap_exceptions()
# Put the widget into an overlay, and run!
def run(self,ui, dim, display):
width,height = ui.get_cols_rows()
# If we are small, "tabbify" the interface
# Else, pile it together
overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width
, ('fixed top',1), height-3)
#dialog = TabbedOverlay(["Foo", "Bar", "Quit"],
# ('body', 'focus'), (1, 1), display)
@@ -261,7 +296,7 @@ class PrefOverlay(urwid.WidgetWrap):
keys = True
while True:
if keys:
ui.draw_screen(dim, self.render(dim, True))
ui.draw_screen(dim, overlay.render(dim, True))
keys = ui.get_input()
if "window resize" in keys:
@@ -271,20 +306,45 @@ class PrefOverlay(urwid.WidgetWrap):
for k in keys:
#Send key to underlying widget:
self.keypress(dim, k)
overlay.keypress(dim, k)
#if program_menu.selected == "Quit":
# return
def run():
dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces())
keys = True
dim = ui.get_cols_rows()
while True:
if keys:
ui.draw_screen(dim, dialog.render(dim, True))
keys = ui.get_input()
#if program_menu.selected == "Foo":
#Do something
# return
if "window resize" in keys:
dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys:
return
#if program_menu.selected == "Bar":
#Do something
#return
for k in keys:
#Send key to underlying widget:
dialog.keypress(dim, k)
#@wrap_exceptions()
#def run_dialog(ui,dim,display,dialog):
# pass
#Event loop:
if __name__=='__main__':
try:
dbusmanager.connect_to_dbus()
except DBusException:
# I may need to be a little more verbose here.
# 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
ui = urwid.curses_display.Screen()
ui.register_palette([
('body','light gray','default'),
('focus','dark magenta','light gray'),
('header','light blue','default'),
('important','light red','default'),
('connected','dark green','default'),
('connected focus','default','dark green'),
('editcp', 'default', 'default', 'standout'),
('editbx', 'light gray', 'dark blue'),
('editfc', 'white','dark blue', 'bold'),
('tab active','dark green','light gray')])
ui.run_wrapper(run)

View File

@@ -42,8 +42,8 @@ import urwid.curses_display
import urwid
# DBus communication stuff
import dbus
import dbus.service
from dbus import DBusException
from dbus import version as dbus_version
# It took me a while to figure out that I have to use this.
import gobject
@@ -58,13 +58,7 @@ from time import sleep
# Curses UIs for other stuff
from curses_misc import SelText,ComboText
import prefs_curses
from prefs_curses import PrefOverlay
if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0):
import dbus.glib
else:
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
from prefs_curses import PrefsDialog
language = misc.get_language_list_gui()
# Whew. Now on to more interesting stuff:
@@ -430,12 +424,15 @@ class appGUI():
self.update_netlist()
if "esc" in keys:
# Force disconnect here if connection in progress
if self.connecting:
daemon.CancelConnect()
# Prevents automatic reconnecting if that option is enabled
daemon.SetForcedDisconnect(True)
if "P" in keys:
dialog = PrefOverlay(self.frame,(0,1),ui)
dialog = PrefsDialog(self.frame,(0,1),ui,
dbusmanager.get_dbus_ifaces())
dialog.run(ui,self.size,self.frame)
dialog.store_results()
for k in keys:
if k == "window resize":
self.size = ui.get_cols_rows()