def __init__(self, parent, id=-1, size=wx.DefaultSize): wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER) self.lines = [] self.maxWidth = 2000 self.maxHeight = 2000 self.x = self.y = 0 self.curLine = [] self.drawing = False self.SetBackgroundColour("WHITE") #self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) #bmp = images.Test2.GetBitmap() img = wx.Image("Images/fish1.png", wx.BITMAP_TYPE_ANY) bmp = img.ConvertToBitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) self.bmp = bmp self.SetVirtualSize((self.maxWidth, self.maxHeight)) #self.SetScrollRate(20,20) self.SetScrollRate(1, 1) # ANDY self.andyscale = 1.0 if BUFFERED: # Initialize the buffer bitmap. No real DC is needed at this point. self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight) dc = wx.BufferedDC(None, self.buffer) dc.SetUserScale(self.andyscale, self.andyscale) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() self.DoDrawing(dc) if ALLOW_DRAWING: self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftButtonEvent) self.Bind(wx.EVT_LEFT_UP, self.OnLeftButtonEvent) self.Bind(wx.EVT_MOTION, self.OnLeftButtonEvent) self.Bind(wx.EVT_PAINT, self.OnPaint) # ANDY self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase) # ANDY self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel) # ANDY self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel2) # ANDY self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) # ANDY self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) # ANDY self.Bind(wx.EVT_MOTION, self.OnMove) # ANDY self.was_dragging = False # True if dragging map self.move_dx = 0 # drag delta values self.move_dy = 0 self.last_drag_x = None # previous drag position self.last_drag_y = None self.SetScrollbars(1, 1, 2000, 2000) self.Bind(wx.EVT_KEY_DOWN, self.onKeyPress) self.Bind(wx.EVT_KEY_UP, self.onKeyUp) self.andywheelScroll = 0
def onPaint(self, evt): #print "TRACE: onPaint" if self.curMillis == None: self.curMillis = self.millisAtLastPaint = int( round(time.time() * 1000)) else: self.curMillis = int(round(time.time() * 1000)) # elapsedMs are the MS since the last paint event. We use this to increment LP rotation. elapsedMs = float(self.curMillis - self.millisAtLastPaint) #print "TRACE: elapsedMs is ", elapsedMs # rotation factor since last paint. radRotateFactor = ((math.pi * 2.0) * (self.rotationsPerSecond * elapsedMs * 0.001)) if self.curRotateFactor == None: self.curRotateFactor = 0 elif self.drop and self.motorOn: self.curRotateFactor += radRotateFactor # update the revolution counter. self.revCountCtrl.SetValue( 'rev ' + str(round(self.curRotateFactor / (math.pi * 2), 1))) w, h = self.GetSize() # ajust the width and height such that they are slightly smaller than the entire container h = w w -= (w / 12) h -= (h / 12) dc = wx.AutoBufferedPaintDC(self) # draw the vinyl album. dc.SetBrush(wx.Brush("#222222")) dc.DrawEllipse(0, 0, w, h) # draw the label of the vinyl album labelW = w / 3.2 middleXPos = w / 2 middleYPos = h / 2 dc.SetBrush(wx.Brush("#FFFFFF")) dc.DrawEllipse(0 + middleXPos - labelW / 2, 0 + middleYPos - labelW / 2, labelW, labelW) # draw the spindle hole of the vinyl album spindleW = labelW / 8 dc.SetBrush(wx.Brush("#000000")) dc.DrawEllipse(0 + middleXPos - spindleW / 2, 0 + middleYPos - spindleW / 2, spindleW, spindleW) #draw the teal radius guide lines dc.SetPen(wx.Pen("#00FFFF")) for i in range(0, 12): rads = i * ((2 * math.pi) / 12) startXLinePos = math.cos(rads + self.curRotateFactor) * ( labelW / 2) + middleXPos startYLinePos = math.sin(rads + self.curRotateFactor) * ( labelW / 2) + middleYPos endXLinePos = math.cos(rads + self.curRotateFactor) * (w / 2) + middleXPos endYLinePos = math.sin(rads + self.curRotateFactor) * (w / 2) + middleYPos if (i != 11): pass #disabled the sectional indicators for now, there were some refresh issues # that were visually distracting. #dc.DrawLine(startXLinePos, startYLinePos, endXLinePos, endYLinePos) else: # draw a special red marker that marks the beginning of the sample # (at 2:00 o'clock, 11th position counterclockwise from horizontal origin). penSize = 3 dc.SetPen(wx.Pen("#FF0000", penSize)) dc.DrawLine(startXLinePos, startYLinePos, endXLinePos, endYLinePos) dc.SetPen(wx.Pen("#00FFFF", 1)) # reset pen to black, 1 pixel. dc.SetPen(wx.Pen("#000000", 1)) # make sure that millisAtLastPaint is set. self.millisAtLastPaint = self.curMillis
def Draw_all(self, dc): ori = (self.blocksize[0] / 2, self.blocksize[1] / 2) dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.Brush('WHITE')) dc.DrawRectangle(0, 0, self.size[0], self.size[1]) # draw horizontal and vertical roads pos = copy.copy(ori) dc.SetBrush(wx.Brush('GREY')) for i in range(self.m): dc.DrawRectangle( pos[0], pos[1] + (i + 1) * self.blocksize[1] - self.roadwidth / 2, self.blocksize[0] * (self.n + 1), self.roadwidth) for j in range(self.n): dc.DrawRectangle( (j + 1) * self.blocksize[0] - self.roadwidth / 2 + pos[0], pos[1], self.roadwidth, self.blocksize[1] * (self.m + 1)) # draw turnings pen = wx.Pen('GREY', 2 * self.roadwidth, wx.PENSTYLE_SOLID) pen.SetCap(wx.CAP_ROUND) dc.SetPen(pen) for i in range(self.m): for j in range(self.n): pos = [ ori[0] + (j + 1) * self.blocksize[0], ori[1] + (i + 1) * self.blocksize[1] ] if np.mod((i + j), 2) == 0: dc.DrawLine(pos[0] - self.blocksize[0] / 4, pos[1] - self.roadwidth / 2, pos[0] - self.roadwidth, pos[1] - self.roadwidth / 2) dc.DrawLine(pos[0] - self.roadwidth / 2, pos[1] - self.blocksize[1] / 4, pos[0] - self.roadwidth / 2, pos[1] - self.roadwidth) dc.DrawLine(pos[0] + self.blocksize[0] / 4, pos[1] + self.roadwidth / 2, pos[0] + self.roadwidth, pos[1] + self.roadwidth / 2) dc.DrawLine(pos[0] + self.roadwidth / 2, pos[1] + self.blocksize[1] / 4, pos[0] + self.roadwidth / 2, pos[1] + self.roadwidth) else: dc.DrawLine(pos[0] + self.blocksize[0] / 4, pos[1] - self.roadwidth / 2, pos[0] + self.roadwidth, pos[1] - self.roadwidth / 2) dc.DrawLine(pos[0] + self.roadwidth / 2, pos[1] - self.blocksize[1] / 4, pos[0] + self.roadwidth / 2, pos[1] - self.roadwidth) dc.DrawLine(pos[0] - self.blocksize[0] / 4, pos[1] + self.roadwidth / 2, pos[0] - self.roadwidth, pos[1] + self.roadwidth / 2) dc.DrawLine(pos[0] - self.roadwidth / 2, pos[1] + self.blocksize[1] / 4, pos[0] - self.roadwidth / 2, pos[1] + self.roadwidth) point_scale = 3.5 for item in self.points: dc.SetPen(wx.Pen("Black", 1)) dc.SetBrush(wx.Brush('Green')) dc.DrawCircle(item[3][0], item[3][1], point_scale) # Whether carring good if item[5][0] == 0: dc.SetPen(wx.Pen("Black", style=wx.PENSTYLE_TRANSPARENT)) dc.SetBrush(wx.Brush('Red')) dc.DrawCircle(item[3][0], item[3][1], point_scale * 0.9) '''
def paint(self, event): """Paints marquee selection, widget connectors, and widgets onscreen.""" # do NOT call self.DoPrepareDC() no matter what the docs may say # we already take into account our scroll origin in our # toPixels() method # OS X already double buffers drawing for us; if we try to do it # ourselves, performance is horrendous if sys.platform == 'darwin': gc = wx.PaintDC(self) else: gc = wx.BufferedPaintDC(self) updateRect = self.updateVisableRectsAndReturnUpdateRegion() # background gc.SetBrush(wx.Brush(StoryPanel.FLAT_BG_COLOR if self.app.config.ReadBool('flatDesign') else StoryPanel.BACKGROUND_COLOR)) gc.DrawRectangle(updateRect.x - 1, updateRect.y - 1, updateRect.width + 2, updateRect.height + 2) # connectors arrowheads = (self.scale > StoryPanel.ARROWHEAD_THRESHOLD) lineDictonary = defaultdict(list) arrowDictonary = defaultdict(list) if arrowheads else None displayArrows = self.app.config.ReadBool('displayArrows') imageArrows = self.app.config.ReadBool('imageArrows') flatDesign = self.app.config.ReadBool('flatDesign') for widget in self.visibleWidgets: if not widget.dimmed: widget.addConnectorLinesToDict(displayArrows, imageArrows, flatDesign, lineDictonary, arrowDictonary, updateRect) for (color, width) in lineDictonary.iterkeys(): gc.SetPen(wx.Pen(color, width)) lines = list(izip(*[iter(chain(*lineDictonary[(color, width)]))] * 4)) gc.DrawLineList(lines) if arrowheads: for (color, width) in arrowDictonary.iterkeys(): gc.SetPen(wx.Pen(color, width)) arrows = arrowDictonary[(color, width)] if self.app.config.ReadBool('flatDesign'): gc.SetBrush(wx.Brush(color)) gc.DrawPolygonList(arrows) else: lines = list(self.arrowPolygonsToLines(arrows)) gc.DrawLineList(lines) for widget in self.visibleWidgets: # Could be "visible" only insofar as its arrow is visible if updateRect.Intersects(widget.getPixelRect()): widget.paint(gc) # marquee selection # with slow drawing, use alpha blending for interior if self.draggingMarquee: if self.app.config.ReadBool('fastStoryPanel'): gc.SetPen(wx.Pen('#ffffff', 1, wx.DOT)) gc.SetBrush(wx.Brush(wx.WHITE, wx.TRANSPARENT)) else: gc = wx.GraphicsContext.Create(gc) marqueeColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) gc.SetPen(wx.Pen(marqueeColor)) r, g, b = marqueeColor.Get(False) marqueeColor = wx.Colour(r, g, b, StoryPanel.MARQUEE_ALPHA) gc.SetBrush(wx.Brush(marqueeColor)) gc.DrawRectangle(self.dragRect.x, self.dragRect.y, self.dragRect.width, self.dragRect.height)
def drawFlowRoutine(self, dc, routine, id, pos=[0, 0], draw=True): """Draw a box to show a routine on the timeline draw=False is for a dry-run, esp to compute and return size without drawing or setting a pdc ID """ name = routine.name if self.appData['flowSize'] == 0 and len(name) > 5: name = ' ' + name[:4] + '..' else: name = ' ' + name + ' ' if draw: dc.SetId(id) font = self.GetFont() if sys.platform == 'darwin': fontSizeDelta = (9, 6, 0)[self.appData['flowSize']] font.SetPointSize(1400 / self.dpi - fontSizeDelta) elif sys.platform.startswith('linux'): fontSizeDelta = (6, 4, 0)[self.appData['flowSize']] font.SetPointSize(1400 / self.dpi - fontSizeDelta) else: fontSizeDelta = (8, 4, 0)[self.appData['flowSize']] font.SetPointSize(1000 / self.dpi - fontSizeDelta) maxTime, nonSlip = routine.getMaxTime() if routine.params['disabled']: rgbFill = disabledRoutineFill rgbEdge = disabledRoutineEdge elif nonSlip: rgbFill = nonSlipFill rgbEdge = nonSlipEdge else: rgbFill = relTimeFill rgbEdge = relTimeEdge # get size based on text self.SetFont(font) if draw: dc.SetFont(font) w, h = self.GetFullTextExtent(name)[0:2] pad = (5, 10, 20)[self.appData['flowSize']] # draw box pos[1] += 2 - self.appData['flowSize'] rect = wx.Rect(pos[0], pos[1], w + pad, h + pad) endX = pos[0] + w + pad # the edge should match the text if draw: dc.SetPen( wx.Pen( wx.Colour(rgbEdge[0], rgbEdge[1], rgbEdge[2], wx.ALPHA_OPAQUE))) dc.SetBrush(wx.Brush(rgbFill)) dc.DrawRoundedRectangle(rect, (4, 6, 8)[self.appData['flowSize']]) # draw text dc.SetTextForeground(rgbEdge) dc.DrawLabel(name, rect, alignment=wx.ALIGN_CENTRE) if nonSlip and self.appData['flowSize'] != 0: font.SetPointSize(font.GetPointSize() * 0.6) dc.SetFont(font) _align = wx.ALIGN_CENTRE | wx.ALIGN_BOTTOM dc.DrawLabel("(%.2fs)" % maxTime, rect, alignment=_align) self.componentFromID[id] = routine # set the area for this component dc.SetIdBounds(id, rect) return endX
def drawHandler(self, list, dc): for i in range(len(list)): if list[i][AG.KEYFRAME][AG.SELECT] == 1: X1 = list[i][AG.KEYFRAME][AG.LOCAL_VALUE][0] Y1 = list[i][AG.KEYFRAME][AG.LOCAL_VALUE][1] if self._OneTangent == True: for j in range(3, 5): X = list[i][j][AG.LOCAL_VALUE][0] Y = list[i][j][AG.LOCAL_VALUE][1] if list[i][j][AG.SELECT] == 1: dc.SetPen(wx.Pen("cyan", 3)) dc.SetBrush(wx.Brush("cyan")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("cyan", 1)) dc.DrawLine(X1, Y1, X, Y) if list[i][j][AG.SELECT] == 0: dc.SetPen(wx.Pen("brown", 3)) dc.SetBrush(wx.Brush("brown")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("brown", 1)) dc.DrawLine(X1, Y1, X, Y) if self._OneTangent == False: if list[i][AG.IN_TANGENT][AG.SELECT] == 1: X = list[i][AG.IN_TANGENT][AG.LOCAL_VALUE][0] Y = list[i][AG.IN_TANGENT][AG.LOCAL_VALUE][1] dc.SetPen(wx.Pen("cyan", 3)) dc.SetBrush(wx.Brush("cyan")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("cyan", 1)) dc.DrawLine(X1, Y1, X, Y) if list[i][AG.IN_TANGENT][AG.SELECT] == 0: X = list[i][AG.IN_TANGENT][AG.LOCAL_VALUE][0] Y = list[i][AG.IN_TANGENT][AG.LOCAL_VALUE][1] dc.SetPen(wx.Pen("navy", 3)) dc.SetBrush(wx.Brush("navy")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("navy", 1)) dc.DrawLine(X1, Y1, X, Y) if list[i][AG.OUT_TANGENT][AG.SELECT] == 1: X = list[i][AG.OUT_TANGENT][AG.LOCAL_VALUE][0] Y = list[i][AG.OUT_TANGENT][AG.LOCAL_VALUE][1] dc.SetPen(wx.Pen("cyan", 3)) dc.SetBrush(wx.Brush("cyan")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("cyan", 1)) dc.DrawLine(X1, Y1, X, Y) if list[i][AG.OUT_TANGENT][AG.SELECT] == 0: X = list[i][AG.OUT_TANGENT][AG.LOCAL_VALUE][0] Y = list[i][AG.OUT_TANGENT][AG.LOCAL_VALUE][1] dc.SetPen(wx.Pen("brown", 3)) dc.SetBrush(wx.Brush("brown")) dc.DrawCircle(X, Y, 2) dc.SetPen(wx.Pen("brown", 1)) dc.DrawLine(X1, Y1, X, Y)
def LabelColorRow(self, colour): brush = wx.Brush(colour, wx.SOLID) self.DC.SetBrush(brush) height = self.label_space + self.label_pt_space_before + self.label_pt_space_after self.DC.DrawRectangle(self.column[0], self.y, self.end_x - self.column[0] + 1, height)
def OnPaint(self, event): dc = wx.BufferedPaintDC(self) dc.SetPen(wx.Pen('blue', 2)) dc.SetBrush(wx.Brush('blue')) (width, height) = self.GetSizeTuple() dc.DrawRoundedRectangle(0, 0, width, height, 8)
def OnPaint(self, event): dc = wx.BufferedPaintDC(self) try: dc.BackgroundMode = wx.SOLID background_color = wx.SystemSettings_GetColour( wx.SYS_COLOUR_WINDOW) metadata_color = get_primary_outline_color() selected_background_color = wx.SystemSettings_GetColour( wx.SYS_COLOUR_HIGHLIGHT) selected_color = wx.SystemSettings_GetColour( wx.SYS_COLOUR_HIGHLIGHTTEXT) text_color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT) dc.Background = wx.Brush(background_color) dc.Font = self.Font dc.Clear() if self.native_border: renderer = wx.RendererNative.Get() style = 0 if self.FindFocus() == self: style |= wx.CONTROL_FOCUSED | wx.CONTROL_CURRENT if not self.Enabled: style |= wx.CONTROL_DISABLED renderer.DrawTextCtrl( self, dc, (0, 0, self.ClientSize[0], self.ClientSize[1]), style) dc.SetClippingRect((self.padding, self.padding, self.ClientSize[0] - 2 * self.padding, self.ClientSize[1] - 2 * self.padding)) text = self.get_text(0, len(self.__tokens)) positions = self.get_positions(dc) last_state = "unknown" text_list = [] state_list = [] position_list = [] selection = None if self.selection is not None: selection = list(self.selection) selection.sort() for i, token in enumerate(self.__tokens): if isinstance(token, self.MetadataToken): current_state = "metadata" elif (self.selection != None and i >= selection[0] and i < selection[1]): current_state = "selection" else: current_state = "boring" if current_state != last_state: state_list.append(current_state) text_list.append("") last_state = current_state position_list.append((positions[i], self.padding)) text_list[-1] += self.get_text(i, i + 1) colors = { "boring": (background_color, text_color), "selection": (selected_background_color, selected_color), "metadata": (metadata_color, text_color) } background_color = [colors[state][0] for state in state_list] foreground_color = [colors[state][1] for state in state_list] dc.BackgroundMode = wx.SOLID for text, position, background, foreground in zip( text_list, position_list, background_color, foreground_color): dc.SetTextBackground(background) dc.SetTextForeground(foreground) dc.DrawText(text, position[0], position[1]) finally: dc.Destroy()
def drawBg(self, dc): dc.SetBackground(wx.Brush((250, 248, 239))) dc.Clear() dc.SetBrush(wx.Brush((187, 173, 160))) dc.SetPen(wx.Pen((187, 173, 160))) dc.DrawRoundedRectangle(15, 150, 475, 475, 5)
def RandomBrush(self): c = random.choice(colours) if c not in self.brush_cache: self.brush_cache[c] = wx.Brush(c) return self.brush_cache[c]
def OnPreparePrinting(self): """ Prepare data for printing / previewing """ # If we have a multi-page report, we need to create all of the pages here if self.multiPage: # Determine the dimensions of the Print Device Context (dcWidth, dcHeight) = self.GetDC().GetSizeTuple() # Determine the dimensions for the graphics canvas passed in canvasWidth = self.canvas.getWidth() canvasHeight = self.canvas.getHeight() # The header area to be repeated on each page for the Series Map reports is 48 pixels high. It just is. headerHeight = 48 # Get a graphic of the whole report image. # Create a Bitmap to draw on bigBMP = wx.EmptyBitmap(canvasWidth, canvasHeight) # Create a Device Context for the Bitmap bigDC = wx.BufferedDC(None, bigBMP) # Indicate that we want a solid background, rather than transparent bigDC.SetBackgroundMode(wx.SOLID) # Set the Background to White bigDC.SetBackground(wx.Brush(wx.WHITE)) # Clear the DC bigDC.Clear() # Paint the background bigDC.FloodFill(1, 1, wx.WHITE) # Draw the report object on the DC self.canvas.DrawLines(bigDC) # Saving the bitmap as a graphic can be helpful in debugging! # bigBMP.SaveFile('c:\Documents and Settings\davidwoods\Desktop\TestImage.jpg', wx.BITMAP_TYPE_JPEG) # Create a data structure to hold the page images self.pageBMPs = [] # Initialize a variable for counting the number of pages in the report self.numPages = 0 # We need to count lines in the report to find page break positions. Initialize the line counter. lineCount = 0 # We need to track what pixel in the whole graphic was used for the last page break. # We initialize this to the starting position of the first line in the report. startingPixel = self.lineStart # Now let's create seperate images for each printed page. We keep going until we have # processed all the pixels in the graphic canvas. while startingPixel < canvasHeight: # Increment the page counter. self.numPages += 1 # Calculate the default height for this page, not including the space used for the page header. pageHeight = int( (float(canvasWidth) / dcWidth) * dcHeight) - headerHeight # Create a full-size Bitmap image to hold the graphic for the individual page, including the page header. pageBMP = wx.EmptyBitmap(canvasWidth, pageHeight + headerHeight) # The problem we have to solve here is to figure out EXACTLY where in the graphic to break the page. # We don't want to break in the middle of a line, so we have to figure out where the space between lines # falls. # To start, initialize a page height variable to 0. newPageHeight = 0 # We can move through the graphic one whole line at a time by incrementing the new page height by # the line height. We do this as long as there is room on the page. while self.lineStart + lineCount * self.lineHeight < startingPixel + pageHeight + headerHeight - self.lineStart - self.lineHeight: # While there's room, increment the line counter ... lineCount += 1 # ... and add the height of the line to the new page height. newPageHeight += self.lineHeight # Create a Device Context that will allow us to manipulate the Bitmap for this individual page pageDC = wx.BufferedDC(None, pageBMP) # Set the Background to White pageDC.SetBackground(wx.Brush(wx.WHITE)) # Clear the DC pageDC.Clear() # Paint the Bitmap's background White, which is probably only needed on the last page! pageDC.FloodFill(1, 1, wx.WHITE) # Put the Page Header from the top of the whole graphic on the top of the page graphic pageDC.Blit(0, 0, canvasWidth, headerHeight, bigDC, 0, 0) # Put the next page-sized segment of the whole graphic onto the page graphic pageDC.Blit(0, headerHeight, canvasWidth, newPageHeight, bigDC, 0, startingPixel) # We want to add the page number to the page. Start by creating the text label. pageNumText = _("Page %d") % self.numPages # Determine the size of the text label on the graphic to aid in positioning (textWidth, textHeight) = pageDC.GetTextExtent(pageNumText) # Begin drawing on the Page device context. pageDC.BeginDrawing() # Add the page number text in the lower right-hand corner of the page. pageDC.DrawText(pageNumText, canvasWidth - textWidth, pageHeight + headerHeight - textHeight) # End drawing on the Page device context. pageDC.EndDrawing() # Move the pointer to the whole graphic's position down by the length of this page startingPixel += newPageHeight # Store the page image in a memory structure where we can get to it later self.pageBMPs.append(pageBMP) # Saving the bitmap as a graphic can be helpful in debugging! # pageBMP.SaveFile('c:\Documents and Settings\davidwoods\Desktop\TestImage%s.jpg' % page, wx.BITMAP_TYPE_JPEG) # If we're dealing with a single-page document, such as a Keyword Map ... else: # ... then we know we only have one page! self.numPages = 1 # Call the base class' OnPreparePrinting() method, which we must do differently in different wxPython versions if wx.VERSION[0] == 2 and wx.VERSION[1] <= 6: self.base_OnPreparePrinting() else: super(MyPrintout, self).OnPreparePrinting()
def draw_scopes(self, gcdc: wx.GCDC): template = self.app.template mid_offset = CONSTANTS.UI.PREVIEW.MID_TEXT_OFFSET width_in_twips = (template.page_width - template.left_margin - template.right_margin - template.gutter) left_centered = template.left_margin + (width_in_twips // 2) right_centered = left_centered + template.page_width + CONSTANTS.UI.PREVIEW.PAGE_GAP + template.gutter mid_vertical = template.page_height // 2 style = template.styles[CONSTANTS.STYLING.NAMES.HEADING1] part = template.top_margin + style.space_before + (style.font_size * mid_offset) style = template.styles[CONSTANTS.STYLING.NAMES.HEADING2] chapter = template.top_margin + style.space_before + (style.font_size * mid_offset) header = template.header_distance font_size = template.styles[CONSTANTS.STYLING.NAMES.HEADER].font_size even_header = (left_centered, header + (font_size * mid_offset)) odd_header = (right_centered, header + (font_size * mid_offset)) font_size = template.styles[CONSTANTS.STYLING.NAMES.FOOTER].font_size footer = template.page_height - template.footer_distance even_footer = (template.left_margin, footer - (font_size * (1 - mid_offset))) even_page = (template.page_width * 2) + CONSTANTS.UI.PREVIEW.PAGE_GAP - template.right_margin odd_footer = (even_page, footer - (font_size * (1 - mid_offset))) gcdc.SetBrush(wx.Brush(self.color_db.Find("WHITE"))) style = template.styles[CONSTANTS.STYLING.NAMES.HEADER] height = _("Header height: %s") % template.header_imperial margin = _("Top margin: %s") % template.top_imperial if SCOPE_ON_EVEN_HEADER in self.scopes: self.draw_scope(gcdc, even_header[0], even_header[1], [style.font_text, height, "", "", margin, ""]) if SCOPE_ON_ODD_HEADER in self.scopes: self.draw_scope(gcdc, odd_header[0], odd_header[1], [style.font_text, height, "", "", margin, ""]) style = template.styles[CONSTANTS.STYLING.NAMES.FOOTER] height = _("Footer height: %s") % template.footer_imperial if SCOPE_ON_EVEN_FOOTER in self.scopes: margin = _("Left margin: %s") % template.left_imperial self.draw_scope(gcdc, even_footer[0], even_footer[1], [style.font_text, height, "", "", margin, ""]) if SCOPE_ON_ODD_FOOTER in self.scopes: self.draw_scope(gcdc, odd_footer[0], odd_footer[1], [style.font_text, "", "", height]) if SCOPE_ON_LEFT_MARGIN in self.scopes: self.draw_scope(gcdc, template.left_margin, mid_vertical, []) if SCOPE_ON_RIGHT_MARGIN in self.scopes: self.draw_scope(gcdc, (template.page_width * 2) + CONSTANTS.UI.PREVIEW.PAGE_GAP - template.right_margin, mid_vertical, []) if SCOPE_ON_GUTTER in self.scopes: margin = _("Right margin: %s") % template.right_imperial gutter = _("Gutter: %s") % template.gutter_imperial self.draw_scope(gcdc, template.page_width - template.gutter, mid_vertical, [margin, gutter]) if SCOPE_ON_PART in self.scopes: style = template.styles[CONSTANTS.STYLING.NAMES.HEADING1] above = "Space above: %s" % style.before_text self.draw_scope(gcdc, right_centered, part, [above, "", "", "", "", style.font_text]) if SCOPE_ON_CHAPTER in self.scopes: style = template.styles[ CONSTANTS.STYLING.NAMES.HEADING2 if template. part_and_chapter else CONSTANTS.STYLING.NAMES.HEADING1] above = "Space above: %s" % style.before_text below = "Space below: %s" % style.after_text self.draw_scope(gcdc, right_centered, chapter, [style.font_text, above, "", "", "", below, ""])
def __init__(self, avenues=10, streets=10, walls=[], beepers={}, robot={}, editWalls=False, screen_offsets=(50, 50, 20, 40), tile_info=(34, 6), beeper_info=(20, 13, 6, 3), wall_colours=("black", "brown"), edit_wall_colours=("brown", "black"), grid_colour="light grey", wall_grid_colour="black", beeper_outside_colour="cadet blue", beeper_inside_colour="white", beeper_number_colour="black"): World.__init__(self, avenues, streets, walls, beepers, robot) # world positioning on "screen" self.xOffset = screen_offsets[0] # left self.yOffset = screen_offsets[1] # bottom self.yTopOffset = screen_offsets[2] # top self.right_scroller_space = screen_offsets[3] # right; leaving enough #room so that the right boundary is never hidden under the scrollbar. # rectangular walls or "tiles" self.tile_wide = tile_info[0] self.tile_narrow = tile_info[1] # the following 4 values are approximate values, used to center # beepers and beeper numbers, obtained through trial and error, based # on self.tile_wide=34, self.tile_narrow = 6 self.beeper_radius = beeper_info[0] self.beeper_offset = beeper_info[1] self.beep_single_digit = beeper_info[2] self.beep_double_digit = beeper_info[3] # Walls are rectangles of a given colour, filled with a second. self.wall_outside_colour = wall_colours[0] self.wall_inside_colour = wall_colours[1] # allows for the possibility of using different colour when editing self.edit_wall_outside_colour = edit_wall_colours[0] self.edit_wall_inside_colour = edit_wall_colours[1] self.editWalls = editWalls self.grid_colour = grid_colour self.wall_grid_colour = wall_grid_colour self.beeper_outside_colour = beeper_outside_colour self.beeper_inside_colour = beeper_inside_colour self.beeper_number_colour = beeper_number_colour self.background_colour = wx.Brush('white') self.maze_colour = wx.Brush('white') # we will create two basic world images and # then set this flag to True; if world dimension changes, we will # reset it to False self.background_images_created = False self.AdjustWorldSize() self.InitTileSizes() self.object_dict = {} # keeps track or robots
def drawY(self, dc): dc.SetPen(wx.Pen("green")) dc.SetBrush(wx.Brush("green")) self.drawSingleCurve(self.Y, dc) self.drawKeys(self.Y, dc) self.drawHandler(self.Y, dc)
def DrawWeek(self, DC): """ Draw the week days. :param `DC`: the :class:`DC` to use. """ # increase by 1 to include all gridlines width = self.gridx[1] - self.gridx[0] + 1 height = self.gridy[1] - self.gridy[0] + 1 rect_w = self.gridx[-1] - self.gridx[0] f = wx.Font(10, self.fontfamily, self.fontstyle, self.fontweight) # initial font setting if self.week_auto is True: test_size = self.max_week_size # max size test_day = ' Sun ' while test_size > 2: f.SetPointSize(test_size) DC.SetFont(f) tw, th = DC.GetTextExtent(test_day) if tw < width and th < height: break test_size = test_size - 1 else: f.SetPointSize(self.week_size) # set fixed size DC.SetFont(f) DC.SetTextForeground(MakeColor(self.colors[COLOR_HEADER_FONT])) cnt_x = 0 cnt_y = 0 brush = wx.Brush(MakeColor(self.colors[COLOR_HEADER_BACKGROUND]), wx.BRUSHSTYLE_SOLID) DC.SetBrush(brush) if self.cal_type == "NORMAL": cal_days = CalDays else: cal_days = BusCalDays for val in cal_days: if val == cal_days[-1]: width = width + self.restW day = AbrWeekday[val] if self.sizew < 200: day = day[0] dw, dh = DC.GetTextExtent(day) diffx = (width - dw) / 2 diffy = (height - dh) / 2 x = self.gridx[cnt_x] y = self.gridy[cnt_y] pointXY = (x, y) pointWH = (width, height) if self.hide_grid is False: pen = wx.Pen(MakeColor(self.GetColor(COLOR_GRID_LINES)), 1, wx.PENSTYLE_SOLID) else: pen = wx.Pen(MakeColor(self.GetColor(COLOR_BACKGROUND)), 1, wx.PENSTYLE_SOLID) DC.SetPen(pen) DC.DrawRectangle(pointXY, pointWH) old_pen = DC.GetPen() pen = wx.Pen(MakeColor(self.colors[COLOR_3D_LIGHT]), 1, wx.PENSTYLE_SOLID) DC.SetPen(pen) # draw the horizontal hilight startPoint = wx.Point(x + 1, y + 1) endPoint = wx.Point(x + width - 1, y + 1) DC.DrawLine(startPoint, endPoint) # draw the vertical hilight startPoint = wx.Point(x + 1, y + 1) endPoint = wx.Point(x + 1, y + height - 2) DC.DrawLine(startPoint, endPoint) pen = wx.Pen(MakeColor(self.colors[COLOR_3D_DARK]), 1, wx.PENSTYLE_SOLID) DC.SetPen(pen) # draw the horizontal lowlight startPoint = wx.Point(x + 1, y + height - 2) endPoint = wx.Point(x + width - 1, y + height - 2) DC.DrawLine(startPoint, endPoint) # draw the vertical lowlight startPoint = wx.Point(x + width - 2, y + 2) endPoint = wx.Point(x + width - 2, y + height - 2) DC.DrawLine(startPoint, endPoint) pen = wx.Pen(MakeColor(self.colors[COLOR_FONT]), 1, wx.PENSTYLE_SOLID) DC.SetPen(pen) point = (x + diffx, y + diffy) DC.DrawText(day, point) cnt_x = cnt_x + 1
def drawZ(self, dc): dc.SetPen(wx.Pen("blue")) dc.SetBrush(wx.Brush("blue")) self.drawSingleCurve(self.Z, dc) self.drawKeys(self.Z, dc) self.drawHandler(self.Z, dc)
def DrawGraph(self, dc): spacer = 10 scaledmax = 150.0 dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() dw, dh = dc.GetSize() # Find out where to draw the title and do it dc.SetFont(self.titleFont) tw, th = dc.GetTextExtent(self.title) dc.DrawText(self.title, (dw - tw) / 2, spacer) # find the center of the space below the title th = th + 2 * spacer cx = dw / 2 cy = (dh - th) / 2 + th # calculate a scale factor to use for drawing the graph based # on the minimum available width or height mindim = min(cx, (dh - th) / 2) scale = mindim / scaledmax # draw the graph axis and "bulls-eye" with rings at scaled 25, # 50, 75 and 100 positions dc.SetPen(wx.Pen("black", 1)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawCircle(cx, cy, 25 * scale) dc.DrawCircle(cx, cy, 50 * scale) dc.DrawCircle(cx, cy, 75 * scale) dc.DrawCircle(cx, cy, 100 * scale) dc.SetPen(wx.Pen("black", 2)) dc.DrawLine(cx - 110 * scale, cy, cx + 110 * scale, cy) dc.DrawLine(cx, cy - 110 * scale, cx, cy + 110 * scale) # Now find the coordinates for each data point, draw the # labels, and find the max data point dc.SetFont(self.labelFont) maxval = 0 angle = 0 polypoints = [] for i, label in enumerate(self.labels): val = self.data[i] point = self.PolarToCartesian(val * scale, angle, cx, cy) polypoints.append(point) x, y = self.PolarToCartesian(125 * scale, angle, cx, cy) dc.DrawText(label, x, y) if val > maxval: maxval = val angle = angle + 360 / len(self.labels) # Set the brush color based on the max value (green is good, # red is bad) c = "forest green" if maxval > 70: c = "yellow" if maxval > 95: c = "red" # Finally, draw the plot data as a filled polygon dc.SetBrush(wx.Brush(c)) dc.SetPen(wx.Pen("navy", 3)) dc.DrawPolygon(polypoints)
def on_paint(self, event): dc = wx.PaintDC(self) controlPanelHeight = 42 bottomWindow = 78 framePadding = 10 frame = { "top": framePadding, "bottom": self.GetSize()[1] - bottomWindow - controlPanelHeight - framePadding, "left": framePadding, "right": self.GetSize()[0] - 2 * framePadding } # controlPanel = { # "top": self.GetSize()[1] - bottomWindow - controlPanelHeight, # "bottom": self.GetSize()[1] - bottomWindow, # "left": 0, # "right": self.GetSize()[0], # } # set Background color dc.SetBackground(wx.Brush("white")) dc.Clear() # draw frame dc.SetBrush(wx.Brush("black")) dc.DrawLine(frame["left"], frame["bottom"], frame["left"], frame["top"]) dc.DrawLine(frame["left"], frame["bottom"], frame["right"], frame["bottom"]) # this draws the little "solid wall" hash lines on left border height = frame["bottom"] while height >= frame["top"] + 10: dc.DrawLine(frame["left"] - 10, height, frame["left"], height - 10) height -= 15 # define a mass multiplier so that the blocks are (almost) # always in frame. Scale both blocks with the multiplier # We order blocks by size. biggest block defines mutliplier first self.blocks.sort(key=lambda x: x.mass) biggestBlock = self.blocks[-1] smallestBlock = self.blocks[0] multiplier = 0.1 * (frame["right"] - frame["left"]) / biggestBlock.mass # if smallest block isn't visible, we make it visible # fixed minimum of 5x5 pixels # and the bigger block will scale accordingly # a too big of a difference between the two blocks will make # the bigger block go out of frame. if (smallestBlock.mass * multiplier < 5): multiplier = 5 / smallestBlock.mass minimalWindowHeight = biggestBlock.mass * multiplier + bottomWindow +controlPanelHeight + 2 * framePadding # if window is too small to display the bigger block, # we enlarge the window to display the block (to screen size limit) if (minimalWindowHeight > self.GetSize()[1]): self.SetSize(0, 0, minimalWindowHeight * 2, minimalWindowHeight) # draw Blocks in frame # 0 is top-left for wxPython but bottom-left on frame. # Taking that in consideration, all our drawings on Y axis will be # "substracted" from frame["bottom"] for block in self.blocks: dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0))) dc.DrawRectangle(frame["left"] + block.x, frame["bottom"] - block.mass * multiplier + 1, block.mass * multiplier, block.mass * multiplier)
def _OnPaintHeaders(self, evt): dc = wx.PaintDC(self._headerPanel) dc.BeginDrawing() try: dc.SetBackground(wx.Brush(SCHEDULER_BACKGROUND_BRUSH)) dc.SetPen(FOREGROUND_PEN) dc.Clear() dc.SetFont(wx.NORMAL_FONT) if self._drawerClass.use_gc: context = wx.GraphicsContext.Create(dc) else: context = dc drawer = self._drawerClass(context, self._lstDisplayedHours) if self._resizable: width, _ = self.GetVirtualSize() else: width, _ = self.CalcMinSize() day = utils.copyDate(self.GetDate()) x, y = 0, 0 # Take horizontal scrolling into account x0, _ = self.GetViewStart() xu, _ = self.GetScrollPixelsPerUnit() x0 *= xu x -= x0 self._headerBounds = [] if self._viewType == wxSCHEDULER_DAILY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): _, h = self._paintDailyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(days=1)) h = maxDY elif self._viewType == wxSCHEDULER_WEEKLY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): h = self._paintWeeklyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(weeks=1)) h = maxDY elif self._viewType == wxSCHEDULER_MONTHLY: _, h = self._paintMonthlyHeaders(drawer, day, x, y, width, 36) minW, minH = self._headerPanel.GetMinSize() if minH != h: self._headerPanel.SetMinSize(wx.Size(-1, h)) self._headerPanel.GetParent().Layout() # Mmmmh, maybe we'll support this later, but not right now if self._style == wxSCHEDULER_VERTICAL: self._headerBounds = [] finally: dc.EndDrawing()
def draw_rect(self, x, y, w, h, c): dc = wx.ClientDC(self.PDFimage) dc.SetPen(wx.Pen(c, width=1)) dc.SetBrush(wx.Brush(c, style=wx.BRUSHSTYLE_TRANSPARENT)) dc.DrawRectangle(x, y, w, h) return
def SetBackgroundColour(self, colour): if self.originalColor == None: self.originalColor = colour self.background = wx.Brush(colour) return wx.Panel.SetBackgroundColour(self, colour)
def draw_plate(self, dc): model = self.model w, h = self.GetClientSize() padding = min(w, h) / 36 margin = min(w, h) / 8 pw, ph = w - margin * 2 - padding * 2, h - margin * 2 - padding * 2 self.size = size = min(pw / model.cols, ph / model.rows) dw, dh = size * model.cols, size * model.rows dx, dy = (w - dw) / 2, (h - dh) / 2 dc.SetPen(wx.Pen(wx.BLACK, 4)) dc.SetBrush(wx.Brush(wx.Colour(235, 235, 235))) dc.DrawRectangle(dx - padding, dy - padding, dw + padding * 2, dh + padding * 2) font = dc.GetFont() font.SetPointSize(size / 5) dc.SetFont(font) box = set(self.box_test(*self.box)) if self.box else set() dc.SetPen(wx.Pen(wx.BLACK, 2)) for row in range(model.rows): for col in range(model.cols): x = dx + col * size + size / 2 y = dy + row * size + size / 2 self.coords[(row, col)] = (x, y) if (row, col) in box: key = model.active_key else: key = model.grid[row][col] if key: dc.SetTextForeground(wx.Colour(0, 0, 0)) else: dc.SetTextForeground(wx.Colour(64, 64, 64)) dc.SetBrush(wx.Brush(wx.Colour(*model.colors[key]))) dc.DrawCircle(x, y, size / 2 - size / 12) if model.show_well_labels: if key == EMPTY: label = '%s%d' % (chr(ord('A') + row), col + 1) else: label = model.labels[key][0] tw, th = dc.GetTextExtent(label) dc.DrawText(label, x - tw / 2, y - th / 2) if model.show_labels: font = dc.GetFont() font.SetPointSize(size / 3) dc.SetFont(font) dc.SetTextForeground(wx.BLACK) for row in range(model.rows): y = dy + row * size + size / 2 x = dx - padding * 2 - size / 4 label = chr(ord('A') + row) tw, th = dc.GetTextExtent(label) dc.DrawText(label, x - tw / 2, y - th / 2) for col in range(model.cols): x = dx + col * size + size / 2 y = dy - padding * 2 - size / 4 label = str(col + 1) tw, th = dc.GetTextExtent(label) dc.DrawText(label, x - tw / 2, y - th / 2) if model.show_legend: x = dx - padding y = dy + dh + padding * 2 w = dw + padding * 2 h = margin - padding * 2 w = w / len(model.labels) dc.SetPen(wx.Pen(wx.BLACK, 2)) font = dc.GetFont() font.SetPointSize(h / 3) dc.SetFont(font) for key in sorted(model.labels): label = model.labels[key] dc.SetBrush(wx.Brush(wx.Colour(*model.colors[key]))) dc.DrawRoundedRectangle(x + padding / 2, y, w - padding, h, padding / 2) tw, th = dc.GetTextExtent(label) dc.DrawText(label, x + w / 2 - tw / 2, y + h / 2 - th / 2) x += w + 1
def UpdateGraph(self, dat): # get first and last time for new data etime = 0 # last time(right side for graph) for cpuno in dat: for d in dat[cpuno]: if d[1] > etime: etime = d[1] stime = etime - self.dtimespan # first time(left side for graph) ctime = datetime.datetime.now( ) # get current time(for time scale diplay) # shift previous drawing if self.itmcount_ > 0: # calcurate graphic shift value sft = self.cgtw_ * (etime - self.dtime) / self.dtimespan # shift [pixel] if sft > self.cgtw_: sft = self.cgtw_ # clear all area for n in range(0, self.itmcount_): dc = wx.PaintDC(self.cgpanels_[n]) dc.SetPen(wx.Pen(self.bgcol_)) dc.SetBrush(wx.Brush(self.bgcol_)) # shift previous drawing dc.Blit(0, 0, self.cgtw_ - sft, self.cgth_, dc, sft, 0) # clear new data drawing area dc.DrawRectangle(self.cgtw_ - sft, 0, sft, self.cgth_) self.dtime = etime # draw graph of new data for cpuno in range(0, self.cpucount_): pid = 0 # previous pid ptm = 0 # previous time for d in dat[cpuno]: cid = d[0] # current pid ctm = d[1] # current time col = '' # drawing color(depend on previous pid) for (_, p) in self.pids_: if p == pid: col = self.GetColor(cpuno, pid) break if len(col) == 0: if self.view_ == 0 and pid != 0: col = "#cccccc" else: ptm = ctm pid = cid continue if self.view_ == 0: n = cpuno else: n = self.labels_.index(pid) dc = wx.PaintDC(self.cgpanels_[n]) dc.SetPen(wx.Pen(col)) dc.SetBrush(wx.Brush(col)) w = int(self.cgtw_ * (ctm - ptm) / self.dtimespan + 1) p = int(self.cgtw_ * (ptm - stime) / self.dtimespan) if (p + w) > (self.cgtw_ - 1): p = self.cgtw_ - w - 1 dc.DrawRectangle(p, 0, w, self.cgth_) ptm = ctm pid = cid # draw scale and time dc = wx.PaintDC(self.cgpanels_[self.itmcount_]) dc.SetPen(wx.Pen(self.bgcol_)) dc.SetBrush(wx.Brush(self.bgcol_)) dc.DrawRectangle(0, 0, self.cgtw_, self.cgth_) # clear drawing area dc.SetTextForeground((0, 0, 0)) tint = self.cgtw_ / self.dtimespan # period for time display tofs = self.cgtw_ * (1 - (ctime.microsecond / self.dtimespan / 1000000) ) # offset for drawing tmin = ctime.minute tsec = ctime.second dc.SetPen(wx.Pen('blue')) for t in range(-10, 30): # draw scale x = tofs - (t / 10.0) * tint dc.DrawLine(x, 0, x, 4) if (t % 5) == 0: dc.DrawLine(x - 1, 0, x - 1, 4) for t in range(0, 4): # draw time ttext = "%02d:%02d" % (tmin, tsec) txtw, _ = dc.GetTextExtent( ttext) # get text width for time display dc.DrawText(ttext, tofs - (txtw / 2), 0) # draw time tofs -= tint tsec -= 1 if tsec < 0: tsec = 59 tmin -= 1 if tmin < 0: tmin = 59
def drawLoop(self, dc, loop, id, startX, endX, base, height, rgb=(0, 0, 0), downwards=True): if downwards: up = -1 else: up = +1 # draw loop itself, as transparent rect with curved corners tmpId = wx.NewIdRef() dc.SetId(tmpId) # extra distance, in both h and w for curve curve = (6, 11, 15)[self.appData['flowSize']] yy = [base, height + curve * up, height + curve * up / 2, height] # for area r, g, b = rgb dc.SetPen(wx.Pen(wx.Colour(r, g, b, 200))) vertOffset = 0 # 1 is interesting too area = wx.Rect(startX, base + vertOffset, endX - startX, max(yy) - min(yy)) dc.SetBrush(wx.Brush(wx.Colour(0, 0, 0, 0), style=wx.TRANSPARENT)) # draws outline: dc.DrawRoundedRectangle(area, curve) dc.SetIdBounds(tmpId, area) flowsize = self.appData['flowSize'] # 0, 1, or 2 # add a name label, loop info, except at smallest size name = loop.params['name'].val _show = self.appData['showLoopInfoInFlow'] if _show and flowsize: _cond = 'conditions' in list(loop.params) if _cond and loop.params['conditions'].val: xnumTrials = 'x' + str(len(loop.params['conditions'].val)) else: xnumTrials = '' name += ' (' + str(loop.params['nReps'].val) + xnumTrials abbrev = [ '', # for flowsize == 0 { 'random': 'rand.', 'sequential': 'sequ.', 'fullRandom': 'f-ran.', 'staircase': 'stair.', 'interleaved staircases': "int-str." }, { 'random': 'random', 'sequential': 'sequential', 'fullRandom': 'fullRandom', 'staircase': 'staircase', 'interleaved staircases': "interl'vd stairs" } ] name += ' ' + abbrev[flowsize][loop.params['loopType'].val] + ')' if flowsize == 0: if len(name) > 9: name = ' ' + name[:8] + '..' else: name = ' ' + name[:9] else: name = ' ' + name + ' ' dc.SetId(id) font = self.GetFont() if sys.platform == 'darwin': basePtSize = (650, 750, 900)[flowsize] elif sys.platform.startswith('linux'): basePtSize = (750, 850, 1000)[flowsize] else: basePtSize = (700, 750, 800)[flowsize] font.SetPointSize(basePtSize / self.dpi) self.SetFont(font) dc.SetFont(font) # get size based on text pad = (5, 8, 10)[self.appData['flowSize']] w, h = self.GetFullTextExtent(name)[0:2] x = startX + (endX - startX) / 2 - w / 2 - pad / 2 y = (height - h / 2) # draw box rect = wx.Rect(x, y, w + pad, h + pad) # the edge should match the text dc.SetPen(wx.Pen(wx.Colour(r, g, b, 100))) # try to make the loop fill brighter than the background canvas: dc.SetBrush(wx.Brush(wx.Colour(235, 235, 235, 250))) dc.DrawRoundedRectangle(rect, (4, 6, 8)[flowsize]) # draw text dc.SetTextForeground([r, g, b]) dc.DrawText(name, x + pad / 2, y + pad / 2) self.componentFromID[id] = loop # set the area for this component dc.SetIdBounds(id, rect)
def DrawXCoord(self, dc): dc.SetBackground(wx.Brush(wx.Colour(200, 200, 200))) dc.Clear() dc.SetPen(wx.BLACK_PEN) dc.SetBrush(wx.BLACK_BRUSH) dc.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL)) dc.DrawLine(self.zeroPos[0], float(0), self.zeroPos[0], self.h) st = str(self.zero) self.tw, self.th = dc.GetTextExtent(st) dc.DrawText(st, self.zeroPos[0] + 1.0, self.h - self.th - 0.5) dc.SetPen(wx.Pen(wx.Colour(150, 150, 150))) dc.SetBrush(wx.Brush(wx.Colour(150, 150, 150))) if self.unitWidth >= 25: posPos = self.zeroPos[0] + self.unitWidth posNum = self.zero + 1 while posPos <= self.w: dc.DrawLine(posPos, float(0), posPos, self.h) st = str(posNum) self.drawXNumber(dc, st, posPos) posPos += self.unitWidth posNum += 1 negPos = self.zeroPos[0] - self.unitWidth negNum = self.zero - 1 while negPos >= float(0): dc.DrawLine(negPos, float(0), negPos, self.h) st = str(negNum) self.drawXNumber(dc, st, negPos) negPos -= self.unitWidth posNum -= 1 elif self.unitWidth >= 10 and self.unitWidth <= 25: posPos = self.zeroPos[0] + self.unitWidth * float(2) posNum = self.zero + 2 while posPos <= self.w: dc.DrawLine(posPos, float(0), posPos, self.h) st = str(posNum) self.drawXNumber(dc, st, posPos) posPos += self.unitWidth * float(2) posNum += 2 negPos = self.zeroPos[0] - self.unitWidth * float(2) negNum = self.zero - 2 while negPos >= float(0): dc.DrawLine(negPos, float(0), negPos, self.h) st = str(negNum) self.drawXNumber(dc, st, negPos) negPos -= self.unitWidth * float(2) posNum -= 2 elif self.unitWidth >= 2 and self.unitWidth <= 10: posPos = self.zeroPos[0] + self.unitWidth * float(5) posNum = self.zero + 5 while posPos <= self.w: dc.DrawLine(posPos, float(0), posPos, self.h) st = str(posNum) self.drawXNumber(dc, st, posPos) posPos += self.unitWidth * float(5) posNum += 5 negPos = self.zeroPos[0] - self.unitWidth * float(5) negNum = self.zero - 5 while negPos >= float(0): dc.DrawLine(negPos, float(0), negPos, self.h) st = str(negNum) self.drawXNumber(dc, st, negPos) negPos -= self.unitWidth * float(5) posNum -= 5
def update_plot(self): '''Draws a graph displaying how many codons for each amino acid is selection''' self.Refresh() self.Update() AA_order = ('A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', 'stop') x = (self.AA_count[AA_order[0]], self.AA_count[AA_order[1]], self.AA_count[AA_order[2]], self.AA_count[AA_order[3]], self.AA_count[AA_order[4]], self.AA_count[AA_order[5]], self.AA_count[AA_order[6]], self.AA_count[AA_order[7]], self.AA_count[AA_order[8]], self.AA_count[AA_order[9]], self.AA_count[AA_order[10]], self.AA_count[AA_order[11]], self.AA_count[AA_order[12]], self.AA_count[AA_order[13]], self.AA_count[AA_order[14]], self.AA_count[AA_order[15]], self.AA_count[AA_order[16]], self.AA_count[AA_order[17]], self.AA_count[AA_order[18]], self.AA_count[AA_order[19]], self.AA_count[AA_order[20]]) originx = 50 originy = 450 sizex = 300 sizey = 120 xspacing = float(sizex) / float(21) yspacing = sizey / 7 tick_size = 5 title = 'Codon count for each AA' self.dc = wx.PaintDC(self) self.dc.SetDeviceOrigin(originx, originy) self.dc.SetAxisOrientation(True, True) self.dc.SetPen(wx.Pen('#333333')) self.font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, 'Courier 10 Pitch') self.dc.SetFont(self.font) #title self.dc.DrawText(title, sizex / 4, sizey + 20) #x labels (amino acids) for i in range(1, 22): self.dc.DrawText(str(AA_order[i - 1]), 0 + (xspacing * i) - xspacing / 1.5, -5) #y labels (count) for i in range(1, 7): self.dc.DrawText(str(i), -10, 0 + (yspacing * i) + 9) self.dc.SetPen(wx.Pen('#FFFFFF')) self.dc.DrawRectangle(0, 0, sizex, sizey) #frame self.dc.SetPen(wx.Pen('#000000')) self.dc.DrawLine(0, 0, sizex, 0) #bottom line... #DrawLine(self, x1, y1, x2, y2) self.dc.DrawLine(0, sizey, sizex, sizey) #top line self.dc.DrawLine(sizex, 0, sizex, sizey) #right line self.dc.DrawLine(0, 0, 0, sizey) #left line #x ticks for i in range(1, 22): self.dc.DrawLine(0 + (xspacing * i), 0, 0 + (xspacing * i), tick_size) self.dc.DrawLine(0 + (xspacing * i), sizey, 0 + (xspacing * i), sizey - tick_size) #y ticks for i in range(1, 7): self.dc.DrawLine(0, 0 + (yspacing * i), tick_size, 0 + (yspacing * i)) self.dc.DrawLine(sizex, 0 + (yspacing * i), sizex - tick_size, 0 + (yspacing * i)) #draw bars self.dc.SetBrush(wx.Brush('#666666', wx.SOLID)) for i in range(1, 22): self.dc.DrawRectangle(0 + (xspacing * (i - 1)) + 2, 0, xspacing * 0.8, x[i - 1] * yspacing) #(x, y, w, h)
def drawX(self, dc): dc.SetPen(wx.Pen("red")) dc.SetBrush(wx.Brush("red")) self.drawSingleCurve(self.X, dc) self.drawKeys(self.X, dc) self.drawHandler(self.X, dc)
def RandomBrush(self): c = random.choice(colours) if not self.brush_cache.has_key(c): self.brush_cache[c] = wx.Brush(c) return self.brush_cache[c]
def OnPaint(self, evt): dc = wx.BufferedPaintDC(self) dc.SetBackground(wx.Brush('Black')) dc.Clear() if self.to_draw_points: self.Render(dc)