RtmProfileList.py
Go to the documentation of this file.
1 #/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # @file RtmProfileList.py
5 # @brief rtc-link component profile list display class
6 # @date $Date: 2007-01-21 13:21:20 $
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2004-2005
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id: RtmProfileList.py 775 2008-07-28 16:14:45Z n-ando $
17 #
18 
19 import wx
20 import rtimages
21 
22 #----------------------------------------------------------------------
23 class RtmProfileListCtrl(wx.ListCtrl):
24  def __init__(self, parent, ID, pos=wx.DefaultPosition,
25  size=wx.DefaultSize, style=0):
26  wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
27 
28 
29 class RtmProfileListPanel(wx.Panel):
30  def __init__(self, parent):
31  self.datamap = [
32  ("Instance ID", ""),
33  ("Impl. ID", ""),
34  ("Maker", ""),
35  ("Description", ""),
36  ("Version", ""),
37  ("Category", ""),
38  ("Component Type" , ""),
39  ("Activity Type", ""),
40  ("Max Instance", ""),
41  ("Language", ""),
42  ("Lang. Type", ""),
43  ("InPort Attr.", ""),
44  (" Name", ""),
45  (" Type", ""),
46  ("OutPort Attr.", ""),
47  (" Name", ""),
48  (" Type", "")]
49 
50  wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
51 
52  self.il = wx.ImageList(16, 16)
53  self.comp_bmp = self.il.Add(rtimages.getComponentBitmap())
54  self.inp_bmp = self.il.Add(rtimages.getInPortBitmap())
55  self.outp_bmp = self.il.Add(rtimages.getOutPortBitmap())
56  self.blank_bmp = self.il.Add(rtimages.getBlankBitmap())
57 
58  tID = wx.NewId()
59  self.list = RtmProfileListCtrl(self, tID, wx.DefaultPosition,
60  (1000, 1000), #wx.DefaultSize,
61  wx.LC_REPORT | wx.SUNKEN_BORDER
62  | wx.LC_VRULES | wx.LC_HRULES)
63 
64  self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
65  info = wx.ListItem()
66  info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_WIDTH | wx.LIST_MASK_FORMAT
67  info.m_text = "Attribute"
68  info.m_image = -1
69  info.m_width = 120
70  info.m_format = wx.LIST_FORMAT_LEFT
71  self.list.InsertColumnInfo(0, info)
72 
73  info.m_width = 100
74  info.m_text = "Value"
75  self.list.InsertColumnInfo(1, info)
76  self.PopulateList()
77 
78  self.Bind(wx.EVT_SIZE, self.OnSize)
79 
80  def PopulateList(self):
81 
82  x = 0
83  for data in self.datamap:
84  attr, val = data
85  if attr == "Instance ID":
86  self.list.InsertImageStringItem(x, attr, self.comp_bmp)
87  elif attr== "InPort Attr.":
88  self.list.InsertImageStringItem(x, attr, self.inp_bmp)
89  elif attr== "OutPort Attr.":
90  self.list.InsertImageStringItem(x, attr, self.outp_bmp)
91  else:
92  self.list.InsertImageStringItem(x, attr, self.blank_bmp)
93  self.list.SetStringItem(x, 1, val)
94 
95  if attr == "InPort Attr.":
96  print "InPort Attr."
97  self.list.SetItemBackgroundColour(x,
98  wx.Color(0xdd, 0xdd, 0xdd))
99  elif attr == "OutPort Attr.":
100  print "OutPort Attr."
101  self.list.SetItemBackgroundColour(x,
102  wx.Color(0xdd, 0xdd, 0xdd))
103  x += 1
104 
105  # show how to select an item
106  self.list.SetItemState(5, wx.LIST_STATE_SELECTED,
107  wx.LIST_STATE_SELECTED)
108 
109  self.currentItem = 0
110 
111  def RefreshProfile(self, profile):
112 
113  self.datamap = [
114  ("Instance ID", profile.instance_name),
115  ("Impl. ID", profile.type_name),
116  ("Maker", profile.vendor),
117  ("Description", profile.description),
118  ("Version", profile.version),
119  ("Category", profile.category)
120 # ("Comp. Type", profile.component_type.__str__()),
121 # ("Act. Type", profile.activity_type.__str__()),
122 # ("Max Inst.", profile.max_instance.__str__()),
123 # ("Language", profile.language),
124 # ("Lang. Type", profile.language_type.__str__())
125  ]
126 
127 # print profile.component_type
128 # print dir(profile.component_type)
129 
130  item_len = len(self.datamap)
131 # in_prof = profile.inport_profile_list
132 # for x in in_prof:
133 # self.datamap.append(("InPort Attr.", "Value"))
134 # self.datamap.append((" Name", x.name))
135 # self.datamap.append((" Type", x.port_type.name()))
136 # out_prof = profile.outport_profile_list
137 # for x in out_prof:
138 # self.datamap.append(("OutPort Attr.", "Value"))
139 # self.datamap.append((" Name", x.name))
140 # self.datamap.append((" Type", x.port_type.name()))
141  self.list.DeleteAllItems()
142  self.PopulateList()
143 
144  def OnSize(self, event):
145  w,h = self.GetClientSizeTuple()
146  self.list.SetDimensions(0, 0, w, h)
147 
148 #----------------------------------------------------------------------
149 
150 def runTest(frame, nb, log):
151  win = RtmProfileListPanel(frame)
152  return win
153 
154 #----------------------------------------------------------------------
155 
156 
157 overview = """\
158 This example demonstrates the ListCtrl's Virtual List features. A Virtual list
159 can contain any number of cells, but data is not loaded into the control itself.
160 It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>,
161 and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required
162 without limiting what can be done with the list control itself.
163 """
164 
165 
166 
167 if __name__ == '__main__':
168  import sys,os
169  import run
170  run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
171 
def runTest(frame, nb, log)
def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0)
def getInPortBitmap()
Definition: rtimages.py:396
def getComponentBitmap()
Definition: rtimages.py:115
def getBlankBitmap()
Definition: rtimages.py:21
def getOutPortBitmap()
Definition: rtimages.py:696


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00