-
Notifications
You must be signed in to change notification settings - Fork 1
/
editor_functions.py
217 lines (198 loc) · 9.56 KB
/
editor_functions.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
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QColor,QPixmap
from settings import *
from editor_class import EDITOR
from shapes import *
#---handles calling add or update user function when add/update editor button cliecked
def add_editor_handler(main):
if main.addEditorButton.text()=='UPDATE':
update_editor(main)
pass
elif main.addEditorButton.text()=='ADD':
add_new_editor(main)
#---saves any change to editor line width to var
def editor_linewidth_changed(main,value):
main.editor_line_width=value
#---saves any change to editor node size to var
def editor_nodesize_changed(main,value):
main.editor_node_size=value
#---flips editor UID toggled Boolean
def editor_uid_toggled(main):
main.editor_UID_toggled = not main.editor_UID_toggled
#---saves any change to editor name to var
def editor_name_changed(main,value):
main.editor_name=value
#---saves any change to editor username to var
def editor_username_changed(main,value):
main.editor_username=value
##---saves any change to editor line color to var and repaints line color preview
def editor_linecolor_changed(main):
color = QColorDialog.getColor()
clr = color.name()
colr = ""
for i in clr:
colr+= str(i)
if colr =="#000000":
colr = main.editor_line_color_text
else:
main.editor_line_color_ui=QColor(color)
main.editor_line_color_text = colr
main.editorLineColorpix.fill(main.editor_line_color_ui)
main.editorLineColorPreview.setPixmap(main.editorLineColorpix)
#---saves any change to editor node color to var and repaints node color preview and node shape preview
def editor_nodecolor_changed(main):
color = QColorDialog.getColor()
clr = color.name()
colr = ""
for i in clr:
colr+= str(i)
if colr =="#000000":
colr=main.editor_node_color_text
else:
main.editor_node_color_ui=QColor(color)
main.editor_node_color_text = colr
main.editorNodeColorpix = QPixmap(15, 15)
main.editorNodeColorpix.fill(main.editor_node_color_ui)
main.editorNodeColorPreview.setPixmap(main.editorNodeColorpix)
main.editorNodeShapePixmap=QPixmap(allShapes[main.editor_node_shape])
main.editorNodeShapeMask = main.editorNodeShapePixmap.createMaskFromColor(QColor(BLACK), Qt.MaskInColor)
main.editorNodeShapePixmap.fill(main.editor_node_color_ui)
main.editorNodeShapePixmap.setMask(main.editorNodeShapeMask)
main.editorNodeShapePixmap=main.editorNodeShapePixmap.scaled(30,30)
main.editorNodeShapePreview.setPixmap(main.editorNodeShapePixmap)
#---Applies any changes in editor settings fields to selected editors then re-renders the editor table with new info
def update_editor(main):
print(len(main.selectedEditors))
if len(main.selectedEditors)>1:
editorNames=main.editorNameField.text().split(',')
editorUsernames=main.editorUsernameField.text().split(',')
for editor,name in zip(main.selectedEditors,editorNames):
editor.firstName=name.strip()
for editor,username in zip(main.selectedEditors,editorUsernames):
editor.username=username.strip()
for editor in main.selectedEditors:
editor.nodeShapeText=main.editor_node_shape
editor.lineColorText=main.editor_line_color_text
editor.nodeColorText=main.editor_node_color_text
editor.lineColorUI=main.editor_line_color_ui
editor.nodeColorUI=main.editor_node_color_ui
editor.iconSize=int(main.editor_node_size)
editor.lineWidth=int(main.editor_line_width)
editor.nodeShape=QPixmap(allShapes[main.editor_node_shape])
editor.nodeShape= editor.nodeShape.scaled(60, 60)
editor.nodeMask = editor.nodeShape.createMaskFromColor(QColor(BLACK), Qt.MaskInColor)
editor.nodeShape.fill(editor.nodeColorUI)
editor.nodeShape.setMask(editor.nodeMask)
main.editorTable.clear()
for editor in main.currentEditorsOrdered:
editor.construct_list_item(main)
clear_editor_info(main)
else:
main.selectedEditors[0].firstName=main.editor_name
main.selectedEditors[0].username=main.editor_username
main.selectedEditors[0].lineColorUI=main.editor_line_color_ui
main.selectedEditors[0].nodeColorUI=main.editor_node_color_ui
main.selectedEditors[0].lineColorText=main.editor_line_color_text
main.selectedEditors[0].nodeColorText=main.editor_node_color_text
main.selectedEditors[0].iconSize=int(main.editor_node_size)
main.selectedEditors[0].lineWidth=int(main.editor_line_width)
main.selectedEditors[0].nodeShapeText=main.editor_node_shape
main.selectedEditors[0].nodeShape=QPixmap(allShapes[main.editor_node_shape])
main.selectedEditors[0].nodeShape= main.selectedEditors[0].nodeShape.scaled(60, 60)
main.selectedEditors[0].nodeMask = main.selectedEditors[0].nodeShape.createMaskFromColor(QColor(BLACK), Qt.MaskInColor)
main.selectedEditors[0].nodeShape.fill(main.selectedEditors[0].nodeColorUI)
main.selectedEditors[0].nodeShape.setMask(main.selectedEditors[0].nodeMask)
main.editorTable.clear()
for editor in main.currentEditorsOrdered:
editor.construct_list_item(main)
clear_editor_info(main)
main.addEditorButton.setText('ADD')
#---creates a new editor class instance from new info in editor settings, adds editor to editor list & table, re-renders editor table with new entry
def add_new_editor(main):
new_editor=EDITOR(
main.editor_name,
main.editor_username,
main.editor_line_color_text,
main.editor_node_color_text,
main.editor_node_size,
main.editor_node_shape,
main.editor_line_width)
main.currentEditorsOrdered.append(new_editor)
main.editorTable.clear()
for editor in main.currentEditorsOrdered:
editor.construct_list_item(main)
clear_editor_info(main)
#---Grabs info on selected editors from editor list and applies it to editor settings fields for change & update
def edit_editor(main):
main.addEditorButton.setText('UPDATE')
editing_names=[]
editing_usernames=[]
for editor in main.selectedEditors:
editing_names.append(editor.firstName)
editing_usernames.append(editor.username)
editing_names=str(editing_names).replace("[",'')
editing_names=str(editing_names.replace("]",''))
editing_names=str(editing_names.replace("'",''))
editing_usernames=str(editing_usernames).replace("[",'')
editing_usernames=str(editing_usernames.replace("]",''))
editing_usernames=str(editing_usernames.replace("'",''))
main.editor_node_color_text= main.selectedEditors[0].nodeColorText
main.editor_line_color_text= main.selectedEditors[0].lineColorText
main.editor_node_color_ui= main.selectedEditors[0].nodeColorUI
main.editor_line_color_ui= main.selectedEditors[0].lineColorUI
main.editor_node_shape=main.selectedEditors[0].nodeShapeText
main.editor_line_width=main.selectedEditors[0].lineWidth
main.editor_node_size=main.selectedEditors[0].iconSize
if len(main.selectedEditors)==1:
main.editorNameField.setText(main.selectedEditors[0].firstName)
main.editorUsernameField.setText(main.selectedEditors[0].username)
main.editorLineWidthSpinner.setValue(int(main.editor_line_width))
main.editorNodeWidthSpinner.setValue(int(main.editor_node_size))
main.editorNodeColorpix = QPixmap(15, 15)
main.editorNodeColorpix.fill(main.editor_node_color_ui)
main.editorNodeColorPreview.setPixmap(main.editorNodeColorpix)
main.editorLineColorpix = QPixmap(15, 15)
main.editorLineColorpix.fill(main.editor_line_color_ui)
main.editorLineColorPreview.setPixmap(main.editorLineColorpix)
pix=main.selectedEditors[0].nodeShape
main.editorNodeShapePreview.setPixmap(pix)
else:
main.editorNameField.setText(editing_names)
main.editorUsernameField.setText(editing_usernames)
#---clears all editor settings fields after editor added or updated
def clear_editor_info(main):
main.editor_name=''
main.editor_username=''
main.editor_line_color_text=''
main.editor_node_color_text=''
main.editor_node_size=1
main.editor_node_shape='circle'
main.editor_line_width=5
main.editorNameField.setText('')
main.editorUsernameField.setText('')
main.editorLineWidthSpinner.setValue(5)
main.editorNodeWidthSpinner.setValue(10)
main.editorNodeColorpix = QPixmap(15, 15)
main.editorNodeColorpix.fill(QColor(WHITE))
main.editorNodeColorPreview.setPixmap(main.editorNodeColorpix)
main.editorLineColorpix = QPixmap(15, 15)
main.editorLineColorpix.fill(QColor(WHITE))
main.editorLineColorPreview.setPixmap(main.editorLineColorpix)
main.editorNodeShapePix=QPixmap(15,15)
main.editorNodeShapePix.fill(QColor(WHITE))
main.editorNodeShapePreview.setPixmap(main.editorNodeShapePix)
def hide_users(main):
for editor in main.selectedEditors:
editor.hidden=True
editor.visibility_icon=HIDDEN_ICON
main.editorTable.clear()
for editor in main.currentEditorsOrdered:
editor.construct_list_item(main)
def show_users(main):
for editor in main.selectedEditors:
editor.hidden=False
editor.visibility_icon=VIEW_ICON
main.editorTable.clear()
for editor in main.currentEditorsOrdered:
editor.construct_list_item(main)