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:
@@ -79,8 +79,9 @@ class TabColumns(urwid.WidgetWrap):
|
|||||||
attr = normal attributes
|
attr = normal attributes
|
||||||
attrsel = attribute when active
|
attrsel = attribute when active
|
||||||
"""
|
"""
|
||||||
def __init__(self,tab_str,tab_wid,title,attr=('body','focus'),attrsel='tab active',
|
def __init__(self,tab_str,tab_wid,title,bottom_part,attr=('body','focus'),
|
||||||
attrtitle='header'):
|
attrsel='tab active', attrtitle='header'):
|
||||||
|
self.bottom_part = bottom_part
|
||||||
#title_wid = urwid.Text((attrtitle,title),align='right')
|
#title_wid = urwid.Text((attrtitle,title),align='right')
|
||||||
column_list = []
|
column_list = []
|
||||||
for w in tab_str:
|
for w in tab_str:
|
||||||
@@ -91,23 +92,38 @@ class TabColumns(urwid.WidgetWrap):
|
|||||||
self.tab_map = dict(zip(tab_str,tab_wid))
|
self.tab_map = dict(zip(tab_str,tab_wid))
|
||||||
self.active_tab = tab_str[0]
|
self.active_tab = tab_str[0]
|
||||||
self.columns = urwid.Columns(column_list,dividechars=1)
|
self.columns = urwid.Columns(column_list,dividechars=1)
|
||||||
walker = urwid.SimpleListWalker([self.columns,tab_wid[0]])
|
#walker = urwid.SimpleListWalker([self.columns,tab_wid[0]])
|
||||||
self.listbox = urwid.ListBox(walker)
|
#self.listbox = urwid.ListBox(walker)
|
||||||
self.__super.__init__(self.listbox)
|
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):
|
def selectable(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def keypress(self,size,key):
|
def keypress(self,size,key):
|
||||||
self._w.keypress(size,key)
|
self._w.keypress(size,key)
|
||||||
(wid,pos) = self.listbox.get_focus()
|
wid = self.pile.get_focus().get_body()
|
||||||
if wid is self.columns:
|
if wid == 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()])
|
self.gen_pile(self.tab_map[self.active_tab])
|
||||||
self.listbox.body = lw
|
return key
|
||||||
|
# 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:
|
||||||
@@ -182,7 +198,8 @@ 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]+' 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. ^_^
|
# Unicode will kill me sooner or later. ^_^
|
||||||
if label != '':
|
if label != '':
|
||||||
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
|
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
|
||||||
|
|||||||
@@ -18,17 +18,27 @@
|
|||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
import urwid.curses_display
|
||||||
|
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
|
from wicd import dbusmanager
|
||||||
from curses_misc import SelText,ToggleEdit,ComboText,TabColumns
|
from curses_misc import SelText,ToggleEdit,ComboText,TabColumns
|
||||||
|
|
||||||
|
daemon = None
|
||||||
|
wireless = None
|
||||||
|
wired = None
|
||||||
# Will work for now, I guess.
|
# Will work for now, I guess.
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
|
|
||||||
class PrefOverlay(urwid.WidgetWrap):
|
class PrefsDialog(urwid.WidgetWrap):
|
||||||
def __init__(self,body,pos,ui):
|
def __init__(self,body,pos,ui,dbus=None):
|
||||||
|
global daemon, wireless, wired
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
|
|
||||||
|
daemon = dbus['daemon']
|
||||||
|
wireless = dbus['wireless']
|
||||||
|
wired = dbus['wired']
|
||||||
|
|
||||||
width,height = ui.get_cols_rows()
|
width,height = ui.get_cols_rows()
|
||||||
height -= 3
|
height -= 3
|
||||||
#width = 80
|
#width = 80
|
||||||
@@ -117,32 +127,32 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
|
|
||||||
self.global_dns_cat = urwid.Text(global_dns_cat_t)
|
self.global_dns_cat = urwid.Text(global_dns_cat_t)
|
||||||
global_dns_state = False
|
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)
|
on_state_change=self.global_dns_trigger)
|
||||||
self.search_dom = ToggleEdit(search_dom_t,global_dns_state)
|
self.search_dom = ToggleEdit(search_dom_t,global_dns_state)
|
||||||
self.dns1 = ToggleEdit(dns1_t,global_dns_state)
|
self.dns1 = ToggleEdit(dns1_t,global_dns_state)
|
||||||
self.dns2 = ToggleEdit(dns2_t,global_dns_state)
|
self.dns2 = ToggleEdit(dns2_t,global_dns_state)
|
||||||
self.dns3 = ToggleEdit(dns3_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 = []
|
wired_auto_l = []
|
||||||
self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
|
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_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_2 = urwid.RadioButton(wired_auto_l,wired_auto_2_t)
|
||||||
self.wired_auto_3 = urwid.RadioButton(wired_auto_l,wired_auto_3_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.wless_iface,#self._blank,
|
||||||
self.wired_iface,
|
self.wired_iface,
|
||||||
self.always_show_wired,self._blank,
|
self.always_show_wired_checkb,self._blank,
|
||||||
self.global_dns_cat,
|
self.global_dns_cat,
|
||||||
self.global_dns,#self._blank,
|
self.global_dns_checkb,#self._blank,
|
||||||
self.search_dom,
|
self.search_dom,
|
||||||
self.dns1,self.dns2,self.dns3,self._blank,
|
self.dns1,self.dns2,self.dns3,self._blank,
|
||||||
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
|
||||||
])
|
])
|
||||||
|
|
||||||
#### External Programs tab
|
#### External Programs tab
|
||||||
@@ -168,15 +178,15 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
self.route1 = urwid.RadioButton(route_l,route1_t)
|
self.route1 = urwid.RadioButton(route_l,route1_t)
|
||||||
self.route2 = urwid.RadioButton(route_l,route2_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.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,
|
||||||
self._blank,
|
self._blank,
|
||||||
self.wired_detect_header,
|
self.wired_detect_header,
|
||||||
self.wired0,self.wired1,self.wired2,
|
self.wired0,self.wired1,self.wired2,
|
||||||
self._blank,
|
self._blank,
|
||||||
self.route_table_header,
|
self.route_table_header,
|
||||||
self.route0,self.route1,self.route2
|
self.route0,self.route1,self.route2
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
#### Advanced settings
|
#### Advanced settings
|
||||||
@@ -187,32 +197,44 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
self.backend_cat = urwid.Text(backend_cat_t)
|
self.backend_cat = urwid.Text(backend_cat_t)
|
||||||
self.backend_cbox = ComboText(backend_t,backend_list,self,ui,8)
|
self.backend_cbox = ComboText(backend_t,backend_list,self,ui,8)
|
||||||
|
|
||||||
self.debug_cat = urwid.Text(debug_cat_t)
|
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.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_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.wpa_cbox,self.wpa_warn,self._blank,
|
||||||
self.backend_cat,
|
self.backend_cat,
|
||||||
self.backend_cbox,self._blank,
|
self.backend_cbox,self._blank,
|
||||||
self.debug_cat,
|
self.debug_cat,
|
||||||
self.debug_mode, self._blank,
|
self.debug_mode_checkb, self._blank,
|
||||||
self.wless_cat,
|
self.wless_cat,
|
||||||
self.use_dbm, self._blank,
|
self.use_dbm_checkb, self._blank,
|
||||||
self.auto_reconn_cat,
|
self.auto_reconn_cat,
|
||||||
self.auto_reconn])
|
self.auto_reconn_checkb])
|
||||||
|
|
||||||
|
|
||||||
headerList = [self.header0,self.header1,self.header2]
|
headerList = [self.header0,self.header1,self.header2]
|
||||||
pileList = [generalPile,externalPile,advancedPile]
|
lbList = [generalLB,externalLB,advancedLB]
|
||||||
self.tab_map = {self.header0 : generalPile,
|
self.tab_map = {self.header0 : generalLB,
|
||||||
self.header1 : externalPile,
|
self.header1 : externalLB,
|
||||||
self.header2 : advancedPile}
|
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.active_tab = self.header0
|
||||||
|
|
||||||
#self.columns = urwid.Columns([('fixed',len(header0_t),self.header0),
|
#self.columns = urwid.Columns([('fixed',len(header0_t),self.header0),
|
||||||
@@ -226,11 +248,21 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
#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)
|
||||||
self.tabs = TabColumns(headerList,pileList,'Preferences')
|
self.tabs = TabColumns(headerList,lbList,'Preferences',self.button_cols)
|
||||||
overlay = urwid.Overlay(self.tabs, body, ('fixed left', pos[0]),
|
#overlay = urwid.Overlay(self.tabs, body, ('fixed left', pos[0]),
|
||||||
width + 2, ('fixed top', pos[1]), height)
|
# width, ('fixed top', pos[1]), height)
|
||||||
self.__super.__init__(overlay)
|
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):
|
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)
|
||||||
@@ -250,9 +282,12 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
#@wrap_exceptions()
|
#@wrap_exceptions()
|
||||||
# Put the widget into an overlay, and run!
|
# Put the widget into an overlay, and run!
|
||||||
def run(self,ui, dim, display):
|
def run(self,ui, dim, display):
|
||||||
|
width,height = ui.get_cols_rows()
|
||||||
# If we are small, "tabbify" the interface
|
# If we are small, "tabbify" the interface
|
||||||
|
|
||||||
# Else, pile it together
|
# Else, pile it together
|
||||||
|
overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width
|
||||||
|
, ('fixed top',1), height-3)
|
||||||
|
|
||||||
#dialog = TabbedOverlay(["Foo", "Bar", "Quit"],
|
#dialog = TabbedOverlay(["Foo", "Bar", "Quit"],
|
||||||
# ('body', 'focus'), (1, 1), display)
|
# ('body', 'focus'), (1, 1), display)
|
||||||
@@ -261,7 +296,7 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
keys = True
|
keys = True
|
||||||
while True:
|
while True:
|
||||||
if keys:
|
if keys:
|
||||||
ui.draw_screen(dim, self.render(dim, True))
|
ui.draw_screen(dim, overlay.render(dim, True))
|
||||||
keys = ui.get_input()
|
keys = ui.get_input()
|
||||||
|
|
||||||
if "window resize" in keys:
|
if "window resize" in keys:
|
||||||
@@ -271,20 +306,45 @@ class PrefOverlay(urwid.WidgetWrap):
|
|||||||
|
|
||||||
for k in keys:
|
for k in keys:
|
||||||
#Send key to underlying widget:
|
#Send key to underlying widget:
|
||||||
self.keypress(dim, k)
|
overlay.keypress(dim, k)
|
||||||
|
|
||||||
#if program_menu.selected == "Quit":
|
def run():
|
||||||
# return
|
dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces())
|
||||||
|
keys = True
|
||||||
#if program_menu.selected == "Foo":
|
dim = ui.get_cols_rows()
|
||||||
#Do something
|
while True:
|
||||||
# return
|
if keys:
|
||||||
|
ui.draw_screen(dim, dialog.render(dim, True))
|
||||||
|
keys = ui.get_input()
|
||||||
|
|
||||||
#if program_menu.selected == "Bar":
|
if "window resize" in keys:
|
||||||
#Do something
|
dim = ui.get_cols_rows()
|
||||||
#return
|
if "esc" in keys or 'Q' in keys:
|
||||||
|
return
|
||||||
|
|
||||||
#@wrap_exceptions()
|
for k in keys:
|
||||||
#def run_dialog(ui,dim,display,dialog):
|
#Send key to underlying widget:
|
||||||
# pass
|
dialog.keypress(dim, k)
|
||||||
#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)
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ import urwid.curses_display
|
|||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
# DBus communication stuff
|
# DBus communication stuff
|
||||||
import dbus
|
from dbus import DBusException
|
||||||
import dbus.service
|
from dbus import version as dbus_version
|
||||||
# It took me a while to figure out that I have to use this.
|
# It took me a while to figure out that I have to use this.
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
@@ -58,13 +58,7 @@ from time import sleep
|
|||||||
# Curses UIs for other stuff
|
# Curses UIs for other stuff
|
||||||
from curses_misc import SelText,ComboText
|
from curses_misc import SelText,ComboText
|
||||||
import prefs_curses
|
import prefs_curses
|
||||||
from prefs_curses import PrefOverlay
|
from prefs_curses import PrefsDialog
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
# Whew. Now on to more interesting stuff:
|
# Whew. Now on to more interesting stuff:
|
||||||
@@ -430,12 +424,15 @@ 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
|
||||||
daemon.CancelConnect()
|
if self.connecting:
|
||||||
# Prevents automatic reconnecting if that option is enabled
|
daemon.CancelConnect()
|
||||||
daemon.SetForcedDisconnect(True)
|
# Prevents automatic reconnecting if that option is enabled
|
||||||
|
daemon.SetForcedDisconnect(True)
|
||||||
if "P" in keys:
|
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.run(ui,self.size,self.frame)
|
||||||
|
dialog.store_results()
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if k == "window resize":
|
if k == "window resize":
|
||||||
self.size = ui.get_cols_rows()
|
self.size = ui.get_cols_rows()
|
||||||
|
|||||||
Reference in New Issue
Block a user