SetIcon strangeness

In Win XP (SP2, Python 2.5.2, wxPython 2.8.? - latest version)

If try this:

try:

window.SetIcon(‘path/to/icon.ico’)

finally:

pass

AND the icon does not exist, I get a pop up window

Python Error

Failed to load icon from file ‘path/to/icon.ico’ (error 2: the system ca not find the file specified)

No exceptions are raised (e.g. the try/execpt does not catch it).

Am I doing something wrong? This does not seem very pythonic.

I just ditched the try/catch and used os.path.exists() to see if the file exists.

I looked at the wx.Python docs (new and old) and wx.Widgets docs, but could not really find any detailed information. I also looked things up in wxPython in Action, to no avail.

So, where do people in the know really find details about wx.Python programming? I find myself digging though the wx Demo code and hoping there is something there that is close what I’m trying to do. If not, I try google and code searches. If I can’t find an example, the docs never seem to help me. I must be missing somthing.

Ok, I understand that: I should use except, not finally (in fact, I
think I did that at first). However, even if I add the except, I
don't think it will mater -- I'm see no execptions thrown -- I'll try
later to verify this.

···

On Tue, Jun 3, 2008 at 1:25 PM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Kevin Grover wrote:

In Win XP (SP2, Python 2.5.2, wxPython 2.8.? - latest version)
If try this:
try:
   window.SetIcon('path/to/icon.ico')
finally:
   pass
AND the icon does not exist, I get a pop up window
Python Error
Failed to load icon from file 'path/to/icon.ico' (error 2: the system ca not find the file specified)
No exceptions are raised (e.g. the try/execpt does not catch it).
Am I doing something wrong? This does not seem very pythonic.
I just ditched the try/catch and used os.path.exists() to see if the file exists.
I looked at the wx.Python docs (new and old) and wx.Widgets docs, but could not really find any detailed information. I also looked things up in wxPython in Action, to no avail.
So, where do people in the _know_ really find details about wx.Python programming? I find myself digging though the wx Demo code and hoping there is something there that is close what I'm trying to do. If not, I try google and code searches. If I can't find an example, the docs never seem to help me. I must be missing somthing.

I think you want to use a try/except, NOT a try/finally. The try/finally won't catch the exception, it will only make sure that pass is called, so-to-speak. See also:

http://docs.python.org/ref/try.html
http://www.diveintopython.org/file_handling/index.html
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Kevin Grover wrote:

···

On Tue, Jun 3, 2008 at 1:31 PM, Kevin Grover <kevin@kevingrover.net> wrote:
  

On Tue, Jun 3, 2008 at 1:25 PM, Mike Driscoll <mike@pythonlibrary.org> wrote:
    

Kevin Grover wrote:
      

In Win XP (SP2, Python 2.5.2, wxPython 2.8.? - latest version)
If try this:
try:
   window.SetIcon('path/to/icon.ico')
finally:
   pass
AND the icon does not exist, I get a pop up window
Python Error
Failed to load icon from file 'path/to/icon.ico' (error 2: the system ca not find the file specified)
No exceptions are raised (e.g. the try/execpt does not catch it).
Am I doing something wrong? This does not seem very pythonic.
I just ditched the try/catch and used os.path.exists() to see if the file exists.
I looked at the wx.Python docs (new and old) and wx.Widgets docs, but could not really find any detailed information. I also looked things up in wxPython in Action, to no avail.
So, where do people in the _know_ really find details about wx.Python programming? I find myself digging though the wx Demo code and hoping there is something there that is close what I'm trying to do. If not, I try google and code searches. If I can't find an example, the docs never seem to help me. I must be missing somthing.
        

I think you want to use a try/except, NOT a try/finally. The try/finally won't catch the exception, it will only make sure that pass is called, so-to-speak. See also:

http://docs.python.org/ref/try.html
http://www.diveintopython.org/file_handling/index.html
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
      

Ok, I understand that: I should use except, not finally (in fact, I
think I did that at first). However, even if I add the except, I
don't think it will mater -- I'm see no execptions thrown -- I'll try
later to verify this.

I confirmed the behavior. On Windows, no exception is throw, but the
popup window occurs:. This is the exact code:

    try:
        window.SetIcon(wx.Icon(icon_file, icon_type))
    except:
        pass

On Linux, there is no problem. With or without the try no exception
is thrown and there is no pop-up dialog.

Like I said, I can work around it. It just seems strange so I assumed
I was doing something wrong.

- Kevin

You are correct. I see the same behavior on Windows Vista. I think I noticed this last year when I first started messing with SetIcon and ended up just using img2py so I could embed the icon in Python code rather than relying on nebulous path names., It's not great, but it works.

Mike