Skip to content

Commit

Permalink
Added Directory node (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jul 6, 2023
1 parent 1d810cb commit 5d1fd71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
8 changes: 8 additions & 0 deletions backend/src/nodes/properties/inputs/file_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(
label: str = "Base Directory",
has_handle: bool = False,
must_exist: bool = True,
hide_label: bool = False,
):
super().__init__("Directory", label, kind="directory", has_handle=has_handle)

Expand All @@ -127,9 +128,16 @@ def __init__(
"""

self.must_exist: bool = must_exist
self.hide_label: bool = hide_label

self.associated_type = str

def toDict(self):
return {
**super().toDict(),
"hideLabel": self.hide_label,
}

def enforce(self, value):
assert isinstance(value, str)
if self.must_exist:
Expand Down
9 changes: 7 additions & 2 deletions backend/src/nodes/properties/outputs/file_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
class DirectoryOutput(BaseOutput):
"""Output for saving to a directory"""

def __init__(self, label: str = "Directory", of_input: int | None = None):
def __init__(
self,
label: str = "Directory",
of_input: int | None = None,
output_type: str = "Directory",
):
directory_type = (
"Directory"
if of_input is None
else f"splitFilePath(Input{of_input}.path).dir"
)

directory_type = navi.intersect(directory_type, output_type)
super().__init__(directory_type, label, associated_type=str)

def get_broadcast_type(self, value: str):
Expand Down
22 changes: 22 additions & 0 deletions backend/src/packages/chaiNNer_standard/utility/value/directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from nodes.properties.inputs import DirectoryInput
from nodes.properties.outputs import DirectoryOutput

from .. import value_group


@value_group.register(
schema_id="chainner:utility:directory",
name="Directory",
description="Outputs the given directory.",
icon="BsFolder",
inputs=[
DirectoryInput("Directory", must_exist=False, hide_label=True, has_handle=True),
],
outputs=[
DirectoryOutput("Directory", output_type="Input0"),
],
)
def directory_node(directory: str) -> str:
return directory
1 change: 1 addition & 0 deletions src/common/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface FileInput extends InputBase {
}
export interface DirectoryInput extends InputBase {
readonly kind: 'directory';
readonly hideLabel: boolean;
}
export interface TextInput extends InputBase {
readonly kind: 'text';
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/inputs/DirectoryInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ipcRenderer } from '../../../common/safeIpc';
import { useContextMenu } from '../../hooks/useContextMenu';
import { useLastDirectory } from '../../hooks/useLastDirectory';
import { CopyOverrideIdSection } from './elements/CopyOverrideIdSection';
import { WithLabel } from './InputContainer';
import { MaybeLabel } from './InputContainer';
import { InputProps } from './props';

const getDirectoryPath = (type: Type): string | undefined => {
Expand Down Expand Up @@ -106,7 +106,7 @@ export const DirectoryInput = memo(
));

return (
<WithLabel input={input}>
<MaybeLabel input={input}>
<Tooltip
borderRadius={8}
label={displayDirectory}
Expand Down Expand Up @@ -140,7 +140,7 @@ export const DirectoryInput = memo(
/>
</InputGroup>
</Tooltip>
</WithLabel>
</MaybeLabel>
);
}
);

0 comments on commit 5d1fd71

Please sign in to comment.