2015-06-05 06:22:37 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#--!-- coding: utf8 --!--
|
|
|
|
|
2015-06-07 06:29:02 +12:00
|
|
|
from qt import *
|
2015-06-16 03:24:02 +12:00
|
|
|
from random import *
|
2015-06-07 06:29:02 +12:00
|
|
|
|
2015-06-05 06:22:37 +12:00
|
|
|
def wordCount(text):
|
2015-06-07 06:29:02 +12:00
|
|
|
return len(text.strip().replace(" ", "\n").split("\n")) if text else 0
|
2015-06-05 21:37:01 +12:00
|
|
|
|
|
|
|
def toInt(text):
|
|
|
|
if text:
|
|
|
|
return int(text)
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def toFloat(text):
|
|
|
|
if text:
|
|
|
|
return float(text)
|
|
|
|
else:
|
2015-06-07 06:29:02 +12:00
|
|
|
return 0.
|
|
|
|
|
2015-06-11 07:23:35 +12:00
|
|
|
def toString(text):
|
2015-06-15 22:18:42 +12:00
|
|
|
if text in [None, "None"]:
|
2015-06-11 07:23:35 +12:00
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return str(text)
|
|
|
|
|
2015-06-07 06:29:02 +12:00
|
|
|
def drawProgress(painter, rect, progress, radius=0):
|
|
|
|
painter.setPen(Qt.NoPen)
|
|
|
|
painter.setBrush(QColor("#dddddd"))
|
|
|
|
painter.drawRoundedRect(rect, radius, radius)
|
|
|
|
|
|
|
|
c1 = QColor(Qt.red)
|
|
|
|
c2 = QColor(Qt.blue)
|
|
|
|
c3 = QColor(Qt.darkGreen)
|
|
|
|
c4 = QColor("#FFA500")
|
|
|
|
|
|
|
|
if progress < 0.3:
|
|
|
|
painter.setBrush(QBrush(c1))
|
|
|
|
elif progress < 0.8:
|
|
|
|
painter.setBrush(QBrush(c2))
|
|
|
|
elif progress > 1.2:
|
|
|
|
painter.setBrush(QBrush(c4))
|
|
|
|
else:
|
|
|
|
painter.setBrush(QBrush(c3))
|
|
|
|
|
|
|
|
r2 = QRect(rect)
|
|
|
|
r2.setWidth(r2.width() * min(progress, 1))
|
2015-06-07 08:39:43 +12:00
|
|
|
painter.drawRoundedRect(r2, radius, radius)
|
|
|
|
|
|
|
|
def mainWindow():
|
|
|
|
for i in qApp.topLevelWidgets():
|
|
|
|
if i.objectName() == "MainWindow":
|
|
|
|
return i
|
2015-06-10 08:05:03 +12:00
|
|
|
return None
|
|
|
|
|
|
|
|
def iconColor(icon):
|
|
|
|
"Returns a QRgb from a QIcon, assuming its all the same color"
|
2015-06-16 02:35:23 +12:00
|
|
|
px = icon.pixmap(5, 5)
|
|
|
|
if px.width() != 0:
|
|
|
|
return QColor(QImage(px).pixel(2, 2))
|
|
|
|
else:
|
|
|
|
return Qt.transparent
|
2015-06-10 10:20:32 +12:00
|
|
|
|
|
|
|
def iconFromColor(color):
|
|
|
|
px = QPixmap(32, 32)
|
|
|
|
px.fill(color)
|
|
|
|
return QIcon(px)
|
|
|
|
|
|
|
|
def iconFromColorString(string):
|
2015-06-16 03:24:02 +12:00
|
|
|
return iconFromColor(QColor(string))
|
|
|
|
|
|
|
|
def randomColor(mix=None):
|
|
|
|
"Generates a random color. If mix (QColor) is given, mixes the random color and mix."
|
|
|
|
r = randint(0, 255)
|
|
|
|
g = randint(0, 255)
|
|
|
|
b = randint(0, 255)
|
|
|
|
|
|
|
|
if mix:
|
|
|
|
r = (r + mix.red()) / 2
|
|
|
|
g = (g + mix.green()) / 2
|
|
|
|
b = (b + mix.blue()) / 2
|
|
|
|
|
|
|
|
return QColor(r, g, b)
|