sverchok icon indicating copy to clipboard operation
sverchok copied to clipboard

FilePath node extra (optional) options.

Open zeffii opened this issue 2 years ago • 3 comments

The issue comes from the need to specify the kinds of files to show in the File Open Dialogue. There are two new properties I propose https://github.com/nortikin/sverchok/commit/d53e460355aa2665b4a7887f6d818331b5e46edd

    filename_ext: StringProperty(default="")#  ".ext"
    filter_glob: StringProperty(
        default="", #*.ext1;*.ext2;*.ext3", 
        options={'HIDDEN'})

If a Node has a File Path socket, then the user's route of least resistance is to use the quicklink button beside the socket. This adds and attaches a File Path Node. We can set the kind of filename_ext and filter_glob per Node with little modifications to FilePath node's source.

>>> nodes = bpy.data.node_groups['NodeTree'].nodes
>>> nodes['File Path'].filename_ext = ".FCStd"
>>> nodes['File Path'].filter_glob = "*.FCStd"
  • [x] This changes the glob and ext, these properties can be set from the quicklink. (TODO)
  • [x] if user fills in the name of a file and doesn't add the extension, it should be possible to automatically suffix the file name.
  • [x] done in such a way as to be extendible and reusable for other file types.

Instances of FilePath Node will only behave differently when those properties are set.

zeffii avatar May 01 '22 16:05 zeffii

i'm not sure the above is the way to go, maybe the FilePath Node could take a single mode property, and depending on the mode it will fill the filename_ext and filter_glob of the FileOpenDialogue Operator.

i'll try both :)

    def draw_buttons(self, context, layout):

        op = 'node.sv_file_path'
        file_path_operator = self.wrapper_tracked_ui_draw_op(layout, op, icon='FILE', text='')
        if self.mode == "FCStd":
            file_path_operator.mode = self.mode
            # file_path_operator.filename_ext = modes[self.mode].filename_ext
            # file_path_operator.filter_glob = modes[self.mode].filter_glob

        ...etc etc

zeffii avatar May 01 '22 17:05 zeffii

I feel like these new properties should belong to the File socket. It's similar to object_kinds attribute of the Object socket.

The down side of the approach is that File Path nodes created wia such quick links will be able to work only with given extensions. However users may want reconnect the node to some other sockets which expect other extensions but they won't be able to select appropriate files.

Probably the functionality could be implemented directly in node.sv_file_path operator. It could just scan next sockets and if some of them has filename_ext attribute the node use it for the file browser. In this case whenever the socket is reconnected the operator will display appropriate extensions.

Durman avatar May 02 '22 05:05 Durman

@Durman i was thinking about that approach too.

zeffii avatar May 02 '22 05:05 zeffii