mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 12:58:07 +01:00
Progress is being made, apparently
curses/curses_misc.py:
Made Dialog a bit more generic with the new Dialog2, also supports mouse events.
Included TextDialog and InputDialog as subclasses of Dialog2
curses/netentry_curses.py:
Changed error() to support Dialog2
Added support for mouse events
curses/prefs_curses.py:
Added support for mouse events
curses/wicd-curses.py:
Added support for wicd's hidden wireless-network functionality
(Really) finished refactoring for the changes in ComboBox
Made some transitions a bit more immediate by calling update_ui() manually
Refactored to about_dialog to support Dialog2
Added support for mouse events (clicking to select, mostly)
Added support for retaining current list netlist focus throughout screen updates
(Hopefully) Added support for handling an instance of 0 available wireless
networks
in/man=wicd-curses.8.in: Hidden network support is fully functional
man/wicd-client.1: Added a word. (You'll live.)
setup.py: From last commit: Added the python "shebang" to the top of the file
This commit is contained in:
@@ -350,73 +350,124 @@ class ComboBox(urwid.WidgetWrap):
|
||||
def set_sensitive(self,state):
|
||||
self.cbox.set_sensitive(state)
|
||||
|
||||
# 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
|
||||
# This is a h4x3d copy of some of the code in Ian Ward's dialog.py example.
|
||||
class DialogExit(Exception):
|
||||
pass
|
||||
|
||||
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
|
||||
"""
|
||||
class Dialog2(urwid.WidgetWrap):
|
||||
def __init__(self, text, height,width, body=None ):
|
||||
self.width = int(width)
|
||||
if width <= 0:
|
||||
self.width = ('relative', 80)
|
||||
self.height = int(height)
|
||||
if height <= 0:
|
||||
self.height = ('relative', 80)
|
||||
|
||||
self.body = body
|
||||
if body is None:
|
||||
# fill space with nothing
|
||||
body = urwid.Filler(urwid.Divider(),'top')
|
||||
|
||||
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)
|
||||
self.frame = urwid.Frame( body, focus_part='footer')
|
||||
if text is not None:
|
||||
self.frame.header = urwid.Pile( [urwid.Text(text),
|
||||
urwid.Divider()] )
|
||||
w = self.frame
|
||||
self.view = w
|
||||
|
||||
urwid.WidgetWrap.__init__(self, overlay)
|
||||
# pad area around listbox
|
||||
#w = urwid.Padding(w, ('fixed left',2), ('fixed right',2))
|
||||
#w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1))
|
||||
#w = urwid.AttrWrap(w, 'body')
|
||||
# buttons: tuple of name,exitcode
|
||||
def add_buttons(self, buttons):
|
||||
l = []
|
||||
for name, exitcode in buttons:
|
||||
b = urwid.Button( name, self.button_press )
|
||||
b.exitcode = exitcode
|
||||
b = urwid.AttrWrap( b, 'body','focus' )
|
||||
l.append( b )
|
||||
self.buttons = urwid.GridFlow(l, 10, 3, 1, 'center')
|
||||
self.frame.footer = urwid.Pile( [ urwid.Divider(),
|
||||
self.buttons ], focus_item = 1)
|
||||
|
||||
def button_press(self, button):
|
||||
raise DialogExit(button.exitcode)
|
||||
|
||||
def run(self,ui,parent):
|
||||
ui.set_mouse_tracking()
|
||||
size = ui.get_cols_rows()
|
||||
overlay = urwid.Overlay(urwid.LineBox(self.view), parent, 'center', self.width,
|
||||
'middle', self.height)
|
||||
try:
|
||||
while True:
|
||||
canvas = overlay.render( size, focus=True )
|
||||
ui.draw_screen( size, canvas )
|
||||
keys = None
|
||||
while not keys:
|
||||
keys = ui.get_input()
|
||||
for k in keys:
|
||||
if urwid.is_mouse_event(k):
|
||||
event, button, col, row = k
|
||||
overlay.mouse_event( size,
|
||||
event, button, col, row,
|
||||
focus=True)
|
||||
if k == 'window resize':
|
||||
size = ui.get_cols_rows()
|
||||
k = self.view.keypress( size, k )
|
||||
if k == 'esc':
|
||||
raise DialogExit(-1)
|
||||
if k:
|
||||
self.unhandled_key( size, k)
|
||||
except DialogExit, e:
|
||||
return self.on_exit( e.args[0] )
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
return exitcode, ""
|
||||
|
||||
def unhandled_key(self, size, key):
|
||||
pass
|
||||
|
||||
class TextDialog(Dialog2):
|
||||
def __init__(self, text, height, width, header=None):
|
||||
l = []
|
||||
# read the whole file (being slow, not lazy this time)
|
||||
#for line in open(file).readlines():
|
||||
# l.append( urwid.Text( line.rstrip() ))
|
||||
l = [urwid.Text(text)]
|
||||
body = urwid.ListBox(l)
|
||||
body = urwid.AttrWrap(body, 'body')
|
||||
|
||||
Dialog2.__init__(self, header, height+2, width+2, body)
|
||||
self.add_buttons([('OK',1)])
|
||||
|
||||
|
||||
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()
|
||||
def unhandled_key(self, size, k):
|
||||
if k in ('up','page up','down','page down'):
|
||||
self.frame.set_focus('body')
|
||||
self.view.keypress( size, k )
|
||||
self.frame.set_focus('footer')
|
||||
|
||||
class InputDialog(Dialog2):
|
||||
def __init__(self, text, height, width,ok_name='OK'):
|
||||
self.edit = urwid.Edit(wrap='clip')
|
||||
body = urwid.ListBox([self.edit])
|
||||
body = urwid.AttrWrap(body, 'editbx','editfc')
|
||||
|
||||
Dialog2.__init__(self, text, height, width, body)
|
||||
|
||||
self.frame.set_focus('body')
|
||||
self.add_buttons([(ok_name,0),('Cancel',-1)])
|
||||
|
||||
def unhandled_key(self, size, k):
|
||||
if k in ('up','page up'):
|
||||
self.frame.set_focus('body')
|
||||
if k in ('down','page down'):
|
||||
self.frame.set_focus('footer')
|
||||
if k == 'enter':
|
||||
# pass enter to the "ok" button
|
||||
self.frame.set_focus('footer')
|
||||
self.view.keypress( size, k )
|
||||
|
||||
def on_exit(self, exitcode):
|
||||
return exitcode, self.edit.get_edit_text()
|
||||
|
||||
Reference in New Issue
Block a user