Re: [Pythonmac-SIG] Python based apps woes on MacOs X (was :Re: [Pythoncard-users] Re: PythonCard on OS X 10.4 with Python 2.4.1)

2005-09-03 Thread Alex Tweedly




[EMAIL PROTECTED] wrote:
Yes, Alex, you're right. It was a supposed bug when I
opened the thread, so the subject line was quite good at the moment.
  

Later it became a bit obscure ;-)

  

OK - as long as you didn't think anyone was doubting that it was a bug


  
  
  
Something appears to have changed wrt the path that Python's sys.modules 
reports for imported files. 

  
  
  
  
As far as I know, no-one has yet verified 
for sure whether it is a Python bug or merely a platform-specific change 
that Pythoncard will need to adjust for. (Nor do I know how we'll be 
able to adjust - but I'm hoping that some of the PythonCard / Mac users 
are investigating )

  
  
That python user could be me !

Alex, would you discuss a bit more about this Python issue ?

  

Sure, I'll talk about it some, and maybe try to distill it down to a
simple small program that would be easy to try out.
But first I'll give a few disclaimers. 
 - I was totally unaware of this part of the code until this topic came
up
 - I'm not a Python details kind of guy 
 - I don't have, or have access to, a Mac

(So if Kevin has to come along and correct anything I say - don't be
too surprised).

  sys.modules reportings about the imported files has changed ?
Since when ?

Does this affect the Apple installed python or the "third parties" ones ?
  

No real idea since when. First guess would be between Python
2.3.something and Python 2.4.something.

I have a vague idea that Apple installed python is 2.3, so it shouldn't
be affected (but that's only a guess).

The issue is how PythonCard finds the resource files that go along with
a Python source file. By default, they live in the same directory as
the source file, and have an extra ".rsrc" appended to the base name
(before the extension) - thus a source file xyz.py would have a
resource file xyz.rsrc.py

PythonCard allows for various alternatives (language specific resource
files, platform specific files, no file but an internal dictionary,
etc.) and these make the code somewhat harder to follow. But if you
ignore all those, the essence of what PythonCard does is

1. determine the full path name for the source file
2. modify it as above
3. read and eval() the resource file.

In this case, the source file is not the application itself, but an
imported module. In the resourceEditor (in resourceEditor.py, in fact),
we do 

(before Kevin's suggested modification)
from modules.propertyEditor import PropertyEditor

    self.propertyEditorWindow = model.childWindow(self,
PropertyEditor)

(or, after Kevin's suggested modification)
from modules import propertyEditor

    self.propertyEditorWindow = model.childWindow(self,
propertyEditor.PropertyEditor)

(modules is a subdirectory within resourceEditor, propertyEditor.py is
a source file, PropertyEditor is a class within that file).

So these two should be equivalent; Kevin suggested the change because
this is the only place within PythonCard that this form of import is
used - every other import is the second form (and there was some hope
that this change would help).

I'll use the second version in this example below  and probably get
some of the terminology wrong.

When you call model.childWindow, you pass in the class you want - i.e.
propertyEditor.PropertyEditor
childWindow() then derives the filename, splits off the extension, adds
in the .rsrc.py and tries to read that file (remember I'm skipping over
the internationalization part ...)

So it does  [ frameClass is the class wanted ]

    filename =
sys.modules[frameClass.__module__].__file__
.
    base, ext = os.path.splitext(filename)
    filename = internationalResourceName(base)
    rsrc = resource.ResourceFile(filename).getResource()


So - that's the background.

Brad sent the debug output from the first case above (before Kevin's
suggested change), and also reported that the problem persisted after
the change. So it looks likely that it's a Python bug. The Python docs
are very sparse on what sys.modules should do.

I'd like to see a simple test output which is independent of PythonCard.

1. Create a test directory
 mine is called C:/python/projects/modulestest

2. create a subdirectory called "mmm"  (calling it "modules" was
confusing me)

3. create a file within that subdirectory called   myFile.py  
containing
class myClass:
    def init():
    pass

4. create another tile in that subdirectory (to make it a package)
called __init__.py containing
# turn modules into a package

(note the name is underscore underscore i n i t underscore underscore .
p y )

5. cd to the main test directory
cd c:\python\projects\modulestest
6. run python, and do
import sys
from mmm import myFile
myFile.myClass.__module__
sys.modules[myFile.myClass.__module__].__file__

and see what the output is.

It *should* be the path name to the file 



This gives the same result on Python 2.4.1 on Windows.
I'd like to see

[Pythonmac-SIG] Run Tkinter from PythonIDE?

2005-09-03 Thread Michael Crawford
Greetings,

I just joined the list.  I just built Python from source so I could do 
GUI programming on OS X.  When I try to run a very simple Tkinter script 
from the IDE, it immediately quits, crashes I guess.  But it runs OK 
when I try it from the command line in Terminal.  Here is all it is:

from Tkinter import *
w = Button( text="Hello", command='exit' )
w.pack()
w.mainloop()

It's on page 22 of Lutz & Ascher's Learning Python.

My guess is that running an event loop from a script disrupts the IDE's 
event loop.  Is that the case?  If so, is there a way I can do Tkinter 
testing from the IDE?

I'm sorry if this is a FAQ.  If you can direct me to it I'm happy to go 
read it.

Possibly I have a bug in Tk or Tcl.  I got a segment violation when 
running Tcl's "make test".  I haven't tried to diagnose it yet.

Here are the versions of everything:

Mac OS X 10.3.9
Python 2.4.1
tk 8.4.11
tcl 8.4.11
XCode 1.5
XCode update: November 2004 GCC updater
gcc version 3.3 20030304 (Apple Computer, Inc. build 1671)
ld Apple Computer, Inc. version cctools-525.1.obj~8

This is the first time I've done any Python on the Mac.  Previously I've 
only done it on Linux.

Thanks!

Michael D. Crawford
[EMAIL PROTECTED]

Read "GoingWare's Bag of Programming Tricks" at:
http://www.goingware.com/tips/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig