Python wx.ScreenDC() Examples

The following are 6 code examples of wx.ScreenDC(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: FCObjects.py    From wafer_map with GNU General Public License v3.0 6 votes vote down vote up
def ComputeFontScale():
    """
    Compute the font scale.
    
    A global variable to hold the scaling from pixel size to point size.
    """
    global FontScale
    dc = wx.ScreenDC()
    dc.SetFont(wx.Font(16, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
    E = dc.GetTextExtent("X")
    FontScale = 16/E[1]
    del dc

# why do we do this here, causes a Sphinx build crash
#ComputeFontScale()    

## fixme: This should probably be re-factored into a class 
Example #2
Source File: WordWrapRenderer.py    From bookhub with MIT License 6 votes vote down vote up
def OnPaint(self, evt):
            dc = wx.PaintDC(self)
            inset = (20, 20, 20, 20)
            rect = [inset[0], inset[1], self.GetSize().width-(inset[0]+inset[2]), self.GetSize().height-(inset[1]+inset[3])]

            # Calculate exactly how high the wrapped is going to be and put a frame around it.
            dc.SetFont(self.font)
            dc.SetPen(wx.RED_PEN)
            rect[3] = WordWrapRenderer.CalculateHeight(dc, self.text, rect[2])
            dc.DrawRectangle(*rect)
            WordWrapRenderer.DrawString(dc, self.text, rect, wx.ALIGN_LEFT)
            #WordWrapRenderer.DrawTruncatedString(dc, self.text, rect, wx.ALIGN_CENTER_HORIZONTAL,s ellipse=wx.CENTER)

            #bmp = wx.EmptyBitmap(rect[0]+rect[2], rect[1]+rect[3])
            #mdc = wx.MemoryDC(bmp)
            #mdc.SetBackground(wx.Brush("white"))
            #mdc.Clear()
            #mdc.SetFont(self.font)
            #mdc.SetPen(wx.RED_PEN)
            #rect[3] = WordWrapRenderer.CalculateHeight(mdc, self.text, rect[2])
            #mdc.DrawRectangle(*rect)
            #WordWrapRenderer.DrawString(mdc, self.text, rect, wx.ALIGN_LEFT)
            #del mdc
            #dc = wx.ScreenDC()
            #dc.DrawBitmap(bmp, 20, 20) 
Example #3
Source File: utils_wx.py    From RF-Monitor with GNU General Public License v2.0 5 votes vote down vote up
def get_text_size(text, font):
    dc = wx.ScreenDC()
    dc.SetFont(font)
    return dc.GetTextExtent(text) 
Example #4
Source File: MeshCanvas.py    From laplacian-meshes with GNU General Public License v3.0 5 votes vote down vote up
def saveImage(canvas, filename):
    s = wx.ScreenDC()
    w, h = canvas.size.Get()
    b = wx.EmptyBitmap(w, h)
    m = wx.MemoryDCFromDC(s)
    m.SelectObject(b)
    m.Blit(0, 0, w, h, s, 70, 0)
    m.SelectObject(wx.NullBitmap)
    b.SaveFile(filename, wx.BITMAP_TYPE_PNG) 
Example #5
Source File: squaremap.py    From pyFileFixity with MIT License 5 votes vote down vote up
def FontForLabels(self, dc):
        ''' Return the default GUI font, scaled for printing if necessary. '''
        font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        scale = dc.GetPPI()[0] / wx.ScreenDC().GetPPI()[0]
        font.SetPointSize(scale*font.GetPointSize())
        return font 
Example #6
Source File: misc.py    From wxGlade with MIT License 5 votes vote down vote up
def GetBestSize(self):
        if not self.__radio_size:
            dc = wx.ScreenDC()
            dc.SetFont(compat.wx_SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
            self.__radio_size = (3*dc.GetCharHeight())//2
        label = self.GetLabel()
        if label:
            w, h = self.GetTextExtent(label)
            w += self.__radio_size + self.GetCharWidth()
            if h < self.__radio_size:
                h = self.__radio_size
        else:
            w = h = self.__radio_size
        return w, h