[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8549 - trunk/gnue-forms/src/uidrivers/wx26/widgets
From: |
reinhard |
Subject: |
[gnue] r8549 - trunk/gnue-forms/src/uidrivers/wx26/widgets |
Date: |
Thu, 3 Aug 2006 10:49:50 -0500 (CDT) |
Author: reinhard
Date: 2006-08-03 10:49:49 -0500 (Thu, 03 Aug 2006)
New Revision: 8549
Modified:
trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
Log:
Implemented screen dump function for wx26.
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2006-08-02 09:52:46 UTC
(rev 8548)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2006-08-03 15:49:49 UTC
(rev 8549)
@@ -24,10 +24,12 @@
Implementation of the UI layer for the <form> and <dialog> tag.
"""
+import time
+import os.path
import wx
-import os.path
from gnue.common.apps import GConfig
+from gnue.forms import VERSION
from gnue.forms.uidrivers.wx26.MenuBar import MenuBar
from gnue.forms.uidrivers.wx26.ToolBar import ToolBar
from gnue.forms.uidrivers.wx26.widgets._base import UIHelper
@@ -349,7 +351,161 @@
self.show_page(page.page_index)
+ # -------------------------------------------------------------------------
+ # Print form screenshot
+ # -------------------------------------------------------------------------
+
+ def _ui_printout_(self, title, subtitle, user):
+
+ # Store the content of the form in a bitmap DC
+ window_dc = wx.ClientDC(self.main_window)
+ w, h = self.main_window.GetClientSizeTuple()
+ bmp = wx.EmptyBitmap(w, h)
+ form_dc = wx.MemoryDC()
+ form_dc.SelectObject(bmp)
+ form_dc.Blit(0,0, w, h, window_dc, 0, 0)
+ image = wx.ImageFromBitmap(bmp)
+
+ wx.Printer().Print(self.main_window,
+ _Printout(title, subtitle, user, image))
+
+
# =============================================================================
+# Helper class for screen dump printing
+# =============================================================================
+
+class _Printout(wx.Printout):
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, title, subtitle, login, image):
+ self.__title = title
+ self.__subtitle = subtitle or ''
+ self.__login = login
+ self.__image = image
+ wx.Printout.__init__(self, title)
+
+
+ # -------------------------------------------------------------------------
+ # Return info about number of pages in the document (always 1 here)
+ # -------------------------------------------------------------------------
+
+ def GetPageInfo(self):
+
+ return (1, 1, 1, 1)
+
+
+ # -------------------------------------------------------------------------
+ # Print the page
+ # -------------------------------------------------------------------------
+
+ def OnPrintPage(self, page):
+
+ # Prepare DC to paint on
+ dc = self.GetDC()
+ dc.SetFont(wx.NORMAL_FONT)
+ dc.SetPen(wx.BLACK_PEN)
+ dc.SetBrush(wx.TRANSPARENT_BRUSH)
+
+ # Scale from screen to printer
+ screen_ppi_x, screen_ppi_y = self.GetPPIScreen()
+ printer_ppi_x, printer_ppi_y = self.GetPPIPrinter()
+ scale_x = float(printer_ppi_x) / screen_ppi_x
+ scale_y = float(printer_ppi_y) / screen_ppi_y
+
+ # Calculate page margins
+ page_width, page_height = self.GetPageSizePixels()
+ page_margin_left = page_margin_right = int(printer_ppi_x*.75+.5)
+ page_margin_top = page_margin_bottom = int(printer_ppi_y*.75+.5)
+ page_left = page_margin_left
+ page_top = page_margin_top
+ page_right = page_width - page_margin_right
+ page_bottom = page_height - page_margin_bottom
+
+ # Page header, left
+ y = self.draw_text(dc, page_left, page_top, self.__title)
+ y = self.draw_text(dc, page_left, y, self.__subtitle)
+
+ # Page header, right
+ timestamp = time.strftime(
+ "%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
+ y = self.draw_text(dc, page_right, page_top, timestamp,
+ align_right=True)
+ y = self.draw_text(dc, page_right, y, u_('Login: ') + self.__login,
+ align_right=True)
+
+ # Page header, line
+ dc.DrawLine(page_left, y, page_right, y)
+ canvas_top = y + int(printer_ppi_y * 0.25 + 0.5)
+
+ # Page footer, left
+ y = self.draw_text(dc, page_left, page_bottom,
+ 'GNUe Forms %s' % VERSION, align_bottom=True)
+
+ # Page footer, line
+ dc.DrawLine(page_left, y, page_right, y)
+ canvas_bottom = y - int(printer_ppi_y * 0.25 + 0.5)
+
+ # Space where we can paint the screenshot
+ canvas_w = page_right - page_left
+ canvas_h = canvas_bottom - canvas_top
+
+ # If necessary, adjust scale factor to fit on page
+ w = self.__image.GetWidth()
+ h = self.__image.GetHeight()
+ if w * scale_x > canvas_w:
+ scale_y = scale_y / (w * scale_x / canvas_w)
+ scale_x = canvas_w / w
+ if h * scale_y > canvas_h:
+ scale_x = scale_x / (h * scale_y / canvas_h)
+ scale_y = canvas_h / h
+
+ # and now, scale by factor
+ w = int (w * scale_x + 0.5)
+ h = int (h * scale_y + 0.5)
+
+ # the actual screenshot
+ dc.DrawBitmap(
+ wx.BitmapFromImage(self.__image.Scale(w, h)),
+ int((canvas_w - w) / 2) + page_left,
+ int((canvas_h - h) / 2) + canvas_top)
+
+ # border
+ dc.DrawRectangle(
+ int((canvas_w - w) / 2) + page_left,
+ int((canvas_h - h) / 2) + canvas_top,
+ w, h)
+
+
+ # -------------------------------------------------------------------------
+ # Draw text and calculate new y position
+ # -------------------------------------------------------------------------
+
+ def draw_text(self, dc, x, y, text, align_right=False, align_bottom=False):
+
+ w, h = dc.GetTextExtent(text)
+
+ _x = x
+ _y = y
+
+ if align_right:
+ _x -= w
+ if align_bottom:
+ _y -= h
+
+ dc.DrawText(text, _x, _y)
+
+ if align_bottom:
+ new_y = y - h * 1.3
+ else:
+ new_y = y + h * 1.3
+
+ return new_y
+
+
+# =============================================================================
# Widget configuration
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8549 - trunk/gnue-forms/src/uidrivers/wx26/widgets,
reinhard <=