-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionsWindow.py
284 lines (220 loc) · 9.83 KB
/
OptionsWindow.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout, QPushButton, QFrame, QMainWindow, QComboBox
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtCore import Qt
from Messenger import messenger
class ArrowButtons(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.arrow_up_callback = None
self.arrow_down_callback = None
def arrow_up_pressed(self):
if self.arrow_up_callback:
self.arrow_up_callback()
def arrow_down_pressed(self):
if self.arrow_down_callback:
self.arrow_down_callback()
def initUI(self):
layout = QVBoxLayout()
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# Add layer up icon
arrow_up_icon = QIcon("resources/arrow_up.png")
arrow_up = QPushButton()
arrow_up.setIcon(arrow_up_icon)
arrow_up.setMaximumWidth(30)
arrow_up.setMaximumHeight(15)
arrow_up.setStyleSheet("background-color: white; shadow: none")
arrow_up.clicked.connect(self.arrow_up_pressed)
layout.addWidget(arrow_up)
# Add layer down icon
arrow_down_icon = QIcon("resources/arrow_down.png")
arrow_down = QPushButton()
arrow_down.setIcon(arrow_down_icon)
arrow_down.setMaximumWidth(30)
arrow_down.setMaximumHeight(15)
arrow_down.setStyleSheet("background-color: white; shadow: none")
arrow_down.clicked.connect(self.arrow_down_pressed)
layout.addWidget(arrow_down)
class CentralLayerSettingsWidget(QWidget):
def __init__(self, layer_view):
super().__init__()
self.layer_view = layer_view
self.initUI()
self.combo_text = "Histogram"
def initUI(self):
self.font = QFont()
self.font.setFamily("Arial")
self.font.setPointSize(14)
layout = QHBoxLayout()
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
self.setStyleSheet('background-color:white')
# Add layer selection tool
layer_type_label = QLabel("Layer Type")
layer_type_label.setFont(self.font)
layout.addWidget(layer_type_label)
# Add layer selection combo box
combo = QComboBox(self)
combo_font = QFont()
combo_font.setFamily("Arial")
combo_font.setPointSize(10)
combo.setFont(combo_font)
combo.addItem("Histogram")
combo.addItem("SmoothBands")
combo.addItem("SimpleBands")
layout.addWidget(combo)
combo.activated[str].connect(self.onChanged)
def onChanged(self, text):
if text != self.combo_text:
messenger.publish("layer_gui_type_changed", {"value": text, "elem": self.layer_view})
self.combo_text = text
class LayerSettingsWindow(QMainWindow):
def __init__(self, layer_view, parent=None):
super(LayerSettingsWindow, self).__init__(parent)
central_widget = CentralLayerSettingsWidget(layer_view)
self.setStyleSheet('background-color:white')
self.setCentralWidget(central_widget)
# The individual layer that shows up in the right hand window. This includes
# the visibility button, name, arrows, settings button, etc
class LayerView(QWidget):
def __init__(self, name):
super().__init__()
self.settings_windows = LayerSettingsWindow(self)
self.initUI(name)
def visibility_toggled(self):
self.checked = not self.checked
icon = self.visible_icon if self.checked else QIcon()
self.toggle_visible.setIcon(icon)
if self.checked:
self.toggle_visible.setStyleSheet('border:none')
else:
self.toggle_visible.setStyleSheet('border:black')
messenger.publish("layer_gui_toggled", {"value" : self.checked, "elem": self})
def arrow_up_pressed(self):
messenger.publish("layer_gui_moved", {"value" : "up", "elem": self})
def arrow_down_pressed(self):
messenger.publish("layer_gui_moved", {"value": "down", "elem": self})
def initUI(self, name):
self.setMinimumSize(240, 40)
self.setMaximumWidth(300)
self.font = QFont()
self.font.setFamily("Arial")
self.font.setPointSize(14)
layout = QHBoxLayout()
self.setLayout(layout)
layout.setContentsMargins(0,0,0,0)
# Add toggle visibility button
self.toggle_visible = QPushButton()
self.checked = True
self.toggle_visible.setFlat(True)
self.visible_icon = QIcon("resources/visible.png")
self.toggle_visible.setIcon(self.visible_icon)
self.toggle_visible.setMaximumWidth(18)
self.toggle_visible.clicked.connect(self.visibility_toggled)
self.toggle_visible.setStyleSheet("background-color: rgb(205, 205, 205);")
layout.addWidget(self.toggle_visible)
# Add layer name
label = QLabel(name)
label.setFont(self.font)
layout.addWidget(label)
# Add layer order buttons button
arrow_buttons = ArrowButtons()
arrow_buttons.arrow_up_callback = self.arrow_up_pressed
arrow_buttons.arrow_down_callback = self.arrow_down_pressed
layout.addWidget(arrow_buttons)
# Add settings button
settingsIcon = QIcon("resources/settings.png")
settings = QPushButton()
settings.setIcon(settingsIcon)
settings.setMaximumWidth(30)
settings.setStyleSheet("background-color: white; shadow: none")
settings.clicked.connect(lambda: self.settings_windows.show())
layout.addWidget(settings)
# Add delete button
delIcon = QIcon("resources/delete.png")
delete = QPushButton()
delete.clicked.connect(lambda: messenger.publish("delete_gui_clicked", {"elem": self}))
delete.setIcon(delIcon)
delete.setMaximumWidth(30)
delete.setStyleSheet("background-color: white; shadow: none")
layout.addWidget(delete)
# Setup behavior when layer is clicked
selected_action = lambda event: messenger.publish("layer_gui_selected", {"elem": self})
self.mouseReleaseEvent = selected_action
selected_action(None)
# Manages all the layers together from a GUI perspective.
# Converts many GUI events into fractal events
class OptionsWindow(QFrame):
def __init__(self, fractalWindow):
super().__init__()
self.fractalWindow = fractalWindow
messenger.subscribe("delete_gui_clicked", self.remove_layer)
messenger.subscribe("layer_gui_selected", self.layer_selected)
messenger.subscribe("layer_gui_toggled", self.forward_layer_toggle_event)
messenger.subscribe("layer_gui_moved", self.layer_moved)
messenger.subscribe("layer_gui_type_changed", self.layer_type_changed)
self.selected_layer = None
self.layer_count = 1
self.initUI()
def forward_layer_toggle_event(self, event):
event["index"] = self.gui_index_to_fractal_index(event["elem"])
del event["elem"]
messenger.publish("layer_toggled", event)
def gui_index_to_fractal_index(self, elem):
layer_index = self.layout.count() - self.layout.indexOf(elem) - 1
if self.layout.indexOf(elem) == -1:
layer_index -= 1
return layer_index
def layer_selected(self, event):
if self.selected_layer:
self.selected_layer.setStyleSheet("background-color: white")
event["elem"].setStyleSheet("background-color: rgb(205, 205, 205)")
self.selected_layer = event["elem"]
layer_index = self.gui_index_to_fractal_index(event["elem"])
messenger.publish("selected_layer_changed", {"index": layer_index})
def remove_layer(self, event):
layer_index = self.gui_index_to_fractal_index(event["elem"])
if event["elem"] is self.selected_layer:
self.selected_layer = None
event["elem"].deleteLater()
messenger.publish("layer_removed", {"index": layer_index})
def layer_type_changed(self, event):
layer_index = self.gui_index_to_fractal_index(event["elem"])
messenger.publish("layer_type_changed", {"index": layer_index, "value": event["value"]})
def add_layer(self):
# Add layer just below 'New Layer' button
position = self.layout.count() - 1
messenger.publish("layer_added", {"index": position})
name = "Layer " + str(self.layer_count)
self.layer_count += 1
self.layout.insertWidget(1, LayerView(name), alignment=Qt.AlignCenter)
def layer_moved(self, event):
layer_index = self.gui_index_to_fractal_index(event["elem"])
gui_index = self.layout.indexOf(event["elem"])
# Ignore bad values
if (layer_index is 0 and event["value"] is "down") or (layer_index is self.layout.count() - 2 and event["value"] is "up"):
return
self.layout.removeWidget(event["elem"])
new_index = gui_index - 1 if event["value"] is "up" else gui_index + 1
self.layout.insertWidget(new_index, event["elem"])
messenger.publish("layer_moved", {"value": event["value"], "index": layer_index})
def initUI(self):
# Configure layout
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.layout.setAlignment(Qt.AlignBottom)
# Configure style
self.setMaximumWidth(300)
self.setMinimumSize(260, 40)
self.setStyleSheet("background-color: white")
self.setFrameStyle(QFrame.Box | QFrame.Raised)
# Add 'New Layer' button
newLayerIcon = QIcon("resources/newLayer.png")
self.newLayerIcon = newLayerIcon
newLayer = QPushButton()
newLayer.clicked.connect(self.add_layer)
newLayer.setIcon(newLayerIcon)
newLayer.setMaximumWidth(30)
newLayer.setStyleSheet("background-color: white; shadow: none")
self.layout.insertWidget(0, newLayer, alignment = Qt.AlignCenter)