mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 20:38:00 +01:00
curses/curses_misc.py:
Added a Dialog class, mostly borrowed from a urwid example curses/prefs_curses.py: Added the DNS domain to the dialog, as was done in the GTK UI curses/wicd-curses.py: Added a semi-pretty about dialog. curses/README: Activating about dialog is done by "A"
This commit is contained in:
@@ -18,6 +18,7 @@ D : disconnect from active network
|
|||||||
ESC : if connecting to a network, stop doing so
|
ESC : if connecting to a network, stop doing so
|
||||||
ENTER : Attempt connection to selected network
|
ENTER : Attempt connection to selected network
|
||||||
P : Display preferences dialog
|
P : Display preferences dialog
|
||||||
|
A : Display "About" dialog
|
||||||
|
|
||||||
IN DIALOGS:
|
IN DIALOGS:
|
||||||
ESC or Q: Quit dialog without saving information (if present)
|
ESC or Q: Quit dialog without saving information (if present)
|
||||||
|
|||||||
@@ -272,3 +272,75 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
def get_selected(self):
|
def get_selected(self):
|
||||||
wid,pos = self.overlay._listbox.get_focus()
|
wid,pos = self.overlay._listbox.get_focus()
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
|
# Almost completely ripped from rbreu_filechooser.py:
|
||||||
|
# http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py
|
||||||
|
class Dialog(urwid.WidgetWrap):
|
||||||
|
"""
|
||||||
|
Creates a BoxWidget that displays a message
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
|
||||||
|
b_pressed -- Contains the label of the last button pressed or None if no
|
||||||
|
button has been pressed.
|
||||||
|
edit_text -- After a button is pressed, this contains the text the user
|
||||||
|
has entered in the edit field
|
||||||
|
"""
|
||||||
|
|
||||||
|
b_pressed = None
|
||||||
|
edit_text = None
|
||||||
|
|
||||||
|
_blank = urwid.Text("")
|
||||||
|
_edit_widget = None
|
||||||
|
_mode = None
|
||||||
|
|
||||||
|
def __init__(self, msg, buttons, attr, width, height, body, ):
|
||||||
|
"""
|
||||||
|
msg -- content of the message widget, one of:
|
||||||
|
plain string -- string is displayed
|
||||||
|
(attr, markup2) -- markup2 is given attribute attr
|
||||||
|
[markupA, markupB, ... ] -- list items joined together
|
||||||
|
buttons -- a list of strings with the button labels
|
||||||
|
attr -- a tuple (background, button, active_button) of attributes
|
||||||
|
width -- width of the message widget
|
||||||
|
height -- height of the message widget
|
||||||
|
body -- widget displayed beneath the message widget
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Text widget containing the message:
|
||||||
|
msg_widget = urwid.Padding(urwid.Text(msg), 'center', width - 4)
|
||||||
|
|
||||||
|
# GridFlow widget containing all the buttons:
|
||||||
|
button_widgets = []
|
||||||
|
|
||||||
|
for button in buttons:
|
||||||
|
button_widgets.append(urwid.AttrWrap(
|
||||||
|
urwid.Button(button, self._action), attr[1], attr[2]))
|
||||||
|
|
||||||
|
button_grid = urwid.GridFlow(button_widgets, 12, 2, 1, 'center')
|
||||||
|
|
||||||
|
# Combine message widget and button widget:
|
||||||
|
widget_list = [msg_widget, self._blank, button_grid]
|
||||||
|
self._combined = urwid.AttrWrap(urwid.Filler(
|
||||||
|
urwid.Pile(widget_list, 2)), attr[0])
|
||||||
|
|
||||||
|
# This was the real thing I added to this class
|
||||||
|
self._linebox = urwid.LineBox(self._combined)
|
||||||
|
# Place the dialog widget on top of body:
|
||||||
|
# Width and height are increased to accomidate the linebox
|
||||||
|
overlay = urwid.Overlay(self._linebox, body, 'center', width+2,
|
||||||
|
'middle', height+2)
|
||||||
|
|
||||||
|
urwid.WidgetWrap.__init__(self, overlay)
|
||||||
|
|
||||||
|
|
||||||
|
def _action(self, button):
|
||||||
|
"""
|
||||||
|
Function called when a button is pressed.
|
||||||
|
Should not be called manually.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.b_pressed = button.get_label()
|
||||||
|
if self._edit_widget:
|
||||||
|
self.edit_text = self._edit_widget.get_edit_text()
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
global_dns_cat_t = ('header','Global DNS Servers')
|
global_dns_cat_t = ('header','Global DNS Servers')
|
||||||
global_dns_t = ('editcp',language['use_global_dns'])
|
global_dns_t = ('editcp',language['use_global_dns'])
|
||||||
|
dns_dom_t = ('editcp',' DNS Domain: ')
|
||||||
search_dom_t = ('editcp',' Search domain:')
|
search_dom_t = ('editcp',' Search domain:')
|
||||||
dns1_t = ('editcp',' DNS server 1: ')
|
dns1_t = ('editcp',' DNS server 1: ')
|
||||||
dns2_t = ('editcp',' DNS server 2: ')
|
dns2_t = ('editcp',' DNS server 2: ')
|
||||||
@@ -132,6 +133,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.global_dns_checkb = 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.dns_dom = ToggleEdit(dns_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)
|
||||||
@@ -149,7 +151,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
self.always_show_wired_checkb,_blank,
|
self.always_show_wired_checkb,_blank,
|
||||||
self.global_dns_cat,
|
self.global_dns_cat,
|
||||||
self.global_dns_checkb,#_blank,
|
self.global_dns_checkb,#_blank,
|
||||||
self.search_dom,
|
self.search_dom,self.dns_dom,
|
||||||
self.dns1,self.dns2,self.dns3,_blank,
|
self.dns1,self.dns2,self.dns3,_blank,
|
||||||
self.wired_auto_cat,
|
self.wired_auto_cat,
|
||||||
self.wired_auto_1,
|
self.wired_auto_1,
|
||||||
@@ -273,7 +275,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
theDNS = daemon.GetGlobalDNSAddresses()
|
theDNS = daemon.GetGlobalDNSAddresses()
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for w in self.dns1,self.dns2,self.dns3,self.search_dom :
|
for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom :
|
||||||
w.set_edit_text(misc.noneToBlankString(theDNS[i]))
|
w.set_edit_text(misc.noneToBlankString(theDNS[i]))
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
@@ -323,7 +325,8 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
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())
|
||||||
daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
|
daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
|
||||||
self.dns3.get_edit_text(), self.search_dom.get_edit_text())
|
self.dns3.get_edit_text(), self.dns_dom.get_edit_text(),
|
||||||
|
self.search_dom.get_edit_text())
|
||||||
daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
|
daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
|
||||||
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
|
daemon.SetWiredInterface(self.wired_edit.get_edit_text())
|
||||||
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_selected()])
|
daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_selected()])
|
||||||
@@ -369,7 +372,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
|
|
||||||
# DNS CheckBox callback
|
# 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.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom:
|
||||||
w.set_sensitive(new_state)
|
w.set_sensitive(new_state)
|
||||||
|
|
||||||
# Button callbacks
|
# Button callbacks
|
||||||
@@ -409,7 +412,7 @@ class PrefsDialog(urwid.WidgetWrap):
|
|||||||
overlay.keypress(dim, k)
|
overlay.keypress(dim, k)
|
||||||
if self.CANCEL_PRESSED:
|
if self.CANCEL_PRESSED:
|
||||||
return False
|
return False
|
||||||
if self.OK_PRESSED:
|
if self.OK_PRESSED in keys:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ at least get a network connection. Or those who don't like using X. :-)
|
|||||||
Comments, criticisms, patches, bug reports all welcome!
|
Comments, criticisms, patches, bug reports all welcome!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
##### NOTICE: THIS ONLY WORKS WITH THE SOURCE IN WICD 1.6 AS FOUND IN THE BZR
|
|
||||||
##### REPOSITORIES!
|
|
||||||
|
|
||||||
# UI stuff
|
# UI stuff
|
||||||
#import urwid.raw_display
|
#import urwid.raw_display
|
||||||
import urwid.curses_display
|
import urwid.curses_display
|
||||||
@@ -56,7 +53,7 @@ import sys
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
# Curses UIs for other stuff
|
# Curses UIs for other stuff
|
||||||
from curses_misc import SelText,ComboBox
|
from curses_misc import SelText,ComboBox,Dialog
|
||||||
import prefs_curses
|
import prefs_curses
|
||||||
from prefs_curses import PrefsDialog
|
from prefs_curses import PrefsDialog
|
||||||
|
|
||||||
@@ -208,6 +205,42 @@ def gen_network_list():
|
|||||||
wlessL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
|
wlessL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
|
||||||
return (wiredL,wlessL)
|
return (wiredL,wlessL)
|
||||||
|
|
||||||
|
def about_dialog(body):
|
||||||
|
# This looks A LOT better when it is actually displayed. I promise :-).
|
||||||
|
# The ASCII Art "Wicd" was made from the "smslant" font on one of those
|
||||||
|
# online ASCII big text generators.
|
||||||
|
theText = [
|
||||||
|
('green'," /// \\\\\\")," _ ___ __\n",
|
||||||
|
('green'," /// \\\\\\")," | | /| / (_)______/ /\n",
|
||||||
|
('green'," /// \\\\\\")," | |/ |/ / / __/ _ / \n",
|
||||||
|
('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ \n",
|
||||||
|
('green',"||| ||"),"(|^|)",('green',"|| |||"),
|
||||||
|
" ($VERSION) \n".replace("$VERSION",daemon.Hello()),
|
||||||
|
|
||||||
|
('green',"\\|| \\\\")," |+| ",('green',"// ||/ \n"),
|
||||||
|
('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net \n",
|
||||||
|
('green'," \\\\\\")," |+| ",('green',"///")," Brought to you by:\n",
|
||||||
|
('green'," \\\\\\")," |+| "('green',"///")," Adam Blackburn (wicd)\n",
|
||||||
|
" ___|+|___ Dan O'Reilly (wicd)\n",
|
||||||
|
" |---------| Andrew Psaltis (this ui)\n",
|
||||||
|
"---------------------------------------------------"]
|
||||||
|
about = Dialog(theText,['OK'],('body','body','focus'),55,14,body)
|
||||||
|
|
||||||
|
keys = True
|
||||||
|
dim = ui.get_cols_rows()
|
||||||
|
while True:
|
||||||
|
if keys:
|
||||||
|
ui.draw_screen(dim, about.render(dim, True))
|
||||||
|
|
||||||
|
keys = ui.get_input()
|
||||||
|
if "window resize" in keys:
|
||||||
|
dim = ui.get_cols_rows()
|
||||||
|
if "esc" in keys:
|
||||||
|
return False
|
||||||
|
for k in keys:
|
||||||
|
about.keypress(dim, k)
|
||||||
|
if about.b_pressed == 'OK':
|
||||||
|
return False
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### APPLICATION INTERFACE CLASS
|
##### APPLICATION INTERFACE CLASS
|
||||||
@@ -449,6 +482,8 @@ class appGUI():
|
|||||||
if dialog.run(ui,self.size,self.frame):
|
if dialog.run(ui,self.size,self.frame):
|
||||||
dialog.save_results()
|
dialog.save_results()
|
||||||
self.update_ui()
|
self.update_ui()
|
||||||
|
if "A" in keys:
|
||||||
|
about_dialog(self.frame)
|
||||||
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()
|
||||||
@@ -524,7 +559,11 @@ def main():
|
|||||||
('editcp', 'default', 'default', 'standout'),
|
('editcp', 'default', 'default', 'standout'),
|
||||||
('editbx', 'light gray', 'dark blue'),
|
('editbx', 'light gray', 'dark blue'),
|
||||||
('editfc', 'white','dark blue', 'bold'),
|
('editfc', 'white','dark blue', 'bold'),
|
||||||
('tab active','dark green','light gray')])
|
('tab active','dark green','light gray'),
|
||||||
|
# Simple colors around text
|
||||||
|
('green','dark green','default'),
|
||||||
|
('blue','dark blue','default'),
|
||||||
|
('red','dark red','default')])
|
||||||
# This is a wrapper around a function that calls another a function that is a
|
# This is a wrapper around a function that calls another a function that is a
|
||||||
# wrapper around a infinite loop. Fun.
|
# wrapper around a infinite loop. Fun.
|
||||||
ui.run_wrapper(run)
|
ui.run_wrapper(run)
|
||||||
|
|||||||
Reference in New Issue
Block a user