2009年6月30日星期二

转贴一个利用sizer的参考代码

原帖地址:http://wxforum.shadonet.com/viewtopic.php?t=24064



实现如图的layout :

//create sizer
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);

// top
pPanelTop = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(320, 60) );
wxColour color(_T("#FDFDFD"));
pPanelTop->SetBackgroundColour(color);

sizer->Add(pPanelTop, 0, wxALIGN_TOP wxEXPAND, 0);

// center
pPanelCenter = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(300, 400) );
wxColour black_color(_T("BLACK"));
pPanelCenter->SetBackgroundColour(black_color);

pPanelLeft = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(10, 100) );
pPanelRight = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(10, 100) );
pPanelLeft->SetBackgroundColour(color);
pPanelRight->SetBackgroundColour(color);

wxBoxSizer *center_sizer = new wxBoxSizer(wxHORIZONTAL);
center_sizer->Add(pPanelLeft, 0, wxEXPAND, 0);
center_sizer->Add(pPanelCenter, 1, wxEXPAND, 0);
center_sizer->Add(pPanelRight, 0, wxEXPAND, 0);

// bottom
pPanelBottom = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(100, 10) );
pPanelBottom->SetBackgroundColour(color);

sizer->Add(center_sizer, 1, wxEXPAND, 0);
sizer->Add(pPanelBottom, 0, wxALIGN_BOTTOM wxEXPAND, 0);

sizer->SetSizeHints(this);
SetSizer(sizer);

2009年6月25日星期四

Python视频教程--(设置环境变量)Adding Python to DOS Path

自己作为一个PYthon的初学者,更能够理解一些初学者的迷惑的心情,和渴望有一个高手能给自己演示操作一下。这样或许能帮助我们更好的理解某些书面文字,今天上网搜到一个视频教程网,虽然是英文的但有些操作是可以看的,所以推荐给网友看看。

直接点击下面网址,进入网站在线观看。

视频所在网址: 'Adding Python to DOS Path'
at ShowMeDo from the Python category.

2009年6月24日星期三

wxpython学习心得

今天调试自己的一个代码,发现在自己电脑上可以通过,转到单位电脑上就报错“NameError: global name 'INB_FIT_LABELTEXT' is not defined”,真的很奇怪,最后发现我个人电脑装的是wxpython 最新版本wxPython2.8-win32-unicode-2.8.10.1-py25,而单位的是wxPython2.8-win32-unicode-2.8.9.2-py25,我把单位电脑的wxpython升级之后,问题迎刃而解了。

看来wxPython2.8-win32-unicode-2.8.9.2-py25里没有定义INB_FIT_LABELTEXT这个style。

推荐一款性能可比Windows优化大师的多国语言版系统优化软件

最近发现一款比较不错的免费的系统优化软件,Glary Utilities。
最大的特点是可以支持多国语言,可以装在日文,英文,中文等多个系统。
下载地址是http://www.glaryutilities.com/gu.html?tag=download

wxpython demo labelbook学习心得

今天终于完成了一个自己第一个代码的完善工作--一个wxpython的demo labelbook的学习代码。
作为纪念想把代码写入博客,也算是给网友一个分享吧。
再此也要感谢python-cn`CPyUG`华蟒用户组(中文Py用户组)中一个叫汪文进的网友,他给了我很大的帮助使得我能够顺利完成。
程序代码如下:
import wx
import wx.lib.colourselect as csel
import os
import sys


try:
dirName = os.path.dirname(os.path.abspath(__file__))
except:
dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

bitmapDir = os.path.join(dirName, 'images')
sys.path.append(os.path.split(dirName)[0])

try:
from agw import labelbook as LB
from agw.fmresources import *
except ImportError: # if it's not there locally, try the wxPython lib.
import wx.lib.agw.labelbook as LB
from wx.lib.agw.fmresources import *

#import images
_pageTexts = ["Hello", "From", "wxPython", "LabelBook", "Demo"]
#_pageIcons = []
_pageIcons = ["roll.png", "charge.png", "add.png", "decrypted.png", "news.png"]

#_pageIcons = ["icon-equiv.png","icon-minimiz.png","icon-product.png","icon-setup.png","product4x.png"]
_pageColours = [wx.RED, wx.GREEN, wx.WHITE, wx.BLUE, "Pink"]

class LabelBook(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.mainpanel = wx.Panel(self, -1)

self.SetProperties()
self.CreateLabelBook()
self.DoLayout()

self.SetSize((600,500))

#self.SetIcon(images.Mondrian.GetIcon())
self.CenterOnScreen()

#self.initializing = False
self.SendSizeEvent()

def SetProperties(self):

self.SetTitle("The success labelbook!-)")


def DoLayout(self):
mainsizer = wx.BoxSizer(wx.VERTICAL)
panelsizer = wx.BoxSizer(wx.VERTICAL)

panelsizer.Add(self.book, 1, wx.EXPAND, 0)
self.mainpanel.SetSizer(panelsizer)
panelsizer.Layout()

mainsizer.Add(self.mainpanel, 1, wx.EXPAND, 0)

self.SetSizer(mainsizer)
mainsizer.Layout()
self.Layout()

def CreateLabelBook(self):
style = self.GetBookStyles()

self.book = LB.LabelBook(self.mainpanel, -1,style=style)
#self.book = LB.FlatImageBook(self.mainpanel, -1, style=style)

self.imagelist = self.CreateImageList()
self.book.AssignImageList(self.imagelist)
#self.Refresh()

for indx, txts in enumerate(_pageTexts):
#label = "This is panel number %d"%(indx+1)
self.book.AddPage(TestPanel(self.book,_pageColours[indx]),
txts, True, indx)

self.book.SetSelection(0)
#self.book.SetWindowStyleFlag(style=LB.INB_FIT_BUTTON)

self.SendSizeEvent()

def GetBookStyles(self):
style = INB_FIT_BUTTON

style |= LB.INB_FIT_LABELTEXT
#style |= INB_WEB_HILITE
style |= INB_USE_PIN_BUTTON
#style |= INB_BORDER
#style |= LB.INB_SHOW_ONLY_TEXT #only used in FlatImageBook type

style = self.GetBookOrientation(style)

return style


def CreateImageList(self):

imagelist = wx.ImageList(32, 32)
for img in _pageIcons:
newImg = os.path.join(bitmapDir, "lb%s"%img)
bmp = wx.Bitmap(newImg, wx.BITMAP_TYPE_PNG)
imagelist.Add(bmp)

#bmp = imagebmp.GetBitmap()
#for i in range(5):
# imagelist.Add(bmp)

return imagelist

def GetBookOrientation(self, style):

style |= INB_LEFT
#style |= INB_RIGHT
#style |= LB.INB_TOP #only used in FlatImageBook type
#style |= INB_BOTTOM #only used in FlatImageBook type

return style

#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent,colour):
#self.log = log
wx.Panel.__init__(self, parent, -1)

st = wx.StaticText(self, -1,
"You can put nearly any type of window here,\n"
"and if the platform supports it then the\n"
"tabs can be on any side of the notebook.",
(10, 10))

b = wx.Button(self, -1, " Test LabelBook And FlatImageBook ", (100,100))


self.Bind(wx.EVT_BUTTON, self.OnButton, b)
self.SetBackgroundColour(colour)

def OnButton(self, evt):
msg= "this is a botton!"
dlg = wx.MessageDialog(self,msg,"this my test",wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = LabelBook(None)
frame.Show()
app.MainLoop()