Porting code woes

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

If someone could take a look at my tutorial and figure out what I'm doing wrong, that would be great. I'm sure it has something to do with not setting up my shell script or my snake script correctly. Any advice would be appreciated:

Here's the link: http://www.blog.pythonlibrary.org/?p=93

I'm using Ubuntu Hardy Heron, wxPython 2.8.8.1 and Python 2.5.2.

Thanks,

···

-------------------
Mike Driscoll

Blog: http:\\blog.pythonlibrary.org
Python Extension Building Network: http:\\www.pythonlibrary.org

Hi Mike,

Mike Driscoll wrote:

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

If someone could take a look at my tutorial and figure out what I'm doing wrong, that would be great. I'm sure it has something to do with not setting up my shell script or my snake script correctly. Any advice would be appreciated:

Here's the link: Porting wxPyMail to Linux - Mouse Vs Python

I'm using Ubuntu Hardy Heron, wxPython 2.8.8.1 and Python 2.5.2.

I have no answer to your problem but a couple of comments.

I am trying it out on Windows Vista.
- part of my from e-mail address is not shown, i.e. to see it I have to position the cursor at the beginning of the textctrl.
- you require a login to the smpt server. I am in France connected to the net with a free.fr ADSL/Broadband connection and there is no login to the smtp server.
- I see the following in the Boa output/stdout window:
['wxPyMail.py']
Unable to execute parseURL...
list index out of range

But the program works nicely, after I commented the login call.

What about using the maskedit control for the email address entries. There is an option so it checks that you enter a valid email and it also has an option to autosize itself based on the number of characters you defined and gives feedback to the user that data is required (see emptyInvalid and yellow background).

The code changes to use masked would be:
import wx.lib.masked as masked
#### self.fromTxt = wx.TextCtrl(p, id=wx.ID_ANY, value=self.email)
        self.fromTxt = masked.TextCtrl(p, id=wx.ID_ANY)
        self.fromTxt.SetCtrlParameters(mask = "X{70}", formatcodes = "F_S>",
                                        autoformat = u'EMAIL',
                                        emptyInvalid = True)
        self.fromTxt.SetValue(self.email)
               self.toLbl = wx.StaticText(p, id=wx.ID_ANY, label='To:', size=(60,-1))
#### self.toTxt = wx.TextCtrl(p, id=wx.ID_ANY, value='')
        self.toTxt = masked.TextCtrl(p, id=wx.ID_ANY)
        self.toTxt.SetCtrlParameters(mask = "X{70}", formatcodes = "F_S>",
                                        autoformat = u'EMAIL',
                                        emptyInvalid = True)

Werner

Werner,

Hi Mike,

Mike Driscoll wrote:

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

If someone could take a look at my tutorial and figure out what I'm doing wrong, that would be great. I'm sure it has something to do with not setting up my shell script or my snake script correctly. Any advice would be appreciated:

Here's the link: Porting wxPyMail to Linux - Mouse Vs Python

I'm using Ubuntu Hardy Heron, wxPython 2.8.8.1 and Python 2.5.2.

I have no answer to your problem but a couple of comments.

I am trying it out on Windows Vista.
- part of my from e-mail address is not shown, i.e. to see it I have to position the cursor at the beginning of the textctrl.

That's weird. It seemed to be working ok on my Vista box. I'll look into this and see if I need to increase the size of the control some more.

- you require a login to the smpt server. I am in France connected to the net with a free.fr ADSL/Broadband connection and there is no login to the smtp server.

I know some smtp servers don't require logins...that's an artifact since my server does seem to require it. I'll add an options menu that allows the user to set up their login credentials or disable it entirely.

- I see the following in the Boa output/stdout window:
['wxPyMail.py']
Unable to execute parseURL...
list index out of range

This happens because the script is technically only supposed to be run when a user clicks a mailto link in a web page. However, I made it so I could use it either way. Since you didn't pass it a mailto string, the error pops up.

But the program works nicely, after I commented the login call.

What about using the maskedit control for the email address entries. There is an option so it checks that you enter a valid email and it also has an option to autosize itself based on the number of characters you defined and gives feedback to the user that data is required (see emptyInvalid and yellow background).

The code changes to use masked would be:
import wx.lib.masked as masked
#### self.fromTxt = wx.TextCtrl(p, id=wx.ID_ANY, value=self.email)
       self.fromTxt = masked.TextCtrl(p, id=wx.ID_ANY)
       self.fromTxt.SetCtrlParameters(mask = "X{70}", formatcodes = "F_S>",
                                       autoformat = u'EMAIL',
                                       emptyInvalid = True)
       self.fromTxt.SetValue(self.email)
             self.toLbl = wx.StaticText(p, id=wx.ID_ANY, label='To:', size=(60,-1))
#### self.toTxt = wx.TextCtrl(p, id=wx.ID_ANY, value='')
       self.toTxt = masked.TextCtrl(p, id=wx.ID_ANY)
       self.toTxt.SetCtrlParameters(mask = "X{70}", formatcodes = "F_S>",
                                       autoformat = u'EMAIL',
                                       emptyInvalid = True)

Werner

I just recently started playing with masked controls last week. This looks like its another good application for it. I'll add that too. Once I've got the options menu done, I'll let you know. Thanks for the feedback!

Mike

Mike Driscoll wrote:

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

What are you doing to register the app as the handler for mailto links? I don't remember details but I think you need to do something with the .desktop file for the app under KDE. Gnome is probably different.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Mike Driscoll wrote:

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

did you make the script executable:

chmod +x myprog.py

you should be able to type "./myprog.py" and have it run after that, and then the browser should be able to run it as well.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Robin,

Mike Driscoll wrote:

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

What are you doing to register the app as the handler for mailto links? I don't remember details but I think you need to do something with the .desktop file for the app under KDE. Gnome is probably different.

I am following this how-to guide: http://www.howtogeek.com/howto/ubuntu/set-gmail-as-default-mail-client-in-ubuntu/

It claims I can go to "System \ Preferences \ Preferred Applications" and change the mail reader to point at a shell script that will run an application. In the how-to, it points to gmail, but I modified the shell script to point to my Python script instead. Nothing happens when I click the mailto link, so I'm not sure if the problem is my shell script or my wxPython script. Unfortunately, I'm very green when it comes to Linux, so I don't really know where to start troubleshooting this.

Thanks for the pointer on the .desktop file. Maybe that will give me a clue...

Mike

Mike Driscoll wrote:

Werner,

Hi Mike,

Mike Driscoll wrote:

Hi,

In writing my next tutorial on porting wxPyMail to Ubuntu, I found that my wxPython code worked very well with almost no modification. Unfortunately, while I can get it to run from the command line by calling "python myprog.py", I can't get it to run when I click on a link in a web page.

If someone could take a look at my tutorial and figure out what I'm doing wrong, that would be great. I'm sure it has something to do with not setting up my shell script or my snake script correctly. Any advice would be appreciated:

Here's the link: Porting wxPyMail to Linux - Mouse Vs Python

I'm using Ubuntu Hardy Heron, wxPython 2.8.8.1 and Python 2.5.2.

I have no answer to your problem but a couple of comments.

I am trying it out on Windows Vista.
- part of my from e-mail address is not shown, i.e. to see it I have to position the cursor at the beginning of the textctrl.

That's weird. It seemed to be working ok on my Vista box. I'll look into this and see if I need to increase the size of the control some more.

I'm almost done with a new version of this silly script, but it's taking me longer than I anticipated. However, the issue seems to be that the code needs a call to the frame's Layout() before it's shown. That fixed it on my machine at any rate.

Mike

Mike Driscoll wrote:

I am following this how-to guide: http://www.howtogeek.com/howto/ubuntu/set-gmail-as-default-mail-client-in-ubuntu/

click the mailto link, so I'm not sure if the problem is my shell script or my wxPython script. Unfortunately, I'm very green when it comes to Linux, so I don't really know where to start troubleshooting this.

Are both your shellscript and python script executable?

you could add some printing in your shell script (and python script):

echo "this script is running"

though I guess I'm not sure where that would show up.

An alternative to it write something to a file in the script:

echo "this is something written to a file" > A_test_file.txt

the look at that file -- that should help you know if the script is running, etc.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

did you make the script executable:

chmod +x myprog.py

you should be able to type "./myprog.py" and have it run after that, and then the browser should be able to run it as well.

On other note: I don't have Linux up at the moment, but in OS-X firefox, there is a tab under preferences:

Applications.

Under there, mailto is set to Thunderbird (in my case), so it's not using the system's defined mail client. That web page seemed to be setting the system default, so Firefox may be ignoring that.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Mike,

Mike Driscoll wrote:

...

I'm almost done with a new version of this silly script, but it's taking me longer than I anticipated. However, the issue seems to be that the code needs a call to the frame's Layout() before it's shown. That fixed it on my machine at any rate.

Let me know when you have it done I'll give it a go.

Werner

Chris,

Mike Driscoll wrote:

I am following this how-to guide: http://www.howtogeek.com/howto/ubuntu/set-gmail-as-default-mail-client-in-ubuntu/

click the mailto link, so I'm not sure if the problem is my shell script or my wxPython script. Unfortunately, I'm very green when it comes to Linux, so I don't really know where to start troubleshooting this.

Are both your shellscript and python script executable?

Ok, here's what I have in my wxPyMail folder:

<terminal session>

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ls -l
total 28
-r--r--r-- 1 mike mike 1749 2007-07-10 12:43 mail_ico.py
-rw-r--r-- 1 mike mike 1437 2008-09-30 11:18 mail_ico.pyc
-r-xr-xr-x 1 mike mike 17325 2008-09-13 09:22 wxPyMail.py

</terminal session>

When I try to run it from the command, I get this:

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ./wxPyMail.py
: No such file or directory

I got my shell script to run from the command line though, but I guess I don't know how to make it connect to my python script. I get this:

./open_mailto.sh: 4: ./home/mike/Desktop/wxPyMail/wxPyMail.py: not found

If I try to run it again, I get the same error as my Python script above:

./open_mailto.sh
: No such file or directory

This is weird.

Mike

Mike Driscoll wrote:

Ok, here's what I have in my wxPyMail folder:

<terminal session>

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ls -l
total 28
-r--r--r-- 1 mike mike 1749 2007-07-10 12:43 mail_ico.py
-rw-r--r-- 1 mike mike 1437 2008-09-30 11:18 mail_ico.pyc
-r-xr-xr-x 1 mike mike 17325 2008-09-13 09:22 wxPyMail.py

</terminal session>

When I try to run it from the command, I get this:

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ./wxPyMail.py
: No such file or directory

Hi Mike

1. Do you have #!/usr/bin/python (or equivalent) as the top line of your
script?

2. Does your file have <crlf> line endings? I have found to my cost in the
past that this prevents the script from executing - it expects a single <lf>
line terminator. I don't know what editor you use, but with Textpad I can
select 'Save as ...', then change the file format to Unix, then save it.
This changes all the <crlf>'s to <lf>'s.

HTH

Frank Millman

Mike Driscoll wrote:

Chris,

Mike Driscoll wrote:

I am following this how-to guide: http://www.howtogeek.com/howto/ubuntu/set-gmail-as-default-mail-client-in-ubuntu/

click the mailto link, so I'm not sure if the problem is my shell script or my wxPython script. Unfortunately, I'm very green when it comes to Linux, so I don't really know where to start troubleshooting this.

Are both your shellscript and python script executable?

Ok, here's what I have in my wxPyMail folder:

<terminal session>

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ls -l
total 28
-r--r--r-- 1 mike mike 1749 2007-07-10 12:43 mail_ico.py
-rw-r--r-- 1 mike mike 1437 2008-09-30 11:18 mail_ico.pyc
-r-xr-xr-x 1 mike mike 17325 2008-09-13 09:22 wxPyMail.py

</terminal session>

When I try to run it from the command, I get this:

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ./wxPyMail.py
: No such file or directory

What does your #! line look like? Does the file use Unix or DOS style line endings?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frank and Robin,

Mike Driscoll wrote:
  

Ok, here's what I have in my wxPyMail folder:

<terminal session>

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ls -l
total 28
-r--r--r-- 1 mike mike 1749 2007-07-10 12:43 mail_ico.py
-rw-r--r-- 1 mike mike 1437 2008-09-30 11:18 mail_ico.pyc
-r-xr-xr-x 1 mike mike 17325 2008-09-13 09:22 wxPyMail.py

</terminal session>

When I try to run it from the command, I get this:

mike@mld-ubuntu-vm:~/Desktop/wxPyMail$ ./wxPyMail.py
: No such file or directory

Hi Mike

1. Do you have #!/usr/bin/python (or equivalent) as the top line of your
script?
  
I have this at the top of my python file: #!/usr/bin/env python

2. Does your file have <crlf> line endings? I have found to my cost in the
past that this prevents the script from executing - it expects a single <lf>
line terminator. I don't know what editor you use, but with Textpad I can
select 'Save as ...', then change the file format to Unix, then save it.
This changes all the <crlf>'s to <lf>'s.
  
I'm not sure how to tell what I currently have and it looks like I don't have TextPad, just some lame Ubuntu-included thing called "Text Editor". It doesn't have an option to save my file as Unix. I tried KomodoEdit, but it doesn't have that option either. TextPad doesn't seem to be found by Synaptic either. I'll bet this is the problem though. I'll have to find a better app...

Thanks for the pointers!.

Mike

···

HTH

Frank Millman

Mike Driscoll wrote:

line terminator. I don't know what editor you use, but with Textpad I can
select 'Save as ...', then change the file format to Unix, then save it.
This changes all the <crlf>'s to <lf>'s.

worth a try, but I thought <crlf> worked, as it's looking for the <lf>. on a mac if you have only the <cr> it definitely breaks the shell's ability to interpret the #!line.

A note: if you are using SVN, it DOES NOT translate line endings by default, you need to set the eol-style property on the files themselves. You can set you client to do this automatically when you add files, but there is no way to set it up as a default on the server -- this is a really broken interface, if you ask me!

I'm not sure how to tell what I currently have and it looks like I don't have TextPad, just some lame Ubuntu-included thing called "Text Editor". It doesn't have an option to save my file as Unix. I tried KomodoEdit, but it doesn't have that option either.

Does it let you show the invisible characters? that will tell you. There are also utilities out there to translate for you (dos2unix). Or, if nothing else, just open the file in python with the "U" flag, and read the data, and write it back out again.

It looks like it's time for you to use a wxPython based editor! I now I've been desperate for years to have a really good editor with a modern interface that works the same on all platforms I use. I'm using Peppy now, which I think has the most promise, but it is still kind of immature.

Editra's pretty good, and it comes with wxPython now.

Oh, and why don't you show us your script?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

Mike Driscoll wrote:

line terminator. I don't know what editor you use, but with Textpad I can
select 'Save as ...', then change the file format to Unix, then save it.
This changes all the <crlf>'s to <lf>'s.

worth a try, but I thought <crlf> worked, as it's looking for the <lf>. on a mac if you have only the <cr> it definitely breaks the shell's ability to interpret the #!line.

The problem with DOS line endings on the #! line is that the shell ends up looking for a program named "python<cr>" instead of "python", so the file not found error is truly reporting the problem.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hello,

···

On Thu, Oct 2, 2008 at 10:44 AM, Mike Driscoll mike@pythonlibrary.org wrote:

Frank and Robin,

  1. Does your file have line endings? I have found to my cost in the

past that this prevents the script from executing - it expects a single

line terminator. I don’t know what editor you use, but with Textpad I can

select ‘Save as …’, then change the file format to Unix, then save it.

This changes all the 's to 's.

I’m not sure how to tell what I currently have and it looks like I don’t have TextPad, just some lame Ubuntu-included thing called “Text Editor”. It doesn’t have an option to save my file as Unix. I tried KomodoEdit, but it doesn’t have that option either. TextPad doesn’t seem to be found by Synaptic either. I’ll bet this is the problem though. I’ll have to find a better app…

Open your file in Editra (comes with your wxpython, from command line ‘editra’)

View->Editor->Show EOL Markers

If you want to convert them then

Format->EOL Mode->Unix

Chris,

Mike Driscoll wrote:

I'm not sure how to tell what I currently have and it looks like I don't have TextPad, just some lame Ubuntu-included thing called "Text Editor". It doesn't have an option to save my file as Unix. I tried KomodoEdit, but it doesn't have that option either.

Does it let you show the invisible characters? that will tell you. There are also utilities out there to translate for you (dos2unix). Or, if nothing else, just open the file in python with the "U" flag, and read the data, and write it back out again.

It doesn't seem to have that feature...but Komodo does and it looks like I do have <crlf> line endings. I'll give Cody's Editra idea a try.

It looks like it's time for you to use a wxPython based editor! I now I've been desperate for years to have a really good editor with a modern interface that works the same on all platforms I use. I'm using Peppy now, which I think has the most promise, but it is still kind of immature.

Editra's pretty good, and it comes with wxPython now.

Oh, and why don't you show us your script?

-Chris

I did show the script in my first post. Or I should say, I linked to it: Porting wxPyMail to Linux - Mouse Vs Python

But I've attached it too so you can see the thing. I am currently adding some functionality to it, so there will be a new version soon (by the weekend, I hope). I've been using WingWare lately for my Python editing. It's really good, although some of wx's code must be kind of obfuscated as Wing can't always find all the methods for certain objects or the help just isn't very helpful. I think that's more of a limitation of the doc strings on some of the objects than anything though.

Mike

wxpymail.zip (5.21 KB)

Mike Driscoll wrote:

It doesn't seem to have that feature...but Komodo does and it looks like I do have <crlf> line endings. I'll give Cody's Editra idea a try.

I hope that takes care of it for you then.

I did show the script in my first post. Or I should say, I linked to it: Porting wxPyMail to Linux - Mouse Vs Python

But I've attached it too so you can see the thing.

I've seen the python, but not the shell script -- that's what I was asking for.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

<div class="moz-text-flowed" style="font-family: -moz-fixed">Mike Driscoll wrote:

It doesn't seem to have that feature...but Komodo does and it looks like I do have <crlf> line endings. I'll give Cody's Editra idea a try.

I hope that takes care of it for you then.

I did show the script in my first post. Or I should say, I linked to it: Porting wxPyMail to Linux - Mouse Vs Python

But I've attached it too so you can see the thing.

I've seen the python, but not the shell script -- that's what I was asking for.

-Chris

Oh...duh! I'm having one of those days today, I guess. Here's the contents of the shell script (minus the xml tags):

<script>

#!/bin/sh
echo "the open_mailto script ran!" > mailto.txt

/home/mike/Desktop/wxPyMail/wxPyMail.py

</script>

Mike