wxPython demo questions

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

wxPython demo questions

Virgil Stokes
I have been studying the wxPython demos (wxPython2.8-win32-docs-demos) which is
very impressive and I have found them very useful for learning wxPython.

I have two questions:

1. The AboutBox demo --- how does one get the Python icon (upper left corner)? I
have extracted the code for this demo and when I execute it the little green
python (Python icon) does not display and further, I can find no direct
reference to an image (bitmap) in the code.

2. The StatusBar demo --- how does one change the color and background of parts
of the text displayed?  For example, I would like the year (2012) to be
displayed in RED on a GREEN background.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Robin Dunn
On 3/26/12 10:00 AM, Virgil Stokes wrote:

> I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
> which is very impressive and I have found them very useful for learning
> wxPython.
>
> I have two questions:
>
> 1. The AboutBox demo --- how does one get the Python icon (upper left
> corner)? I have extracted the code for this demo and when I execute it
> the little green python (Python icon) does not display and further, I
> can find no direct reference to an image (bitmap) in the code.

By default it will use the icon of the application's "top" window, if it
has one.  You can use a different icon if desired by calling info.SetIcon.

>
> 2. The StatusBar demo --- how does one change the color and background
> of parts of the text displayed? For example, I would like the year
> (2012) to be displayed in RED on a GREEN background.

The status bar doesn't have built-in support for doing this, but you can
do it yourself either by putting static text widgets on the statusbar
(you'll have to manage their size and position so they appear to lie
withing one of the statusbar's fields) or you can catch its paint event
and draw the text yourself.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
On 26-Mar-2012 19:23, Robin Dunn wrote:

> On 3/26/12 10:00 AM, Virgil Stokes wrote:
>> I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
>> which is very impressive and I have found them very useful for learning
>> wxPython.
>>
>> I have two questions:
>>
>> 1. The AboutBox demo --- how does one get the Python icon (upper left
>> corner)? I have extracted the code for this demo and when I execute it
>> the little green python (Python icon) does not display and further, I
>> can find no direct reference to an image (bitmap) in the code.
>
> By default it will use the icon of the application's "top" window, if it has
> one.  You can use a different icon if desired by calling info.SetIcon.
Ok, thanks.  I will now try to track down this "top" window icon.

>
>>
>> 2. The StatusBar demo --- how does one change the color and background
>> of parts of the text displayed? For example, I would like the year
>> (2012) to be displayed in RED on a GREEN background.
>
> The status bar doesn't have built-in support for doing this, but you can do it
> yourself either by putting static text widgets on the statusbar (you'll have
> to manage their size and position so they appear to lie withing one of the
> statusbar's fields) or you can catch its paint event and draw the text yourself.
I would like to try your 2nd suggestion --- catch its paint event. Would you
please elaborate a little on how to perform this "catch" for the status bar when
the paint event fires?

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Robin Dunn
On 3/26/12 10:49 AM, Virgil Stokes wrote:

> On 26-Mar-2012 19:23, Robin Dunn wrote:
>> On 3/26/12 10:00 AM, Virgil Stokes wrote:
>>> I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
>>> which is very impressive and I have found them very useful for learning
>>> wxPython.
>>>
>>> I have two questions:
>>>
>>> 1. The AboutBox demo --- how does one get the Python icon (upper left
>>> corner)? I have extracted the code for this demo and when I execute it
>>> the little green python (Python icon) does not display and further, I
>>> can find no direct reference to an image (bitmap) in the code.
>>
>> By default it will use the icon of the application's "top" window, if
>> it has one. You can use a different icon if desired by calling
>> info.SetIcon.
> Ok, thanks. I will now try to track down this "top" window icon.

It is either the frame passed to theApp.SetTopWindow if you called it,
otherwise it is the first top-level window (frame or dialog) created
that still exists.

>>
>>>
>>> 2. The StatusBar demo --- how does one change the color and background
>>> of parts of the text displayed? For example, I would like the year
>>> (2012) to be displayed in RED on a GREEN background.
>>
>> The status bar doesn't have built-in support for doing this, but you
>> can do it yourself either by putting static text widgets on the
>> statusbar (you'll have to manage their size and position so they
>> appear to lie withing one of the statusbar's fields) or you can catch
>> its paint event and draw the text yourself.
> I would like to try your 2nd suggestion --- catch its paint event. Would
> you please elaborate a little on how to perform this "catch" for the
> status bar when the paint event fires?

Bind a handler for the statusbar's EVT_PAINT event and in the handler
create a wx.PaintDC and use it to DrawText where and how you want it.
You can use the statusbar's GetFieldRect to get a rectangle defining the
position and size of the field you want to draw yourself.  There are
several examples in the demo of implementing handlers for EVT_PAINT.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
On 2012-03-26 20:06, Robin Dunn wrote:

> On 3/26/12 10:49 AM, Virgil Stokes wrote:
>> On 26-Mar-2012 19:23, Robin Dunn wrote:
>>> On 3/26/12 10:00 AM, Virgil Stokes wrote:
>>>> I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
>>>> which is very impressive and I have found them very useful for
>>>> learning
>>>> wxPython.
>>>>
>>>> I have two questions:
>>>>
>>>> 1. The AboutBox demo --- how does one get the Python icon (upper left
>>>> corner)? I have extracted the code for this demo and when I execute it
>>>> the little green python (Python icon) does not display and further, I
>>>> can find no direct reference to an image (bitmap) in the code.
>>>
>>> By default it will use the icon of the application's "top" window, if
>>> it has one. You can use a different icon if desired by calling
>>> info.SetIcon.
>> Ok, thanks. I will now try to track down this "top" window icon.
>
> It is either the frame passed to theApp.SetTopWindow if you called it,
> otherwise it is the first top-level window (frame or dialog) created
> that still exists.
Ummh.... I will see what I can find.

>
>>>
>>>>
>>>> 2. The StatusBar demo --- how does one change the color and background
>>>> of parts of the text displayed? For example, I would like the year
>>>> (2012) to be displayed in RED on a GREEN background.
>>>
>>> The status bar doesn't have built-in support for doing this, but you
>>> can do it yourself either by putting static text widgets on the
>>> statusbar (you'll have to manage their size and position so they
>>> appear to lie withing one of the statusbar's fields) or you can catch
>>> its paint event and draw the text yourself.
>> I would like to try your 2nd suggestion --- catch its paint event. Would
>> you please elaborate a little on how to perform this "catch" for the
>> status bar when the paint event fires?
>
> Bind a handler for the statusbar's EVT_PAINT event and in the handler
> create a wx.PaintDC and use it to DrawText where and how you want it.
> You can use the statusbar's GetFieldRect to get a rectangle defining
> the position and size of the field you want to draw yourself.  There
> are several examples in the demo of implementing handlers for EVT_PAINT.
Thanks Robin.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
In reply to this post by Robin Dunn
On 2012-03-26 20:06, Robin Dunn wrote:

> On 3/26/12 10:49 AM, Virgil Stokes wrote:
>> On 26-Mar-2012 19:23, Robin Dunn wrote:
>>> On 3/26/12 10:00 AM, Virgil Stokes wrote:
>>>> I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
>>>> which is very impressive and I have found them very useful for
>>>> learning
>>>> wxPython.
>>>>
>>>> I have two questions:
>>>>
>>>> 1. The AboutBox demo --- how does one get the Python icon (upper left
>>>> corner)? I have extracted the code for this demo and when I execute it
>>>> the little green python (Python icon) does not display and further, I
>>>> can find no direct reference to an image (bitmap) in the code.
>>>
>>> By default it will use the icon of the application's "top" window, if
>>> it has one. You can use a different icon if desired by calling
>>> info.SetIcon.
>> Ok, thanks. I will now try to track down this "top" window icon.
>
> It is either the frame passed to theApp.SetTopWindow if you called it,
> otherwise it is the first top-level window (frame or dialog) created
> that still exists.
I tracked the icon down to be LB04.png and tried the following,

def OnButton(self, evt):
         # First we create and fill the info object
         info = wx.AboutDialogInfo()
         info.SetIcon("LB04.png")
         info.Name = "Hello World"
         info.Version = "1.2.3"
         ...

which gave the following error

TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of
type 'wxIcon const &'

Any suggestions as how to correct this?

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
C M
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

C M


On Mon, Mar 26, 2012 at 4:26 PM, Virgil Stokes <[hidden email]> wrote:
On 2012-03-26 20:06, Robin Dunn wrote:
On 3/26/12 10:49 AM, Virgil Stokes wrote:
On 26-Mar-2012 19:23, Robin Dunn wrote:
On 3/26/12 10:00 AM, Virgil Stokes wrote:
I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
which is very impressive and I have found them very useful for learning
wxPython.

I have two questions:

1. The AboutBox demo --- how does one get the Python icon (upper left
corner)? I have extracted the code for this demo and when I execute it
the little green python (Python icon) does not display and further, I
can find no direct reference to an image (bitmap) in the code.

By default it will use the icon of the application's "top" window, if
it has one. You can use a different icon if desired by calling
info.SetIcon.
Ok, thanks. I will now try to track down this "top" window icon.

It is either the frame passed to theApp.SetTopWindow if you called it, otherwise it is the first top-level window (frame or dialog) created that still exists.
I tracked the icon down to be LB04.png and tried the following,

It is not a matter of tracking the icon down...it is just using whatever icon was provided to the main frame (or other top-level window) in the Demo's code.

Instead, what you need to do is:

1) Choose an icon you'd like to use.
2) Get the .ico file. / save it on your computer to a folder, like "myGraphicsFolder"
3) Set it:

info.SetIcon(wx.Icon(u'C:/mycode/myGraphicsFolder/happyface_icon.ico', wx.BITMAP_TYPE_ICO))

You're done.

I recommend, though, using img2py to turn the image into Python code so you don't have to worry about paths to a specific file.  Google for more on that topic.

Che

 

def OnButton(self, evt):
       # First we create and fill the info object
       info = wx.AboutDialogInfo()
       info.SetIcon("LB04.png")
       info.Name = "Hello World"
       info.Version = "1.2.3"
       ...

which gave the following error

TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Any suggestions as how to correct this?


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
On 2012-03-26 22:32, C M wrote:


On Mon, Mar 26, 2012 at 4:26 PM, Virgil Stokes <[hidden email]> wrote:
On 2012-03-26 20:06, Robin Dunn wrote:
On 3/26/12 10:49 AM, Virgil Stokes wrote:
On 26-Mar-2012 19:23, Robin Dunn wrote:
On 3/26/12 10:00 AM, Virgil Stokes wrote:
I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
which is very impressive and I have found them very useful for learning
wxPython.

I have two questions:

1. The AboutBox demo --- how does one get the Python icon (upper left
corner)? I have extracted the code for this demo and when I execute it
the little green python (Python icon) does not display and further, I
can find no direct reference to an image (bitmap) in the code.

By default it will use the icon of the application's "top" window, if
it has one. You can use a different icon if desired by calling
info.SetIcon.
Ok, thanks. I will now try to track down this "top" window icon.

It is either the frame passed to theApp.SetTopWindow if you called it, otherwise it is the first top-level window (frame or dialog) created that still exists.
I tracked the icon down to be LB04.png and tried the following,

It is not a matter of tracking the icon down...it is just using whatever icon was provided to the main frame (or other top-level window) in the Demo's code.

Instead, what you need to do is:

1) Choose an icon you'd like to use.
2) Get the .ico file. / save it on your computer to a folder, like "myGraphicsFolder"
3) Set it:

info.SetIcon(wx.Icon(u'C:/mycode/myGraphicsFolder/happyface_icon.ico', wx.BITMAP_TYPE_ICO))

You're done.

I recommend, though, using img2py to turn the image into Python code so you don't have to worry about paths to a specific file.  Google for more on that topic.

Che

 

def OnButton(self, evt):
       # First we create and fill the info object
       info = wx.AboutDialogInfo()
       info.SetIcon("LB04.png")
       info.Name = "Hello World"
       info.Version = "1.2.3"
       ...

which gave the following error

TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Any suggestions as how to correct this?


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
I had an error in my previous email on this subject, it should have been,

def OnButton(self, evt):
        # First we create and fill the info object
        info = wx.AboutDialogInfo()
        info.SetIcon("wxpdemo.ico")
        info.Name = "Hello World"
        info.Version = "1.2.3"

                ....

But, this gives the same error,

        TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
C M
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

C M
info.SetIcon("wxpdemo.ico")
But, this gives the same error,
 
        TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Right.  It's saying it expected a wxIcon.  You need to "cast"* the .ico file to that by using

wx.Icon(your_icon.ico', wx.BITMAP_TYPE_ICO)

See my previous answer for the full answer.

(*Not sure if that is the right way to think about it, but you get the point)

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Tim Roberts
In reply to this post by Virgil Stokes
Virgil Stokes wrote:
I had an error in my previous email on this subject, it should have been,

def OnButton(self, evt):
        # First we create and fill the info object
        info = wx.AboutDialogInfo()
        info.SetIcon("wxpdemo.ico")
        info.Name = "Hello World"
        info.Version = "1.2.3"

                ....

But, this gives the same error,

        TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Of course it does.  That's because you're still not reading what he suggested.  You can't pass a string to SetIcon.  As the error says, you have to pass a wx.Icon.  Fortunately, wx.Icon has a constructor that accepts a file name:

    info.SetIcon( wx.Icon("wxpdemo.ico", wx.BITMAP_TYPE_ICO))
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
In reply to this post by C M
On 2012-03-26 22:32, C M wrote:


On Mon, Mar 26, 2012 at 4:26 PM, Virgil Stokes <[hidden email]> wrote:
On 2012-03-26 20:06, Robin Dunn wrote:
On 3/26/12 10:49 AM, Virgil Stokes wrote:
On 26-Mar-2012 19:23, Robin Dunn wrote:
On 3/26/12 10:00 AM, Virgil Stokes wrote:
I have been studying the wxPython demos (wxPython2.8-win32-docs-demos)
which is very impressive and I have found them very useful for learning
wxPython.

I have two questions:

1. The AboutBox demo --- how does one get the Python icon (upper left
corner)? I have extracted the code for this demo and when I execute it
the little green python (Python icon) does not display and further, I
can find no direct reference to an image (bitmap) in the code.

By default it will use the icon of the application's "top" window, if
it has one. You can use a different icon if desired by calling
info.SetIcon.
Ok, thanks. I will now try to track down this "top" window icon.

It is either the frame passed to theApp.SetTopWindow if you called it, otherwise it is the first top-level window (frame or dialog) created that still exists.
I tracked the icon down to be LB04.png and tried the following,

It is not a matter of tracking the icon down...it is just using whatever icon was provided to the main frame (or other top-level window) in the Demo's code.

Instead, what you need to do is:

1) Choose an icon you'd like to use.
2) Get the .ico file. / save it on your computer to a folder, like "myGraphicsFolder"
3) Set it:

info.SetIcon(wx.Icon(u'C:/mycode/myGraphicsFolder/happyface_icon.ico', wx.BITMAP_TYPE_ICO))

You're done.

I recommend, though, using img2py to turn the image into Python code so you don't have to worry about paths to a specific file.  Google for more on that topic.

Che

 

def OnButton(self, evt):
       # First we create and fill the info object
       info = wx.AboutDialogInfo()
       info.SetIcon("LB04.png")
       info.Name = "Hello World"
       info.Version = "1.2.3"
       ...

which gave the following error

TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Any suggestions as how to correct this?


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Thanks C M,
The following works as per your suggestion,

def OnButton(self, evt):
        # First we create and fill the info object
        info = wx.AboutDialogInfo()       
        info.SetIcon(wx.Icon('wxpdemo.ico', wx.BITMAP_TYPE_ICO))
        info.Name = "Hello World"
        info.Version = "1.2.3"

                ...

I did look at the WWW wxPython documentation on AboutDialogInfo before posting this problem; but, your solution was not obvious from the documentation (http://www.wxpython.org/docs/api/wx.AboutDialogInfo-class.html#SetIcon).

Thanks again :-)

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: wxPython demo questions

Virgil Stokes
In reply to this post by Tim Roberts
On 2012-03-26 22:50, Tim Roberts wrote:
Virgil Stokes wrote:
I had an error in my previous email on this subject, it should have been,

def OnButton(self, evt):
        # First we create and fill the info object
        info = wx.AboutDialogInfo()
        info.SetIcon("wxpdemo.ico")
        info.Name = "Hello World"
        info.Version = "1.2.3"

                ....

But, this gives the same error,

        TypeError: in method 'AboutDialogInfo_SetIcon', expected argument 2 of type 'wxIcon const &'

Of course it does.  That's because you're still not reading what he suggested.  You can't pass a string to SetIcon.  As the error says, you have to pass a wx.Icon.  Fortunately, wx.Icon has a constructor that accepts a file name:

    info.SetIcon( wx.Icon("wxpdemo.ico", wx.BITMAP_TYPE_ICO))
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.
--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
You are correct Tim,
But I did read the documentation and the error --- just could not understand them.  Hopefully, with time and more experience with wxPython, I will be able to better understand wxPyton error messages and the API documentation.


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en