Ejemplo n.º 1
0
    def addNewMessage(self):
        name = self.ui.txt_name.text()
        text = self.ui.txt_message.text()
        now = datetime.now().strftime('%H')

        if name != "" and text != "":
            for message in self.messages:
                if name == message[1]:
                    if int(now) - int(message[3][11:12]) <= 0:
                        self.msgBox("Your message should be for 1 hour ago or more")
                        break
            else:
                response = Database.insert(name, text)
                if response:
                    self.length += 1
                    label = QLabel()
                    label.setText(name + ": " + text)
                    self.ui.gl_messages.addWidget(label, self.length, 1, alignment=Qt.Alignment())
                    
                    btn = QPushButton()
                    btn.setText('×')
                    btn.setStyleSheet('max-width: 18px; min-height: 18px; background-color: red; color: white; border: 0px; border-radius: 5px;')
                    self.ui.gl_messages.addWidget(btn, self.length, 0, alignment=Qt.Alignment())
                    btn.clicked.connect(partial(self.deleteMessage, self.messages[-1][0], btn, label))
                
                    self.ui.txt_name.setText("")
                    self.ui.txt_message.setText("")

                    self.msgBox("Your message sent successfully!")
                else:
                    self.msgBox("Database error!")                
        else:
            self.msgBox("Error: feilds are empty!")
Ejemplo n.º 2
0
    def saveStopWatch(self):
        self.length_stw += 1

        label_num = QLabel()
        label_total = QLabel()
        label_num.setText(str(self.length_stw))
        label_total.setText(self.ui.lbl_stopwatch.text())
        label_num.setStyleSheet('max-width: 50px; padding-left: 20px;')
        self.ui.gl_saved_times.addWidget(label_num, self.length_stw, 0, alignment=Qt.Alignment())
        self.ui.gl_saved_times.addWidget(label_total, self.length_stw, 1, alignment=Qt.Alignment())
Ejemplo n.º 3
0
    def readMessages(self):
        messages = Database.select()
        for i, message in enumerate(messages):
            label = QLabel()
            label.setText(message[1] + ": " + message[2])
            self.ui.gl_messages.addWidget(label,i, 1, alignment=Qt.Alignment())
            
            btn = QPushButton()
            btn.setText('×')
            btn.setStyleSheet('max-width: 18px; min-height: 18px; background-color: red; color: white; border: 0px; border-radius: 5px;')

            self.ui.gl_messages.addWidget(btn, i, 0, alignment=Qt.Alignment())
            btn.clicked.connect(partial(self.deleteMessage, message[0], btn, label))
        return messages