caddy_gui.py
Go to the documentation of this file.
00001 '''
00002 Created on Sep 10, 2013
00003  \todo Add license information here
00004 @author: dnad
00005 '''
00006 import sys
00007 #from PyQt4 import QtCore, QtGui, uic
00008 from python_qt_binding import QtCore, QtGui, loadUi
00009 from functools import partial
00010 
00011 class CaddyGui(QtCore.QObject):
00012     def __init__(self):
00013         QtCore.QObject.__init__(self)
00014         # Set up the user interface from Designer.
00015         #self._widget = uic.loadUi("resource/CaddyGui.ui")
00016         #self._widget.show()
00017         self._widget = QtGui.QWidget()
00018     
00019     def setup(self):    
00020         self._setup_diver_data()
00021         self._setup_gui()
00022         
00023     def bindHook(self, data):
00024         self._exthook = data        
00025     
00026     def newChatMessage(self, text, source = "Topside"):
00027         chatHistory = QtGui.QTextEdit()
00028         if source == "Topside":
00029             chatHistory = self._widget.topsideChatHistory;
00030         else:      
00031             n = text.find("\n");
00032             if n != -1:
00033                 text = text[0:n] + "|||"+text[n:len(text)]; 
00034             chatHistory = self._widget.diverChatHistory;
00035     
00036         chatHistory.insertPlainText(text)
00037 
00038         
00039     def newDefaultMessage(self, idx):
00040         if idx in self.defaultMsgs.keys(): 
00041             self._widget.defaultTextEdit.insertHtml("<b>" + "Diver: " + "</b>");
00042             self._widget.defaultTextEdit.insertHtml(self.defaultMsgs[idx]);
00043             self._widget.defaultTextEdit.insertPlainText("\n");
00044         
00045     def newOriginPosition(self, data):
00046         self._widget.latLabel.setText(str(data.x))
00047         self._widget.lonLabel.setText(str(data.y))
00048         
00049     def newPladyposInfo(self,data):
00050         if len(data) >= 6:
00051             self._widget.p0field.setText(str(data[0]));
00052             self._widget.p1field.setText(str(data[1]));
00053             self._widget.p2field.setText(str(data[2]));
00054             self._widget.p3field.setText(str(data[3]));
00055             self._widget.currentField.setText(str(data[4]));
00056             self._widget.voltageField.setText(str(data[5]));
00057         
00058     def newManagerState(self,data):                      
00059         if data in self._managerButtons.keys():
00060             for key in self._managerButtons.keys():
00061                 if key == data: 
00062                     self._managerButtons[data].setStyleSheet("color: green;");
00063                 else:
00064                     self._managerButtons[key].setStyleSheet("");
00065                     
00066     def unload(self):
00067         from datetime import datetime;
00068         
00069         if self._widget.saveAll.isChecked():
00070             logFile = open(datetime.today().isoformat() + "_gui_logs.html",'w');
00071             for textEdit in (self._widget.diverChatHistory, 
00072                              self._widget.topsideChatHistory,
00073                              self._widget.defaultTextEdit):
00074                 
00075                 logFile.write(textEdit.toHtml());
00076                 logFile.write("<br>");
00077             
00078             logFile.close(); 
00079         
00080     def _setup_diver_data(self):
00081         self.defaultMsgs = {0:"Alert",
00082                             1:"Ok",
00083                             2:"Yes",
00084                             3:"No",
00085                             4:"Repeat again",
00086                             5:"Diving out",
00087                             6:"Next kml set",
00088                             7:"End kml",
00089                             8:"InitReq"};              
00090         
00091     def _setup_gui(self):
00092         #Fill default combo box
00093         self._widget.defaultComboBox.addItem("Everything OK?");
00094         self._widget.defaultComboBox.addItem("Ok");
00095         self._widget.defaultComboBox.addItem("Yes");
00096         self._widget.defaultComboBox.addItem("No");
00097         self._widget.defaultComboBox.addItem("Repeat again");
00098         self._widget.defaultComboBox.addItem("Dive out");
00099         
00100         #Fill manager state indicators
00101         self._managerButtons={0: self._widget.idleButton,
00102                               1: self._widget.initButton,
00103                               2: self._widget.waitButton,
00104                               3: self._widget.transmitButton};
00105                               
00106         QtCore.QObject.connect(self, QtCore.SIGNAL("onSendKml"), self._exthook.sendKml)
00107         QtCore.QObject.connect(self, QtCore.SIGNAL("onSendText"), self._exthook.sendText)
00108         QtCore.QObject.connect(self, QtCore.SIGNAL("onSendDefault"), self._exthook.sendDefault)
00109        # QtCore.QObject.connect(self, QtCore.SIGNAL("onManagerState"), self._gui.newManagerState)
00110         
00111         #Connect signals and slots
00112         self._widget.chatInput.returnPressed.connect(self._newTopsideMessage)
00113         self._widget.loadKml.clicked.connect(self._onLoadKml)
00114         self._widget.sendDefault.clicked.connect(self._onSendDefault);        
00115         self._widget.sendKml.clicked.connect(
00116                     lambda: 
00117                         self.emit(QtCore.SIGNAL("onSendKml"),self._widget.kmlFilePath.text()));      
00118         
00119         for key, button in self._managerButtons.iteritems():
00120             button.clicked.connect(partial(self._exthook.setManagerState,key))
00121     
00122     def _newTopsideMessage(self):
00123         text = (self._widget.chatInput.text() + "\n");
00124         self.newChatMessage(text)
00125         self.emit(QtCore.SIGNAL("onSendText"),text);
00126         #clear input   
00127         self._widget.chatInput.setText("");
00128         
00129     def _onSendDefault(self):
00130         self._widget.defaultTextEdit.insertHtml("<b>" + "Topside: " + "</b>");
00131         self._widget.defaultTextEdit.insertHtml(self._widget.defaultComboBox.currentText());
00132         self._widget.defaultTextEdit.insertPlainText("\n");
00133         self.emit(QtCore.SIGNAL("onSendDefault"),self._widget.defaultComboBox.currentIndex());
00134         
00135     def _onLoadKml(self):
00136         self._widget.kmlFilePath.setText(QtGui.QFileDialog.getOpenFileName(self._widget, "Get KML file",".","Google KML (*.kml)")[0]);
00137                 
00138 if __name__ == '__main__':
00139     app = QtGui.QApplication(sys.argv)
00140     window = CaddyGui()
00141     sys.exit(app.exec_())


caddy_ui
Author(s): Gyula NagyJane Doe
autogenerated on Fri Feb 7 2014 11:36:10