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. 12
      korman/nodes/node_python.py

12
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,11 +219,15 @@ 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"
if self.text_id is not None:
# package button # package button
row = main_row.row(align=True) row = main_row.row(align=True)
if self.text_id is not None: if self.text_id is not None:

Loading…
Cancel
Save