我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用wx.ClientDC()。
def do_about(self, evt): info = wx.AboutDialogInfo() info.Name = self.title info.Version = __version__ info.Copyright = __copyright__ info.Description = ( "Visual Template designer for PyFPDF (using wxPython OGL library)\n" "Input files are CSV format describing the layout, separated by ;\n" "Use toolbar buttons to open, save, print (preview) your template, " "and there are buttons to find, add, remove or duplicate elements.\n" "Over an element, a double left click opens edit text dialog, " "and a right click opens edit properties dialog. \n" "Multiple element can be selected with shift left click. \n" "Use arrow keys or drag-and-drop to move elements.\n" "For further information see project webpage:" ) info.WebSite = ("http://code.google.com/p/pyfpdf/wiki/Templates", "pyfpdf Google Code Project") info.Developers = [ __author__, ] info.License = wordwrap(__license__, 500, wx.ClientDC(self)) # Then we call wx.AboutBox giving it that info object wx.AboutBox(info)
def FillTextCtrl(self, textctrl, fname, srcdir='appdir'): if srcdir == 'appdir': fpath = appconstants.getapppath(fname) else: fpath = appconstants.getdatapath(fname) try: f = open(fpath, 'r') except IOError: fcontent = fname + filemissing + appconstants.AppURL else: fcontent = f.read() textctrl.SetFont(self.font) textctrl.SetValue(fcontent) winDC = wx.ClientDC(textctrl) width, height = winDC.GetTextExtent(text_82) height *= 26 textctrl.SetMinSize(wx.Size(width, height))
def Clear(self): """Erase the window.""" self.last_PointLabel = None # reset pointLabel dc = wx.BufferedDC(wx.ClientDC(self.canvas), self._Buffer) bbr = wx.Brush(self.GetBackgroundColour(), wx.SOLID) dc.SetBackground(bbr) dc.SetBackgroundMode(wx.SOLID) dc.Clear() if self._antiAliasingEnabled: try: dc = wx.GCDC(dc) except Exception: pass dc.SetTextForeground(self.GetForegroundColour()) dc.SetTextBackground(self.GetBackgroundColour()) self.last_draw = None
def _drawPointLabel(self, mDataDict): """Draws and erases pointLabels""" width = self._Buffer.GetWidth() height = self._Buffer.GetHeight() if sys.platform != "darwin": tmp_Buffer = wx.Bitmap(width, height) dcs = wx.MemoryDC() dcs.SelectObject(tmp_Buffer) dcs.Clear() else: tmp_Buffer = self._Buffer.GetSubBitmap((0, 0, width, height)) dcs = wx.MemoryDC(self._Buffer) self._pointLabelFunc(dcs, mDataDict) # custom user pointLabel function dc = wx.ClientDC(self.canvas) dc = wx.BufferedDC(dc, self._Buffer) # this will erase if called twice dc.Blit(0, 0, width, height, dcs, 0, 0, self._logicalFunction) if sys.platform == "darwin": self._Buffer = tmp_Buffer
def update(self, pix): if self.ips == None: return lay(self.box, self.imgbox) dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) #dc.BeginDrawing() dc.Clear() self.draw_image(dc, self.ips.img, self.ips.backimg, self.ips.backmode, self.imgbox, self.scales[self.scaleidx], pix) #dc.EndDrawing() #cdc = wx.ClientDC(self) #cdc.BeginDrawing() if self.ips.roi != None: self.ips.roi.draw(dc, self.to_panel_coor) if self.ips.mark != None: self.ips.mark.draw(dc, self.to_panel_coor, cur=self.ips.cur, k = self.get_scale()) #cdc.EndDrawing() if self.ips.unit!=(1,'pix'): self.draw_ruler(dc) dc.UnMask()
def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id, title) self.MainPanel = wx.Panel(self, size=(640, 480)) self.MainPanel.SetBackgroundColour('WHITE') self.panel = wx.Panel(self.MainPanel, size = (640,480)) self.panel.SetBackgroundColour('WHITE') mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(self.panel) self.SetSizer(mainSizer) self.Fit() self.Bind(wx.EVT_CLOSE, self.CloseWindow) self.World = None self.cdc = wx.ClientDC(self.panel) w, h = self.panel.GetSize() self.bmp = wx.EmptyBitmap(w,h) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(20)
def canvasCallback(self, event=None): # create the device context dc = wx.ClientDC(self) brushBMP = wx.Brush(self.bmp) dc.SetBrush(brushBMP) width, height = self.GetClientSize() dc.DrawRectangle(0, 0, width, height) #=================================================================================
def _handle_connection_error(self, error_message=None): """Handle connection errors that might be thrown when initially connecting to IRIDA. Args: error_message: A more detailed error message than "Can't connect" """ logging.error("Handling connection error.") self.Freeze() connection_error_sizer = wx.BoxSizer(wx.HORIZONTAL) connection_error_header = wx.StaticText(self, label=u"? Uh-oh. I couldn't to connect to IRIDA.") connection_error_header.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)) connection_error_header.SetForegroundColour(wx.Colour(255, 0, 0)) connection_error_header.Wrap(350) connection_error_sizer.Add(connection_error_header, flag=wx.LEFT | wx.RIGHT, border=5) self._sizer.Add(connection_error_sizer, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) if error_message: self._sizer.Add(wx.StaticText(self, label=wordwrap(error_message, 350, wx.ClientDC(self))), flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) open_settings_button = wx.Button(self, label="Open Settings") self.Bind(wx.EVT_BUTTON, self._parent._open_settings, id=open_settings_button.GetId()) self._sizer.Add(open_settings_button, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) self.Layout() self.Thaw() pub.unsubscribe(self._handle_connection_error, APIConnectorTopics.connection_error_topic)
def _open_about(self, event): """Open the about dialog.""" app_info = wx.AboutDialogInfo() app_info.Name = self._app_name app_info.Version = self._app_version app_info.WebSite = (self._app_url, "IRIDA Uploader on GitHub") app_info.Description = wordwrap("IRIDA Uploader is a tool to send Illumina MiSeq data to an instance of IRIDA for management.", 350, wx.ClientDC(self)) wx.AboutBox(app_info)
def __init__(self, parent, sheets_directory): """Initalize InvalidSampleSheetsPanel. Args: parent: the owning Window sheets_directory: the parent directory for searching sample sheets. This argument is used in the error message that's displayed to the user to tell them where to look to fix any issues. """ wx.Panel.__init__(self, parent) self._sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self._sizer) header = wx.StaticText(self, label=u"? Looks like some sample sheets are not valid.") header.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)) header.SetForegroundColour(wx.Colour(255, 0, 0)) header.Wrap(350) self._sizer.Add(header,flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER, border=5) self._sizer.Add(wx.StaticText(self, label=wordwrap(( "I found the following sample sheets in {}, but I couldn't understand " "their contents. Check these sample sheets in an editor outside " "of the uploader, then click the 'Scan Again' button below.").format(sheets_directory), 350, wx.ClientDC(self))), flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) self._errors_tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_LINES_AT_ROOT | wx.TR_HIDE_ROOT) self._errors_tree_root = self._errors_tree.AddRoot("") self._sizer.Add(self._errors_tree, flag=wx.EXPAND, proportion=1) scan_again_button = wx.Button(self, label="Scan Again") self.Bind(wx.EVT_BUTTON, lambda evt: send_message(SettingsDialog.settings_closed_topic), id=scan_again_button.GetId()) self._sizer.Add(scan_again_button, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5) pub.subscribe(self._sample_sheet_error, DirectoryScannerTopics.garbled_sample_sheet) pub.subscribe(self._sample_sheet_error, DirectoryScannerTopics.missing_files)
def DoDeletePage(self, page): """ Does the actual page deletion. :param `page`: the index of the tab. """ # Remove the page from the vector book = self.GetParent() self._pagesInfoVec.pop(page) if self._nIndex >= page: self._nIndex = self._nIndex - 1 # The delete page was the last first on the array, # but the book still has more pages, so we set the # active page to be the first one (0) if self._nIndex < 0 and len(self._pagesInfoVec) > 0: self._nIndex = 0 # Refresh the tabs if self._nIndex >= 0: book._bForceSelection = True book.SetSelection(self._nIndex) book._bForceSelection = False if not self._pagesInfoVec: # Erase the page container drawings dc = wx.ClientDC(self) dc.Clear()
def OnLeftClick(self, x, y, keys=0, attachment=0): shape = self.GetShape() canvas = shape.GetCanvas() dc = wx.ClientDC(canvas) canvas.PrepareDC(dc) if shape.Selected() and keys & ogl.KEY_SHIFT: shape.Select(False, dc) #canvas.Redraw(dc) canvas.Refresh(False) else: redraw = False shapeList = canvas.GetDiagram().GetShapeList() toUnselect = [] for s in shapeList: if s.Selected() and not keys & ogl.KEY_SHIFT: # If we unselect it now then some of the objects in # shapeList will become invalid (the control points are # shapes too!) and bad things will happen... toUnselect.append(s) shape.Select(True, dc) if toUnselect: for s in toUnselect: s.Select(False, dc) ##canvas.Redraw(dc) canvas.Refresh(False) self.callback()
def _drawRubberBand(self, corner1, corner2): """Draws/erases rect box from corner1 to corner2""" ptx, pty, rectWidth, rectHeight = self._point2ClientCoord( corner1, corner2) # draw rectangle dc = wx.ClientDC(self.canvas) dc.SetPen(wx.Pen(wx.BLACK)) dc.SetBrush(wx.Brush(wx.WHITE, wx.BRUSHSTYLE_TRANSPARENT)) dc.SetLogicalFunction(wx.INVERT) dc.DrawRectangle(ptx, pty, rectWidth, rectHeight) dc.SetLogicalFunction(wx.COPY)
def draw_box(self): x1, x2 = self.plot._point2ClientCoord(*self.selected)[::2] dc = wx.ClientDC(self.plot.canvas) dc.SetLogicalFunction(wx.INVERT) dc.DrawRectangle(x1, 0, x2, dc.GetSize()[1]) dc.SetLogicalFunction(wx.COPY) # def clear(self): # # An experimental way to clear the canvas without redrawing the plot every time # # dc.Blit() usage from SOF. # if self.selection_drawn: # self.draw_box() # clear old # self.selection_drawn = False # dc = wx.ClientDC(self.plot.canvas) # size = dc.GetSize() # bmp = wx.Bitmap(size.width, size.height) # prev_dc = wx.MemoryDC() # prev_dc.SelectObject(bmp) # prev_dc.Blit( # 0, # Copy to this X coordinate # 0, # Copy to this Y coordinate # size.width, # Copy this width # size.height, # Copy this height # dc, # From where do we copy? # 0, # What's the X offset in the original DC? # 0 # What's the Y offset in the original DC? # ) # prev_dc.SelectObject(wx.NullBitmap) # dc.Clear() # dc.DrawBitmap(bmp, 0, 0) # # if self.plot.last_draw is not None: # # self.plot.Draw(self.plot.last_draw[0])
def OnEraseBackground(self, evt): """ Add a picture to the background """ # yanked from ColourDB.py dc = evt.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) dc.Clear() # bmp = wx.Bitmap("/home/pi/Desktop/GoBox/Troubleshooting_GUI/dex.png") # Draw the photograph. # dc.DrawBitmap(bmp, 0, 400) # Absolute position of where to put the picture
def SetItemExtraImage(self, item, bitmap): dc = wx.ClientDC(self) image = self.ExtraImages.get(bitmap) if image is not None: item.SetExtraImage(image) else: item.SetExtraImage(None) self.CalculateSize(item, dc) self.RefreshLine(item)
def OnEraseBackground(self, event): dc = event.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) dc.Clear() bitmap_rect = self.GetBitmapRect() dc.DrawBitmap(self.BackgroundBitmap, bitmap_rect.x, bitmap_rect.y)
def GetLogicalDC(self, buffered=False): if buffered: bitmap = wx.EmptyBitmap(*self.Editor.GetClientSize()) dc = wx.MemoryDC(bitmap) else: dc = wx.ClientDC(self.Editor) dc.SetFont(self.GetFont()) if wx.VERSION >= (2, 6, 0): self.Editor.DoPrepareDC(dc) else: self.Editor.PrepareDC(dc) dc.SetUserScale(self.ViewScale[0], self.ViewScale[1]) return dc
def GetMinSize(self): dc = wx.ClientDC(self.Parent) min_width = 0 min_height = 0 # The comment minimum size is the maximum size of words in the content for line in self.Content.splitlines(): for word in line.split(" "): wordwidth, wordheight = dc.GetTextExtent(word) min_width = max(min_width, wordwidth) min_height = max(min_height, wordheight) return min_width + 20, min_height + 20 # Changes the comment position
def save_bitmap(self, path): context = wx.ClientDC( self ) memory = wx.MemoryDC( ) x, y = self.ClientSize bitmap = wx.Bitmap( x, y, -1 ) memory.SelectObject( bitmap ) memory.Blit( 0, 0, x, y, context, 0, 0) memory.SelectObject( wx.NullBitmap) bitmap.SaveFile( path, wx.BITMAP_TYPE_PNG )
def on_paint(self, event): wx.BufferedPaintDC(self, self.buffer) ''' cdc = wx.ClientDC(self) #cdc.BeginDrawing() if self.ips.roi != None: self.ips.roi.draw(cdc, self.to_panel_coor) if self.ips.mark != None: self.ips.mark.draw(cdc, self.to_panel_coor, cur=self.ips.cur, k = self.get_scale()) if self.ips.unit!=(1,'pix'): self.draw_ruler(cdc) #cdc.EndDrawing() '''
def OnEraseBackground(self, evt): """ Add a picture to the background """ # yanked from ColourDB.py dc = evt.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) dc.Clear() bmp = wx.Bitmap("big_cat.jpg") dc.DrawBitmap(bmp, 0, 0)
def onAboutDlg(self, event): info = wx.AboutDialogInfo() info.Name = "My About Box" info.Version = "0.0.1 Beta" info.Copyright = "(C) 2016 Python Geeks Everywhere" info.Description = wordwrap( "This is an example application that shows how to create " "different kinds of About Boxes using wxPython!", 350, wx.ClientDC(self.panel)) info.WebSite = ("http://www.pythonlibrary.org", "My Home Page") info.Developers = ["Mike Driscoll"] info.License = wordwrap("Completely and totally open source!", 500, wx.ClientDC(self.panel)) # Show the wx.AboutBox wx.AboutBox(info)
def onAboutDlg(self, event): info = wx.adv.AboutDialogInfo() info.Name = "My About Box" info.Version = "0.0.1 Beta" info.Copyright = "(C) 2008 Python Geeks Everywhere" info.Description = wordwrap( "This is an example application that shows how to create " "different kinds of About Boxes using wxPython!", 350, wx.ClientDC(self.panel)) info.WebSite = ("http://www.pythonlibrary.org", "My Home Page") info.Developers = ["Mike Driscoll"] info.License = wordwrap("Completely and totally open source!", 500, wx.ClientDC(self.panel)) # Show the wx.AboutBox wx.adv.AboutBox(info)
def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id, title) self.panel = wx.Panel(self, size=(640, 480)) self.panel.SetBackgroundColour('WHITE') self.Fit() self.A = Agent(self.panel, 150, 100 ) self.greenB = [Ball(rnd.randint(40, 600),rnd.randint(40, 440), wx.Colour(112,173,71), property = 1) for i in range(0, 15)] self.redB = [Ball(rnd.randint(40, 600),rnd.randint(40, 440), wx.Colour(237,125,49), property = 2) for i in range(0, 10)] # OutrBox self.Box = Walls(640, 480, 0, 480) self.Box.addPoint(0,0) self.Box.addPoint(640,0) self.Box.addPoint(640,480) # Wall in the world self.WallA = Walls(96, 90, 256, 90) self.WallA.addPoint(256, 390) self.WallA.addPoint(96,390) self.Bind(wx.EVT_CLOSE, self.CloseWindow) self.cdc = wx.ClientDC(self.panel) w, h = self.panel.GetSize() self.bmp = wx.EmptyBitmap(w,h) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(20)
def _get_sash_DC(self): dc = wx.ClientDC(self) dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.Brush(self.sashColor)) return dc
def OnMenuHelpAboutMenu(self, event): """ This function is run when About is clicked on the menu. It calls a standard About dialog window. """ info = wx.AboutDialogInfo() info.Name = u"PAWS" info.Version = Engine.Version info.Copyright = u"© 1998–2016 Roger Plowman, Matthias C. Hormann" info.Description = wordwrap( u"Core Engine: v" + Engine.Version + u", " u"Universe: v" + UniverseVersion + u"\n\n" u"PAWS is the Python Adventure Writing System, " u"a software to play and develop Interactive Fiction with. " u"It was originally developed by Roger Plowman and continued " u"in 2016 by Matthias C. Hormann, just for the fun of it.", 350, wx.ClientDC(self)) info.WebSite = (u"https://github.com/Moonbase59/PAWS", u"PAWS GitHub page") info.Developers = [u"Roger Plowman", u"Kevin Russell", u"Matthias C. Hormann"] info.License = wordwrap( u"Please see the LICENSE file that came with the software.", 350, wx.ClientDC(self)) # show it wx.AboutBox(info) # event.Skip()
def RefreshPreview(self): """ Refresh preview panel of graphic element May be overridden by inherited classes """ # Init preview panel paint device context dc = wx.ClientDC(self.Preview) dc.SetFont(self.Preview.GetFont()) dc.Clear() # Return immediately if no graphic element defined if self.Element is None: return # Calculate block size according to graphic element min size due to its # parameters and graphic element min size defined min_width, min_height = self.GetMinElementSize() width = max(self.MinElementSize[0], min_width) height = max(self.MinElementSize[1], min_height) self.Element.SetSize(width, height) # Get element position and bounding box to center in preview posx, posy = self.Element.GetPosition() bbox = self.Element.GetBoundingBox() # Get Preview panel size client_size = self.Preview.GetClientSize() # If graphic element is too big to be displayed in preview panel, # calculate preview panel scale so that graphic element fit inside k = 1.1 if (bbox.width * 1.1 > client_size.width or bbox.height * 1.1 > client_size.height) \ else 1.0 scale = (max(float(bbox.width) / client_size.width, float(bbox.height) / client_size.height) * k) dc.SetUserScale(1.0 / scale, 1.0 / scale) # Center graphic element in preview panel x = int(client_size.width * scale - bbox.width) / 2 + posx - bbox.x y = int(client_size.height * scale - bbox.height) / 2 + posy - bbox.y self.Element.SetPosition(x, y) # Draw graphic element self.Element.Draw(dc)
def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id, title) self.MainPanel = wx.Panel(self, size=(640, 640)) self.MainPanel.SetBackgroundColour('WHITE') self.panel = wx.Panel(self.MainPanel, size = (640,480)) self.panel.SetBackgroundColour('WHITE') self.plotter = plot.PlotCanvas(self.MainPanel, size =(640, 640-480)) self.plotter.SetEnableZoom(False) self.plotter.SetEnableLegend(True) self.plotter.SetFontSizeLegend(10.5) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(self.panel) mainSizer.Add(self.plotter) self.SetSizer(mainSizer) self.Fit() self.A = Agent(self.panel, 240, 49 ) self.B = Agent(self.panel, 240, 49) self.B.B_color = wx.Colour(112,173,71) # OutrBox self.Box = Walls(640, 479, 0, 479) self.Box.addPoint(0,0) self.Box.addPoint(640,0) self.Box.addPoint(640,479) # Oval Course Rad = 190.0 Poly = 16 self.Course = Walls(240, 50, 640-(50+Rad),50) for i in range(1, Poly): self.Course.addPoint(Rad*math.cos(-np.pi/2.0 + np.pi*i/Poly)+640-(50+Rad), Rad*math.sin(-np.pi/2.0 + np.pi*i/Poly)+50+Rad) self.Course.addPoint(240, 50+Rad*2) for i in range(1, Poly): self.Course.addPoint(Rad*math.cos(np.pi/2.0 + np.pi*i/Poly)+(50+Rad), Rad*math.sin(np.pi/2.0 + np.pi*i/Poly)+50+Rad) self.Course.addPoint(240,50) self.Bind(wx.EVT_CLOSE, self.CloseWindow) self.cdc = wx.ClientDC(self.panel) w, h = self.panel.GetSize() self.bmp = wx.EmptyBitmap(w,h) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(20) self.i = 0 self.tmp_sum = 0.0 self.data = []
def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id, title) self.MainPanel = wx.Panel(self, size=(640, 640)) self.MainPanel.SetBackgroundColour('WHITE') self.panel = wx.Panel(self.MainPanel, size = (640,480)) self.panel.SetBackgroundColour('WHITE') self.plotter = plot.PlotCanvas(self.MainPanel, size =(640, 640-480)) self.plotter.SetEnableZoom(False) self.plotter.SetEnableLegend(True) self.plotter.SetFontSizeLegend(10.5) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(self.panel) mainSizer.Add(self.plotter) self.SetSizer(mainSizer) self.Fit() self.A = Agent(self.panel, 150, 100 ) self.B = Agent(self.panel, 400, 300, model = self.A.model) self.C = Agent(self.panel, 400, 150, model = self.A.model) self.D = Agent(self.panel, 320, 240, model = self.A.model) self.greenB = [Ball(rnd.randint(40, 600),rnd.randint(40, 440), wx.Colour(112,173,71), property = 1) for i in range(0, 15)] self.redB = [Ball(rnd.randint(40, 600),rnd.randint(40, 440), wx.Colour(237,125,49), property = 2) for i in range(0, 10)] # OutrBox self.Box = Walls(640, 480, 0, 480) self.Box.addPoint(0,0) self.Box.addPoint(640,0) self.Box.addPoint(640,480) # Wall in the world self.WallA = Walls(96, 90, 256, 90) self.WallA.addPoint(256, 390) self.WallA.addPoint(96,390) self.Bind(wx.EVT_CLOSE, self.CloseWindow) self.cdc = wx.ClientDC(self.panel) w, h = self.panel.GetSize() self.bmp = wx.EmptyBitmap(w,h) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer.Start(20) self.i = 0 self.tmp_sum = 0.0 self.data = []