2005年02月03日 星期四 17:22
不好意思,对wxWindows不是很熟悉。 我写了以下代码,把窗体分成左右两部分SplitterWindow,左边放一个Tree,右边放一个ListCtrl 请问,如何让右边的ListCtrl充满窗体右边整个SplitterWindow部分? #!/bin/python import sys, os, time, traceback, types import wx # This module uses the new wx namespace import wx.html import wx.lib.mixins.listctrl as listmix listctrldata = { 1 : ("Name1", "Type1", "Data1"), 2 : ("Name2", "Type2", "Data2"), } class DemoListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.TextEditMixin): def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES): wx.ListCtrl.__init__(self, parent, ID, pos, size, style) listmix.ListCtrlAutoWidthMixin.__init__(self) self.Populate() listmix.TextEditMixin.__init__(self) def Populate(self): # for normal, simple columns, you can add them like this: self.InsertColumn(0, "Name") self.InsertColumn(1, "Type") self.InsertColumn(2, "Data") items = listctrldata.items() for key, data in items: index = self.InsertStringItem(sys.maxint, data[0]) self.SetStringItem(index, 0, data[0]) self.SetStringItem(index, 1, data[1]) self.SetStringItem(index, 2, data[2]) self.SetItemData(index, key) self.SetColumnWidth(0, wx.LIST_AUTOSIZE) self.SetColumnWidth(1, wx.LIST_AUTOSIZE) self.SetColumnWidth(2, wx.LIST_AUTOSIZE) self.currentItem = 0 def SetStringItem(self, index, col, data): if col in range(3): wx.ListCtrl.SetStringItem(self, index, col, data) wx.ListCtrl.SetStringItem(self, index, 3+col, str(len(data))) else: try: datalen = int(data) except: return wx.ListCtrl.SetStringItem(self, index, col, data) data = self.GetItem(index, col-3).GetText() wx.ListCtrl.SetStringItem(self, index, col-3, data[0:datalen]) class DemoWnd(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, -1, title, size = (950, 720), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE ) self.SetMinSize((640,480)) self.Centre(wx.BOTH) self.CreateStatusBar(1, wx.ST_SIZEGRIP) # Make a File menu self.mainmenu = wx.MenuBar() menu = wx.Menu() item = menu.Append(-1, 'E&xit;\tAlt-X', 'Get the heck outta here!') self.Bind(wx.EVT_MENU, self.OnFileExit, item) wx.App.SetMacExitMenuItemId(item.GetId()) self.mainmenu.Append(menu, '&File;') self.SetMenuBar(self.mainmenu) splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE ) self.splitter = splitter splitter2 = wx.SplitterWindow(splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) self.splitter2 = splitter2 def EmptyHandler(evt): pass # Create a TreeCtrl tID = wx.NewId() self.treeMap = {} self.tree = wx.TreeCtrl(splitter, tID, style = wx.TR_DEFAULT_STYLE #| wx.TR_HAS_VARIABLE_ROW_HEIGHT ) root = self.tree.AddRoot("wxPython Overview") # Create a ListCtrl tID = wx.NewId() self.list = DemoListCtrl(splitter2, tID, style=wx.LC_REPORT | wx.BORDER_NONE | wx.LC_SORT_ASCENDING ) #self.Bind(wx.EVT_SIZE, self.OnSize) # add the windows to the splitter and split it. splitter.SplitVertically(self.tree, splitter2, 200) #splitter2.SplitHorizontally(self.list, -160) splitter.SetMinimumPaneSize(120) splitter2.SetMinimumPaneSize(60) # Make the splitter on the right expand the top window when resized def SplitterOnSize(evt): splitter = evt.GetEventObject() sz = splitter.GetSize() splitter.SetSashPosition(sz.height - 160, False) evt.Skip() splitter2.Bind(wx.EVT_SIZE, SplitterOnSize) #--------------------------------------------- # Menu methods def OnFileExit(self, *event): self.Close() class App(wx.App): def OnInit(self): frame = DemoWnd(None, -1, "TestDemo") frame.Show() return True app = App(0) app.MainLoop()
2005年02月03日 星期四 17:40
在两个窗口上放两个panel,然后将tree和listctrl分别放在两个panel上。同时可 以考虑使用boxsizer来控制tree和listctrl的大小。 hw_cg wrote: > 不好意思,对wxWindows不是很熟悉。 > 我写了以下代码,把窗体分成左右两部分SplitterWindow,左边放一个Tree,右边放一个ListCtrl > > 请问,如何让右边的ListCtrl充满窗体右边整个SplitterWindow部分? > > #!/bin/python > > import sys, os, time, traceback, types > import wx # This module uses the new wx namespace > import wx.html > > import wx.lib.mixins.listctrl as listmix > > listctrldata = { > 1 : ("Name1", "Type1", "Data1"), > 2 : ("Name2", "Type2", "Data2"), > } > > class DemoListCtrl(wx.ListCtrl, > listmix.ListCtrlAutoWidthMixin, > listmix.TextEditMixin): > > def __init__(self, parent, ID, pos=wx.DefaultPosition, > size=wx.DefaultSize, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES): > wx.ListCtrl.__init__(self, parent, ID, pos, size, style) > > listmix.ListCtrlAutoWidthMixin.__init__(self) > self.Populate() > listmix.TextEditMixin.__init__(self) > > def Populate(self): > # for normal, simple columns, you can add them like this: > self.InsertColumn(0, "Name") > self.InsertColumn(1, "Type") > self.InsertColumn(2, "Data") > > items = listctrldata.items() > for key, data in items: > index = self.InsertStringItem(sys.maxint, data[0]) > self.SetStringItem(index, 0, data[0]) > self.SetStringItem(index, 1, data[1]) > self.SetStringItem(index, 2, data[2]) > self.SetItemData(index, key) > > self.SetColumnWidth(0, wx.LIST_AUTOSIZE) > self.SetColumnWidth(1, wx.LIST_AUTOSIZE) > self.SetColumnWidth(2, wx.LIST_AUTOSIZE) > > self.currentItem = 0 > > def SetStringItem(self, index, col, data): > if col in range(3): > wx.ListCtrl.SetStringItem(self, index, col, data) > wx.ListCtrl.SetStringItem(self, index, 3+col, str(len(data))) > else: > try: > datalen = int(data) > except: > return > wx.ListCtrl.SetStringItem(self, index, col, data) > data = self.GetItem(index, col-3).GetText() > wx.ListCtrl.SetStringItem(self, index, col-3, data[0:datalen]) > > > class DemoWnd(wx.Frame): > def __init__(self, parent, id, title): > wx.Frame.__init__(self, parent, -1, title, size = (950, 720), > style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE ) > > self.SetMinSize((640,480)) > > self.Centre(wx.BOTH) > self.CreateStatusBar(1, wx.ST_SIZEGRIP) > > # Make a File menu > self.mainmenu = wx.MenuBar() > menu = wx.Menu() > > item = menu.Append(-1, 'E&xit;\tAlt-X', 'Get the heck outta here!') > self.Bind(wx.EVT_MENU, self.OnFileExit, item) > wx.App.SetMacExitMenuItemId(item.GetId()) > self.mainmenu.Append(menu, '&File;') > > self.SetMenuBar(self.mainmenu) > > splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE ) > self.splitter = splitter > splitter2 = wx.SplitterWindow(splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) > self.splitter2 = splitter2 > > def EmptyHandler(evt): pass > > # Create a TreeCtrl > tID = wx.NewId() > self.treeMap = {} > self.tree = wx.TreeCtrl(splitter, tID, style = > wx.TR_DEFAULT_STYLE #| wx.TR_HAS_VARIABLE_ROW_HEIGHT > ) > root = self.tree.AddRoot("wxPython Overview") > > # Create a ListCtrl > tID = wx.NewId() > self.list = DemoListCtrl(splitter2, tID, > style=wx.LC_REPORT > | wx.BORDER_NONE > | wx.LC_SORT_ASCENDING > ) > #self.Bind(wx.EVT_SIZE, self.OnSize) > > # add the windows to the splitter and split it. > splitter.SplitVertically(self.tree, splitter2, 200) > #splitter2.SplitHorizontally(self.list, -160) > > splitter.SetMinimumPaneSize(120) > splitter2.SetMinimumPaneSize(60) > > # Make the splitter on the right expand the top window when resized > def SplitterOnSize(evt): > splitter = evt.GetEventObject() > sz = splitter.GetSize() > splitter.SetSashPosition(sz.height - 160, False) > evt.Skip() > > splitter2.Bind(wx.EVT_SIZE, SplitterOnSize) > #--------------------------------------------- > # Menu methods > def OnFileExit(self, *event): > self.Close() > > class App(wx.App): > def OnInit(self): > frame = DemoWnd(None, -1, "TestDemo") > frame.Show() > return True > > app = App(0) > app.MainLoop() > > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese -- I love python! My Blog: http://www.donews.net/limodou
2005年02月04日 星期五 09:31
hw_cg wrote: > 我写了以下代码,把窗体分成左右两部分SplitterWindow,左边放一个Tree,右边放一个ListCtrl > > 请问,如何让右边的ListCtrl充满窗体右边整个SplitterWindow部分? [snip] > > splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE ) > self.splitter = splitter > splitter2 = wx.SplitterWindow(splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) > self.splitter2 = splitter2 你在splitter的右边放的是一个SplitterWindow,不是ListCtrl。 [snip] > # Create a ListCtrl > tID = wx.NewId() > self.list = DemoListCtrl(splitter2, tID, > style=wx.LC_REPORT > | wx.BORDER_NONE > | wx.LC_SORT_ASCENDING > ) > #self.Bind(wx.EVT_SIZE, self.OnSize) 你把ListCtrl放在splitter2下面了。 [snip] 你的splitter2只设置了一个子窗口,当然显示不正确。 解决方法一: 删除splitter2,直接将ListCtrl放在splitter下 解决方法二: 给splitter2再加一个子窗口,然后用splitter2.SplitHorizontally分割。
2005年02月04日 星期五 09:48
明白了,原来是自己对splitter的理解不正确,采用方法二多了一个窗口不符合我的要求, 采用方法一,解决问题了。 ----- Original Message ----- From: "Qiangning Hong" <hongqn at gmail.com> To: <python-chinese at lists.python.cn> Sent: Friday, February 04, 2005 9:31 AM Subject: Re: [python-chinese] wxWindows中,如何让一个控件充满整个对话框? > hw_cg wrote: > > 我写了以下代码,把窗体分成左右两部分SplitterWindow,左边放一个Tree,右边放一个ListCtrl > > > > 请问,如何让右边的ListCtrl充满窗体右边整个SplitterWindow部分? > [snip] > > > > splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE ) > > self.splitter = splitter > > splitter2 = wx.SplitterWindow(splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D) > > self.splitter2 = splitter2 > > 你在splitter的右边放的是一个SplitterWindow,不是ListCtrl。 > > [snip] > > # Create a ListCtrl > > tID = wx.NewId() > > self.list = DemoListCtrl(splitter2, tID, > > style=wx.LC_REPORT > > | wx.BORDER_NONE > > | wx.LC_SORT_ASCENDING > > ) > > #self.Bind(wx.EVT_SIZE, self.OnSize) > > 你把ListCtrl放在splitter2下面了。 > > [snip] > > 你的splitter2只设置了一个子窗口,当然显示不正确。 > > 解决方法一: > 删除splitter2,直接将ListCtrl放在splitter下 > > 解决方法二: > 给splitter2再加一个子窗口,然后用splitter2.SplitHorizontally分割。 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号