MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / avatarize

Function avatarize

src/bitmessageqt/utils.py:67–108  ·  view source on GitHub ↗

loads a supported image for the given address' hash form 'avatars' folder falls back to default avatar if 'default.*' file exists falls back to identiconize(address)

(address)

Source from the content-addressed store, hash-verified

65 return idcon
66
67def avatarize(address):
68 """
69 loads a supported image for the given address' hash form 'avatars' folder
70 falls back to default avatar if 'default.*' file exists
71 falls back to identiconize(address)
72 """
73 idcon = QtGui.QIcon()
74 hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest()
75 str_broadcast_subscribers = '[Broadcast subscribers]'
76 if address == str_broadcast_subscribers:
77 # don't hash [Broadcast subscribers]
78 hash = address
79 # http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats
80 # print QImageReader.supportedImageFormats ()
81 # QImageReader.supportedImageFormats ()
82 extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA']
83 # try to find a specific avatar
84 for ext in extensions:
85 lower_hash = state.appdata + 'avatars/' + hash + '.' + ext.lower()
86 upper_hash = state.appdata + 'avatars/' + hash + '.' + ext.upper()
87 if os.path.isfile(lower_hash):
88 # print 'found avatar of ', address
89 idcon.addFile(lower_hash)
90 return idcon
91 elif os.path.isfile(upper_hash):
92 # print 'found avatar of ', address
93 idcon.addFile(upper_hash)
94 return idcon
95 # if we haven't found any, try to find a default avatar
96 for ext in extensions:
97 lower_default = state.appdata + 'avatars/' + 'default.' + ext.lower()
98 upper_default = state.appdata + 'avatars/' + 'default.' + ext.upper()
99 if os.path.isfile(lower_default):
100 default = lower_default
101 idcon.addFile(lower_default)
102 return idcon
103 elif os.path.isfile(upper_default):
104 default = upper_default
105 idcon.addFile(upper_default)
106 return idcon
107 # If no avatar is found
108 return identiconize(address)

Callers 8

on_action_SetAvatarMethod · 0.90
dataMethod · 0.85
dataMethod · 0.85
dataMethod · 0.85

Calls 2

addBMIfNotPresentFunction · 0.90
identiconizeFunction · 0.85

Tested by

no test coverage detected