圆月山庄资源网 Design By www.vgjia.com
本文实例为大家分享了wxPython画图板展示的具体代码,供大家参考,具体内容如下
#coding:GBK ''' Created on 2012-3-22 @author: cWX53049 ''' import wx import time from bsddb.test.test_pickle import cPickle import os _formatStr="%Y-%m-%d %H:%M:%S" class SkethWindow(wx.Window): def __init__(self,parent,ID): wx.Window.__init__(self,parent,ID) self.SetBackgroundColour("White") self.color="Black" self.thickness=1 self.pen=wx.Pen(self.color,self.thickness,wx.SOLID)#创建一个pen self.lines=[] self.curLine=[] self.pos=(0,0) self.InitBuffer() self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_IDLE,self.OnIdle) self.Bind(wx.EVT_PAINT, self.OnPaint) def InitBuffer(self): size = self.GetClientSize() self.buffer=wx.EmptyBitmap(size.width,size.height) dc = wx.BufferedDC(None,self.buffer) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() self.DrawLines(dc) self.reInitBuffer=False def GetLinesData(self): return self.lines[:] def SetLinesData(self,lines): self.lines = lines[:] self.InitBuffer() self.Refresh() def OnLeftDown(self,event): self.curLine=[] self.pos=event.GetPositionTuple()#得到鼠标的位置 self.CaptureMouse()#捕获鼠标 def OnLeftUp(self,event): if self.HasCapture(): self.lines.append((self.color, self.thickness, self.curLine)) self.curLine=[] self.ReleaseMouse()#释放鼠标 def OnMotion(self,event): if event.Dragging() and event.LeftIsDown():#确定是否在拖动 dc = wx.BufferedDC(wx.ClientDC(self),self.buffer)#创建另一个 self.drawMotion(dc,event) event.Skip() def drawMotion(self,dc,event): dc.SetPen(self.pen) newPos=event.GetPositionTuple() coords=self.pos+newPos self.curLine.append(coords) dc.DrawLine(*coords) self.pos=newPos def OnSize(self,event): self.reInitBuffer=True#处理一个resize事件 def OnIdle(self,event): if self.reInitBuffer: self.InitBuffer() self.Refresh() def OnPaint(self,event): wx.BufferedPaintDC(self,self.buffer) def DrawLines(self,dc): for colur,thickness,line in self.lines: pen = wx.Pen(colur,thickness,wx.SOLID) dc.SetPen(pen) for coords in line: dc.DrawLine(*coords) def SetColor(self,color): self.color = color self.pen = wx.Pen(self.color,self.thickness,wx.SOLID) def SetThickness(self,num): self.thickness=num self.pen=wx.Pen(self.color,self.thickness,wx.SOLID) class SkethFrame(wx.Frame): def __init__(self,parent): self.title="绘画窗体" wx.Frame.__init__(self,parent,-1,self.title,size=(500,500)) self.sketh=SkethWindow(self,-1) self.InitStatusBar() self.sketh.Bind(wx.EVT_MOTION, self.showPosition) self.initMenuBar() self.wildcard="Sketch file(*.sketch)|All files(*.*)|*.*" self.fileName="" def OnNew(self,event): pass def OnOpen(self,event): pass def OnSave(self,event): if not self.fileName: self.OnSaveAs(event) else: self.SaveFile() def SaveFile(self): if self.fileName: data = self.sketh.GetLinesData() f = open(self.fileName,'w') cPickle.dump(data, f) f.close() def OnSaveAs(self,event): dlf = wx.FileDialog(self,"Sketch file",os.getcwd(),style=wx.SAVE|wx.OVERWRITE_PROMPT) if dlf.ShowModal()==wx.ID_OK: fileName = dlf.GetPath() if not os.path.splitext(fileName)[1]: fileName=fileName+'.sketch' self.fileName=fileName self.SaveFile() self.SetTitle(self.title+'--'+self.fileName) dlf.Destroy() def OnColor(self,event): pass def OnCloseWindow(self,event): self.Destroy() def menuData(self): return [("&File",( ("&New","New Sketch file",self.OnNew), ("&Open","open sketch file",self.OnOpen), ("&Save","save sktech file",self.OnSave), ("","",""), ("&Color",( ("&Black","",self.OnColor,wx.ITEM_RADIO), ("&Red","",self.OnColor,wx.ITEM_RADIO), ("&Red","",self.OnColor,wx.ITEM_RADIO), ("&Blue","",self.OnColor,wx.ITEM_RADIO))), ("","",""), ("&Quit","quit sketch ",self.OnCloseWindow)))] def initMenuBar(self): menuBar=wx.MenuBar() for eachMenu in self.menuData(): eachMenuLabel = eachMenu[0] eachMenuItems = eachMenu[1] menuBar.Append(self.createMenu(eachMenuItems),eachMenuLabel) self.SetMenuBar(menuBar) def createMenu(self,menuData): menu = wx.Menu() for eachMenu in menuData: if len(eachMenu)==2: label = eachMenu[0] subBar =self.createMenu(eachMenu[1]) menu.AppendMenu(wx.NewId(),label,subBar) else: self.createMenuItem(menu,*eachMenu) return menu def createMenuItem(self,menu,label,status,handler,kind=wx.ITEM_NORMAL): if not label: menu.AppendSeparator() return menuItem=menu.Append(-1,label,status,kind) self.Bind(wx.EVT_MENU,handler,menuItem) def InitStatusBar(self): self.statusBar=self.CreateStatusBar() self.statusBar.SetFieldsCount(4) self.statusBar.SetStatusWidths([-1,-2,-2,-2]) self.timer=wx.Timer(self) self.Bind(wx.EVT_TIMER, self.updateTime, self.timer) self.timer.Start(1000) self.statusBar.SetStatusText("Time is %s"%time.strftime(_formatStr,time.localtime()),3) self.statusBar.SetStatusText("Pos (0,0)",1) self.statusBar.SetStatusText("Cur Line 0",2) self.statusBar.SetStatusText("Lines 0" ,3) def showPosition(self,event): self.statusBar.SetStatusText("Pos %s"%str(event.GetPositionTuple()),0) self.statusBar.SetStatusText("Cur Line %s"%len(self.sketh.curLine),1) self.statusBar.SetStatusText("Lines %s"%len(self.sketh.lines),2) event.Skip() def updateTime(self,event): self.statusBar.SetStatusText("Time is %s"%time.strftime(_formatStr,time.localtime()),3) if __name__=="__main__": app = wx.PySimpleApp(False) frame=SkethFrame(None) frame.Center() frame.Show(True) app.MainLoop()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
wxPython,画图板
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月05日
2024年11月05日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]