-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
client.py
282 lines (240 loc) · 9.67 KB
/
client.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
#Client System for the Spectrum and Intensity Node
#Used for Saving, Deleting Files by Kaleidoscope
import bpy
import math
try:
import ctypes
except:
pass
import json, os, requests
import urllib.request
from collections import OrderedDict
from . import spectrum, intensity
if "bpy" in locals():
import importlib
importlib.reload(spectrum)
importlib.reload(intensity)
palette_export = {}
class CancelProcess(bpy.types.Operator):
"""Cancel the Process"""
bl_idname = "kaleidoscope.cancel_process"
bl_label = "Cancel Process"
def execute(self, context):
try:
VK_ESCAPE = 0x1B
ctypes.windll.user32.keybd_event(VK_ESCAPE)
except AttributeError:
pass
return{'FINISHED'}
#General Structure of layout which will be used by all the popups
def menu_layout_builder(self, yes_operator, process_type):
layout = self.layout
col = layout.column(align=True)
col.scale_y = 1.2
if process_type == "spectrum_save":
col.label(text="Save a Color Palette", icon='FILE_TICK')
for i in range(1, 4):
col.separator()
col.prop(self, "name")
col.separator()
col.separator()
elif process_type == "spectrum_remove":
col.label(text="Are you sure you want to", icon="ERROR")
col.label(text="delete the current saved palette?")
col.label()
elif process_type == "intensity_save":
col.label(text="Save a Value", icon='FILE_TICK')
for i in range(1, 4):
col.separator()
col.prop(self, "name")
col.separator()
col.separator()
elif process_type == "intensity_remove":
col.label(text="Are you sure you want to", icon="ERROR")
col.label(text="delete the current saved value?")
col.label()
row = layout.row(align = False)
row.scale_y = 1.2
for i in range(1, 8):
row.separator()
row = layout.row(align = False)
row.scale_y = 1.2
for i in range(1, 13):
row.separator()
row.alert = False
row.separator()
row.operator(yes_operator, text="Yes")
class SavePaletteMenu(bpy.types.Operator):
"""Save the current Palette for future use"""
bl_idname = "spectrum.save_palette"
bl_label = "Save Spectrum Palette"
def set_name(self, context):
kaleidoscope_spectrum_props=bpy.context.scene.kaleidoscope_spectrum_props
kaleidoscope_spectrum_props.save_palette_name = self.name
return None
name: bpy.props.StringProperty(name="Palette Name", description="Enter the Name for the Palette", default="My Palette", update=set_name)
def draw(self, context):
menu_layout_builder(self, SavePaletteYes.bl_idname, "spectrum_save")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_popup(self)
class SavePaletteYes(bpy.types.Operator):
"""Save the Current Color Palette with the above name"""
bl_idname = "spectrum.save_palette_yes"
bl_label = "Save Yes"
def execute(self, context):
try:
VK_ESCAPE = 0x1B
ctypes.windll.user32.keybd_event(VK_ESCAPE)
except AttributeError:
pass
kaleidoscope_spectrum_props=bpy.context.scene.kaleidoscope_spectrum_props
global palette_export
name = kaleidoscope_spectrum_props.save_palette_name
temp_name = name
name = name.title()
name = name.replace('_', ' ')
kaleidoscope_spectrum_props.save_palette_name = name
palette_export[kaleidoscope_spectrum_props.save_palette_name] = OrderedDict([
("palette_name", kaleidoscope_spectrum_props.save_palette_name),
("color1", spectrum.rgb_to_hex(kaleidoscope_spectrum_props.color1)),
("color2", spectrum.rgb_to_hex(kaleidoscope_spectrum_props.color2)),
("color3", spectrum.rgb_to_hex(kaleidoscope_spectrum_props.color3)),
("color4", spectrum.rgb_to_hex(kaleidoscope_spectrum_props.color4)),
("color5", spectrum.rgb_to_hex(kaleidoscope_spectrum_props.color5))
])
name = kaleidoscope_spectrum_props.save_palette_name
name = name.lower()
kaleidoscope_spectrum_props.save_palette_name = name.replace(' ', '_')
if not os.path.exists(os.path.join(os.path.dirname(__file__), "palettes")):
os.makedirs(os.path.join(os.path.dirname(__file__), "palettes"))
path = os.path.join(os.path.dirname(__file__), "palettes", kaleidoscope_spectrum_props.save_palette_name+".json")
s = json.dumps(palette_export, sort_keys=True)
with open(path, "w") as f:
f.write(s)
temp_name = temp_name.title().replace("_", " ")
self.report({'INFO'}, temp_name+" palette was saved successfully")
return{'FINISHED'}
class DeletePaletteMenu(bpy.types.Operator):
"""Delete the Current Selected Palette"""
bl_idname = "spectrum.save_palette_remove"
bl_label = "Delete"
def draw(self, context):
menu_layout_builder(self, DeletePaletteYes.bl_idname, "spectrum_remove")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_popup(self)
class DeletePaletteYes(bpy.types.Operator):
"""Delete the Current Selected Palette"""
bl_idname = "spectrum.save_palette_remove_yes"
bl_label = "Delete Yes"
def execute(self, context):
try:
VK_ESCAPE = 0x1B
ctypes.windll.user32.keybd_event(VK_ESCAPE)
except AttributeError:
pass
local_error = False
kaleidoscope_spectrum_props=bpy.context.scene.kaleidoscope_spectrum_props
name = kaleidoscope_spectrum_props.saved_palettes
temp_name = name
name = name.lower()
name = name.replace(' ', '_')
path = os.path.join(os.path.dirname(__file__), "palettes", name+".json")
try:
os.remove(path)
except:
local_error = True
if local_error == False:
self.report({'INFO'}, temp_name+" palette was successfully deleted")
else:
self.report({'WARNING'}, temp_name+" palette could not be deleted")
return{'CANCELLED'}
#Intensity Node
class SaveValueMenu(bpy.types.Operator):
"""Save the current Value for future use"""
bl_idname = "intensity.save_value"
bl_label = "Save Intensity Value"
def set_name(self, context):
SaveValueMenu.pass_name = (self.name.replace(' ', '_')).lower()
pass_name = None
name: bpy.props.StringProperty(name="Value Name", description="Enter the Name for the Value", default="My Value", update=set_name)
def draw(self, context):
menu_layout_builder(self, SaveValueYes.bl_idname, "intensity_save")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_popup(self)
class SaveValueYes(bpy.types.Operator):
"""Save the current Value with the above name"""
bl_idname = "intensity.save_value_yes"
bl_label = "Save Yes"
def execute(self, context):
try:
VK_ESCAPE = 0x1B
ctypes.windll.user32.keybd_event(VK_ESCAPE)
except AttributeError:
pass
kaleidoscope_props = bpy.context.scene.kaleidoscope_props
name = SaveValueMenu.pass_name
temp_name = name
name = name.title()
name = name.replace('_', ' ')
value_export = OrderedDict([
("value_name", name),
("Value", float(intensity.IntensityNode.num_val))
])
name = SaveValueMenu.pass_name
name = name.lower()
SaveValueMenu.pass_name = name.replace(' ', '_')
if not os.path.exists(os.path.join(os.path.dirname(__file__), "values")):
os.makedirs(os.path.join(os.path.dirname(__file__), "values"))
path = os.path.join(os.path.dirname(__file__), "values", SaveValueMenu.pass_name+".json")
s = json.dumps(value_export, sort_keys=True)
with open(path, "w") as f:
f.write(s)
intensity.IntensityNode.get_custom_vals(self, context)
temp_name = temp_name.title().replace('_', " ")
self.report({'INFO'}, temp_name+" value was saved successfully")
return{'FINISHED'}
class DeleteValueMenu(bpy.types.Operator):
"""Remove this Value from the list"""
bl_idname = "intensity.remove_value"
bl_label = "Remove Intensity Value"
def draw(self, context):
menu_layout_builder(self, DeleteValueYes.bl_idname, "intensity_remove")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_popup(self)
class DeleteValueYes(bpy.types.Operator):
"""Remove this Value from the list"""
bl_idname = "intensity.remove_value_yes"
bl_label = "Delete Yes"
def execute(self, context):
try:
VK_ESCAPE = 0x1B
ctypes.windll.user32.keybd_event(VK_ESCAPE)
except AttributeError:
pass
kaleidoscope_props=bpy.context.scene.kaleidoscope_props
local_error = False
name = intensity.IntensityNode.active_custom_preset
temp_name = name
name = name.lower().replace(' ', '_')+".json"
path = os.path.join(os.path.dirname(__file__), "values", name)
try:
os.remove(path)
except:
local_error = True
if local_error == False:
self.report({'INFO'}, temp_name+" value was successfully deleted")
else:
self.report({'WARNING'}, temp_name+" value could not be deleted")
return{'FINISHED'}
def register():
pass
def unregister():
pass