home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / Democracy-0.8.2.exe / components / pybridge.py < prev    next >
Encoding:
Python Source  |  2006-04-10  |  2.7 KB  |  89 lines

  1. import sys
  2. from xpcom import components, nsError, ServerException
  3. import traceback
  4. import sys
  5. import os
  6. import time
  7.  
  8.  
  9. #print "PYBRIDGE TOP"
  10.  
  11. # Copied from resource.py; if you change this function here, change it
  12. # there too.
  13. def appRoot():
  14.     klass = components.classes["@mozilla.org/file/directory_service;1"]
  15.     service = klass.getService(components.interfaces.nsIProperties)
  16.     file = service.get("XCurProcD", components.interfaces.nsIFile)
  17.     return file.path
  18.  
  19. class PyBridge:
  20.     _com_interfaces_ = [components.interfaces.pcfIDTVPyBridge]
  21.     _reg_clsid_ = "{F87D30FF-C117-401e-9194-DF3877C926D4}"
  22.     _reg_contractid_ = "@participatoryculture.org/dtv/pybridge;1"
  23.     _reg_desc_ = "Bridge into DTV Python core"
  24.  
  25.     def __init__(self):
  26.         self.started = False
  27.         self.booted = False
  28.  
  29.     def onStartup(self, mainWindowDocument):
  30.         if self.started:
  31.             import util
  32.             util.failed("Loading window", details="onStartup called twice")
  33.             return
  34.         else:
  35.             self.started = True
  36.         print "onStartup"
  37.         self.mainWindowDocument = mainWindowDocument
  38.  
  39.         from util import AutoflushingStream
  40.  
  41.         try:
  42.             import config
  43.             logFile = config.get(config.LOG_PATHNAME)
  44.             if logFile is not None:
  45.                 h = open(logFile, "wt")
  46.                 sys.stdout = sys.stderr = AutoflushingStream(h)
  47.         except:
  48.             pass
  49. #        try:
  50. #           print "got:: %s" % mainWindowDocument
  51.  
  52. #           klass = components.classes["@participatoryculture.org/dtv/jsbridge;1"]
  53. #           jsb = klass.getService(components.interfaces.pcfIDTVJSBridge)
  54. #           jsb.xulLoadURI(elt, "http://www.achewood.com")
  55. #
  56. #        except:
  57. #            traceback.print_exc()
  58.  
  59.     def bootApp(self):
  60.         if self.booted:
  61.             import util
  62.             util.failed("Loading window", details="bootApp called twice")
  63.             return
  64.         else:
  65.             self.booted = True
  66.         import app
  67.         app.start()
  68.  
  69.     def onShutdown(self):
  70.         import app
  71.         app.Controller.instance.onShutdown()
  72.  
  73.     def eventURL(self, cookie, url):
  74.         import frontend
  75.         frontend.HTMLDisplay.dispatchEventByCookie(cookie, url)
  76.  
  77.     def addChannel(self, url):
  78.         print "Add Channel %s" % url
  79.         import feed
  80.         feed.Feed(url)
  81.  
  82.     def getServerPort(self):
  83.         # Frontend has to go first, because it knows the right time to
  84.         # import frontend for the first time (after the right set of classes
  85.         # have been set up)
  86.         import app
  87.         import frontend
  88.         return frontend.getServerPort()
  89.