Python wx 模块,ScreenDC() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用wx.ScreenDC()

项目:squaremap3    作者:kawaiicthulhu    | 项目源码 | 文件源码
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
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent):
        self.panel = wx.ScrolledWindow.__init__(self, parent)
        self.SetScrollRate(5, 5)
        self.panelphase = self.GetParent().panelphase
        self.panelvisual = self.GetParent().panelvisual
        self.cmvbox = wx.BoxSizer(wx.VERTICAL)
        self.cmhbox = []
        self.imglist = []
        self.sellist = []
        self.rb = []
        self.chkb = []
        array = self.panelphase.cms[0][1]
        dc = wx.ScreenDC()
        dc.SetFont(self.panelvisual.font)
        w,h = dc.GetTextExtent("TestString")
        height = h
        if IsNotWX4():
            image = wx.EmptyImage(array.shape[0],height)
        else:
            image = wx.Image(array.shape[0],height)
        newarray = numpy.zeros((height, array.shape[0], 3), dtype=numpy.uint8)
        for i in range(self.panelphase.cms.shape[0]):
            self.cmhbox.append( wx.BoxSizer(wx.HORIZONTAL) )
            name = self.panelphase.cms[i][0]
            array = self.panelphase.cms[i][1]
            for j in range(height):
                newarray[j,:,:] = numpy.uint8(255.0*array)
            image.SetData( newarray.tostring())
            bmp = image.ConvertToBitmap()
            self.imglist.append(wx.StaticBitmap(self, -1, bmp))
            self.rb.append( wx.RadioButton(self, -1, label=name, size=(160, height) ) )
            self.cmhbox[-1].Add(self.rb[-1], 0)
            self.cmhbox[-1].Add((5, -1))
            self.cmhbox[-1].Add(self.imglist[-1], 1, wx.EXPAND)
            self.chkb.append( wx.CheckBox(self, -1, 'Reverse', size=(160, height)) )
            self.cmhbox[-1].Add(self.chkb[-1], 0, wx.EXPAND)
            self.cmvbox.Add(self.cmhbox[-1], 1, wx.EXPAND)
        self.SetSizer(self.cmvbox)
        self.Fit()
        self.Layout()
        self.Show()
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent, name, objectpath, textwidth, file_extension):
        def assign(input):
            self.objectpath.ChangeValue(input)
        def OnBrowse(self):
            if IsNotWX4():
                dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '',  file_extension, wx.OPEN)
            else:
                dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '',  file_extension, wx.FD_OPEN)
            if dlg.ShowModal() == wx.ID_OK:
                assign(dlg.GetPath())
            dlg.Destroy()
        def OnEdit(event):
            self.objectpath.ChangeValue(event.GetString())
        fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
        self.font = wx.Font(fontpointsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
        dc = wx.ScreenDC()
        dc.SetFont(self.font)
        textw,texth = dc.GetTextExtent(name)
        if textw > textwidth:
            labelw = textw
        else:
            labelw = textwidth
        wx.BoxSizer.__init__(self, wx.HORIZONTAL)
        self.label = StaticTextNew(parent, -1, name, style =wx.ALIGN_RIGHT, size=(labelw,-1) )
        self.label.SetFont(self.font)
        self.Add( self.label, 0, wx.CENTER )
        self.objectpath = TextCtrlNew(parent, -1)
        self.objectpath.SetFont(self.font)
        self.objectpath.SetValue(objectpath)
        self.objectpath.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
        self.objectpath.Bind(wx.EVT_TEXT_ENTER, OnEdit)
        self.Add( self.objectpath, 1, wx.CENTER |wx.EXPAND )
        self.button = ButtonNew(parent, -1, "Browse")
        self.button.SetFont(self.font)
        self.button.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
        self.button.Bind(wx.EVT_BUTTON, OnBrowse)
        self.Add( self.button, 0, wx.LEFT|wx.CENTER)
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent, name, init, stextwidth):
        def OnEdit(event):
            text = event.GetString()
            point = self.value.GetInsertionPoint()
            if (IsNumber(self.value.GetValue()) == False):
                self.value.SetBackgroundColour( "Pink" )
                self.value.SetForegroundColour( "Black" )
            else:
                self.value.SetBackgroundColour(wx.NullColour)
                self.value.SetForegroundColour(wx.NullColour)
                self.value.ChangeValue(text)
                self.value.SetInsertionPoint(point)
        fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
        self.font = wx.Font(fontpointsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
        wx.BoxSizer.__init__(self, wx.HORIZONTAL)
        dc = wx.ScreenDC()
        dc.SetFont(self.font)
        textw,texth = dc.GetTextExtent(name)
        if textw > stextwidth:
            labelw = textw
        else:
            labelw = stextwidth
        self.label = StaticTextNew(parent, -1, name, style =wx.ALIGN_RIGHT, size=(labelw,-1) )
        self.label.SetFont(self.font)
        self.Add( self.label, 0, wx.CENTER )
        self.value = TextCtrlNew(parent, value=str(init), style=wx.TE_PROCESS_ENTER)
        self.value.SetWindowStyle(wx.TE_RIGHT)
        self.value.SetFont(self.font)
        self.value.Bind(wx.EVT_TEXT, OnEdit)
        self.Add( self.value, 1, wx.CENTER|wx.EXPAND )
项目:laplacian-meshes    作者:bmershon    | 项目源码 | 文件源码
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)
项目:procrustes    作者:bmershon    | 项目源码 | 文件源码
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)
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
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
项目:TensorKart    作者:kevinhughes27    | 项目源码 | 文件源码
def take_screenshot(self):
        screen = wx.ScreenDC()
        bmp = wx.Bitmap(Screenshot.SRC_W, Screenshot.SRC_H)
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, Screenshot.SRC_W, Screenshot.SRC_H, screen, Screenshot.OFFSET_X, Screenshot.OFFSET_Y)
        return bmp
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent, name, smax, smin, sinc, sinit, stextwidth, swidth):
        if abs(sinc) < 1.0:
            self.precision = "%."+str(str(sinc)[::-1].find('.'))+"f"
        else:
            self.precision = "%d"
        def OnSpin(pos):
            self.value.ChangeValue(self.precision%(sinc * pos + self.remainder))
        def OnEdit(event):
            text = event.GetString()
            point = self.value.GetInsertionPoint()
            if (IsNumber(self.value.GetValue()) == False):
                self.value.SetBackgroundColour( "Pink" )
                self.value.SetForegroundColour( "Black" )
            else:
                self.value.SetBackgroundColour(wx.NullColour)
                self.value.SetForegroundColour(wx.NullColour)
                self.value.ChangeValue(text)
                self.value.SetInsertionPoint(point)
                if ( text == '' or  text == '.'): self.spin.SetValue(smin/sinc);
                try:
                    self.spin.SetValue(int(float(text)/sinc))
                except:
                    pass
                event.Skip()
        fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
        self.font = wx.Font(fontpointsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
        dc = wx.ScreenDC()
        dc.SetFont(self.font)
        textw,texth = dc.GetTextExtent(name)
        if textw > stextwidth:
            labelw = textw
        else:
            labelw = stextwidth
        wx.BoxSizer.__init__(self, wx.HORIZONTAL)
        self.label = StaticTextNew(parent, -1, name, style=wx.ALIGN_RIGHT, size=(labelw,-1) )
        self.label.SetFont(self.font)
        self.Add( self.label, 0, wx.CENTER )
        self.value = TextCtrlNew(parent, value=str(sinit),size=(swidth, -1), style=wx.TE_PROCESS_ENTER)
        self.value.SetWindowStyle(wx.TE_RIGHT)
        self.value.SetFont(self.font)
        self.value.Bind(wx.EVT_TEXT, OnEdit)
        self.Add( self.value, 0, wx.CENTER )
        bw,bh = dc.GetTextExtent("0")
        spinw = int(1.5*bh)
        self.spin = SpinButtonNew(parent, size=(spinw,-1), spinfunc=OnSpin)
        self.spin.SetRange(int(smin/sinc), int(smax/sinc))
        self.spin.SetValue(int(sinit/sinc))
        self.remainder = smin%sinc
        self.Add( self.spin, 0, wx.CENTER )
        self.IsEnabled = True
        self.Layout()
        self.Show()
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def onTakeScreenShot(self, event):
        """
        Takes a screenshot of the screen at give pos & size (rect).

        Method based on a script by Andrea Gavana
        """
        print('Taking screenshot...')
        rect = self.GetRect()

        # adjust widths for Linux (figured out by John Torres
        # http://article.gmane.org/gmane.comp.python.wxpython/67327)
        if sys.platform == 'linux2':
            client_x, client_y = self.ClientToScreen((0, 0))
            border_width = client_x - rect.x
            title_bar_height = client_y - rect.y
            rect.width += (border_width * 2)
            rect.height += title_bar_height + border_width

        # Create a DC for the whole screen area
        dcScreen = wx.ScreenDC()

        # Create a Bitmap that will hold the screenshot image later on
        # Note that the Bitmap must have a size big enough to hold the screenshot
        # -1 means using the current default colour depth
        bmp = wx.EmptyBitmap(rect.width, rect.height)

        #Create a memory DC that will be used for actually taking the screenshot
        memDC = wx.MemoryDC()

        # Tell the memory DC to use our Bitmap
        # all drawing action on the memory DC will go to the Bitmap now
        memDC.SelectObject(bmp)

        # Blit (in this case copy) the actual screen on the memory DC
        # and thus the Bitmap
        memDC.Blit( 0, # Copy to this X coordinate
                    0, # Copy to this Y coordinate
                    rect.width, # Copy this width
                    rect.height, # Copy this height
                    dcScreen, # Where to copy from
                    rect.x, # What's the X offset in the original DC?
                    rect.y  # What's the Y offset in the original DC?
                    )

        # Select the Bitmap out of the memory DC by selecting a new
        # uninitialized Bitmap
        memDC.SelectObject(wx.NullBitmap)

        img = bmp.ConvertToImage()
        fileName = "myImage.png"
        img.SaveFile(fileName, wx.BITMAP_TYPE_PNG)
        print('...saving as png!')