GlobalPanelImpl.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 #                               Copyright 2005
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __author__   = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online"
00012 __abstract__ = "ScriptEngine Global Panel Implementation"
00013 __date__     = "2002/10/11 00:00:00"
00014 __updated__  = "$Date: 2006/04/14 02:21:57 $"
00015 __version__  = "$Revision: 1.12 $"
00016 __release__  = "$Name: HEAD $"
00017 __credits__  = "SLAC"
00018 
00019 import LICOS.copyright_SLAC
00020 
00021 
00022 from qt import SIGNAL, QCursor, Qt, QAction, QKeySequence, QPixmap
00023 import         os
00024 import         sys
00025 
00026 from LICOS.scriptEngine.GlobalPanel           import GlobalPanel
00027 from LICOS.scriptEngine.HwCfgSelectorImpl     import HwCfgSelectorImpl
00028 from LICOS.tools.teleCmdGUI.TeleCmdTesterImpl import TeleCmdTesterImpl
00029 from LICOS.tools.monitor.TelemMonitorImpl     import TelemMonitorImpl
00030 from LICOS.scriptEngine.FileToolImpl          import FileToolImpl
00031 
00032 class GlobalPanelImpl(GlobalPanel):
00033   """!\brief ScriptEngine Global Panel Implementation.
00034 
00035   """
00036   def __init__(self, rc, common, parent = None, name = None, fl = 0):
00037     """!\brief GlobalPanelImpl constructor
00038 
00039     \param rc     ScriptEngine GUI instance
00040     \param common ScriptEngineCommon instance
00041     \param parent Parent GUI
00042     \param name   GUI name
00043     \param fl     GUI flags
00044     """
00045     GlobalPanel.__init__(self, parent, name, fl)
00046     self.__rc       = rc
00047     self.__common   = common
00048     self.__parent   = parent
00049     self.__userapp  = None
00050     self.__operator = None
00051     self.__tcGUI    = None
00052     self.__dmGUI    = None
00053     self.__tlmGUI   = None
00054     self.__fileGUI  = None
00055 
00056     self.connect(self.MSGLoggerButton,SIGNAL("clicked()"),self.loadMSGLogger)
00057     self.connect(self.cmdBrowseExport,SIGNAL("clicked()"),self.browseExportedFiles)
00058     self.connect(self.cmdTeleCommand,SIGNAL("clicked()"),self.teleCommandGUI)
00059     self.connect(self.cmdDiagMonitor,SIGNAL("clicked()"),self.diagMonitor)
00060     self.connect(self.cmdTelemMonitor,SIGNAL("clicked()"),self.telemMonitor)
00061     self.connect(self.cmdHwCfgSelector,SIGNAL("clicked()"),self.hwConfigSelector)
00062     self.connect(self.cmdFileTool,SIGNAL("clicked()"),self.fileTool)
00063 
00064     self.toolsMessage_LoggerAction = QAction(self.__rc,"toolsMessage_LoggerAction")
00065     self.toolsBrowse_Exported_FilesAction = QAction(self.__rc,"toolsBrowse_Exported_FilesAction")
00066     self.toolsTeleCommandAction = QAction(self.__rc,"toolsTeleCommandAction")
00067     self.toolsDiagMonitorAction = QAction(self.__rc,"toolsDiagMonitorAction")
00068     self.toolsTelemMonitorAction = QAction(self.__rc,"toolsTelemMonitorAction")
00069     self.toolsHwCfgSelectorAction = QAction(self.__rc,"toolsHwCfgSelectorAction")
00070     self.toolsFileTransferAction  = QAction(self.__rc,"toolsFileTransferAction")
00071 
00072     self.toolsMessage_LoggerAction.setText("Message Logger")
00073     self.toolsMessage_LoggerAction.setMenuText("&Message Logger")
00074     self.toolsMessage_LoggerAction.setToolTip("Message Logger")
00075     self.toolsMessage_LoggerAction.setAccel(QKeySequence("Ctrl+Shift+M"))
00076 
00077     self.toolsBrowse_Exported_FilesAction.setText("Browse Exported Files")
00078     self.toolsBrowse_Exported_FilesAction.setMenuText("&Browse Exported Files")
00079     self.toolsBrowse_Exported_FilesAction.setToolTip("Browse Exported Files")
00080     self.toolsBrowse_Exported_FilesAction.setAccel(QKeySequence("Ctrl+Shift+B"))
00081 
00082     self.toolsTeleCommandAction.setText("Real-time TeleCommand GUI")
00083     self.toolsTeleCommandAction.setMenuText("Real-time &TeleCommand GUI")
00084     self.toolsTeleCommandAction.setToolTip("Real-time TeleCommand GUI")
00085     self.toolsTeleCommandAction.setAccel(QKeySequence("Ctrl+Shift+T"))
00086 
00087     self.toolsDiagMonitorAction.setText("Diagnostics Telemetry Monitor")
00088     self.toolsDiagMonitorAction.setMenuText("&Diagnostics Telemetry Monitor")
00089     self.toolsDiagMonitorAction.setToolTip("Diagnostics Telemetry Monitor")
00090     self.toolsDiagMonitorAction.setAccel(QKeySequence("Ctrl+Shift+D"))
00091     self.toolsDiagMonitorAction.setText("Diagnostics Telemetry Monitor")
00092 
00093     self.toolsTelemMonitorAction.setMenuText("&Telemetry Monitor")
00094     self.toolsTelemMonitorAction.setToolTip("Telemetry Monitor")
00095     self.toolsTelemMonitorAction.setAccel(QKeySequence("Ctrl+Shift+L"))
00096     self.toolsTelemMonitorAction.setText("Telemetry Monitor")
00097 
00098     self.toolsHwCfgSelectorAction.setMenuText("&Hardware Config Selector")
00099     self.toolsHwCfgSelectorAction.setToolTip("Hardware Config Selector")
00100     self.toolsHwCfgSelectorAction.setAccel(QKeySequence("Ctrl+Shift+H"))
00101     self.toolsHwCfgSelectorAction.setText("Hardware Config Selector")
00102 
00103     self.toolsFileTransferAction.setMenuText("&File Transfer Tool")
00104     self.toolsFileTransferAction.setToolTip("File Transfer Tool")
00105     self.toolsFileTransferAction.setText("File Transfer Tool")
00106 
00107     self.toolsMessage_LoggerAction.addTo(self.__rc.Tools)
00108     self.toolsBrowse_Exported_FilesAction.addTo(self.__rc.Tools)
00109     self.toolsTeleCommandAction.addTo(self.__rc.Tools)
00110     self.toolsDiagMonitorAction.addTo(self.__rc.Tools)
00111     self.toolsTelemMonitorAction.addTo(self.__rc.Tools)
00112     self.toolsHwCfgSelectorAction.addTo(self.__rc.Tools)
00113     self.toolsFileTransferAction.addTo(self.__rc.Tools)
00114 
00115     self.connect(self.toolsMessage_LoggerAction,SIGNAL("activated()"),self.loadMSGLogger)
00116     self.connect(self.toolsBrowse_Exported_FilesAction,SIGNAL("activated()"),self.browseExportedFiles)
00117     self.connect(self.toolsTeleCommandAction,SIGNAL("activated()"),self.teleCommandGUI)
00118     self.connect(self.toolsDiagMonitorAction,SIGNAL("activated()"),self.diagMonitor)
00119     self.connect(self.toolsTelemMonitorAction,SIGNAL("activated()"),self.telemMonitor)
00120     self.connect(self.toolsHwCfgSelectorAction,SIGNAL("activated()"),self.hwConfigSelector)
00121     self.connect(self.toolsFileTransferAction,SIGNAL("activated()"),self.fileTool)
00122 
00123     if self.__common.options().securedir is not None:
00124       if os.path.splitext(os.path.split(sys.executable)[1])[0] == 'pythonw':
00125         self.loadMSGLogger()
00126 
00127     if not self.isrealfile(sys.__stdout__):
00128       sys.stdout = NullStream()
00129 
00130     if not self.isrealfile(sys.__stderr__):
00131       sys.stderr = NullStream()
00132 
00133     if self.__common.options().appdir is not None:
00134       self.userAppAction = QAction(self.__rc, "userAppAction")
00135       self.userAppAction.setText("User Applications Browser")
00136       self.userAppAction.setMenuText("&User Applications Browser")
00137       self.userAppAction.setToolTip("User Applications Browser")
00138       self.userAppAction.setAccel(QKeySequence("Ctrl+Shift+U"))
00139       self.userAppAction.addTo(self.__rc.Tools)
00140       self.connect(self.userAppAction,SIGNAL("activated()"),self.startUserApp)
00141 
00142   def isrealfile(self, file):
00143     """!\brief Test if file is on the os filesystem
00144 
00145     """
00146     if not hasattr(file, 'fileno'): return False
00147 
00148     try:
00149       tmp = os.dup(file.fileno())
00150     except:
00151       return False
00152     else:
00153       os.close(tmp)
00154       return True
00155 
00156   def applyPermissions(self, operator):
00157     """!\brief Apply the permissions based on the \a operator's privileges.
00158 
00159     \param operator Operator's rcUser instance
00160     """
00161     self.__operator = operator
00162     adminOverride = operator.isAdministrator()
00163     if 'start_message_logger' in operator.getPermissions() or adminOverride:
00164       self.toolsMessage_LoggerAction.setEnabled(1)
00165       self.MSGLoggerButton.setEnabled(1)
00166     else:
00167       self.toolsMessage_LoggerAction.setEnabled(0)
00168       self.MSGLoggerButton.setEnabled(0)
00169 
00170     if 'browse_exported_files' in operator.getPermissions() or adminOverride:
00171       self.toolsBrowse_Exported_FilesAction.setEnabled(1)
00172       self.cmdBrowseExport.setEnabled(1)
00173     else:
00174       self.toolsBrowse_Exported_FilesAction.setEnabled(0)
00175       self.cmdBrowseExport.setEnabled(0)
00176 
00177     if 'realtime_telecmd' in operator.getPermissions() or adminOverride:
00178       self.toolsTeleCommandAction.setEnabled(1)
00179       self.cmdTeleCommand.setEnabled(1)
00180     else:
00181       self.toolsTeleCommandAction.setEnabled(0)
00182       self.cmdTeleCommand.setEnabled(0)
00183 
00184     if 'diag_monitor' in operator.getPermissions() or adminOverride:
00185       self.toolsDiagMonitorAction.setEnabled(1)
00186       self.cmdDiagMonitor.setEnabled(1)
00187     else:
00188       self.toolsDiagMonitorAction.setEnabled(0)
00189       self.cmdDiagMonitor.setEnabled(0)
00190 
00191     if 'telem_monitor' in operator.getPermissions() or adminOverride:
00192       self.toolsTelemMonitorAction.setEnabled(1)
00193       self.cmdTelemMonitor.setEnabled(1)
00194     else:
00195       self.toolsTelemMonitorAction.setEnabled(0)
00196       self.cmdTelemMonitor.setEnabled(0)
00197 
00198   def loadMSGLogger(self):
00199     """!\brief Show the message logger GUI
00200 
00201     """
00202     if self.__common.getMSGLogger() is not None:
00203       self.activateWindow(self.__common.getMSGLogger())
00204 
00205   def browseExportedFiles(self):
00206     """!\brief Show the folder for files exported during the last run.
00207 
00208     """
00209     dbn = self.__common.getDBN()
00210     if '_LastExportPath' in dbn:
00211       import webbrowser
00212       webbrowser.open(url=self.__common.getDBN()['_LastExportPath'], new=1)
00213 
00214   def teleCommandGUI(self):
00215     """!\brief Show the real-time tele command execution GUI.
00216 
00217     """
00218     if self.__tcGUI is None:
00219       self.__tcGUI = TeleCmdTesterImpl(self.__common.getCmdCli())
00220       self.__tcGUI.setCaption("Real-time Tele Command Execution Window")
00221     self.activateWindow(self.__tcGUI)
00222 
00223   def diagMonitor(self):
00224     """!\brief Show the diagnostics telemetry monitor.
00225 
00226     """
00227     if self.__dmGUI is None:
00228       self.__dmGUI = TelemMonitorImpl(self.__common.getDiagHandler(), self.__common.getGUI())
00229       self.__dmGUI.setCaption("Diagnostics Telemetry Monitor")
00230     self.activateWindow(self.__dmGUI)
00231 
00232   def telemMonitor(self):
00233     """!\brief Show the telemetry monitor.
00234 
00235     """
00236     if self.__tlmGUI is None:
00237       self.__tlmGUI = TelemMonitorImpl(self.__common.getTelemHandler(), self.__common.getGUI())
00238       self.__tlmGUI.setCaption("Telemetry Monitor")
00239     self.activateWindow(self.__tlmGUI)
00240 
00241   def hwConfigSelector(self):
00242     self.__common.configureHardware()
00243 
00244   def fileTool(self):
00245     """!\brief Show the File transfer tool
00246 
00247     """
00248     if self.__fileGUI is None:
00249       self.__fileGUI = FileToolImpl(self.__common, self.__common.getGUI())
00250       self.__fileGUI.setCaption("File Transfer Tool")
00251     self.activateWindow(self.__fileGUI)
00252 
00253   def activateWindow(self, window):
00254     """!\brief Activate the window so that it is visible and has focus.
00255 
00256     \param window The dialog or window
00257     """
00258     window.setWindowState(window.windowState() & ~Qt.WindowMinimized)
00259     window.setActiveWindow()
00260     window.show()
00261 
00262 
00263   def startUserApp(self):
00264     """!\brief Start the user application
00265 
00266     """
00267     if self.__userapp is None:
00268       if self.__common.options().appdir is not None:
00269         appdir = self.__common.options().appdir
00270         self.__userapp = userAppBrowser(self.__rc, appdir)
00271         self.__userapp.updateSchema()
00272         self.__userapp.show()
00273     elif self.__userapp.isVisible():
00274       self.__userapp.hide()
00275     else:
00276       self.__userapp.updateSchema()
00277       self.__userapp.show()
00278 
00279   def getUserApp(self, appname=None):
00280     """!\brief Retrieve the user application
00281 
00282     \param appname Application name
00283 
00284     \return User application
00285     """
00286     if appname is not None:
00287       return self.__userapp.getGui(appname)
00288     else:
00289       return self.__userapp
00290 
00291   def getUserAppTree(self):
00292     """!\brief Retrieve the user application tree
00293 
00294     \return User application tree
00295     """
00296     return self.__userapp.getTree()
00297 
00298 class NullStream:
00299     """!\brief A file like class that writes nothing.
00300 
00301     """
00302     def close(self): pass
00303     def flush(self): pass
00304     def write(self, str): pass
00305     def writelines(self, sequence): pass

Generated on Thu Apr 27 20:52:41 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO