python - PyQT project organization -


I want to organize my PyQT project, I tried to put the UI in a subfolder and import it like this GUI_sensors_extended Import Ui_SensorsWindow_Extended

from import sys.path.append ('UI / gui_sensors') but it gives me an error because it * Ui_SensorsWindow * , ui-class which was inherited in * Ui_SensorsWindow_Extended *

, what suggestions do you have to organize my project Give it Not? And how can I handle it in code?

One important thing to remember when configuring a dragon is the project: currently running script The directory is automatically added to the beginning of sys.path .

So if you put your main.py script out of your package in the top level container directory, it will guarantee that the package imports It will always work, no matter where the script is implemented. For example, here is a simple project structure:

  project / main.py package / __init__.py apap.py ui / __init__.py mainwindow.py   The script should be very low 

main.py , and this should be something like this:

  if __name__ == '__main__': import from import import package Within the  app  

and app modules, the Guinea modules will be imported like this:

  from package.ui.mainwindow import Ui_MainWindow   

This same import syntax package can be used anywhere within the tree. Can be found. So if you added another sub-package like this:

  project / main.py package / ... dialog / __init__.py search.py ​​  

Then the search module will import its GUI module in such a way:

  package. Import from ui.search Ui_SearchDialog   

If you organize all your dragon projects in such a way, there should be no need to manipulate sys.path to work properly for your local import.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -