Browse Source

Improve PyFile node file picker

pull/133/head
Adam Johnson 6 years ago
parent
commit
2c0a6f9d33
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 42
      korman/nodes/node_python.py

42
korman/nodes/node_python.py

@ -174,6 +174,9 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
bl_label = "Python File" bl_label = "Python File"
bl_width_default = 290 bl_width_default = 290
def _poll_pytext(self, value):
return value.name.endswith(".py")
def _update_pyfile(self, context): def _update_pyfile(self, context):
if self.no_update: if self.no_update:
return return
@ -185,7 +188,7 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
if self.no_update: if self.no_update:
return return
with self.NoUpdate(): with self.NoUpdate():
self.filename = self.text_id.name self.filename = self.text_id.name if self.text_id is not None else ""
self.attributes.clear() self.attributes.clear()
self.inputs.clear() self.inputs.clear()
if self.text_id is not None: if self.text_id is not None:
@ -198,6 +201,7 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
text_id = PointerProperty(name="Script File", text_id = PointerProperty(name="Script File",
description="Script file datablock", description="Script file datablock",
type=bpy.types.Text, type=bpy.types.Text,
poll=_poll_pytext,
update=_update_pytext) update=_update_pytext)
# This property exists for UI purposes ONLY # This property exists for UI purposes ONLY
@ -215,27 +219,31 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
row = main_row.row(align=True) row = main_row.row(align=True)
row.alert = self.text_id is None and bool(self.filename) row.alert = self.text_id is None and bool(self.filename)
row.prop(self, "text_id", text="Script") row.prop(self, "text_id", text="Script")
# open operator # open operator
operator = main_row.operator("file.plasma_file_picker", icon="FILESEL", text="") sel_text = "Load Script" if self.text_id is None else ""
operator = main_row.operator("file.plasma_file_picker", icon="FILESEL", text=sel_text)
operator.filter_glob = "*.py" operator.filter_glob = "*.py"
operator.data_path = self.node_path operator.data_path = self.node_path
operator.filename_property = "filename" operator.filename_property = "filename"
# package button
row = main_row.row(align=True)
if self.text_id is not None:
row.enabled = True
icon = "PACKAGE" if self.text_id.plasma_text.package else "UGLYPACKAGE"
row.prop(self.text_id.plasma_text, "package", icon=icon, text="")
else:
row.enabled = False
row.prop(self, "package", text="", icon="UGLYPACKAGE")
# rescan operator
row = main_row.row(align=True)
row.enabled = self.text_id is not None
operator = row.operator("node.plasma_attributes_to_node", icon="FILE_REFRESH", text="")
if self.text_id is not None: if self.text_id is not None:
operator.text_path = self.text_id.name # package button
operator.node_path = self.node_path row = main_row.row(align=True)
if self.text_id is not None:
row.enabled = True
icon = "PACKAGE" if self.text_id.plasma_text.package else "UGLYPACKAGE"
row.prop(self.text_id.plasma_text, "package", icon=icon, text="")
else:
row.enabled = False
row.prop(self, "package", text="", icon="UGLYPACKAGE")
# rescan operator
row = main_row.row(align=True)
row.enabled = self.text_id is not None
operator = row.operator("node.plasma_attributes_to_node", icon="FILE_REFRESH", text="")
if self.text_id is not None:
operator.text_path = self.text_id.name
operator.node_path = self.node_path
# This could happen on an upgrade # This could happen on an upgrade
if self.text_id is None and self.filename: if self.text_id is None and self.filename:

Loading…
Cancel
Save