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

More htoppish ui changes

curses/prefs_curses.py: changed save_results to save_settings
curses/curses_misc.py:
  M^[ and M^] shift the tabs left and right respectively.  The curses module
    has trouble picking up M^left and M^right
curses/netentry_curses.py:
  Removed the buttons and button-related code from the interface.
  Removed the overlay code.
  Adapted the code for direct insertion into the wicd-curses interface
curses/wicd-curses.py:
  Teaked the wireless header.
  Added support for sticking the network config dialog into the interface, and
    changing the current OptCols when it is activated.
  Added new OptCols for other large dialogs
This commit is contained in:
Andrew Psaltis
2009-03-05 23:09:17 -05:00
parent 6690d9bb32
commit dc49a2fc4f
5 changed files with 139 additions and 149 deletions

View File

@@ -206,9 +206,10 @@ class TabColumns(urwid.WidgetWrap):
def keypress(self,size,key): def keypress(self,size,key):
self._w.keypress(size,key) self._w.keypress(size,key)
if key == "meta left" or key == "meta right": if key == "meta [" or key == "meta ]":
self._w.get_body().set_focus(0) self._w.get_body().set_focus(0)
self.keypress(size,key[5:]) newK = 'left' if key[-1] == '[' else 'right'
self.keypress(size,newK)
self._w.get_body().set_focus(1) self._w.get_body().set_focus(1)
else: else:
wid = self.pile.get_focus().get_body() wid = self.pile.get_focus().get_body()

View File

@@ -84,13 +84,6 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
_blank = urwid.Text('') _blank = urwid.Text('')
# Buttons. These need to be added to the list in superclasses.
self.OK_PRESSED= False
self.CANCEL_PRESSED = False
self.ok_button = urwid.AttrWrap(urwid.Button('OK',self.ok_callback),'body','focus')
self.cancel_button = urwid.AttrWrap(urwid.Button('Cancel',self.cancel_callback),'body','focus')
self.button_cols = urwid.Columns([self.ok_button,self.cancel_button])
walker = urwid.SimpleListWalker([self.static_ip_cb, walker = urwid.SimpleListWalker([self.static_ip_cb,
self.ip_edit, self.ip_edit,
self.netmask_edit, self.netmask_edit,
@@ -105,16 +98,9 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self._listbox = urwid.ListBox(walker) self._listbox = urwid.ListBox(walker)
#self._frame = urwid.Frame(self._listbox) #self._frame = urwid.Frame(self._listbox)
self._frame = urwid.Frame(self._listbox,footer=self.button_cols) self._frame = urwid.Frame(self._listbox)
self.__super.__init__(self._frame) self.__super.__init__(self._frame)
# 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 static_ip_set_state(self,checkb,new_state,user_data=None): def static_ip_set_state(self,checkb,new_state,user_data=None):
for w in [ self.ip_edit,self.netmask_edit,self.gateway_edit ]: for w in [ self.ip_edit,self.netmask_edit,self.gateway_edit ]:
w.set_sensitive(new_state) w.set_sensitive(new_state)
@@ -166,54 +152,9 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.set_net_prop("dns1", '') self.set_net_prop("dns1", '')
self.set_net_prop("dns2", '') self.set_net_prop("dns2", '')
self.set_net_prop("dns3", '') self.set_net_prop("dns3", '')
# Prevent comboboxes from dying.
def prerun(self,ui,dim,display): def ready_widgets(self,ui,body):
pass pass
def run(self,ui,dim,display):
self.ui = ui
self.parent = display
width,height = ui.get_cols_rows()
self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width
, ('fixed top',1), height-3)
self.prerun(ui,dim,display)
#self.ready_comboboxes(ui,overlay)
keys = True
while True:
if keys:
ui.draw_screen(dim, self.overlay.render(dim, True))
keys = ui.get_input()
for k in keys:
#Send key to underlying widget:
if urwid.is_mouse_event(k):
event, button, col, row = k
self.overlay.mouse_event( dim,
event, button, col, row,
focus=True)
else:
k = self.overlay.keypress(dim, k)
if k in ('up','page up'):
self._w.set_focus('body')
# Until I figure out a better way to do this, then
# this will have to do.
self._w.body.get_focus()[0].get_focus()._invalidate()
#self._w.body.keypress(dim,'down')
elif k in ('down','page down'):
self._w.set_focus('footer')
if "window resize" in keys:
dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys:
return False
if "meta enter" in keys or self.OK_PRESSED:
self.OK_PRESSED = False
if self.save_settings():
return True
if self.CANCEL_PRESSED:
return False
class WiredSettingsDialog(AdvancedSettingsDialog): class WiredSettingsDialog(AdvancedSettingsDialog):
def __init__(self,name): def __init__(self,name):
@@ -367,13 +308,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
encrypt_methods[self.encryption_combo.get_focus()[1] ][1]) encrypt_methods[self.encryption_combo.get_focus()[1] ][1])
for x in encryption_info: for x in encryption_info:
if encryption_info[x].get_edit_text() == "": if encryption_info[x].get_edit_text() == "":
error(self.ui, self.overlay,language['encrypt_info_missing']) error(self.ui, self.body,language['encrypt_info_missing'])
return False return False
self.set_net_prop(x, noneToString(encryption_info[x]. self.set_net_prop(x, noneToString(encryption_info[x].
get_edit_text())) get_edit_text()))
elif not self.encryption_chkbox.get_state() and \ elif not self.encryption_chkbox.get_state() and \
wireless.GetWirelessProperty(self.networkID, "encryption"): wireless.GetWirelessProperty(self.networkID, "encryption"):
error(self.ui, self.overlay, language['enable_encryption']) error(self.ui, self.body, language['enable_encryption'])
return False return False
else: else:
#print 'encryption is ' + str(wireless.GetWirelessProperty(self.networkID, #print 'encryption is ' + str(wireless.GetWirelessProperty(self.networkID,
@@ -431,6 +372,8 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self._w.body.body.insert(self._w.body.body.__len__(),self.pile_encrypt) self._w.body.body.insert(self._w.body.body.__len__(),self.pile_encrypt)
#self._w.body.body.append(self.pile_encrypt) #self._w.body.body.append(self.pile_encrypt)
def prerun(self,ui,dim,display): def ready_widgets(self,ui,body):
self.encryption_combo.build_combobox(self.overlay,ui,14) self.ui = ui
self.body = body
self.encryption_combo.build_combobox(body,ui,14)
self.change_encrypt_method() self.change_encrypt_method()

View File

@@ -322,7 +322,7 @@ class PrefsDialog(urwid.WidgetWrap):
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())
def save_results(self): def save_settings(self):
""" Pushes the selected settings to the daemon. """ Pushes the selected settings to the daemon.
This exact order is found in prefs.py""" This exact order is found in prefs.py"""
daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state()) daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())

204
curses/wicd-curses.py Normal file → Executable file
View File

@@ -314,9 +314,9 @@ def gen_list_header():
# Allocate 25 cols for the ESSID name # Allocate 25 cols for the ESSID name
essidgap = 25 essidgap = 25
else: else:
# Need 3 more to accomodate dBm strings (I think) # Need 3 more to accomodate dBm strings
essidgap = 28 essidgap = 28
return 'C %s %*s %9s %17s %6s %s' % ('STR',essidgap,'ESSID','ENCRYPT','BSSID','MODE','CHNL') return 'C %s %*s %9s %17s %6s %s' % ('STR ',essidgap,'ESSID','ENCRYPT','BSSID','MODE','CHNL')
# Wireless network label # Wireless network label
class NetLabel(urwid.WidgetWrap): class NetLabel(urwid.WidgetWrap):
@@ -338,7 +338,7 @@ class NetLabel(urwid.WidgetWrap):
self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') if wireless.GetWirelessProperty(id, 'encryption') else language['unsecured'] self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') if wireless.GetWirelessProperty(id, 'encryption') else language['unsecured']
self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc
self.channel = wireless.GetWirelessProperty(id, 'channel') self.channel = wireless.GetWirelessProperty(id, 'channel')
theString = ' %*s %25s %9s %17s %6s %4s' % (gap, theString = ' %-*s %25s %9s %17s %6s %4s' % (gap,
self.stren,self.essid,self.encrypt,self.bssid,self.mode,self.channel) self.stren,self.essid,self.encrypt,self.bssid,self.mode,self.channel)
if is_active: if is_active:
theString = '>'+theString[1:] theString = '>'+theString[1:]
@@ -536,7 +536,9 @@ class appGUI():
# These are empty to make sure that things go my way. # These are empty to make sure that things go my way.
wiredL,wlessL = [],[]# = gen_network_list() wiredL,wlessL = [],[]# = gen_network_list()
self.frame = None self.frame = None
self.diag = None
self.wiredCB = urwid.Filler(WiredComboBox(wiredL)) self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
self.wlessLB = urwid.ListBox(wlessL) self.wlessLB = urwid.ListBox(wlessL)
@@ -566,20 +568,23 @@ class appGUI():
#(' ' ,' ',None), #(' ' ,' ',None),
#(' ' ,' ',None), #(' ' ,' ',None),
self.footer1 = OptCols(keys,debug=True) self.primaryCols = OptCols(keys,debug=True)
#self.time_label = urwid.Text(strftime('%H:%M:%S')) #self.time_label = urwid.Text(strftime('%H:%M:%S'))
self.time_label = \ self.time_label = \
urwid.AttrWrap(urwid.Text(strftime('%H:%M:%S')), 'timebar') urwid.AttrWrap(urwid.Text(strftime('%H:%M:%S')), 'timebar')
self.status_label = urwid.AttrWrap(urwid.Text('blah'),'important') self.status_label = urwid.AttrWrap(urwid.Text('blah'),'important')
self.footer2 = urwid.Columns([self.status_label,('fixed', 8, self.time_label)]) self.footer2 = urwid.Columns([self.status_label,('fixed', 8, self.time_label)])
self.footerList = urwid.ListBox([self.footer1,self.footer2]) self.footerList = urwid.Pile([self.primaryCols,self.footer2])
# Pop takes a number! # Pop takes a number!
#walker.pop(1) #walker.pop(1)
self.frame = urwid.Frame(self.thePile, self.frame = urwid.Frame(self.thePile,
header=header, header=header,
footer=urwid.BoxAdapter(self.footerList,2)) footer=self.footerList)
self.wiredCB.get_body().build_combobox(self.frame,ui,3) self.wiredCB.get_body().build_combobox(self.frame,ui,3)
# Init the other columns used in the program
self.init_other_optcols()
self.frame.set_body(self.thePile) self.frame.set_body(self.thePile)
# Booleans gallore! # Booleans gallore!
self.prev_state = False self.prev_state = False
@@ -592,6 +597,18 @@ class appGUI():
#self.dialog = PrefOverlay(self.frame,self.size) #self.dialog = PrefOverlay(self.frame,self.size)
def init_other_optcols(self):
# The "tabbed" preferences dialog
self.prefCols = OptCols( [('meta enter','OK'),
('ESC','Cancel'),
('meta [','Tab Left',),
('meta ]','Tab Right')],debug=True )
self.confCols = OptCols( [
('<-','OK'),
('ESC','Cancel')
],debug=True )
# Does what it says it does # Does what it says it does
def lock_screen(self): def lock_screen(self):
self.frame.set_body(self.screen_locker) self.frame.set_body(self.screen_locker)
@@ -636,7 +653,11 @@ class appGUI():
# TODO: Preserve current focus when updating the list. # TODO: Preserve current focus when updating the list.
@wrap_exceptions() @wrap_exceptions()
def update_netlist(self,state=None, x=None, force_check=False,firstrun=False): def update_netlist(self,state=None, x=None, force_check=False,firstrun=False):
# Run focus-collecting code if we are not running this for the first time # Don't even try to do this if we are running a dialog
if self.diag:
return
# Run focus-collecting code if we are not running this for the first
# time
if not firstrun: if not firstrun:
self.update_focusloc() self.update_focusloc()
self.list_header.set_text(gen_list_header()) self.list_header.set_text(gen_list_header())
@@ -787,6 +808,11 @@ class appGUI():
def dbus_scan_started(self): def dbus_scan_started(self):
self.lock_screen() self.lock_screen()
def restore_primary(self):
self.frame.set_body(self.thePile)
self.diag = None
self.frame.set_footer(urwid.Pile([self.primaryCols,self.footer2]))
self.update_ui()
# Redraw the screen # Redraw the screen
@wrap_exceptions() @wrap_exceptions()
def update_ui(self): def update_ui(self):
@@ -800,78 +826,92 @@ class appGUI():
#canvaso = urwid.CanvasOverlay(self.dialog.render( (80,20),True),canvas,0,1) #canvaso = urwid.CanvasOverlay(self.dialog.render( (80,20),True),canvas,0,1)
ui.draw_screen((self.size),canvas) ui.draw_screen((self.size),canvas)
keys = ui.get_input() keys = ui.get_input()
if not self.diag:
# Handle keystrokes
if "f8" in keys or 'Q' in keys or 'q' in keys:
loop.quit()
#return False
if "f5" in keys or 'R' in keys:
self.lock_screen()
wireless.Scan(True)
if "D" in keys:
# Disconnect from all networks.
daemon.Disconnect()
self.update_netlist()
if 'right' in keys:
focus = self.thePile.get_focus()
self.frame.set_footer(urwid.Pile([self.confCols,self.footer2]))
if focus == self.wiredCB:
self.diag = WiredSettingsDialog(self.wiredCB.get_body().get_selected_profile())
self.frame.set_body(self.diag)
else:
# wireless list only other option
wid,pos = self.thePile.get_focus().get_focus()
self.diag = WirelessSettingsDialog(pos)
self.diag.ready_widgets(ui,self.frame)
self.frame.set_body(self.diag)
# Guess what! I actually need to put this here, else I'll have
# tons of references to self.frame lying around. ^_^
if "enter" in keys:
focus = self.frame.body.get_focus()
if focus == self.wiredCB:
self.special = focus
self.connect("wired",0)
else:
# wless list only other option
wid,pos = self.thePile.get_focus().get_focus()
self.connect("wireless",pos)
# Handle keystrokes if "esc" in keys:
if "f8" in keys or 'Q' in keys or 'q' in keys: # Force disconnect here if connection in progress
loop.quit() if self.connecting:
#return False daemon.CancelConnect()
if "f5" in keys or 'R' in keys: # Prevents automatic reconnecting if that option is enabled
self.lock_screen() daemon.SetForcedDisconnect(True)
wireless.Scan(True) if "P" in keys:
if "D" in keys: if not self.pref:
# Disconnect from all networks. self.pref = PrefsDialog(self.frame,(0,1),ui,
daemon.Disconnect() dbusmanager.get_dbus_ifaces())
self.update_netlist() if self.pref.run(ui,self.size,self.frame):
# Guess what! I actually need to put this here, else I'll have tons of self.pref.save_settings()
# references to self.frame lying around. ^_^ self.update_ui()
if "enter" in keys: if "A" in keys:
focus = self.frame.body.get_focus() self.footer1 = self.confCols
if focus == self.wiredCB: about_dialog(self.frame)
self.special = focus if "C" in keys:
self.connect("wired",0) focus = self.thePile.get_focus()
else: if focus == self.wiredCB:
# wless list only other option WiredSettingsDialog(self.wiredCB.get_body().
wid,pos = self.thePile.get_focus().get_focus() get_selected_profile()).run(ui,self.size,self.frame)
self.connect("wireless",pos) else:
# wireless list only other option
if "esc" in keys: wid,pos = self.thePile.get_focus().get_focus()
# Force disconnect here if connection in progress WirelessSettingsDialog(pos).run(ui,self.size,self.frame)
if self.connecting: #self.netentry = NetEntryBase(dbusmanager.get_dbus_ifaces())
daemon.CancelConnect() #self.netentry.run(ui,self.size,self.frame)
# Prevents automatic reconnecting if that option is enabled if "I" in keys:
daemon.SetForcedDisconnect(True) self.raise_hidden_network_dialog()
if "P" in keys: if "H" in keys or 'h' in keys or '?' in keys:
if not self.pref: help_dialog(self.frame)
self.pref = PrefsDialog(self.frame,(0,1),ui, if "S" in keys:
dbusmanager.get_dbus_ifaces()) focus = self.thePile.get_focus()
if self.pref.run(ui,self.size,self.frame): if focus == self.wiredCB:
self.pref.save_results() nettype = 'wired'
self.update_ui() netname = self.wiredCB.get_body().get_selected_profile()
if "A" in keys: else:
about_dialog(self.frame) nettype = 'wireless'
if "C" in keys: netname = str(self.wlessLB.get_focus()[1])
focus = self.thePile.get_focus() run_configscript(self.frame,netname,nettype)
if focus == self.wiredCB: if "O" in keys:
WiredSettingsDialog(self.wiredCB.get_body(). exitcode,data = AdHocDialog().run(ui,self.frame)
get_selected_profile()).run(ui,self.size,self.frame) #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
else: if exitcode == 1:
# wireless list only other option wireless.CreateAdHocNetwork(data[0],
wid,pos = self.thePile.get_focus().get_focus() data[2],
WirelessSettingsDialog(pos).run(ui,self.size,self.frame) data[1], "WEP",
#self.netentry = NetEntryBase(dbusmanager.get_dbus_ifaces()) data[5],
#self.netentry.run(ui,self.size,self.frame) data[4], False)
if "I" in keys:
self.raise_hidden_network_dialog()
if "H" in keys or 'h' in keys or '?' in keys:
help_dialog(self.frame)
if "S" in keys:
focus = self.thePile.get_focus()
if focus == self.wiredCB:
nettype = 'wired'
netname = self.wiredCB.get_body().get_selected_profile()
else:
nettype = 'wireless'
netname = str(self.wlessLB.get_focus()[1])
run_configscript(self.frame,netname,nettype)
if "O" in keys:
exitcode,data = AdHocDialog().run(ui,self.frame)
#data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
if exitcode == 1:
wireless.CreateAdHocNetwork(data[0],
data[2],
data[1], "WEP",
data[5],
data[4], False)
for k in keys: for k in keys:
if urwid.is_mouse_event(k): if urwid.is_mouse_event(k):
@@ -882,7 +922,13 @@ class appGUI():
if k == "window resize": if k == "window resize":
self.size = ui.get_cols_rows() self.size = ui.get_cols_rows()
continue continue
self.frame.keypress( self.size, k ) k = self.frame.keypress( self.size, k )
if self.diag:
if k == 'esc':
self.restore_primary()
if k == 'left' or k == 'meta enter':
self.diag.save_settings()
self.restore_primary()
return True return True
def connect(self, nettype, networkid, networkentry=None): def connect(self, nettype, networkid, networkentry=None):

View File

@@ -28,7 +28,7 @@ import subprocess
VERSION_NUM = '1.6.0a1' VERSION_NUM = '1.6.0a1'
# REVISION_NUM is automatically updated # REVISION_NUM is automatically updated
REVISION_NUM = 'unknown' REVISION_NUM = 'unknown'
CURSES_REVNO = 'uimod-r286' CURSES_REVNO = 'uimod-r287'
try: try:
if not os.path.exists('vcsinfo.py'): if not os.path.exists('vcsinfo.py'):