-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanels.py
163 lines (131 loc) · 5.86 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
import bpy # type: ignore
from .functions.basic_functions import BasePanel, BaseList, SearchList, ParamAddOperator, ParamRemoveOperator, is_usb_device
from .functions import blender_funcs as bf
from . import TYPES_NAME
class PRUSASLICER_UL_SearchParamValue(SearchList):
def draw_properties(self, row, item):
row.label(text=item.param_id + " - " + item.param_description)
class SelectedCollRemoveOperator(ParamRemoveOperator):
bl_idname = f"{TYPES_NAME}.selected_coll_remove_param"
bl_label = "Remove Parameter"
def get_pg(self):
cx = bf.coll_from_selection()
return getattr(cx, TYPES_NAME)
class SelectedCollAddOperator(ParamAddOperator):
bl_idname = f"{TYPES_NAME}.selected_coll_add_param"
bl_label = "Add Parameter"
def get_pg(self):
cx = bf.coll_from_selection()
return getattr(cx, TYPES_NAME)
class PRUSASLICER_UL_IdValue(BaseList):
delete_operator = f"{TYPES_NAME}.selected_coll_remove_param"
def draw_properties(self, row, item):
row.prop(item, "param_id")
row.prop(item, "param_value")
class PRUSASLICER_UL_PauseValue(BaseList):
delete_operator = f"{TYPES_NAME}.selected_coll_remove_param"
def draw_properties(self, row, item):
sub_row = row.row(align=True)
sub_row.prop(item, "param_type")
sub_row.scale_x = 0.1
if item.param_type == "custom_gcode":
row.prop(item, "param_cmd")
else:
label = "Pause" if item.param_type == "pause" else None
label = "Color Change" if item.param_type == "color_change" else label
row.label(text=label)
# row.label(text="on layer")
sub_row = row.row(align=True)
sub_row.scale_x = 0.8 # Adjust this scale value as needed
sub_row.prop(item, 'param_value_type')
sub_row = row.row(align=True)
sub_row.scale_x = 0.5 # Adjust this scale value as needed
sub_row.prop(item, "param_value", text="")
class PrusaSlicerPanel(BasePanel):
bl_label = "Blender to PrusaSlicer"
bl_idname = f"SCENE_PT_{TYPES_NAME}"
def draw(self, context):
cx = bf.coll_from_selection()
pg = getattr(cx, TYPES_NAME)
layout = self.layout
sliceable = (pg.printer_config_file and pg.filament_config_file and pg.print_config_file)
# Toggle button for single or multiple configuration files
row = layout.row()
row.label(text=f"Slicing settings for Collection '{cx.name}'")
row = layout.row()
for prop in ['printer', 'filament', 'print']:
row = layout.row()
row.prop(pg, f"{prop}_config_file_enum", text=prop.capitalize())
row = layout.row()
if sliceable:
op = row.operator(f"export.slice", text="Slice", icon="ALIGN_JUSTIFY")
op.mode="slice"
op.mountpoint=""
op = row.operator(f"export.slice", text="Slice and Preview", icon="ALIGN_JUSTIFY")
op.mode="slice_and_preview"
op.mountpoint=""
row.operator(f"export.slice", text="Open with PrusaSlicer").mode="open"
if pg.print_time:
row = layout.row()
row.label(text=f"Printing time: {pg.print_time}")
if pg.print_weight:
row = layout.row()
row.label(text=f"Print weight: {pg.print_weight}g")
row = layout.row()
row.prop(pg, "progress", text=pg.progress_text, slider=True)
row.enabled = False
### USB Devices
import psutil
partitions = psutil.disk_partitions()
for partition in partitions:
if is_usb_device(partition):
row = layout.row()
row.label(text="Detected USB Devices:")
break
for partition in partitions:
if is_usb_device(partition):
row = layout.row()
mountpoint = partition.mountpoint
row.enabled = False if pg.running else True
row.operator(f"export.unmount_usb", text="", icon='UNLOCKED').mountpoint=mountpoint
op = row.operator(f"export.slice", text="", icon='DISK_DRIVE')
op.mountpoint=mountpoint
op.mode = "slice"
row.label(text=f"{mountpoint.split('/')[-1]} mounted at {mountpoint} ({partition.device})")
class SlicerPanel_0_Overrides(BasePanel):
bl_label = "Configuration Overrides"
bl_idname = f"SCENE_PT_{TYPES_NAME}_Overrides"
bl_parent_id = f"SCENE_PT_{TYPES_NAME}"
search_list_id = f"search_list"
list_id = f"list"
def draw(self, context):
cx = bf.coll_from_selection()
pg = getattr(cx, TYPES_NAME)
layout = self.layout
row = layout.row()
row.prop(pg, "search_term")
row = layout.row()
active_list = "PRUSASLICER_UL_SearchParamValue" if pg.search_term else "PRUSASLICER_UL_IdValue"
active_list_id = self.search_list_id if pg.search_term else self.list_id
row.template_list(active_list, f"{active_list_id}",
pg, f"{active_list_id}",
pg, f"{active_list_id}_index"
)
row = layout.row()
row.operator(f"{TYPES_NAME}.selected_coll_add_param").target=f"{self.list_id}"
class SlicerPanel_1_Pauses(BasePanel):
bl_label = "Pauses, Color Changes and Custom Gcode"
bl_idname = f"SCENE_PT_{TYPES_NAME}_Pauses"
bl_parent_id = f"SCENE_PT_{TYPES_NAME}"
list_id = f"pause_list"
def draw(self, context):
cx = bf.coll_from_selection()
pg = getattr(cx, TYPES_NAME)
layout = self.layout
row = layout.row()
row.template_list(f"PRUSASLICER_UL_PauseValue", f"{self.list_id}",
pg, f"{self.list_id}",
pg, f"{self.list_id}_index"
)
row = layout.row()
row.operator(f"{TYPES_NAME}.selected_coll_add_param").target=f"{self.list_id}"