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

Allow to add Views with more than one word with kivymd.add_view function #1728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

krille90
Copy link

Description of the problem

Currently when creating views via kivymd.add_view, only views with one word, e.g. NotificationScreen, will be added correctly. When you try to add a view with the name NotificationSettingsScreen, all classes in the folders Model, Controller and View will be added. However, it won't be added in the screens.py(and no error / warning is thrown).

Describe the algorithm of actions that leads to the problem

In the file kivymd/tools/patterns/add_view.py (line 158ff) there is a restriction for only allowing one word screens:

if res and len(res) == 2 and res[-1] == "Screen":
                    screens += (
                        "\n    '%s': {"
                        "\n        'model': %s,"
                        "\n        'controller': %s,"
                        "\n    },"
                        % (
                            f"{res[0].lower()} {res[1].lower()}",
                            f'{"".join(res)}Model',
                            f'{"".join(res)}Controller',
                        )
...

Reproducing the problem

First create an kivymd MVC project. Then type in the following in commandline:

> kivymd.add_view MVC . NotificationSettingsScreen 

In the end, have a look into the screens.py, the imports are there, but not added in the screens dict.

Screenshots of the problem

Here you can see, that NotificationSettingsScreen wasn't added to the screens dict in screens.py
image

Description of Changes

I changed above code to allow multiple words:

if res and len(res) >= 2 and res[-1] == "Screen":
                    screens += (
                        "\n    '%s': {"
                        "\n        'model': %s,"
                        "\n        'controller': %s,"
                        "\n    },"
                        % (
                            f'{" ".join(res).lower()}',
                            f'{"".join(res)}Model',
                            f'{"".join(res)}Controller',
                        )
...

Screenshots of the solution to the problem

Here you can see, that it is now added properly.
image

Code for testing new changes

> kivymd.add_view MVC . NotificationSettingsScreen 

@HeaTTheatR
Copy link
Member

This module needs to be completely rewritten in accordance with the new API version 2.0.0

@krille90
Copy link
Author

I understand, although I don't seem to have any issue with using this module using 2.0.x.
I think merging wouldn't be much of a problem though as it's quite the small change and a rewrite of the module will still take some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants