RtmProfileList.py
Go to the documentation of this file.
00001 #/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #
00004 #  @file RtmProfileList.py
00005 #  @brief rtc-link component profile list display class
00006 #  @date $Date: 2007-01-21 13:21:20 $
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2004-2005
00010 #      Task-intelligence Research Group,
00011 #      Intelligent Systems Research Institute,
00012 #      National Institute of
00013 #          Advanced Industrial Science and Technology (AIST), Japan
00014 #      All rights reserved.
00015 # 
00016 #  $Id: RtmProfileList.py 775 2008-07-28 16:14:45Z n-ando $
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), #wx.DefaultSize,
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         # show how to select an item
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 #            ("Comp. Type",  profile.component_type.__str__()),
00121 #            ("Act. Type",   profile.activity_type.__str__()),
00122 #            ("Max Inst.",   profile.max_instance.__str__()),
00123 #            ("Language",    profile.language),
00124 #            ("Lang. Type",  profile.language_type.__str__())
00125             ]
00126 
00127 #        print profile.component_type
00128 #        print dir(profile.component_type)
00129 
00130         item_len = len(self.datamap)
00131 #        in_prof = profile.inport_profile_list
00132 #        for x in in_prof:
00133 #            self.datamap.append(("InPort Attr.", "Value"))
00134 #            self.datamap.append(("    Name", x.name))
00135 #            self.datamap.append(("    Type", x.port_type.name()))
00136 #        out_prof = profile.outport_profile_list
00137 #        for x in out_prof:
00138 #            self.datamap.append(("OutPort Attr.", "Value"))
00139 #            self.datamap.append(("    Name", x.name))
00140 #            self.datamap.append(("    Type", x.port_type.name()))
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 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:06