RtmTreeCtrl.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @file RtmTreeCtrl.py
4 # @brief rtc-link name tree management class
5 # @date $Date: 2007-01-21 13:21:26 $
6 # @author Tsuyoshi Tanabe, Noriaki Ando <n-ando@aist.go.jp>
7 #
8 # Copyright (C) 2004-2005
9 # Task-intelligence Research Group,
10 # Intelligent Systems Research Institute,
11 # National Institute of
12 # Advanced Industrial Science and Technology (AIST), Japan
13 # All rights reserved.
14 #
15 # $Id: RtmTreeCtrl.py 775 2008-07-28 16:14:45Z n-ando $
16 #
17 
18 # Basic modules
19 import string
20 import time
21 import cPickle
22 import thread
23 
24 # wxPython modules
25 import wx
26 import rtimages
27 
28 # RTM modules
29 import RTM
30 import RtmNSHelper
31 from RtmCompData import *
32 from RtmDialog import *
33 
34 
35 #-------------------------------------------------------------------------------
36 class RtmPopup:
37  """ポップアップメニュ基底クラス"""
38  def __init__(self, parent, menulist):
39  self.menu = wx.Menu()
40  self.parent = parent
41  self.root_item = self.parent.tree.GetRootItem()
42  for item_name, handler in menulist:
43  if item_name == "---":
44  self.menu.AppendSeparator()
45  elif handler == None:
46  sm = wx.Menu()
47  new_id = wx.NewId()
48  self.menu.AppendMenu(new_id, item_name, sm)
49  else:
50  new_id = wx.NewId()
51  self.parent.Bind(wx.EVT_MENU, handler, id=new_id)
52  item = wx.MenuItem(self.menu, new_id, item_name)
53  self.menu.AppendItem(item)
54 
55  def GetMenu(self):
56  """メニューを取得する [引数] void [戻り値] self.menu -- メニューオブジェクト
57 
58  [引数]
59  void
60 
61  [戻り値]
62  self.menu -- メニューオブジェクト
63  """
64  return self.menu
65 
66  def SetItem(self, item):
67  """カレントのツリーItemIDををセットする [引数] item -- ItemID [戻り値] void
68 
69  [引数]
70  item -- ItemID
71 
72  [戻り値]
73  void
74  """
75  self.item = item
76 
77  def DeleteToCxt(self, event):
78  test_id = self.parent.tree.GetItemText(self.item)
79  fullpath = self.parent.makeFullPath(self.item)
80  if self.item != self.root_item:
81  item = self.parent.tree.GetItemParent(self.item)
82  parent_path = self.parent.makeFullPath(item)
83  if item != self.root_item:
84  cxt_obj = self.parent.myDict.GetObjRefToFullpath(parent_path)
85  else:
86  cxt_obj = self.parent.nshelper.root_cxt
87  else:
88  cxt_obj = self.parent.nshelper.root_cxt
89  bname = self.parent.myDict.GetBindingNameToFullpath(fullpath)
90  self.parent.nshelper.DeleteToContext(cxt_obj,bname)
91 
92  def CreateComp(self,event):
93  test_id = self.parent.tree.GetItemText(self.item)
94  fullpath = self.parent.makeFullPath(self.item)
95  mod_name = self.parent.myDict.GetCompName(fullpath)
96  cate_name = self.parent.myDict.GetCateName(fullpath)
97  if cate_name == '':
98  print 'cate_cxt search error!!'
99  return
100  mgrpath = self.parent.searchManagerPath(self.item)
101  if mgrpath == None:
102  print 'RTCManager object-ref search error!!'
103  return
104 
105  objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
106  try:
107  objref._narrow(RTM.RTCManager)
108 
109  (ret,ret_str) = objref.create_component(mod_name, cate_name)
110  except:
111  except_mess("create_component error!:")
112 
113 
114 #-------------------------------------------------------------------------------
116  """コンポーネントItemポップアップクラス"""
117  def __init__(self, parent):
118  menulist = [("Start", self.OnStart),
119  ("Stop", self.OnStop),
120  ("Reset", self.OnReset),
121  ("Exit", self.OnExit),
122  ("Kill", self.OnKill),
123  ("---", None),
124  ("Delete", self.OnDelete),
125  ("Profile", self.OnProperty)]
126  self.parent = parent
127  self.rootitem_id = self.parent.tree.GetRootItem()
128  return RtmPopup.__init__(self, parent, menulist)
129 
130  def makeFullPath(self, cur_id):
131  """現在のItemIdからFullPathを生成
132 
133  [引数]
134  cur_id -- 現在のItemID
135 
136  [戻り値]
137  ret -- ツリーのFull Path
138  """
139  ret = self.parent.tree.GetItemText(self.item)
140 # num = ret.find('|')
141 # if num != -1:
142 # ret = ret[0:num]
143  while (self.rootitem_id != cur_id):
144  tmp_id = self.parent.tree.GetItemParent(cur_id)
145 # if tmp_id == self.rootitem_id:
146 # break
147  name = self.parent.tree.GetItemText(tmp_id)
148 # num = name.find('|')
149 # if num != -1:
150 # name = name[0:num]
151  ret = name + '/' + ret
152  cur_id = tmp_id
153  return str(ret)
154 
155  def OnStart(self, event):
156  """コンポーネントをrtc_start()させる [引数] event -- Event, 使用していない [戻り値] void
157  [引数]
158  event -- Event, 使用していない
159 
160  [戻り値]
161  void
162  """
163  try:
164  fullpath = self.makeFullPath(self.item)
165 # print "full-path:",fullpath
166  ret = self.parent.myDict.TreeListCompStart(fullpath)
167  if (ret != RTM.RTM_OK):
168  print "RTM_ERR:"
169  except:
170  except_mess("except error!:")
171 
172  print "OnStart"
173 
174  def OnStop(self, event):
175  """コンポーネントをrtc_stop()させる [引数] event -- Event, 使用していない [戻り値] void
176  [引数]
177  event -- Event, 使用していない
178 
179  [戻り値]
180  void
181  """
182  fullpath = self.makeFullPath(self.item)
183 # print "full-path:",fullpath
184  ret = self.parent.myDict.TreeListCompStop(fullpath)
185  print "OnStop"
186 
187  def OnReset(self, event):
188  """コンポーネントをrtc_reset()させる [引数] event -- Event, 使用していない [戻り値] void
189  [引数]
190  event -- Event, 使用していない
191 
192  [戻り値]
193  void
194  """
195  fullpath = self.makeFullPath(self.item)
196 # print "full-path:",fullpath
197  ret = self.parent.myDict.TreeListCompReset(fullpath)
198  print "OnReset"
199 
200  def OnExit(self, event):
201  """コンポーネントをrtc_exit()させる [引数] event -- Event, 使用していない [戻り値] void
202  [引数]
203  event -- Event, 使用していない
204 
205  [戻り値]
206  void
207  """
208  fullpath = self.makeFullPath(self.item)
209 # print "full-path:",fullpath
210  ret = self.parent.myDict.TreeListCompExit(fullpath)
211  print "OnExit"
212 
213  def OnKill(self, event):
214  """コンポーネントをrtc_kill()させる [引数] event -- Event, 使用していない [戻り値] void
215  [引数]
216  event -- Event, 使用していない
217 
218  [戻り値]
219  void
220  """
221  fullpath = self.makeFullPath(self.item)
222 # print "full-path:",fullpath
223  ret = self.parent.myDict.TreeListCompKill(fullpath)
224  print "OnKill"
225 
226  def OnProperty(self, event):
227  fullpath = self.makeFullPath(self.item)
228  kind = self.parent.myDict.GetKindToFullpath(fullpath)
229  if kind == "rtc":
230  ref = self.parent.myDict.GetObjRefToFullpath(fullpath)
231  try:
232  self.parent.frame.profilepanel.RefreshProfile(ref.get_component_profile())
233  except:
234  except_mess("except error!:")
235  pass
236  print "OnProperty"
237 
238  def OnDelete(self, event):
239  print 'OnDelete'
240  self.DeleteToCxt(event)
241 
242 #-------------------------------------------------------------------------------
244  """モジュールItemポップアップクラス"""
245  def __init__(self, parent):
246  menulist = [("Create", self.OnCreate),
247  ("---", None),
248  ("Delete", self.OnDelete)]
249 # ("Property", self.OnProperty)]
250  return RtmPopup.__init__(self, parent, menulist)
251 
252  def OnCreate(self, event):
253  print "OnCreate"
254  self.CreateComp(event)
255 
256  def OnDelete(self, event):
257  print "OnDelete"
258  self.DeleteToCxt(event)
259 
260  def OnProperty(self, event):
261  print "OnProperty"
262 
263 #-------------------------------------------------------------------------------
265  """Unknown Itemポップアップクラス"""
266  def __init__(self, parent):
267  menulist = [("Delete", self.OnDelete)]
268  return RtmPopup.__init__(self, parent, menulist)
269 
270  def OnDelete(self, event):
271  print "OnDelete"
272  self.DeleteToCxt(event)
273 
274 #-------------------------------------------------------------------------------
276  """マネージャItemポップアップクラス"""
277  def __init__(self, parent):
278  menulist = [("Create", None),
279  ("Load", self.OnLoad),
280  ("---", None),
281  ("Delete", self.OnDelete)]
282 # ("Property", self.OnProperty)]
283 
284  return RtmPopup.__init__(self, parent, menulist)
285 
286  def SetSubMenu(self):
287  tmp_id = self.menu.FindItem("Create")
288 
289  item_list = self.menu.GetMenuItems()
290  sub_menu = None
291  for item in item_list:
292  if item.GetId() == tmp_id:
293  sub_menu = item.GetSubMenu()
294  break
295 
296  child_items = sub_menu.GetMenuItems()
297  for item in child_items:
298  id = item.GetId()
299  sub_menu.Remove(id)
300  del item
301 
302  mgrpath = self.parent.searchManagerPath(self.item)
303  if mgrpath == None:
304  print 'RTCManager object-ref search error!!'
305  return
306 
307  objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
308  try:
309  objref._narrow(RTM.RTCManager)
310 
311  fact_list = objref.factory_list()
312  except:
313  except_mess("component_factory_list error!:")
314 
315  for item_struct in fact_list:
316  name = item_struct.name
317  cate = item_struct.category
318  item_name = cate + '/' + name
319  new_id = wx.NewId()
320  item = wx.MenuItem(sub_menu, new_id, item_name)
321  sub_menu.AppendItem(item)
322  self.parent.Bind(wx.EVT_MENU, self.OnCreateSub, id=new_id)
323 
324  def OnCreateSub(self, event):
325  item_id= event.GetId()
326  item_name = self.menu.GetLabel(item_id)
327  num = item_name.find('/')
328  cate = str(item_name[0:num])
329  name = str(item_name[num+1:])
330  mgrpath = self.parent.searchManagerPath(self.item)
331  if mgrpath == None:
332  print 'RTCManager object-ref search error!!'
333  return
334  objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
335  try:
336  objref._narrow(RTM.RTCManager)
337 
338  (ret,ret_str) = objref.create_component(name, cate)
339  except:
340  except_mess("create_component error!:")
341 
342  def OnCreate(self, event):
343  print "OnCreate"
344  mgrpath = self.parent.searchManagerPath(self.item)
345  if mgrpath == None:
346  print 'RTCManager object-ref search error!!'
347  return
348  cate_name = self.parent.searchCategoryName(self.item)
349  if cate_name == '':
350  print 'cate_cxt search error!!'
351  return
352 
353  objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
354  try:
355  objref._narrow(RTM.RTCManager)
356 
357  item_id= event.GetId()
358  item_name = self.menu.GetLabel(item_id)
359  print "item_name:",item_name
360 
361  (ret,ret_str) = objref.create_component(item_name, cate_name)
362  except:
363  except_mess("create_component error!:")
364 
365 
366  def OnLoad(self, event):
367  print "OnLoad"
368 
369  def OnProperty(self, event):
370  print "OnProperty"
371 
372  def OnDelete(self, event):
373  print "OnDelete"
374  self.DeleteToCxt(event)
375 
376 #-------------------------------------------------------------------------------
378  """ネームサーバItemポップアップクラス"""
379  def __init__(self, parent):
380  menulist = [("Connect", self.OnConnect),
381  ("Refresh", self.OnRefresh)]
382  return RtmPopup.__init__(self, parent, menulist)
383 
384  def OnConnect(self, event):
385  """ネームサーバ接続ダイアログを表示させる [引数] event -- Event, 使用していない [戻り値] void
386  [引数]
387  event -- Event, 使用していない
388 
389  [戻り値]
390  void
391  """
392  self.parent.OnConnectNSClick(None)
393 
394  def OnRefresh(self, event):
395  """ネーミングツリーをリフレッシュする [引数] event -- Event, 使用していない [戻り値] void
396  [引数]
397  event -- Event, 使用していない
398 
399  [戻り値]
400  void
401  """
402  dummy = 0
403  self.parent.myDict.Mutex.lock(self.parent.Refresh,dummy)
404  self.parent.myDict.Mutex.unlock()
405 
406 
407 #-------------------------------------------------------------------------------
408 class RtmTreeCtrl(wx.TreeCtrl):
409  """ネーミングツリークラス"""
410  def __init__(self, parent, id, pos, size, style, log):
411  """初期化
412 
413  [引数]
414  parent -- 親ウインドウ
415  id -- ウインドウID
416  pos -- 位置 size -- サイズ style -- ウインドウスタイル # wx.TreeCtrl と同じ [戻り値] this
417  size -- サイズ
418  style -- ウインドウスタイル # wx.TreeCtrl と同じ [戻り値] this
419  # wx.TreeCtrl と同じ
420 
421  [戻り値]
422  this
423  """
424 
425  wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
426  self.log = log
427 
428  isz = (16,16)
429  il = wx.ImageList(isz[0], isz[1])
430 
431  self.treeimg_list = {}
432 
433  self.parent = parent
434 
435  rticon = il.Add(rtimages.getRTLogoBitmap())
436  computer = il.Add(rtimages.getComputerBitmap())
437  manager = il.Add(rtimages.getManagerBitmap())
438  category = il.Add(rtimages.getCategoryBitmap())
439  module = il.Add(rtimages.getModuleBitmap())
440  component= il.Add(rtimages.getComponentBitmap())
441 
442  self.treeimg_list['unknown'] = (rticon,rticon)
443  self.treeimg_list['ns'] = (rticon,rticon)
444  self.treeimg_list['host_cxt'] = (computer, computer)
445  self.treeimg_list['mgr_cxt'] = (manager, manager)
446  self.treeimg_list['mgr'] = (category, category)
447  self.treeimg_list['cate_cxt'] = (category, category)
448  self.treeimg_list['mod_cxt'] = (module, module)
449  self.treeimg_list['rtc'] = (component, component)
450 
451  print self.treeimg_list
452  self.depth = 0
453 
454  self.SetImageList(il)
455  self.il = il
456 
457  self.depth = 0
458  self.root = self.AddRoot("NS:")
459  self.SetPyData(self.root, None)
460  self.SetItemImage(self.root, self.treeimg_list['ns'][0],
461  wx.TreeItemIcon_Normal)
462  self.SetItemImage(self.root, self.treeimg_list['ns'][0],
463  wx.TreeItemIcon_Expanded)
464  self.Expand(self.root)
465  rootitem_id = self.GetRootItem()
466  self.SelectItem(rootitem_id)
467 
468  self.kindDispMode = self.parent.frame.kindDispMode
469 
470  def OnCompareItems(self, item1, item2):
471  """itemの比較 [引数] item1 -- item1 item2 -- item2 [戻り値] -1 -- t1 < t2 0 -- t1 = t2 1 -- t1 > t2
472 
473  [引数]
474  item1 -- item1
475  item2 -- item2
476 
477  [戻り値]
478  -1 -- t1 < t2
479  0 -- t1 = t2
480  1 -- t1 > t2
481  """
482  t1 = self.GetItemText(item1)
483  t2 = self.GetItemText(item2)
484  self.log.WriteText('compare: ' + t1 + ' <> ' + t2 + '\n')
485  if t1 < t2: return -1
486  if t1 == t2: return 0
487  return 1
488 
489  def PrintAll(self):
490  """全Itemの表示
491 
492  [引数]
493  void
494 
495  [戻り値]
496  void
497  """
498  rootitem_id = self.GetRootItem()
499  self.__ListupRecursive__(rootitem_id)
500 
501  def checkDispKind(self,kind):
502  ret = 1
503  kindCheck = 0
504  mode = self.kindDispMode
505  # 'all', 'alias','long'
506 
507  if 'cxt_' == kind[0:4] or '' == kind or kind == None:
508  kindCheck = 'alias'
509  else:
510  kindCheck = 'long'
511 
512  if mode == kindCheck or mode == 'all' or kind == 'rtc':
513  ret = 1
514  else:
515  ret = 0
516 
517  return ret
518 
519  def SetItemByDict(self, dict):
520  """ディクショナリを与えてItemをセット [引数] dict -- Item のディクショナリ [戻り値] void
521 
522  [引数]
523  dict -- Item のディクショナリ [戻り値] void
524 
525  [戻り値]
526  void
527  """
528  rootitem_id = self.GetRootItem()
529  item_list = self.GetChildrenItemNameList(rootitem_id)
530  self.depth = 0
531  if dict != None:
532  self.__SetItemRecursive__(rootitem_id, dict)
533  else:
534  self.DeleteChildren(rootitem_id)
535  self.SelectItem(rootitem_id)
536 
537  def __SetItemRecursive__(self, item_id, dict):
538  """Item をディクショナリから再帰的にセットする [引数] item_id -- 現在のレベルのItemのID dict -- Item の残りのディクショナリ [戻り値] void
539 
540  [引数]
541  item_id -- 現在のレベルのItemのID
542  dict -- Item の残りのディクショナリ [戻り値] void
543 
544  [戻り値]
545  void
546  """
547  self.depth += 1
548  check_disp = 0
549  self.kindDispMode = self.parent.frame.kindDispMode
550  # dict => {"name":(data, child_dict)}
551  # items => {"name":(id, cookie)}
552  items = self.GetChildrenItemNameList(item_id)
553 
554  # Append new item or new item data
555  for dict_name in dict.keys():
556 
557  kind = dict[dict_name][0]['kind']
558  check_disp = self.checkDispKind(kind)
559  # If given item name of dictionary is already exist,
560  # just replace with new ItemData.
561  if dict_name in items.keys():
562  if check_disp == 0:
563  pass
564  else:
565  self.SetPyData(items[dict_name][0], dict[dict_name][0])
566  new_item_id = items[dict_name][0]
567  else:
568  if check_disp == 1:
569  new_item_id = self.AppendItem(item_id, dict_name)
570  self.SetPyData(new_item_id, dict[dict_name][0])
571  print dict_name + ":", self.depth
572  if kind not in self.treeimg_list.keys():
573  kind = 'unknown'
574  try:
575  self.SetItemImage(new_item_id, self.treeimg_list[kind][0],
576  wx.TreeItemIcon_Normal)
577  self.SetItemImage(new_item_id, self.treeimg_list[kind][0],
578  wx.TreeItemIcon_Expanded)
579  except:
580  except_mess("except error!:")
581 
582 
583  # Recursive call to children.
584  if dict[dict_name][1] != None and check_disp == 1:
585  self.__SetItemRecursive__(new_item_id, dict[dict_name][1])
586 
587  # Delete current item if is not in given dictionary
588  for item_name in items.keys():
589  if item_name in dict.keys():
590  kind = dict[item_name][0]['kind']
591  check_disp = self.checkDispKind(kind)
592  if check_disp != 1:
593  self.DeleteChildren(items[item_name][0])
594  self.Delete(items[item_name][0])
595  else: # 辞書にないケース
596  self.DeleteChildren(items[item_name][0])
597  self.Delete(items[item_name][0])
598  self.depth -= 1
599 
600  def GetChildrenItemIdList(self, parent_id):
601  """現在のItemID以下の子供のIDリストを取得する [引数] paren_id -- 現在のレベルのItemID [戻り値] items -- 子供のItemのリスト
602 
603  [引数]
604  paren_id -- 現在のレベルのItemID
605 
606  [戻り値]
607  items -- 子供のItemのリスト
608  """
609  items = []
610  if self.ItemHasChildren(parent_id):
611  id, cookie = self.GetFirstChild(parent_id)
612  items.append((id, cookie))
613 
614  for i in range(self.GetChildrenCount(parent_id, False) - 1):
615  id, cookie = self.GetNextChild(parent_id, cookie)
616  items.append((id, cookie))
617  return items
618 
619  def GetChildrenItemNameList(self, parent_id):
620  """現在のItemID以下の子供のItemTextリストを取得する [引数] paren_id -- 現在のレベルのItemID [戻り値] items -- 子供のItemTextのリスト
621 
622  [引数]
623  paren_id -- 現在のレベルのItemID
624 
625  [戻り値]
626  items -- 子供のItemTextのリスト
627  """
628  item_names = {}
629  if self.ItemHasChildren(parent_id):
630  id, cookie = self.GetFirstChild(parent_id)
631  item_names[self.GetItemText(id)] = (id, cookie)
632 
633  for i in range(self.GetChildrenCount(parent_id, False) - 1):
634  id, cookie = self.GetNextChild(parent_id, cookie)
635  item_names[self.GetItemText(id)] = (id, cookie)
636  return item_names
637 
638  def __ListupRecursive__(self, item_id):
639  """現在のItemID以下の子供のItemTextを再帰的に表示する [引数] item_id -- 現在のレベルのItemID [戻り値] void
640 
641  [引数]
642  item_id -- 現在のレベルのItemID
643 
644  [戻り値]
645  void
646  """
647  for id, cookie in self.GetChildrenItemIdList(item_id):
648  if self.ItemHasChildren(id):
649  print self.GetItemText(id)
650  self.__ListupRecursive__(id)
651  else:
652  print self.GetItemText(id)
653 
654 
655 #-------------------------------------------------------------------------------
656 class RtmTreeCtrlPanel(wx.Panel):
657  """ネーミングツリーコントロールのパネルクラス"""
658  def __init__(self, frame, parent, log):
659  """クラス初期化
660 
661  [引数]
662  frame -- 親フレーム parent -- 親ウインドウ [戻り値] this
663  parent -- 親ウインドウ
664 
665  [戻り値]
666  this
667  """
668  self.parent = parent
669  self.myDict = frame.myDict
670  self.threadloop = 1
671  self.frame = frame
672  # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
673  wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
674  self.Bind(wx.EVT_SIZE, self.OnSize)
675 
676  self.log = log
677  tID = wx.NewId()
678 
679  self.tree = RtmTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
680  wx.TR_HAS_BUTTONS
681  #| wx.TR_HAS_BUTTONS
682  #| wx.TR_TWIST_BUTTONS
683  #| wx.TR_EDIT_LABELS
684  #| wx.TR_MULTIPLE
685  #| wx.TR_HIDE_ROOT
686  , self.log)
687  self.tree.Expand(self.tree.GetRootItem())
688 
690 
691  self.name_server = self.NSHistory.GetNSName()
692  self.name_server_pre = self.NSHistory.GetNSName()
693 
695  self.nshelper.Connect(self.name_server)
696  self.tree.SetItemText(self.tree.root, "NS:"+self.name_server)
697 
698 
699  self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
700  self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree)
701 # self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
702  self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnSelChanging, self.tree)
703 # self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree)
704 # self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree)
705  self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, self.tree)
706  self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
707  self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag)
708  self.tree.Bind(wx.EVT_TREE_END_DRAG, self.OnEndDrag)
709 
710  self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
711  self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightClick)
712  self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
713 # self.tree.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
714  self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
715 
716  # タイマでリフレッシュするとmutexが必要なのでやめた
717  # self.Bind(wx.EVT_TIMER, self.OnRefresh)
718  # self.t1 = wx.Timer(self)
719  # self.t1.Start(2000)
720  # self.mutex = mutex.mutex()
721  thread.start_new_thread(self.OnRefresh,())
722 
723 
729 
730 
731  def makeDict(self):
732  """ツリー表示のためのディクショナリを生成
733 
734  [引数]
735  void
736 
737  [戻り値]
738  void
739  """
740  rootitem_id = self.tree.GetRootItem()
741  fullpath = self.makeFullPath(rootitem_id)
742  self.myDict.SetObjRefToFullpath(fullpath,None)
743  self.__makeDictRecursive__(rootitem_id)
744 
745  def __makeDictRecursive__(self, item_id):
746  """ツリー表示のためのディクショナリを再帰的に生成
747  [引数]
748  item_id -- 現在のレベルのItemID
749 
750  [戻り値]
751  void
752  """
753  for id, cookie in self.tree.GetChildrenItemIdList(item_id):
754  if self.tree.ItemHasChildren(id):
755  data = self.tree.GetItemData(id)
756  comp = data.GetData()
757  fullpath = self.makeFullPath(id)
758  self.myDict.SetObjRefToFullpath(fullpath,comp)
759  self.__makeDictRecursive__(id)
760  else:
761  data = self.tree.GetItemData(id)
762  comp = data.GetData()
763  fullpath = self.makeFullPath(id)
764  self.myDict.SetObjRefToFullpath(fullpath,comp)
765 
766  def SetNameServer(self, name_server):
767  """ネームサーバのアドレス:ポートをセット [引数] name_server -- ネームサーバのアドレス:ポート [戻り値] void
768 
769  [引数]
770  name_server -- ネームサーバのアドレス:ポート [戻り値] void
771 
772  [戻り値]
773  void
774  """
775  self.name_server = namer_server
776 
777  def GetNameServer(self):
778  """ネームサーバのアドレス:ポートを取得 [引数] void [戻り値] name_server -- ネームサーバのアドレス:ポート
779 
780  [引数]
781  void
782 
783  [戻り値]
784  name_server -- ネームサーバのアドレス:ポート
785  """
786  return self.name_server
787 
788  def OnConnectNSClick(self, event):
789  """ネームサービスホスト:ポート設定ダイアログを表示
790 
791  [引数]
792  event -- Event, 使用していない
793 
794  [戻り値]
795  void
796  """
797  win = ConnectDialog(self, -1, "Naming Server", self.NSHistory.GetNSNames(),size=(400, 200),
798  #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
799  style = wx.DEFAULT_DIALOG_STYLE
800  )
801  win.SetNameServer(self.name_server)
802  win.CenterOnScreen()
803  val = win.ShowModal()
804 
805  if val == wx.ID_OK:
806  self.name_server = win.GetNameServer().encode()
807  self.tree.SetItemText(self.tree.root, "NS:"+self.name_server)
808  self.tree.Expand(self.tree.root)
809  self.NSHistory.SetNSName(self.name_server)
810 
811  win.Destroy()
812 
813  def OnRefresh(self):
814  """ネーミングツリーをリフレッシュ ループするので別スレッドから呼ぶべき [引数] void [戻り値] void
815  ループするので別スレッドから呼ぶべき
816 
817  [引数]
818  void
819 
820  [戻り値]
821  void
822  """
823  # if not self.mutex.testandset():
824  # return
825  # thread.start_new_thread(self.__OnRefresh__, ())
826  self.frame.close_evt.clear()
827  while (self.threadloop):
828  dummy = 0
829  self.myDict.Mutex.lock(self.Refresh,dummy)
830  self.myDict.Mutex.unlock()
831  time.sleep(1.0)
832  self.frame.close_evt.set()
833 
834  def Refresh(self,dummy):
835  """ネーミングツリーをリフレッシュ [引数] void [戻り値] void
836 
837  [引数]
838  void
839 
840  [戻り値]
841  void
842  """
843  if self.name_server_pre != self.name_server or self.nshelper.root_cxt == None:
844  self.nshelper.Connect(self.name_server)
845  self.name_server_pre = self.name_server
846 
847  self.tree.SetItemByDict(self.nshelper.GetNSDict())
848  self.tree.Update()
849  self.makeDict()
850 
851  def OnRightClick(self, event):
852 # print "OnRightClick"
853  pass
854 # pt = event.GetPosition();
855 # item, flags = self.tree.HitTest(pt)
856 # self.tree.SelectItem(item)
857 
858  def OnRightUp(self, event):
859  """ツリー右クリック時コンテキストメニュー表示
860 
861  [引数]
862  event -- イベント [戻り値] void
863 
864  [戻り値]
865  void
866  """
867  try:
868  pt = event.GetPosition();
869  item, flags = self.tree.HitTest(pt)
870 
871  # 空白部分をクリック->無視 if self.tree.GetItemText(item) == "": return cur_item = item fullpath = self.makeFullPath(cur_item) kind = self.myDict.GetKindToFullpath(fullpath) if (kind == 'ns'): self.names_popup.SetItem(item) self.PopupMenu(self.names_popup.GetMenu(), event.GetPosition()) elif (kind == 'mgr' or kind == 'mgr_cxt'): self.manager_popup.SetItem(item) self.manager_popup.SetSubMenu() self.PopupMenu(self.manager_popup.GetMenu(), event.GetPosition()) elif (kind == 'mod_cxt'): self.module_popup.SetItem(item) self.PopupMenu(self.module_popup.GetMenu(), event.GetPosition()) elif (kind == 'rtc'): self.comp_popup.SetItem(item) self.PopupMenu(self.comp_popup.GetMenu(), event.GetPosition()) else: # (kind == 'unknown'): & cate_cxt self.unknown_popup.SetItem(item) self.PopupMenu(self.unknown_popup.GetMenu(), event.GetPosition()) except: except_mess("except error!:") pass def OnBeginEdit(self, event): self.log.WriteText("OnBeginEdit\n") # show how to prevent edit... if self.tree.GetItemText(event.GetItem()) == "The Root Item": wx.Bell() self.log.WriteText("You can't edit this one...\n") # Lets just see what's visible of its children cookie = 0 root = event.GetItem() (child, cookie) = self.tree.GetFirstChild(root) while child.IsOk(): self.log.WriteText("Child [%s] visible = %d" % (self.tree.GetItemText(child), self.tree.IsVisible(child))) (child, cookie) = self.tree.GetNextChild(root, cookie) event.Veto() def OnEndEdit(self, event): self.log.WriteText("OnEndEdit\n") # show how to reject edit, we'll not allow any digits for x in event.GetLabel(): if x in string.digits: self.log.WriteText("You can't enter digits...\n") event.Veto() return def OnLeftDClick(self, event): pt = event.GetPosition(); item, flags = self.tree.HitTest(pt) self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item)) rootitem_id = self.tree.GetRootItem() parent = self.tree.GetItemParent(item) try: self.tree.SortChildren(parent) except: except_mess("invalid tree item!:") event.Skip() def OnSize(self, event): w,h = self.GetClientSizeTuple() self.tree.SetDimensions(0, 0, w, h) def OnItemExpanded(self, event): item = event.GetItem() self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item)) def OnItemCollapsed(self, event): item = event.GetItem() self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item)) def OnSelChanged(self, event): self.item = event.GetItem() self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item)) if wx.Platform == '__WXMSW__': self.log.WriteText("BoundingRect: %s\n" % self.tree.GetBoundingRect(self.item, True)) def OnSelChanging(self, event): self.item = event.GetItem() def OnActivate(self, event): pass def makeFullPath(self, item): """現在のItemIdからFullPathを生成 [引数] cur_id -- 現在のItemID [戻り値] ret -- ツリーのFull Path """ cur_id = item ret = self.tree.GetItemText(item) if ret == '': print "item name is None!!: error!!" return # num = ret.find('|') # if num != -1: # ret = ret[0:num] rootitem_id = self.tree.GetRootItem() while (rootitem_id != cur_id): tmp_id = self.tree.GetItemParent(cur_id) # if tmp_id == rootitem_id: # break name = self.tree.GetItemText(tmp_id) # num = name.find('|') # if num != -1: # name = name[0:num] ret = name + '/' + ret cur_id = tmp_id return str(ret) def searchCategoryName(self, item): """現在のItemIdからCategoryの名称を検索 manager にぶら下がっているcategory名を検索 [引数] cur_id -- 現在のItemID [戻り値] ret -- ツリーのFull Path """ cur_id = item ret = '' cur_name = '' kind = '' items = [] parent_id = item if self.ItemHasChildren(parent_id): cur_id, cookie = self.GetFirstChild(parent_id) for i in range(self.GetChildrenCount(parent_id, False) - 1): cur_name = self.tree.GetItemText(cur_id) num = cur_name.find('|') if num != -1: kind = cur_name[num+1:] else: # print 'nothing kind!!! error!?' kind = '' break if kind == 'cate_cxt': ret = cur_name[0:num-1] break cur_id, cookie = self.GetNextChild(cur_id, cookie) return ret def searchManagerPath(self, item): """現在のItemIdからManagerのFullPathを作成 [引数] cur_id -- 現在のItemID [戻り値] ret -- ツリーのFull Path """ cur_id = item ret = '' cur_name = '' kind = '' rootitem_id = self.tree.GetRootItem() # search manager_cxt(kind:mgr_cxt) while (rootitem_id != cur_id): cur_name = self.tree.GetItemText(cur_id) num = cur_name.find('|') if num != -1: kind = cur_name[num+1:] else: # print 'nothing kind!!! error!?' kind = '' break if kind == 'mgr_cxt': break tmp_id = self.tree.GetItemParent(cur_id) cur_id = tmp_id # search mgr kind tmp_id = cur_id cur_id = None if kind == 'mgr_cxt': kind = '' for id, cookie in self.tree.GetChildrenItemIdList(tmp_id): cur_name = self.tree.GetItemText(id) num = cur_name.find('|') if num != -1: kind = cur_name[num+1:] else: # print 'nothing kind!!! error!?' kind = '' break if kind == 'mgr': cur_id = id break if cur_id == None: return None ret = self.tree.GetItemText(cur_id) while (rootitem_id != cur_id): tmp_id = self.tree.GetItemParent(cur_id) # if tmp_id == rootitem_id: # break name = self.tree.GetItemText(tmp_id) ret = name + '/' + ret cur_id = tmp_id return ret def OnBeginDrag(self, event): """DnDスタート [引数] event -- Event, 使用していない [戻り値] void """ # Change selection when drag is starting item = event.GetItem() self.tree.SelectItem(item) fullpath = self.makeFullPath(item) kind = self.myDict.GetKindToFullpath(fullpath) # itemPt = event.GetPoint() # (checkID, checkFlag) = self.tree.HitTest(itemPt) # if checkFlag == wx.TREE_HITTEST_NOWHERE: # print "check ok!!: item now here.",itemPt,checkFlag if (kind != 'rtc'): return data = wx.DataObjectComposite() dragText = fullpath textDataObj = wx.TextDataObject(dragText) data.Add(textDataObj) drop_source = wx.DropSource(self.tree) drop_source.SetData(data) result = drop_source.DoDragDrop() if result == wx.DragError: print "DragError" elif result == wx.DragNone: print "DragNone" elif result == wx.DragCopy: print "DragCopy: Sucseed" elif result == wx.DragMove: print "DragCopy: Sucseed" elif result == wx.DragCancel: print "DragCancel" else: print result def OnEndDrag(self, event): """DnDエンド [引数] event -- Event, 使用していない [戻り値] void """ item = event.GetItem() self.tree.SelectItem(item) print self.tree.GetItemText(item) def OnLeftUp(self, event): """マウスの左ボタンクリック [引数] event -- Event, 使用していない [戻り値] void """ item = self.tree.GetSelection() name = self.tree.GetItemText(item) fullpath = self.makeFullPath(item) kind = self.myDict.GetKindToFullpath(fullpath) if kind == "rtc": ref = self.myDict.GetObjRefToFullpath(fullpath) try: self.frame.profilepanel.RefreshProfile(ref.get_component_profile()) except: except_mess("except error!:") pass def OnSelChanged(self, event): """セレクトされた [引数] event -- Event, 使用していない [戻り値] void """ item = event.GetItem() name = self.tree.GetItemText(item) if name == '': # print "OnSelChanged name is Non!" return fullpath = self.makeFullPath(item) kind = self.myDict.GetKindToFullpath(fullpath) if kind == "rtc": ref = self.myDict.GetObjRefToFullpath(fullpath) try: self.frame.profilepanel.RefreshProfile(ref.get_component_profile()) except: except_mess("except error!:") pass #------------------------------------------------------------------------------- class ConnectDialog(wx.Dialog): """ ネーミングサービス接続ダイアログクラス""" def __init__( self, parent, ID, title, text_list,size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE ): """クラス初期化 [引数] parent -- 親ウインドウ ID -- ウインドウID title -- ダイアログウインドウタイトル size -- サイズ pos -- 位置 style -- ダイアログウインドウスタイル [戻り値] this """ pre = wx.PreDialog() pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) pre.Create(parent, ID, title, pos, size, style) self.this = pre.this sizer = wx.BoxSizer(wx.VERTICAL) box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, -1, "NameServer:port ") label.SetHelpText("Name server and port number") box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.hosttxt = wx.ComboBox(self, -1, "", (90,50),(160,-1), text_list,wx.CB_DROPDOWN) self.hosttxt.SetHelpText("Name server and port number") box.Add(self.hosttxt, 1, wx.ALIGN_CENTRE|wx.ALL, 5) sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) box = wx.BoxSizer(wx.HORIZONTAL) if wx.Platform != "__WXMSW__": btn = wx.ContextHelpButton(self) box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5) btn = wx.Button(self, wx.ID_OK, " OK ") btn.SetDefault() btn.SetHelpText("The OK button completes the dialog") box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5) btn = wx.Button(self, wx.ID_CANCEL, " Cancel ") btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)") box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5) sizer.Add(box, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self) def SetNameServer(self, name_server): """ダイアログウインドウに予め表示するネーミングサーバ名 [引数] name_server -- ネーミングサーバ名 [戻り値] void """ self.hosttxt.SetValue(name_server) def GetNameServer(self): """ダイアログウインドウに入力されたネーミングサーバ名を取得する [引数] void [戻り値] name_server -- ネーミングサーバ名 """ return self.hosttxt.GetValue() #--------------------------------------------------------------------------- class RtmNSHistory: """ ネーミングサービス接続ヒストリークラス""" def __init__(self): """クラス初期化 [引数] なし [戻り値] なし """ self.err = 0 self.history = [] self.filename = 'rtclink_nshist.dat' if os.name == 'posix': self.rootdir = os.getenv('HOME','.') self.filename = '.rtclink_nshist' elif os.name == 'nt': self.win_drive = os.getenv('HOMEDRIVE','C:') self.win_root = os.getenv('HOMEPATH','\\') self.rootdir = os.path.join(self.win_drive, self.win_root) else: self.rootdir = '.' self.hist_path = os.path.join(self.rootdir,self.filename) try: self.file = open(self.hist_path, 'rw') except: print "No sach file:",self.hist_path print "create to history-file:",self.hist_path try: self.file = open(self.hist_path, 'w') self.file.write('localhost\n') self.file.close() self.file = open(self.hist_path, 'rw') except: except_mess("except error!:") self.history.append('localhost') self.err = 1 return tmp_hist = self.file.readlines() for hist in tmp_hist: hist = hist[0:-1] self.history.append(hist) self.file.close() def GetNSName(self): return self.history[0] def GetNSNames(self): return self.history def SetNSName(self,newName): if newName in self.history: indx = self.history.index(newName) del self.history[indx] self.history.insert(0,newName) n = 10 if len(self.history) > 10: for n in range(10,len(self.history)): del self.history[n] self.file = open(self.hist_path, 'w') for hist in self.history: self.file.write(hist) self.file.write('\n') self.file.close() #--------------------------------------------------------------------------- def runTest(frame, nb, log): win = RtmTreeCtrlPanel(nb, log) return win #--------------------------------------------------------------------------- if __name__ == '__main__': import sys,os import run run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
872  if self.tree.GetItemText(item) == "":
873  return
874  cur_item = item
875 
876  fullpath = self.makeFullPath(cur_item)
877  kind = self.myDict.GetKindToFullpath(fullpath)
878 
879  if (kind == 'ns'):
880  self.names_popup.SetItem(item)
881  self.PopupMenu(self.names_popup.GetMenu(),
882  event.GetPosition())
883  elif (kind == 'mgr' or kind == 'mgr_cxt'):
884  self.manager_popup.SetItem(item)
885  self.manager_popup.SetSubMenu()
886  self.PopupMenu(self.manager_popup.GetMenu(),
887  event.GetPosition())
888  elif (kind == 'mod_cxt'):
889  self.module_popup.SetItem(item)
890  self.PopupMenu(self.module_popup.GetMenu(),
891  event.GetPosition())
892  elif (kind == 'rtc'):
893  self.comp_popup.SetItem(item)
894  self.PopupMenu(self.comp_popup.GetMenu(),
895  event.GetPosition())
896  else: # (kind == 'unknown'): & cate_cxt
897  self.unknown_popup.SetItem(item)
898  self.PopupMenu(self.unknown_popup.GetMenu(),
899  event.GetPosition())
900  except:
901  except_mess("except error!:")
902  pass
903 
904  def OnBeginEdit(self, event):
905  self.log.WriteText("OnBeginEdit\n")
906  # show how to prevent edit...
907  if self.tree.GetItemText(event.GetItem()) == "The Root Item":
908  wx.Bell()
909  self.log.WriteText("You can't edit this one...\n")
910 
911  # Lets just see what's visible of its children
912  cookie = 0
913  root = event.GetItem()
914  (child, cookie) = self.tree.GetFirstChild(root)
915 
916  while child.IsOk():
917  self.log.WriteText("Child [%s] visible = %d" %
918  (self.tree.GetItemText(child),
919  self.tree.IsVisible(child)))
920  (child, cookie) = self.tree.GetNextChild(root, cookie)
921 
922  event.Veto()
923 
924  def OnEndEdit(self, event):
925  self.log.WriteText("OnEndEdit\n")
926  # show how to reject edit, we'll not allow any digits
927  for x in event.GetLabel():
928  if x in string.digits:
929  self.log.WriteText("You can't enter digits...\n")
930  event.Veto()
931  return
932 
933  def OnLeftDClick(self, event):
934  pt = event.GetPosition();
935  item, flags = self.tree.HitTest(pt)
936  self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item))
937  rootitem_id = self.tree.GetRootItem()
938  parent = self.tree.GetItemParent(item)
939  try:
940  self.tree.SortChildren(parent)
941  except:
942  except_mess("invalid tree item!:")
943  event.Skip()
944 
945  def OnSize(self, event):
946  w,h = self.GetClientSizeTuple()
947  self.tree.SetDimensions(0, 0, w, h)
948 
949  def OnItemExpanded(self, event):
950  item = event.GetItem()
951  self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
952 
953  def OnItemCollapsed(self, event):
954  item = event.GetItem()
955  self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
956 
957  def OnSelChanged(self, event):
958  self.item = event.GetItem()
959  self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
960  if wx.Platform == '__WXMSW__':
961  self.log.WriteText("BoundingRect: %s\n" %
962  self.tree.GetBoundingRect(self.item, True))
963 
964  def OnSelChanging(self, event):
965  self.item = event.GetItem()
966 
967  def OnActivate(self, event):
968  pass
969 
970  def makeFullPath(self, item):
971  """現在のItemIdからFullPathを生成
972 
973  [引数]
974  cur_id -- 現在のItemID
975 
976  [戻り値]
977  ret -- ツリーのFull Path
978  """
979  cur_id = item
980  ret = self.tree.GetItemText(item)
981  if ret == '':
982  print "item name is None!!: error!!"
983  return
984 # num = ret.find('|')
985 # if num != -1:
986 # ret = ret[0:num]
987  rootitem_id = self.tree.GetRootItem()
988  while (rootitem_id != cur_id):
989  tmp_id = self.tree.GetItemParent(cur_id)
990 # if tmp_id == rootitem_id:
991 # break
992  name = self.tree.GetItemText(tmp_id)
993 # num = name.find('|')
994 # if num != -1:
995 # name = name[0:num]
996  ret = name + '/' + ret
997  cur_id = tmp_id
998  return str(ret)
999 
1000  def searchCategoryName(self, item):
1001  """現在のItemIdからCategoryの名称を検索 manager にぶら下がっているcategory名を検索 [引数] cur_id -- 現在のItemID [戻り値] ret -- ツリーのFull Path
1002  manager にぶら下がっているcategory名を検索 [引数] cur_id -- 現在のItemID [戻り値] ret -- ツリーのFull Path
1003 
1004  [引数]
1005  cur_id -- 現在のItemID
1006 
1007  [戻り値]
1008  ret -- ツリーのFull Path
1009  """
1010  cur_id = item
1011  ret = ''
1012  cur_name = ''
1013  kind = ''
1014  items = []
1015  parent_id = item
1016  if self.ItemHasChildren(parent_id):
1017  cur_id, cookie = self.GetFirstChild(parent_id)
1018 
1019  for i in range(self.GetChildrenCount(parent_id, False) - 1):
1020  cur_name = self.tree.GetItemText(cur_id)
1021  num = cur_name.find('|')
1022  if num != -1:
1023  kind = cur_name[num+1:]
1024  else:
1025  # print 'nothing kind!!! error!?'
1026  kind = ''
1027  break
1028  if kind == 'cate_cxt':
1029  ret = cur_name[0:num-1]
1030  break
1031  cur_id, cookie = self.GetNextChild(cur_id, cookie)
1032 
1033  return ret
1034 
1035 
1036  def searchManagerPath(self, item):
1037  """現在のItemIdからManagerのFullPathを作成
1038 
1039  [引数]
1040  cur_id -- 現在のItemID
1041 
1042  [戻り値]
1043  ret -- ツリーのFull Path
1044  """
1045  cur_id = item
1046  ret = ''
1047  cur_name = ''
1048  kind = ''
1049  rootitem_id = self.tree.GetRootItem()
1050  # search manager_cxt(kind:mgr_cxt)
1051  while (rootitem_id != cur_id):
1052  cur_name = self.tree.GetItemText(cur_id)
1053  num = cur_name.find('|')
1054  if num != -1:
1055  kind = cur_name[num+1:]
1056  else:
1057 # print 'nothing kind!!! error!?'
1058  kind = ''
1059  break
1060  if kind == 'mgr_cxt':
1061  break
1062  tmp_id = self.tree.GetItemParent(cur_id)
1063  cur_id = tmp_id
1064 
1065  # search mgr kind
1066  tmp_id = cur_id
1067  cur_id = None
1068  if kind == 'mgr_cxt':
1069  kind = ''
1070  for id, cookie in self.tree.GetChildrenItemIdList(tmp_id):
1071  cur_name = self.tree.GetItemText(id)
1072  num = cur_name.find('|')
1073  if num != -1:
1074  kind = cur_name[num+1:]
1075  else:
1076 # print 'nothing kind!!! error!?'
1077  kind = ''
1078  break
1079  if kind == 'mgr':
1080  cur_id = id
1081  break
1082 
1083  if cur_id == None:
1084  return None
1085 
1086  ret = self.tree.GetItemText(cur_id)
1087 
1088  while (rootitem_id != cur_id):
1089  tmp_id = self.tree.GetItemParent(cur_id)
1090 # if tmp_id == rootitem_id:
1091 # break
1092  name = self.tree.GetItemText(tmp_id)
1093  ret = name + '/' + ret
1094  cur_id = tmp_id
1095 
1096  return ret
1097 
1098  def OnBeginDrag(self, event):
1099  """DnDスタート [引数] event -- Event, 使用していない [戻り値] void
1100 
1101  [引数]
1102  event -- Event, 使用していない
1103 
1104  [戻り値]
1105  void
1106  """
1107  # Change selection when drag is starting
1108  item = event.GetItem()
1109  self.tree.SelectItem(item)
1110  fullpath = self.makeFullPath(item)
1111 
1112  kind = self.myDict.GetKindToFullpath(fullpath)
1113 
1114 # itemPt = event.GetPoint()
1115 # (checkID, checkFlag) = self.tree.HitTest(itemPt)
1116 # if checkFlag == wx.TREE_HITTEST_NOWHERE:
1117 # print "check ok!!: item now here.",itemPt,checkFlag
1118 
1119  if (kind != 'rtc'):
1120  return
1121 
1122  data = wx.DataObjectComposite()
1123 
1124  dragText = fullpath
1125  textDataObj = wx.TextDataObject(dragText)
1126  data.Add(textDataObj)
1127 
1128  drop_source = wx.DropSource(self.tree)
1129  drop_source.SetData(data)
1130  result = drop_source.DoDragDrop()
1131 
1132  if result == wx.DragError:
1133  print "DragError"
1134  elif result == wx.DragNone:
1135  print "DragNone"
1136  elif result == wx.DragCopy:
1137  print "DragCopy: Sucseed"
1138  elif result == wx.DragMove:
1139  print "DragCopy: Sucseed"
1140  elif result == wx.DragCancel:
1141  print "DragCancel"
1142  else:
1143  print result
1144 
1145  def OnEndDrag(self, event):
1146  """DnDエンド [引数] event -- Event, 使用していない [戻り値] void
1147 
1148  [引数]
1149  event -- Event, 使用していない
1150 
1151  [戻り値]
1152  void
1153  """
1154  item = event.GetItem()
1155  self.tree.SelectItem(item)
1156  print self.tree.GetItemText(item)
1157 
1158  def OnLeftUp(self, event):
1159  """マウスの左ボタンクリック
1160 
1161  [引数]
1162  event -- Event, 使用していない
1163 
1164  [戻り値]
1165  void
1166  """
1167  item = self.tree.GetSelection()
1168  name = self.tree.GetItemText(item)
1169  fullpath = self.makeFullPath(item)
1170  kind = self.myDict.GetKindToFullpath(fullpath)
1171  if kind == "rtc":
1172  ref = self.myDict.GetObjRefToFullpath(fullpath)
1173  try:
1174  self.frame.profilepanel.RefreshProfile(ref.get_component_profile())
1175  except:
1176  except_mess("except error!:")
1177  pass
1178 
1179  def OnSelChanged(self, event):
1180  """セレクトされた
1181 
1182  [引数]
1183  event -- Event, 使用していない
1184 
1185  [戻り値]
1186  void
1187  """
1188  item = event.GetItem()
1189  name = self.tree.GetItemText(item)
1190  if name == '':
1191 # print "OnSelChanged name is Non!"
1192  return
1193  fullpath = self.makeFullPath(item)
1194  kind = self.myDict.GetKindToFullpath(fullpath)
1195  if kind == "rtc":
1196  ref = self.myDict.GetObjRefToFullpath(fullpath)
1197  try:
1198  self.frame.profilepanel.RefreshProfile(ref.get_component_profile())
1199  except:
1200  except_mess("except error!:")
1201  pass
1202 
1203 
1204 #-------------------------------------------------------------------------------
1205 class ConnectDialog(wx.Dialog):
1206  """ ネーミングサービス接続ダイアログクラス"""
1207  def __init__(
1208  self, parent, ID, title, text_list,size=wx.DefaultSize, pos=wx.DefaultPosition,
1209  style=wx.DEFAULT_DIALOG_STYLE
1210  ):
1211  """クラス初期化
1212 
1213  [引数]
1214  parent -- 親ウインドウ
1215  ID -- ウインドウID
1216  title -- ダイアログウインドウタイトル size -- サイズ pos -- 位置 style -- ダイアログウインドウスタイル [戻り値] this
1217  size -- サイズ
1218  pos -- 位置 style -- ダイアログウインドウスタイル [戻り値] this
1219  style -- ダイアログウインドウスタイル [戻り値] this
1220 
1221  [戻り値]
1222  this
1223  """
1224  pre = wx.PreDialog()
1225  pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1226  pre.Create(parent, ID, title, pos, size, style)
1227 
1228  self.this = pre.this
1229 
1230  sizer = wx.BoxSizer(wx.VERTICAL)
1231  box = wx.BoxSizer(wx.HORIZONTAL)
1232 
1233  label = wx.StaticText(self, -1, "NameServer:port ")
1234  label.SetHelpText("Name server and port number")
1235  box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
1236 
1237  self.hosttxt = wx.ComboBox(self, -1, "", (90,50),(160,-1), text_list,wx.CB_DROPDOWN)
1238  self.hosttxt.SetHelpText("Name server and port number")
1239  box.Add(self.hosttxt, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
1240 
1241  sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
1242 
1243  line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
1244  sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
1245 
1246  box = wx.BoxSizer(wx.HORIZONTAL)
1247 
1248  if wx.Platform != "__WXMSW__":
1249  btn = wx.ContextHelpButton(self)
1250  box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
1251 
1252  btn = wx.Button(self, wx.ID_OK, " OK ")
1253  btn.SetDefault()
1254  btn.SetHelpText("The OK button completes the dialog")
1255  box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
1256 
1257  btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
1258  btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
1259  box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
1260 
1261  sizer.Add(box, 0,
1262  wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
1263  5)
1264 
1265  self.SetSizer(sizer)
1266  self.SetAutoLayout(True)
1267  sizer.Fit(self)
1268 
1269  def SetNameServer(self, name_server):
1270  """ダイアログウインドウに予め表示するネーミングサーバ名
1271 
1272  [引数]
1273  name_server -- ネーミングサーバ名
1274 
1275  [戻り値]
1276  void
1277  """
1278  self.hosttxt.SetValue(name_server)
1279 
1280  def GetNameServer(self):
1281  """ダイアログウインドウに入力されたネーミングサーバ名を取得する [引数] void [戻り値] name_server -- ネーミングサーバ名
1282 
1283  [引数]
1284  void
1285 
1286  [戻り値]
1287  name_server -- ネーミングサーバ名
1288 """
1289  return self.hosttxt.GetValue()
1290 #---------------------------------------------------------------------------
1292  """ ネーミングサービス接続ヒストリークラス"""
1293  def __init__(self):
1294  """クラス初期化
1295 
1296  [引数]
1297  なし
1298 
1299  [戻り値]
1300  なし
1301  """
1302  self.err = 0
1303  self.history = []
1304 
1305  self.filename = 'rtclink_nshist.dat'
1306  if os.name == 'posix':
1307  self.rootdir = os.getenv('HOME','.')
1308  self.filename = '.rtclink_nshist'
1309  elif os.name == 'nt':
1310  self.win_drive = os.getenv('HOMEDRIVE','C:')
1311  self.win_root = os.getenv('HOMEPATH','\\')
1312  self.rootdir = os.path.join(self.win_drive, self.win_root)
1313  else:
1314  self.rootdir = '.'
1315 
1316  self.hist_path = os.path.join(self.rootdir,self.filename)
1317  try:
1318  self.file = open(self.hist_path, 'rw')
1319  except:
1320  print "No sach file:",self.hist_path
1321  print "create to history-file:",self.hist_path
1322  try:
1323  self.file = open(self.hist_path, 'w')
1324  self.file.write('localhost\n')
1325  self.file.close()
1326  self.file = open(self.hist_path, 'rw')
1327  except:
1328  except_mess("except error!:")
1329  self.history.append('localhost')
1330  self.err = 1
1331  return
1332 
1333  tmp_hist = self.file.readlines()
1334  for hist in tmp_hist:
1335  hist = hist[0:-1]
1336  self.history.append(hist)
1337  self.file.close()
1338 
1339  def GetNSName(self):
1340  return self.history[0]
1341 
1342  def GetNSNames(self):
1343  return self.history
1344 
1345  def SetNSName(self,newName):
1346  if newName in self.history:
1347  indx = self.history.index(newName)
1348  del self.history[indx]
1349  self.history.insert(0,newName)
1350  n = 10
1351  if len(self.history) > 10:
1352  for n in range(10,len(self.history)):
1353  del self.history[n]
1354  self.file = open(self.hist_path, 'w')
1355  for hist in self.history:
1356  self.file.write(hist)
1357  self.file.write('\n')
1358  self.file.close()
1359 
1360 #---------------------------------------------------------------------------
1361 
1362 def runTest(frame, nb, log):
1363  win = RtmTreeCtrlPanel(nb, log)
1364  return win
1365 
1366 #---------------------------------------------------------------------------
1367 
1368 
1369 
1370 
1371 if __name__ == '__main__':
1372  import sys,os
1373  import run
1374  run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1375 
def OnEndEdit(self, event)
Definition: RtmTreeCtrl.py:924
def searchCategoryName(self, item)
def CreateComp(self, event)
Definition: RtmTreeCtrl.py:92
def OnDelete(self, event)
Definition: RtmTreeCtrl.py:256
def OnSelChanged(self, event)
Definition: RtmTreeCtrl.py:957
def SetItemByDict(self, dict)
Definition: RtmTreeCtrl.py:519
def OnKill(self, event)
Definition: RtmTreeCtrl.py:213
def DeleteToCxt(self, event)
Definition: RtmTreeCtrl.py:77
def getCategoryBitmap()
Definition: rtimages.py:69
def OnEndDrag(self, event)
def OnItemExpanded(self, event)
Definition: RtmTreeCtrl.py:949
def OnProperty(self, event)
Definition: RtmTreeCtrl.py:369
def OnActivate(self, event)
Definition: RtmTreeCtrl.py:967
def __SetItemRecursive__(self, item_id, dict)
Definition: RtmTreeCtrl.py:537
def __init__(self, parent)
Definition: RtmTreeCtrl.py:379
def __init__(self, parent, id, pos, size, style, log)
Definition: RtmTreeCtrl.py:410
def OnDelete(self, event)
Definition: RtmTreeCtrl.py:270
def SetNameServer(self, name_server)
Definition: RtmTreeCtrl.py:766
def OnBeginEdit(self, event)
Definition: RtmTreeCtrl.py:904
def OnLoad(self, event)
Definition: RtmTreeCtrl.py:366
def OnStart(self, event)
Definition: RtmTreeCtrl.py:155
def Refresh(self, dummy)
Definition: RtmTreeCtrl.py:834
def OnDelete(self, event)
Definition: RtmTreeCtrl.py:372
def __init__(self, parent)
Definition: RtmTreeCtrl.py:245
def OnProperty(self, event)
Definition: RtmTreeCtrl.py:226
def GetChildrenItemIdList(self, parent_id)
Definition: RtmTreeCtrl.py:600
def getRTLogoBitmap()
Definition: rtimages.py:776
def OnLeftDClick(self, event)
Definition: RtmTreeCtrl.py:933
def makeFullPath(self, item)
Definition: RtmTreeCtrl.py:970
def searchManagerPath(self, item)
def OnCreateSub(self, event)
Definition: RtmTreeCtrl.py:324
def __init__(self, parent)
Definition: RtmTreeCtrl.py:277
def OnItemCollapsed(self, event)
Definition: RtmTreeCtrl.py:953
def makeFullPath(self, cur_id)
Definition: RtmTreeCtrl.py:130
def OnSelChanging(self, event)
Definition: RtmTreeCtrl.py:964
def runTest(frame, nb, log)
def getModuleBitmap()
Definition: rtimages.py:558
def OnReset(self, event)
Definition: RtmTreeCtrl.py:187
def OnProperty(self, event)
Definition: RtmTreeCtrl.py:260
def OnCompareItems(self, item1, item2)
Definition: RtmTreeCtrl.py:470
def getComponentBitmap()
Definition: rtimages.py:115
def OnDelete(self, event)
Definition: RtmTreeCtrl.py:238
def OnStop(self, event)
Definition: RtmTreeCtrl.py:174
def OnRightUp(self, event)
Definition: RtmTreeCtrl.py:858
def OnCreate(self, event)
Definition: RtmTreeCtrl.py:252
def OnCreate(self, event)
Definition: RtmTreeCtrl.py:342
def OnConnectNSClick(self, event)
Definition: RtmTreeCtrl.py:788
def __ListupRecursive__(self, item_id)
Definition: RtmTreeCtrl.py:638
def SetItem(self, item)
Definition: RtmTreeCtrl.py:66
def OnBeginDrag(self, event)
def SetNameServer(self, name_server)
def __init__(self, frame, parent, log)
Definition: RtmTreeCtrl.py:658
def __init__(self, parent, ID, title, text_list, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE)
def OnRightClick(self, event)
Definition: RtmTreeCtrl.py:851
def __makeDictRecursive__(self, item_id)
Definition: RtmTreeCtrl.py:745
def GetChildrenItemNameList(self, parent_id)
Definition: RtmTreeCtrl.py:619
def checkDispKind(self, kind)
Definition: RtmTreeCtrl.py:501
def OnExit(self, event)
Definition: RtmTreeCtrl.py:200
def __init__(self, parent)
Definition: RtmTreeCtrl.py:266
def SetNSName(self, newName)
def getManagerBitmap()
Definition: rtimages.py:480
def __init__(self, parent, menulist)
Definition: RtmTreeCtrl.py:38
def except_mess(mess)
Definition: RtmDialog.py:100
def __init__(self, parent)
Definition: RtmTreeCtrl.py:117
def getComputerBitmap()
Definition: rtimages.py:165


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