wx.ScrolledWindow wx.PseudoDC
# encoding: utf-8
import logging
import random
import wx
import wx.lib.inspection
def GetMyBitmap():
image = wx.Image("0.png", wx.BITMAP_TYPE_PNG)
return wx.BitmapFromImage(image)
ID_BTN_SPY = wx.NewId()
W = 2000
H = 2000
SW = 150
SH = 150
SHAPE_COUNT = 2500
hitradius = 5
colours = [
"BLACK",
"BLUE",
"BLUE VIOLET",
"BROWN",
"CYAN",]
class MyCanvas(wx.ScrolledWindow):
def RandomPen(self):
c = random.choice(colours)
t = random.randint(1, 4)
if not self.pen_cache.has_key( (c, t) ):
self.pen_cache[(c, t)] = wx.Pen(c, t)
return self.pen_cache[(c, t)]
def RandomColor(self):
return random.choice(colours)
def RandomBrush(self):
c = random.choice(colours)
if not self.brush_cache.has_key(c):
self.brush_cache[c] = wx.Brush(c)
return self.brush_cache[c]
def DoDrawing(self, dc):
random.seed()
self.objids = []
self.boundsdict = {}
dc.BeginDrawing()
id = wx.NewId()
dc.SetId(id)
w,h = self.bmp.GetSize()
x = w
y = h
dc.DrawBitmap(self.bmp,x,y,True)
dc.SetIdBounds(id,wx.Rect(x,y,w,h))
self.objids.append(id)
dc.EndDrawing()
def __init__(self, parent, id, log, size = wx.DefaultSize):
wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER)
self.lines = []
self.maxWidth = W
self.maxHeight = H
self.x = self.y = 0
self.curLine = []
self.drawing = False
self.SetBackgroundColour("WHITE")
bmp = GetMyBitmap()
mask = wx.Mask(bmp, wx.BLUE)
bmp.SetMask(mask)
self.bmp = bmp
self.SetVirtualSize((self.maxWidth, self.maxHeight))
self.SetScrollRate(20,20)
# create a PseudoDC to record our drawing
self.pdc = wx.PseudoDC()
self.pen_cache = {}
self.brush_cache = {}
self.DoDrawing(self.pdc)
log.info('Created PseudoDC draw list with %d operations!'%self.pdc.GetLen())
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
# vars for handling mouse clicks
self.dragid = -1
self.lastpos = (0,0)
def OnMouse(self, event):
pass
def OnPaint(self, event):
# Create a buffered paint DC. It will create the real
# wx.PaintDC and then blit the bitmap to it when dc is
# deleted.
dc = wx.BufferedPaintDC(self)
# use PrepateDC to set position correctly
self.PrepareDC(dc)
# we need to clear the dc BEFORE calling PrepareDC
bg = wx.Brush(self.GetBackgroundColour())
dc.SetBackground(bg)
dc.Clear()
# create a clipping rect from our position and size
# and the Update Region
xv, yv = self.GetViewStart()
dx, dy = self.GetScrollPixelsPerUnit()
x, y = (xv * dx, yv * dy)
rgn = self.GetUpdateRegion()
rgn.Offset(x,y)
r = rgn.GetBox()
# draw to the dc using the calculated clipping rect
self.pdc.DrawToDCClipped(dc,r)
class MyFrame(wx.Frame):
def OnBtnSpy(self, evt):
print 'click btn spy'
wx.lib.inspection.InspectionTool().Show()
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(300,300))
self.log = None
panel0 = wx.Panel(self, -1)
btn1 = wx.Button(panel0, ID_BTN_SPY, label='spy++')
self.log = logging
win = MyCanvas(self, -1, self.log)
sz0 = wx.BoxSizer(wx.VERTICAL)
sz0.Add(panel0, flag=wx.EXPAND)
sz0.Add(win, proportion=1, flag=wx.EXPAND)
self.SetSizer(sz0)
self.Bind(wx.EVT_BUTTON, self.OnBtnSpy, id=ID_BTN_SPY)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
wx.ScrolledWindow wx.PseudoDC的更多相关文章
- 微信 小程序 drawImage wx.canvasToTempFilePath wx.saveFile 获取设备宽高 尺寸问题
以下问题测试环境为微信开发者0.10.102800,手机端iphone6,如有不对敬谢指出. 根据我的测试,context.drawImage,在开发者工具中并不能画出来,只有预览到手机中显示. wx ...
- 设置API:wx.openSetting,wx.getSetting使用说明(示例:地图授权与取消授权后的重新授权)
这个API解决了过去一个长久以来无法解决的问题,如何让用户重复授权: 打开小程序的设置界面:就是主动调取授权 目前资料极少,但是已经可以让大家先看看了: 官方文档地址:https://mp.weixi ...
- 开发 | 小程序wx.setScreenBrightness/wx.getScreenBrightness接口测试
前言 最近接触了微信小程序 API - wx.setScreenBrightness .wx.getScreenBrightness 接口,调用该接口可以调节并显示手机屏幕亮度数据.对于喜欢腾讯新闻. ...
- H5+.Net Webapi集成微信分享前后端代码 微信JS-SDK wx.onMenuShareTimeline wx.onMenuShareAppMessage
说明: 1/因为赚麻烦这里没有使用数据库或服务器缓存来存储access_token和jsapi_ticket,为了方便这里使用了本地的xml进行持久化这两个值以及这两个值的创建时间和有限期限. 2/每 ...
- 微信小程序 带参调用后台接口 循环渲染页面 wx.request wx:for
test.js 文件里的onLoad function getarticles(p,order,mythis) { wx.request({ url: 'https://ganggouo.cn/ind ...
- 微信小游戏 交互接口的使用 wx.showToast wx.showLoading
在小游戏中,会有如下图的提示窗口,这些可以使用微信提供的交互接口实现. 使用loading等待的接口.mask=true表示遮罩,防止等待时点击其他按钮触发其他操作导致异常. wx.showLoadi ...
- 小程序中navigator和wx.navigateTo,wx.redirectTo,wx.reLaunch,wx.switchTab,wx.navigateBack的用法
如果用一句话来表明navigator和API中wx.系列的跳转有什么区别,那就是navigator是在wxml中用标签添加open-type属性来达到和wx.系列一样的效果. navigator的属性 ...
- wx:for wx:for-items wx:for-item
data:{ arr:[1,2,3,4,5], arrs:[[1,2,3,4,5],[1,2,3,4,5]] }wx:for 用于循环数组 默认数组的当前项的下标变量名默认为 index,数组当 ...
- 微信小程序开发之三元运算符代替wx.if/wx.else
直接上代码 实现功能为:当fbphotoFirst为空时,src路径为“pic/信息反馈1-1_14.png“,并且点击事件uploadfbphotoFirst有效,否则为路径fbphotoFirst ...
随机推荐
- 「暑期训练」「基础DP」 Monkey and Banana (HDU-1069)
题意与分析 给定立方体(个数不限),求最多能堆叠(堆叠要求上方的方块严格小于下方方块)的高度. 表面上个数不限,问题是堆叠的要求决定了每个方块最多可以使用三次.然后就是对3n" role=& ...
- join ,left join ,right join有什么区别
join等价于inner join内连接,是返回两个表中都有的符合条件的行. left join左连接,是返回左表中所有的行及右表中符合条件的行.(左表为主表) right join右连接,是返回右表 ...
- 怎样安装Python3
在浏览器地址栏输入https://www.python.org/ 打开Python官网 好了,安装完成了! 可以把安装路径C:\Users\Administrator\AppData\Local\Pr ...
- laravel跨域问题
// 只有同源策略才允许发送cookies // header('Access-Control-Allow-Credentials:true'); 需要要index.php下开启 最近写登录图形验证码 ...
- Fluentd插件使用方法
这里主要介绍从MongoDB同步数据到ODPS.ruby环境的搭建以及fluent_plugin_mongo_odps插件的安装.1.准备工作1.1安装环境要求Ruby 2.1以上Gem 2.4.5以 ...
- GraphSAGE 代码解析(一) - unsupervised_train.py
原创文章-转载请注明出处哦.其他部分内容参见以下链接- GraphSAGE 代码解析(二) - layers.py GraphSAGE 代码解析(三) - aggregators.py GraphSA ...
- Halcon17对硬件配置要求
Halcon17对硬件配置要求 Halcon17已经发布出来了,很多朋友一定想安装这款机器视觉软件来学习,我们今天给大家讲解下,Halcon17对硬件配置的要求: Halcon17 For Wind ...
- NOIP 2009 靶形数独(DLX)
小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士拿出了他最近发明的“靶形数独”,作 ...
- 第十三次ScrumMeeting会议
第十三次Scrum Meeting 时间:2017/12/1 地点:咖啡馆 人员:策划组美工组 名字 完成的工作 计划工作 蔡帜 完成公式的基本策划,Bug数量产生机制设计 科技树方面机制确定 游心 ...
- hadoop自定义数据类型
统计某手机数据库的每个手机号的上行数据包数量和下行数据包数量 数据库类型如下: 数据库内容如下: 下面自定义类型SimLines,类似于平时编写的model import java.io.DataIn ...