2 # Copyright (C) 2008 jerous <jerous@gmail.com>
3 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
5 # Nephilim is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Nephilim is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4
import QtCore
, QtGui
23 socket
.setdefaulttimeout(8)
25 appIcon
= 'gfx/nephilim_small.png'
30 """Converts seconds to min:sec."""
33 if sec
<10:sec
='0'+str(sec
)
34 return str(min)+':'+str(sec
)
36 class Button(QtGui
.QPushButton
):
38 """A simple Button class which calls $onClick when clicked."""
39 def __init__(self
, caption
, onClick
=None, iconPath
=None, iconOnly
=False, parent
=None):
40 QtGui
.QPushButton
.__init
__(self
, parent
)
43 self
.connect(self
, QtCore
.SIGNAL('clicked(bool)'), onClick
)
45 self
.changeIcon(iconPath
)
47 if not(iconPath
and iconOnly
):
48 QtGui
.QPushButton
.setText(self
, caption
)
50 self
.setToolTip(caption
)
52 def setText(self
, caption
):
53 self
.setToolTip(caption
)
57 def changeIcon(self
, iconPath
):
59 icon
.addFile(iconPath
, QtCore
.QSize(self
.iconSize
, self
.iconSize
))
62 def expand_tags(str, expanders
):
63 #ensure that str is QString
64 str = QtCore
.QString(str)
65 for expander
in expanders
:
66 str = expander
.expand_tags(str)
68 #remove unexpanded tags
69 return str.replace(QtCore
.QRegExp('\\$\\w+'), '')