Project structure and organization

Skip to first unread message

Andrea Lazzarotto

Jan 5, 2015, 7:29:40 AM1/5/15

I'm new to Monkey Studio and I decided to try it because it has a very nice GUI designer for PyQT. However, I'm struggling a bit because I know Python but I don't know much about Python packages and project organization. After reading several blog posts and advices by experienced Python developers, I decided to use this project structure:

|- mainPackage
|- gui
|- otherpackage
|- anotherpackage
|- bin
|- docs

That's pretty much it. mainPackage and each sub-package have a file inside it. The file is there for now, but I am planning to refactor its logic inside the bin directory later.

So far so good, but I had difficulties to start the GUI. I got an error on this line in mainPackage/gui/

( Ui_MainWindow, QMainWindow ) = uic.loadUiType( 'mainwindow.ui' )

In fact, if called from the file, the working directory is different and the loading fails. What I did to get it working is to put this inside the file of the GUI folder:

import os

# Hack the path to run the GUI

Now, I think this solution is awful. Unfortunately, this is what I was able to accomplish.

I was wondering if you could suggest a better way to handle this, or a built-in MkS feature which allows to put GUI elements in sub-folders and get them to work without problems. Do you have any suggestion on this matter?

Finally, is there a way so that MkS can automatically refresh project files (e.g. if I add a file to bin, it will automatically show up as a project file in MkS)?

Thank you very much for your attention.

Best regards

Andrea Lazzarotto

Filipe Azevedo

Jul 3, 2015, 12:53:40 PM7/3/15
Hi Andrea,

I'm not much a python developer but i will try to help u.

For ( Ui_MainWindow, QMainWindow ) = uic.loadUiType( 'mainwindow.ui' )
The best way is to find a python api to give you the application dir path, probably u have access to QApplication::applicationDirPath(), in this case doing something like that can help:

function getUiFilePath(QString fileName ) {
    return QString("%1/gui/%2").arg(QApplication::applicationDirPath()).arg(fileName);

For auto updating the project tree when adding new files I guess it's already present feature, make sure u activated it from the project properties.

Reply all
Reply to author
0 new messages