MacPython applet problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • boris m

    MacPython applet problem

    I am running Python 2.3 on Mac OS 10.3.

    My problem is that applets don't seem to work. If I run a python
    script in the terminal, everything is fine. If I run the same script
    as an applet, nothing happens. The applet starts up, but dies after a
    second or two.

    I used applets quite frequently unter OS9 and never had a problem with
    them. Has anyone any idea why applets on OS X don't work the way they
    did in OS 9?

    Thanks in advance,
    Boris
  • Ronald Oussoren

    #2
    Re: MacPython applet problem


    On 10-mei-04, at 12:02, boris m wrote:
    [color=blue]
    > I am running Python 2.3 on Mac OS 10.3.
    >
    > My problem is that applets don't seem to work. If I run a python
    > script in the terminal, everything is fine. If I run the same script
    > as an applet, nothing happens. The applet starts up, but dies after a
    > second or two.
    >
    > I used applets quite frequently unter OS9 and never had a problem with
    > them. Has anyone any idea why applets on OS X don't work the way they
    > did in OS 9?[/color]

    There's probably a traceback or other message in the console log
    (Console.app). That should point you in the right direction.

    Ronald


    Comment

    • boris m

      #3
      Re: MacPython applet problem

      After some tinkering with AppleScript, I found a workaround for my
      problem. I think it is worth sharing, so here we go...

      As Ronald pointed out, python applets currently do not support
      input/output functions like 'input' or 'print'. Of course, I could run
      the script from the command line, but then I would not have a nice
      drag and drop feature.

      I wanted to have both drag/drop (via sys.argv) *and* input/output
      functions. So I wrote an AppleScript droplet that allows me to do
      this. The droplet is currently limited to accept just one item, but it
      could easily be extended.

      This was one of my first explorations into AppleScript, so I am more
      than open to suggestions and improvements.

      Boris

      ---

      --> save as application
      on open dropItem
      set itemPath to POSIX path of dropItem
      set itemPathStr to (itemPath) as string
      set itemPathCLI to textReplace(ite mPathStr, " ", "\\ ")

      tell application "Finder"
      set currentMacFolde r to (container of (path to me)) as alias
      set currentFolder to POSIX path of currentMacFolde r
      set folderPath to (currentFolder) as string
      end tell

      set folderPathCLI to textReplace(fol derPath, " ", "\\ ")
      --> don't forget chmod +x myscript.py
      --> myscript.py is in the same directory as the droplet
      set scriptPath to folderPathCLI & "myscript.p y" & " " & itemPathCLI

      activate application "Terminal"
      tell application "Terminal"
      do script scriptPath
      end tell
      end open



      on textReplace(the Text, srchStrng, replStrng)
      tell (a reference to AppleScript's text item delimiters)
      set {od, contents} to {contents, {srchStrng}}
      try
      set {textList, contents} to {(text items of theText), {replStrng}}
      set {newText, contents} to {(textList as text), od}
      return item 1 of result
      on error errMsg number errNbr
      set contents to od
      error errMsg number errNbr
      end try
      end tell
      end textReplace



      [color=blue][color=green]
      >> My problem is that I the script needs some user input (I want to[/color][/color]
      drag[color=blue][color=green]
      >> some
      >> text files to the applet and then specify some changes). For the[/color][/color]
      user[color=blue][color=green]
      >> input
      >> I am using:
      >>
      >> inputStr = raw_input("Ente r a number: \n>>> ")
      >>
      >> This, however, seems to produce the error.[/color]
      >
      > That's right. I'm pretty sure applets on OSX do no (yet) support user
      > input/output using the input function and print statement.
      >
      > IIRC this is on the TODO list for the next release of MacPython.
      >
      > B.T.W. with MacPython the default action for .py file is to execute
      > them in a Terminal window, which gives you complete support for input
      > and print.
      >
      > Ronald[/color]

      Comment

      Working...