コード例 #1
0
    def _browse_path(self, platform):
        """Browse and set the path for the supplied platform.

        :param platform: A string indicating the platform to associate with the
            browsed path. Should match the strings returned by ``sys.platform``.
        """

        # create the dialog
        folder_path = QtGui.QFileDialog.getExistingDirectory(
            parent=self,
            caption="Choose Storage Root Folder",
            options=QtGui.QFileDialog.DontResolveSymlinks |
                    QtGui.QFileDialog.DontUseNativeDialog |
                    QtGui.QFileDialog.ShowDirsOnly
        )

        if not folder_path:
            return

        # create the SG path object. assigning the path to the corresponding
        # OS property below will sanitize
        sg_path = ShotgunPath()

        if platform.startswith("linux"):
            sg_path.linux = folder_path
            self.ui.linux_path_edit.setText(sg_path.linux)
        elif platform == "darwin":
            sg_path.macosx = folder_path
            self.ui.mac_path_edit.setText(sg_path.macosx)
        elif platform == "win32":
            sg_path.windows = folder_path
            self.ui.windows_path_edit.setText(sg_path.windows)
コード例 #2
0
    def _on_path_changed(self, path, platform):
        """
        Keep track of any path edits as they happen. Keep the user informed if
        there are any concerns about the entered text.

        :param path: The path that has changed.
        :param platform: The platform the modified path is associated with.
        """

        # does the path only contain slashes?
        only_slashes = path.replace("/", "").replace("\\", "") == ""

        # does it end in a slash?
        trailing_slash = path.endswith("/") or path.endswith("\\")

        # the name of the storage being edited
        storage_name = str(self.ui.storage_select_combo.currentText())

        # a temp SG path object used for sanitization
        sg_path = ShotgunPath()

        # store the edited path in the appropriate path lookup. sanitize first
        # by running it through the ShotgunPath object. since sanitize removes
        # the trailing slash, add it back in if the user typed it.
        # if the sanitized path differs, update the edit.
        if platform.startswith("linux"):
            if only_slashes:
                # SG path code doesn't like only slashes in a path
                self._linux_path_edit[storage_name] = path
            elif path:
                sg_path.linux = path  # sanitize
                sanitized_path = sg_path.linux
                if trailing_slash:
                    # add the trailing slash back in
                    sanitized_path = "%s/" % (sanitized_path,)
                if sanitized_path != path:
                    # path changed due to sanitation. change it in the UI
                    self.ui.linux_path_edit.setText(sanitized_path)
                # remember the sanitized path
                self._linux_path_edit[storage_name] = sanitized_path
            else:
                # no path. update the edit lookup to reflect
                self._linux_path_edit[storage_name] = ""
        elif platform == "darwin":
            if only_slashes:
                # SG path code doesn't like only slashes in a path
                self._mac_path_edit[storage_name] = path
            elif path:
                sg_path.macosx = path  # sanitize
                sanitized_path = sg_path.macosx
                if trailing_slash:
                    # add the trailing slash back in
                    sanitized_path = "%s/" % (sanitized_path,)
                if sanitized_path != path:
                    # path changed due to sanitation. change it in the UI
                    self.ui.mac_path_edit.setText(sanitized_path)
                # remember the sanitized path
                self._mac_path_edit[storage_name] = sanitized_path
            else:
                # no path. update the edit lookup to reflect
                self._mac_path_edit[storage_name] = ""
        elif platform == "win32":
            if only_slashes:
                # SG path code doesn't like only slashes in a path
                self._windows_path_edit[storage_name] = path
            elif path:
                sg_path.windows = path  # sanitize
                sanitized_path = sg_path.windows
                if trailing_slash and not sanitized_path.endswith("\\"):
                    # add the trailing slash back in
                    sanitized_path = "%s\\" % (sanitized_path,)
                if sanitized_path != path:
                    # path changed due to sanitation. change it in the UI
                    self.ui.windows_path_edit.setText(sanitized_path)
                # remember the sanitized path
                self._windows_path_edit[storage_name] = sanitized_path
            else:
                # no path. update the edit lookup to reflect
                self._windows_path_edit[storage_name] = ""

        # run the validation tell the user if there are issues
        self.mapping_is_valid()