Python wx.ClientDC() Examples
The following are 30
code examples of wx.ClientDC().
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: wrapped_static_text.py From Gooey with MIT License | 6 votes |
def Wrap(self, width): """ This functions wraps the controls label so that each of its lines becomes at most `width` pixels wide if possible (the lines are broken at words boundaries so it might not be the case if words are too long). If `width` is negative, no wrapping is done. :param integer `width`: the maximum available width for the text, in pixels. :note: Note that this `width` is not necessarily the total width of the control, since a few pixels for the border (depending on the controls border style) may be added. """ if width < 0: return self.Freeze() dc = wx.ClientDC(self) dc.SetFont(self.GetFont()) text = wordwrap(self.label, width, dc) self.SetLabel(text, wrapped=True) self.Thaw()
Example #2
Source File: backend_wx.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #3
Source File: ListCtrl.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def set_default_widths(self): # must be called before *any* data is put into the control. sample_data = {} for name in self.column_order: sample_data[name] = self.columns[name].sample_data sample_row = BTListRow(None, sample_data) self.InsertRow(-1, sample_row) for name in self.column_order: column = self.columns[name] if name in self.enabled_columns: self.SetColumnWidth(column.GetColumn(), wx.LIST_AUTOSIZE) column.width = self.GetColumnWidth(column.GetColumn()) dc = wx.ClientDC(self) header_width = dc.GetTextExtent(column.GetText())[0] header_width += 4 # arbitrary allowance for header decorations column.width = max(column.width, header_width) if name in self.enabled_columns: self.SetColumnWidth(column.GetColumn(), column.width) self.default_rect = self.GetItemRect(0) self.DeleteRow(-1)
Example #4
Source File: backend_wx.py From CogAlg with MIT License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #5
Source File: backend_wx.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #6
Source File: backend_wx.py From coffeegrindsize with MIT License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #7
Source File: backend_wx.py From neural-network-animation with MIT License | 6 votes |
def gui_repaint(self, drawDC=None): """ Performs update of the displayed image on the GUI canvas, using the supplied device context. If drawDC is None, a ClientDC will be used to redraw the image. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if drawDC is None: drawDC=wx.ClientDC(self) drawDC.BeginDrawing() drawDC.DrawBitmap(self.bitmap, 0, 0) drawDC.EndDrawing() #wx.GetApp().Yield() else: pass
Example #8
Source File: recipe-577951.py From code with MIT License | 6 votes |
def DoGetBestSize(self): """ Overridden base class virtual. Determines the best size of the button based on the label and bezel size. """ label = self.GetLabel() if not label: return wx.Size(32, 32) dc = wx.ClientDC(self) dc.SetFont(self.GetFont()) retWidth, retHeight = dc.GetTextExtent(label) width = int(max(retWidth, retHeight) * 1.5) return wx.Size(width, width)
Example #9
Source File: relay_board_gui.py From R421A08-rs485-8ch-relay-board with MIT License | 6 votes |
def OnAboutClick(self, event=None): info = wx.adv.AboutDialogInfo() info.SetName('RS485 MODBUS GUI') info.SetVersion('v{}'.format(relay_boards.VERSION)) info.SetCopyright('(C) 2018 by Erriez') ico_path = resource_path('images/R421A08.ico') if os.path.exists(ico_path): info.SetIcon(wx.Icon(ico_path)) info.SetDescription(wordwrap( "This is an example application to control a R421A08 relay board using wxPython!", 350, wx.ClientDC(self))) info.SetWebSite(SOURCE_URL, "Source & Documentation") info.AddDeveloper('Erriez') info.SetLicense(wordwrap("MIT License: Completely and totally open source!", 500, wx.ClientDC(self))) wx.adv.AboutBox(info) # -------------------------------------------------------------------------------------------------- # Relay panel # --------------------------------------------------------------------------------------------------
Example #10
Source File: backend_wx.py From matplotlib-4-abaqus with MIT License | 6 votes |
def gui_repaint(self, drawDC=None): """ Performs update of the displayed image on the GUI canvas, using the supplied device context. If drawDC is None, a ClientDC will be used to redraw the image. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if drawDC is None: drawDC=wx.ClientDC(self) drawDC.BeginDrawing() drawDC.DrawBitmap(self.bitmap, 0, 0) drawDC.EndDrawing() #wx.GetApp().Yield() else: pass
Example #11
Source File: relay_modbus_gui.py From R421A08-rs485-8ch-relay-board with MIT License | 6 votes |
def OnMenuAbout(self, event): """ Display an About Dialog :param event: :return: """ info = wx.adv.AboutDialogInfo() info.SetName('RS485 MODBUS GUI') info.SetVersion('v{}'.format(relay_modbus.VERSION)) info.SetCopyright('(C) 2018 by Erriez') ico_path = resource_path('images/modbus.ico') if os.path.exists(ico_path): info.SetIcon(wx.Icon(ico_path)) info.SetDescription(wordwrap( "This is an example application to monitor and send MODBUS commands using wxPython!", 350, wx.ClientDC(self))) info.SetWebSite("https://github.com/Erriez/R421A08-rs485-8ch-relay-board", "Source & Documentation") info.AddDeveloper('Erriez') info.SetLicense(wordwrap("MIT License: Completely and totally open source!", 500, wx.ClientDC(self))) # Then we call wx.AboutBox giving it that info object wx.adv.AboutBox(info)
Example #12
Source File: backend_wx.py From twitter-stock-recommendation with MIT License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #13
Source File: backend_wx.py From ImageFusion with MIT License | 6 votes |
def gui_repaint(self, drawDC=None): """ Performs update of the displayed image on the GUI canvas, using the supplied device context. If drawDC is None, a ClientDC will be used to redraw the image. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if drawDC is None: drawDC=wx.ClientDC(self) drawDC.BeginDrawing() drawDC.DrawBitmap(self.bitmap, 0, 0) drawDC.EndDrawing() #wx.GetApp().Yield() else: pass
Example #14
Source File: backend_wx.py From twitter-stock-recommendation with MIT License | 6 votes |
def draw_rubberband(self, x0, y0, x1, y1): dc = wx.ClientDC(self.canvas) # this would be required if the Canvas is a ScrolledWindow, # which is not the case for now # self.PrepareDC(dc) # delete old rubberband if self._rect: self.remove_rubberband(dc) # draw new rubberband dc.SetPen(wx.Pen(wx.BLACK, 1, wx.SOLID)) dc.SetBrush(wx.TRANSPARENT_BRUSH) self._rect = (x0, self.canvas._height-y0, x1-x0, -y1+y0) if wxc.is_phoenix: dc.DrawRectangle(self._rect) else: dc.DrawRectangleRect(self._rect)
Example #15
Source File: backend_wx.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the supplied wx.PaintDC device context. The 'WXAgg' backend sets origin accordingly. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if not drawDC: # not called from OnPaint use a ClientDC drawDC = wx.ClientDC(self) # following is for 'WX' backend on Windows # the bitmap can not be in use by another DC, # see GraphicsContextWx._cache if wx.Platform == '__WXMSW__' and origin == 'WX': img = self.bitmap.ConvertToImage() bmp = img.ConvertToBitmap() drawDC.DrawBitmap(bmp, 0, 0) else: drawDC.DrawBitmap(self.bitmap, 0, 0)
Example #16
Source File: backend_wx.py From Computable with MIT License | 6 votes |
def gui_repaint(self, drawDC=None): """ Performs update of the displayed image on the GUI canvas, using the supplied device context. If drawDC is None, a ClientDC will be used to redraw the image. """ DEBUG_MSG("gui_repaint()", 1, self) if self.IsShownOnScreen(): if drawDC is None: drawDC=wx.ClientDC(self) drawDC.BeginDrawing() drawDC.DrawBitmap(self.bitmap, 0, 0) drawDC.EndDrawing() #wx.GetApp().Yield() else: pass
Example #17
Source File: PDFLinkMaint.py From PyMuPDF-Utilities with GNU General Public License v3.0 | 5 votes |
def redraw_bitmap(self): """Refresh bitmap image.""" w = self.bitmap.Size[0] h = self.bitmap.Size[1] x = y = 0 rect = wx.Rect(x, y, w, h) bm = self.bitmap.GetSubBitmap(rect) dc = wx.ClientDC(self.PDFimage) # make a device control out of img dc.DrawBitmap(bm, x, y) # refresh bitmap before draw return
Example #18
Source File: CustomTree.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: Viewer.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
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()) self.Editor.DoPrepareDC(dc) dc.SetUserScale(self.ViewScale[0], self.ViewScale[1]) return dc
Example #20
Source File: backend_wx.py From twitter-stock-recommendation with MIT License | 5 votes |
def draw_rubberband(self, x0, y0, x1, y1): # Use an Overlay to draw a rubberband-like bounding box. if self.wxoverlay is None: self.wxoverlay = wx.Overlay() dc = wx.ClientDC(self.canvas) odc = wx.DCOverlay(self.wxoverlay, dc) odc.Clear() dc = wx.GCDC(dc) height = self.canvas.figure.bbox.height y1 = height - y1 y0 = height - y0 if y1 < y0: y0, y1 = y1, y0 if x1 < x0: x0, x1 = x1, x0 w = x1 - x0 h = y1 - y0 rect = wx.Rect(x0, y0, w, h) rubberBandColor = '#C0C0FF' # or load from config? # Set a pen for the border color = wxc.NamedColour(rubberBandColor) dc.SetPen(wx.Pen(color, 1)) # use the same color, plus alpha for the brush r, g, b, a = color.Get(True) color.Set(r, g, b, 0x60) dc.SetBrush(wx.Brush(color)) if wxc.is_phoenix: dc.DrawRectangle(rect) else: dc.DrawRectangleRect(rect)
Example #21
Source File: CustomTree.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: Main_Dialog.py From topoflow with MIT License | 5 votes |
def Plotting_Test(self): #-------------------------------------------------------- # Note: We may need to save the window's bitmap in a # buffer and refresh it on certain events. # As it stands now, moving the cursor to another # window causes window contents to be lost, # even if we use the Freeze() method. #-------------------------------------------------------- window = self.plot_window nx = self.window_nx ny = self.window_ny # win_buffer = self.plot_buffer win_buffer = wx.EmptyBitmap(nx,ny) #--------------------------------------------- # Create a device context (don't store them) #--------------------------------------------- dc = wx.BufferedDC(wx.ClientDC(window)) ## dc = wx.BufferedDC(wx.ClientDC(window), win_buffer) ## dc = wx.ClientDC(window) # (also works) ## dc = wx.WindowDC(window) # (also works) pen = wx.Pen("black", 2, wx.SOLID) brush = wx.Brush("white", wx.SOLID) # (for filling in areas) dc.SetPen(pen) dc.SetBrush(brush) dc.SetBackground(brush) dc.Clear() #------------------------------------------ dc.DrawRectangle(0,0,nx,ny) dc.DrawLine(0,0,nx,ny) dc.DrawCircle(nx/2,ny/2, nx/3) # print 'dc.GetSize() =', dc.GetSize() ## window.Freeze() # (see also window.Thaw() ) ## window.Disable() # Plotting_Test() #----------------------------------------------------------------
Example #23
Source File: GraphicCommons.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
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
Example #24
Source File: edit_base.py From wxGlade with MIT License | 5 votes |
def on_erase_background(self, event): dc = event.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.widget.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) self._draw_background(dc, clear=False)
Example #25
Source File: ListCtrl.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def OnEraseBackground(self, event=None): nsp = self.GetScrollPos(wx.VERTICAL) if self._last_scrollpos != nsp: self._last_scrollpos = nsp # should only refresh visible items, hmm wx.CallAfter(self.Refresh) dc = wx.ClientDC(self) # erase the section of the background which is not covered by the # items or the selected column highlighting dc.SetBackground(wx.Brush(self.GetBackgroundColour())) f = self.GetRect() r = wx.Region(0, 0, f.width, f.height) x = self.GetVisibleViewRect() offset = self._get_origin_offset(include_header=True) x.Offset(offset) r.SubtractRect(x) if '__WXMSW__' in wx.PlatformInfo: c = self.GetColumnRect(self.enabled_columns.index(self.selected_column)) r.SubtractRect(c) dc.SetClippingRegionAsRegion(r) dc.Clear() if '__WXMSW__' in wx.PlatformInfo: # draw the selected column highlighting under the items dc.DestroyClippingRegion() r = wx.Region(0, 0, f.width, f.height) r.SubtractRect(x) dc.SetClippingRegionAsRegion(r) dc.SetPen(wx.TRANSPARENT_PEN) hc = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) r = highlight_color(hc.Red()) g = highlight_color(hc.Green()) b = highlight_color(hc.Blue()) hc.Set(r, g, b) dc.SetBrush(wx.Brush(hc)) dc.DrawRectangle(c.x, c.y, c.width, c.height)
Example #26
Source File: wx_plot_points.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def area_expose_cb(self, event): dc = wx.ClientDC(self) def DrawPoints(points): for point in points: dc.DrawPoint(*point) dc.DrawPoints = DrawPoints self.draw_points(dc, *self.points) return True
Example #27
Source File: wxTableExtract.py From PyMuPDF-Utilities with GNU General Public License v3.0 | 5 votes |
def DrawRect(self, x, y, w, h): # Draw a rectangle (red border, transparent interior) dc = wx.ClientDC(self.PDFimage) # make a device control out of img dc.SetPen(wx.Pen("RED")) dc.SetBrush(wx.Brush("RED", style=wx.BRUSHSTYLE_TRANSPARENT)) self.redraw_bitmap() dc.DrawRectangle(x, y, w, h)
Example #28
Source File: PDFLinkMaint.py From PyMuPDF-Utilities with GNU General Public License v3.0 | 5 votes |
def draw_links(self): dc = wx.ClientDC(self.PDFimage) dc.SetPen(wx.Pen("BLUE", width=1)) dc.SetBrush(wx.Brush("BLUE", style=wx.BRUSHSTYLE_TRANSPARENT)) self.link_rects = [] self.link_bottom_rects = [] self.link_texts = [] for lnk in self.page_links: if lnk.get("update", False): self.enable_update() wxr = self.Rect_to_wxRect(lnk["from"]) dc.DrawRectangle(wxr[0], wxr[1], wxr[2], wxr[3]) self.link_rects.append(wxr) p = wxr.BottomRight br = wx.Rect(p.x - self.sense, p.y - self.sense, 2*self.sense, 2*self.sense) self.link_bottom_rects.append(br) if lnk["kind"] == fitz.LINK_GOTO: if lnk["page"] >= 0: txt = "page " + str(lnk["page"] + 1) else: txt = "name " + str(lnk["to"]) elif lnk["kind"] == fitz.LINK_GOTOR: txt = lnk["file"] if lnk["page"] >= 0: txt += " p. " + str(lnk["page"] + 1) else: txt += "(" + str(lnk["to"]) + ")" elif lnk["kind"] == fitz.LINK_URI: txt = lnk["uri"] elif lnk["kind"] == fitz.LINK_LAUNCH: txt = "open " + lnk["file"] elif lnk["kind"] == fitz.LINK_NONE: txt = "none" else: txt = "unkown destination" self.link_texts.append(txt) return
Example #29
Source File: wxTableExtract.py From PyMuPDF-Utilities with GNU General Public License v3.0 | 5 votes |
def redraw_bitmap(self): w = self.bitmap.Size[0] h = self.bitmap.Size[1] x = y = 0 rect = wx.Rect(x, y, w, h) bm = self.bitmap.GetSubBitmap(rect) dc = wx.ClientDC(self.PDFimage) # make a device control out of img dc.DrawBitmap(bm, x, y) # refresh bitmap before draw return
Example #30
Source File: backend_wx.py From ImageFusion with MIT License | 5 votes |
def draw_rubberband(self, event, x0, y0, x1, y1): # Use an Overlay to draw a rubberband-like bounding box. dc = wx.ClientDC(self.canvas) odc = wx.DCOverlay(self.wxoverlay, dc) odc.Clear() # Mac's DC is already the same as a GCDC, and it causes # problems with the overlay if we try to use an actual # wx.GCDC so don't try it. if 'wxMac' not in wx.PlatformInfo: dc = wx.GCDC(dc) height = self.canvas.figure.bbox.height y1 = height - y1 y0 = height - y0 if y1<y0: y0, y1 = y1, y0 if x1<y0: x0, x1 = x1, x0 w = x1 - x0 h = y1 - y0 rect = wx.Rect(x0, y0, w, h) rubberBandColor = '#C0C0FF' # or load from config? # Set a pen for the border color = wx.NamedColour(rubberBandColor) dc.SetPen(wx.Pen(color, 1)) # use the same color, plus alpha for the brush r, g, b = color.Get() color.Set(r,g,b, 0x60) dc.SetBrush(wx.Brush(color)) dc.DrawRectangleRect(rect)