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

curses/curses_misc.py:

Added a get_edit_text function to ToggleEdit.
  Changed the get_selected function in ComboBox to return the index only.
curses/prefs_curses.py:
  Completed the load+save functions of the UI
  Buttons are now functional.  Only selecting the OK button will save the data for now.
curses/wicd-curses.py:
  Added support for the "Always Show Wired Interface" config option
  Completed support for the preferences dialog
curses/TODO,README: Preferences dialog is done. :-)
This commit is contained in:
Andrew Psaltis
2008-12-30 23:10:18 -05:00
parent 5fd6cca50b
commit 64741b032a
4 changed files with 181 additions and 58 deletions

View File

@@ -1,8 +1,6 @@
Things to do (in no particular order): Things to do (in no particular order):
* Make a settings dialog -- Finish the backend. The frontend is pretty much * Make a network config dialog for both wireless and wired interfaces
done.
* Make a network config dialog
* Make an about dialog * Make an about dialog
* Implement a keyhandler function for the overall frame * Implement a keyhandler function for the overall frame
* Make keystrokes customizable * Make keystrokes customizable

View File

@@ -67,6 +67,9 @@ class ToggleEdit(urwid.WidgetWrap):
def set_edit_text(self,text): def set_edit_text(self,text):
self._w.set_edit_text(text) self._w.set_edit_text(text)
def get_edit_text(self):
return self._w.get_edit_text()
# If we aren't sensitive, don't be selectable # If we aren't sensitive, don't be selectable
def selectable(self): def selectable(self):
return self.sensitive return self.sensitive
@@ -75,7 +78,7 @@ 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)
# Tabbed interface # Tabbed interface, mostly for use in the Preferences Dialog
class TabColumns(urwid.WidgetWrap): class TabColumns(urwid.WidgetWrap):
""" """
titles_dict = dictionary of tab_contents (a SelText) : tab_widget (box) titles_dict = dictionary of tab_contents (a SelText) : tab_widget (box)
@@ -265,6 +268,7 @@ class ComboBox(urwid.WidgetWrap):
def selectable(self): def selectable(self):
return True return True
# Return a tuple of (widget,position) # Return the index of the selected element
def get_selected(self): def get_selected(self):
return self.overlay._listbox.get_focus() wid,pos = self.overlay._listbox.get_focus()
return pos

View File

@@ -43,6 +43,7 @@ class PrefsDialog(urwid.WidgetWrap):
#width = 80 #width = 80
#height = 20 #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"]
header2_t = language["advanced_settings"] header2_t = language["advanced_settings"]
@@ -52,7 +53,7 @@ class PrefsDialog(urwid.WidgetWrap):
title = language['preferences'] title = language['preferences']
# Blank line # Blank line
self._blank = urwid.Text('') _blank = urwid.Text('')
#### ####
#### Text in the widgets #### Text in the widgets
@@ -137,19 +138,19 @@ class PrefsDialog(urwid.WidgetWrap):
self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t) self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)
wired_auto_l = [] self.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(self.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(self.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(self.wired_auto_l,wired_auto_3_t)
generalLB = urwid.ListBox([self.net_cat, generalLB = urwid.ListBox([self.net_cat,
self.wless_edit,#self._blank, self.wless_edit,#_blank,
self.wired_edit, self.wired_edit,
self.always_show_wired_checkb,self._blank, self.always_show_wired_checkb,_blank,
self.global_dns_cat, self.global_dns_cat,
self.global_dns_checkb,#self._blank, self.global_dns_checkb,#_blank,
self.search_dom, self.search_dom,
self.dns1,self.dns2,self.dns3,self._blank, self.dns1,self.dns2,self.dns3,_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,
@@ -181,10 +182,10 @@ class PrefsDialog(urwid.WidgetWrap):
externalLB = urwid.ListBox([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, _blank,
self.wired_detect_header, self.wired_detect_header,
self.wired0,self.wired1,self.wired2, self.wired0,self.wired1,self.wired2,
self._blank, _blank,
self.flush_header, self.flush_header,
self.flush0,self.flush1,self.flush2 self.flush0,self.flush1,self.flush2
]) ])
@@ -208,13 +209,13 @@ class PrefsDialog(urwid.WidgetWrap):
self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t) self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
advancedLB = urwid.ListBox([self.wpa_cat, advancedLB = urwid.ListBox([self.wpa_cat,
self.wpa_cbox,self.wpa_warn,self._blank, self.wpa_cbox,self.wpa_warn,_blank,
self.backend_cat, self.backend_cat,
self.backend_cbox,self._blank, self.backend_cbox,_blank,
self.debug_cat, self.debug_cat,
self.debug_mode_checkb, self._blank, self.debug_mode_checkb, _blank,
self.wless_cat, self.wless_cat,
self.use_dbm_checkb, self._blank, self.use_dbm_checkb, _blank,
self.auto_reconn_cat, self.auto_reconn_cat,
self.auto_reconn_checkb]) self.auto_reconn_checkb])
@@ -227,15 +228,17 @@ class PrefsDialog(urwid.WidgetWrap):
#self.load_settings() #self.load_settings()
# Now for the buttons: # Now for the buttons:
ok_t = 'OK' ok_t = 'OK'
cancel_t = 'Cancel' cancel_t = 'Cancel'
ok_button = urwid.AttrWrap(urwid.Button('OK'),'body','focus') ok_button = urwid.AttrWrap(urwid.Button('OK',self.ok_callback),'body','focus')
cancel_button = urwid.AttrWrap(urwid.Button('Cancel'),'body','focus') cancel_button = urwid.AttrWrap(urwid.Button('Cancel',self.cancel_callback),'body','focus')
# Variables set by the buttons' callback functions
self.CANCEL_PRESSED = False
self.OK_PRESSED = False
self.button_cols = urwid.Columns([ok_button,cancel_button]) self.button_cols = urwid.Columns([ok_button,cancel_button],dividechars=1)
#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),
@@ -255,37 +258,130 @@ class PrefsDialog(urwid.WidgetWrap):
self.__super.__init__(self.tabs) self.__super.__init__(self.tabs)
def load_settings(self): def load_settings(self):
### General Settings
# Urwid does not like dbus.Strings as text markups
wless_iface = unicode(daemon.GetWirelessInterface())
wired_iface = unicode(daemon.GetWiredInterface())
self.wless_edit.set_edit_text(wless_iface)
self.wired_edit.set_edit_text(wired_iface)
self.always_show_wired_checkb.set_state( self.always_show_wired_checkb.set_state(
daemon.GetAlwaysShowWiredInterface()) daemon.GetAlwaysShowWiredInterface())
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
# DNS
self.global_dns_checkb.set_state(daemon.GetUseGlobalDNS())
theDNS = daemon.GetGlobalDNSAddresses()
i = 0
for w in self.dns1,self.dns2,self.dns3,self.search_dom :
w.set_edit_text(misc.noneToBlankString(theDNS[i]))
i+=1
# Wired Automatic Connection
self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1]
### External Programs
dhcp_method = daemon.GetDHCPClient()
self.dhcp_l[dhcp_method].set_state(True)
wired_link_method = daemon.GetLinkDetectionTool()
self.wired_l[wired_link_method].set_state(True)
flush_method = daemon.GetFlushTool()
self.flush_l[flush_method].set_state(True)
### Advanced settings
# wpa_supplicant janx
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel",
"ndiswrapper", "ipw"]
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
self.wpadrivers.append("ralink_legacy")
# Same as above with the dbus.String
self.thedrivers = [unicode(w) for w in self.wpadrivers]
self.wpa_cbox.set_list(self.thedrivers)
# Pick where to begin first:
def_driver = daemon.GetWPADriver()
try:
self.wpa_cbox.set_show_first(self.wpadrivers.index(def_driver))
except ValueError:
pass # It defaults to 0 anyway
self.backends = daemon.GetBackendList()
# Remove the blank string b/c of some dbus mess
self.backends.remove('')
self.thebackends= [unicode(w) for w in self.backends]
self.backend_cbox.set_list(self.thebackends)
# Three last checkboxes
self.debug_mode_checkb.set_state(daemon.GetDebugMode()) self.debug_mode_checkb.set_state(daemon.GetDebugMode())
self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType()) self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())
def store_results(self): def save_results(self):
""" Pushes the selected settings to the daemon.
This exact order is found in prefs.py"""
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())
daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
self.dns3.get_edit_text(), 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.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state()) 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())
daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
if self.wired_auto_2.get_state():
daemon.SetWiredAutoConnectMethod(2)
elif self.wired_auto_3.get_state():
daemon.SetWiredAutoConnectMethod(3)
else:
daemon.SetWiredAutoConnectMethod(1)
daemon.SetBackend(self.backends[self.backend_cbox.get_selected()])
# External Programs Tab
if self.dhcp0.get_state():
dhcp_client = misc.AUTO
elif self.dhcp1.get_state():
dhcp_client = misc.DHCLIENT
elif self.dhcp2.get_state():
dhcp_client = misc.DHCPCD
else:
dhcp_client = misc.PUMP
daemon.SetDHCPClient(dhcp_client)
if self.wired0.get_state():
link_tool = misc.AUTO
elif self.wired1.get_state():
link_tool = misc.ETHTOOL
else:
link_tool = misc.MIITOOL
daemon.SetLinkDetectionTool(link_tool)
if self.flush0.get_state():
flush_tool = misc.AUTO
elif self.flush1.get_state():
flush_tool = misc.IP
else:
flush_tool = misc.ROUTE
daemon.SetFlushTool(flush_tool)
# DNS CheckBox callback
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)
# Button callbacks
def ok_callback(self,button_object,user_data=None):
self.OK_PRESSED = True
def cancel_callback(self,button_object,user_data=None):
self.CANCEL_PRESSED = True
def ready_comboboxes(self,ui,body): def ready_comboboxes(self,ui,body):
self.wpa_cbox.build_combobox(body,ui,4) self.wpa_cbox.build_combobox(body,ui,4)
self.backend_cbox.build_combobox(body,ui,8) self.backend_cbox.build_combobox(body,ui,8)
# Normal keypress, but if we are at the top, then be "tabbish" instead
#def keypress(self,size,ui):
# self._w.keypress(size,ui)
# (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
#@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() width,height = ui.get_cols_rows()
@@ -296,8 +392,7 @@ class PrefsDialog(urwid.WidgetWrap):
overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width
, ('fixed top',1), height-3) , ('fixed top',1), height-3)
# Will need once we actually get the comboboxes filled with stuff self.ready_comboboxes(ui,overlay)
#self.ready_comboboxes(ui,overlay)
keys = True keys = True
while True: while True:
@@ -308,19 +403,25 @@ class PrefsDialog(urwid.WidgetWrap):
if "window resize" in keys: if "window resize" in keys:
dim = ui.get_cols_rows() dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys: if "esc" in keys or 'Q' in keys:
return return False
for k in keys: for k in keys:
#Send key to underlying widget: #Send key to underlying widget:
overlay.keypress(dim, k) overlay.keypress(dim, k)
if self.CANCEL_PRESSED:
return False
if self.OK_PRESSED:
return True
###
### EXTERNAL ENTRY POINT STUFF
###
def run_it(): def run_it():
dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces()) dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces())
keys = True keys = True
dim = ui.get_cols_rows() dim = ui.get_cols_rows()
dialog.load_settings() dialog.load_settings()
# Will need once we actually get the comboboxes filled with stuff dialog.ready_comboboxes(ui,dialog)
#self.ready_comboboxes(ui,overlay)
while True: while True:
if keys: if keys:
ui.draw_screen(dim, dialog.render(dim, True)) ui.draw_screen(dim, dialog.render(dim, True))
@@ -329,11 +430,14 @@ def run_it():
if "window resize" in keys: if "window resize" in keys:
dim = ui.get_cols_rows() dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys: if "esc" in keys or 'Q' in keys:
return return False
for k in keys: for k in keys:
#Send key to underlying widget:
dialog.keypress(dim, k) dialog.keypress(dim, k)
if dialog.CANCEL_PRESSED:
return False
if dialog.OK_PRESSED:
dialog.save_results()
return True
if __name__=='__main__': if __name__=='__main__':
try: try:

View File

@@ -241,11 +241,15 @@ class appGUI():
# spam,spam,spam,spam,spam,spam,spam,spam,spam,spam,spam,spam, # spam,spam,spam,spam,spam,spam,spam,spam,spam,spam,spam,spam,
# 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),
('fixed',1,self.wiredCB),
('fixed',1,self.wlessH),
self.wlessLB] )
# Choose whether to show the wired part of the interface.
if daemon.GetAlwaysShowWiredInterface():
self.thePile = urwid.Pile([('fixed',1,self.wiredH),
('fixed',1,self.wiredCB),
('fixed',1,self.wlessH),
self.wlessLB] )
else:
self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] )
self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body') 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.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important')
self.footerList = urwid.ListBox([self.footer1,self.footer2]) self.footerList = urwid.ListBox([self.footer1,self.footer2])
@@ -263,7 +267,7 @@ class appGUI():
self.connecting = False self.connecting = False
self.screen_locked = False self.screen_locked = False
self.connecting = False self.connecting = False
self.always_show_wired = daemon.GetAlwaysShowWiredInterface()
self.update_status() self.update_status()
#self.dialog = PrefOverlay(self.frame,self.size) #self.dialog = PrefOverlay(self.frame,self.size)
@@ -296,7 +300,18 @@ 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)
self.wlessLB.body = urwid.SimpleListWalker(wlessL) self.wlessLB.body = urwid.SimpleListWalker(wlessL)
# If the "Always Show Wired" part of the interface changes, change
# along with it.
if daemon.GetAlwaysShowWiredInterface() != self.always_show_wired:
if daemon.GetAlwaysShowWiredInterface():
self.thePile = urwid.Pile([('fixed',1,self.wiredH),
('fixed',1,self.wiredCB),
('fixed',1,self.wlessH),
self.wlessLB] )
else:
self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] )
self.frame.body = self.thePile
self.always_show_wired = not self.always_show_wired
self.prev_state = state self.prev_state = state
# Update the footer/status bar # Update the footer/status bar
@@ -430,8 +445,10 @@ class appGUI():
if "P" in keys: if "P" in keys:
dialog = PrefsDialog(self.frame,(0,1),ui, dialog = PrefsDialog(self.frame,(0,1),ui,
dbusmanager.get_dbus_ifaces()) dbusmanager.get_dbus_ifaces())
dialog.run(ui,self.size,self.frame) # There is some lag in using the buttons. Not my fault.
dialog.store_results() if dialog.run(ui,self.size,self.frame):
dialog.save_results()
self.update_ui()
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()