示例#1
0
def fill_sector_table(data, table, plot):
    table.setSortingEnabled(False)
    smodel = table.selectionModel()
    for c, field in enumerate(data.index):
        if str(field) != '':
            widget_item = QTableWidgetItem(str(field))
            if data.iloc[c]['Selected'] == "Yes":
                widget_item.setSelected(True)
                model_index = table.model().createIndex(c + 1, 0)
                smodel.select(model_index, QItemSelectionModel.Select)
            table.setItem(c, 1, widget_item)
    table.setSortingEnabled(True)
示例#2
0
    def __init__(self, genreList=[], *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Get screen size to make obj reletive instread of fixed
        sizeObject = QDesktopWidget().screenGeometry(-1)
        width = sizeObject.width()
        height = sizeObject.height()

        # set initial Layouts
        mainLayout = QVBoxLayout(self)
        exitLayout = QHBoxLayout()
        cacheLayout = QVBoxLayout()
        genreLayout = QVBoxLayout()
        classLayout = QVBoxLayout()
        genreBox = QHBoxLayout()

        # Label for cache
        cacheLable = QLabel(
            "Update Music Cache: Updating the music cache means you will pull new music from Spotify and update the databse"
        )
        cacheLable.setAlignment(Qt.AlignCenter)

        # Button to update cache
        self.cacheButton = QPushButton("Update Cache")
        self.cacheButton.setFixedSize(QSize(width / 14, height / 30))

        # Label for genre
        genreLable = QLabel(
            "Update Your Genres: Updating your genres means you will be recommended more music in these genres"
        )
        genreLable.setAlignment(Qt.AlignCenter)

        # Table for genres
        self.genreTable = QTableWidget()

        self.genreTable.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.genreTable.horizontalHeader().setVisible(False)
        self.genreTable.verticalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.genreTable.verticalHeader().setVisible(False)
        self.genreTable.setSizeAdjustPolicy(
            QAbstractScrollArea.AdjustToContents)

        genres = [
            'acoustic', 'afrobeat', 'alt-rock', 'alternative', 'ambient',
            'black-metal', 'bluegrass', 'blues', 'bossanova', 'chicago-house',
            'chill', 'classical', 'comedy', 'country', 'dance', 'death-metal',
            'deep-house', 'detroit-techno', 'disco', 'dubstep', 'edm',
            'electronic', 'emo', 'folk', 'funk', 'gospel', 'goth', 'grindcore',
            'groove', 'grunge', 'guitar', 'happy', 'hard-rock', 'hardcore',
            'heavy-metal', 'hip-hop', 'house', 'indie', 'industrial', 'jazz',
            'latin', 'latino', 'metal', 'metal-misc', 'metalcore', 'indie-pop',
            'new-age', 'new-release', 'opera', 'party', 'piano', 'pop',
            'progressive-house', 'psych-rock', 'punk-rock', 'r-n-b',
            'rainy-day', 'reggae', 'rock', 'rock-n-roll', 'romance', 'sad',
            'salsa', 'sleep', 'soul', 'spanish', 'study', 'summer', 'tango',
            'techno', 'trance', 'work-out'
        ]

        self.genreTable.setRowCount(math.ceil(len(genres) / 6))
        self.genreTable.setColumnCount(6)
        self.genreTable.setSelectionMode(QAbstractItemView.MultiSelection)
        self.genreTable.setEditTriggers(QAbstractItemView.NoEditTriggers)

        # Set the table widget item in table and center the text.
        row = 0
        for i in range(len(genres)):
            if (i % 6 == 0 and i != 0):
                row += 1
            col = i % 6
            types = QTableWidgetItem(genres[i])
            types.setTextAlignment(Qt.AlignCenter)
            self.genreTable.setItem(row, col, types)
            if genres[i] in genreList:
                types.setSelected(True)

        # Label for classifier
        classifierLable = QLabel(
            "Update Your Classifier: Updating your classifier will change the algorithm used to get your recommendations.\n(Note: Please see the 'Help' tab to learn more)"
        )
        classifierLable.setAlignment(Qt.AlignLeft)

        # Combo box to select classifier
        self.classifierCombo = QComboBox()
        self.classifierCombo.setFixedWidth(width / 10)
        self.classifierCombo.addItem("Gradient Boosting ")
        self.classifierCombo.addItem("K-Nearest Neighbors")
        self.classifierCombo.addItem("RBF SVM")

        # Way to cancel and exit GUI
        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.setFixedSize(QSize(width / 18, height / 25))

        # Way to save options selected
        self.okButton = QPushButton("OK")
        self.okButton.setFixedSize(QSize(width / 18, height / 25))

        # First/Main layout to hold the main widget stuff
        mainLayout.addStretch(0)
        mainLayout.addSpacing(width / 50)
        cacheLayout.addWidget(cacheLable)
        cacheLayout.addSpacing(width / 90)
        cacheLayout.addWidget(self.cacheButton)
        cacheLayout.setAlignment(Qt.AlignLeft)
        mainLayout.addLayout(cacheLayout)
        mainLayout.addStretch(0)
        genreLayout.addWidget(genreLable)
        genreLayout.setAlignment(Qt.AlignLeft)
        mainLayout.addSpacing(width / 50)
        mainLayout.addLayout(genreLayout)
        mainLayout.addSpacing(width / 90)
        genreBox.addWidget(self.genreTable)
        genreBox.addSpacing(width / 5)
        mainLayout.addLayout(genreBox)
        mainLayout.addSpacing(width / 50)
        mainLayout.addStretch(0)
        classLayout.addWidget(classifierLable)
        classLayout.addSpacing(width / 90)
        classLayout.addWidget(self.classifierCombo)
        classLayout.setAlignment(Qt.AlignLeft)
        mainLayout.addLayout(classLayout)
        mainLayout.addSpacing(width / 50)
        mainLayout.addStretch(0)
        mainLayout.addLayout(exitLayout)
        mainLayout.setAlignment(Qt.AlignHCenter)

        # second layout for exiting cleanly
        exitLayout.addWidget(self.okButton)
        exitLayout.addWidget(self.cancelButton)
        exitLayout.setAlignment(Qt.AlignRight)

        # Stylesheets!!!!!!
        labelStyle = """
            padding: 2%;
            text-align: left;
            color: gray;
            font-size: 14px;
            border-radius: 3px;
            font:helvetica;
        """
        cacheLable.setStyleSheet(labelStyle)
        genreLable.setStyleSheet(labelStyle)
        classifierLable.setStyleSheet(labelStyle)

        buttonStyle = """
            border: .5px solid balck;
            color: gray;
            font-size: 12px;
            font:helvetica;
            border-radius: 3px;
            
        """
        self.okButton.setStyleSheet(buttonStyle)
        self.cancelButton.setStyleSheet(buttonStyle)
        self.cacheButton.setStyleSheet(buttonStyle)

        self.classifierCombo.setStyleSheet("""
            QComboBox{background-color: rgb(33,33,33); color:gray; border:.5px solid black;}
            QComboBox::item{color: gray; background-color: rgb(33,33,33);}
            QComboBox::item:selected{color: rgb(255,255,255);}
            """)

        self.genreTable.setStyleSheet("""
            QTableWidget{
                background-color: transparent;
                border: none;
            }
            QTableView{
                selection-background-color:transparent;
                selection-color:red;
                border:.5px solid black;
                color:gray;
            }
            QTableWidget::item:selected:active{
                color:red;
                background-color:transparent;
            }
            """)