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 ...
随机推荐
- Wannafly挑战赛21:C - 大水题
链接:Wannafly挑战赛21:C - 大水题 题意: 现在给你N个正整数ai,每个数给出一“好数程度” gi(数值相同但位置不同的数之间可能有不同的好数程度).对于在 i 位置的数,如果有一在j位 ...
- 树莓派的WIFI配置
参考网址: http://www.cnblogs.com/iusmile/archive/2013/03/30/2991139.html http://my.oschina.net/pikeman/b ...
- 【Linux运维】LNMP环境配置
安装准备: Centos7.3 MYSQL5.6 PHP5.6 NGINX1.10.3 一.安装Mysql mysql:[root@host129 src]#cd /usr/local/src/ [r ...
- Oracle to MySQL Goldengate实现增量迁移
第一部分:安装和基本配置 一.环境 两台rhel 6.4虚拟机,分别异构oracle到mysql数据库同步测试Ip:192.168.0.23 部署oracle 11.2.0.4,goldgate 12 ...
- [leetcode-636-Exclusive Time of Functions]
Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...
- Python之tornado框架实现翻页功能
1.结果如图所示,这里将html页面与网站的请求处理放在不同地方了 start.py代码 import tornado.ioloop import tornado.web from controlle ...
- term "JavaScript"
在Web浏览器上下文中理解的总称“JavaScript”包含几个非常不同的元素. 其中一个是核心语言(ECMAScript),另一个是Web API的集合,包括DOM(文档对象模型) JavaScri ...
- 常用的gif加载动态图片
精心搜集的网页素材,包括:Loading GIF动画,"正在加载中"小图片,"请等待"小图标等,欢迎您的下载. 提示:点击鼠标右键,选择”图片另存为“即可轻松保 ...
- this.getClass().getResource()示例详解
public class ResourceTest extends TimerTask{ @Override public void run() { System.out.prin ...
- jcaptcha配置验证码
准备开始 首先导入jar包:jcaptcha-my-1.0 /** * web 常量 * @author lx * */ public abstract class Constants { /** 用 ...