wxpython 打印

zheng_j_c 2010-08-26 03:19:02
wxpython 打印表格时怎样打印的啊???
...全文
255 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbbliyong 2010-09-13
  • 打赏
  • 举报
回复
你参考下这个例子

import os
import wx
import wx.lib.printout as printout

#---------------------------------------------------------------------------

buttonDefs = {
814 : ('PreviewWide', 'Preview print of a wide table'),
815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
816 : ('PreviewText', 'Preview print of a text file'),
818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'),
817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'),
819 : ('PrintWide', 'Direct print (no preview) of a wide table'),
}


class TablePanel(wx.Panel):
def __init__(self, parent, log, frame):
wx.Panel.__init__(self, parent, -1)
self.log = log
self.frame = frame

box = wx.BoxSizer(wx.VERTICAL)
box.Add((20, 30))
keys = buttonDefs.keys()
keys.sort()

for k in keys:
text = buttonDefs[k][1]
btn = wx.Button(self, k, text)
box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.Bind(wx.EVT_BUTTON, self.OnButton, btn)

self.SetAutoLayout(True)
self.SetSizer(box)

def OnButton(self, evt):
funct = buttonDefs[evt.GetId()][0]
code = 'self.' + funct + '()'
eval(code)

def ReadData(self):
test_file = "./data/testtable.txt"
file = open(test_file,'r',1)
i = 0

data = []
while 1:
text = file.readline()
text = text.strip()
if not text:
break

list_val = text.split('\t')
data.append(list_val)
file.close()

self.header = data[0]
self.data = data[1:]

def PreviewWide(self):
self.ReadData()
prt = printout.PrintTable(self.frame)
prt.data = self.data
prt.left_margin = 0.5
prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
prt.label = self.header
prt.SetLandscape()

prt.SetColumnLineSize(2, 3)
prt.SetColumnLineColour(3, wx.NamedColour('RED'))

prt.SetRowLineSize(1, 3)
prt.SetRowLineColour(5, wx.NamedColour('RED'))

prt.SetHeader("wx.Windows Applications")
prt.SetFooter()
prt.SetFooter("Date: ", type = "Date", align=wx.ALIGN_RIGHT, indent = -1, colour = wx.NamedColour('RED'))
prt.Preview()

def PreviewNarrow(self):
self.ReadData()
new_data = []
for val in self.data:
new_data.append([val[0], val[1], val[2], val[4], val[5]])

val = self.header
new_header = [val[0], val[1], val[2], val[4], val[5]]

prt = printout.PrintTable(self.frame)
prt.data = new_data
prt.set_column = [ 1, 1, 1, 1, 2]
prt.label = new_header
prt.SetColAlignment(1, wx.ALIGN_CENTRE)
prt.SetColBackgroundColour(0, wx.NamedColour('RED'))
prt.SetColTextColour(0, wx.NamedColour('WHITE'))
prt.SetCellColour(4, 0, wx.NamedColour('LIGHT BLUE'))
prt.SetCellColour(4, 1, wx.NamedColour('LIGHT BLUE'))
prt.SetCellColour(17, 1, wx.NamedColour('LIGHT BLUE'))

prt.SetColBackgroundColour(2, wx.NamedColour('LIGHT BLUE'))
prt.SetCellText(4, 2, wx.NamedColour('RED'))

prt.SetColTextColour(3, wx.NamedColour('RED'))
prt.label_font_colour = wx.NamedColour('WHITE')
prt.SetHeader("wxWindows Applications", colour = wx.NamedColour('RED'))

prt.SetHeader("Printed: ", type = "Date & Time", align=wx.ALIGN_RIGHT, indent = -1, colour = wx.NamedColour('BLUE'))
prt.SetFooter("Page No", colour = wx.NamedColour('RED'), type ="Num")
prt.Preview()

def OnPreviewMatrix(self):
total_col = 45
total_row = 10
hsize = 0.2
vsize = 0.2

data = []
startx = 1.0
columns = []
for val in range(total_col):
columns.append(hsize)

prt = printout.PrintTable(self.frame)

for row in range(total_row):
value = []
for col in range(total_col):
value.append(str(col))
data.append(value)

for col in range(total_col):
prt.SetColAlignment(col, wx.ALIGN_CENTRE)

prt.SetLandscape()
prt.text_font_size = 8
prt.cell_left_margin = 0

prt.data = data
prt.set_column = columns
prt.SetHeader("Test of Small Grid Size")
prt.Preview()

def PreviewLine(self):
prt = printout.PrintTable(self.frame)
prt.label = ["Header 1", "Header 2", "Header 3"]
prt.set_column = []
prt.data = [["Row 1", "1", "2"], ["Row 2", "3", "4\nNew Line to see if it also can wrap around the cell region properly\nAnother new line"]]
prt.SetFooter()
prt.Preview()

def PreviewText(self):
prt = printout.PrintTable(self.frame)
prt.SetHeader("PROCLAMATION")
file = open('data/proclamation.txt')
data = []
for txt in file:
data.append(txt.strip())
file.close()
prt.data = data
prt.Preview()

def PrintWide(self):
self.ReadData()
prt = printout.PrintTable(self.frame)
prt.data = self.data

prt.left_margin = 0.5
prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ]
prt.label = self.header
prt.SetLandscape()
prt.Print()


#---------------------------------------------------------------------------

def runTest(frame, nb, log):
win = TablePanel(nb, log, frame)
return win

#---------------------------------------------------------------------------





overview = """\
<html><body>
<h2>Table Printing</h2>

This demo shows various ways of using the <b><i>new
</i></b> PrintOut class. To understand the class you need to examine the demo examples
and the library <a href="%s">printout.py</a> module classes.
<p>
The initial class primarily contains a Table preview/printing class. There is a lot of flexibility
in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
There are also a number of options for printing Header and Footer information on the page.
<p>
There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
<p>
The data is printed from a list object containing the column and row values. The label or table header
can be defined and will be repeated for all pages.
<p>
The correct "Total Page" does get calculated and used in the print out Footer.
<p>
There is still problems with the print framework to properly get the total pages in the preview unless
the program knows it before trying to parse through the available pages. This will be fixed
when the framework allows for it.


""" % os.path.join(os.path.dirname(printout.__file__), "printout.py")





if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

zheng_j_c 2010-09-13
  • 打赏
  • 举报
回复
有没有哪位老大又源码啊发来看看

邮箱:zjc19871110@qq.com
李察德-泰森 2010-08-31
  • 打赏
  • 举报
回复
把表格中的数据全部读取到列表中,然后自己设计打印的格式,填充数据,再打印吧。
zheng_j_c 2010-08-31
  • 打赏
  • 举报
回复
那位老大知道啊 !!支援一下下 啊??
thy38 2010-08-28
  • 打赏
  • 举报
回复
还是有点麻烦
javacode007 2010-08-26
  • 打赏
  • 举报
回复
自己写个打印表格的程序也可以啊
oluckly 2010-08-26
  • 打赏
  • 举报
回复
wxpython 自带demo中wxPython2.8 Docs and Demos有个TablePrint例子可以参考下
本课程采用了漫画+动手实操+练习讲授Python编程技能。课程简介:第11章 常用内置模块11.1 数学计算模块 —— math模块11.2 日期时间模块 —— datetime模块11.2.1 datetime类11.2.2 date类11.2.3 time类11.2.4 计算时间跨度类——timedelta11.2.5 将日期时间对象与字符串相互转换11.3 正则表达式模块 —— re模块11.3.1 字符串匹配11.3.2 字符串查找11.3.3 字符串替换11.3.4 字符串分割11.5 练一练第12章 文件读写12.1 打开文件12.2 关闭文件12.2.1 在finally代码块中关闭文件12.2.2 在with as代码块中关闭文件12.3 读写文本文件12.4 动动手 —— 复制文本文件12.5 读写二进制文件12.6 动动手 —— 复制二进制文件12.1 练一练第13章 图形用户界面13.1 Python中的图形用户界面开发库13.2 安装wxPython17813.3 第一个wxPython程序18013.4 自定义窗口类18213.5 在窗口中添加控件18213.6 事件处理18413.7 布局管理18513.7.1 盒子布局管理器18613.7.2 动动手——重构事件处理示例13.7.3 动动手——盒子布局管理器嵌套示例13.8 控件13.8.1 文本输入控件13.8.2 复选框和单选按钮13.8.3 列表13.8.4 静态图片控件13.9 点拨点拨 —— 如何使用wxPython官方文档13.10 练一练第14章 网络通信14.1 基本的网络知识14.1.1 TCP/IP14.1.2 IP地址14.1.3 端口14.1.4 HTTP/HTTPS14.2 搭建自己的Web服务器14.3 urllib.request模块14.3.1 发送GET请求14.3.2 发送POST请求14.4 JSON数据14.4.1 JSON文档的结构14.4.2 对JSON数据的解码14.5 动动手 —— 下载图片示例14.6 动动手 —— 返回所有备忘录信息14.7 练一练第15章 访问数据库15.1 SQLite15.1.1 SQLite的数据类型15.1.2 Python的数据类型与SQLite的数据类型的映射15.1.3 使用GUI管理工具管理SQLite15.2 数据库编程的基本操作过程15.3.1 数据库连接对象Connection15.3.2 游标对象Cursor15.4 动动手 —— 数据库的CRUD操作示例15.4.1 示例中的数据表15.4.2 无条件查询15.4.3 有条件查询15.4.4 插入数据15.4.5 更新数据15.4.6 删除数据15.5 点拨点拨 —— 防止SQL注入攻击15.6 练一练第16章 多线程16.1 线程相关的知识16.1.1 进程16.1.2 线程16.1.3 主线程16.2 线程模块 —— threading模块16.3 创建子线程16.3.1 自定义函数实现线程体16.3.2 自定义线程类实现线程体16.4 线程管理16.4.1 等待线程结束16.4.2 线程停止16.5 动动手 —— 下载图片示例16.6 练一练

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧