mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 12:28:08 +01:00
Things are coming along...
curses/netentry_curses.py: Realigned some text
curses/curses_misc.py:
Added support for clicking stuff (doesn't do anything except change a label
for now)
The keys 'left' and 'right' now accepted, and translated into fake arrows
Added a debug mode for the OptCols
curses/wicd-curses.py:
Removed if loop in locals() from the exception wrapper, this was causing bugs
in OptCols to spam my console
Debug mode on the optcols is set to default (for now)
Cleaned up idle_incr
Removed some of the exception wrappers
This commit is contained in:
@@ -136,7 +136,8 @@ class MaskingEdit(urwid.Edit):
|
|||||||
Render edit widget and return canvas. Include cursor when in
|
Render edit widget and return canvas. Include cursor when in
|
||||||
focus.
|
focus.
|
||||||
"""
|
"""
|
||||||
# If we aren't masking anything ATM, then act like an Edit. No problems.
|
# If we aren't masking anything ATM, then act like an Edit.
|
||||||
|
# No problems.
|
||||||
if self.mask_mode == "off" or (self.mask_mode == 'no_focus' and focus == True):
|
if self.mask_mode == "off" or (self.mask_mode == 'no_focus' and focus == True):
|
||||||
canv = self.__super.render((maxcol,),focus)
|
canv = self.__super.render((maxcol,),focus)
|
||||||
# The cache messes this thing up, because I am totally changing what
|
# The cache messes this thing up, because I am totally changing what
|
||||||
@@ -438,7 +439,8 @@ class Dialog2(urwid.WidgetWrap):
|
|||||||
def run(self,ui,parent):
|
def run(self,ui,parent):
|
||||||
ui.set_mouse_tracking()
|
ui.set_mouse_tracking()
|
||||||
size = ui.get_cols_rows()
|
size = ui.get_cols_rows()
|
||||||
overlay = urwid.Overlay(urwid.LineBox(self.view), parent, 'center', self.width,
|
overlay = urwid.Overlay(urwid.LineBox(self.view),
|
||||||
|
parent, 'center', self.width,
|
||||||
'middle', self.height)
|
'middle', self.height)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@@ -514,31 +516,80 @@ class InputDialog(Dialog2):
|
|||||||
return exitcode, self.edit.get_edit_text()
|
return exitcode, self.edit.get_edit_text()
|
||||||
|
|
||||||
|
|
||||||
|
class ClickCols(urwid.WidgetWrap):
|
||||||
|
def __init__(self,items,callback=None,args=None):
|
||||||
|
cols = urwid.Columns(items)
|
||||||
|
self.__super.__init__(cols)
|
||||||
|
self.callback = callback
|
||||||
|
self.args = args
|
||||||
|
def mouse_event(self,size,event,button,x,y,focus):
|
||||||
|
self.callback(self.args)
|
||||||
|
|
||||||
# htop-style menu menu-bar on the bottom of the screen
|
# htop-style menu menu-bar on the bottom of the screen
|
||||||
class OptCols(urwid.WidgetWrap):
|
class OptCols(urwid.WidgetWrap):
|
||||||
# tuples = [(key,desc,on_event)], on_event currently ignored
|
# tuples = [(key,desc,on_event)], on_event currently ignored
|
||||||
# attrs = (attr_key,attr_desc)
|
# attrs = (attr_key,attr_desc)
|
||||||
def __init__(self,tuples,attrs=('body','infobar')):
|
# mentions of 'left' and right will be converted to <- and -> respectively
|
||||||
|
def __init__(self,tuples,attrs=('body','infobar'),debug=False):
|
||||||
# Find the longest string. Keys for this bar should be no greater than
|
# Find the longest string. Keys for this bar should be no greater than
|
||||||
# 2 characters long (e.g., -> for left)
|
# 2 characters long (e.g., -> for left)
|
||||||
maxlen = 6
|
#maxlen = 6
|
||||||
for i in tuples:
|
#for i in tuples:
|
||||||
newmax = len(i[0])+len(i[1])
|
# newmax = len(i[0])+len(i[1])
|
||||||
if newmax > maxlen:
|
# if newmax > maxlen:
|
||||||
maxlen = newmax
|
# maxlen = newmax
|
||||||
|
|
||||||
# Construct the texts
|
# Construct the texts
|
||||||
textList = []
|
textList = []
|
||||||
i = 0
|
i = 0
|
||||||
|
# callbacks map the text contents to its assigned callback.
|
||||||
|
self.callbacks = []
|
||||||
for cmd in tuples:
|
for cmd in tuples:
|
||||||
|
if cmd[0] == 'left':
|
||||||
|
key = '<-'
|
||||||
|
elif cmd[0] == 'right':
|
||||||
|
key = '->'
|
||||||
|
else:
|
||||||
|
key = cmd[0]
|
||||||
#theText = urwid.Text([(attrs[0],cmd[0]),(attrs[1],cmd[1])])
|
#theText = urwid.Text([(attrs[0],cmd[0]),(attrs[1],cmd[1])])
|
||||||
col = urwid.Columns([('fixed',len(cmd[0]),
|
if debug:
|
||||||
urwid.Text((attrs[0],cmd[0])) ),
|
callback = self.debugClick
|
||||||
urwid.AttrWrap(urwid.Text(cmd[1]),attrs[1])])
|
args = cmd[1]
|
||||||
if i != len(tuples)-1:
|
#self.callbacks.append(cmd[2])
|
||||||
textList.append(('fixed',maxlen,col))
|
col = ClickCols([
|
||||||
else: # The last one
|
('fixed',len(key),urwid.Text((attrs[0],key)) ),
|
||||||
|
urwid.AttrWrap(urwid.Text(cmd[1]),attrs[1])],
|
||||||
|
callback,args)
|
||||||
|
#if i != len(tuples)-1:
|
||||||
|
# textList.append(('fixed',maxlen,col))
|
||||||
|
#else: # The last one
|
||||||
textList.append(col)
|
textList.append(col)
|
||||||
i+=1
|
i+=1
|
||||||
|
if debug:
|
||||||
|
self.debug = urwid.Text("DEBUG_MODE")
|
||||||
|
textList.append(('fixed',10,self.debug))
|
||||||
|
|
||||||
cols = urwid.Columns(textList)
|
cols = urwid.Columns(textList)
|
||||||
self.__super.__init__(cols)
|
self.__super.__init__(cols)
|
||||||
|
def debugClick(self,args):
|
||||||
|
self.debug.set_text(args)
|
||||||
|
|
||||||
|
def mouse_event(self,size,event,button,x,y,focus):
|
||||||
|
# Widgets are evenly long (as of current), so...
|
||||||
|
return self._w.mouse_event(size,event,button,x,y,focus)
|
||||||
|
"""
|
||||||
|
if self.debug:
|
||||||
|
if x > size[0]-10:
|
||||||
|
return
|
||||||
|
widsize = (size[0]-10)/len(self.callbacks)
|
||||||
|
else:
|
||||||
|
widsize = size[0]/len(self.callbacks)
|
||||||
|
widnum = x/widsize
|
||||||
|
if self.debug:
|
||||||
|
text = str(widnum)
|
||||||
|
if self.callbacks[widnum] == None:
|
||||||
|
text += " None"
|
||||||
|
self.debug.set_text(text)
|
||||||
|
elif self.callbacks[widnum] != None:
|
||||||
|
self.callbacks[widnum]()
|
||||||
|
"""
|
||||||
|
|||||||
@@ -196,8 +196,8 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
|
|||||||
k = self.overlay.keypress(dim, k)
|
k = self.overlay.keypress(dim, k)
|
||||||
if k in ('up','page up'):
|
if k in ('up','page up'):
|
||||||
self._w.set_focus('body')
|
self._w.set_focus('body')
|
||||||
# Until I figure out a better way to do this, then this will
|
# Until I figure out a better way to do this, then
|
||||||
# have to do.
|
# this will have to do.
|
||||||
self._w.body.get_focus()[0].get_focus()._invalidate()
|
self._w.body.get_focus()[0].get_focus()._invalidate()
|
||||||
#self._w.body.keypress(dim,'down')
|
#self._w.body.keypress(dim,'down')
|
||||||
elif k in ('down','page down'):
|
elif k in ('down','page down'):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -* coding: utf-8 -*-
|
||||||
|
|
||||||
""" wicd-curses. (curses/urwid-based) console interface to wicd
|
""" wicd-curses. (curses/urwid-based) console interface to wicd
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ class wrap_exceptions:
|
|||||||
raise
|
raise
|
||||||
except :
|
except :
|
||||||
# Quit the loop
|
# Quit the loop
|
||||||
if 'loop' in locals():
|
#if 'loop' in locals():
|
||||||
loop.quit()
|
loop.quit()
|
||||||
# Zap the screen
|
# Zap the screen
|
||||||
ui.stop()
|
ui.stop()
|
||||||
@@ -487,6 +488,7 @@ class AdHocDialog(Dialog2):
|
|||||||
class appGUI():
|
class appGUI():
|
||||||
"""The UI itself, all glory belongs to it!"""
|
"""The UI itself, all glory belongs to it!"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
global loop
|
||||||
self.size = ui.get_cols_rows()
|
self.size = ui.get_cols_rows()
|
||||||
# Happy screen saying that you can't do anything because we're scanning
|
# Happy screen saying that you can't do anything because we're scanning
|
||||||
# for networks. :-)
|
# for networks. :-)
|
||||||
@@ -527,20 +529,20 @@ class appGUI():
|
|||||||
# Keymappings proposed by nanotube in #wicd
|
# Keymappings proposed by nanotube in #wicd
|
||||||
keys = [
|
keys = [
|
||||||
('H' ,'Help' ,None),
|
('H' ,'Help' ,None),
|
||||||
('->','Config',None),
|
('right','Config',None),
|
||||||
#(' ',' ',None),
|
#(' ',' ',None),
|
||||||
('C' ,'Connect',None),
|
('C' ,'Connect',None),
|
||||||
('D' ,'Disconn',None),
|
('D' ,'Disconn',None),
|
||||||
('R' ,'Refresh',None),
|
('R' ,'Refresh',None),
|
||||||
('P' ,'Prefs',None),
|
('P' ,'Prefs',None),
|
||||||
('I' ,'Hidden',None),
|
('I' ,'Hidden',None),
|
||||||
('Q' ,'Quit',None)
|
('Q' ,'Quit',loop.quit)
|
||||||
]
|
]
|
||||||
#(' ' ,' ',None),
|
#(' ' ,' ',None),
|
||||||
#(' ' ,' ',None),
|
#(' ' ,' ',None),
|
||||||
#(' ' ,' ',None),
|
#(' ' ,' ',None),
|
||||||
|
|
||||||
self.footer1 = OptCols(keys)
|
self.footer1 = OptCols(keys,debug=True)
|
||||||
self.footer2 = urwid.Columns([urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important'),urwid.Text('0',align='right')])
|
self.footer2 = urwid.Columns([urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important'),urwid.Text('0',align='right')])
|
||||||
self.footerList = urwid.ListBox([self.footer1,self.footer2])
|
self.footerList = urwid.ListBox([self.footer1,self.footer2])
|
||||||
# Pop takes a number!
|
# Pop takes a number!
|
||||||
@@ -734,15 +736,8 @@ class appGUI():
|
|||||||
# Not necessary in the end, but I will be using footer1 for stuff in
|
# Not necessary in the end, but I will be using footer1 for stuff in
|
||||||
# the long run, so I might as well put something there.
|
# the long run, so I might as well put something there.
|
||||||
incr = 0
|
incr = 0
|
||||||
@wrap_exceptions()
|
#@wrap_exceptions()
|
||||||
def idle_incr(self):
|
def idle_incr(self):
|
||||||
theText = " "
|
|
||||||
if self.connecting:
|
|
||||||
theText += "-- "+language['connecting']+' -- '+language["esc_to_cancel"]
|
|
||||||
else:
|
|
||||||
theText += "-- Press H or ? for Help"
|
|
||||||
quit_note = ' -- '+language["press_to_quit"]
|
|
||||||
#self.footer1 = urwid.Text(str(self.incr) + theText+quit_note,wrap='clip')
|
|
||||||
self.incr+=1
|
self.incr+=1
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -765,7 +760,7 @@ class appGUI():
|
|||||||
#self.update_status()
|
#self.update_status()
|
||||||
canvas = self.frame.render( (self.size),True )
|
canvas = self.frame.render( (self.size),True )
|
||||||
### GRRRRRRRRRRRRRRRRRRRRR ->^^^^
|
### GRRRRRRRRRRRRRRRRRRRRR ->^^^^
|
||||||
# It looks like if I wanted to get the statusbar to update itself
|
# It looks like if I want to get the statusbar to update itself
|
||||||
# continuously, I would have to use overlay the canvasses and redirect
|
# 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
|
# the input. I'll try to get that working at a later time, if people
|
||||||
# want that "feature".
|
# want that "feature".
|
||||||
@@ -875,7 +870,6 @@ class appGUI():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
global ui
|
global ui
|
||||||
|
|
||||||
# We are _not_ python.
|
# We are _not_ python.
|
||||||
misc.RenameProcess('wicd-curses')
|
misc.RenameProcess('wicd-curses')
|
||||||
|
|
||||||
@@ -908,7 +902,7 @@ def main():
|
|||||||
('editfc', 'white','dark blue', 'bold'),
|
('editfc', 'white','dark blue', 'bold'),
|
||||||
('editnfc','dark gray','default'),
|
('editnfc','dark gray','default'),
|
||||||
('tab active','dark green','light gray'),
|
('tab active','dark green','light gray'),
|
||||||
('infobar','black','dark cyan'),
|
('infobar','black','dark blue'),
|
||||||
# Simple colors around text
|
# Simple colors around text
|
||||||
('green','dark green','default'),
|
('green','dark green','default'),
|
||||||
('blue','dark blue','default'),
|
('blue','dark blue','default'),
|
||||||
@@ -921,6 +915,7 @@ def main():
|
|||||||
|
|
||||||
def run():
|
def run():
|
||||||
global loop
|
global loop
|
||||||
|
loop = gobject.MainLoop()
|
||||||
|
|
||||||
ui.set_mouse_tracking()
|
ui.set_mouse_tracking()
|
||||||
app = appGUI()
|
app = appGUI()
|
||||||
@@ -933,7 +928,6 @@ def run():
|
|||||||
# I've left this commented out many times.
|
# I've left this commented out many times.
|
||||||
bus.add_signal_receiver(app.update_netlist, 'StatusChanged',
|
bus.add_signal_receiver(app.update_netlist, 'StatusChanged',
|
||||||
'org.wicd.daemon')
|
'org.wicd.daemon')
|
||||||
loop = gobject.MainLoop()
|
|
||||||
# Update what the interface looks like as an idle function
|
# Update what the interface looks like as an idle function
|
||||||
gobject.idle_add(app.update_ui)
|
gobject.idle_add(app.update_ui)
|
||||||
# Update the connection status on the bottom every 1.5 s.
|
# Update the connection status on the bottom every 1.5 s.
|
||||||
|
|||||||
Reference in New Issue
Block a user