Deprecation Warnings on Floats

Robin wrote:

Perhaps better would be to create a decorator class that is constructed
with a DC of whatever type, and wraps the methods you need and simply
forwards the rest to the real DC.

class FloatDCWrapper:
def __init__(self, aDC):
self.theDC = aDC

def DrawLine(self, x1, y1, x2, y2):
self.theDC.DrawLine(int(round(x1)), int(round(y1)),
  int(round(x2)), int(round(y2)))

I tried a trick like this, including in the 'FloatDCWrapper' my own plotting
procedures. It is working ok for the screen, wxPaintDC, but I got stuck in printing.

When using wxPrintout, how do I inform wxPrintout to use FloatDCWrapper?
wxPrintout has a GetDC method, but no SetDC. According to the doc,
wxPrintout uses wxPrinterDC, wxPostScriptDC or wxMemoryDC.
wxPrinterDC and wxPostScriptDC are derived from wxDC.
Do I miss something?

wxPrintout.GetDC doc:
Returns the device context associated with the printout (given to the
printout at start of printing or previewing). This will be a wxPrinterDC
if printing under Windows, a wxPostScriptDC if printing on other
platforms, and a wxMemoryDC if previewing.

Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

Robin wrote:

Perhaps better would be to create a decorator class that is constructed
with a DC of whatever type, and wraps the methods you need and simply forwards the rest to the real DC.

class FloatDCWrapper:
def __init__(self, aDC):
self.theDC = aDC

def DrawLine(self, x1, y1, x2, y2):
self.theDC.DrawLine(int(round(x1)), int(round(y1)),
int(round(x2)), int(round(y2)))

I tried a trick like this, including in the 'FloatDCWrapper' my own plotting
procedures. It is working ok for the screen, wxPaintDC, but I got stuck in printing.

When using wxPrintout, how do I inform wxPrintout to use FloatDCWrapper?
wxPrintout has a GetDC method, but no SetDC. According to the doc, wxPrintout uses wxPrinterDC, wxPostScriptDC or wxMemoryDC.
wxPrinterDC and wxPostScriptDC are derived from wxDC.
Do I miss something?

Yes. Look at the code above again. It is not derived from any specific wxDC class. You give it one when you construct it. So you can use it to wrap any kind of dc.

  printdc = self.GetDC()
  floatdc = FloatDCWrapper(printdc)
  floatdc.DrawLine(0.5, 1.5, 100.123, 123.765)

···

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