-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathui.py
210 lines (154 loc) · 7.48 KB
/
ui.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
import bpy
from bpy.types import Panel
from sys import platform
import textwrap
from . import operators
# helper method to render long texts in multiple lines inside a GUI panel
def _label_multiline(context, text, parent):
chars = int(context.region.width / 7) # 7 pix on 1 character
wrapper = textwrap.TextWrapper(width=chars)
text_lines = wrapper.wrap(text=text)
for text_line in text_lines:
parent.label(text=text_line)
# Read-only string property
def get_server_name():
data = bpy.context.scene.TEXS_servers
return data
class CameraButtonsPanel:
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
engine = context.engine
return context.camera and (engine in cls.COMPAT_ENGINES)
class TEXS_PT_camera_texshare( CameraButtonsPanel, Panel ):
bl_label = "Share Texture"
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH', 'CYCLES', 'BLENDER_EEVEE_NEXT'}
def draw_header(self, context):
camera = context.camera
settings = camera.TEXS_share
if settings.streaming_type != '':
self.layout.prop(settings, "enable", text="")
def draw(self, context):
layout = self.layout
ob = context.object
camera = context.camera
settings = camera.TEXS_share
layout.use_property_split = True
layout.active = 1 - settings.enable
if settings.streaming_type == '' or settings.streaming_type == None:
row = layout.row(align=True)
row.label(text='Addon TextureSharing misses libraries', text_ctxt='', translate=True, icon='ERROR', icon_value=0)
else:
row = layout.row(align=True)
row.prop(settings, "streaming_type", text="Streaming Type")
row = layout.row(align=True)
row.prop(ob.data, "name", text="Sender name")
row = layout.row(align=True)
row.prop(settings, "backgroundTransparent", text="Transparency")
row = layout.row(align=True)
row.prop(settings, "applyColorManagmentSettings", text="Apply color managment")
row = layout.row(align=True)
row.prop(settings, "isflipped", text="Flip texture")
row = layout.row(align=True)
row.prop(settings, "preview", text="Show Preview")
col = layout.column()
sub = col.column(align=True)
sub.prop(settings, "capture_width", slider=True)
sub.prop(settings, "capture_height", slider=True)
row = layout.row(align=True)
row.prop_search(settings,'workspace',bpy.data,'workspaces',text='Shading')
col = layout.column()
sub = col.column(align=True)
sub.prop_search(settings,'scene',bpy.data,'scenes',text='Scene')
sub.prop_search(settings,'layer',bpy.data.scenes[settings.scene],'view_layers',text='Layer')
#######################################
# TEXSHARE RX PANEL #
#######################################
class TEXS_PT_Receiving(bpy.types.Panel):
bl_category = "Share Texture"
bl_label = "Receive Textures"
bl_space_type = "IMAGE_EDITOR"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
texture_type = context.scene.TEXS_streaming_type
generate = layout.column()
if texture_type.streaming_type == '' or texture_type.streaming_type == None:
gen_type = generate.row(align=True)
gen_type.label(text='Addon TextureSharing misses libraries', text_ctxt='', translate=True, icon='ERROR', icon_value=0)
else:
gen_type = generate.row(align=True)
gen_type.prop(texture_type, 'streaming_type', text='Type')
dataSplit = generate.split(factor = 0.7)
gen_server = dataSplit.column(align = True)
gen_server.prop(context.scene, "TEXS_servers", text='')
gen_refresh = dataSplit.column(align = True)
gen_refresh.operator("textureshare.directoryupdate", text='Update').type = texture_type.streaming_type
selected_server = context.scene.TEXS_servers
if selected_server != "OFF":
gen_create = generate.row(align = True)
create =gen_create.operator("textureshare.createitem", icon='PRESET_NEW', text='Create new texture receiver')
create.type = texture_type.streaming_type
create.server = get_server_name()
col = layout.column()
index = 0
for item in bpy.context.scene.TEXS_imgs:
col_box = col.column()
box = col_box.box()
#box.enabled = not envars.isServerRunning
colsub = box.column()
row = colsub.row(align=True)
row.prop(item, "ui_expanded", text = "",
icon='DISCLOSURE_TRI_DOWN' if item.ui_expanded else 'DISCLOSURE_TRI_RIGHT',
emboss = False)
sub1 = row.row()
if item.texs_server != "OFF" and item.texs_image != None:
sub1.prop(item, "enable", text = "",
icon='CHECKBOX_HLT' if item.enable else 'CHECKBOX_DEHLT',
emboss = False)
sub1.label(icon='IMPORT')
sub2 = row.row()
sub2.label(text=item.texs_server)
else:
sub2 = row.row()
sub2.label(text="image required", icon='ERROR')
if not item.enable:
subsub = sub2.row(align=True)
subsub.operator("textureshare.deleteitem", icon='PANEL_CLOSE', text = "").index = index
if item.ui_expanded:
colsub.active = not item.enable
dataColumn = colsub.column(align=True)
dataSplit = dataColumn.split(factor = 0.2)
colLabel = dataSplit.column(align = True)
colData = dataSplit.column(align = True)
colLabel.label(text='Server')
datapath_row = colData.row(align = True)
datapath_row.prop(item, 'texs_server',text='')
colLabel.label(text='Image')
image_row = colData.row(align = True)
image_row.prop(item, 'texs_image',text='')
colLabel.label(text='Rate')
image_row = colData.row(align = True)
image_row.prop(item, 'refresh_rate', text='')
colLabel.label(text='Type')
image_row = colData.row(align = True)
image_row.prop(item, 'streaming_type', text='')
image_row.active = 0
index = index + 1
classes = (
TEXS_PT_camera_texshare,
TEXS_PT_Receiving
)
def register():
bpy.utils.register_class(TEXS_PT_camera_texshare)
bpy.utils.register_class(TEXS_PT_Receiving)
#if platform.startswith("darwin"):
# bpy.utils.register_class(TEXS_PT_Receiving)
def unregister():
bpy.utils.unregister_class(TEXS_PT_camera_texshare)
bpy.utils.unregister_class(TEXS_PT_Receiving)
#if platform.startswith("darwin"):
# bpy.utils.unregister_class(TEXS_PT_Receiving)