Skip to content

Commit

Permalink
✨🚧Supported exportFullImages
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed Oct 5, 2023
1 parent a1f7f72 commit 68eabf6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
18 changes: 11 additions & 7 deletions cfdraw/.web/src/hooks/usePython.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ export async function getPythonRequest({
getExtraRequestData,
opt = {},
needExportNodeData,
exportFullImages,
}: Omit<IUsePythonInfo, "isInvisible"> & {
opt?: IGetPythonRequest;
}): Promise<Omit<IPythonSocketRequest, "hash">> {
let exportBox: BBox | undefined;
if (!opt.noExport) {
exportBox =
nodes.length === 0
? node?.bbox ?? BBox.unit()
: nodes.length === 1
? nodes[0].bbox
: nodes[argMax(nodes.map((n) => n.bbox.area))].bbox;
exportBox = exportFullImages
? undefined
: nodes.length === 0
? node?.bbox ?? BBox.unit()
: nodes.length === 1
? nodes[0].bbox
: nodes[argMax(nodes.map((n) => n.bbox.area))].bbox;
}
const getNodeDataOpt: IGetNodeData = { exportBox, ...opt };
const getNodeDataOpt: IGetNodeData = { exportBox, forceExport: exportFullImages, ...opt };
const nodeData = needExportNodeData ? await getNodeData(node, getNodeDataOpt) : {};
const nodeDataList =
!needExportNodeData || nodes.length <= 1 ? [] : await getNodeDataList(nodes, getNodeDataOpt);
Expand Down Expand Up @@ -61,6 +63,7 @@ export function useSocketPython<R>({
onMessage,
onSocketError,
needExportNodeData,
exportFullImages,
}: IUseSocketPython<R>) {
const deps = [
hash,
Expand All @@ -81,6 +84,7 @@ export function useSocketPython<R>({
identifier,
getExtraRequestData,
needExportNodeData,
exportFullImages,
}).then((req) => ({ hash: hash!, ...req })),
[deps],
);
Expand Down
2 changes: 2 additions & 0 deletions cfdraw/.web/src/plugins/_python/PluginWithSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function PythonPluginWithSubmit({
closeOnSubmit = true,
toastOnSubmit = true,
toastMessageOnSubmit,
exportFullImages,
} = pluginInfo;
const lang = langStore.tgt;
const [hash, setHash] = useState<string | undefined>(undefined);
Expand Down Expand Up @@ -96,6 +97,7 @@ function PythonPluginWithSubmit({
onSocketError,
getExtraRequestData,
needExportNodeData: hasConstraint,
exportFullImages,
});

useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion cfdraw/.web/src/plugins/_python/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function useTextTransfer({ key, plugin: { pluginInfo, ...props } }: IUseT
id: string;
text: string;
} {
const { node, nodes, identifier, retryInterval, updateInterval } = pluginInfo;
const { node, nodes, identifier, retryInterval, updateInterval, exportFullImages } = pluginInfo;
const id = usePluginIds(`${key}_${identifier}`).id;
const needRender = usePluginNeedRender(id);
const [hash, setHash] = useState<string | undefined>(undefined);
Expand Down Expand Up @@ -174,6 +174,7 @@ export function useTextTransfer({ key, plugin: { pluginInfo, ...props } }: IUseT
updateInterval,
onMessage,
needExportNodeData: hasConstraint,
exportFullImages,
});

return { id, text: value };
Expand Down
1 change: 1 addition & 0 deletions cfdraw/.web/src/schema/_python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IPythonPluginInfo extends IPluginInfo, IPythonSocketIntervals {
name?: IStr;
identifier: string;
noErrorToast?: boolean;
exportFullImages?: boolean;
}
export interface IPythonPlugin extends IPlugin {
pluginInfo: IPythonPluginInfo;
Expand Down
4 changes: 4 additions & 0 deletions cfdraw/schema/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class IPluginInfo(BaseModel):
gt=0,
description="If not None, the plugin will be called every `updateInterval` ms",
)
exportFullImages: Optional[bool] = Field(
None,
description="Whether to export full images when multiple images are selected",
)


class IPluginSettings(IChakra):
Expand Down

0 comments on commit 68eabf6

Please sign in to comment.