-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanels.py
240 lines (184 loc) · 7.28 KB
/
panels.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
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Menu,
Operator,
PropertyGroup,
UIList
)
import bpy
import os
from uuid import uuid4
# ------------------------------------------------------------------------
# Scene Properties
# ------------------------------------------------------------------------
class StudentObject(PropertyGroup):
name: StringProperty()
uid: StringProperty()
rep_socket: StringProperty()
class ChatProperties(PropertyGroup):
port : IntProperty(
name = "Port number",
description="Port number of client or server",
default = 5550,
min = 1024,
max = 65535
)
# TODO: ADD VALIDATION
ip : StringProperty(
name = "Lecturer IP",
description = "IP address of lecturer",
default="127.0.0.1"
)
login : StringProperty(
name="User Name",
description="Provide your username",
default="",
maxlen=50
)
uid : StringProperty(
name="UID",
default=str(uuid4())
)
connection_type : EnumProperty(
name="Type of user:",
description="Apply Data to attribute.",
items=[ ('Server', "Lecturer", ""),
('Client', "Student", ""),
]
)
message: StringProperty(
name="Message",
default="",
maxlen=100
)
is_connected : BoolProperty(
name="Is Connected",
default=False,
)
path : StringProperty(
name="Server path:",
description="Select where images and .blend files from student will be saved",
default='/tmp',
subtype='DIR_PATH'
)
class PIPZMQProperties(PropertyGroup):
"""pip install and pyzmq install Properties"""
install_status: StringProperty(name="Install status",
description="Install status messages",
default="pyzmq not found in Python distribution",
)
class STUDENT_UL_items(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.3)
split.label(text="Student: %d" % (index))
#split.prop(item, "name", text="", emboss=False, translate=False, icon=custom_icon)
split.label(text=item.name) # avoids renaming the item by accident
def invoke(self, context, event):
pass
def enum_previews_from_directory_items(self, context):
"""EnumProperty callback"""
enum_items = []
if context is None:
return enum_items
students = [s.name for s in context.scene.students]
wm = context.window_manager
directory = wm.socket_settings.path
reload = wm.reload_previews
# Get the preview collection (defined in register func).
pcoll = wm.preview_collections["main"]
if not reload:
return pcoll.my_previews
pcoll.clear()
print("Scanning directory: %s" % directory)
print([(k,v.icon_id) for k, v in pcoll.items()])
def_dir = os.path.dirname(bpy.data.filepath) + directory[:]
if directory and os.path.exists(def_dir):
# Scan the directory for png files
image_paths = []
for fn in os.listdir(def_dir):
if fn.lower().endswith(".png"):
if fn[:-4] in students:
image_paths.append(fn)
print(image_paths)
for i, name in enumerate(image_paths):
# generates a thumbnail preview for a file.
filepath = os.path.join(def_dir, name)
if filepath not in [k for k, v in pcoll.items()]:
thumb = pcoll.load(filepath, filepath, 'IMAGE', force_reload=True)
enum_items.append((name, name, "", thumb.icon_id, i))
print(f'Added thumbnail: {filepath}')
pcoll.my_previews = enum_items
pcoll.my_previews_dir = directory
wm.reload_previews = False
return pcoll.my_previews
class OBJECT_PT_CustomPanel(Panel):
bl_label = "Lecture Connector"
bl_idname = "OBJECT_PT_custom_panel"
bl_category = "Lecture"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
# Crash when making screenshot
# bl_space_type = "PROPERTIES"
# bl_region_type = "WINDOW"
# bl_context = "render"
def draw(self, context):
layout = self.layout
mytool = context.window_manager.socket_settings
scene = bpy.context.scene
wm = context.window_manager
try:
import zmq
if not mytool.is_connected:
layout.prop(mytool, "connection_type", text="")
layout.prop(mytool, "port")
if mytool.connection_type == 'Client':
layout.prop(scene, "networks")
layout.prop(mytool, "ip")
layout.prop(mytool, "login")
# layout.prop(mytool, "uid")
else:
layout.prop(mytool, 'path')
layout.operator("wm.establish_connection")
else: # CONNECTED
if mytool.connection_type == 'Client':
layout.prop(mytool, "message")
row = layout.row()
row.operator("wm.send_message")
# row.operator("wm.send_file")
# row.operator("wm.send_screen")
layout.operator("wm.close_client")
else:
for _, network, _ in scene.network_list:
layout.label(text=network)
layout.prop(mytool, "login")
layout.prop(mytool, "message")
layout.label(text="Students list")
rows = 2
row = layout.row()
row.template_list("STUDENT_UL_items", "", scene, "students", scene, "student_index", rows=rows)
col = row.column(align=True)
col.operator("student.list_action", icon="ZOOM_OUT", text="").action = "REMOVE"
row = layout.row()
col = row.column(align=True)
row = col.row(align=True)
row.operator('student.send', icon="LINENUMBERS_ON")
layout.label(text="Students previews")
row = layout.row()
row.template_icon_view(wm, "my_previews", show_labels=True,scale=10.0, scale_popup=8.0)
row = layout.row()
row.prop(wm, "my_previews")
layout.operator("wm.close_server")
except ImportError:
# keep track of how our installation is going
install_props = context.window_manager.install_props
# button: enable pip and install pyzmq if not available
layout.operator("pipzmq.pip_pyzmq")
# show status messages (kinda cramped)
layout.prop(install_props, "install_status")