PrintFramework print preview has black background under Linux

When bringing up the print preview in the wxdemo under Linux (Ubuntu 18.04), the background is black. It should be white (like it is on Mac and Windows) - not black.

The only way I’ve thought of mitigating this effect is to draw a white rectangle onto the dc before I draw my own stuff. Viz:

def OnPrintPage(self, page):

            dc = self.GetDC()

-------------------------------------------

One possible method of setting scaling factors…

canvasMaxX = self.canvas.GetSize()[0]

canvasMaxY = self.canvas.GetSize()[1]

canvasMaxX, canvasMaxY = self._fit_diagram_to_paper(canvasMaxX, canvasMaxY)

Let’s have at least 50 device units margin

marginX = 50

marginY = 50

Add the margin to the graphic size

maxX = canvasMaxX + (2 * marginX)

maxY = canvasMaxY + (2 * marginY)

Get the size of the DC in pixels

(w, h) = dc.GetSize() # was GetSizeTuple() in classic wxpython

if “wxGTK” in wx.PlatformInfo:

# Try to mitigate the black background bug under linux by drawing a white rect

dc.SetPen(wx.Pen(wx.WHITE, 1, wx.PENSTYLE_SOLID)) # change to wx.RED to see border

dc.SetBrush(wx.Brush(wx.WHITE, wx.BRUSHSTYLE_SOLID))

dc.DrawRectangle(0,0,w,h)

Calculate a suitable scaling factor

scaleX = float(w) / maxX

scaleY = float(h) / maxY

Use x or y scaling factor, whichever fits on the DC

actualScale = min(scaleX, scaleY)

Calculate the position on the DC for centering the graphic

posX = (w - (canvasMaxX * actualScale)) / 2.0

posY = (h - (canvasMaxY * actualScale)) / 2.0

Set the scale and origin

dc.SetUserScale(actualScale, actualScale)

dc.SetDeviceOrigin(int(posX), int(posY))

-------------------------------------------

self.canvas.Redraw(dc) # <---- actual user drawing happens here

return True

``

Notice the bold lines where I test for **wxGTK **(linux) and draw the big white rectangle. Maybe this code can help someone.

Can anyone think of a better solution or know why this is happening in the first place?

Should an issue be filed in wxpython/phoenix GitHub?

Screenshot from 2019-02-27 10-29-09.png

Hi,

I can confirm the bug in Xubuntu 18.04, using python3 + phoenix and python2.7+ classic

···

Saludos / Best regards

Mario Lacunza
Email:: mlacunza@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Skype: mlacunzav

Lima - Peru

OpenSuse 15.0 -wxPython
4.0.4, python 3.6 - confirmed.

    Johnf
···

On 2/26/19 4:01 PM, Mario Lacunza
wrote:

Hi,

      I can confirm the bug in Xubuntu 18.04, using python3 +

phoenix and python2.7+ classic

Saludos / Best regards

                    Mario Lacunza

                    Email:: mlacunza@gmail.com

                    Personal Website:: [http://www.lacunza.biz/](http://www.lacunza.biz/)

                    Hosting:: [http://mlv-host.com/](http://mlv-host.com/)

                    Skype: mlacunzav



                    Lima - Peru
      El mar., 26 de feb. de 2019 a

la(s) 18:45, Andy Bulka (abulka@gmail.com) escribió:

        When bringing up the print preview in the

wxdemo under Linux (Ubuntu 18.04), the background is black.
It should be white (like it is on Mac and Windows) - not
black.

          The only way I've thought of mitigating this effect is

to draw a white rectangle onto the dc before I draw my own
stuff. Viz:

                    def

OnPrintPage(self, page):

          dc = self.GetDC()
                    #

                    # One possible method of setting scaling

factors…

canvasMaxX = self.canvas.GetSize()[0]

canvasMaxY = self.canvas.GetSize()[1]

                    canvasMaxX, canvasMaxY =

self._fit_diagram_to_paper(canvasMaxX,
canvasMaxY)

                    # Let's have at least 50 device units

margin

marginX = 50

marginY = 50

Add the margin to the graphic size

maxX = canvasMaxX + (2 * marginX)

maxY = canvasMaxY + (2 * marginY)

Get the size of the DC in pixels

                    (w, h) = dc.GetSize()  # was

GetSizeTuple() in classic wxpython

if “wxGTK” in wx.PlatformInfo:

** # Try to mitigate the black
background bug under linux by drawing a white
rect**

** dc.SetPen(wx.Pen(wx.WHITE, 1,
wx.PENSTYLE_SOLID)) # change to wx.RED to see
border**

** dc.SetBrush(wx.Brush(wx.WHITE,
wx.BRUSHSTYLE_SOLID))**

dc.DrawRectangle(0,0,w,h)

Calculate a suitable scaling factor

scaleX = float(w) / maxX

scaleY = float(h) / maxY

                    # Use x or y scaling factor, whichever

fits on the DC

actualScale = min(scaleX, scaleY)

                    # Calculate the position on the DC for

centering the graphic

                    posX = (w - (canvasMaxX * actualScale)) /

2.0

                    posY = (h - (canvasMaxY * actualScale)) /

2.0

Set the scale and origin

dc.SetUserScale(actualScale, actualScale)

dc.SetDeviceOrigin(int(posX), int(posY))

                    #

self.canvas.Redraw(dc) # ** <----
actual user drawing happens here**

return True

``

Notice the bold lines where I test for **wxGTK ** (linux)
and draw the big white rectangle. Maybe this code can
help someone.

          Can anyone think of a better solution or know why this

is happening in the first place?

Should an issue be filed in wxpython/phoenix GitHub?

      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-users+unsubscribe@googlegroups.com.

      For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

  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-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).