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

Make uix widgets accessible with "from kivy.uix import Button..." #4221

Closed
Michael-F-Bryan opened this issue Apr 25, 2016 · 6 comments
Closed

Comments

@Michael-F-Bryan
Copy link

It seems almost trivial, but would it be possible to make some of the more commonly used/base widgets accessible in the kivy/uix/__init__.py module?

This would mean instead of needing to do the following:

from kivy.uix.button import Button
from kivy.uix.label import Label
...
from kivy.uix.scatter import Scatter

You only need to do the following:

from kivy.uix import Label, Button, ... , Scatter

The reason for this request is mainly to help tidy up the imports a little and means it isn't necessary to write a 30 almost identical lines when wanting to import 30 different widgets.

As far as I can tell, you would just need to import the desired classes into the kivy/uix/__init__.py module and adjust the __all__ variable like so:

# kivy/uix/__init__.py

from kivy.uix.button import Button
from kivy.uix.label import Label
...
from kivy.uix.scatter import Scatter

__all__ = ['Button', 'Label', ..., 'Scatter']
@dessant
Copy link
Contributor

dessant commented Apr 25, 2016

The import syntax would be nice, but requiring all the other widgets to be present is not desired.

Duplicate of #3583.

@dessant dessant closed this as completed Apr 25, 2016
@ghost
Copy link

ghost commented Apr 25, 2016

Worth mentioning that Factory provides easy import if you need it;

from kivy.factory import Factory

lbl = Factory.Label(text="Hello World")

class MyScatter(Factory.Scatter):
    pass

@KeyWeeUsr
Copy link
Contributor

KeyWeeUsr commented Apr 25, 2016

Maybe that's the way how init could work? Import in init Factory and for each widget return Factory.<widget>. Or is it too harsh?

@inclement
Copy link
Member

It probably would be possible to use an import hook method, though this has the disadvantage of possibly breaking the code detection of some IDEs.

Is the reason for not doing this entirely performance? If so, it would be possible (though a little untidy) to have a kivy.uix.everything module providing all the imports.

@KeyWeeUsr
Copy link
Contributor

Not really performance, just making it less to write. Sometimes it reminds me java(e.g. writing the same words multiple times). It doesn't look like that if the words are short, but when you import for example screenmanager, the imports can be long.

@inclement
Copy link
Member

I'm referring to the reason not to have this type of import - if all the widgets are imported by __init__.py it imposes a minor perfomance penalty whenever you import any widget, since all of their files are loaded. This penalty would be quite small though, I don't know if it's important (though on Android these things can be relevant even if negligible on the desktop).

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

No branches or pull requests

4 participants