home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / digsby / widgets / widget.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  6.7 KB  |  152 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from pyxmpp.utils import from_utf8
  5. from pyxmpp.objects import StanzaPayloadObject
  6. from pyxmpp.xmlextra import get_node_ns_uri
  7. from digsby.widgets import DIGSBY_WIDGETS_NS
  8. from hashlib import sha256
  9. from util import callsback
  10. from digsby.web import digsby_webget
  11. from logging import getLogger
  12. log = getLogger('digsby.widget')
  13. from gui import skin
  14. from util.xml_tag import tag
  15. from urllib2 import urlopen
  16. from urllib import urlencode
  17. from common import profile
  18. from util.net import UrlQuery
  19. import wx
  20.  
  21. def iswidget(buddy):
  22.     if hasattr(buddy, 'jid'):
  23.         pass
  24.     return buddy.jid.domain == 'guest.digsby.org'
  25.  
  26.  
  27. def get_local_swf():
  28.     return skin.resourcedir() / 'widget' / 'digsby_widget.swf'
  29.  
  30.  
  31. class Widget(StanzaPayloadObject):
  32.     action_url = 'https://accounts.digsby.com/login.php?'
  33.     modify_url = 'http://widget.digsby.com/?'
  34.     xml_element_name = 'widget'
  35.     xml_element_namespace = DIGSBY_WIDGETS_NS
  36.     
  37.     def __init__(self, xmlnode_or_acct_or_id):
  38.         self._Widget__from_xml(xmlnode_or_acct_or_id)
  39.  
  40.     
  41.     def __repr__(self):
  42.         return '<Digsby.Widget id:%(id)s title:%(title)s on:%(on)s width:%(width)d height:%(height)d type:%(type)s typeuid:%(typeuid)s>' % self.__dict__
  43.  
  44.     
  45.     def __from_xml(self, node):
  46.         if node.type != 'element':
  47.             raise ValueError, 'XML node is not an %s element (not en element)' % self.xml_element_name
  48.         
  49.         ns = get_node_ns_uri(node)
  50.         if ns or ns != DIGSBY_WIDGETS_NS or node.name != self.xml_element_name:
  51.             raise ValueError, 'XML node is not an %s element' % self.xml_element_name
  52.         
  53.         for prop in ('id', 'title', 'on', 'width', 'height', 'type', 'typeuid'):
  54.             val = node.prop(prop)
  55.             if val is not None:
  56.                 setattr(self, prop, from_utf8(val))
  57.                 continue
  58.             setattr(self, prop, val)
  59.         
  60.         for prop in [
  61.             'width',
  62.             'height']:
  63.             if getattr(self, prop):
  64.                 setattr(self, prop, int(getattr(self, prop)))
  65.                 continue
  66.         
  67.         self.on = bool(int(self.on))
  68.  
  69.     
  70.     def set_enabled(self, enabled):
  71.         if enabled:
  72.             action = 'toggleon'
  73.         else:
  74.             action = 'toggleoff'
  75.             conn = profile.connection
  76.             if conn is not None:
  77.                 conn.remove_widget_buddies(self)
  78.             
  79.         None(self._action if enabled else 'toggleoff')
  80.  
  81.     
  82.     def edit(self):
  83.         
  84.         def success(res):
  85.             print 
  86.             print res
  87.             print 
  88.             (file, key) = res.split(':')
  89.             wx.LaunchDefaultBrowser(UrlQuery(self.modify_url, id = file, tkn = key))
  90.  
  91.         self._action('modify', success = success)
  92.  
  93.     
  94.     def delete(self):
  95.         self._action('del')
  96.  
  97.     
  98.     def _action(self, action, callback = None):
  99.         url = self.action_url
  100.         params = dict(obj = 'widget', user = profile.username, key = sha256(profile.password).hexdigest(), act = action, doto = self.id)
  101.         
  102.         def error(result = ('',)):
  103.             log.warning('server indicated an error %r', result)
  104.             callback.error()
  105.  
  106.         
  107.         def success(result):
  108.             if result.lower() == 'err':
  109.                 error(result)
  110.             else:
  111.                 callback.success(result)
  112.  
  113.         digsby_webget(url, success = success, error = error, **params)
  114.  
  115.     _action = callsback(_action)
  116.     
  117.     def embed_tag(self):
  118.         if self.type == 'fb':
  119.             return ''
  120.         
  121.         return '<embed src="http://w.digsby.com/dw.swf?c=%s" wmode="transparent" type="application/x-shockwave-flash" width="%s" height="%s"></embed>' % (self.id, self.width, self.height)
  122.  
  123.     embed_tag = property(embed_tag)
  124.     
  125.     def flash_url(self):
  126.         return 'http://w.digsby.com/dw.swf?c=%s&STATE=creator' % self.id
  127.  
  128.     flash_url = property(flash_url)
  129.     
  130.     def embed_creator(self, w, h):
  131.         widget = '<embed src="%s" wmode="transparent"type="application/x-shockwave-flash" width="%s" height="%s"></embed>' % (self.flash_url, self.width, self.height)
  132.         return '<html><head><style type="text/css">body { border: 0px; padding: 0px; margin: 0px;} *{overflow:hidden;}</style></head><body border=0 padding=0 margin=0><div id="widget">%s</div></body></html>' % self.get_config(w, h)
  133.  
  134.     
  135.     def get_config(self, w, h):
  136.         url = 'http://config.digsby.com/%s' % self.id
  137.         data = urlopen(url).read()
  138.         xml = tag(data)
  139.         sc = xml.style.text.status['color']
  140.         bc = xml.style.background['color']
  141.         tc = xml.style.title['color']
  142.         fc = xml.style.field['color']
  143.         xc = xml.style.text['color']
  144.         tt = xml.o['title']
  145.         nt = xml.o['nick']
  146.         d = dict(title = tt, nick = nt, statustext = sc, bgcolor = bc, titletext = tc, field = fc, text = xc)
  147.         flashvars = urlencode(d)
  148.         widget_url = 'http://w.digsby.com/dw.swf'
  149.         return '<embed src="%s%s" type="application/x-shockwave-flash" wmode="transparent" width="%s" height="%s"></embed>' % (widget_url, '?STATE=creator&' + flashvars, w, h)
  150.  
  151.  
  152.