Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 8th, 2008, 10:42 AM   #1
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Question Set application Icon wxPython

Anyone knows how to set the application icon for a wxPython app? I have some leads about the wx.Frame.SetIcon() function, but how do I load the icon from a .ico or .bmp file into my program?
OpenLoop is offline   Reply With Quote
Old Mar 8th, 2008, 12:31 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Set application Icon wxPython

There's a wxBitmap function. Check the alphabetical class reference in the docs. I'll look for the exact code when I get home.
Sane is offline   Reply With Quote
Old Mar 8th, 2008, 1:57 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Set application Icon wxPython

I believe there are multiple ways to do it, including the wxBitmap way. But the easiest way is with wxIcon.

Here, wx.BITMAP_TYPE_ICO specifies that the file is .ico. I've found that no other format will handle transparency very well (including PNG) for application icons.

class myApp(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, None,
            pos=wx.DefaultPosition, size=wx.Size(548, 438),
            style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN, 
            title="My Application")

        favicon = wx.Icon('favicon.ico', wx.BITMAP_TYPE_ICO, 16, 16)
        wx.Frame.SetIcon(self, favicon)

Edit: And here's the Alphabetical Class Reference. Perhaps the most useful thing out there for wxWidgets and wxPython.
Sane is offline   Reply With Quote
Old Mar 8th, 2008, 2:30 PM   #4
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: Set application Icon wxPython

Works great. I was going about it the wrong way trying to self.SetIcon() on on the frame class since I couldn't find decent references for this specific issue under wxPython documentations. I really miss the F1 in C# & MSDN when working with python. Thanks for the help.
OpenLoop is offline   Reply With Quote
Old Mar 9th, 2008, 5:10 PM   #5
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Set application Icon wxPython

I am pretty sure those last two lines can be written like this as well (notice the self.SetIcon()):
python Syntax (Toggle Plain Text)
  1. favicon = wx.Icon('favicon.ico', wx.BITMAP_TYPE_ICO, 16, 16)
  2. self.SetIcon(favicon)
All that other code was doing was invoking an unbound member function and passing it the object to work with.
__________________
Robotics @ Maryland AUV Team - Software Lead
Game_Ender is offline   Reply With Quote
Old Mar 9th, 2008, 5:46 PM   #6
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: Set application Icon wxPython

I tried that and it seems to work... I was calling self.SetIcon(self, favicon) and it complained about the arguments but my real issue was reading the icon from a file.

I really don't understand the 'self' keyword. I try to think of it as 'this' in C++, but why does every function of a class has to have it as first argument in the definition, but then when you call it you have to omit the first argument? It's just a confusing way to do things!

Back to the icon issue, this is unrelated but if anyone out there is looking for a way to set the icon of an exe file when using py2exe, here's how your setup.py should look like:
PYTHON Syntax (Toggle Plain Text)
  1. from distutils.core import setup
  2. import py2exe
  3.  
  4. setup(
  5. windows = [
  6. {
  7. "script": "Datetool.pyw",
  8. "icon_resources": [(1, "icon.ico")]
  9. }
  10. ],
  11. )
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PC application with bluetooth urip Java 5 Feb 13th, 2008 12:15 PM
PFO URL icon mrynit Community Announcements and Feedback 3 Nov 21st, 2007 5:09 PM
creating an application that stands between the browser and the serve ronias Visual Basic 5 Oct 30th, 2005 4:22 PM
"Not Responding" Message in Windows Form Application G_Zola C# 1 Apr 29th, 2005 10:15 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:30 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC