def browse(self, line_edit, relative_to_combobox):
root = cmds.workspace(q=True, rd=True)
file_path = cmds.fileDialog2(fileFilter=self.filter, dialogStyle=2, caption=self.name,
fileMode=1, returnFilter=False, startingDirectory=root)
if file_path:
# Modify the file path to be a path based on the relative_to value
file_path = file_path[0].replace('\\', '/')
relative_to = relative_to_combobox.currentText().replace('\\', '/')
if relative_to == FilePathField.project_root:
project_root = cmds.workspace(q=True, rd=True).replace('\\', '/')
file_path = file_path.replace(project_root, '')
elif relative_to == FilePathField.full_path:
# Do nothing, just take the full path
pass
else:
# Account for if the relative_to is an environment variable.
file_path = os.path.expandvars(file_path)
# Account for if the relative_to is an actual file path.
file_path = re.sub('^{0}'.format(relative_to), '', file_path)
line_edit.setText(file_path)
评论列表
文章目录