# Set host and port to connect with.
DEFHOST = 'www.cs.orst.edu'
DEFPORT = 55571
# Get the standard Python modules that are used.
import sys,time,string
# Get the iHTML modules that are used.
import ihBrowser, ihDoc, ihURL
class DocTracker(ihURL.LineURL):
def __init__(self,doc,server):
# Initialize the last document state that was sent to the server.
self.last_clock = time.time()
self.last_top = 0
self.last_bottom = 0
self.last_lines = 0
self.doc = doc
# Connect to the remote server.
ihURL.LineURL.__init__(self,doc,server)
result = (self.GetStatus(),self.GetURL())
self.sock_result = `result`
self.sock_address = self.GetURL()
self.Write("* send\n")
def OnLine(self,lines):
self.doc.ShowProgress(self.GetURL() + ' - ' + lines[-1])
def OnError(self,error):
addr = self.GetURL()
if( not addr ): addr = '[tcp connection]'
self.doc.ShowProgress(addr + ' - ' + error)
# Global document event handler. After instantiating the class,
# this method can be attached to the document's list of handlers.
def doc_handler(self,doc,event):
self.send_event(doc,string.lower(event.Code+""),event)
# Send a new document state message to the server.
def send_event(self,doc,action,event=None):
if( self.GetStatus() != ihURL.URL_INTERACTIVE ):
return
if( action == "initpos" or action == "scroll" ):
if self.last_clock != 0:
new_clock = time.time()
elapsed = new_clock - self.last_clock
self.last_clock = new_clock
if(elapsed > 0.2):
txt = "* " + action + ": top=" \
+ `self.last_top` \
+ "; bot=" + `self.last_bottom` \
+ "; total=" + `self.last_lines` \
+ "; time=" + ("%.2f" % elapsed) + " secs\n"
txt = "* " + action + " " + `self.last_top` + " " \
+ `self.last_bottom` + " " + `self.last_lines` \
+ " " + ("%.2f" % elapsed) + "\n"
self.Write(txt)
else:
self.last_clock = time.time()
self.last_top = doc.ViewTop
self.last_bottom = doc.ViewBottom
self.last_lines = doc.DocHeight
elif( action == "print" ):
self.Write("* print\n")
elif( action == "hitanchor" ):
anchor = ""
if( event ):
anchor = event.AnchorName
self.Write("* anchor select " + anchor + "\n")
elif( action == "onanchor" ):
anchor = ""
if( event ):
anchor = event.AnchorName
self.Write("* anchor over " + anchor + "\n")
elif( action == "offanchor" ):
self.Write("* anchor over\n")
class ihMain(ihDoc.Document):
def __init__(self,**args):
apply(ihDoc.Document.__init__,(self,),args)
# Extract arguments
if( args.has_key('Server') ):
self.server = args['Server']
else:
self.server = 'tcp://'+DEFHOST+':'+`DEFPORT`
self.tracker = DocTracker(self,self.server)
# Clear progress display.
self.ShowProgress()
# Display the document.
self.Reformat()
# Send initial position report.
self.tracker.send_event(self,"initpos")
# Install the handler.
self.Handlers.append(self.tracker.doc_handler)
__export__ = ['ihMain']
![]()
| Dianne Kyra Hackborn <hackbod@angryredplanet.com> | Last modified: Wed Aug 14 14:55:54 PDT 1996 |