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

Added mouse support to OptCols. Everything works :-).

This branch will be merged into experimental-nacl once I'm sure that everything works, and I update the documentation.
This commit is contained in:
Andrew Psaltis
2009-03-07 16:26:41 -05:00
parent 9dd7e06b99
commit 7d5fac6f0a
3 changed files with 61 additions and 54 deletions

View File

@@ -530,14 +530,15 @@ class ClickCols(urwid.WidgetWrap):
self.callback = callback
self.args = args
def mouse_event(self,size,event,button,x,y,focus):
if event == "mouse press":
self.callback(self.args)
# htop-style menu menu-bar on the bottom of the screen
class OptCols(urwid.WidgetWrap):
# tuples = [(key,desc,on_event)], on_event currently ignored
# tuples = [(key,desc)], on_event gets passed a key
# attrs = (attr_key,attr_desc)
# mentions of 'left' and right will be converted to <- and -> respectively
def __init__(self,tuples,attrs=('body','infobar'),debug=False):
def __init__(self,tuples,handler,attrs=('body','infobar'),debug=False):
# Find the longest string. Keys for this bar should be no greater than
# 2 characters long (e.g., -> for left)
#maxlen = 6
@@ -564,6 +565,8 @@ class OptCols(urwid.WidgetWrap):
key += '<-'
elif part == 'right':
key += '->'
elif part == 'esc':
key += 'ESC'
else:
key += part
@@ -571,6 +574,9 @@ class OptCols(urwid.WidgetWrap):
if debug:
callback = self.debugClick
args = cmd[1]
else:
callback = handler
args = cmd[0]
#self.callbacks.append(cmd[2])
col = ClickCols([
('fixed',len(key)+1,urwid.Text((attrs[0],key+':')) ),

View File

@@ -163,24 +163,6 @@ def check_for_wireless(iwconfig, wireless_ip, set_status):
# DBUS interfaces do. ^_^
# Whatever calls this must be exception-wrapped if it is run if the UI is up
def gen_network_list():
#id=0
#wiredL = []
#is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
# This one makes a list of strings to put in a combo box.
#for profile in wired.GetWiredProfileList():
#theString = '%4s %25s' % (id, profile)
#### THIS IS wired.blah() in experimental
#print config.GetLastUsedWiredNetwork()
# Tag if no wireless IP present, and wired one is
#if is_active:
# theString = '>'+theString[1:]
#wiredL.append(urwid.AttrWrap(SelText(theString),'connected',
# 'connected focus'))
#else:
#wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
#wiredL.append(theString)
#id+=1
wiredL = wired.GetWiredProfileList()
wlessL = []
# This one makes a list of NetLabels
@@ -239,6 +221,9 @@ def help_dialog(body):
('bold',' Q'),": Quit wicd-curses\n",
])
textF = urwid.Text('Press any key to return.')
# textJ = urwid.Text('Nobody expects the Spanish Inquisition!')
blank = urwid.Text('')
# Pile containing a text and columns?
cols = urwid.Columns([text1,text2])
@@ -250,6 +235,14 @@ def help_dialog(body):
ui.draw_screen(dim, frame.render(dim, True))
keys = ui.get_input()
# Don't stop because someone let go of the mouse on the frame
mouse_release = False
for k in keys:
if urwid.is_mouse_event(k) and k[0] == "mouse release":
mouse_release = True
break
if mouse_release :
continue
if 'window resize' in keys:
dim = ui.get_cols_rows()
elif keys:
@@ -306,10 +299,6 @@ Once there, you can adjust (or add) the "beforescript", "afterscript", and "disc
main()
"""
########################################
##### URWID SUPPORT CLASSES
########################################
def gen_list_header():
if daemon.GetSignalDisplayType() == 0:
# Allocate 25 cols for the ESSID name
@@ -319,6 +308,10 @@ def gen_list_header():
essidgap = 28
return 'C %s %*s %9s %17s %6s %s' % ('STR ',essidgap,'ESSID','ENCRYPT','BSSID','MODE','CHNL')
########################################
##### URWID SUPPORT CLASSES
########################################
# Wireless network label
class NetLabel(urwid.WidgetWrap):
def __init__(self, id, is_active):
@@ -566,7 +559,7 @@ class appGUI():
('Q' ,'Quit',loop.quit)
]
self.primaryCols = OptCols(keys,debug=True)
self.primaryCols = OptCols(keys,self.handle_keys)
#self.time_label = urwid.Text(strftime('%H:%M:%S'))
self.time_label = \
urwid.AttrWrap(urwid.Text(strftime('%H:%M:%S')), 'timebar')
@@ -598,13 +591,14 @@ class appGUI():
def init_other_optcols(self):
# The "tabbed" preferences dialog
self.prefCols = OptCols( [('meta enter','OK'),
('ESC','Cancel'),
('esc','Cancel'),
('meta [','Tab Left',),
('meta ]','Tab Right')],debug=True )
('meta ]','Tab Right')],self.handle_keys
)
self.confCols = OptCols( [
('<-','OK'),
('ESC','Cancel')
],debug=True )
('left','OK'),
('esc','Cancel')
],self.handle_keys)
# Does what it says it does
def lock_screen(self):
@@ -808,20 +802,8 @@ class appGUI():
self.diag = None
self.frame.set_footer(urwid.Pile([self.primaryCols,self.footer2]))
self.update_ui()
# Redraw the screen
@wrap_exceptions()
def update_ui(self):
#self.update_status()
canvas = self.frame.render( (self.size),True )
### GRRRRRRRRRRRRRRRRRRRRR ->^^^^
# It looks like if I want 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()
def handle_keys(self,keys):
if not self.diag:
# Handle keystrokes
if "f8" in keys or 'Q' in keys or 'q' in keys:
@@ -890,6 +872,9 @@ class appGUI():
if "I" in keys:
self.raise_hidden_network_dialog()
if "H" in keys or 'h' in keys or '?' in keys:
# FIXME I shouldn't need this, OptCols messes up this one
# particular button
if not self.diag:
help_dialog(self.frame)
if "S" in keys:
focus = self.thePile.get_focus()
@@ -910,22 +895,38 @@ class appGUI():
data[5],
data[4], False)
if self.diag:
if 'esc' in keys:
self.restore_primary()
if ('left' in keys and issubclass(self.diag.__class__,AdvancedSettingsDialog)) or 'meta enter' in keys:
self.diag.save_settings()
self.restore_primary()
for k in keys:
if urwid.is_mouse_event(k):
event, button, col, row = k
self.frame.mouse_event( self.size,
event, button, col, row,
focus=True)
continue
if k == "window resize":
self.size = ui.get_cols_rows()
continue
k = self.frame.keypress( self.size, k )
if self.diag:
if k == 'esc':
self.restore_primary()
if (k == 'left' and issubclass(self.diag.__class__,AdvancedSettingsDialog)) or k == 'meta enter':
self.diag.save_settings()
self.restore_primary()
# Redraw the screen
@wrap_exceptions()
def update_ui(self):
#self.update_status()
canvas = self.frame.render( (self.size),True )
### GRRRRRRRRRRRRRRRRRRRRR ->^^^^
# It looks like if I want 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()
self.handle_keys(keys)
return True
def connect(self, nettype, networkid, networkentry=None):

View File

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