[wxPython] Bug? Undocumented requirement wxIcon for wxFrame.SetIcon( icon )

Just encountered a weird thing: When I attempt to use a wxIcon source other
than a .ico file (specifically a .png (8 or 24 bit) or .bmp (24 bit)), no
complaint is raised, but the icon doesn't show up. Using a .ico file with
the same contents does work. I'd prefer to let my users do their
customisations without requiring specialised .ico editors, so I'm wondering
if there's a way to get the .png's to work?

I'm on Win2000, wxPython is 2.2.5 if I recall correctly.

Icons are attached. Thoughts appreciated,
Mike

8<_______ test.py ________
from wxPython.wx import *
import os

class PreviewWindow(wxFrame ):
  def __init__( self, parent=NULL, id=-1, title="Preview"):
    wxFrame.__init__( self, parent, id, title )
    localDirectory = os.path.abspath(
      os.path.dirname(__file__)
    )
## DIAGRAMICON = wxIcon(
## os.path.join( localDirectory, 'previewicon.ico'),
## wxBITMAP_TYPE_ICO
## )
    DIAGRAMICON = wxIcon(
      os.path.join( localDirectory, 'previewicon.png'),
      wxBITMAP_TYPE_PNG
    )
    self.SetIcon( DIAGRAMICON )

if __name__ == "__main__":
  __file__ = '.'
  class DemoApp(wxApp):
    def OnInit(self):
      wxInitAllImageHandlers()
      frame = PreviewWindow(NULL)
      frame.Show(true)
      self.SetTopWindow(frame)
      return true

  def test( ):
    app = DemoApp(0)
    app.MainLoop()
  print 'Creating dialog'
  test( )

previewicon.ico

previewicon.png

···

__________________________________
Mike C. Fletcher
Designer, VR Plumber
http://members.home.com/mcfletch

Just encountered a weird thing: When I attempt to use a wxIcon source

other

than a .ico file (specifically a .png (8 or 24 bit) or .bmp (24 bit)), no
complaint is raised,

What does icon.Ok() return? I think XPMs are supported for wxIcon on
windows, you may want to try that format.

but the icon doesn't show up. Using a .ico file with
the same contents does work. I'd prefer to let my users do their
customisations without requiring specialised .ico editors, so I'm

wondering

if there's a way to get the .png's to work?

In 2.3.x you'll be able to do it this way and support any image type that
can be loaded into a wxBitmap:

            bmp = wxBitmap(...)
            icon = wxEmptyIcon()
            icon.CopyFromBitmap(bmp)

···

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

Hmm, Ok() returns 0. XPM is actually _harder_ to generate on windows boxes
(where this app runs) than is .ico. I think I'll just wait for 2.3.x for
that then (which, given that I'm done my contract in a month may mean it
never gets done).

Thanks,
Mike

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Friday, April 27, 2001 12:33
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Bug? Undocumented requirement wxIcon for
wxFrame.SetIcon( icon )
...
What does icon.Ok() return? I think XPMs are supported for wxIcon on
windows, you may want to try that format.
...
In 2.3.x you'll be able to do it this way and support any image type that
can be loaded into a wxBitmap:

            bmp = wxBitmap(...)
            icon = wxEmptyIcon()
            icon.CopyFromBitmap(bmp)
...

Hmm, Ok() returns 0. XPM is actually _harder_ to generate on windows

boxes

(where this app runs) than is .ico.

Yep. Unless you have this little tool. It's from 2.3.x so there may be
something in it that won't work on 2.2.5, but I don't think so... Oops yes
there is. The wxBitmapFromIcon function doesn't exist in 2.2.5, but you can
probably replace that line with something like this (only on wxMSW):

    img = wxEmptyBitmap()
    img.CopyFromIcon(icon)

BTW, this tool has a pal named img2py.py that can produce code like this:

def getSmilesData():
    return cPickle.loads(zlib.decompress(
'x\332}\320\275\012\0021\014\007\360\375\236"[o\372\323\200\334\003\270\270{
\
K\005\227r\336d!\342"\276\275\275\304~\210hhK\371\021\2226c\272\3610;\236(\
\257\035\261\033\342\354\350\354\231\027:\334\343\223\275W\202\321>\305\345\
\252\020\014NkJ\362P\021\223\343z\261"[
\344\000\266kA%\345\206\325r\024\354\
-\347\032Z9\333\371\374\215\370\304P\261/\3332K\233\277\231\024\252\242uW\
\020\300\032\225\037i\226\010\372\307\277\265|\276N\011\337\003Q\206\015N\
\021/\343\263l\217' ))

def getSmilesBitmap():
    return wxBitmapFromXPMData(getSmilesData())

def getSmilesImage():
    return wxImageFromBitmap(getSmilesBitmap())

Cool, eh?

···

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

begin 666 img2xpm.py
M(R$O=7-R+V)I;B]E;G8@<'ET:&]N#0HB(B(-"FEM9S)X<&TN<'D@("TM(&-O
M;G9E<G0@<V5V97)A;"!I;6%G92!F;W)M871S('1O(%A030T*#0I5<V%G93H-
M"@T*(" @(&EM9S)X<&TN<'D@6V]P=&EO;G-=(&EM86=E7V9I;&5S+BXN#0H-
M"D]P=&EO;G,Z#0H-"B @(" M;R \9&ER/B @(" @("!4:&4@9&ER96-T;W)Y
M('1O('!L86-E('1H92 N>'!M(&9I;&4H<RDL(&1E9F%U;'1S('1O#0H@(" @
M(" @(" @(" @(" @(" @=&AE(&-U<G)E;G0@9&ER96-T;W)Y+@T*#0H@(" @
M+6T@/"-R<F=G8F(^(" @268@=&AE(&]R:6=I;F%L(&EM86=E(&AA<R!A(&UA
M<VL@;W(@=')A;G-P87)E;F-Y(&1E9FEN960-"B @(" @(" @(" @(" @(" @
M("!I="!W:6QL(&)E('5S960@8GD@9&5F875L="X@(%EO=2!C86X@=7-E('1H
M:7,@;W!T:6]N('1O#0H@(" @(" @(" @(" @(" @(" @;W9E<G)I9&4@=&AE
M(&1E9F%U;'0@;W(@<')O=FED92!A(&YE=R!M87-K(&)Y('-P96-I9GEI;F<-
M"B @(" @(" @(" @(" @(" @("!A(&-O;&]U<B!I;B!T:&4@:6UA9V4@=&\@
M;6%R:R!A<R!T<F%N<W!A<F5N="X-"@T*(" @("UN(#QN86UE/B @(" @($$@
M9FEL96YA;64@=&\@=W)I=&4@=&AE("YX<&T@9&%T82!T;RX@($1E9F%U;'1S
M('1O('1H90T*(" @(" @(" @(" @(" @(" @(&)A<V5N86UE(&]F('1H92!I
M;6%G92!F:6QE("L@)RYX<&TG("!4:&ES(&]P=&EO;B!O=F5R<FED97,-"B @
M(" @(" @(" @(" @(" @("!T:&4@+6\@;W!T:6]N+@T*(B(B#0H-"@T*:6UP
M;W)T('-Y<RP@;W,L(&=L;V(L(&=E=&]P="P@<W1R:6YG#0IF<F]M('=X4'ET
M:&]N+G=X(&EM<&]R=" J#0H-"FEF('=X4&QA=&9O<FT@/3T@(E]?5UA'5$M?
M7R(Z#0H@(" @<F%I<V4@4WES=&5M17AI="P@(E1H:7,@=&]O;"!C86X@;F]T
M(&)E('5S960@;VX@=WA'5$L@=6YT:6P@=WA'5$L@8V%N('-A=F4@6%!-(&9I
M;&5S+B(-"@T*=WA);FET06QL26UA9V5(86YD;&5R<R@I#0H-"@T*9&5F(&-O
M;G9E<G0H9FEL92P@;6%S:T-L<BP@;W5T<'5T1&ER+"!O=71P=71.86UE*3H-
M"B @("!I9B!S=')I;F<N;&]W97(H;W,N<&%T:"YS<&QI=&5X="AF:6QE*5LQ
M72D@/3T@(BYI8V\B.@T*(" @(" @("!I8V]N(#T@=WA)8V]N*&9I;&4L('=X
M0DE434%07U194$5?24-/*0T*(" @(" @("!I;6<@/2!W>$)I=&UA<$9R;VU)
M8V]N*&EC;VXI#0H@(" @96QS93H-"B @(" @(" @:6UG(#T@=WA":71M87 H
M9FEL92P@=WA"251-05!?5%E015]!3EDI#0H-"B @("!I9B!N;W0@:6UG+D]K
M*"DZ#0H@(" @(" @(')E='5R;B P+"!F:6QE("L@(B!F86EL960@=&\@;&]A
M9"$B#0H@(" @96QS93H-"B @(" @(" @:68@;6%S:T-L<CH-"B @(" @(" @
M(" @(&]M(#T@:6UG+D=E=$UA<VLH*0T*(" @(" @(" @(" @;6%S:R ]('=X
M36%S:T-O;&]U<BAI;6<L(&UA<VM#;'(I#0H@(" @(" @(" @("!I;6<N4V5T
M36%S:RAM87-K*0T*(" @(" @(" @(" @:68@;VT@:7,@;F]T($YO;F4Z#0H@
M(" @(" @(" @(" @(" @;VTN1&5S=')O>2@I#0H@(" @(" @(&EF(&]U='!U
M=$YA;64Z#0H@(" @(" @(" @("!N97=N86UE(#T@;W5T<'5T3F%M90T*(" @
M(" @("!E;'-E.@T*(" @(" @(" @(" @;F5W;F%M92 ](&]S+G!A=&@N:F]I
M;BAO=71P=71$:7(L(&]S+G!A=&@N8F%S96YA;64H;W,N<&%T:"YS<&QI=&5X
M="AF:6QE*5LP72D@*R B+GAP;2(I#0H@(" @(" @(&EF(&EM9RY3879E1FEL
M92AN97=N86UE+"!W>$))5$U!4%]465!%7UA032DZ#0H@(" @(" @(" @("!R
M971U<FX@,2P@9FEL92 K("(@8V]N=F5R=&5D('1O("(@*R!N97=N86UE#0H@
M(" @(" @(&5L<V4Z#0H@(" @(" @(" @("!I;6<@/2!W>$EM86=E1G)O;4)I
M=&UA<"AI;6<I#0H@(" @(" @(" @("!I9B!I;6<N4V%V949I;&4H;F5W;F%M
M92P@=WA"251-05!?5%E015]84$TI.@T*(" @(" @(" @(" @(" @(')E='5R
M;B Q+" B;VLB#0H@(" @(" @(" @("!E;'-E.@T*(" @(" @(" @(" @(" @
M(')E='5R;B P+"!F:6QE("L@(B!F86EL960@=&\@<V%V92$B#0H-"@T*#0ID
M968@;6%I;BAA<F=S*3H-"B @("!I9B!N;W0@87)G<R!O<B H(BUH(B!I;B!A
M<F=S*3H-"B @(" @(" @<')I;G0@7U]D;V-?7PT*(" @(" @("!R971U<FX-
M"@T*(" @(&]U='!U=$1I<B ]("(B#0H@(" @;6%S:T-L<B ]($YO;F4-"B @
M("!O=71P=71.86UE(#T@3F]N90T*#0H@(" @=')Y.@T*(" @(" @("!O<'1S
M+"!F:6QE07)G<R ](&=E=&]P="YG971O<'0H87)G<RP@(FTZ;CIO.B(I#0H@
M(" @97AC97!T(&=E=&]P="Y'971O<'1%<G)O<CH-"B @(" @(" @<')I;G0@
M7U]D;V-?7PT*(" @(" @("!R971U<FX-"@T*(" @(&9O<B!O<'0L('9A;"!I
M;B!O<'1S.@T*(" @(" @("!I9B!O<'0@/3T@(BUM(CH-"B @(" @(" @(" @
M(&UA<VM#;'(@/2!V86P-"B @(" @(" @96QI9B!O<'0@/3T@(BUN(CH-"B @
M(" @(" @(" @(&]U='!U=$YA;64@/2!V86P-"B @(" @(" @96QI9B!O<'0@
M/3T@(BUO(CH-"B @(" @(" @(" @(&]U='!U=$1I<B ]('9A; T*#0H@(" @
M:68@;F]T(&9I;&5!<F=S.@T*(" @(" @("!P<FEN="!?7V1O8U]?#0H@(" @
M(" @(')E='5R;@T*#0H@(" @9F]R(&%R9R!I;B!F:6QE07)G<SH-"B @(" @
M(" @9F]R(&9I;&4@:6X@9VQO8BYG;&]B*&%R9RDZ#0H@(" @(" @(" @("!I
M9B!N;W0@;W,N<&%T:"YI<V9I;&4H9FEL92DZ#0H@(" @(" @(" @(" @(" @
M8V]N=&EN=64-"B @(" @(" @(" @(&]K+"!M<V<@/2!C;VYV97)T*&9I;&4L
M(&UA<VM#;'(L(&]U='!U=$1I<BP@;W5T<'5T3F%M92D-"B @(" @(" @(" @
M('!R:6YT(&US9PT*#0H-"@T*:68@7U]N86UE7U\@/3T@(E]?;6%I;E]?(CH-
M"B @("!I9B!W>%!L871F;W)M(#T](")?7U=81U1+7U\B.@T*(" @(" @("!A
M<' @/2!W>%!Y4VEM<&QE07!P*"D@(" @(",@0FQE8V@A("!T:&4@1U5)(&YE
M961S(&EN:71I86QI>F5D(&)E9F]R90T*(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(",@8FET;6%P<R!C86X@8F4@8W)E871E9"XN+@T*(" @
9(&UA:6XH<WES+F%R9W9;,3I=*0T*#0H-"@``
`
end

Finally got a chance to try this out. Seems to work (doesn't complain when
converting an icon), but attempts to use the resulting xpms result in icons
that report Ok() == false . For the record, the changes to work with 2.2.5
were:

def convert(file, maskClr, outputDir, outputName):
    if string.lower(os.path.splitext(file)[1]) == ".ico":
        icon = wxIcon(file, wxBITMAP_TYPE_ICO)
        img = wxEmptyBitmap(icon.GetWidth(), icon.GetHeight())
        img.CopyFromIcon(icon)
    else:
        img = wxBitmap(file, wxBITMAP_TYPE_ANY)
    ...

Eliminating the resource problem is definitely cool though.

Enjoy,
Mike

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Friday, April 27, 2001 13:21
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Bug? Undocumented requirement wxIcon for
wxFrame.SetIcon( icon )

Hmm, Ok() returns 0. XPM is actually _harder_ to generate on windows

boxes

(where this app runs) than is .ico.

Yep. Unless you have this little tool. It's from 2.3.x so there may be
something in it that won't work on 2.2.5, but I don't think so... Oops yes
there is. The wxBitmapFromIcon function doesn't exist in 2.2.5, but you can
probably replace that line with something like this (only on wxMSW):
...
<partner tool description>
...
Cool, eh?
...