2549 def ClearErrors(self): |
2549 def ClearErrors(self): |
2550 self.ClearHighlights(ERROR_HIGHLIGHT) |
2550 self.ClearHighlights(ERROR_HIGHLIGHT) |
2551 |
2551 |
2552 def ClearSearchResults(self): |
2552 def ClearSearchResults(self): |
2553 self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
2553 self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
|
2554 |
|
2555 #------------------------------------------------------------------------------- |
|
2556 # Viewer Printout |
|
2557 #------------------------------------------------------------------------------- |
|
2558 |
|
2559 UPPER_DIV = lambda x, y: (x / y) + {True : 0, False : 1}[(x % y) == 0] |
|
2560 |
|
2561 class GraphicPrintout(wx.Printout): |
|
2562 def __init__(self, viewer, page_size, margins, preview = False): |
|
2563 wx.Printout.__init__(self) |
|
2564 self.Viewer = viewer |
|
2565 self.PageSize = page_size |
|
2566 if self.PageSize[0] == 0 or self.PageSize[1] == 0: |
|
2567 self.PageSize = (1050, 1485) |
|
2568 self.Preview = preview |
|
2569 self.Margins = margins |
|
2570 self.FontSize = 5 |
|
2571 self.TextMargin = 3 |
|
2572 |
|
2573 maxx, maxy = viewer.GetMaxSize() |
|
2574 self.PageGrid = (UPPER_DIV(maxx, self.PageSize[0]), |
|
2575 UPPER_DIV(maxy, self.PageSize[1])) |
|
2576 |
|
2577 def GetPageNumber(self): |
|
2578 return self.PageGrid[0] * self.PageGrid[1] |
|
2579 |
|
2580 def HasPage(self, page): |
|
2581 return page <= self.GetPageNumber() |
|
2582 |
|
2583 def GetPageInfo(self): |
|
2584 page_number = self.GetPageNumber() |
|
2585 return (1, page_number, 1, page_number) |
|
2586 |
|
2587 def OnBeginDocument(self, startPage, endPage): |
|
2588 dc = self.GetDC() |
|
2589 if not self.Preview and isinstance(dc, wx.PostScriptDC): |
|
2590 dc.SetResolution(720) |
|
2591 super(GraphicPrintout, self).OnBeginDocument(startPage, endPage) |
|
2592 |
|
2593 def OnPrintPage(self, page): |
|
2594 dc = self.GetDC() |
|
2595 dc.SetUserScale(1.0, 1.0) |
|
2596 dc.SetDeviceOrigin(0, 0) |
|
2597 dc.printing = not self.Preview |
|
2598 |
|
2599 # Get the size of the DC in pixels |
|
2600 ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
|
2601 ppiScreenX, ppiScreenY = self.GetPPIScreen() |
|
2602 pw, ph = self.GetPageSizePixels() |
|
2603 dw, dh = dc.GetSizeTuple() |
|
2604 Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4) |
|
2605 Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4) |
|
2606 |
|
2607 fontsize = self.FontSize * Yscale |
|
2608 text_margin = self.TextMargin * Yscale |
|
2609 |
|
2610 margin_left = self.Margins[0].x * Xscale |
|
2611 margin_top = self.Margins[0].y * Yscale |
|
2612 area_width = dw - self.Margins[1].x * Xscale - margin_left |
|
2613 area_height = dh - self.Margins[1].y * Yscale - margin_top |
|
2614 |
|
2615 dc.SetPen(MiterPen(wx.BLACK)) |
|
2616 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
2617 dc.DrawRectangle(margin_left, margin_top, area_width, area_height) |
|
2618 |
|
2619 dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) |
|
2620 dc.SetTextForeground(wx.BLACK) |
|
2621 block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:]) |
|
2622 text_width, text_height = dc.GetTextExtent(block_name) |
|
2623 dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin) |
|
2624 dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin) |
|
2625 |
|
2626 # Calculate the position on the DC for centering the graphic |
|
2627 posX = area_width * ((page - 1) % self.PageGrid[0]) |
|
2628 posY = area_height * ((page - 1) / self.PageGrid[0]) |
|
2629 |
|
2630 scaleX = float(area_width) / float(self.PageSize[0]) |
|
2631 scaleY = float(area_height) / float(self.PageSize[1]) |
|
2632 scale = min(scaleX, scaleY) |
|
2633 |
|
2634 # Set the scale and origin |
|
2635 dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
|
2636 dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale) |
|
2637 dc.SetUserScale(scale, scale) |
|
2638 |
|
2639 #------------------------------------------- |
|
2640 |
|
2641 self.Viewer.DoDrawing(dc, True) |
|
2642 |
|
2643 return True |
|
2644 |