コード例 #1
0
ファイル: loggui.py プロジェクト: zhouyiju803904/LogReader
 def fignum_changed(self, action):
     new_fig_num = int(action.text())
     xmin, xmax = self.axs[0].get_xlim()
     for ax in self.axs:
         self.static_canvas.figure.delaxes(ax)
     self.static_canvas.figure.set_figheight(new_fig_num * self.fig_height)
     self.axs = self.static_canvas.figure.subplots(new_fig_num,
                                                   1,
                                                   sharex=True)
     self.static_canvas.figure.canvas.draw()
     self.scroll.setWidgetResizable(True)
     for i in reversed(range(2, self.grid.count())):
         self.grid.itemAt(i).widget().deleteLater()
     for i in range(0, new_fig_num):
         self.grid.setColumnMinimumWidth(i * 2, 40)
         self.grid.setColumnStretch(i * 2 + 1, 1)
     combo_ind = []
     for combo in self.combos:
         combo_ind.append(combo.currentIndex())
     self.labels = []
     self.combos = []
     for i in range(0, new_fig_num):
         label = QtWidgets.QLabel("图片" + str(i + 1), self)
         label.adjustSize()
         combo = ExtendedComboBox(self)
         combo.resize(10, 10)
         combo.activated.connect(self.combo_onActivated)
         self.labels.append(label)
         self.combos.append(combo)
         self.grid.addWidget(label, 1, i * 2)
         self.grid.addWidget(combo, 1, i * 2 + 1)
     # self.info = QtWidgets.QTextBrowser(self)
     # self.info.setReadOnly(True)
     # self.info.setFixedHeight(50)
     # self.grid.addWidget(self.info,2,0,1,50)
     if self.finishReadFlag:
         if self.read_thread.filenames:
             keys = list(self.read_thread.data.keys())
             count = 0
             for ax, combo in zip(self.axs, self.combos):
                 combo.addItems(keys)
                 if count < len(combo_ind):
                     combo.setCurrentIndex(combo_ind[count])
                 count = count + 1
                 ax.set_xlim(xmin, xmax)
                 self.drawdata(ax,
                               self.read_thread.data[combo.currentText()],
                               combo.currentText(), False)
コード例 #2
0
class AddInstructor(QWidget):
    def __init__(self, obj, school=None, ins=None):
        super().__init__()
        self.setWindowTitle('Add Instructor')
        self.setWindowIcon(QIcon('icon/online-learning.png'))
        self.setGeometry(450, 100, 350, 550)
        self.obj = obj
        self.school = school
        self.ins = ins
        self.setFixedSize(self.size())
        self.UI()
        if self.school is None and self.ins is None:
            self.show()
        else:
            self.AddInstructor()

    def UI(self):
        self.get_Defaults()
        self.widgets()
        self.layouts()

    def widgets(self):
        self.titleText = QLabel("Add Instructor")
        self.titleText.setFont(QFont("SansSerif", 20))
        self.titleText.setAlignment(Qt.AlignCenter)

        self.nameEntry = QLineEdit()
        self.nameEntry.setPlaceholderText("Instructor Name")
        self.schoolEntry = ExtendedComboBox()
        self.addSchool = QPushButton('Add')
        self.addSchool.clicked.connect(self.add_School)
        self.savebtn = QPushButton('Save')
        self.savebtn.clicked.connect(self.AddInstructor)

        self.schoolEntry.addItems(sorted(self.schools))

    def layouts(self):
        self.mainLayout = QVBoxLayout()
        self.topLayout = QHBoxLayout()
        self.bottomLayout = QFormLayout()
        self.topFrame = QFrame()
        self.bottomFrame = QFrame()
        self.addSchoolLayout = QHBoxLayout()

        self.addSchoolLayout.addWidget(self.schoolEntry)
        self.addSchoolLayout.addWidget(self.addSchool)

        self.topLayout.addWidget(self.titleText)
        self.topFrame.setLayout(self.topLayout)

        self.bottomLayout.addRow(QLabel("Name: "), self.nameEntry)
        self.bottomLayout.addRow(QLabel("School: "), self.addSchoolLayout)
        self.bottomLayout.addRow(QLabel(''), self.savebtn)

        self.bottomFrame.setLayout(self.bottomLayout)
        self.mainLayout.addWidget(self.topFrame)
        self.mainLayout.addWidget(self.bottomFrame)
        self.setLayout(self.mainLayout)

    def add_School(self):
        self.AddSchool = addschool.AddSchool(self.obj)

    def AddInstructor(self):
        if self.ins is not None and self.school is not None:
            name = self.ins
            school = self.school
        else:
            name = self.nameEntry.text().replace("'", "''")
            school = self.schoolEntry.currentText().replace("'", "''")
        if name and school:
            try:
                query1 = f""" SELECT ID FROM Instructor WHERE LOWER(Instructor.Name) == '{name.lower()}'"""
                curr.execute(query1)
                instructorid = curr.fetchall()
                query2 = f""" SELECT ID FROM School WHERE LOWER(School.Name) == '{school.lower()}'"""
                curr.execute(query2)
                schoolid = curr.fetchall()
                if instructorid == []:
                    if schoolid == []:
                        QMessageBox.information(self, "School Doesn't Exist",
                                                'Please Add the school to the database before using it')
                    else:
                        query = """INSERT INTO Instructor (Name,CoursesCount,SchoolID)  VALUES(?,?,?)"""
                        curr.execute(query, (name, 0, schoolid[0][0]))
                        if instructorid != []:
                            count_query = f''' SELECT count(*) FROM Course WHERE InstructorID='{instructorid[0][0]}' '''
                            count = curr.execute(count_query)
                            count = count[0][0] if count != [] else 0
                            update_query = f''' UPDATE Instructor SET CoursesCount={count} WHERE InstructorID = {instructorid[0][0]}'''
                            curr.execute(update_query)
                        conn.commit()
                        QMessageBox.information(self, 'Info', 'Instructor Has Been added succesfully')
                        self.obj.funcRefresh()
                        self.close()
                else:
                    QMessageBox.information(self, 'Info', 'The Instructor is already added')
                    self.close()
            except Exception as e:
                QMessageBox.information(self, 'Info', 'Instructor Has not been added succesfully')
        else:
            QMessageBox.information(self, 'Info', 'Fields cannot be empty!')

    def get_Defaults(self):
        s = curr.execute('SELECT DISTINCT Name FROM School')
        self.schools = [i[0] for i in s]
コード例 #3
0
class AddCourse(QWidget):
    def __init__(self, obj):
        super().__init__()
        self.setWindowTitle('Add Course')
        self.setWindowIcon(QIcon('icon/courses.png'))
        self.setGeometry(450, 100, 350, 550)
        self.obj = obj
        self.setFixedSize(self.size())
        self.UI()
        self.show()

    def UI(self):
        self.get_Defaults()
        self.widgets()
        self.layouts()

    def widgets(self):
        self.titleText = QLabel("Add Course")
        self.titleText.setFont(QFont("SansSerif", 20))
        self.titleText.setAlignment(Qt.AlignCenter)

        self.titleEntry = QLineEdit()
        self.titleEntry.setPlaceholderText("Course Title")
        self.categoryEntry = ExtendedComboBox()
        self.tagsEntry = QLineEdit()
        self.tagsEntry.setPlaceholderText("Tags comma separated")
        self.durationEntry = QLineEdit()
        self.durationEntry.setPlaceholderText("Duration")
        self.linkEntry = QLineEdit()
        self.linkEntry.setPlaceholderText('Link')
        self.directoryEntry = ExtendedComboBox()
        self.stateEntry = ExtendedComboBox()
        self.instructorEntry = ExtendedComboBox()
        self.addInstructor = QPushButton('Add')
        self.addInstructor.clicked.connect(self.add_Instructor)
        self.schoolEntry = ExtendedComboBox()
        self.addSchool = QPushButton('Add')
        self.addSchool.clicked.connect(self.add_School)
        self.savebtn = QPushButton('Save')
        self.savebtn.clicked.connect(self.addCourse)

        self.schoolEntry.addItems(sorted(self.schools))
        self.instructorEntry.addItems(sorted(self.instructors))
        self.categoryEntry.addItems(sorted(self.categories))
        self.directoryEntry.addItems(['2', '1', '3'])
        self.stateEntry.addItems(['Not Completed', 'Completed'])

    def layouts(self):
        self.mainLayout = QVBoxLayout()
        self.topLayout = QHBoxLayout()
        self.bottomLayout = QFormLayout()
        self.topFrame = QFrame()
        self.bottomFrame = QFrame()
        self.addInstructorLayout = QHBoxLayout()
        self.addSchoolLayout = QHBoxLayout()

        self.topLayout.addWidget(self.titleText)
        self.topFrame.setLayout(self.topLayout)

        self.addInstructorLayout.addWidget(self.instructorEntry)
        self.addInstructorLayout.addWidget(self.addInstructor)
        self.addSchoolLayout.addWidget(self.schoolEntry)
        self.addSchoolLayout.addWidget(self.addSchool)

        self.bottomLayout.addRow(QLabel("Title: "), self.titleEntry)
        self.bottomLayout.addRow(QLabel("School: "), self.addSchoolLayout)
        self.bottomLayout.addRow(QLabel("Instructor: "),
                                 self.addInstructorLayout)
        self.bottomLayout.addRow(QLabel("Category: "), self.categoryEntry)
        self.bottomLayout.addRow(QLabel("Tags: "), self.tagsEntry)
        self.bottomLayout.addRow(QLabel("Duration: "), self.durationEntry)
        self.bottomLayout.addRow(QLabel("Link: "), self.linkEntry)
        self.bottomLayout.addRow(QLabel("Directory: "), self.directoryEntry)
        self.bottomLayout.addRow(QLabel("State: "), self.stateEntry)
        self.bottomLayout.addRow(QLabel(''), self.savebtn)

        self.bottomFrame.setLayout(self.bottomLayout)

        self.mainLayout.addWidget(self.topFrame)
        self.mainLayout.addWidget(self.bottomFrame)
        self.setLayout(self.mainLayout)

    def addCourse(self):
        title = self.titleEntry.text().replace("'", "''")
        category = self.categoryEntry.currentText().replace("'", "''")
        tags = self.tagsEntry.text().replace("'", "''")
        duration = self.durationEntry.text().replace("'", "''")
        link = self.linkEntry.text().replace("'", "''")
        directory = self.directoryEntry.currentText().replace("'", "''")
        state = self.stateEntry.currentText().replace("'", "''")
        instructor = self.instructorEntry.currentText().replace("'", "''")
        school = self.schoolEntry.currentText().replace("'", "''")
        if title and category and tags and duration and link and directory and state and instructor and school:
            try:
                query1 = f""" SELECT ID FROM School WHERE LOWER(School.Name) == '{school.lower()}'"""
                curr.execute(query1)
                schoolid = curr.fetchall()
                query2 = f""" SELECT ID FROM Instructor WHERE LOWER(Instructor.Name) == '{instructor.lower()}'"""
                curr.execute(query2)
                instructorid = curr.fetchall()
                if schoolid == []:
                    QMessageBox.information(
                        self, "School Doesn't Exist",
                        'Please Add the school to the database before using it'
                    )
                elif instructorid == []:
                    QMessageBox.information(
                        self, "Instructor Doesn't Exist",
                        'Please Add the instructor to the database before using it'
                    )
                elif schoolid == [] and instructorid == []:
                    QMessageBox.information(
                        self, "Instructor and School Doesn't Exist",
                        'Please Add the instructor and the school to the database before using it'
                    )
                else:
                    query = """ INSERT INTO Course (Title,Category,Duration,Link,IsCompleted,Directory,Tags,SchoolID,InstructorID) VALUES(?,?,?,?,?,?,?,?,?)"""
                    curr.execute(
                        query,
                        (title, category, duration, link, state, directory,
                         tags, schoolid[0][0], instructorid[0][0]))
                    count_query = f''' SELECT count(*) FROM Course WHERE SchoolID='{schoolid[0][0]}' '''
                    curr.execute(count_query)
                    count = curr.fetchall()[0][0]
                    update_query = f''' UPDATE School SET CourseCount={count} WHERE ID = {schoolid[0][0]}'''
                    curr.execute(update_query)
                    count_query = f''' SELECT count(*) FROM Course WHERE InstructorID='{instructorid[0][0]}' '''
                    curr.execute(count_query)
                    count = curr.fetchall()[0][0]
                    update_query = f''' UPDATE Instructor SET CoursesCount={count} WHERE ID = {instructorid[0][0]}'''
                    curr.execute(update_query)
                    conn.commit()
                    QMessageBox.information(
                        self, 'Info', 'Course Has Been added succesfully')
                    self.obj.funcRefresh()
                    self.close()
            except Exception as e:
                QMessageBox.information(self, 'Info',
                                        'Course has not been added')
        else:
            QMessageBox.information(self, 'Info', 'Fields cannot be empty')

    def add_School(self):
        self.add_school = addschool.AddSchool(self.obj)

    def add_Instructor(self):
        self.add_intructor = addinstructor.AddInstructor(self.obj)

    def get_Defaults(self):
        s = curr.execute('SELECT DISTINCT Name FROM School')
        self.schools = [i[0] for i in s]
        i = curr.execute('SELECT DISTINCT Name FROM Instructor')
        self.instructors = [j[0] for j in i]
        c = curr.execute('SELECT DISTINCT Category FROM Course')
        self.categories = [i[0] for i in c]