원래는 리스트 컨트롤로 프로퍼티 컨트롤을 구성하려고 했습니다만;
처리해줘야 할 부분이 너무 많더군요 T_T)~

그러던중 vc2005 의 프로퍼티 컨트롤을 spy 로 찍어보니 PropertyGrid 로 나왔던지라
wxGrid 를 이용해서 PropertyGrid 를 구현해보고 있는중입니다.

import wx
import wx.grid

class PropertyGrid(wx.grid.Grid):
    def __init__(self, parent, keys = []):
        wx.grid.Grid.__init__(self, parent, -1)
        self.CreateGrid(len(keys), 2)
        self.SetColLabelSize(0)
        self.SetRowLabelSize(0)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColSize)
        self.keyCellWidth = 100

        for row, key in enumerate(keys):
            self.SetReadOnly(row, 0)
            self.SetCellValue(row, 0, key)

    def SetCellChoice(self, row, choices, sel = 0):
        self.SetCellEditor(row, 1, wx.grid.GridCellChoiceEditor(choices))
        self.SetCellValue(row, 1, choices[sel])

    def OnColSize(self, evt):
        evt.Skip()

        self.keyCellWidth = self.GetColSize(0)

    def OnSize(self, evt):
        evt.Skip()
        w, h = evt.GetSize()

        self.SetColSize(0, self.keyCellWidth)
        self.SetColSize(1, w - self.keyCellWidth)

class TestFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(0, 0), size=(320, 240))
        self.CentreOnScreen(wx.BOTH)

        grid = PropertyGrid(self, ["race", "body", "face", "hair"])
        grid.SetCellChoice(0, ["human_m", "human_f"])
        grid.SetCellChoice(1, ["body0", "body1", "body2", "body3", "body4"])
        grid.SetCellChoice(2, ["face0", "face1", "face2", "face3", "face4"])

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, wx.EXPAND|wx.ALL, 0)
        self.SetSizer(sizer)



class TestApp(wx.App):
    def OnInit(self):
        "OnInit"

        frame = TestFrame(None, "TestApp")
        frame.Show()
        self.SetTopWindow(frame)
        return True

    def OnExit(self):
        "OnExit"
        pass

TestApp(redirect=False).MainLoop()


이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/08/29 12:44 2007/08/29 12:44

wx파이썬 그리드

Posted at 2007/08/29 12:40// Posted in wxPython/wxGrid
import wx
import wx.grid

class TestFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(0, 0), size=(320, 240))
        self.CentreOnScreen(wx.BOTH)

        grid = wx.grid.Grid(self, -1)
        grid.CreateGrid(25, 1)
        grid.SetColLabelValue(0, "value")
        grid.SetRowLabelValue(0, "race")
        grid.SetRowLabelValue(1, "body")
        grid.SetRowLabelValue(2, "face")
        grid.SetRowLabelValue(3, "hair")
        grid.SetColLabelSize(20)
        grid.SetRowLabelSize(50)
        grid.SetCellEditor(0, 0, wx.grid.GridCellChoiceEditor(["human_m", "human_f"]))
        grid.SetCellEditor(1, 0, wx.grid.GridCellChoiceEditor(["body0", "body1", "body2", "body3", "body4"]))
        grid.SetCellEditor(2, 0, wx.grid.GridCellChoiceEditor(["face0", "face1", "face2", "face3", "face4"]))


        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, wx.EXPAND|wx.ALL, 0)
        self.SetSizer(sizer)



class TestApp(wx.App):
    def OnInit(self):
        "OnInit"

        frame = TestFrame(None, "TestApp")
        frame.Show()
        self.SetTopWindow(frame)
        return True

    def OnExit(self):
        "OnExit"
        pass

TestApp(redirect=False).MainLoop()
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/08/29 12:40 2007/08/29 12:40