1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 12:28:08 +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:
Andrew Psaltis
2009-01-01 00:30:53 -05:00
parent 77f0e1c54b
commit f0466be6b8
4 changed files with 125 additions and 10 deletions

View File

@@ -272,3 +272,75 @@ class ComboBox(urwid.WidgetWrap):
def get_selected(self):
wid,pos = self.overlay._listbox.get_focus()
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()