[Pythonmac-SIG] Toxic Edit / Cocoa 'IDE'

Steven D. Majewski sdm7g@Virginia.EDU
Tue, 3 Apr 2001 17:23:22 -0400 (EDT)


On Tue, 3 Apr 2001, Jonathan Wight wrote:

> For anyone who's interested there's a new version of 'ToxicEdit' (a very
> basic Cocoa Python IDE). It's at <http://toxicsoftware.com/ToxicEdit/>.
> Changes include: totally rewritten after an accident involving the 'cp'
> command, gui tidy ups, errors from Python are now display (so you're not
> coding blind), fixes a problem with Mac OS X shared library importing where
> running this code twice would cause a crash: "import string; print
> string.split('foo bar');".


Just a quick report on trying this out: 

On first try it didn't appear to be working but it works fine now
that I figured out the "gotchas" :

 Console output is just output -- there's no "listener window". 
 Instead use "New" from the file menu, type python commands in 
 the window and click "run" .  ( BTW: What's the other button 
  mean ? "DNGN" ? ) 


 Since it's running as a file, it doesn't echo returned values -- 
 you need to explicitly print the values. 


 'RUN' doesn't seem to run them as __main__ . None of my scripts
 seemed to work until, for example, after the line: 
	if __name__ == '__main__' : main()
 I added:
	else: main()


 My Nib loading code didn't appear to work any better under Toxic Edit 
 than under Terminal.app command lines. 


 Since it uses the normal "/use/local/lib/python2.1"  paths, it was 
 able to see and import  my previously installed ObjC & Carbon 
 modules.  ( Eventually, we ought to figure out how to make a real
 Python.framework! ) 


> Hey Steve, you might want to use ToxicEdit to play about with Python on OSX
> as you'd be running the Python scripts directly in the Cocoa process
> (ToxicEdit doesn't fork - it currently uses PyRun_String() to execute the
> Python scripts). It might help with the bundle problem?

  Thanks. 

  I had started to look at the NSText* docs in AppKit just before you 
  posted this -- I was thinking along the same lines, and I was trying
  to figure out one of the missing pieces in your code -- how to grab
  a line after <RETURN> and make an in/out console window. 

  I'm going to take a peek at your sources next and see if I can 
  catch up! 

  FYI: The following code works fine from Toxic Edit with ObjC 
  installed.  -- Steve. 

 (PS. I just set up an iDisk & home page at mac.com. 
   I'm going to put  binaries on ObjCmodule.so & Carbonmodule.so   
   there for folks who don't want  to attempt the whole build. ) 


#!/usr/local/bin/python
#
# Heavily modified following an example by Lele Gaifax
# that no longer works under OSX. 
# This seems to work under 'gdb python', but not without the debugger. (?)
#
# -- Steve Majewski <sdm7g@Virginia.EDU>
#

from time import sleep
import ObjC
rt = ObjC.runtime

_AppKit = None
_Pool = None

def Pool():
    global _Pool
    POOL = rt.NSAutoreleasePool
    _Pool = POOL()
    return _Pool

def Load():
    global _AppKit
    _AppKit = rt.NSBundle.bundleWithPath_('/System/Library/Frameworks/AppKit.framework' )
    _AppKit.load()

def run():

    NSApp = rt.NSApplication.sharedApplication()

    win = rt.NSWindow.alloc()
    frame = ((200.0, 300.0), (250.0, 100.0))
    win.initWithContentRect_styleMask_backing_defer_ (frame, 15, 2, 0)
    win.setTitle_ ('Little.Button.Window')
    win.setLevel_ (3)                   # floating window

    but = rt.NSButton.alloc().initWithFrame_ (((10.0, 10.0), (80.0,80.0)))
    win.contentView().addSubview_ (but)

    but.setBezelStyle_( 4 )
    but.setTarget_ (NSApp)
    but.setAction_ ('stop:')
    but.setEnabled_ ( 1 )
    
    win.display()
#    win.makeKeyAndOrderFront_ (NSApp)  ## This doesn't seem to  work 
    win.orderFrontRegardless()          ## but this one does

    NSApp.run()    


def main():
    if not _Pool: Pool()
    if not _AppKit: Load()
    run()

if __name__ == '__main__' : main()