[Tutor] Menu data from file
Neven Goršić
neven.gorsic at gmail.com
Tue Apr 6 00:05:47 CEST 2010
OK, I will describe my "case".
I use menu date stored in list "shape" in file CMFlowData.py in the same
directory as my main program x.py. In the beginning of the program I have
command:
import CMFlowData
and everything works fine till I make executable with py2exe. There are no
error during "compilation" and exe are created in ...\dist directory. I copy
all my external files to that directory, together with CMFlowData.py file,
but when I run x.exe I get x.exe.log file with message:
Traceback (most recent call last):
File "x.py", line 8, in <module>
ImportError: No module named CMFlowData
Traceback (most recent call last):
File "x.py", line 8, in <module>
ImportError: No module named CMFlowData
All other files that I read from disk are created with relative paths and
work fine, except when I import
my own module.
Is there some procedure to "announce" my module to the Python or System?
That is all.
Neven
----------------------------
On Mon, Apr 5, 2010 at 4:03 PM, Lie Ryan <lie.1296 at gmail.com> wrote:
> On 04/05/10 17:39, Neven Goršić wrote:
> > Thank you for mentioning the possible options.
> > I already use option where I import .py module,
> > but I run into troubles when making executable with py2exe.
>
> Maybe you should elaborate what problems you're experiencing with
> py2exe? Probably we can solve that instead of developing workarounds.
>
> Many popular UI toolkit provides an XML-based menu file.
> Here is one for PyGTK:
> http://www.pygtk.org/pygtk2tutorial/sec-UIManager.html
>
> You should better use your GUI toolkit's version instead of writing your
> own.
>
> > I suppose that XML approach is the most general method.
> > Can you recommend a good introduction text (not for experts :-))
> > and give more details about the tool ElementCTree.
> >
> > Maybe it will be educational and interesting for other beginners too.
>
> ElementTree is quite simple, though I don't think there are many good
> tutorials about it (at least I can't find one). In the simplest use
> case, you just use xml.etree.ElementTree.parse("menu.xml") and you can
> iterate the tree like so:
>
> import xml.etree.cElementTree as Et
> menuxml = """
> <menubar>
> <menu title="File">
> <menuitem title="Open File..." action="open_file"/>
> <menu title="Recent Files">
> <menuitem title="placeholder_1" action="recent_1"/>
> <menuitem title="placeholder_2" action="recent_2"/>
> <menuitem title="placeholder_3" action="recent_3"/>
> </menu>
> <menuitem title="Exit My Program" action="quit"/>
> </menu>
> <menu title="Edit">
> <menuitem title="Copy" action="copy_clipboard"/>
> <menuitem title="Paste" action="paste_clipboard"/>
> </menu>
> </menubar>
> """
> # root = Et.parse("menu.xml")
> root = Et.fromstring(menuxml)
>
> def parse(menutk, element):
> for menu in mbar:
> if menu.tag == 'menu':
> # have submenus, recurse
> submenutk = add_menu(menutk)
> parse(submenutk, menu)
> elif emnu.tag == 'menuitem':
> add_menuitem(menutk, menuitem)
>
> or something like that.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100406/252aff82/attachment.html>
More information about the Tutor
mailing list