Example #1
0
class EkdMessage(QDialog):
    '''
    EkdMessage : Classe représentant une boite de dialogue avec un texte,
    des bouton et une icone permettant d'avertir l'utilisateur
    '''
    def __init__(self, titre, texte="", min_w=320, min_h=250, max_w=500,
                    max_h=600, icone="Icones/messagebox_info.png",
                    checkbox=False, parent=None):
        """Boite de message standard pour ekd.
           Usage :
             1. initialisation en spécifiant la taille, le titre et
                éventuellement le texte de la fenêtre.
                l'icone est également paramétrable
             2. Ajout du text avec la fonction setAideText.
             3. Affichage de la fenêtre en appelant la fonction show().
           Facilité :
             1. Redimensionnement de la fenêtre par appel de la fonction
                setSize(w, h)
             2. Ajout automatique des bars de défilement."""
        super(EkdMessage, self).__init__(parent)
        self.setWindowTitle(titre)
        self.setMaximumHeight(max_h)
        self.setMaximumWidth(max_w)
        self.setMinimumHeight(min_h)
        self.setMinimumWidth(min_w)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setVerticalStretch(1)
        self.setSizePolicy(sizePolicy)

        self.w = min_w
        self.h = min_h
        self.verticalLayout = QVBoxLayout(self)
        self.hbox1 = QHBoxLayout()
        self.vbox1 = QVBoxLayout()

        # Icone
        self.iconeI = QLabel(self)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
                    self.iconeI.sizePolicy().hasHeightForWidth())
        self.iconeI.setSizePolicy(sizePolicy)
        self.iconeI.setPixmap(QPixmap(icone))
        self.vbox1.addWidget(self.iconeI)
        spacerItem = QSpacerItem(20, 40,
                                QSizePolicy.Minimum,
                                QSizePolicy.Expanding)
        self.vbox1.addItem(spacerItem)
        self.hbox1.addLayout(self.vbox1)
        ##

        # Definition de la zone de texte
        self.text = QTextEdit(self)

        ## On utilise le même thème que la fenêtre pour la zone de texte
        ## On force les couleur ici, on ne laisse pas le Thème s'en charger
        palette = self.text.palette()
        palette.setBrush(QPalette.Active,
                            QPalette.Base,
                            self.palette().window())
        palette.setBrush(QPalette.Inactive,
                            QPalette.Base,
                            self.palette().window())
        palette.setBrush(QPalette.Disabled,
                            QPalette.Base,
                            self.palette().window())
        palette.setBrush(QPalette.Active,
                            QPalette.Text,
                            self.palette().windowText())
        palette.setBrush(QPalette.Inactive,
                            QPalette.Text,
                            self.palette().windowText())
        palette.setBrush(QPalette.Disabled,
                            QPalette.Text,
                            self.palette().windowText())
        self.text.setPalette(palette)

        self.text.setFrameShape(QFrame.NoFrame)
        self.text.setFrameShadow(QFrame.Plain)
        self.text.setLineWidth(0)
        self.text.setReadOnly(True)
        self.text.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.text.sizePolicy().hasHeightForWidth())
        self.text.setSizePolicy(sizePolicy)
        self.hbox1.addWidget(self.text)
        ##

        self.verticalLayout.addLayout(self.hbox1)
        self.hbox2 = QHBoxLayout()
        self.ok = QPushButton(self)
        self.ok.setText(_("Ok"))
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.ok.sizePolicy().hasHeightForWidth())
        self.ok.setSizePolicy(sizePolicy)
        self.hbox2.addWidget(self.ok)
        self.verticalLayout.addLayout(self.hbox2)
        self.setText(texte)

        '''
        Checkbox pour savoir si l'utilisateur veut oui ou non revoir
        l'avertissement
        '''
        if checkbox :
            self.checkbox = QCheckBox(_(u"Voir ce message la prochaine fois"),
                                        self)
            self.hbox2.addWidget(self.checkbox)
            try :
                self.checkbox.setCheckState(int(EkdConfig.get("general",
                                                    "show_warning_messages")))
            except Exception, e:
                #print "First time launched"
		EkdPrint(u"First time launched")
            self.connect(self.checkbox, SIGNAL("stateChanged(int)"),
                                                    self.setDontShow)

        self.connect(self.ok, SIGNAL("clicked()"), self.close)
Example #2
0
class ErrorLogDialog(QDialog):
    def __init__(self, parent):
        super(ErrorLogDialog, self).__init__(parent, Qt.WindowStaysOnTopHint)
        self._empty = True
        
        self._initUI()
        self.setWindowTitle("Error")
        get_notification_center().connectLogMessage(self._checkLogMessage)
        
        for record in getCachedLogRecords():
            self._checkLogMessage(record)
        
    def sizeHint(self):
        return QSize(400, 200)
        
    def _initUI(self):
        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 10, 0, 0)
        layout.setSpacing(0)
        
        labelLayout = QHBoxLayout()
        labelLayout.addWidget(QLabel(u"Sorry, something went wrong:", self))
        labelLayout.setContentsMargins(10, 0, 0, 0)
        layout.addLayout(labelLayout)
        layout.addSpacing(5)
        self._errorLog = QTextEdit(self)
        self._errorLog.setReadOnly(True)
        self._errorLog.setWordWrapMode(QTextOption.NoWrap)
        self._errorLog.setTextColor(QColor(180, 0, 0))
        self._errorLog.setObjectName(u"__ERROR_LOG_")
        
        self._errorLog.setFrameShape(QFrame.StyledPanel)
        if getPlatform() == PLATFORM_MAC:
            self._errorLog.setStyleSheet("QFrame#__ERROR_LOG_{border-width: 1px; border-top-style: solid; border-right-style: none; border-bottom-style: solid; border-left-style: none; border-color:palette(mid)}");
            
        layout.addWidget(self._errorLog)
        
        bottomWidget = QWidget(self)
        bottomLayout = QHBoxLayout(bottomWidget)
        
        self._notAgain = QCheckBox(u"Please, no more error messages!", self)
        bottomLayout.addWidget(self._notAgain, 1, Qt.AlignTop)
        
        buttonBox = QDialogButtonBox(QDialogButtonBox.Close, Qt.Horizontal, self)
        buttonBox.rejected.connect(self.reject)
        bottomLayout.addWidget(buttonBox)
        
        layout.addWidget(bottomWidget)
        
    @loggingSlot()
    def reject(self):
        self._errorLog.clear()
        self._empty = True
        return QDialog.reject(self)
    
    @loggingSlot(object)
    def _checkLogMessage(self, record):
        try:
            if self._notAgain.checkState() == Qt.Checked:
                return
            if record.levelno >= logging.ERROR:
                recMsg = record.msg
                if not isinstance(recMsg, basestring):
                    recMsg = unicode(recMsg)
                err = convert_string(recMsg) % record.args
                component = record.name
                if component.startswith("lunchinator."):
                    component = component[12:]
                    
                msg = u"%s - In component %s (%s:%d):\n%s" % (strftime("%H:%M:%S", localtime(record.created)),
                                                              component,
                                                              record.pathname,
                                                              record.lineno,
                                                              err)
                if record.exc_info:
                    out = StringIO()
                    traceback.print_tb(record.exc_info[2], file=out)
                    msg += u"\nStack trace:\n" + out.getvalue() + formatException(record.exc_info) + u"\n"
                    
                self._errorLog.append(msg)
                self._empty = False
                if not self.isVisible():
                    self.showNormal()
                    self.raise_()
                    self.activateWindow()
        except:
            from lunchinator.log import getCoreLogger
            getCoreLogger().info(formatException())