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

curses/prefs_curses.py: ADDED. A basic global preferences dialog. Has a tabbed interface. It is missing things such as buttons, external program controls, advanced settings, and the ability to save information. :-)

curses/wicd-curses.py: Some code cleanup, replaced the language mess with the GUI list in misc, and added support for running the Preferences dialog with 'P'.
curses/README: Added the keybindings to bring up the preferences dialog.
This commit is contained in:
Andrew Psaltis
2008-12-26 13:48:26 -05:00
parent fb96a229bb
commit 780a05cef3
3 changed files with 271 additions and 119 deletions

View File

@@ -16,5 +16,11 @@ F8 or Q: quit
D : disconnect from active network
ESC : if connecting to a network, stop doing so
ENTER : Attempt connection to selected network
P : Display preferences dialog
IN DIALOGS:
ESC or Q: Quit dialog without saving information (if present)
~nacl

249
curses/prefs_curses.py Normal file
View File

@@ -0,0 +1,249 @@
#!/usr/bin/env python
import urwid
from wicd import misc
# Will work for now, I guess.
language = misc.get_language_list_gui()
class SelText(urwid.Text):
"""A selectable text widget. See urwid.Text."""
def selectable(self):
"""Make widget selectable."""
return True
def keypress(self, size, key):
"""Don't handle any keys."""
return key
class ToggleEdit(urwid.WidgetWrap):
"""A edit that can be rendered unselectable by somethhing like a checkbox"""
def __init__(self, caption='', state=True,attr=('editbx','editfc'),attrnfoc='body'):
edit = urwid.Edit(caption)
curattr = attr[0] if state == True else attrnfoc
w = urwid.AttrWrap(edit,curattr,attr[1])
self.sensitive=state
self.__super.__init__(w)
def set_sensitive(self,state):
self.sensitive=state
if state:
self._w.set_attr('editbx')
else:
self._w.set_attr('body')
def selectable(self):
return self.sensitive
def keypress(self,size,key):
return self._w.keypress(size,key)
# Would seem to complicate things a little bit...
class TabColumns(urwid.WidgetWrap):
def __init__(self):
pass
def selectable(self):
return True
def keypress(self,size,key):
pass
# A "combo box" of SelTexts
class ComboText(urwid.WidgetWrap):
class ComboSpace(urwid.WidgetWrap):
def init(self,body,list,show_first=0,pos=(0,0)):
#Calculate width and height of the menu widget:
height = len(list)
width = 0
for entry in list:
if len(entry) > width:
width = len(entry)
self._listbox = urwid.ListBox(list)
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]),
width + 2, ('fixed top', pos[1]), height)
def init(self,list,show_first=0):
pass
class PrefOverlay(urwid.WidgetWrap):
def __init__(self,body,pos):
# We are on a VT100, I presume.
width = 80
height = 20
# Stuff that goes at the top
header0_t = language["gen_settings"]
header1_t = language["ext_programs"]
header2_t = language["advanced_settings"]
self.header0 = urwid.AttrWrap(SelText(header0_t),'body','focus')
self.header1 = urwid.AttrWrap(SelText(header1_t),'body','focus')
self.header2 = urwid.AttrWrap(SelText(header2_t),'body','focus')
title = language['preferences']
# Blank line
self._blank = urwid.Text('')
####
#### Text in the widgets
####
# General Settings
wired_t=('editcp',language['wired_interface']+':')
wless_t=('editcp',language['wireless_interface']+':')
global_dns_t=(language['use_global_dns'])
search_dom_t= ('editcp','Search domain:')
dns1_t = ('editcp','DNS server 1:')
dns2_t = ('editcp','DNS server 2:')
dns3_t = ('editcp','DNS server 3:')
always_show_wired_t = 'wired always on' #language['wired always on']
auto_reconnect_t = language['auto_reconnect']
#wired_autoconnect_header = 'Wired Autoconnect Setting'
wired_auto_1_t = language['use_default_profile']
wired_auto_2_t = language['show_wired_list']
wired_auto_3_t = language['use_last_used_profile']
#### External Programs
automatic_t = language['wicd_auto_config']
dhcp_header = language["dhcp_client"]
# Automatic
dhcp1_t = 'dhclient'
dhcp2_t = 'dhcpcd'
dhcp3_t = 'pump'
wired_detect_header = language["wired_detect"]
wired1_t = 'ethtool'
wired2_t = 'mii-tool'
route_table_header = language["route_flush"]
route1_t = 'ip'
route2_t = 'route'
# Advanced Settings
wpa_t=('editcp',language['wpa_supplicant_driver']+':')
debug_mode_t = language['use_debug_mode']
use_dbm_t = language['display_type_dialog']
# backend_sel_t =
####
#### UI Widgets
####
# General Settings
self.wpa_edit = urwid.AttrWrap(urwid.Edit(wpa_t),'editbx','editfc')
self.wired_iface = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc')
self.wless_iface = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc')
global_dns_state = False
self.global_dns = 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.auto_reconnect = urwid.CheckBox(auto_reconnect_t)
self.debug_mode = urwid.CheckBox(debug_mode_t)
self.use_dbm = urwid.CheckBox(use_dbm_t)
wired_auto_l = []
self.wired_auto_1_r = urwid.RadioButton(wired_auto_l,wired_auto_1_t)
self.wired_auto_2_r = urwid.RadioButton(wired_auto_l,wired_auto_2_t)
self.wired_auto_3_r = urwid.RadioButton(wired_auto_l,wired_auto_3_t)
generalPile = urwid.Pile([
self.wired_iface,#self._blank,
self.wless_iface,self._blank,
self.global_dns,#self._blank,
self.search_dom,
self.dns1,self.dns2,self.dns3,self._blank,
self.always_show_wired,
self.auto_reconnect,
self.debug_mode,
self.use_dbm,self._blank,
self.wired_auto_1_r,
self.wired_auto_2_r,
self.wired_auto_3_r
])
#externalPile = urwid.Pile()
# Advanced Settings
# WPA Supplicant: Combo Box
# Backend: Combo box
# Debugging
# Enable debug mode
# Wireless Interface
# Use DBM to measure signal strength
advancedPile = urwid.Pile([self.wpa_edit,self._blank])
self.columns = urwid.Columns([('fixed',len(header0_t),self.header0),('fixed',len(header1_t),self.header1),urwid.Text(('header',title),align='right')],dividechars=1)
self.tab_map = {self.header0 : generalPile,
self.header1 : advancedPile,
self.header2 : advancedPile}
content = [self.columns,generalPile]
#self._label = urwid.AttrWrap(SelText(titles),attr[0],attr[1])
self.walker = urwid.SimpleListWalker(content)
self._listbox = urwid.ListBox(self.walker)
self._boxadap = urwid.BoxAdapter
#self._linebox = urwid.LineBox(self._listbox)
overlay = urwid.Overlay(self._listbox, body, ('fixed left', pos[0]),
width + 2, ('fixed top', pos[1]), height)
self.__super.__init__(overlay)
def global_dns_trigger(self,check_box,new_state,user_data=None):
for w in self.search_dom,self.dns1,self.dns2,self.dns3:
w.set_sensitive(new_state)
# 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)
lw.append(self.tab_map[self.columns.get_focus()])
self._listbox.body = lw
#@wrap_exceptions()
def run(self,ui, dim, display):
global app
#dialog = TabbedOverlay(["Foo", "Bar", "Quit"],
# ('body', 'focus'), (1, 1), display)
#dialog = PrefOverlay(display,(0,1))
keys = True
while True:
if keys:
ui.draw_screen(dim, self.render(dim, True))
keys = ui.get_input()
if "window resize" in keys:
dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys:
return
for k in keys:
#Send key to underlying widget:
self.keypress(dim, k)
#if program_menu.selected == "Quit":
# return
#if program_menu.selected == "Foo":
#Do something
# return
#if program_menu.selected == "Bar":
#Do something
#return
#@wrap_exceptions()
#def run_dialog(ui,dim,display,dialog):
# pass
#Event loop:

View File

@@ -54,129 +54,17 @@ from wicd import dbusmanager
# Internal Python stuff
import sys
# Curses UIs for other stuff
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)
# Translations for the text that people will see. This code is
# already found in the gui.py file
# IN EXPERIMENTAL, THIS IS ALL IN wicd.misc
# (Yeah... um... all 102 of them ^_^)
_ = misc.get_gettext()
language = {}
language['connect'] = _("Connect")
language['ip'] = _("IP")
language['netmask'] = _("Netmask")
language['gateway'] = _('Gateway')
language['dns'] = _('DNS')
language['use_static_ip'] = _('Use Static IPs')
language['use_static_dns'] = _('Use Static DNS')
language['use_encryption'] = _('Use Encryption')
language['advanced_settings'] = _('Advanced Settings')
language['wired_network'] = _('Wired Network')
language['wired_network_instructions'] = _('To connect to a wired network,'
' you must create a network profile. To create a network profile, type a'
' name that describes this network, and press Add.')
language['automatic_connect'] = _('Automatically connect to this network')
language['secured'] = _('Secured')
language['unsecured'] = _('Unsecured')
language['channel'] = _('Channel')
language['preferences'] = _('Preferences')
language['wpa_supplicant_driver'] = _('WPA Supplicant Driver')
language['wireless_interface'] = _('Wireless Interface')
language['wired_interface'] = _('Wired Interface')
language['hidden_network'] = _('Hidden Network')
language['hidden_network_essid'] = _('Hidden Network ESSID')
language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)')
language['connected_to_wired'] = _('Connected to wired network (IP: $A)')
language['not_connected'] = _('Not connected')
language['no_wireless_networks_found'] = _('No wireless networks found.')
language['killswitch_enabled'] = _('Wireless Kill Switch Enabled')
language['key'] = _('Key')
language['username'] = _('Username')
language['password'] = _('Password')
language['anonymous_identity'] = _('Anonymous Identity')
language['identity'] = _('Identity')
language['authentication'] = _('Authentication')
language['path_to_pac_file'] = _('Path to PAC File')
language['select_a_network'] = _('Choose from the networks below:')
language['connecting'] = _('Connecting...')
language['wired_always_on'] = _('Always show wired interface')
language['auto_reconnect'] = _('Automatically reconnect on connection loss')
language['create_adhoc_network'] = _('Create an Ad-Hoc Network')
language['essid'] = _('ESSID')
language['use_wep_encryption'] = _('Use Encryption (WEP only)')
language['before_script'] = _('Run script before connect')
language['after_script'] = _('Run script after connect')
language['disconnect_script'] = _('Run disconnect script')
language['script_settings'] = _('Scripts')
language['use_ics'] = _('Activate Internet Connection Sharing')
language['madwifi_for_adhoc'] = _('Check if using madwifi/atheros drivers')
language['default_wired'] = _('Use as default profile (overwrites any previous default)')
language['use_debug_mode'] = _('Enable debug mode')
language['use_global_dns'] = _('Use global DNS servers')
language['use_default_profile'] = _('Use default profile on wired autoconnect')
language['show_wired_list'] = _('Prompt for profile on wired autoconnect')
language['use_last_used_profile'] = _('Use last used profile on wired autoconnect')
language['choose_wired_profile'] = _('Select or create a wired profile to connect with')
language['wired_network_found'] = _('Wired connection detected')
language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily')
language['display_type_dialog'] = _('Use dBm to measure signal strength')
language['scripts'] = _('Scripts')
language['invalid_address'] = _('Invalid address in $A entry.')
language['global_settings'] = _('Use these settings for all networks sharing this essid')
language['encrypt_info_missing'] = _('Required encryption information is missing.')
language['enable_encryption'] = _('This network requires encryption to be enabled.')
language['wicd_auto_config'] = _('Automatic (recommended)')
language["gen_settings"] = _("General Settings")
language["ext_programs"] = _("External Programs")
language["dhcp_client"] = _("DHCP Client")
language["wired_detect"] = _("Wired Link Detection")
language["route_flush"] = _("Route Table Flushing")
language["backend"] = _("Backend")
language["backend_alert"] = _("Changes to your backend won't occur until the daemon is restarted.")
language['search_domain'] = _("Search Domain")
language['scripts_need_pass'] = _('You must enter your password to configure scripts')
language['no_sudo_prog'] = _("Could not find a graphical sudo program. The script editor could not be launched." +
"You'll have to edit scripts directly your configuration file.")
language['0'] = _('0')
language['1'] = _('1')
language['2'] = _('2')
language['3'] = _('3')
language['4'] = _('4')
language['5'] = _('5')
language['6'] = _('6')
language['7'] = _('7')
language['8'] = _('8')
language['9'] = _('9')
language['interface_down'] = _('Putting interface down...')
language['resetting_ip_address'] = _('Resetting IP address...')
language['interface_up'] = _('Putting interface up...')
language['setting_encryption_info'] = _('Setting encryption info')
language['removing_old_connection'] = _('Removing old connection...')
language['generating_psk'] = _('Generating PSK...')
language['generating_wpa_config'] = _('Generating WPA configuration file...')
language['flushing_routing_table'] = _('Flushing the routing table...')
language['configuring_interface'] = _('Configuring wireless interface...')
language['validating_authentication'] = _('Validating authentication...')
language['setting_broadcast_address'] = _('Setting broadcast address...')
language['setting_static_dns'] = _('Setting static DNS servers...')
language['setting_static_ip'] = _('Setting static IP addresses...')
language['running_dhcp'] = _('Obtaining IP address...')
language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address')
language['aborted'] = _('Connection Cancelled')
language['bad_pass'] = _('Connection Failed: Bad password')
language['done'] = _('Done connecting...')
language['scanning'] = _('Scanning')
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
"This typically means there was a problem starting the daemon." + \
"Check the wicd log for more info")
language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.")
language = misc.get_language_list_gui()
# Whew. Now on to more interesting stuff:
########################################
@@ -392,6 +280,8 @@ class appGUI():
self.update_status()
#self.dialog = PrefOverlay(self.frame,self.size)
# Does what it says it does
def lock_screen(self):
@@ -512,6 +402,11 @@ class appGUI():
#self.update_status()
canvas = self.frame.render( (self.size),True )
### GRRRRRRRRRRRRRRRRRRRRR ->^^^^
# It looks like if I wanted to get the statusbar to update itself
# continuously, I would have to use overlay the canvasses and redirect
# the input. I'll try to get that working at a later time, if people
# want that "feature".
#canvaso = urwid.CanvasOverlay(self.dialog.render( (80,20),True),canvas,0,1)
ui.draw_screen((self.size),canvas)
keys = ui.get_input()
# Should make a keyhandler method, but this will do until I get around to
@@ -534,6 +429,9 @@ class appGUI():
daemon.CancelConnect()
# Prevents automatic reconnecting if that option is enabled
daemon.SetForcedDisconnect(True)
if "P" in keys:
dialog = PrefOverlay(self.frame,(0,1))
dialog.run(ui,self.size,self.frame)
for k in keys:
if k == "window resize":
self.size = ui.get_cols_rows()
@@ -648,7 +546,6 @@ def setup_dbus(force=True):
return True
bus = dbus.SystemBus()
setup_dbus()
########################################