home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / digsby / widgets / widget.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  6.7 KB  |  152 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from peak.util.imports import lazyModule
  5. from pyxmpp.utils import from_utf8
  6. from pyxmpp.objects import StanzaPayloadObject
  7. from pyxmpp.xmlextra import get_node_ns_uri
  8. from digsby.widgets import DIGSBY_WIDGETS_NS
  9. from hashlib import sha256
  10. from util import callsback
  11. from digsby.web import digsby_webget
  12. from logging import getLogger
  13. log = getLogger('digsby.widget')
  14. skin = lazyModule('gui.skin')
  15. from util.xml_tag import tag
  16. from urllib2 import urlopen
  17. from urllib import urlencode
  18. from common import profile
  19. from util.net import UrlQuery
  20. import wx
  21.  
  22. def iswidget(buddy):
  23.     if hasattr(buddy, 'jid'):
  24.         pass
  25.     return buddy.jid.domain == 'guest.digsby.org'
  26.  
  27.  
  28. def get_local_swf():
  29.     return skin.resourcedir() / 'widget' / 'digsby_widget.swf'
  30.  
  31.  
  32. class Widget(StanzaPayloadObject):
  33.     action_url = 'https://accounts.digsby.com/login.php?'
  34.     modify_url = 'http://widget.digsby.com/?'
  35.     xml_element_name = 'widget'
  36.     xml_element_namespace = DIGSBY_WIDGETS_NS
  37.     
  38.     def __init__(self, xmlnode_or_acct_or_id):
  39.         self._Widget__from_xml(xmlnode_or_acct_or_id)
  40.  
  41.     
  42.     def __repr__(self):
  43.         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__
  44.  
  45.     
  46.     def __from_xml(self, node):
  47.         if node.type != 'element':
  48.             raise ValueError, 'XML node is not an %s element (not en element)' % self.xml_element_name
  49.         node.type != 'element'
  50.         ns = get_node_ns_uri(node)
  51.         if ns or ns != DIGSBY_WIDGETS_NS or node.name != self.xml_element_name:
  52.             raise ValueError, 'XML node is not an %s element' % self.xml_element_name
  53.         node.name != self.xml_element_name
  54.         for prop in ('id', 'title', 'on', 'width', 'height', 'type', 'typeuid'):
  55.             val = node.prop(prop)
  56.             if val is not None:
  57.                 setattr(self, prop, from_utf8(val))
  58.                 continue
  59.             setattr(self, prop, val)
  60.         
  61.         for prop in [
  62.             'width',
  63.             'height']:
  64.             if getattr(self, prop):
  65.                 setattr(self, prop, int(getattr(self, prop)))
  66.                 continue
  67.         
  68.         self.on = bool(int(self.on))
  69.  
  70.     
  71.     def set_enabled(self, enabled):
  72.         if enabled:
  73.             action = 'toggleon'
  74.         else:
  75.             action = 'toggleoff'
  76.             conn = profile.connection
  77.             if conn is not None:
  78.                 conn.remove_widget_buddies(self)
  79.             
  80.         None(self._action if enabled else 'toggleoff')
  81.  
  82.     
  83.     def edit(self):
  84.         
  85.         def success(res):
  86.             print 
  87.             print res
  88.             print 
  89.             (file, key) = res.split(':')
  90.             wx.LaunchDefaultBrowser(UrlQuery(self.modify_url, id = file, tkn = key))
  91.  
  92.         self._action('modify', success = success)
  93.  
  94.     
  95.     def delete(self):
  96.         self._action('del')
  97.  
  98.     
  99.     def _action(self, action, callback = None):
  100.         url = self.action_url
  101.         params = dict(obj = 'widget', user = profile.username, key = sha256(profile.password).hexdigest(), act = action, doto = self.id)
  102.         
  103.         def error(result = ('',)):
  104.             log.warning('server indicated an error %r', result)
  105.             callback.error()
  106.  
  107.         
  108.         def success(result):
  109.             if result.lower() == 'err':
  110.                 error(result)
  111.             else:
  112.                 callback.success(result)
  113.  
  114.         digsby_webget(url, success = success, error = error, **params)
  115.  
  116.     _action = callsback(_action)
  117.     
  118.     def embed_tag(self):
  119.         if self.type == 'fb':
  120.             return ''
  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.