forked from Skinok/backtrader-pyqt-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicatorParametersUI.py
91 lines (68 loc) · 2.67 KB
/
indicatorParametersUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from PyQt6 import QtCore, QtWidgets, QtGui, uic
import os
class IndicatorParametersUI(QtWidgets.QDialog):
def __init__(self, parent = None):
super(IndicatorParametersUI, self).__init__()
#self.setParent(parent)
# It does not finish by a "/"
self.current_dir_path = os.path.dirname(os.path.realpath(__file__))
uic.loadUi( self.current_dir_path + "/ui/indicatorParameters.ui", self)
self.title = self.findChild(QtWidgets.QLabel, "title")
self.parameterLayout = self.findChild(QtWidgets.QFormLayout, "parameterLayout")
pass
def setTitle(self, title):
self.title = title
pass
def addParameter(self, parameterName, defaultValue):
lineEdit = QtWidgets.QLineEdit(parameterName, self)
lineEdit.setObjectName(parameterName)
lineEdit.setText(str(defaultValue))
self.parameterLayout.addRow(parameterName, lineEdit)
pass
def addParameterColor(self, parameterName, defaultValue):
# Custom color picker
colorButton = SelectColorButton(parameterName, self)
self.parameterLayout.addRow(parameterName, colorButton)
pass
def getValue(self, parameterName):
lineEdit = self.findChild(QtWidgets.QLineEdit, parameterName)
if lineEdit is not None:
try:
return int(lineEdit.text())
except:
try:
return float(lineEdit.text())
except:
try:
return lineEdit.text()
except:
return None
else:
return None
def getColorValue(self, parameterName):
colorButton = self.findChild(SelectColorButton, parameterName)
if colorButton is not None:
try:
return colorButton.getColor().name()
except:
return None
else:
return None
class SelectColorButton(QtWidgets.QPushButton):
def __init__(self, objectName, parent = None):
super(SelectColorButton, self).__init__()
self.setColor( QtGui.QColor("yellow") )
self.setObjectName(objectName)
self.setParent(parent)
self.clicked.connect(self.changeColor)
def setColor(self,color):
self.color = color
self.updateColor()
def getColor(self):
return self.color
def updateColor(self):
self.setStyleSheet( "background-color: " + self.color.name() )
def changeColor(self):
newColor = QtWidgets.QColorDialog.getColor(self.color, self.parentWidget())
if newColor != self.color:
self.setColor( newColor )