Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Project subfolders vs. code generation

Help
petrd
2008-05-13
2013-05-01
  • petrd
    petrd
    2008-05-13

    Hi, I'm newbie with Boa. I have this problem:
    I want to try to create small app, but for nice arrangment I want to divide my project to some subdirectories.
    So, I have dir c:/Project and subdir c:/Project/ui.
    I choose wxApp in Boa and save the Frame1.py file to Project/ui subdir and App1.py file to Project dir.
    Boa will create this:

    #Boa:App:BoaApp

    import wx

    import Frame1

    modules ={'Frame1': [1, 'Main frame of Application', u'ui/Frame1.py']}
    ...

    I think, this is wrong (in fact it doesn't work) - module Frame1 should be ui.Frame1 and the whole import string should be import ui.Frame1 as Frame1, or somthing like this, to get this example to work...?

    Please can somebody confirm, that this is a bug? Or I'm wrong?

    Thank you very much

     
    • Chelonian
      Chelonian
      2008-05-14

      Hmmm, I'm sure someone will jump in with why this isn't working in Boa--I haven't had this problem yet and can't find anything in the Boa help or Googling about it yet.  The path information is known to the app in that dict statement, but it is not using it.  I'm not sure how this is supposed to work and why it isn't.

      Anyway, here is a quick fix for now.  Add this to your import statements in the App:

      import sys
      sys.path.append("C:/Project/ui")

      As far as this goes:

      > I think, this is wrong (in fact it doesn't work) - module Frame1 should be ui.Frame1
      > and the whole import string should be import ui.Frame1 as Frame1, or somthing like
      > this, to get this example to work...?

      No, the module name is the same as the filename:  Frame1.  The problem here is that at the point in the import statement of

      import Frame1

      Python doesn't know where to find that module called "Frame1.py".  By appending the folder to the system path as above, now it does know where to find it.  What you are thinking of, I think, is accessing objects within a class via dot notation, like Frame1.textCtrl1 will give you the textCtrl1 that is an object in the Frame1 class.

       
      • petrd
        petrd
        2008-05-14

        Thanks for quick reply and fix suggestion.
        This statement (I hope)
        import ui.Frame1,
        is import of frame1 from package ui (in subdir ui there is __init__.py file (as described here: http://www.python.org/doc/essays/packages.html\). It works in my case, but I supposed, that boa can do this automatically, because the path is known (modules ={'Frame1': [1, 'Main frame of Application', u'ui/Frame1.py']} )...

         
    • Riaan Booysen
      Riaan Booysen
      2008-05-16

      Hi,

      Yes, Boa assumes the main frame to be in the same directory as the app module.

      If you change this it's up to you to change the source in the app module to match your
      structure.

      Cheers,
      Riaan.