00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import wx
00020 import rtimages
00021
00022
00023 class RtmProfileListCtrl(wx.ListCtrl):
00024 def __init__(self, parent, ID, pos=wx.DefaultPosition,
00025 size=wx.DefaultSize, style=0):
00026 wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
00027
00028
00029 class RtmProfileListPanel(wx.Panel):
00030 def __init__(self, parent):
00031 self.datamap = [
00032 ("Instance ID", ""),
00033 ("Impl. ID", ""),
00034 ("Maker", ""),
00035 ("Description", ""),
00036 ("Version", ""),
00037 ("Category", ""),
00038 ("Component Type" , ""),
00039 ("Activity Type", ""),
00040 ("Max Instance", ""),
00041 ("Language", ""),
00042 ("Lang. Type", ""),
00043 ("InPort Attr.", ""),
00044 (" Name", ""),
00045 (" Type", ""),
00046 ("OutPort Attr.", ""),
00047 (" Name", ""),
00048 (" Type", "")]
00049
00050 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
00051
00052 self.il = wx.ImageList(16, 16)
00053 self.comp_bmp = self.il.Add(rtimages.getComponentBitmap())
00054 self.inp_bmp = self.il.Add(rtimages.getInPortBitmap())
00055 self.outp_bmp = self.il.Add(rtimages.getOutPortBitmap())
00056 self.blank_bmp = self.il.Add(rtimages.getBlankBitmap())
00057
00058 tID = wx.NewId()
00059 self.list = RtmProfileListCtrl(self, tID, wx.DefaultPosition,
00060 (1000, 1000),
00061 wx.LC_REPORT | wx.SUNKEN_BORDER
00062 | wx.LC_VRULES | wx.LC_HRULES)
00063
00064 self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
00065 info = wx.ListItem()
00066 info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_WIDTH | wx.LIST_MASK_FORMAT
00067 info.m_text = "Attribute"
00068 info.m_image = -1
00069 info.m_width = 120
00070 info.m_format = wx.LIST_FORMAT_LEFT
00071 self.list.InsertColumnInfo(0, info)
00072
00073 info.m_width = 100
00074 info.m_text = "Value"
00075 self.list.InsertColumnInfo(1, info)
00076 self.PopulateList()
00077
00078 self.Bind(wx.EVT_SIZE, self.OnSize)
00079
00080 def PopulateList(self):
00081
00082 x = 0
00083 for data in self.datamap:
00084 attr, val = data
00085 if attr == "Instance ID":
00086 self.list.InsertImageStringItem(x, attr, self.comp_bmp)
00087 elif attr== "InPort Attr.":
00088 self.list.InsertImageStringItem(x, attr, self.inp_bmp)
00089 elif attr== "OutPort Attr.":
00090 self.list.InsertImageStringItem(x, attr, self.outp_bmp)
00091 else:
00092 self.list.InsertImageStringItem(x, attr, self.blank_bmp)
00093 self.list.SetStringItem(x, 1, val)
00094
00095 if attr == "InPort Attr.":
00096 print "InPort Attr."
00097 self.list.SetItemBackgroundColour(x,
00098 wx.Color(0xdd, 0xdd, 0xdd))
00099 elif attr == "OutPort Attr.":
00100 print "OutPort Attr."
00101 self.list.SetItemBackgroundColour(x,
00102 wx.Color(0xdd, 0xdd, 0xdd))
00103 x += 1
00104
00105
00106 self.list.SetItemState(5, wx.LIST_STATE_SELECTED,
00107 wx.LIST_STATE_SELECTED)
00108
00109 self.currentItem = 0
00110
00111 def RefreshProfile(self, profile):
00112
00113 self.datamap = [
00114 ("Instance ID", profile.instance_name),
00115 ("Impl. ID", profile.type_name),
00116 ("Maker", profile.vendor),
00117 ("Description", profile.description),
00118 ("Version", profile.version),
00119 ("Category", profile.category)
00120
00121
00122
00123
00124
00125 ]
00126
00127
00128
00129
00130 item_len = len(self.datamap)
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 self.list.DeleteAllItems()
00142 self.PopulateList()
00143
00144 def OnSize(self, event):
00145 w,h = self.GetClientSizeTuple()
00146 self.list.SetDimensions(0, 0, w, h)
00147
00148
00149
00150 def runTest(frame, nb, log):
00151 win = RtmProfileListPanel(frame)
00152 return win
00153
00154
00155
00156
00157 overview = """\
00158 This example demonstrates the ListCtrl's Virtual List features. A Virtual list
00159 can contain any number of cells, but data is not loaded into the control itself.
00160 It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>,
00161 and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required
00162 without limiting what can be done with the list control itself.
00163 """
00164
00165
00166
00167 if __name__ == '__main__':
00168 import sys,os
00169 import run
00170 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
00171