Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve use of Enum as widget choices and fix types #256

Merged
merged 4 commits into from
May 31, 2024

Conversation

qin-yu
Copy link
Collaborator

@qin-yu qin-yu commented May 31, 2024

This PR originally attempts to fix the type warnings from #249. There are two modules using Enum for choices. I have enhanced both and resolved the type warnings along the way. The most significant changes include:

class RescaleType(Enum):
    NEAREST = (0, "Nearest")
    LINEAR = (1, "Linear")
    BILINEAR = (2, "Bilinear")

    def __init__(self, int_val, str_val):
        self.int_val = int_val
        self.str_val = str_val

    @classmethod
    def to_choices(cls):
        return [(mode.str_val, mode.int_val) for mode in cls]


class RescaleModes(Enum):
    FROM_FACTOR = "From factor"
    TO_LAYER_VOXEL_SIZE = "To layer voxel size"
    TO_LAYER_SHAPE = "To layer shape"
    TO_MODEL_VOXEL_SIZE = "To model voxel size"
    TO_VOXEL_SIZE = "To voxel size"
    SET_SHAPE = "To shape"
    SET_VOXEL_SIZE = "Set voxel size"

    @classmethod
    def to_choices(cls):
        return [(mode.value, mode) for mode in RescaleModes]

This approach provides an elegant solution for managing lists of string choices and their corresponding values.

@qin-yu qin-yu added bug Something isn't working duplicate This issue or pull request already exists labels May 31, 2024
@qin-yu qin-yu self-assigned this May 31, 2024
@qin-yu qin-yu added enhancement New feature or request and removed duplicate This issue or pull request already exists labels May 31, 2024
@lorenzocerrone
Copy link
Collaborator

Looks good to me

@qin-yu qin-yu merged commit 51251e9 into master May 31, 2024
1 check passed
@qin-yu qin-yu deleted the qy/fix-types-and-enum branch June 3, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants