00001 # -*- coding: utf-8 -*- 00002 #!/usr/local/bin/python 00003 # 00004 # Copyright 2003 00005 # by 00006 # The Board of Trustees of the 00007 # Leland Stanford Junior University. 00008 # All rights reserved. 00009 # 00010 00011 __facility__ = "Online" 00012 __abstract__ = "GLAST Online Single Event Display preferences handler" 00013 __author__ = "A. Kavelaars <aliciak@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00014 __date__ = "12/12/2003" 00015 __version__ = "$Revision: 1.10 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 import sys 00021 import os 00022 from qt import * 00023 import logging as myLog 00024 from ServerPreferences import ServerPreferences 00025 import ConfigParser 00026 00027 00028 00029 class ServerPreferencesImpl(ServerPreferences): 00030 00031 def __init__(self, confParser, parent = None,name = None,modal = 0,fl = 0): 00032 ServerPreferences.__init__(self,parent,name,modal,fl) 00033 00034 self.connect(self.selectServerBox, SIGNAL('clicked(int)'), self.selectServer) 00035 self.connect(self.buttonOk, SIGNAL('clicked()'), self.saveServer) 00036 00037 self.__confParser = confParser 00038 # Revisit: Should check --config option and use that, if supplied 00039 if os.name == "posix": 00040 configName = ".gosedrc" 00041 else: 00042 configName = "gosed.cfg" 00043 00044 configFile = "./" + configName # Current directory 00045 if not os.path.exists(configFile): 00046 try: 00047 home = os.environ['HOME'] 00048 configFile = os.path.join(home, configName) # Home directory 00049 except KeyError: 00050 pass 00051 if not os.path.exists(configFile): 00052 configFile = os.path.join(os.environ['ONLINE_ROOT'], # Source directory 00053 'LATTE/gosed/' + configName) 00054 self.__configFile = configFile 00055 00056 if os.path.exists(self.__configFile): 00057 self.__confParser.read(self.__configFile) 00058 self.selectedServer.setText(self.__confParser.get("server options", "server")) 00059 else: 00060 self.selectedServer.setText('1') 00061 self.__confParser.add_section("server options") 00062 self.__confParser.set("server options", "server", '1') 00063 00064 self.defaultServerButton.setChecked(1) 00065 00066 def selectServer(self): 00067 if self.customServerButton.isChecked(): 00068 self.comboSelectServer.setEnabled(1) 00069 #~ self.comboSelectServerLbl.setEnabled(1) 00070 else: 00071 self.comboSelectServer.setEnabled(0) 00072 #~ self.comboSelectServerLbl.setEnabled(0) 00073 00074 def saveServer(self): 00075 self.__confParser.set("server options", "server", str(self.selectedServer.text())) 00076 try: 00077 self.__confParser.write(file(self.__configFile, "w+")) 00078 except IOError, e: 00079 myLog.warning("Preferences file not saved due to: %s" % e) 00080 00081 00082 if __name__ == "__main__": 00083 a = QApplication(sys.argv) 00084 QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) 00085 w = ServerPreferencesImpl() 00086 a.setMainWidget(w) 00087 w.show() 00088 a.exec_loop()