コード例 #1
0
    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'])
コード例 #2
0
    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))
コード例 #3
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)
コード例 #4
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]
コード例 #5
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]
コード例 #6
0
class MainWindow(QtGui.QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.init_ui()
        self.paused = True

    def init_ui(self):
        genre_label = QtGui.QLabel('Genre: ')
        max_tempo_label = QtGui.QLabel('Max Tempo: ')
        min_tempo_label = QtGui.QLabel('Min Tempo: ')
        key_label   = QtGui.QLabel('Key Signature: ')

        # Create the genre combo box and fill it with genres
        self.genre_edit = ExtendedComboBox()
        for genre in DataCollector.get_genres():
            self.genre_edit.addItem(genre)
        
        # Create the tempo combo boxes and fill it with tempos
        tempos = list(xrange(1,499))
        self.max_tempo_edit = ExtendedComboBox()
        self.min_tempo_edit = ExtendedComboBox()
        for tempo in tempos:
            self.max_tempo_edit.addItem(str(tempo))
            self.min_tempo_edit.addItem(str(tempo))

        # Create the key combo box and fill it with keys
        keys = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#','G','Ab','A','Bb','B']
        self.key_edit   = QtGui.QComboBox()
        for key in keys:
            self.key_edit.addItem(key)

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(genre_label, 1, 0)
        grid.addWidget(self.genre_edit, 1, 1)
        
        grid.addWidget(max_tempo_label, 2, 0)
        grid.addWidget(self.max_tempo_edit, 2, 1)

        grid.addWidget(min_tempo_label, 3, 0)
        grid.addWidget(self.min_tempo_edit, 3, 1)

        grid.addWidget(key_label, 4, 0)
        grid.addWidget(self.key_edit, 4, 1)

        # Add a compose button
        compose_btn = QtGui.QPushButton('Compose', self)
        compose_btn.resize(compose_btn.sizeHint())
        # links the creation to the clicking of compose
        compose_btn.clicked.connect(self.create)
        grid.addWidget(compose_btn, 5, 1)
        
        # Add a play button
        play_btn = QtGui.QPushButton('Play', self)
        play_btn.resize(play_btn.sizeHint())
        # links the creation to the clicking of play
        play_btn.clicked.connect(self.play)
        grid.addWidget(play_btn, 6, 1)
        
        # Add a pause button
        pause_btn = QtGui.QPushButton('Pause', self)
        pause_btn.resize(pause_btn.sizeHint())
        # links the creation to the clicking of pause
        pause_btn.clicked.connect(self.pause)
        grid.addWidget(pause_btn, 8, 1)
        
        # pygame intialization
        freq = 44100
        bitsize = -16
        channels = 2
        _buffer = 1024
        pygame.mixer.init(freq, bitsize, channels, _buffer)

        self.setLayout(grid)
        self.setGeometry(300, 300, 350, 300)
        self.center()
        self.setWindowTitle('Automatic Music Generator')
        self.show()

    def center(self):
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def create(self):
        style = str(self.genre_edit.currentText())
        max_tempo = str(self.max_tempo_edit.currentText())
        min_tempo = str(self.min_tempo_edit.currentText())
        key = self.key_edit.currentIndex()
        
        # Create a worked thread to learn and compose in the background
        self.thread = QtCore.QThread()
        self.worker = CreatorThread(style, max_tempo, min_tempo, key)
        self.worker.moveToThread(self.thread)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('started()'), self.worker.process)
        QtCore.QObject.connect(self.worker, QtCore.SIGNAL('finished()'), self.thread.quit)
        QtCore.QObject.connect(self.worker, QtCore.SIGNAL('finished()'), self.worker.deleteLater)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('finished()'), self.thread.deleteLater)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('finished()'), self.load_file)
        self.thread.start()

    def load_file(self):
        try:
            pygame.mixer.music.load("output.mid")
            print "Output file loaded!"
        except pygame.error:
            print "File output.mid not found!"
            return

    def play(self):
        pygame.mixer.music.play()
        self.paused = not self.paused

    def pause(self):
        if self.paused:
            pygame.mixer.music.unpause()
            self.paused = not self.paused
        else:
            pygame.mixer.music.pause()
            self.paused = not self.paused
コード例 #7
0
    def init_ui(self):
        genre_label = QtGui.QLabel('Genre: ')
        max_tempo_label = QtGui.QLabel('Max Tempo: ')
        min_tempo_label = QtGui.QLabel('Min Tempo: ')
        key_label   = QtGui.QLabel('Key Signature: ')

        # Create the genre combo box and fill it with genres
        self.genre_edit = ExtendedComboBox()
        for genre in DataCollector.get_genres():
            self.genre_edit.addItem(genre)
        
        # Create the tempo combo boxes and fill it with tempos
        tempos = list(xrange(1,499))
        self.max_tempo_edit = ExtendedComboBox()
        self.min_tempo_edit = ExtendedComboBox()
        for tempo in tempos:
            self.max_tempo_edit.addItem(str(tempo))
            self.min_tempo_edit.addItem(str(tempo))

        # Create the key combo box and fill it with keys
        keys = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#','G','Ab','A','Bb','B']
        self.key_edit   = QtGui.QComboBox()
        for key in keys:
            self.key_edit.addItem(key)

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(genre_label, 1, 0)
        grid.addWidget(self.genre_edit, 1, 1)
        
        grid.addWidget(max_tempo_label, 2, 0)
        grid.addWidget(self.max_tempo_edit, 2, 1)

        grid.addWidget(min_tempo_label, 3, 0)
        grid.addWidget(self.min_tempo_edit, 3, 1)

        grid.addWidget(key_label, 4, 0)
        grid.addWidget(self.key_edit, 4, 1)

        # Add a compose button
        compose_btn = QtGui.QPushButton('Compose', self)
        compose_btn.resize(compose_btn.sizeHint())
        # links the creation to the clicking of compose
        compose_btn.clicked.connect(self.create)
        grid.addWidget(compose_btn, 5, 1)
        
        # Add a play button
        play_btn = QtGui.QPushButton('Play', self)
        play_btn.resize(play_btn.sizeHint())
        # links the creation to the clicking of play
        play_btn.clicked.connect(self.play)
        grid.addWidget(play_btn, 6, 1)
        
        # Add a pause button
        pause_btn = QtGui.QPushButton('Pause', self)
        pause_btn.resize(pause_btn.sizeHint())
        # links the creation to the clicking of pause
        pause_btn.clicked.connect(self.pause)
        grid.addWidget(pause_btn, 8, 1)
        
        # pygame intialization
        freq = 44100
        bitsize = -16
        channels = 2
        _buffer = 1024
        pygame.mixer.init(freq, bitsize, channels, _buffer)

        self.setLayout(grid)
        self.setGeometry(300, 300, 350, 300)
        self.center()
        self.setWindowTitle('Automatic Music Generator')
        self.show()
コード例 #8
0
class MainWindow(QtGui.QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.init_ui()
        self.paused = True

    def init_ui(self):
        genre_label = QtGui.QLabel('Genre: ')
        max_tempo_label = QtGui.QLabel('Max Tempo: ')
        min_tempo_label = QtGui.QLabel('Min Tempo: ')
        key_label = QtGui.QLabel('Key Signature: ')

        # Create the genre combo box and fill it with genres
        self.genre_edit = ExtendedComboBox()
        for genre in DataCollector.get_genres():
            self.genre_edit.addItem(genre)

        # Create the tempo combo boxes and fill it with tempos
        tempos = list(xrange(1, 499))
        self.max_tempo_edit = ExtendedComboBox()
        self.min_tempo_edit = ExtendedComboBox()
        for tempo in tempos:
            self.max_tempo_edit.addItem(str(tempo))
            self.min_tempo_edit.addItem(str(tempo))

        # Create the key combo box and fill it with keys
        keys = [
            'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B'
        ]
        self.key_edit = QtGui.QComboBox()
        for key in keys:
            self.key_edit.addItem(key)

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(genre_label, 1, 0)
        grid.addWidget(self.genre_edit, 1, 1)

        grid.addWidget(max_tempo_label, 2, 0)
        grid.addWidget(self.max_tempo_edit, 2, 1)

        grid.addWidget(min_tempo_label, 3, 0)
        grid.addWidget(self.min_tempo_edit, 3, 1)

        grid.addWidget(key_label, 4, 0)
        grid.addWidget(self.key_edit, 4, 1)

        # Add a compose button
        compose_btn = QtGui.QPushButton('Compose', self)
        compose_btn.resize(compose_btn.sizeHint())
        # links the creation to the clicking of compose
        compose_btn.clicked.connect(self.create)
        grid.addWidget(compose_btn, 5, 1)

        # Add a play button
        play_btn = QtGui.QPushButton('Play', self)
        play_btn.resize(play_btn.sizeHint())
        # links the creation to the clicking of play
        play_btn.clicked.connect(self.play)
        grid.addWidget(play_btn, 6, 1)

        # Add a pause button
        pause_btn = QtGui.QPushButton('Pause', self)
        pause_btn.resize(pause_btn.sizeHint())
        # links the creation to the clicking of pause
        pause_btn.clicked.connect(self.pause)
        grid.addWidget(pause_btn, 8, 1)

        # pygame intialization
        freq = 44100
        bitsize = -16
        channels = 2
        _buffer = 1024
        pygame.mixer.init(freq, bitsize, channels, _buffer)

        self.setLayout(grid)
        self.setGeometry(300, 300, 350, 300)
        self.center()
        self.setWindowTitle('Automatic Music Generator')
        self.show()

    def center(self):
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def create(self):
        style = str(self.genre_edit.currentText())
        max_tempo = str(self.max_tempo_edit.currentText())
        min_tempo = str(self.min_tempo_edit.currentText())
        key = self.key_edit.currentIndex()

        # Create a worked thread to learn and compose in the background
        self.thread = QtCore.QThread()
        self.worker = CreatorThread(style, max_tempo, min_tempo, key)
        self.worker.moveToThread(self.thread)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('started()'),
                               self.worker.process)
        QtCore.QObject.connect(self.worker, QtCore.SIGNAL('finished()'),
                               self.thread.quit)
        QtCore.QObject.connect(self.worker, QtCore.SIGNAL('finished()'),
                               self.worker.deleteLater)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('finished()'),
                               self.thread.deleteLater)
        QtCore.QObject.connect(self.thread, QtCore.SIGNAL('finished()'),
                               self.load_file)
        self.thread.start()

    def load_file(self):
        try:
            pygame.mixer.music.load("output.mid")
            print "Output file loaded!"
        except pygame.error:
            print "File output.mid not found!"
            return

    def play(self):
        pygame.mixer.music.play()
        self.paused = not self.paused

    def pause(self):
        if self.paused:
            pygame.mixer.music.unpause()
            self.paused = not self.paused
        else:
            pygame.mixer.music.pause()
            self.paused = not self.paused
コード例 #9
0
    def init_ui(self):
        genre_label = QtGui.QLabel('Genre: ')
        max_tempo_label = QtGui.QLabel('Max Tempo: ')
        min_tempo_label = QtGui.QLabel('Min Tempo: ')
        key_label = QtGui.QLabel('Key Signature: ')

        # Create the genre combo box and fill it with genres
        self.genre_edit = ExtendedComboBox()
        for genre in DataCollector.get_genres():
            self.genre_edit.addItem(genre)

        # Create the tempo combo boxes and fill it with tempos
        tempos = list(xrange(1, 499))
        self.max_tempo_edit = ExtendedComboBox()
        self.min_tempo_edit = ExtendedComboBox()
        for tempo in tempos:
            self.max_tempo_edit.addItem(str(tempo))
            self.min_tempo_edit.addItem(str(tempo))

        # Create the key combo box and fill it with keys
        keys = [
            'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B'
        ]
        self.key_edit = QtGui.QComboBox()
        for key in keys:
            self.key_edit.addItem(key)

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(genre_label, 1, 0)
        grid.addWidget(self.genre_edit, 1, 1)

        grid.addWidget(max_tempo_label, 2, 0)
        grid.addWidget(self.max_tempo_edit, 2, 1)

        grid.addWidget(min_tempo_label, 3, 0)
        grid.addWidget(self.min_tempo_edit, 3, 1)

        grid.addWidget(key_label, 4, 0)
        grid.addWidget(self.key_edit, 4, 1)

        # Add a compose button
        compose_btn = QtGui.QPushButton('Compose', self)
        compose_btn.resize(compose_btn.sizeHint())
        # links the creation to the clicking of compose
        compose_btn.clicked.connect(self.create)
        grid.addWidget(compose_btn, 5, 1)

        # Add a play button
        play_btn = QtGui.QPushButton('Play', self)
        play_btn.resize(play_btn.sizeHint())
        # links the creation to the clicking of play
        play_btn.clicked.connect(self.play)
        grid.addWidget(play_btn, 6, 1)

        # Add a pause button
        pause_btn = QtGui.QPushButton('Pause', self)
        pause_btn.resize(pause_btn.sizeHint())
        # links the creation to the clicking of pause
        pause_btn.clicked.connect(self.pause)
        grid.addWidget(pause_btn, 8, 1)

        # pygame intialization
        freq = 44100
        bitsize = -16
        channels = 2
        _buffer = 1024
        pygame.mixer.init(freq, bitsize, channels, _buffer)

        self.setLayout(grid)
        self.setGeometry(300, 300, 350, 300)
        self.center()
        self.setWindowTitle('Automatic Music Generator')
        self.show()
コード例 #10
0
ファイル: loggui.py プロジェクト: zhouyiju803904/LogReader
    def setupUI(self):
        """初始化窗口结构"""
        self.setGeometry(50, 50, 800, 900)
        self.max_fig_num = 6
        self.file_menu = QtWidgets.QMenu('&File', self)
        self.file_menu.addAction('&Open', self.openLogFilesDialog,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_O)
        self.file_menu.addAction('&Quit', self.fileQuit,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        self.fig_menu = QtWidgets.QMenu('&Numer', self)
        group = QtWidgets.QActionGroup(self.fig_menu)
        texts = [str(i) for i in range(2, self.max_fig_num + 1)]
        cur_id = 1
        cur_fig_num = int(texts[cur_id])
        for text in texts:
            action = QtWidgets.QAction(text,
                                       self.fig_menu,
                                       checkable=True,
                                       checked=text == texts[cur_id])
            self.fig_menu.addAction(action)
            group.addAction(action)
        group.setExclusive(True)
        group.triggered.connect(self.fignum_changed)
        self.menuBar().addMenu(self.fig_menu)

        self.help_menu = QtWidgets.QMenu('&Help', self)
        self.help_menu.addAction('&About', self.about)
        self.menuBar().addMenu(self.help_menu)

        self._main = Widget()
        self._main.dropped.connect(self.dragFiles)
        self.setCentralWidget(self._main)
        self.layout = QtWidgets.QVBoxLayout(self._main)
        #Add ComboBox
        self.grid = QtWidgets.QGridLayout()
        for i in range(0, cur_fig_num):
            self.grid.setColumnMinimumWidth(i * 2, 40)
            self.grid.setColumnStretch(i * 2 + 1, 1)
        self.labels = []
        self.combos = []
        for i in range(0, cur_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.layout.addLayout(self.grid)

        #消息框
        # self.label_info = QtWidgets.QLabel("",self)
        # self.label_info.setStyleSheet("background-color: white;")
        # self.label_info.setWordWrap(True)
        self.info = QtWidgets.QTextBrowser(self)
        self.info.setReadOnly(True)
        self.info.setMinimumHeight(5)
        # self.layout.addWidget(self.info)

        #图形化结构
        self.fig_height = 2.5
        self.static_canvas = FigureCanvas(
            Figure(figsize=(10, self.fig_height * cur_fig_num)))
        self.static_canvas.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                         QtWidgets.QSizePolicy.Minimum)
        self.fig_widget = Widget()
        self.fig_layout = QtWidgets.QVBoxLayout(self.fig_widget)
        self.fig_layout.addWidget(self.static_canvas)
        self.scroll = QtWidgets.QScrollArea(self.fig_widget)
        self.scroll.setWidget(self.static_canvas)
        self.scroll.setWidgetResizable(True)
        # self.layout.addWidget(self.scroll)
        self.old_home = NavigationToolbar.home
        self.old_forward = NavigationToolbar.forward
        self.old_back = NavigationToolbar.back
        NavigationToolbar.home = self.new_home
        NavigationToolbar.forward = self.new_forward
        NavigationToolbar.back = self.new_back
        self.addToolBar(NavigationToolbar(self.static_canvas, self._main))
        self.axs = self.static_canvas.figure.subplots(cur_fig_num,
                                                      1,
                                                      sharex=True)
        #鼠标移动消息
        self.static_canvas.mpl_connect('motion_notify_event', self.mouse_move)
        self.static_canvas.mpl_connect('button_press_event', self.mouse_press)

        #Log
        self.log_info = QtWidgets.QTextBrowser(self)
        self.log_info.setReadOnly(True)
        self.log_info.setMinimumHeight(10)
        self.log_info.setOpenLinks(False)
        self.log_info.anchorClicked.connect(self.openFileUrl)
        # self.layout.addWidget(self.log_info)

        #消息框,绘图,Log窗口尺寸可变
        splitter1 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        splitter1.addWidget(self.info)
        splitter1.addWidget(self.scroll)
        splitter1.setSizes([1, 100])

        splitter2 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        splitter2.addWidget(splitter1)
        splitter2.addWidget(self.log_info)
        splitter2.setSizes([100, 1])
        self.layout.addWidget(splitter2)

        #选择消息框
        self.hbox = QtWidgets.QHBoxLayout()
        self.check_all = QtWidgets.QCheckBox('ALL', self)
        self.check_fatal = QtWidgets.QCheckBox('FATAL', self)
        self.check_err = QtWidgets.QCheckBox('ERROR', self)
        self.check_war = QtWidgets.QCheckBox('WARNING', self)
        self.check_notice = QtWidgets.QCheckBox('NOTICE', self)
        self.check_tstart = QtWidgets.QCheckBox('TASK START', self)
        self.check_tfinish = QtWidgets.QCheckBox('TASK FINISHED', self)
        self.check_service = QtWidgets.QCheckBox('SERVICE', self)
        self.hbox.addWidget(self.check_all)
        self.hbox.addWidget(self.check_fatal)
        self.hbox.addWidget(self.check_err)
        self.hbox.addWidget(self.check_war)
        self.hbox.addWidget(self.check_notice)
        self.hbox.addWidget(self.check_tstart)
        self.hbox.addWidget(self.check_tfinish)
        self.hbox.addWidget(self.check_service)
        self.hbox.setAlignment(QtCore.Qt.AlignLeft)
        self.layout.addLayout(self.hbox)
        self.check_fatal.stateChanged.connect(self.changeCheckBox)
        self.check_err.stateChanged.connect(self.changeCheckBox)
        self.check_war.stateChanged.connect(self.changeCheckBox)
        self.check_notice.stateChanged.connect(self.changeCheckBox)
        self.check_tstart.stateChanged.connect(self.changeCheckBox)
        self.check_tfinish.stateChanged.connect(self.changeCheckBox)
        self.check_service.stateChanged.connect(self.changeCheckBox)
        self.check_all.stateChanged.connect(self.changeCheckBoxAll)
        self.check_all.setChecked(True)