Skip to content
Snippets Groups Projects
Commit e7ba6b9e authored by Bob Lantz's avatar Bob Lantz
Browse files

Add title to consoles.

parent bbe5f8a3
No related branches found
No related tags found
No related merge requests found
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
class Console( Frame ): class Console( Frame ):
"A simple console on a host." "A simple console on a host."
def __init__( self, parent, net, node, height=10, width=32 ): def __init__( self, parent, net, node, height=10, width=32, title='Node' ):
Frame.__init__( self, parent ) Frame.__init__( self, parent )
self.net = net self.net = net
self.node = node self.node = node
self.prompt = node.name + '# ' self.prompt = node.name + '# '
self.height, self.width = height, width self.height, self.width, self.title = height, width, title
# Initialize widget styles # Initialize widget styles
self.buttonStyle = { 'font': 'Monaco 7' } self.buttonStyle = { 'font': 'Monaco 7' }
...@@ -48,9 +48,9 @@ def __init__( self, parent, net, node, height=10, width=32 ): ...@@ -48,9 +48,9 @@ def __init__( self, parent, net, node, height=10, width=32 ):
def makeWidgets( self ): def makeWidgets( self ):
"Make a label, a text area, and a scroll bar." "Make a label, a text area, and a scroll bar."
def newTerm( net=self.net, node=self.node ): def newTerm( net=self.net, node=self.node, title=self.title ):
"Pop up a new terminal window for a node." "Pop up a new terminal window for a node."
net.terms += makeTerms( [ node ] ) net.terms += makeTerms( [ node ], title )
label = Button( self, text=self.node.name, command=newTerm, label = Button( self, text=self.node.name, command=newTerm,
**self.buttonStyle ) **self.buttonStyle )
label.pack( side='top', fill='x' ) label.pack( side='top', fill='x' )
...@@ -63,9 +63,10 @@ def newTerm( net=self.net, node=self.node ): ...@@ -63,9 +63,10 @@ def newTerm( net=self.net, node=self.node ):
def bindEvents( self ): def bindEvents( self ):
"Bind keyboard and file events." "Bind keyboard and file events."
# The text widget handles regular key presses, but we
# use special handlers for the following:
self.text.bind( '<Return>', self.handleReturn ) self.text.bind( '<Return>', self.handleReturn )
self.text.bind( '<Control-c>', self.handleInt ) self.text.bind( '<Control-c>', self.handleInt )
# self.text.bind( '<KeyPress>', self.handleKey )
# This is not well-documented, but it is the correct # This is not well-documented, but it is the correct
# way to trigger a file event handler from Tk's # way to trigger a file event handler from Tk's
# event loop! # event loop!
...@@ -78,10 +79,6 @@ def append( self, text ): ...@@ -78,10 +79,6 @@ def append( self, text ):
self.text.mark_set( 'insert', 'end' ) self.text.mark_set( 'insert', 'end' )
self.text.see( 'insert' ) self.text.see( 'insert' )
def handleKey( self, event ):
"Handle a regular key press."
self.append( event.char )
def handleReturn( self, event ): def handleReturn( self, event ):
"Handle a carriage return." "Handle a carriage return."
cmd = self.text.get( 'insert linestart', 'insert lineend' ) cmd = self.text.get( 'insert linestart', 'insert lineend' )
...@@ -104,7 +101,7 @@ def handleReadable( self, file=None, mask=None ): ...@@ -104,7 +101,7 @@ def handleReadable( self, file=None, mask=None ):
data = self.node.monitor() data = self.node.monitor()
self.append( data ) self.append( data )
if not self.node.waiting: if not self.node.waiting:
# Print prompt, just for the heck of it # Print prompt
self.append( self.prompt ) self.append( self.prompt )
def waitOutput( self ): def waitOutput( self ):
...@@ -128,9 +125,15 @@ def __init__( self, net, parent=None, width=4 ): ...@@ -128,9 +125,15 @@ def __init__( self, net, parent=None, width=4 ):
self.menubar = self.createMenuBar() self.menubar = self.createMenuBar()
cframe = self.cframe = Frame( self ) cframe = self.cframe = Frame( self )
self.consoles = {} # consoles themselves self.consoles = {} # consoles themselves
for name in 'hosts', 'switches', 'controllers': titles = {
'hosts': 'Host',
'switches': 'Switch',
'controllers': 'Controller'
}
for name in titles:
nodes = getattr( net, name ) nodes = getattr( net, name )
frame, consoles = self.createConsoles( cframe, nodes, width ) frame, consoles = self.createConsoles(
cframe, nodes, width, titles[ name ] )
self.consoles[ name ] = Object( frame=frame, consoles=consoles ) self.consoles[ name ] = Object( frame=frame, consoles=consoles )
self.selected = None self.selected = None
self.select( 'hosts' ) self.select( 'hosts' )
...@@ -140,14 +143,14 @@ def __init__( self, net, parent=None, width=4 ): ...@@ -140,14 +143,14 @@ def __init__( self, net, parent=None, width=4 ):
# Close window gracefully # Close window gracefully
Wm.wm_protocol( self.top, name='WM_DELETE_WINDOW', func=self.quit ) Wm.wm_protocol( self.top, name='WM_DELETE_WINDOW', func=self.quit )
def createConsoles( self, parent, nodes, width ): def createConsoles( self, parent, nodes, width, title ):
"Create a grid of consoles in a frame." "Create a grid of consoles in a frame."
f = Frame( parent ) f = Frame( parent )
# Create consoles # Create consoles
consoles = [] consoles = []
index = 0 index = 0
for node in nodes: for node in nodes:
console = Console( f, net, node ) console = Console( f, net, node, title=title )
consoles.append( console ) consoles.append( console )
row = index / width row = index / width
column = index % width column = index % width
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment