Fake LCD screen, overlaying onto bitmap, using wxglade

56 views
Skip to first unread message

Brendan Simon

unread,
May 21, 2017, 12:46:37 AM5/21/17
to wxPython-users
I've created a custom control that fakes an LCD screen by creating a grid of sizers containing StaticTextCtrl objects.

Now I want to get funky and overlay this onto a bitmap, which gives the appearance of a real appliance I'm trying to visualise to the user.

What is the best way to do that with wxPython (using wxPython 4.0.0a and Python3.6)?

NOTE: I'm using lots of wx sizers via wxglade for the gui layout of the app !!

Are there any good examples of overlaying wx widgets over bitmaps?

Can such an overlay be accomplished with wxglade, or do I have to create a custom control which does all the work and just insert this custom control as any other widget?

I'm using PNG for the bitmap image.  If I want the control/graphics to scale with sizers, I guess I would need a scalable image format (presumably SVG).

What is the best way to render svg images.  It doesn't seem to have standard support in wxPython.  Is the `pyWxSVG` modules the answer?

Thanks,
Brendan.

Andrea Gavana

unread,
May 21, 2017, 1:09:39 AM5/21/17
to wxpytho...@googlegroups.com
Hi,

If your layout is not awfully complex, I would strongly suggest to abandon sizers and statictexts in favor of a fully owner-drawn custom control. This will give you freedom of putting whatever image you want as background and avoid the statictexts background color to show - as all your texts will be drawn via dc.DrawText.

I've never tried wxpysvg, best way to see how it works is actually download it and get your hands dirty with it :-)

Andrea.




--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karsten Hilbert

unread,
May 21, 2017, 5:25:29 AM5/21/17
to wxPython-users
On Sun, May 21, 2017 at 02:46:29PM +1000, Brendan Simon wrote:

> I've created a custom control that fakes an LCD screen by creating a
> grid of sizers containing StaticTextCtrl objects.

Any particular reason you aren't using a gridsizer ?

Karsten

Dietmar Schwertberger

unread,
May 21, 2017, 9:47:56 AM5/21/17
to wxpytho...@googlegroups.com
Hi Brendan!


On 5/21/17 6:46 AM, Brendan Simon wrote:
Can such an overlay be accomplished with wxglade, or do I have to create a custom control which does all the work and just insert this custom control as any other widget?
I think you need to create the custom control. wxglade is more for "standard" things.



I'm using PNG for the bitmap image.  If I want the control/graphics to scale with sizers, I guess I would need a scalable image format (presumably SVG).
The custom control may just be a (scrolled) panel and you would handle the EVT_PAINT by painting the background. Scaling could be done using PIL.

Regards,
Dietmar

Brendan Simon

unread,
May 22, 2017, 8:44:30 AM5/22/17
to wxPython-users, wxPytho...@googlegroups.com

I'm fairly sure I am using gridsizer (via the wx sized control) :)

import wx
import wx.lib.sized_controls as wxSC

class wxLCD(wxSC.SizedPanel):
   
def __init__(self, parent, cols=COLS_DEFAULT, rows=ROWS_DEFAULT, font_size=FONT_SIZE, font_family=FONT_FAMILY, font_style=FONT_STYLE, font_weight=FONT_WEIGHT):
        wxSC
.SizedPanel.__init__(self, parent)

       
self.cols = cols
       
self.rows = rows

        pane
= self
        pane
.SetSizerType("grid", {'cols':self.cols, 'rows':self.rows})

Since I'm also experimenting with wxglade, I might rewrite the code to use normal sizers via wxglade ;-)

Or as others have suggested an owner drawn custom control may well be the way to go.

Brendan Simon

unread,
May 29, 2017, 8:35:45 AM5/29/17
to wxPython-users, wxPytho...@googlegroups.com, Bre...@brendansimon.com
Google threw up this as a possibility, which uses EVT_ERASE_BACKGROUND to repaint a bitmap and other widgets on top (e.g. buttons).

https://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/

This could possibly work for what I want?

I also saw wx.Overlay.  Is this also a possibility?  I'm thinking the bitmap on the control and the overlay would have controls.  Would that work?

I tried the wx.Overlay demo (on Mac Sierra, python 3.6, wxPhoenix 4.0.0a2) but it seems broken.  Every time I click the contents seem to magnify (zoom in).  Anyone else experience that?
Reply all
Reply to author
Forward
0 new messages