1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 20:38:00 +01:00

curses/wicd-curses.py: Add gobject.MainLoop support, and enable the D-Bus function connections (It works!). Various comments/code cleanup done.

curses/README: f5 refreshes the netlist now
curses/TODO: Added a bunch of features to implement, and removed one of them.
This commit is contained in:
Andrew Psaltis
2008-12-13 16:06:11 -05:00
parent f145b03ca3
commit 64fd3940d6
3 changed files with 72 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
This is a CURSES-based client for wicd. It is designed to imitate wicd-client This is a curses-based client for wicd. It is designed to imitate wicd-client
as much as can be done with a console-based interface. It is written using the as much as can be done with a console-based interface. It is written using the
Urwid (http://excess.org/urwid) toolkit, and thus requires it. Urwid (http://excess.org/urwid) toolkit, and thus requires it.
@@ -10,4 +10,10 @@ connected to anything or not, and that is updated in real time. It does not
actually connect you to anything yet. I'll get on that when I have more free actually connect you to anything yet. I'll get on that when I have more free
time than I do now (which will be soon). time than I do now (which will be soon).
~ ampsaltis Other important things:
F5: refresh wireless networks
F8: quit
~nacl

View File

@@ -1,12 +1,14 @@
Things to do (in no particular order): Things to do (in no particular order):
* Integrate a glib mainloop into the UI so that it can be aware of whether
we're connecting or not by some means.
* Implement the ability to connect/disconnect to/from stuff. * Implement the ability to connect/disconnect to/from stuff.
Yeah, I know that it's important... Yeah, I know that it's important...
* Make a settings dialog * Make a settings dialog
* Implement something that resembles a combo box in urwid * Implement something that resembles a combo box in urwid
* Make a network config dialog * Make a network config dialog
* Make an about dialog
* Implement a keyhandler function for the overall frame
* Make keystrokes customizable
* Make color schemes customizable
Oh, and most importantly: Oh, and most importantly:

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
""" wicd-curses -- a (cursed-based) console interface to wicd """ wicd-curses -- a (curses-based) console interface to wicd
Provides the a console UI for wicd, so that people with broken X servers can Provides the a console UI for wicd, so that people with broken X servers can
at least get a network connection. Or for those who don't like using X. :-) at least get a network connection. Or for those who don't like using X. :-)
@@ -44,14 +44,10 @@ import dbus.service
# It took me a while to figure out that I have to use this. # It took me a while to figure out that I have to use this.
import gobject import gobject
# Other stuff # Other important wicd-related stuff
import wicd.misc as misc import wicd.misc as misc
#import sys #import sys
# Both of these are not currently used, until I can best resolve how to use them
#import functions
#from functions import language #,Functions
# Translations for the text that people will see... as of yet. This code is # Translations for the text that people will see... as of yet. This code is
# already found in the gui.py file # already found in the gui.py file
# Stick into own ui_common file? # Stick into own ui_common file?
@@ -216,6 +212,8 @@ class appGUI():
# And I can't use it yet b/c of that blasted glib mainloop # And I can't use it yet b/c of that blasted glib mainloop
self.screen_locker = urwid.Filler(urwid.Text(('important',"Scanning networks... stand by..."), align='center')) self.screen_locker = urwid.Filler(urwid.Text(('important',"Scanning networks... stand by..."), align='center'))
#self.update_ct = 0
txt = urwid.Text("Wicd Curses Interface",align='right') txt = urwid.Text("Wicd Curses Interface",align='right')
#wrap1 = urwid.AttrWrap(txt, 'black') #wrap1 = urwid.AttrWrap(txt, 'black')
#fill = urwid.Filler(txt) #fill = urwid.Filler(txt)
@@ -224,7 +222,6 @@ class appGUI():
self.update_netlist() self.update_netlist()
#walker = urwid.SimpleListWalker(gen_network_list()) #walker = urwid.SimpleListWalker(gen_network_list())
#thePile = urwid.Pile(walker)
footer = urwid.AttrWrap(urwid.Text("Something will go here... eventually!"),'important') footer = urwid.AttrWrap(urwid.Text("Something will go here... eventually!"),'important')
# Pop takes a number! # Pop takes a number!
#walker.pop(1) #walker.pop(1)
@@ -246,7 +243,9 @@ class appGUI():
netElems = gen_network_list() netElems = gen_network_list()
self.netList = NetList(netElems) self.netList = NetList(netElems)
# Update the footer/status bar
def update_status(self): def update_status(self):
#self.update_ct += 1
if check_for_wired(wired.GetWiredIP(),self.set_status): if check_for_wired(wired.GetWiredIP(),self.set_status):
return True return True
elif check_for_wireless(wireless.GetIwconfig(), elif check_for_wireless(wireless.GetIwconfig(),
@@ -256,58 +255,77 @@ class appGUI():
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
return True return True
# Set the status text, called by the update_status method
def set_status(self,text): def set_status(self,text):
self.frame.set_footer(urwid.AttrWrap(urwid.Text(text),'important')) self.frame.set_footer(urwid.AttrWrap(urwid.Text(text),'important'))
# Yeah, I'm copying code. Anything wrong with that? # Yeah, I'm copying code. Anything wrong with that?
#def dbus_scan_finished(self): def dbus_scan_finished(self):
# #if not self.connecting: # I'm pretty sure that I'll need this later.
# #self.refresh_networks(fresh=False) #if not self.connecting:
# self.unlock_screen() #self.refresh_networks(fresh=False)
self.unlock_screen()
# Same, same, same, same, same, same # Same, same, same, same, same, same
#def dbus_scan_started(self): def dbus_scan_started(self):
# self.lock_screen() self.lock_screen()
# Run the bleeding thing. # Run the bleeding thing.
# Calls the main loop. This is how the thing should be started, at least # Calls the main loop. This is how the thing should be started, at least
# until I decide to change it, whenever that is. # until I decide to change it, whenever that is.
def main(self): def main(self):
misc.RenameProcess('urwicd') misc.RenameProcess('wicd-curses')
self.ui = urwid.curses_display.Screen() self.ui = urwid.curses_display.Screen()
# Color scheme
# Other potential color schemes can be found at:
# http://excess.org/urwid/wiki/RecommendedPalette
self.ui.register_palette([ self.ui.register_palette([
('body','light gray','black'), ('body','light gray','black'),
('selected','dark blue','light gray'), ('selected','dark magenta','light gray'),
('header','light blue','black'), ('header','light blue','black'),
('important','light red','black')]) ('important','light red','black')])
# This is a wrapper around a function that calls another a function that is a
# wrapper around a infinite loop. Fun.
self.ui.run_wrapper(self.run) self.ui.run_wrapper(self.run)
# Main program loop # Main program loop
def run(self): def run(self):
size = self.ui.get_cols_rows() self.size = self.ui.get_cols_rows()
# This doesn't do what I need it to do! # This actually makes some things easier to do, amusingly enough
# What I will have to do is... (unless I totally misunderstand glib) self.loop = gobject.MainLoop()
# 1. Stick all this loop into another function (probably update_ui) # Update what the interface looks like every 0.5 ms
# 2. Make a glib MainLoop object somewhere in this file gobject.timeout_add(0.5,self.update_ui)
# 3. Connect the DBus Main Loop to that main loop # Update the connection status on the bottom every 0.5 s
# 4. Throw update_ui into gobject.timeout() gobject.timeout_add(500,self.update_status)
# 5. Pray. :-) # Terminate the loop if the UI is terminated.
while True: gobject.idle_add(self.stop_loop)
self.update_status() self.loop.run()
canvas = self.frame.render( (size) )
self.ui.draw_screen((size),canvas)
keys = self.ui.get_input()
if "f8" in keys:
break
for k in keys:
if k == "window resize":
size = self.ui.get_cols_rows()
continue
self.frame.keypress( size, k )
# Mostly borrowed from gui.py, but also with the standard "need daemon first" # Redraw the screen
# check def update_ui(self):
#self.update_status()
canvas = self.frame.render( (self.size) )
self.ui.draw_screen((self.size),canvas)
keys = self.ui.get_input()
# Should make a keyhandler method, but this will do until I get around to
# that stage
if "f8" in keys:
return False
if "f5" in keys:
wireless.Scan()
for k in keys:
if k == "window resize":
self.size = self.ui.get_cols_rows()
continue
self.frame.keypress( self.size, k )
return True
# Terminate the loop, used as the glib mainloop's idle function
def stop_loop(self):
self.loop.quit()
# Mostly borrowed from gui.py, but also with the "need daemon first" check
def setup_dbus(): def setup_dbus():
global proxy_obj, daemon, wireless, wired, config, dbus_ifaces global proxy_obj, daemon, wireless, wired, config, dbus_ifaces
try: try:
@@ -329,11 +347,10 @@ setup_dbus()
if __name__ == '__main__': if __name__ == '__main__':
app = appGUI() app = appGUI()
# This stuff doesn't work yet. I have to stick a gobject mainloop in to get # Connect signals and whatnot to UI screen control functions
# it to work... It'll be done soon enough bus.add_signal_receiver(app.dbus_scan_finished, 'SendEndScanSignal',
#bus.add_signal_receiver(app.dbus_scan_finished, 'SendEndScanSignal', 'org.wicd.daemon')
# 'org.wicd.daemon') bus.add_signal_receiver(app.dbus_scan_started, 'SendStartScanSignal',
#bus.add_signal_receiver(app.dbus_scan_started, 'SendStartScanSignal', 'org.wicd.daemon')
# 'org.wicd.daemon')
app.main() app.main()