1 from PyQt4
import QtCore
, QtGui
2 from htmlentitydefs
import name2codepoint
as n2cp
4 import urllib2
, cookielib
10 socket
.setdefaulttimeout(8)
12 appIcon
= 'gfx/icon.png'
17 """Make some time for necessary events."""
18 QtCore
.QEventLoop().processEvents(QtCore
.QEventLoop
.AllEvents
)
21 """Converts seconds to min:sec."""
24 if sec
<10:sec
='0'+str(sec
)
25 return str(min)+':'+str(sec
)
27 def numeric_compare(x
, y
):
34 """Retrieve list of unique elements."""
36 return t(c
for c
in seq
if not (c
in seen
or seen
.append(c
)))
41 return unicodedata
.normalize('NFKD', ustr
).encode('ascii', 'ignore')
43 def substEntity(match
):
45 if match
.group(1) == "#":
46 return unichr(int(ent
))
55 def decodeHTMLEntities(string
):
56 # replace entities with their UTF-counterpart
57 entity_re
= re
.compile("&(#?)(\d{1,5}|\w{1,8});")
58 return entity_re
.subn(substEntity
, string
)[0]
61 class Button(QtGui
.QPushButton
):
63 """A simple Button class which calls $onClick when clicked."""
64 def __init__(self
, caption
, onClick
=None, iconPath
=None, iconOnly
=False, parent
=None):
65 QtGui
.QPushButton
.__init
__(self
, parent
)
68 self
.connect(self
, QtCore
.SIGNAL('clicked(bool)'), onClick
)
70 self
.changeIcon(iconPath
)
72 if not(iconPath
and iconOnly
):
73 QtGui
.QPushButton
.setText(self
, caption
)
75 self
.setToolTip(caption
)
77 def setText(self
, caption
):
78 self
.setToolTip(caption
)
82 def changeIcon(self
, iconPath
):
84 icon
.addFile(iconPath
, QtCore
.QSize(self
.iconSize
, self
.iconSize
))