I am looking in the demo at printout.py -- which is seems to be exctly what you are asking for. It is found under the "More Windows/Controls" Tree under "TablePrint".
···
---------
Vernon Cole
MrJanes wrote:
Hello everyone,
I struggle with the wxPrintPreview:
MY QUESTION 1:
I need a small help with the printing of a Database grid.
I'm working on a small database(pysqlite) application. I display a table from the database on a frame with an wx.grid table:
I would like to PrintPreview it and after that print everything on paper
######__BEGIN_Code_Snipped__#####
import sqlite, SqliteHelperClass
import wx
import wx.gridDataBaseDir = "DataBase\\"
DataBaseFileName = "MyDatabase.db"#---------------------------------------------------------------------------
class Frame_ResultDisplayGrid(wx.Frame):
def __init__(self, parent, Titel, GridNumber, TotalNumberOfColumns, AusfuehrenColumnNamesListSQLReturnResult, AusfuehrenSqlQueryReslutSQLReturnResult):
wx.Frame.__init__(self,
parent = parent,
id = -1,
title = Titel,
pos = wx.Point(-1, -1),
#size = wx.Size(700, 400),
size = wx.Size(1024, 768),
style = wx.STAY_ON_TOP | wx.SYSTEM_MENU | wx.CAPTION | wx.MAXIMIZE_BOX,
name = "htmlWindow")self.CentreOnScreen()
self.SetBackgroundColour(wx.Colour(205, 114, 109))
# Menu Bar
self.frame_1_menubar = wx.MenuBar()
self.SetMenuBar(self.frame_1_menubar)
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.AppendSeparator()
wxglade_tmp_menu.Append(19, "Close", "Close the Application!", wx.ITEM_NORMAL)
self.frame_1_menubar.Append(wxglade_tmp_menu, "File")# bind the menu event to an event handler
self.Bind(wx.EVT_MENU, self.CloseApplication_OnClick, id=19)# Menu Bar end
self.frame_1_statusbar = self.CreateStatusBar(1, 0)self.frame_1_statusbar.SetStatusWidths([-1])
# statusbar fields
frame_1_statusbar_fields = ["Info:"]
for i in range(len(frame_1_statusbar_fields)):
self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)# ____________________________________ #
#_Begin___GRID
self.GridResultDisplay = wx.grid.Grid(parent = self,
id = -1,
pos = wx.Point(0, 0),
size = wx.Size(1024, 768),
style = 0,
name = wx.PanelNameStr)self.GridResultDisplay.CreateGrid(int(GridNumber), int(TotalNumberOfColumns))
#create dynamically the ColumnNames
self.GridResultDisplay .SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM)
for x in AusfuehrenColumnNamesListSQLReturnResult:
ColumnNumber= x[0]
ColumnName= x[1]
self.GridResultDisplay .SetColLabelValue(int(ColumnNumber), str(ColumnName))#create dynamically the CellValueToDisplay
self.GridResultDisplay.SetDefaultCellOverflow(False)
for x in AusfuehrenSqlQueryReslutSQLReturnResult:
RowNumberRead= int(x[0])
RowNumber= RowNumberRead - 1
for s,y in zip (x, AusfuehrenColumnNamesListSQLReturnResult):ColumnNumber = int(y[0])
if str(s) == "None":
CellValueToDisplay = ''
else:
CellValueToDisplay = str(s)self.GridResultDisplay.SetCellValue(RowNumber, ColumnNumber, CellValueToDisplay)
# Set Auto Resize of Columns and Rows
self.GridResultDisplay.AutoSize()# test all the events
self.GridResultDisplay.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)self.Refresh()
#_End___GRID
#_____________________FUNCTIONS_________________def CloseApplication_OnClick(self, evt):
""" handleEventr for the button click."""
self.Close(1)#____FUNCTIONS____#
def DialogAusfuehrenGRID_GRID_CELL_LEFT_CLICK(self, Message_VALUE):dlg1 = wx.MessageDialog(parent = None,
message = Message_VALUE,
caption = "Cell Information",
style=wx.ICON_INFORMATION | wx.STAY_ON_TOP | wx.OK,
pos = wx.Point(-1, -1))
dlg1.ShowModal()
dlg1.Destroy()
def OnCellLeftClick(self, evt):
row=evt.GetRow()
col=evt.GetCol()
value=self.GridResultDisplay.GetCellValue(row, col)
Message_VALUE = value
self.DialogAusfuehrenGRID_GRID_CELL_LEFT_CLICK("The cell information is: \n\n %s" %Message_VALUE)
print value
evt.Skip()# end of class Dialog_DisplayHelp
#---------------------------------------------------------------------------
######__END_Code_Snipped__#####
I import and execute this from a main frame menu.
MY QUESTION 1:
I would like to add a printing support so that I can preview and print the Database Resluting Grid to paper.
__________________________________________________________________________________________
MY QUESTION 2:
I also have a wx.panel where a wx.html.HtmlWindow displays a html readme.html file.
######__BEGIN_Code_Snipped__#####
import wx
import wx.htmlclass Panel_ReadMe(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self,
parent = parent,
id = -1,
pos = wx.Point(-1, -1),
size = wx.Size(1024, 768),
style = wx.TAB_TRAVERSAL,
name = "panel")self.SetBackgroundColour(wx.Colour(255, 127, 200))
#_Begin___htmlWindow
self.MyHtmlWindow = wx.html.HtmlWindow(parent = self,
id = -1,
pos = wx.Point(-1, -1),
size = wx.Size(1024, 768),
style = wx.html.HW_SCROLLBAR_AUTO,
name = "htmlWindow")self.MyHtmlWindow.LoadFile('readme.html')
#_End___htmlWindow
self.Refresh()
######__END_Code_Snipped__#####MY QUESTION 2:
How could I add preview and printing support to this.
Thanks So much.
MrJanes