00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import sys, os, time
00020 import wx
00021 import wx.html
00022 import rtimages
00023 from wxPython.wx import *
00024
00025
00026 import RtmSystemDraw
00027 import wx.ogl as ogl
00028 import os
00029 import cPickle
00030
00031
00032
00033 import threading
00034
00035 import RtmAbout
00036
00037 from RtmCompData import *
00038
00039 import RTM
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 ID_WINDOW_LEFT = 5000
00052 ID_WINDOW_CENTER_TOP = 5001
00053 ID_WINDOW_CENTER_BOTTOM = 5002
00054 ID_WINDOW_RIGHT = 5003
00055
00056 class MenuFactory:
00057 def __init__(self, parent, menulist):
00058 self.parent = parent
00059 self.menu = wx.Menu()
00060 for item_name, handler in menulist:
00061 if item_name == "---":
00062 self.menu.AppendSeparator()
00063 else:
00064 new_id = wx.NewId()
00065 parent.Bind(wx.EVT_MENU, handler, id=new_id)
00066 item = wx.MenuItem(self.menu, new_id, item_name)
00067 self.menu.AppendItem(item)
00068 def GetMenu(self):
00069 return self.menu
00070
00071 class RTComponentDropTarget(wx.DropTarget):
00072 def __init__(self, window):
00073 wx.DropTarget.__init__(self)
00074 self.window = window
00075
00076 self.df = wx.CustomDataFormat("RTComponent")
00077
00078 print "RTComponentDropTarget", self.df.GetId(), self.df.GetType()
00079 self.data = wx.CustomDataObject(self.df)
00080 self.SetDataObject(self.data)
00081
00082 def OnDragOver(self, x, y, d):
00083 print "OnDragOver"
00084 self.window.AppendText("OnDragOver\n")
00085 return wx.DragLink
00086
00087 def OnDrop(self, x, y):
00088 print "OnDrop"
00089 print x, y
00090 return True
00091
00092
00093 def OnData(self, x, y, d):
00094 print "OnData"
00095 if self.GetData():
00096 data = self.data.GetData()
00097 cdata = cPickle.loads(data)
00098 self.window.AppendText(cdata + "\n")
00099
00100
00101
00102
00103 return d
00104
00105
00106 class RtmFileMenu(MenuFactory):
00107 def __init__(self, parent):
00108 menu_list = [("&New System", self.OnNew),
00109 ("&Open System", self.OnOpen),
00110 ("&Save System", self.OnSave),
00111 ("Save System &as", self.OnSaveAs),
00112 ("---", None),
00113 ("&Import Component", self.OnImport),
00114 ("&Export Component", self.OnExport),
00115 ("---", None),
00116 ("Print Pre&view", self.OnPrintPreview),
00117 ("&Print System", self.OnPrint),
00118 ("---", None),
00119 ("&Connect Naming Server", self.OnConnect),
00120 ("---", None),
00121 ("E&xit", self.OnExit)]
00122 MenuFactory.__init__(self, parent, menu_list)
00123
00124 def OnNew(self, event):
00125 self.parent.OnNewSystemClick(None)
00126 print "OnNew"
00127
00128 def OnOpen(self, event):
00129 self.parent.drawWin[self.parent.drawCurNum].loadXML()
00130 print "OnOpen"
00131
00132 def OnSave(self, event):
00133 filename = "System%d.xml" % self.parent.drawCurNum
00134 self.parent.drawWin[self.parent.drawCurNum].saveXML(filename)
00135 print "OnSave"
00136
00137 def OnSaveAs(self, event):
00138 self.parent.drawWin[self.parent.drawCurNum].saveAsXML()
00139 print "OnSaveAs"
00140
00141 def OnImport(self, event):
00142 self.parent.OnFileOpen(event)
00143 print "OnImport"
00144
00145 def OnExport(self, event):
00146 self.parent.OnFileOpen(event)
00147 print "OnExport"
00148
00149 def OnPrint(self, event):
00150 dlg = wx.PrintDialog(self.parent, None)
00151 if dlg.ShowModal() == wx.ID_OK:
00152 data = dlg.GetPrintDialogData()
00153 print "OnPrint"
00154
00155 def OnPrintPreview(self, event):
00156 self.parent.OnFileOpen(event)
00157 print "OnOpen"
00158
00159 def OnConnect(self, event):
00160 self.parent.treepanel.OnConnectNSClick(None)
00161 print "OnConnect"
00162
00163 def OnExit(self, event):
00164 print "OnExit"
00165 self.parent.treepanel.threadloop = 0
00166 self.parent.close_evt.wait()
00167 self.parent.Close(true)
00168
00169
00170 class RtmEditMenu(MenuFactory):
00171 def __init__(self, parent):
00172 menu_list = [("&Copy", self.OnCopy),
00173 ("C&ut", self.OnCut),
00174 ("&Paste", self.OnPaste)]
00175 MenuFactory.__init__(self, parent, menu_list)
00176
00177 def OnCopy(self, event):
00178 print "OnCopy"
00179
00180 def OnCut(self, event):
00181 print "OnCut"
00182
00183 def OnPaste(self, event):
00184 print "OnPaste"
00185
00186 class RtmDisplayMenu(MenuFactory):
00187 def __init__(self, parent):
00188 menu_list = [("Long Name &and Alias", self.OnAllDisp),
00189 ("&Long Name", self.OnLongDisp),
00190 ("&Alias", self.OnAliasDisp)]
00191 MenuFactory.__init__(self, parent, menu_list)
00192
00193 def OnAllDisp(self, event):
00194 self.parent.kindDispMode = 'all'
00195 print "OnAllDisp"
00196
00197 def OnLongDisp(self, event):
00198 self.parent.kindDispMode = 'long'
00199 print "OnLongDisp"
00200
00201 def OnAliasDisp(self, event):
00202 self.parent.kindDispMode = 'alias'
00203 print "OnAliasDisp"
00204
00205
00206 class RtmHelpMenu(MenuFactory):
00207 def __init__(self, parent):
00208 menu_list = [("&Help", self.OnHelp),
00209 ("---", None),
00210 ("&About", self.OnAbout)]
00211 MenuFactory.__init__(self, parent, menu_list)
00212
00213 def OnHelp(self, event):
00214 print "OnHelp"
00215
00216 def OnAbout(self, event):
00217 print "OnAbout"
00218 dlg = RtmAbout.RtdAboutBox(None)
00219 dlg.ShowModal()
00220 dlg.Destroy()
00221
00222
00223
00224
00225
00226 class Log:
00227 def WriteText(self, text):
00228 if text[-1:] == '\n':
00229 text = text[:-1]
00230
00231 write = WriteText
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 class RtdFrame(wxMDIParentFrame):
00249 def __del__(self):
00250
00251
00252
00253 ogl.OGLCleanUp()
00254
00255 def __init__(self, parent, ID, title):
00256 wxMDIParentFrame.__init__(self, parent, -1, title, size = (800, 600),
00257 style=wx.DEFAULT_FRAME_STYLE|wx.HSCROLL | wx.VSCROLL
00258
00259 )
00260
00261
00262 self.winCount = 0
00263 self.drawWin = {}
00264 self.drawWin2 = {}
00265 self.drawWinID = {}
00266 self.drawCurNum = 0
00267 self.cwd = os.getcwd()
00268 self.curOverview = ""
00269 self.window = None
00270 self.log = Log()
00271 ogl.OGLInitialize()
00272 self.close_evt = threading.Event()
00273 self.kindDispMode = 'all'
00274
00275
00276
00277
00278 self.SetIcon(rtimages.getRT_iconIcon())
00279
00280
00281 self.status_bar = self.CreateStatusBar()
00282
00283
00284 self.toolbar = self.CreateToolBar(wxTB_HORIZONTAL
00285 | wxTB_DOCKABLE
00286 | wx.NO_BORDER
00287 | wx.TB_FLAT
00288
00289 )
00290
00291 self.exitdoorID = wx.NewId()
00292 self.toolbar.AddSimpleTool(self.exitdoorID, rtimages.getExitDoorBitmap(),
00293 "Exit", "Exit from rtc-link.")
00294 self.Bind(wx.EVT_TOOL, self.TimeToQuit, id=self.exitdoorID)
00295
00296 self.toolbar.AddSeparator()
00297
00298 self.connectID = wx.NewId()
00299 self.toolbar.AddSimpleTool(self.connectID,
00300 rtimages.getConnect2Bitmap(),
00301 "Connect",
00302 "Connect to a Naming Server.")
00303
00304
00305 self.alldispID = wx.NewId()
00306 self.toolbar.AddSimpleTool(self.alldispID, rtimages.getMixNameBitmap(),
00307 "Long Name and Alias", "Display long name and alias on the naming tree window.")
00308 self.Bind(wx.EVT_TOOL, self.OnAllDisp, id=self.alldispID)
00309
00310
00311 self.longdispID = wx.NewId()
00312 self.toolbar.AddSimpleTool(self.longdispID, rtimages.getLongNameBitmap(),
00313 "Long Name", "Display only long name on the naming tree window.")
00314 self.Bind(wx.EVT_TOOL, self.OnLongnameDisp, id=self.longdispID)
00315
00316 self.aliasdispID = wx.NewId()
00317 self.toolbar.AddSimpleTool(self.aliasdispID, rtimages.getShortNameBitmap(),
00318 "Alias", "Display only alias on the naming tree window.")
00319 self.Bind(wx.EVT_TOOL, self.OnAliasDisp, id=self.aliasdispID)
00320
00321
00322
00323 self.toolbar.AddSeparator()
00324
00325 self.newsysID = wx.NewId()
00326 self.toolbar.AddSimpleTool(self.newsysID,
00327 rtimages.getNewRTSystemBitmap(),
00328 "New",
00329 "Open.: Open a new system draw window.")
00330 self.Bind(wx.EVT_TOOL, self.OnNewSystemClick, id=self.newsysID)
00331
00332
00333
00334
00335
00336
00337
00338 self.toolbar.Realize()
00339
00340
00341 self.SetMenuBar(self.CreateMenu())
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 self.myDict = RtmCompData(self)
00355
00356
00357
00358
00359 self.nametreeW_ID = wxNewId()
00360 win = wxSashLayoutWindow(self, self.nametreeW_ID,
00361 style=wx.NO_BORDER|wx.SW_3D)
00362 win.SetDefaultSize((200, 600))
00363 win.SetOrientation(wxLAYOUT_VERTICAL)
00364 win.SetAlignment(wxLAYOUT_LEFT)
00365 win.SetBackgroundColour(wxColour(200, 200, 200))
00366 win.SetSashVisible(wxSASH_RIGHT, True)
00367
00368
00369 tID = wxNewId()
00370 self.treeMap = {}
00371
00372 import RtmTreeCtrl
00373 log = Log()
00374
00375 self.treepanel = RtmTreeCtrl.RtmTreeCtrlPanel(self,win, log)
00376 self.Bind(wx.EVT_TOOL,
00377 self.treepanel.OnConnectNSClick,
00378 id=self.connectID)
00379 self.treepanelW = win
00380
00381
00382
00383
00384 self.profileW_ID = wxNewId()
00385 win = wxSashLayoutWindow(self, self.profileW_ID,
00386 style=wx.NO_BORDER|wx.SW_3D)
00387 win.SetDefaultSize((200, 600))
00388 win.SetOrientation(wxLAYOUT_VERTICAL)
00389 win.SetAlignment(wxLAYOUT_RIGHT)
00390 win.SetBackgroundColour(wxColour(200, 200, 200))
00391 win.SetSashVisible(wxSASH_LEFT, True)
00392
00393 import RtmProfileList
00394 self.profilepanel = RtmProfileList.RtmProfileListPanel(win)
00395 self.profilepanelW = win
00396
00397
00398
00399
00400 self.logW_ID = wxNewId()
00401 win = wxSashLayoutWindow(self, self.logW_ID,
00402 style=wx.NO_BORDER|wx.SW_3D)
00403 win.SetDefaultSize((400, 100))
00404 win.SetOrientation(wx.LAYOUT_HORIZONTAL)
00405 win.SetAlignment(wx.LAYOUT_BOTTOM)
00406 win.SetBackgroundColour(wx.Colour(200, 200, 200))
00407 win.SetSashVisible(wx.SASH_TOP, True)
00408
00409 self.textWindow = wx.TextCtrl(win, -1, "",
00410 style=wx.TE_MULTILINE|wx.SUNKEN_BORDER)
00411 self.textWindow.SetValue("A sub window")
00412
00413 self.logW = win
00414 self.textWindow.SetDropTarget(RTComponentDropTarget(self.textWindow))
00415
00416 self.bg_bmp = rtimages.getGridBGBitmap()
00417 self.GetClientWindow().Bind(
00418 wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground
00419 )
00420
00421 self.Bind(wx.EVT_CLOSE, self.OnClose)
00422 self.Bind(
00423 wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
00424 id=self.nametreeW_ID,
00425 id2=self.logW_ID
00426 )
00427 self.Bind(wx.EVT_SIZE, self.OnSize)
00428
00429
00430 def OnAllDisp(self, event):
00431 self.kindDispMode = 'all'
00432
00433 def OnLongnameDisp(self, event):
00434 self.kindDispMode = 'long'
00435
00436 def OnAliasDisp(self, event):
00437 self.kindDispMode = 'alias'
00438
00439 def OnNewSystemClick(self, event):
00440 self.winCount = self.winCount + 1
00441 new_id = wx.NewId()
00442 win = wxMDIChildFrame(self, new_id , "System: %d" % self.winCount)
00443
00444 self.drawWin[self.winCount] = RtmSystemDraw.RtdSystemDraw(win, self.log, self)
00445 self.drawWin2[self.winCount] = win
00446 win.Show(True)
00447 win.SetIcon(rtimages.getRTIcon())
00448 self.drawWinID[self.winCount] = self.drawWin[self.winCount].GetId()
00449 self.drawCurNum = self.winCount
00450
00451 os_check = sys.platform
00452 if os_check == 'win32':
00453 self.drawWin[self.winCount].Bind(wx.EVT_SET_FOCUS, self.OnChangeDraw)
00454 else:
00455 self.drawWin[self.winCount].Bind(wx.EVT_ENTER_WINDOW, self.OnChangeDraw)
00456 self.drawWin2[self.winCount].Bind(wx.EVT_CLOSE, self.OnChildClose)
00457
00458 def OnChildClose(self, event):
00459 curID = event.GetId()
00460 for n in self.drawWinID.keys():
00461 if self.drawWinID[n] == curID:
00462 self.drawCurNum = n
00463 break
00464 del self.drawWin[self.drawCurNum]
00465 del self.drawWinID[self.drawCurNum]
00466 event.Skip()
00467
00468 def OnChangeDraw(self, event):
00469 curID = event.GetId()
00470 for n in self.drawWinID.keys():
00471 if self.drawWinID[n] == curID:
00472 self.drawCurNum = n
00473 break
00474
00475 def OnSize(self, event):
00476 wxLayoutAlgorithm().LayoutMDIFrame(self)
00477
00478
00479 def OnSashDrag(self, event):
00480 if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
00481 return
00482
00483 eID = event.GetId()
00484 if eID == self.nametreeW_ID:
00485 self.treepanelW.SetDefaultSize((event.GetDragRect().width, 200))
00486
00487 elif eID == self.profileW_ID:
00488 self.profilepanelW.SetDefaultSize((event.GetDragRect().width, 200))
00489
00490 elif eID == self.logW_ID:
00491 print "logW_ID", self.logW_ID
00492 self.logW.SetDefaultSize((1000, event.GetDragRect().height))
00493
00494 wx.LayoutAlgorithm().LayoutMDIFrame(self)
00495 self.GetClientWindow().Refresh()
00496
00497
00498 def OnClose(self, event):
00499 if hasattr(self, "treepanel"):
00500 print 'OnClose:'
00501 self.treepanel.threadloop = 0
00502 self.close_evt.wait()
00503 event.Skip()
00504
00505 def TimeToQuit(self, event):
00506 self.Close(true)
00507
00508
00509 def CreateMenu(self):
00510 menu_file = RtmFileMenu(self).GetMenu()
00511 menu_edit = RtmEditMenu(self).GetMenu()
00512 menu_disp = RtmDisplayMenu(self).GetMenu()
00513 menu_help = RtmHelpMenu(self).GetMenu()
00514
00515 menuBar = wxMenuBar()
00516 menuBar.Append(menu_file, "&File");
00517 menuBar.Append(menu_edit, "&Edit");
00518 menuBar.Append(menu_disp, "&Display");
00519 menuBar.Append(menu_help, "&Help");
00520
00521
00522 id = menuBar.FindMenuItem("Edit","Copy")
00523 menuBar.FindItemById(id).Enable(false)
00524 id = menuBar.FindMenuItem("Edit","Cut")
00525 menuBar.FindItemById(id).Enable(false)
00526 id = menuBar.FindMenuItem("Edit","Paste")
00527 menuBar.FindItemById(id).Enable(false)
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 id = menuBar.FindMenuItem("File","Import Component")
00538 menuBar.FindItemById(id).Enable(false)
00539 id = menuBar.FindMenuItem("File","Export Component")
00540 menuBar.FindItemById(id).Enable(false)
00541
00542 id = menuBar.FindMenuItem("File","Print Preview")
00543 menuBar.FindItemById(id).Enable(false)
00544 id = menuBar.FindMenuItem("File","Print System")
00545 menuBar.FindItemById(id).Enable(false)
00546
00547 return menuBar
00548
00549 def OnFileOpen(self, event):
00550 dlg = wx.FileDialog(
00551 self, message="Choose a file", defaultDir=os.getcwd(),
00552 defaultFile="", wildcard="*.*", style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
00553 )
00554
00555 if dlg.ShowModal() == wx.ID_OK:
00556
00557 self.paths = dlg.GetPaths()
00558
00559
00560
00561
00562
00563
00564
00565
00566 dlg.Destroy()
00567
00568
00569
00570 def OnEraseBackground(self, evt):
00571 dc = evt.GetDC()
00572
00573 if not dc:
00574 dc = wx.ClientDC(self.GetClientWindow())
00575
00576
00577 sz = self.GetClientSize()
00578 w = self.bg_bmp.GetWidth()
00579 h = self.bg_bmp.GetHeight()
00580 x = 0
00581
00582 while x < sz.width:
00583 y = 0
00584
00585 while y < sz.height:
00586 dc.DrawBitmap(self.bg_bmp, (x, y))
00587 y = y + h
00588
00589 x = x + w