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?