Reputation: 2544
Suppose I have a Paper (wx.Panel)
and I want to draw a chart on it in millimeter scale, so I set the mapping mode of the PaintDc
to millimeter: dc.SetMapMode(wx.MM_METRIC)
and then I am going to draw the horizontal axis.
class Paper(wx.Panel):
def onPaint(self, event):
dc = wx.PaintDC(self)
dc.SetMapMode(wx.MM_METRIC)
w, h = self.GetClientSize() <<< This line get size in pixel.
dc.DrawLine(0, h-10, w-1, h-10)
I want the axis to stay 10 millimeters afar from the bottom of the paper, so I query the paper's size as w, h = self.GetClientSize()
, but the problem is the size is in pixel rather than millimeter.
What is the function to get panel's size in mm., or is there a function to map size in pixel to mm.?
Upvotes: 1
Views: 686
Reputation: 2544
Fortunately, I have found that there are functions to get the screen's size in pixel and in mm.: wx.GetDisplaySize()
and wx.GetDisplaySizeMM()
, which I can use to calculate the amount of millimeters per pixel mmperpx
, which in turn can used to convert size in pixels to millimeters.
def px2mm(pixels):
px = float(wx.GetDisplaySize()[1])
mm = float(wx.GetDisplaySizeMM()[1])
mmperpx = mm/px
return mmperpx * pixels
Upvotes: 2
Reputation: 2801
I'm not a python programmer, nor used wxWidgets for more than small times, so my answer is purely assuming that no method will do this for you.
You need to get the resolution of the screen (normally 75dpi), and then calculate how many mm a pixel will equal on that screen.
Details of screen resolution http://www.scantips.com/basics1a.html
Don't assume that without calibration or getting the monitor info from some source, you will get a rule and measure the same mm as your draw.
Upvotes: 2