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
|
||||
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):
|
||||
canv = self.__super.render((maxcol,),focus)
|
||||
# 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):
|
||||
ui.set_mouse_tracking()
|
||||
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)
|
||||
try:
|
||||
while True:
|
||||
@@ -514,31 +516,80 @@ class InputDialog(Dialog2):
|
||||
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
|
||||
class OptCols(urwid.WidgetWrap):
|
||||
# tuples = [(key,desc,on_event)], on_event currently ignored
|
||||
# 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
|
||||
# 2 characters long (e.g., -> for left)
|
||||
maxlen = 6
|
||||
for i in tuples:
|
||||
newmax = len(i[0])+len(i[1])
|
||||
if newmax > maxlen:
|
||||
maxlen = newmax
|
||||
#maxlen = 6
|
||||
#for i in tuples:
|
||||
# newmax = len(i[0])+len(i[1])
|
||||
# if newmax > maxlen:
|
||||
# maxlen = newmax
|
||||
|
||||
# Construct the texts
|
||||
textList = []
|
||||
i = 0
|
||||
# callbacks map the text contents to its assigned callback.
|
||||
self.callbacks = []
|
||||
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])])
|
||||
col = urwid.Columns([('fixed',len(cmd[0]),
|
||||
urwid.Text((attrs[0],cmd[0])) ),
|
||||
urwid.AttrWrap(urwid.Text(cmd[1]),attrs[1])])
|
||||
if i != len(tuples)-1:
|
||||
textList.append(('fixed',maxlen,col))
|
||||
else: # The last one
|
||||
if debug:
|
||||
callback = self.debugClick
|
||||
args = cmd[1]
|
||||
#self.callbacks.append(cmd[2])
|
||||
col = ClickCols([
|
||||
('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)
|
||||
i+=1
|
||||
if debug:
|
||||
self.debug = urwid.Text("DEBUG_MODE")
|
||||
textList.append(('fixed',10,self.debug))
|
||||
|
||||
cols = urwid.Columns(textList)
|
||||
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)
|
||||
if k in ('up','page up'):
|
||||
self._w.set_focus('body')
|
||||
# Until I figure out a better way to do this, then this will
|
||||
# have to do.
|
||||
# Until I figure out a better way to do this, then
|
||||
# this will have to do.
|
||||
self._w.body.get_focus()[0].get_focus()._invalidate()
|
||||
#self._w.body.keypress(dim,'down')
|
||||
elif k in ('down','page down'):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -* coding: utf-8 -*-
|
||||
|
||||
""" wicd-curses. (curses/urwid-based) console interface to wicd
|
||||
|
||||
@@ -99,7 +100,7 @@ class wrap_exceptions:
|
||||
raise
|
||||
except :
|
||||
# Quit the loop
|
||||
if 'loop' in locals():
|
||||
#if 'loop' in locals():
|
||||
loop.quit()
|
||||
# Zap the screen
|
||||
ui.stop()
|
||||
@@ -487,6 +488,7 @@ class AdHocDialog(Dialog2):
|
||||
class appGUI():
|
||||
"""The UI itself, all glory belongs to it!"""
|
||||
def __init__(self):
|
||||
global loop
|
||||
self.size = ui.get_cols_rows()
|
||||
# Happy screen saying that you can't do anything because we're scanning
|
||||
# for networks. :-)
|
||||
@@ -527,20 +529,20 @@ class appGUI():
|
||||
# Keymappings proposed by nanotube in #wicd
|
||||
keys = [
|
||||
('H' ,'Help' ,None),
|
||||
('->','Config',None),
|
||||
('right','Config',None),
|
||||
#(' ',' ',None),
|
||||
('C' ,'Connect',None),
|
||||
('D' ,'Disconn',None),
|
||||
('R' ,'Refresh',None),
|
||||
('P' ,'Prefs',None),
|
||||
('I' ,'Hidden',None),
|
||||
('Q' ,'Quit',None)
|
||||
('Q' ,'Quit',loop.quit)
|
||||
]
|
||||
#(' ' ,' ',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.footerList = urwid.ListBox([self.footer1,self.footer2])
|
||||
# Pop takes a number!
|
||||
@@ -734,15 +736,8 @@ class appGUI():
|
||||
# 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.
|
||||
incr = 0
|
||||
@wrap_exceptions()
|
||||
#@wrap_exceptions()
|
||||
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
|
||||
return True
|
||||
|
||||
@@ -765,7 +760,7 @@ class appGUI():
|
||||
#self.update_status()
|
||||
canvas = self.frame.render( (self.size),True )
|
||||
### 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
|
||||
# the input. I'll try to get that working at a later time, if people
|
||||
# want that "feature".
|
||||
@@ -875,7 +870,6 @@ class appGUI():
|
||||
|
||||
def main():
|
||||
global ui
|
||||
|
||||
# We are _not_ python.
|
||||
misc.RenameProcess('wicd-curses')
|
||||
|
||||
@@ -908,7 +902,7 @@ def main():
|
||||
('editfc', 'white','dark blue', 'bold'),
|
||||
('editnfc','dark gray','default'),
|
||||
('tab active','dark green','light gray'),
|
||||
('infobar','black','dark cyan'),
|
||||
('infobar','black','dark blue'),
|
||||
# Simple colors around text
|
||||
('green','dark green','default'),
|
||||
('blue','dark blue','default'),
|
||||
@@ -921,6 +915,7 @@ def main():
|
||||
|
||||
def run():
|
||||
global loop
|
||||
loop = gobject.MainLoop()
|
||||
|
||||
ui.set_mouse_tracking()
|
||||
app = appGUI()
|
||||
@@ -933,7 +928,6 @@ def run():
|
||||
# I've left this commented out many times.
|
||||
bus.add_signal_receiver(app.update_netlist, 'StatusChanged',
|
||||
'org.wicd.daemon')
|
||||
loop = gobject.MainLoop()
|
||||
# Update what the interface looks like as an idle function
|
||||
gobject.idle_add(app.update_ui)
|
||||
# Update the connection status on the bottom every 1.5 s.
|
||||
|
||||
Reference in New Issue
Block a user