add licence headers to all files.
[nephilim.git] / nephilim / misc.py
blob001fcee804c336dbbbc652db3d46b7c02ef6d6ae
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
20 import socket
21 import logging
23 socket.setdefaulttimeout(8)
25 appIcon = 'gfx/nephilim_small.png'
26 APPNAME = 'nephilim'
27 ORGNAME = 'nephilim'
29 def sec2min(secs):
30 """Converts seconds to min:sec."""
31 min=int(secs/60)
32 sec=secs%60
33 if sec<10:sec='0'+str(sec)
34 return str(min)+':'+str(sec)
36 class Button(QtGui.QPushButton):
37 iconSize=32
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)
42 if onClick:
43 self.connect(self, QtCore.SIGNAL('clicked(bool)'), onClick)
44 if iconPath:
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)
54 if self.icon()==None:
55 self.setText(caption)
57 def changeIcon(self, iconPath):
58 icon=QtGui.QIcon()
59 icon.addFile(iconPath, QtCore.QSize(self.iconSize, self.iconSize))
60 self.setIcon(icon)
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+'), '')