-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayerMenu.py
152 lines (136 loc) · 6.66 KB
/
LayerMenu.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from PyQt6.QtWidgets import QPushButton, QDialog, QLineEdit, QComboBox, QLabel, QGridLayout, QColorDialog, QCheckBox, QSpinBox
from PyQt6.QtGui import QColor, QIcon
import os
class LayerMenu(QDialog):
def __init__(self):
super().__init__()
# Default values
self.font = 'arial.ttf'
self.text = 'Default'
self.fontsize = 100
self.threeD = False
self.color = (255, 255, 255)
self.x = 0
self.y = 0
self.userChoices = [self.font, self.text, self.fontsize, self.threeD, self.color] # user choices to be applied
# Window
self.window_width, self.window_height = 250, 300
self.setMinimumSize(self.window_width, self.window_height)
self.setWindowTitle("Add Text")
self.setWindowIcon(QIcon("Resources/Icons/ACM_logo.jpg")) # Provide the path to your icon image
# Create Buttons, ComboBoxes,...
self.fontLabel = QLabel('Font')
self.fontBox = QComboBox() # Combobox for font
self.addFontsToList()
self.textColorLabel = QLabel('Text Color')
self.colorLabel = QLabel('Color')
self.colorButton = QPushButton() # Button for picking color
self.colorButton.clicked.connect(self.color_picker)
self.textLabel = QLabel('Text')
self.titleTextbox = QLineEdit() # Textbox for title
self.titleTextbox.setFixedWidth(150)
self.fontSizeLabel = QLabel('Font Size')
self.sizeSpinbox = QSpinBox() # Spinbox for size
self.sizeSpinbox.setRange(1, 1000) # TODO: adjust range to an appropriate value
self.sizeSpinbox.setValue(50)
self.sizeSpinbox.setFixedWidth(150)
self.depthLabel = QLabel('3D Depth')
self.depthSpinbox = QSpinBox() # Spinbox for depth
self.depthSpinbox.setRange(1, 1000) # TODO: adjust range to an appropriate value
self.depthSpinbox.setFixedWidth(150)
self.depthSpinbox.setEnabled(False)
self.depthSpinbox.setValue(10)
self.threeDLabel = QLabel('3D')
self.threeDCheckBox = QCheckBox() # Checkbox for 3D Text
self.threeDCheckBox.stateChanged.connect(self.toggleDepthSpinbox)
self.threeDCheckBox.setChecked(False) # Set initial state to unchecked
self.applyButton = QPushButton('Apply') # Button to confirm all textboxes
self.applyButton.clicked.connect(self.conclude)
self.deleteLayerButton = QPushButton('Delete Layer') # Button to confirm all textboxes
self.deleteLayerButton.clicked.connect(self.deleteLayer)
self.xLabel = QLabel('x')
self.xSpinbox = QSpinBox() # Spinbox for size
self.xSpinbox.setRange(1, 1000) # TODO: adjust range to an appropriate value
self.xSpinbox.setFixedWidth(150)
self.yLabel = QLabel('y')
self.ySpinbox = QSpinBox() # Spinbox for size
self.ySpinbox.setRange(1, 1000) # TODO: adjust range to an appropriate value
self.ySpinbox.setFixedWidth(150)
# Create grid layout
self.layout = QGridLayout()
self.layout.addWidget(self.fontLabel, 0, 0)
self.layout.addWidget(self.fontBox, 0, 1)
self.layout.addWidget(self.textLabel, 1, 0)
self.layout.addWidget(self.titleTextbox, 1, 1)
self.layout.addWidget(self.fontSizeLabel, 2, 0)
self.layout.addWidget(self.sizeSpinbox, 2, 1)
self.layout.addWidget(self.threeDLabel, 3, 0)
self.layout.addWidget(self.threeDCheckBox, 3, 1)
self.layout.addWidget(self.depthLabel, 3, 2)
self.layout.addWidget(self.depthSpinbox, 3, 3)
self.layout.addWidget(self.colorLabel, 4, 0)
self.layout.addWidget(self.colorButton, 4, 1)
self.layout.addWidget(self.xLabel, 5, 0)
self.layout.addWidget(self.xSpinbox, 5, 1)
self.layout.addWidget(self.yLabel, 5, 2)
self.layout.addWidget(self.ySpinbox, 5, 3)
self.layout.addWidget(self.applyButton, 6, 0) # span two columns for the button
self.layout.addWidget(self.deleteLayerButton, 6, 1)
# Set column stretch to push items to the top
self.layout.setColumnStretch(0, 1)
self.layout.setColumnStretch(1, 1)
# Set layout
self.setLayout(self.layout)
# Show window
self.show()
def color_picker(self):
pickedColor = QColorDialog.getColor()
r, g, b, t = pickedColor.getRgb()
self.color = (r, g, b)
print(self.color)
if pickedColor.isValid():
self.colorButton.setStyleSheet(f"background-color: {pickedColor.name()}; color: white;")
def updateChoices(self):
self.font = self.fontBox.currentText() # Get selected font from ComboBox
self.text = self.titleTextbox.text() # Get text from QLineEdit
self.fontsize = self.sizeSpinbox.value() # Get value from SpinBox
self.threeD = self.threeDCheckBox.isChecked() # Get whether CheckBox is checked
self.depth = self.depthSpinbox.value()
self.x = self.xSpinbox.value()
self.y = self.ySpinbox.value()
self.userChoices = [self.font, self.text, self.fontsize, self.threeD, self.color, self.depth, self.x, self.y] # tuple of user choices to be applied
def conclude(self):
self.updateChoices()
self.close()
return self.userChoices
def deleteLayer(self):
self.titleTextbox.setText('') # Get text from QLineEdit
self.close()
return self.userChoices
# Define the method to toggle the enabled state of the depthSpinbox
def toggleDepthSpinbox(self):
if self.threeDCheckBox.isChecked():
self.depthSpinbox.setEnabled(True)
else:
self.depthSpinbox.setEnabled(False)
def loadLayer(self, layer):
self.fontBox.setCurrentText(layer[0]) # TODO: fix
self.titleTextbox.setText(layer[1])
self.sizeSpinbox.setValue(layer[2])
self.depthSpinbox.setValue(layer[5])
self.threeDCheckBox.setChecked(layer[3])
self.color = layer[4]
qcolor = QColor(*self.color)
self.colorButton.setStyleSheet(f"background-color: {qcolor.name()}; color: white;")
self.xSpinbox.setValue(layer[6])
self.ySpinbox.setValue(layer[7])
def addFontsToList(self):
self.fontBox.addItem('arial.ttf')
self.fontBox.addItem('georgia.ttf')
for file in os.listdir("Custom fonts"):
filename = os.fsdecode(file)
if filename.endswith(".ttf"):
print('Font found:', filename)
self.fontBox.addItem(filename)
else:
continue