00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import string
00020 import time
00021 import cPickle
00022 import thread
00023
00024
00025 import wx
00026 import rtimages
00027
00028
00029 import RTM
00030 import RtmNSHelper
00031 from RtmCompData import *
00032 from RtmDialog import *
00033
00034
00035
00036 class RtmPopup:
00037 """ポップアップメニュ基底クラス"""
00038 def __init__(self, parent, menulist):
00039 self.menu = wx.Menu()
00040 self.parent = parent
00041 self.root_item = self.parent.tree.GetRootItem()
00042 for item_name, handler in menulist:
00043 if item_name == "---":
00044 self.menu.AppendSeparator()
00045 elif handler == None:
00046 sm = wx.Menu()
00047 new_id = wx.NewId()
00048 self.menu.AppendMenu(new_id, item_name, sm)
00049 else:
00050 new_id = wx.NewId()
00051 self.parent.Bind(wx.EVT_MENU, handler, id=new_id)
00052 item = wx.MenuItem(self.menu, new_id, item_name)
00053 self.menu.AppendItem(item)
00054
00055 def GetMenu(self):
00056 """メニューを取得する
00057
00058 [引数]
00059 void
00060
00061 [戻り値]
00062 self.menu -- メニューオブジェクト
00063 """
00064 return self.menu
00065
00066 def SetItem(self, item):
00067 """カレントのツリーItemIDををセットする
00068
00069 [引数]
00070 item -- ItemID
00071
00072 [戻り値]
00073 void
00074 """
00075 self.item = item
00076
00077 def DeleteToCxt(self, event):
00078 test_id = self.parent.tree.GetItemText(self.item)
00079 fullpath = self.parent.makeFullPath(self.item)
00080 if self.item != self.root_item:
00081 item = self.parent.tree.GetItemParent(self.item)
00082 parent_path = self.parent.makeFullPath(item)
00083 if item != self.root_item:
00084 cxt_obj = self.parent.myDict.GetObjRefToFullpath(parent_path)
00085 else:
00086 cxt_obj = self.parent.nshelper.root_cxt
00087 else:
00088 cxt_obj = self.parent.nshelper.root_cxt
00089 bname = self.parent.myDict.GetBindingNameToFullpath(fullpath)
00090 self.parent.nshelper.DeleteToContext(cxt_obj,bname)
00091
00092 def CreateComp(self,event):
00093 test_id = self.parent.tree.GetItemText(self.item)
00094 fullpath = self.parent.makeFullPath(self.item)
00095 mod_name = self.parent.myDict.GetCompName(fullpath)
00096 cate_name = self.parent.myDict.GetCateName(fullpath)
00097 if cate_name == '':
00098 print 'cate_cxt search error!!'
00099 return
00100 mgrpath = self.parent.searchManagerPath(self.item)
00101 if mgrpath == None:
00102 print 'RTCManager object-ref search error!!'
00103 return
00104
00105 objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
00106 try:
00107 objref._narrow(RTM.RTCManager)
00108
00109 (ret,ret_str) = objref.create_component(mod_name, cate_name)
00110 except:
00111 except_mess("create_component error!:")
00112
00113
00114
00115 class RtmCompPopup(RtmPopup):
00116 """コンポーネントItemポップアップクラス"""
00117 def __init__(self, parent):
00118 menulist = [("Start", self.OnStart),
00119 ("Stop", self.OnStop),
00120 ("Reset", self.OnReset),
00121 ("Exit", self.OnExit),
00122 ("Kill", self.OnKill),
00123 ("---", None),
00124 ("Delete", self.OnDelete),
00125 ("Profile", self.OnProperty)]
00126 self.parent = parent
00127 self.rootitem_id = self.parent.tree.GetRootItem()
00128 return RtmPopup.__init__(self, parent, menulist)
00129
00130 def makeFullPath(self, cur_id):
00131 """現在のItemIdからFullPathを生成
00132
00133 [引数]
00134 cur_id -- 現在のItemID
00135
00136 [戻り値]
00137 ret -- ツリーのFull Path
00138 """
00139 ret = self.parent.tree.GetItemText(self.item)
00140
00141
00142
00143 while (self.rootitem_id != cur_id):
00144 tmp_id = self.parent.tree.GetItemParent(cur_id)
00145
00146
00147 name = self.parent.tree.GetItemText(tmp_id)
00148
00149
00150
00151 ret = name + '/' + ret
00152 cur_id = tmp_id
00153 return str(ret)
00154
00155 def OnStart(self, event):
00156 """コンポーネントをrtc_start()させる
00157 [引数]
00158 event -- Event, 使用していない
00159
00160 [戻り値]
00161 void
00162 """
00163 try:
00164 fullpath = self.makeFullPath(self.item)
00165
00166 ret = self.parent.myDict.TreeListCompStart(fullpath)
00167 if (ret != RTM.RTM_OK):
00168 print "RTM_ERR:"
00169 except:
00170 except_mess("except error!:")
00171
00172 print "OnStart"
00173
00174 def OnStop(self, event):
00175 """コンポーネントをrtc_stop()させる
00176 [引数]
00177 event -- Event, 使用していない
00178
00179 [戻り値]
00180 void
00181 """
00182 fullpath = self.makeFullPath(self.item)
00183
00184 ret = self.parent.myDict.TreeListCompStop(fullpath)
00185 print "OnStop"
00186
00187 def OnReset(self, event):
00188 """コンポーネントをrtc_reset()させる
00189 [引数]
00190 event -- Event, 使用していない
00191
00192 [戻り値]
00193 void
00194 """
00195 fullpath = self.makeFullPath(self.item)
00196
00197 ret = self.parent.myDict.TreeListCompReset(fullpath)
00198 print "OnReset"
00199
00200 def OnExit(self, event):
00201 """コンポーネントをrtc_exit()させる
00202 [引数]
00203 event -- Event, 使用していない
00204
00205 [戻り値]
00206 void
00207 """
00208 fullpath = self.makeFullPath(self.item)
00209
00210 ret = self.parent.myDict.TreeListCompExit(fullpath)
00211 print "OnExit"
00212
00213 def OnKill(self, event):
00214 """コンポーネントをrtc_kill()させる
00215 [引数]
00216 event -- Event, 使用していない
00217
00218 [戻り値]
00219 void
00220 """
00221 fullpath = self.makeFullPath(self.item)
00222
00223 ret = self.parent.myDict.TreeListCompKill(fullpath)
00224 print "OnKill"
00225
00226 def OnProperty(self, event):
00227 fullpath = self.makeFullPath(self.item)
00228 kind = self.parent.myDict.GetKindToFullpath(fullpath)
00229 if kind == "rtc":
00230 ref = self.parent.myDict.GetObjRefToFullpath(fullpath)
00231 try:
00232 self.parent.frame.profilepanel.RefreshProfile(ref.get_component_profile())
00233 except:
00234 except_mess("except error!:")
00235 pass
00236 print "OnProperty"
00237
00238 def OnDelete(self, event):
00239 print 'OnDelete'
00240 self.DeleteToCxt(event)
00241
00242
00243 class RtmModulePopup(RtmPopup):
00244 """モジュールItemポップアップクラス"""
00245 def __init__(self, parent):
00246 menulist = [("Create", self.OnCreate),
00247 ("---", None),
00248 ("Delete", self.OnDelete)]
00249
00250 return RtmPopup.__init__(self, parent, menulist)
00251
00252 def OnCreate(self, event):
00253 print "OnCreate"
00254 self.CreateComp(event)
00255
00256 def OnDelete(self, event):
00257 print "OnDelete"
00258 self.DeleteToCxt(event)
00259
00260 def OnProperty(self, event):
00261 print "OnProperty"
00262
00263
00264 class RtmUnknownPopup(RtmPopup):
00265 """Unknown Itemポップアップクラス"""
00266 def __init__(self, parent):
00267 menulist = [("Delete", self.OnDelete)]
00268 return RtmPopup.__init__(self, parent, menulist)
00269
00270 def OnDelete(self, event):
00271 print "OnDelete"
00272 self.DeleteToCxt(event)
00273
00274
00275 class RtmManagerPopup(RtmPopup):
00276 """マネージャItemポップアップクラス"""
00277 def __init__(self, parent):
00278 menulist = [("Create", None),
00279 ("Load", self.OnLoad),
00280 ("---", None),
00281 ("Delete", self.OnDelete)]
00282
00283
00284 return RtmPopup.__init__(self, parent, menulist)
00285
00286 def SetSubMenu(self):
00287 tmp_id = self.menu.FindItem("Create")
00288
00289 item_list = self.menu.GetMenuItems()
00290 sub_menu = None
00291 for item in item_list:
00292 if item.GetId() == tmp_id:
00293 sub_menu = item.GetSubMenu()
00294 break
00295
00296 child_items = sub_menu.GetMenuItems()
00297 for item in child_items:
00298 id = item.GetId()
00299 sub_menu.Remove(id)
00300 del item
00301
00302 mgrpath = self.parent.searchManagerPath(self.item)
00303 if mgrpath == None:
00304 print 'RTCManager object-ref search error!!'
00305 return
00306
00307 objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
00308 try:
00309 objref._narrow(RTM.RTCManager)
00310
00311 fact_list = objref.factory_list()
00312 except:
00313 except_mess("component_factory_list error!:")
00314
00315 for item_struct in fact_list:
00316 name = item_struct.name
00317 cate = item_struct.category
00318 item_name = cate + '/' + name
00319 new_id = wx.NewId()
00320 item = wx.MenuItem(sub_menu, new_id, item_name)
00321 sub_menu.AppendItem(item)
00322 self.parent.Bind(wx.EVT_MENU, self.OnCreateSub, id=new_id)
00323
00324 def OnCreateSub(self, event):
00325 item_id= event.GetId()
00326 item_name = self.menu.GetLabel(item_id)
00327 num = item_name.find('/')
00328 cate = str(item_name[0:num])
00329 name = str(item_name[num+1:])
00330 mgrpath = self.parent.searchManagerPath(self.item)
00331 if mgrpath == None:
00332 print 'RTCManager object-ref search error!!'
00333 return
00334 objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
00335 try:
00336 objref._narrow(RTM.RTCManager)
00337
00338 (ret,ret_str) = objref.create_component(name, cate)
00339 except:
00340 except_mess("create_component error!:")
00341
00342 def OnCreate(self, event):
00343 print "OnCreate"
00344 mgrpath = self.parent.searchManagerPath(self.item)
00345 if mgrpath == None:
00346 print 'RTCManager object-ref search error!!'
00347 return
00348 cate_name = self.parent.searchCategoryName(self.item)
00349 if cate_name == '':
00350 print 'cate_cxt search error!!'
00351 return
00352
00353 objref = self.parent.myDict.GetObjRefToFullpath(mgrpath)
00354 try:
00355 objref._narrow(RTM.RTCManager)
00356
00357 item_id= event.GetId()
00358 item_name = self.menu.GetLabel(item_id)
00359 print "item_name:",item_name
00360
00361 (ret,ret_str) = objref.create_component(item_name, cate_name)
00362 except:
00363 except_mess("create_component error!:")
00364
00365
00366 def OnLoad(self, event):
00367 print "OnLoad"
00368
00369 def OnProperty(self, event):
00370 print "OnProperty"
00371
00372 def OnDelete(self, event):
00373 print "OnDelete"
00374 self.DeleteToCxt(event)
00375
00376
00377 class RtmNameServerPopup(RtmPopup):
00378 """ネームサーバItemポップアップクラス"""
00379 def __init__(self, parent):
00380 menulist = [("Connect", self.OnConnect),
00381 ("Refresh", self.OnRefresh)]
00382 return RtmPopup.__init__(self, parent, menulist)
00383
00384 def OnConnect(self, event):
00385 """ネームサーバ接続ダイアログを表示させる
00386 [引数]
00387 event -- Event, 使用していない
00388
00389 [戻り値]
00390 void
00391 """
00392 self.parent.OnConnectNSClick(None)
00393
00394 def OnRefresh(self, event):
00395 """ネーミングツリーをリフレッシュする
00396 [引数]
00397 event -- Event, 使用していない
00398
00399 [戻り値]
00400 void
00401 """
00402 dummy = 0
00403 self.parent.myDict.Mutex.lock(self.parent.Refresh,dummy)
00404 self.parent.myDict.Mutex.unlock()
00405
00406
00407
00408 class RtmTreeCtrl(wx.TreeCtrl):
00409 """ネーミングツリークラス"""
00410 def __init__(self, parent, id, pos, size, style, log):
00411 """初期化
00412
00413 [引数]
00414 parent -- 親ウインドウ
00415 id -- ウインドウID
00416 pos -- 位置
00417 size -- サイズ
00418 style -- ウインドウスタイル
00419 # wx.TreeCtrl と同じ
00420
00421 [戻り値]
00422 this
00423 """
00424
00425 wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
00426 self.log = log
00427
00428 isz = (16,16)
00429 il = wx.ImageList(isz[0], isz[1])
00430
00431 self.treeimg_list = {}
00432
00433 self.parent = parent
00434
00435 rticon = il.Add(rtimages.getRTLogoBitmap())
00436 computer = il.Add(rtimages.getComputerBitmap())
00437 manager = il.Add(rtimages.getManagerBitmap())
00438 category = il.Add(rtimages.getCategoryBitmap())
00439 module = il.Add(rtimages.getModuleBitmap())
00440 component= il.Add(rtimages.getComponentBitmap())
00441
00442 self.treeimg_list['unknown'] = (rticon,rticon)
00443 self.treeimg_list['ns'] = (rticon,rticon)
00444 self.treeimg_list['host_cxt'] = (computer, computer)
00445 self.treeimg_list['mgr_cxt'] = (manager, manager)
00446 self.treeimg_list['mgr'] = (category, category)
00447 self.treeimg_list['cate_cxt'] = (category, category)
00448 self.treeimg_list['mod_cxt'] = (module, module)
00449 self.treeimg_list['rtc'] = (component, component)
00450
00451 print self.treeimg_list
00452 self.depth = 0
00453
00454 self.SetImageList(il)
00455 self.il = il
00456
00457 self.depth = 0
00458 self.root = self.AddRoot("NS:")
00459 self.SetPyData(self.root, None)
00460 self.SetItemImage(self.root, self.treeimg_list['ns'][0],
00461 wx.TreeItemIcon_Normal)
00462 self.SetItemImage(self.root, self.treeimg_list['ns'][0],
00463 wx.TreeItemIcon_Expanded)
00464 self.Expand(self.root)
00465 rootitem_id = self.GetRootItem()
00466 self.SelectItem(rootitem_id)
00467
00468 self.kindDispMode = self.parent.frame.kindDispMode
00469
00470 def OnCompareItems(self, item1, item2):
00471 """itemの比較
00472
00473 [引数]
00474 item1 -- item1
00475 item2 -- item2
00476
00477 [戻り値]
00478 -1 -- t1 < t2
00479 0 -- t1 = t2
00480 1 -- t1 > t2
00481 """
00482 t1 = self.GetItemText(item1)
00483 t2 = self.GetItemText(item2)
00484 self.log.WriteText('compare: ' + t1 + ' <> ' + t2 + '\n')
00485 if t1 < t2: return -1
00486 if t1 == t2: return 0
00487 return 1
00488
00489 def PrintAll(self):
00490 """全Itemの表示
00491
00492 [引数]
00493 void
00494
00495 [戻り値]
00496 void
00497 """
00498 rootitem_id = self.GetRootItem()
00499 self.__ListupRecursive__(rootitem_id)
00500
00501 def checkDispKind(self,kind):
00502 ret = 1
00503 kindCheck = 0
00504 mode = self.kindDispMode
00505
00506
00507 if 'cxt_' == kind[0:4] or '' == kind or kind == None:
00508 kindCheck = 'alias'
00509 else:
00510 kindCheck = 'long'
00511
00512 if mode == kindCheck or mode == 'all' or kind == 'rtc':
00513 ret = 1
00514 else:
00515 ret = 0
00516
00517 return ret
00518
00519 def SetItemByDict(self, dict):
00520 """ディクショナリを与えてItemをセット
00521
00522 [引数]
00523 dict -- Item のディクショナリ
00524
00525 [戻り値]
00526 void
00527 """
00528 rootitem_id = self.GetRootItem()
00529 item_list = self.GetChildrenItemNameList(rootitem_id)
00530 self.depth = 0
00531 if dict != None:
00532 self.__SetItemRecursive__(rootitem_id, dict)
00533 else:
00534 self.DeleteChildren(rootitem_id)
00535 self.SelectItem(rootitem_id)
00536
00537 def __SetItemRecursive__(self, item_id, dict):
00538 """Item をディクショナリから再帰的にセットする
00539
00540 [引数]
00541 item_id -- 現在のレベルのItemのID
00542 dict -- Item の残りのディクショナリ
00543
00544 [戻り値]
00545 void
00546 """
00547 self.depth += 1
00548 check_disp = 0
00549 self.kindDispMode = self.parent.frame.kindDispMode
00550
00551
00552 items = self.GetChildrenItemNameList(item_id)
00553
00554
00555 for dict_name in dict.keys():
00556
00557 kind = dict[dict_name][0]['kind']
00558 check_disp = self.checkDispKind(kind)
00559
00560
00561 if dict_name in items.keys():
00562 if check_disp == 0:
00563 pass
00564 else:
00565 self.SetPyData(items[dict_name][0], dict[dict_name][0])
00566 new_item_id = items[dict_name][0]
00567 else:
00568 if check_disp == 1:
00569 new_item_id = self.AppendItem(item_id, dict_name)
00570 self.SetPyData(new_item_id, dict[dict_name][0])
00571 print dict_name + ":", self.depth
00572 if kind not in self.treeimg_list.keys():
00573 kind = 'unknown'
00574 try:
00575 self.SetItemImage(new_item_id, self.treeimg_list[kind][0],
00576 wx.TreeItemIcon_Normal)
00577 self.SetItemImage(new_item_id, self.treeimg_list[kind][0],
00578 wx.TreeItemIcon_Expanded)
00579 except:
00580 except_mess("except error!:")
00581
00582
00583
00584 if dict[dict_name][1] != None and check_disp == 1:
00585 self.__SetItemRecursive__(new_item_id, dict[dict_name][1])
00586
00587
00588 for item_name in items.keys():
00589 if item_name in dict.keys():
00590 kind = dict[item_name][0]['kind']
00591 check_disp = self.checkDispKind(kind)
00592 if check_disp != 1:
00593 self.DeleteChildren(items[item_name][0])
00594 self.Delete(items[item_name][0])
00595 else:
00596 self.DeleteChildren(items[item_name][0])
00597 self.Delete(items[item_name][0])
00598 self.depth -= 1
00599
00600 def GetChildrenItemIdList(self, parent_id):
00601 """現在のItemID以下の子供のIDリストを取得する
00602
00603 [引数]
00604 paren_id -- 現在のレベルのItemID
00605
00606 [戻り値]
00607 items -- 子供のItemのリスト
00608 """
00609 items = []
00610 if self.ItemHasChildren(parent_id):
00611 id, cookie = self.GetFirstChild(parent_id)
00612 items.append((id, cookie))
00613
00614 for i in range(self.GetChildrenCount(parent_id, False) - 1):
00615 id, cookie = self.GetNextChild(parent_id, cookie)
00616 items.append((id, cookie))
00617 return items
00618
00619 def GetChildrenItemNameList(self, parent_id):
00620 """現在のItemID以下の子供のItemTextリストを取得する
00621
00622 [引数]
00623 paren_id -- 現在のレベルのItemID
00624
00625 [戻り値]
00626 items -- 子供のItemTextのリスト
00627 """
00628 item_names = {}
00629 if self.ItemHasChildren(parent_id):
00630 id, cookie = self.GetFirstChild(parent_id)
00631 item_names[self.GetItemText(id)] = (id, cookie)
00632
00633 for i in range(self.GetChildrenCount(parent_id, False) - 1):
00634 id, cookie = self.GetNextChild(parent_id, cookie)
00635 item_names[self.GetItemText(id)] = (id, cookie)
00636 return item_names
00637
00638 def __ListupRecursive__(self, item_id):
00639 """現在のItemID以下の子供のItemTextを再帰的に表示する
00640
00641 [引数]
00642 item_id -- 現在のレベルのItemID
00643
00644 [戻り値]
00645 void
00646 """
00647 for id, cookie in self.GetChildrenItemIdList(item_id):
00648 if self.ItemHasChildren(id):
00649 print self.GetItemText(id)
00650 self.__ListupRecursive__(id)
00651 else:
00652 print self.GetItemText(id)
00653
00654
00655
00656 class RtmTreeCtrlPanel(wx.Panel):
00657 """ネーミングツリーコントロールのパネルクラス"""
00658 def __init__(self, frame, parent, log):
00659 """クラス初期化
00660
00661 [引数]
00662 frame -- 親フレーム
00663 parent -- 親ウインドウ
00664
00665 [戻り値]
00666 this
00667 """
00668 self.parent = parent
00669 self.myDict = frame.myDict
00670 self.threadloop = 1
00671 self.frame = frame
00672
00673 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
00674 self.Bind(wx.EVT_SIZE, self.OnSize)
00675
00676 self.log = log
00677 tID = wx.NewId()
00678
00679 self.tree = RtmTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
00680 wx.TR_HAS_BUTTONS
00681
00682
00683
00684
00685
00686 , self.log)
00687 self.tree.Expand(self.tree.GetRootItem())
00688
00689 self.NSHistory = RtmNSHistory()
00690
00691 self.name_server = self.NSHistory.GetNSName()
00692 self.name_server_pre = self.NSHistory.GetNSName()
00693
00694 self.nshelper = RtmNSHelper.RtmNSHelper()
00695 self.nshelper.Connect(self.name_server)
00696 self.tree.SetItemText(self.tree.root, "NS:"+self.name_server)
00697
00698
00699 self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
00700 self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree)
00701
00702 self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnSelChanging, self.tree)
00703
00704
00705 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, self.tree)
00706 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
00707 self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag)
00708 self.tree.Bind(wx.EVT_TREE_END_DRAG, self.OnEndDrag)
00709
00710 self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
00711 self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightClick)
00712 self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
00713
00714 self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
00715
00716
00717
00718
00719
00720
00721 thread.start_new_thread(self.OnRefresh,())
00722
00723
00724 self.comp_popup = RtmCompPopup(self)
00725 self.module_popup = RtmModulePopup(self)
00726 self.manager_popup = RtmManagerPopup(self)
00727 self.names_popup = RtmNameServerPopup(self)
00728 self.unknown_popup = RtmUnknownPopup(self)
00729
00730
00731 def makeDict(self):
00732 """ツリー表示のためのディクショナリを生成
00733
00734 [引数]
00735 void
00736
00737 [戻り値]
00738 void
00739 """
00740 rootitem_id = self.tree.GetRootItem()
00741 fullpath = self.makeFullPath(rootitem_id)
00742 self.myDict.SetObjRefToFullpath(fullpath,None)
00743 self.__makeDictRecursive__(rootitem_id)
00744
00745 def __makeDictRecursive__(self, item_id):
00746 """ツリー表示のためのディクショナリを再帰的に生成
00747 [引数]
00748 item_id -- 現在のレベルのItemID
00749
00750 [戻り値]
00751 void
00752 """
00753 for id, cookie in self.tree.GetChildrenItemIdList(item_id):
00754 if self.tree.ItemHasChildren(id):
00755 data = self.tree.GetItemData(id)
00756 comp = data.GetData()
00757 fullpath = self.makeFullPath(id)
00758 self.myDict.SetObjRefToFullpath(fullpath,comp)
00759 self.__makeDictRecursive__(id)
00760 else:
00761 data = self.tree.GetItemData(id)
00762 comp = data.GetData()
00763 fullpath = self.makeFullPath(id)
00764 self.myDict.SetObjRefToFullpath(fullpath,comp)
00765
00766 def SetNameServer(self, name_server):
00767 """ネームサーバのアドレス:ポートをセット
00768
00769 [引数]
00770 name_server -- ネームサーバのアドレス:ポート
00771
00772 [戻り値]
00773 void
00774 """
00775 self.name_server = namer_server
00776
00777 def GetNameServer(self):
00778 """ネームサーバのアドレス:ポートを取得
00779
00780 [引数]
00781 void
00782
00783 [戻り値]
00784 name_server -- ネームサーバのアドレス:ポート
00785 """
00786 return self.name_server
00787
00788 def OnConnectNSClick(self, event):
00789 """ネームサービスホスト:ポート設定ダイアログを表示
00790
00791 [引数]
00792 event -- Event, 使用していない
00793
00794 [戻り値]
00795 void
00796 """
00797 win = ConnectDialog(self, -1, "Naming Server", self.NSHistory.GetNSNames(),size=(400, 200),
00798
00799 style = wx.DEFAULT_DIALOG_STYLE
00800 )
00801 win.SetNameServer(self.name_server)
00802 win.CenterOnScreen()
00803 val = win.ShowModal()
00804
00805 if val == wx.ID_OK:
00806 self.name_server = win.GetNameServer().encode()
00807 self.tree.SetItemText(self.tree.root, "NS:"+self.name_server)
00808 self.tree.Expand(self.tree.root)
00809 self.NSHistory.SetNSName(self.name_server)
00810
00811 win.Destroy()
00812
00813 def OnRefresh(self):
00814 """ネーミングツリーをリフレッシュ
00815 ループするので別スレッドから呼ぶべき
00816
00817 [引数]
00818 void
00819
00820 [戻り値]
00821 void
00822 """
00823
00824
00825
00826 self.frame.close_evt.clear()
00827 while (self.threadloop):
00828 dummy = 0
00829 self.myDict.Mutex.lock(self.Refresh,dummy)
00830 self.myDict.Mutex.unlock()
00831 time.sleep(1.0)
00832 self.frame.close_evt.set()
00833
00834 def Refresh(self,dummy):
00835 """ネーミングツリーをリフレッシュ
00836
00837 [引数]
00838 void
00839
00840 [戻り値]
00841 void
00842 """
00843 if self.name_server_pre != self.name_server or self.nshelper.root_cxt == None:
00844 self.nshelper.Connect(self.name_server)
00845 self.name_server_pre = self.name_server
00846
00847 self.tree.SetItemByDict(self.nshelper.GetNSDict())
00848 self.tree.Update()
00849 self.makeDict()
00850
00851 def OnRightClick(self, event):
00852
00853 pass
00854
00855
00856
00857
00858 def OnRightUp(self, event):
00859 """ツリー右クリック時コンテキストメニュー表示
00860
00861 [引数]
00862 event -- イベント
00863
00864 [戻り値]
00865 void
00866 """
00867 try:
00868 pt = event.GetPosition();
00869 item, flags = self.tree.HitTest(pt)
00870
00871
00872 if self.tree.GetItemText(item) == "":
00873 return
00874 cur_item = item
00875
00876 fullpath = self.makeFullPath(cur_item)
00877 kind = self.myDict.GetKindToFullpath(fullpath)
00878
00879 if (kind == 'ns'):
00880 self.names_popup.SetItem(item)
00881 self.PopupMenu(self.names_popup.GetMenu(),
00882 event.GetPosition())
00883 elif (kind == 'mgr' or kind == 'mgr_cxt'):
00884 self.manager_popup.SetItem(item)
00885 self.manager_popup.SetSubMenu()
00886 self.PopupMenu(self.manager_popup.GetMenu(),
00887 event.GetPosition())
00888 elif (kind == 'mod_cxt'):
00889 self.module_popup.SetItem(item)
00890 self.PopupMenu(self.module_popup.GetMenu(),
00891 event.GetPosition())
00892 elif (kind == 'rtc'):
00893 self.comp_popup.SetItem(item)
00894 self.PopupMenu(self.comp_popup.GetMenu(),
00895 event.GetPosition())
00896 else:
00897 self.unknown_popup.SetItem(item)
00898 self.PopupMenu(self.unknown_popup.GetMenu(),
00899 event.GetPosition())
00900 except:
00901 except_mess("except error!:")
00902 pass
00903
00904 def OnBeginEdit(self, event):
00905 self.log.WriteText("OnBeginEdit\n")
00906
00907 if self.tree.GetItemText(event.GetItem()) == "The Root Item":
00908 wx.Bell()
00909 self.log.WriteText("You can't edit this one...\n")
00910
00911
00912 cookie = 0
00913 root = event.GetItem()
00914 (child, cookie) = self.tree.GetFirstChild(root)
00915
00916 while child.IsOk():
00917 self.log.WriteText("Child [%s] visible = %d" %
00918 (self.tree.GetItemText(child),
00919 self.tree.IsVisible(child)))
00920 (child, cookie) = self.tree.GetNextChild(root, cookie)
00921
00922 event.Veto()
00923
00924 def OnEndEdit(self, event):
00925 self.log.WriteText("OnEndEdit\n")
00926
00927 for x in event.GetLabel():
00928 if x in string.digits:
00929 self.log.WriteText("You can't enter digits...\n")
00930 event.Veto()
00931 return
00932
00933 def OnLeftDClick(self, event):
00934 pt = event.GetPosition();
00935 item, flags = self.tree.HitTest(pt)
00936 self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item))
00937 rootitem_id = self.tree.GetRootItem()
00938 parent = self.tree.GetItemParent(item)
00939 try:
00940 self.tree.SortChildren(parent)
00941 except:
00942 except_mess("invalid tree item!:")
00943 event.Skip()
00944
00945 def OnSize(self, event):
00946 w,h = self.GetClientSizeTuple()
00947 self.tree.SetDimensions(0, 0, w, h)
00948
00949 def OnItemExpanded(self, event):
00950 item = event.GetItem()
00951 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
00952
00953 def OnItemCollapsed(self, event):
00954 item = event.GetItem()
00955 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
00956
00957 def OnSelChanged(self, event):
00958 self.item = event.GetItem()
00959 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
00960 if wx.Platform == '__WXMSW__':
00961 self.log.WriteText("BoundingRect: %s\n" %
00962 self.tree.GetBoundingRect(self.item, True))
00963
00964 def OnSelChanging(self, event):
00965 self.item = event.GetItem()
00966
00967 def OnActivate(self, event):
00968 pass
00969
00970 def makeFullPath(self, item):
00971 """現在のItemIdからFullPathを生成
00972
00973 [引数]
00974 cur_id -- 現在のItemID
00975
00976 [戻り値]
00977 ret -- ツリーのFull Path
00978 """
00979 cur_id = item
00980 ret = self.tree.GetItemText(item)
00981 if ret == '':
00982 print "item name is None!!: error!!"
00983 return
00984
00985
00986
00987 rootitem_id = self.tree.GetRootItem()
00988 while (rootitem_id != cur_id):
00989 tmp_id = self.tree.GetItemParent(cur_id)
00990
00991
00992 name = self.tree.GetItemText(tmp_id)
00993
00994
00995
00996 ret = name + '/' + ret
00997 cur_id = tmp_id
00998 return str(ret)
00999
01000 def searchCategoryName(self, item):
01001 """現在のItemIdからCategoryの名称を検索
01002 manager にぶら下がっているcategory名を検索
01003
01004 [引数]
01005 cur_id -- 現在のItemID
01006
01007 [戻り値]
01008 ret -- ツリーのFull Path
01009 """
01010 cur_id = item
01011 ret = ''
01012 cur_name = ''
01013 kind = ''
01014 items = []
01015 parent_id = item
01016 if self.ItemHasChildren(parent_id):
01017 cur_id, cookie = self.GetFirstChild(parent_id)
01018
01019 for i in range(self.GetChildrenCount(parent_id, False) - 1):
01020 cur_name = self.tree.GetItemText(cur_id)
01021 num = cur_name.find('|')
01022 if num != -1:
01023 kind = cur_name[num+1:]
01024 else:
01025
01026 kind = ''
01027 break
01028 if kind == 'cate_cxt':
01029 ret = cur_name[0:num-1]
01030 break
01031 cur_id, cookie = self.GetNextChild(cur_id, cookie)
01032
01033 return ret
01034
01035
01036 def searchManagerPath(self, item):
01037 """現在のItemIdからManagerのFullPathを作成
01038
01039 [引数]
01040 cur_id -- 現在のItemID
01041
01042 [戻り値]
01043 ret -- ツリーのFull Path
01044 """
01045 cur_id = item
01046 ret = ''
01047 cur_name = ''
01048 kind = ''
01049 rootitem_id = self.tree.GetRootItem()
01050
01051 while (rootitem_id != cur_id):
01052 cur_name = self.tree.GetItemText(cur_id)
01053 num = cur_name.find('|')
01054 if num != -1:
01055 kind = cur_name[num+1:]
01056 else:
01057
01058 kind = ''
01059 break
01060 if kind == 'mgr_cxt':
01061 break
01062 tmp_id = self.tree.GetItemParent(cur_id)
01063 cur_id = tmp_id
01064
01065
01066 tmp_id = cur_id
01067 cur_id = None
01068 if kind == 'mgr_cxt':
01069 kind = ''
01070 for id, cookie in self.tree.GetChildrenItemIdList(tmp_id):
01071 cur_name = self.tree.GetItemText(id)
01072 num = cur_name.find('|')
01073 if num != -1:
01074 kind = cur_name[num+1:]
01075 else:
01076
01077 kind = ''
01078 break
01079 if kind == 'mgr':
01080 cur_id = id
01081 break
01082
01083 if cur_id == None:
01084 return None
01085
01086 ret = self.tree.GetItemText(cur_id)
01087
01088 while (rootitem_id != cur_id):
01089 tmp_id = self.tree.GetItemParent(cur_id)
01090
01091
01092 name = self.tree.GetItemText(tmp_id)
01093 ret = name + '/' + ret
01094 cur_id = tmp_id
01095
01096 return ret
01097
01098 def OnBeginDrag(self, event):
01099 """DnDスタート
01100
01101 [引数]
01102 event -- Event, 使用していない
01103
01104 [戻り値]
01105 void
01106 """
01107
01108 item = event.GetItem()
01109 self.tree.SelectItem(item)
01110 fullpath = self.makeFullPath(item)
01111
01112 kind = self.myDict.GetKindToFullpath(fullpath)
01113
01114
01115
01116
01117
01118
01119 if (kind != 'rtc'):
01120 return
01121
01122 data = wx.DataObjectComposite()
01123
01124 dragText = fullpath
01125 textDataObj = wx.TextDataObject(dragText)
01126 data.Add(textDataObj)
01127
01128 drop_source = wx.DropSource(self.tree)
01129 drop_source.SetData(data)
01130 result = drop_source.DoDragDrop()
01131
01132 if result == wx.DragError:
01133 print "DragError"
01134 elif result == wx.DragNone:
01135 print "DragNone"
01136 elif result == wx.DragCopy:
01137 print "DragCopy: Sucseed"
01138 elif result == wx.DragMove:
01139 print "DragCopy: Sucseed"
01140 elif result == wx.DragCancel:
01141 print "DragCancel"
01142 else:
01143 print result
01144
01145 def OnEndDrag(self, event):
01146 """DnDエンド
01147
01148 [引数]
01149 event -- Event, 使用していない
01150
01151 [戻り値]
01152 void
01153 """
01154 item = event.GetItem()
01155 self.tree.SelectItem(item)
01156 print self.tree.GetItemText(item)
01157
01158 def OnLeftUp(self, event):
01159 """マウスの左ボタンクリック
01160
01161 [引数]
01162 event -- Event, 使用していない
01163
01164 [戻り値]
01165 void
01166 """
01167 item = self.tree.GetSelection()
01168 name = self.tree.GetItemText(item)
01169 fullpath = self.makeFullPath(item)
01170 kind = self.myDict.GetKindToFullpath(fullpath)
01171 if kind == "rtc":
01172 ref = self.myDict.GetObjRefToFullpath(fullpath)
01173 try:
01174 self.frame.profilepanel.RefreshProfile(ref.get_component_profile())
01175 except:
01176 except_mess("except error!:")
01177 pass
01178
01179 def OnSelChanged(self, event):
01180 """セレクトされた
01181
01182 [引数]
01183 event -- Event, 使用していない
01184
01185 [戻り値]
01186 void
01187 """
01188 item = event.GetItem()
01189 name = self.tree.GetItemText(item)
01190 if name == '':
01191
01192 return
01193 fullpath = self.makeFullPath(item)
01194 kind = self.myDict.GetKindToFullpath(fullpath)
01195 if kind == "rtc":
01196 ref = self.myDict.GetObjRefToFullpath(fullpath)
01197 try:
01198 self.frame.profilepanel.RefreshProfile(ref.get_component_profile())
01199 except:
01200 except_mess("except error!:")
01201 pass
01202
01203
01204
01205 class ConnectDialog(wx.Dialog):
01206 """ ネーミングサービス接続ダイアログクラス"""
01207 def __init__(
01208 self, parent, ID, title, text_list,size=wx.DefaultSize, pos=wx.DefaultPosition,
01209 style=wx.DEFAULT_DIALOG_STYLE
01210 ):
01211 """クラス初期化
01212
01213 [引数]
01214 parent -- 親ウインドウ
01215 ID -- ウインドウID
01216 title -- ダイアログウインドウタイトル
01217 size -- サイズ
01218 pos -- 位置
01219 style -- ダイアログウインドウスタイル
01220
01221 [戻り値]
01222 this
01223 """
01224 pre = wx.PreDialog()
01225 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
01226 pre.Create(parent, ID, title, pos, size, style)
01227
01228 self.this = pre.this
01229
01230 sizer = wx.BoxSizer(wx.VERTICAL)
01231 box = wx.BoxSizer(wx.HORIZONTAL)
01232
01233 label = wx.StaticText(self, -1, "NameServer:port ")
01234 label.SetHelpText("Name server and port number")
01235 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
01236
01237 self.hosttxt = wx.ComboBox(self, -1, "", (90,50),(160,-1), text_list,wx.CB_DROPDOWN)
01238 self.hosttxt.SetHelpText("Name server and port number")
01239 box.Add(self.hosttxt, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
01240
01241 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
01242
01243 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
01244 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
01245
01246 box = wx.BoxSizer(wx.HORIZONTAL)
01247
01248 if wx.Platform != "__WXMSW__":
01249 btn = wx.ContextHelpButton(self)
01250 box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
01251
01252 btn = wx.Button(self, wx.ID_OK, " OK ")
01253 btn.SetDefault()
01254 btn.SetHelpText("The OK button completes the dialog")
01255 box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
01256
01257 btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
01258 btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
01259 box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
01260
01261 sizer.Add(box, 0,
01262 wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
01263 5)
01264
01265 self.SetSizer(sizer)
01266 self.SetAutoLayout(True)
01267 sizer.Fit(self)
01268
01269 def SetNameServer(self, name_server):
01270 """ダイアログウインドウに予め表示するネーミングサーバ名
01271
01272 [引数]
01273 name_server -- ネーミングサーバ名
01274
01275 [戻り値]
01276 void
01277 """
01278 self.hosttxt.SetValue(name_server)
01279
01280 def GetNameServer(self):
01281 """ダイアログウインドウに入力されたネーミングサーバ名を取得する
01282
01283 [引数]
01284 void
01285
01286 [戻り値]
01287 name_server -- ネーミングサーバ名
01288 """
01289 return self.hosttxt.GetValue()
01290
01291 class RtmNSHistory:
01292 """ ネーミングサービス接続ヒストリークラス"""
01293 def __init__(self):
01294 """クラス初期化
01295
01296 [引数]
01297 なし
01298
01299 [戻り値]
01300 なし
01301 """
01302 self.err = 0
01303 self.history = []
01304
01305 self.filename = 'rtclink_nshist.dat'
01306 if os.name == 'posix':
01307 self.rootdir = os.getenv('HOME','.')
01308 self.filename = '.rtclink_nshist'
01309 elif os.name == 'nt':
01310 self.win_drive = os.getenv('HOMEDRIVE','C:')
01311 self.win_root = os.getenv('HOMEPATH','\\')
01312 self.rootdir = os.path.join(self.win_drive, self.win_root)
01313 else:
01314 self.rootdir = '.'
01315
01316 self.hist_path = os.path.join(self.rootdir,self.filename)
01317 try:
01318 self.file = open(self.hist_path, 'rw')
01319 except:
01320 print "No sach file:",self.hist_path
01321 print "create to history-file:",self.hist_path
01322 try:
01323 self.file = open(self.hist_path, 'w')
01324 self.file.write('localhost\n')
01325 self.file.close()
01326 self.file = open(self.hist_path, 'rw')
01327 except:
01328 except_mess("except error!:")
01329 self.history.append('localhost')
01330 self.err = 1
01331 return
01332
01333 tmp_hist = self.file.readlines()
01334 for hist in tmp_hist:
01335 hist = hist[0:-1]
01336 self.history.append(hist)
01337 self.file.close()
01338
01339 def GetNSName(self):
01340 return self.history[0]
01341
01342 def GetNSNames(self):
01343 return self.history
01344
01345 def SetNSName(self,newName):
01346 if newName in self.history:
01347 indx = self.history.index(newName)
01348 del self.history[indx]
01349 self.history.insert(0,newName)
01350 n = 10
01351 if len(self.history) > 10:
01352 for n in range(10,len(self.history)):
01353 del self.history[n]
01354 self.file = open(self.hist_path, 'w')
01355 for hist in self.history:
01356 self.file.write(hist)
01357 self.file.write('\n')
01358 self.file.close()
01359
01360
01361
01362 def runTest(frame, nb, log):
01363 win = RtmTreeCtrlPanel(nb, log)
01364 return win
01365
01366
01367
01368
01369
01370
01371 if __name__ == '__main__':
01372 import sys,os
01373 import run
01374 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
01375