python中wx将图标显示在右下角的脚本代码
2013-03-08 00:00
615 查看
import wx import images class DemoTaskBarIcon(wx.TaskBarIcon): TBMENU_RESTORE = wx.NewId() TBMENU_CLOSE = wx.NewId() TBMENU_CHANGE = wx.NewId() TBMENU_REMOVE = wx.NewId() def __init__(self, frame): wx.TaskBarIcon.__init__(self) self.frame = frame # Set the image icon = self.MakeIcon(images.getWXPdemoImage()) self.SetIcon(icon, "wxPython Demo") self.imgidx = 1 # bind some events self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate) self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=self.TBMENU_RESTORE) self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE) self.Bind(wx.EVT_MENU, self.OnTaskBarChange, id=self.TBMENU_CHANGE) self.Bind(wx.EVT_MENU, self.OnTaskBarRemove, id=self.TBMENU_REMOVE) def CreatePopupMenu(self): """ This method is called by the base class when it needs to popup the menu for the default EVT_RIGHT_DOWN event. Just create the menu how you want it and return it from this function, the base class takes care of the rest. """ menu = wx.Menu() menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo") menu.Append(self.TBMENU_CLOSE, "Close wxPython Demo") menu.AppendSeparator() menu.Append(self.TBMENU_CHANGE, "Change the TB Icon") menu.Append(self.TBMENU_REMOVE, "Remove the TB Icon") return menu def MakeIcon(self, img): """ The various platforms have different requirements for the icon size... """ if "wxMSW" in wx.PlatformInfo: img = img.Scale(16, 16) elif "wxGTK" in wx.PlatformInfo: img = img.Scale(22, 22) # wxMac can be any size upto 128x128, so leave the source img alone.... icon = wx.IconFromBitmap(img.ConvertToBitmap() ) return icon def OnTaskBarActivate(self, evt): if self.frame.IsIconized(): self.frame.Iconize(False) if not self.frame.IsShown(): self.frame.Show(True) self.frame.Raise() def OnTaskBarClose(self, evt): self.frame.Close() def OnTaskBarChange(self, evt): names = [ "WXPdemo", "Mondrian", "Pencil", "Carrot" ] name = names[self.imgidx] getFunc = getattr(images, "get%sImage" % name) self.imgidx += 1 if self.imgidx >= len(names): self.imgidx = 0 icon = self.MakeIcon(getFunc()) self.SetIcon(icon, "This is a new icon: " + name) def OnTaskBarRemove(self, evt): self.RemoveIcon() class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300)) panel = wx.Panel(self, -1) panel.Bind(wx.EVT_MOTION, self.OnMove) wx.StaticText(panel, -1, "Pos:", pos=(10, 12)) self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10)) try: self.tbicon = DemoTaskBarIcon(self) except: self.tbicon = None #wx.CallAfter(self.ShowTip) #self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) #self.Bind(wx.EVT_ICONIZE, self.OnIconfiy) def OnCloseWindow(self, event): self.dying = True self.demoPage = None self.codePage = None self.mainmenu = None if self.tbicon is not None: self.tbicon.Destroy() self.Destroy() def OnIconfiy(self, evt): wx.LogMessage("OnIconfiy: %s" % evt.Iconized()) evt.Skip() def OnMove(self, event): pos = event.GetPosition() self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y)) if __name__ == '__main__': app = wx.PySimpleApp() frame = MyFrame() frame.Show(True) app.MainLoop()
相关文章推荐
- python中wx将图标显示在右下角的脚本代码
- 编写Python脚本使得web页面上的代码高亮显示
- Python进度条实时显示处理进度的示例代码
- 问题描述:project图标显示错误,但内部代码没错误
- 【脚本语言系列】关于Python代码包/代码库搜索,你需要知道的事
- 【脚本语言系列】关于Python安装代码包,你需要知道的事
- 利用python脚本抓取AC的代码[爬虫+HTMLParser+handle_entityref+正则表达式+模拟登陆+文件操作]
- 教你用Python脚本快速为iOS10生成图标和截屏
- selenium+python关于登录的脚本代码,使用了读取excel以及向excel中写入测试结果的方法
- PHP预防跨站脚本(XSS)攻击且不影响html代码显示效果
- Python测试用例生成脚本(合并相应单元格以及写入单行数据)代码实例
- python wx中 TextCtrl 实现与 StaticText 相似的显示效果
- 怎样使用hightlight高亮显示脚本代码?
- python写的小巧的(14行有效代码)随机密码生成小脚本工具
- python 生成目录树及显示文件大小的代码
- Python抓取Discuz!用户名脚本代码
- shell脚本命令 运行python文件&python命令行运行python代码
- Python代码高亮显示工具
- 28. Python脚本学习笔记二十八代码检测和分析
- Photoshop脚本代码一键生成所有IOS图标