def OnMouseMove(self, evt): if not self.HasCapture(): return rect = wx.RectPP(self.startPos, evt.GetPosition()) # Draw the rubber-band rectangle using an overlay so it # will manage keeping the rectangle and the former window # contents separate. dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() pen = wx.Pen("black", 2) brush = wx.Brush(wx.Color(192, 192, 192, 128)) if "wxMac" in wx.PlatformInfo: dc.SetPen(pen) dc.SetBrush(brush) dc.DrawRectangleRect(rect) else: # use a GC on Windows (and GTK?) # this crashed on the Mac ctx = wx.GraphicsContext_Create(dc) ctx.SetPen(pen) ctx.SetBrush(brush) ctx.DrawRectangle(*rect) del odc # work around a bug in the Python wrappers to make
def SnipPart(self, evt): self.bResize = False if self.bHideCurrent: self.Iconize(True) # minimize current window else: self.Iconize(False) # keep current window show dlg = select_area_dialog.SelectArea(self) result = dlg.ShowModal() dlg.Destroy() print(self.startPoint, self.endPoint) if result == wx.OK: rect = wx.RectPP(self.startPoint, self.endPoint) scrDC = wx.ScreenDC() if rect: self.imageOfBitmap = wx.EmptyBitmap(rect.size[0], rect.size[1]) mem = wx.MemoryDC(self.imageOfBitmap) mem.Blit(0, 0, rect.size[0], rect.size[1], scrDC, rect.GetX(), rect.GetY()) del mem self.SetClientSizeWH(rect.size[0] + 200, rect.size[1] + 100) self.Refresh() self.Iconize(False) # restore app window self.isSaved = False self.menuBar.Enable(const.ID_FILE_SAVE, True) else: self.Iconize(False)
def mouse_up(self, evt, wx_obj=None): "Release the selected object (pass a wx_obj if the event was captured)" self.resizing = False if self.current: wx_obj = self.current if self.parent.wx_obj.HasCapture(): self.parent.wx_obj.ReleaseMouse() self.current = None if self.overlay: # When the mouse is released we reset the overlay and it # restores the former content to the window. dc = wx.ClientDC(wx_obj) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() del odc self.overlay.Reset() self.overlay = None pos = evt.GetPosition() # convert to relative client coordinates of the container: if evt.GetEventObject() != wx_obj: pos = evt.GetEventObject().ClientToScreen(pos) # frame pos = wx_obj.ScreenToClient(pos) # panel # finish the multiple selection using the mouse: rect = wx.RectPP(self.pos, pos) for obj in wx_obj.obj: # only check child controls (not menubar/statusbar) if isinstance(obj, Control): obj_rect = obj.wx_obj.GetRect() if rect.ContainsRect(obj_rect): self.select(obj, keep_selection=True) self.pos = None if self.inspector and wx_obj: self.inspector.inspect(wx_obj.obj) if DEBUG: print "SELECTION", self.selection
def GetColumnRect(self, col): x0, x1 = self._GetColumnWidthExtent(col) r = self.GetItemRect(0) y0 = r.y y1 = self.GetClientSize()[1] x_scroll = self.GetScrollPos(wx.HORIZONTAL) return wx.RectPP(wx.Point(x0 - x_scroll, y0), wx.Point(x1 - x_scroll, y1))
def GetCellRect(self, row, col): x0, x1 = self._GetColumnWidthExtent(col) r = self.GetItemRect(row) y0 = r.y y1 = r.GetBottom() x_scroll = self.GetScrollPos(wx.HORIZONTAL) return wx.RectPP(wx.Point(x0 - x_scroll, y0), wx.Point(x1 - x_scroll, y1))
def OnLeftUp(self, evt): if not self.HasCapture(): return self.ReleaseMouse() self.permRect = wx.RectPP(self.selectionStart, evt.Position) self.selectionStart = None #clear out any existing drawing self.overlay.Reset() self.Refresh()
def redraw_rectangle(self, pos): rect = wx.RectPP(self.start_pos, pos) dc = wx.ClientDC(self.mplayer) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() dc.SetPen(wx.Pen(wx.RED, 1, wx.SOLID)) dc.SetBrush(wx.Brush("grey", style=wx.TRANSPARENT)) dc.DrawRectangleRect(rect) del odc #bug in python, this makes sure odc destroyed before dc
def OnMotion(self, evt): if not self.HasCapture(): return dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() ctx = wx.GraphicsContext_Create(dc) ctx.SetPen(wx.GREY_PEN) ctx.SetBrush(wx.Brush(wx.Color(192, 192, 192, 128))) ctx.DrawRectangle(*wx.RectPP(self.selectionStart, evt.Position)) del odc
def popup(self, event): assert (len(mouse_over)) == 1, "Only one thing can have mouse over" name, (pane, rect, title, clipping_rect) = mouse_over.items()[0] if not self.pane_can_be_seen(pane): event.Skip() return frames = [frame for frame, f_title in self.panes if f_title == name] assert len(frames) == 1, "Wrong frame count: %s (%r)" % (name, frames) frame = frames[0] keytext = frame.reference if not isinstance(keytext, basestring): keytext = keytext.text # find the intersection of the clipping rect and the actual rect # this will be the actual rectangle the user can see. r = wx.RectPP(( max(rect[0], clipping_rect[0]), max(rect[1], clipping_rect[1]), ), ( min(rect.Right, clipping_rect.Right), min(rect.Bottom, clipping_rect.Bottom), )) p = ModulePopup(self, event, r, frame.book, keytext) # use the main frame to grab the mouse wheel events, as wxPopupWindow # cannot have focus, nor any of its children # This isn't needed under gtk, as the scroll wheel will automatically # select the window underneath for scrolling if osutils.is_msw(): self.SetFocus() self.Bind(wx.EVT_MOUSEWHEEL, p.box.on_mouse_wheel) def on_dismiss(chosen): if not r.Contains(self.ScreenToClient(wx.GetMousePosition())): self.clear_over_list() if chosen is not None: frame.book.SetModule(p.box.modules[chosen]) if osutils.is_msw(): self.Unbind(wx.EVT_MOUSEWHEEL) wx.CallAfter(p.Destroy) p.on_dismiss += on_dismiss p.Popup()
def OnMotion(self, evt): if not self.HasCapture(): return dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() if 'phoenix' in wx.version(): ctx = wx.GraphicsContext.Create(dc) else: ctx = wx.GraphicsContext_Create(dc) ctx.SetPen(wx.GREY_PEN) ctx.SetBrush(wx.Brush(wx.Colour(192, 192, 192, 128))) if 'phoenix' in wx.version(): ctx.DrawRectangle(self.selectionStart[0], self.selectionStart[0], evt.Position[0], evt.Position[1]) else: ctx.DrawRectangle(*wx.RectPP(self.selectionStart, evt.Position)) del odc
def OnMouseMove(self, evt): if evt.Dragging() and evt.LeftIsDown(): rect = wx.RectPP(self.startPos, evt.GetPosition()) # Draw the rubber-band rectangle using an overlay so it # will manage keeping the rectangle and the former window # contents separate. dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() dc.SetPen(wx.Pen("black", 2)) if 'wxMac' in wx.PlatformInfo: dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80))) else: dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangleRect(rect) del odc # work around a bug in the Python wrappers to make
def mouse_move(self, evt): "Move the selected object" if DEBUG: print "move!" if self.current and not self.overlay: wx_obj = self.current sx, sy = self.start x, y = wx.GetMousePosition() # calculate the new position (this will overwrite relative dimensions): x, y = (x + sx, y + sy) if evt.ShiftDown(): # snap to grid: x = x / GRID_SIZE[0] * GRID_SIZE[0] y = y / GRID_SIZE[1] * GRID_SIZE[1] # calculate the diff to use in the rest of the selected objects: ox, oy = wx_obj.obj.pos dx, dy = (x - ox), (y - oy) # move all selected objects: for obj in self.selection: x, y = obj.pos x = x + dx y = y + dy obj.pos = (wx.Point(x, y)) elif self.overlay: wx_obj = self.current pos = evt.GetPosition() # convert to relative client coordinates of the containter: if evt.GetEventObject() != wx_obj: pos = evt.GetEventObject().ClientToScreen(pos) # frame pos = wx_obj.ScreenToClient(pos) # panel rect = wx.RectPP(self.pos, pos) # Draw the rubber-band rectangle using an overlay so it # will manage keeping the rectangle and the former window # contents separate. dc = wx.ClientDC(wx_obj) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() dc.SetPen(wx.Pen("blue", 2)) if 'wxMac' in wx.PlatformInfo: dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80))) else: dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangleRect(rect) del odc # work around a bug in the Python wrappers to make
def OnMouseMove(self, evt): if evt.Dragging() and evt.LeftIsDown(): rect = wx.RectPP(self.startPos, evt.GetPosition()) # Draw the rubber-band rectangle using an overlay so it # will manage keeping the rectangle and the former window # contents separate. dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, 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) dc.SetPen(wx.Pen("black", 2)) dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80))) dc.DrawRectangleRect(rect)
def OnPrintPage(self, page): dc = self.GetDC() self.CalculateScale(dc) self.CalculateLayout(dc) dc.SetPen(wx.Pen('black', 0)) dc.SetBrush(wx.TRANSPARENT_BRUSH) r = wx.RectPP((self.x1, self.y1), (self.x2, self.y2)) dc.DrawRectangleRect(r) dc.SetClippingRect(r) line = (page - 1) * self.linesPerPage x = self.x1 + self.logUnitsMM y = self.y1 + self.logUnitsMM while line < (page * self.linesPerPage): dc.DrawText(self.lines[line], x, y) y += self.lineHeight line += 1 if line >= len(self.lines): break return True
def mouseDrag(self, event, imgCtrl): if event.Dragging(): x = event.GetX() y = event.GetY() rect = wx.RectPP((self.startX, self.startY), (x, y)) dc = wx.ClientDC(imgCtrl) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() dc.SetPen(wx.Pen("black", 2)) if 'wxMac' in wx.PlatformInfo: dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80))) else: dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangleRect(rect) del odc '''
def OnPrintPage(self, page): '''OnPrintPage''' # Imprimimos una página. dc = self.GetDC() self.CalculateScale(dc) self.CalculateLayout(dc) # Dibujamos el contorno de página. dc.SetPen(wx.Pen("black", 0)) dc.SetBrush(wx.TRANSPARENT_BRUSH) r = wx.RectPP((self.x1, self.y1), (self.x2, self.y2)) dc.DrawRectangleRect(r) dc.SetClippingRect(r) # Se dibuja las líneas de texto para esta página. line = (page - 1) * self.linesPerPage x = self.x1 + self.logUnitsMM y = self.y1 + self.logUnitsMM while line < (page * self.linesPerPage): dc.DrawText(self.lines[line], x, y) y += self.lineHeight line += 1 if line >= len(self.lines): break return True
def OnPrintPage(self, page): dc = self.GetDC() self.CalculateScale(dc) self.CalculateLayout(dc) # draw a page outline at the margin points dc.SetPen(wx.Pen("black", 0)) dc.SetBrush(wx.TRANSPARENT_BRUSH) r = wx.RectPP((self.x1, self.y1), (self.x2, self.y2)) dc.DrawRectangleRect(r) dc.SetClippingRect(r) # Draw the text lines for this page line = (page - 1) * self.linesPerPage x = self.x1 + self.logUnitsMM y = self.y1 + self.logUnitsMM while line(page * self.linesPerPage): dc.DrawText(self.lines[line], x, y) y += self.lineHeight line += 1 if line == len(self.lines): break return True
def draw(self, dc, size): s_rect = wx.Rect(0, 0, size.width, size.height) elements = list(self.history.upload_data) + list( self.history.download_data) max_data = max(elements + [self.MIN_MAX_DATA]) interval = self.history.interval / 1000 seconds = self.history.max_len * interval time_label_text = "%d" % seconds + _(" seconds, ") time_label_text += str(interval) + _(" second interval") dr_label_text = _("Download rate") ur_label_text = _("Upload rate") text_color = wx.NamedColour("light gray") border_color = wx.NamedColour("gray") dr_color = wx.NamedColor("green") ur_color = wx.NamedColor("slate blue") size = 8 if sys.platform == "darwin": size = 10 dc.SetFont(wx.Font(size, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() if (self.max_label_width == None): self.max_label_width = dc.GetTextExtent(unicode( Rate(1000000.0)))[0] self.max_label_width = max( self.max_label_width, dc.GetTextExtent(unicode(Rate(max_data)))[0]) top_label_height = dc.GetTextExtent(unicode(Rate(max_data)))[1] bottom_label_height = dc.GetTextExtent(unicode(Rate(0.0)))[1] time_label_width = dc.GetTextExtent(unicode(time_label_text))[0] time_label_height = dc.GetTextExtent(unicode(time_label_text))[1] dr_label_width = dc.GetTextExtent(unicode(dr_label_text))[0] dr_label_height = dc.GetTextExtent(unicode(dr_label_text))[1] ur_label_width = dc.GetTextExtent(unicode(ur_label_text))[0] ur_label_height = dc.GetTextExtent(unicode(ur_label_text))[1] label_spacer = 4 b_spacer = 15 legend_box_size = 10 legend_guts_height = max( (legend_box_size, ur_label_height, dr_label_height)) legend_height = legend_guts_height + b_spacer x1 = b_spacer y1 = b_spacer x2 = max( x1, s_rect.GetRight() - (label_spacer + self.max_label_width + label_spacer)) y2 = max( y1 + top_label_height + SPACING + bottom_label_height, s_rect.GetBottom() - (label_spacer + time_label_height + label_spacer + legend_height)) b_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = b_spacer + b_spacer y1 = max((b_rect.GetBottom() + label_spacer + time_label_height + label_spacer), s_rect.GetBottom() - (legend_box_size + b_spacer)) x2 = x1 + legend_box_size y2 = y1 + legend_box_size db_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = db_rect.GetRight() + label_spacer + dr_label_width + b_spacer y1 = db_rect.y x2 = x1 + legend_box_size y2 = y1 + legend_box_size ub_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = min(b_rect.x + 1, b_rect.GetRight()) y1 = min(b_rect.y + 1, b_rect.GetBottom()) x2 = max(x1, b_rect.GetRight() - 1) y2 = max(y1, b_rect.GetBottom() - 1) i_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) bw_label_x = b_rect.GetRight() + label_spacer time_label_x = max(b_rect.x, (b_rect.GetRight() / 2) - (time_label_width / 2)) dc.SetTextForeground(text_color) dc.DrawText(unicode(Rate(max_data)), bw_label_x, b_rect.y) dc.DrawText(unicode(Rate(0.0)), bw_label_x, b_rect.GetBottom() - bottom_label_height) dc.DrawText(unicode(time_label_text), time_label_x, b_rect.GetBottom() + label_spacer) dc.DrawText(unicode(dr_label_text), db_rect.GetRight() + label_spacer, db_rect.y + (legend_box_size / 2) - (dr_label_height / 2)) dc.DrawText(unicode(ur_label_text), ub_rect.GetRight() + label_spacer, ub_rect.y + (legend_box_size / 2) - (ur_label_height / 2)) pen = wx.Pen(border_color, 1, wx.SOLID) dc.SetPen(pen) brush = wx.Brush(dr_color) dc.SetBrush(brush) dc.DrawRectangle(db_rect.x, db_rect.y, db_rect.GetWidth(), db_rect.GetHeight()) brush = wx.Brush(ur_color) dc.SetBrush(brush) dc.DrawRectangle(ub_rect.x, ub_rect.y, ub_rect.GetWidth(), ub_rect.GetHeight()) dc.DrawLine(b_rect.x, b_rect.y, b_rect.GetRight(), b_rect.y) dc.DrawLine(b_rect.x, b_rect.y, b_rect.x, b_rect.GetBottom()) dc.DrawLine(b_rect.x, b_rect.GetBottom(), b_rect.GetRight(), b_rect.GetBottom()) dc.DrawLine(b_rect.GetRight(), b_rect.y, b_rect.GetRight(), b_rect.GetBottom()) pen = wx.Pen(border_color, 1, wx.DOT) dc.SetPen(pen) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.75), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.75)) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.5), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.5)) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.25), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.25)) pen = wx.Pen(ur_color, 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.max_upload_rate, max_data, i_rect, offset=3) pen = wx.Pen(ur_color, 1, wx.SOLID) dc.SetPen(pen) self.draw_graph(dc, self.history.max_len, self.history.upload_data, max_data, i_rect) pen = wx.Pen(dr_color, 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.max_download_rate, max_data, i_rect) pen = wx.Pen(dr_color, 1, wx.SOLID) dc.SetPen(pen) self.draw_graph(dc, self.history.max_len, self.history.download_data, max_data, i_rect) ## variance line if wx.the_app.config['show_variance_line']: pen = wx.Pen(wx.NamedColor("yellow"), 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.variance, self.history.max_variance, i_rect)
def _drawObject(self, robj): """!Draw given object to the device The object is defined as robject() from vedit.h. @param robj object to be rendered @return 1 on success @return -1 on failure (vector feature marked as dead, etc.) """ if not self.dc or not self.dcTmp: return -1 Debug.msg(3, "_drawObject(): line=%d type=%d npoints=%d", robj.fid, robj.type, robj.npoints) brush = None if self._isSelected(robj.fid): pdc = self.dcTmp if robj.type == TYPE_AREA: return 1 else: if self.settings['highlightDupl']['enabled'] and self._isDuplicated(robj.fid): pen = wx.Pen(self.settings['highlightDupl']['color'], self.settings['lineWidth'], wx.SOLID) else: pen = wx.Pen(self.settings['highlight'], self.settings['lineWidth'], wx.SOLID) dcId = 1 self.topology['highlight'] += 1 if not self._drawSelected: return else: pdc = self.dc pen, brush = self._definePen(robj.type) dcId = 0 pdc.SetPen(pen) if brush: pdc.SetBrush(brush) if robj.type & (TYPE_POINT | TYPE_CENTROIDIN | TYPE_CENTROIDOUT | TYPE_CENTROIDDUP | TYPE_NODEONE | TYPE_NODETWO | TYPE_VERTEX): # -> point if dcId > 0: if robj.type == TYPE_VERTEX: dcId = 3 # first vertex elif robj.type & (TYPE_NODEONE | TYPE_NODETWO): if self.firstNode: dcId = 1 self.firstNode = False else: dcId = self.lastNodeId for i in range(robj.npoints): p = robj.point[i] if dcId > 0: pdc.SetId(dcId) dcId += 2 self._drawCross(pdc, p) else: if dcId > 0 and self._drawSegments: self.fisrtNode = True self.lastNodeId = robj.npoints * 2 - 1 dcId = 2 # first segment i = 0 while i < robj.npoints - 1: point_beg = wx.Point(robj.point[i].x, robj.point[i].y) point_end = wx.Point(robj.point[i+1].x, robj.point[i+1].y) pdc.SetId(dcId) # set unique id & set bbox for each segment pdc.SetPen(pen) pdc.SetIdBounds(dcId - 1, wx.Rect(point_beg.x, point_beg.y, 0, 0)) pdc.SetIdBounds(dcId, wx.RectPP(point_beg, point_end)) pdc.DrawLine(point_beg.x, point_beg.y, point_end.x, point_end.y) i += 1 dcId += 2 pdc.SetIdBounds(dcId - 1, wx.Rect(robj.point[robj.npoints - 1].x, robj.point[robj.npoints - 1].y, 0, 0)) else: points = list() for i in range(robj.npoints): p = robj.point[i] points.append(wx.Point(p.x, p.y)) if robj.type == TYPE_AREA: pdc.DrawPolygon(points) else: pdc.DrawLines(points)