Package qt_dialog_service :: Module qt_dialog_service
[hide private]
[frames] | no frames]

Source Code for Module qt_dialog_service.qt_dialog_service

 1   
 2  import sys 
 3   
 4  from python_qt_binding import QtGui 
 5  from QtGui import QWidget, QErrorMessage, QMessageBox, QApplication 
 6   
7 -class DialogService(QWidget):
8 ''' 9 Provides popup windows for information and error messages 10 ''' 11 12 #---------------------------------- 13 # Initializer 14 #-------------- 15
16 - def __init__(self, parent=None):
17 super(DialogService, self).__init__(parent); 18 19 # All-purpose error popup message: 20 # Used by self.showErrorMsgByErrorCode(<errorCode>), 21 # or self.showErrorMsg(<string>). Returns a 22 # QErrorMessage without parent, but with QWindowFlags set 23 # properly to be a dialog popup box: 24 self.errorMsgPopup = QErrorMessage.qtHandler(); 25 # Re-parent the popup, retaining the window flags set 26 # by the qtHandler: 27 self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); 28 #self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); 29 self.infoMsg = QMessageBox(parent=parent);
30 #self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); 31 32 #---------------------------------- 33 # showErrorMsg 34 #-------------- 35 QErrorMessage
36 - def showErrorMsg(self,errMsg):
37 ''' 38 Given a string, pop up an error dialog on top of the application window. 39 @param errMsg: The message 40 @type errMsg: string 41 ''' 42 self.errorMsgPopup.showMessage(errMsg);
43 44 #---------------------------------- 45 # showInfoMsg 46 #-------------- 47
48 - def showInfoMsg(self, text):
49 ''' 50 Display a message window with an OK button on top of the application window. 51 @param text: text to display 52 @type text: string 53 ''' 54 self.infoMsg.setText(text); 55 self.infoMsg.exec_();
56 57 if __name__ == '__main__': 58 59 60 app = QApplication(sys.argv); 61 dservice = DialogService() 62 dservice.showErrorMsg("This is an error") 63 dservice.showInfoMsg("This is info") 64 app.exec_(); 65 sys.exit(); 66