Ejemplo n.º 1
0
    def load_information(self, ServerName, DatabaseName):

        # Load Tables
        self.FoobarDB = AppDB(Server(ServerName).connect_to(DatabaseName))

        self.tblArtists = self.FoobarDB.load_table('tblArtists')
        self.tblAlbums = self.FoobarDB.load_table('tblAlbums')
        self.tblSongs = self.FoobarDB.load_table('tblSongs')
        self.tblArtistsSongs = self.FoobarDB.load_table('tblArtistsSongs')

        # Text indicators
        self.Online_QLabel.setText("The database is online.")
        self.Artists_QLabel.setText(f"There are {self.tblArtists.count_records()} artists in the database.")
        self.Albums_QLablel.setText(f"There are {self.tblAlbums.count_records()} albums in the database.")
        self.Songs_QLabel.setText(f"There are {self.tblSongs.count_records()} songs in the database.")
        self.SongsArtists_QLabel.setText(f"There are {self.tblArtistsSongs.count_records()} pairs of songs-artists data in the database.")

        # Table data
        CommonArtists_DataFrame = pd.read_sql('SELECT * FROM viewMostAppArtists ORDER BY Appearances DESC', self.FoobarDB.Connection)
        self.Model = Model(CommonArtists_DataFrame.iloc[:, :5])
        self.QTableView.setModel(self.Model)
        self.QTableView.resizeColumnsToContents()
        self.QTableView.setColumnWidth(1, 180)
        self.QTableView.resizeRowsToContents()

        # Comboboxes
        self.Genre_QComboBox.addItems(self.tblArtists.get_genre_list())
        self.Type_QComboBox.addItems(self.tblArtists.get_type_list())
        self.Sex_QComboBox.addItems(self.tblArtists.get_sex_list())

        # Status Bar
        self.QStatusBar.showMessage(f'Last Update: {self.FoobarDB.get_last_scrape()}')
Ejemplo n.º 2
0
 def viewDialog_onUpdate():
     self.Model = Model(ui.df)
     self.QTableView.setModel(self.Model)
     self.QTableView.resizeColumnsToContents()
     self.QTableView.resizeRowsToContents()
     self.Genre_QComboBox.setEnabled(False)
     self.Type_QComboBox.setEnabled(False)
     self.Sex_QComboBox.setEnabled(False)
     self.Update_QPushButton.setEnabled(False)
Ejemplo n.º 3
0
    def FindDupes_QAction_onFinish(self):

        # Change the table view
        self.Model = Model(self.Duplicates_Thread.df)
        self.QTableView.setModel(self.Model)
        self.QTableView.resizeColumnsToContents()
        self.QTableView.resizeRowsToContents()

        self.FindDupes_QAction_onUpdate(0)
        self.Update_QPushButton.setText("Not Duplicate")
        self.Update_QPushButton.setEnabled(True)
Ejemplo n.º 4
0
 def Albums_QLineEdit_OnTextChanged(self, Text):
     Albums_Model = Model(
         pd.read_sql(
             f"SELECT tblArtists.Artist, tblAlbums.Album, IIF(tRaw.Locked = 0, 'Unlocked', 'Locked') AS [Status] FROM tblAlbums INNER JOIN tblArtists ON tblArtists.ID = tblAlbums.Artist_ID INNER JOIN (SELECT tblRaw.AlbumArtist, tblRaw.Album, tblRaw.Locked FROM tblRaw GROUP BY AlbumArtist, Album, Locked) AS tRaw ON tRaw.AlbumArtist = tblArtists.Artist AND tRaw.Album = tblAlbums.Album WHERE tblAlbums.Album LIKE '%{Text}%'",
             self.Connection))
     self.Album_QTableView.setModel(Albums_Model)
     self.Album_QTableView.resizeRowsToContents()
Ejemplo n.º 5
0
 def Artists_QLineEdit_OnTextChanged(self, Text):
     Artists_Model = Model(
         pd.read_sql(
             f"SELECT tblArtists.ID, tblArtists.Artist FROM tblArtists INNER JOIN tblAlbums ON tblAlbums.Artist_ID = tblArtists.ID WHERE tblArtists.Artist LIKE '%{Text}%' GROUP BY tblArtists.ID, tblArtists.Artist",
             self.Connection))
     self.Artists_QTableView.setModel(Artists_Model)
     self.Artists_QTableView.resizeRowsToContents()
Ejemplo n.º 6
0
 def RefreshTableView(self):
     df = pd.read_sql(
         'SELECT CAST(TimeStamp AS DATE) AS TimeStamp, Operation, Value FROM viewLastLogs',
         self.db.Connection)
     Log_Model = Model(df)
     self.QTableView.setModel(Log_Model)
     self.QTableView.resizeColumnsToContents()
     self.QTableView.resizeRowsToContents()
Ejemplo n.º 7
0
 def Artists_QTableView_OnItemClicked(self, ModelIndex):
     ArtistID_String = self.Artists_QTableView.model().index(
         ModelIndex.row(), 0).data()
     Albums_Model = Model(
         pd.read_sql(
             f"SELECT tblArtists.Artist, tblAlbums.Album, IIF(tRaw.Locked = 0, 'Unlocked', 'Locked') AS [Status] FROM tblAlbums INNER JOIN tblArtists ON tblArtists.ID = tblAlbums.Artist_ID INNER JOIN (SELECT tblRaw.AlbumArtist, tblRaw.Album, tblRaw.Locked FROM tblRaw GROUP BY AlbumArtist, Album, Locked) AS tRaw ON tRaw.AlbumArtist = tblArtists.Artist AND tRaw.Album = tblAlbums.Album WHERE tblArtists.ID = {ArtistID_String}",
             self.Connection))
     self.Album_QTableView.setModel(Albums_Model)
     self.Album_QTableView.resizeRowsToContents()
Ejemplo n.º 8
0
 def Change_QPushButton_OnClick(self):
     SelectedIndex_QModelIndex = self.Album_QTableView.selectedIndexes()[0]
     AlbumArtist_String = self.Album_QTableView.model().index(
         SelectedIndex_QModelIndex.row(), 0).data()
     AlbumName_String = self.Album_QTableView.model().index(
         SelectedIndex_QModelIndex.row(), 1).data()
     Metadata = MetaData(self.Connection)
     Raw_Table = Table('tblRaw', Metadata, autoload=True)
     UpdateQuery_String = sql.update(Raw_Table).where(
         Raw_Table.c.AlbumArtist == AlbumArtist_String).where(
             Raw_Table.c.Album == AlbumName_String).values(Locked=1)
     self.Connection.execute(UpdateQuery_String)
     QMessageBox = QtWidgets.QMessageBox()
     QMessageBox.setText(
         "Records have been locked.\nDo you want to delete its corresponding folder too?"
     )
     QMessageBox.setIcon(QtWidgets.QMessageBox.Question)
     QMessageBox.setStandardButtons(QtWidgets.QMessageBox.Yes
                                    | QtWidgets.QMessageBox.No)
     QMessageBox.setWindowTitle('Delete folder')
     QMessageBox.setWindowIcon(
         QtGui.QIcon(
             path.join(path.dirname(self.CurrentPath_String),
                       'fobalisis.ico')))
     response = QMessageBox.exec_()
     if response == QtWidgets.QMessageBox.Yes:
         Folder_String = QtWidgets.QFileDialog.getExistingDirectory()
         shutil.rmtree(Folder_String)
         QMessageBox = QtWidgets.QMessageBox()
         QMessageBox.setText("Folder deleted.")
         QMessageBox.setIcon(QtWidgets.QMessageBox.Information)
         QMessageBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
         QMessageBox.setWindowTitle('Done')
         QMessageBox.setWindowIcon(
             QtGui.QIcon(
                 path.join(path.dirname(self.CurrentPath_String),
                           'fobalisis.ico')))
         QMessageBox.exec_()
         Albums_Model = Model(
             pd.read_sql(
                 "SELECT tblArtists.Artist, tblAlbums.Album, IIF(tRaw.Locked = 0, 'Unlocked', 'Locked') AS [Status] FROM tblAlbums INNER JOIN tblArtists ON tblArtists.ID = tblAlbums.Artist_ID INNER JOIN (SELECT tblRaw.AlbumArtist, tblRaw.Album, tblRaw.Locked FROM tblRaw GROUP BY AlbumArtist, Album, Locked) AS tRaw ON tRaw.AlbumArtist = tblArtists.Artist AND tRaw.Album = tblAlbums.Album",
                 self.Connection))
         self.Album_QTableView.setModel(Albums_Model)
Ejemplo n.º 9
0
    def Save_QPushButton_onButtonClick(self):

        strJSONFile = path.join(self.ThisFilePath_String, 'Views.txt')

        with open(strJSONFile, 'r') as File:
            JSON_Dictionary = json.load(File)

        JSON_Dictionary[self.Title_QLineEdit.text(
        )] = self.Definition_QPlainTextEdit.toPlainText()

        with open(strJSONFile, 'w') as File:
            json.dump(JSON_Dictionary, File)

        self.Views_Dataframe = pd.DataFrame.from_dict(JSON_Dictionary,
                                                      orient='index',
                                                      columns=['Definition'])
        self.Views_Dataframe.reset_index(inplace=True)
        View_Model = Model(self.Views_Dataframe)
        self.QListView.setModel(View_Model)
Ejemplo n.º 10
0
    def Remove_QPushButton_onButtonClick(self):

        SelectedElement_String = self.QListView.model().index(
            self.QListView.currentIndex().row(), 0).data()
        JSONFilePath_String = path.join(self.ThisFilePath_String, 'Views.txt')

        with open(JSONFilePath_String, 'r') as File:
            JSON_Dictionary = json.load(File)

        del JSON_Dictionary[SelectedElement_String]

        with open(JSONFilePath_String, 'w') as File:
            json.dump(JSON_Dictionary, File)

        self.Views_Dataframe = pd.DataFrame.from_dict(JSON_Dictionary,
                                                      orient='index',
                                                      columns=['Definition'])
        self.Views_Dataframe.reset_index(inplace=True)
        View_Model = Model(self.Views_Dataframe)
        self.QListView.setModel(View_Model)
Ejemplo n.º 11
0
    def setupUi(self, Dialog, FoobarDB):

        self.Connection = FoobarDB.Connection

        Dialog.setObjectName("Dialog")
        Dialog.setFixedSize(692, 304)
        Dialog.setWindowTitle("Lock/Unlocking Albums")
        Dialog.setWindowIcon(
            QtGui.QIcon(
                path.join(path.dirname(self.CurrentPath_String),
                          'fobalisis.ico')))

        Artists_QLabel = QtWidgets.QLabel(Dialog)
        Artists_QLabel.setGeometry(QtCore.QRect(20, 20, 321, 16))
        Artists_QLabel.setAlignment(QtCore.Qt.AlignCenter)
        Artists_QLabel.setObjectName("Artists_QLabel")
        Artists_QLabel.setText("Artists")

        Albums_QLabel = QtWidgets.QLabel(Dialog)
        Albums_QLabel.setGeometry(QtCore.QRect(350, 20, 321, 16))
        Albums_QLabel.setAlignment(QtCore.Qt.AlignCenter)
        Albums_QLabel.setObjectName("Albums_QLabel")
        Albums_QLabel.setText("Albums")

        Artists_Model = Model(
            pd.read_sql(
                'SELECT tblArtists.ID, tblArtists.Artist FROM tblArtists INNER JOIN tblAlbums ON tblAlbums.Artist_ID = tblArtists.ID GROUP BY tblArtists.ID, tblArtists.Artist',
                FoobarDB.Connection))
        self.Artists_QTableView = QtWidgets.QTableView(Dialog)
        self.Artists_QTableView.setGeometry(QtCore.QRect(20, 70, 321, 192))
        self.Artists_QTableView.setObjectName("Artists_QTableView")
        self.Artists_QTableView.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.Artists_QTableView.setModel(Artists_Model)
        self.Artists_QTableView.setColumnHidden(0, True)
        self.Artists_QTableView.setColumnWidth(1, 270)
        self.Artists_QTableView.resizeRowsToContents()
        self.Artists_QTableView.clicked.connect(
            self.Artists_QTableView_OnItemClicked)

        Albums_Model = Model(
            pd.read_sql(
                "SELECT tblArtists.Artist, tblAlbums.Album, IIF(tRaw.Locked = 0, 'Unlocked', 'Locked') AS [Status] FROM tblAlbums INNER JOIN tblArtists ON tblArtists.ID = tblAlbums.Artist_ID INNER JOIN (SELECT tblRaw.AlbumArtist, tblRaw.Album, tblRaw.Locked FROM tblRaw GROUP BY AlbumArtist, Album, Locked) AS tRaw ON tRaw.AlbumArtist = tblArtists.Artist AND tRaw.Album = tblAlbums.Album",
                self.Connection))
        self.Album_QTableView = QtWidgets.QTableView(Dialog)
        self.Album_QTableView.setGeometry(QtCore.QRect(350, 70, 321, 192))
        self.Album_QTableView.setObjectName("Album_QTableView")
        self.Album_QTableView.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.Album_QTableView.setModel(Albums_Model)
        self.Album_QTableView.setColumnHidden(0, True)
        self.Album_QTableView.setColumnWidth(1, 203)
        self.Album_QTableView.setColumnWidth(2, 60)
        self.Album_QTableView.resizeRowsToContents()

        Artists_QLineEdit = QtWidgets.QLineEdit(Dialog)
        Artists_QLineEdit.setGeometry(QtCore.QRect(20, 50, 321, 20))
        Artists_QLineEdit.setObjectName("Artists_QLineEdit")
        Artists_QLineEdit.textChanged.connect(
            self.Artists_QLineEdit_OnTextChanged)

        self.Albums_QLineEdit = QtWidgets.QLineEdit(Dialog)
        self.Albums_QLineEdit.setGeometry(QtCore.QRect(350, 50, 321, 20))
        self.Albums_QLineEdit.setObjectName("Albums_QLineEdit")
        self.Albums_QLineEdit.textChanged.connect(
            self.Albums_QLineEdit_OnTextChanged)

        Change_QPushButton = QtWidgets.QPushButton(Dialog)
        Change_QPushButton.setGeometry(QtCore.QRect(590, 270, 75, 23))
        Change_QPushButton.setObjectName("Change_QPushButton")
        Change_QPushButton.setText("Lock")
        Change_QPushButton.clicked.connect(self.Change_QPushButton_OnClick)

        QtCore.QMetaObject.connectSlotsByName(Dialog)
Ejemplo n.º 12
0
class Ui_MainWindow(object):

    def setupUi(self, MainWindow):

        self.ThisFilePath_String = path.dirname(__file__)

        # Window
        MainWindow.setObjectName("MainWindow")
        MainWindow.setFixedSize(541, 539)
        MainWindow.setWindowTitle("Musica")
        MainWindow.setWindowIcon(QtGui.QIcon(path.join(self.ThisFilePath_String, 'fobalisis.ico')))
        self.CentralWidget = QtWidgets.QWidget(MainWindow)
        self.CentralWidget.setObjectName("CentralWidget")
        MainWindow.setCentralWidget(self.CentralWidget)

        # Set up menubar
        QMenuBar = QtWidgets.QMenuBar(MainWindow)
        QMenuBar.setGeometry(QtCore.QRect(0, 0, 541, 21))
        QMenuBar.setObjectName("QMenuBar")
        MainWindow.setMenuBar(QMenuBar)

        # Add menus to the menubar
        Interactions_QMenu = QtWidgets.QMenu(QMenuBar)
        Interactions_QMenu.setObjectName("Interactions_QMenu")
        Interactions_QMenu.setTitle("Interactions")
        QMenuBar.addAction(Interactions_QMenu.menuAction())

        View_QMenu = QtWidgets.QMenu(QMenuBar)
        View_QMenu.setObjectName("View_QMenu")
        View_QMenu.setTitle("View")
        QMenuBar.addAction(View_QMenu.menuAction())

        Tools_QMenu = QtWidgets.QMenu(QMenuBar)
        Tools_QMenu.setObjectName("Tools_QMenu")
        Tools_QMenu.setTitle("Tools")
        QMenuBar.addAction(Tools_QMenu.menuAction())

        # Generate CSV button config
        Scrape_QAction = QtWidgets.QAction(MainWindow)
        Scrape_QAction.setObjectName("Scrape_QAction")
        Scrape_QAction.setText("Scrape Data")
        Scrape_QAction.triggered.connect(self.Scrape_QAction_onButtonClick)

        # Video player button config
        self.PlayVideo_QAction = QtWidgets.QAction(MainWindow)
        self.PlayVideo_QAction.setObjectName("PlayVideo_QAction")
        self.PlayVideo_QAction.setText("Enable Video Player")
        self.VideoPlaying_Boolean = False
        self.PlayVideo_QAction.triggered.connect(self.PlayVideo_QAction_onButtonClick)

        # Open dash button config
        OpenDashboard_QAction = QtWidgets.QAction(MainWindow)
        OpenDashboard_QAction.setObjectName("OpenDashboard_QAction")
        OpenDashboard_QAction.setText("Open Music Dashboard")
        OpenDashboard_QAction.triggered.connect(self.OpenDashboard_QAction_onButtonClick)

        # Run command button config
        RunCMD_QAction = QtWidgets.QAction(MainWindow)
        RunCMD_QAction.setObjectName("RunCMD_QAction")
        RunCMD_QAction.setText("Run Command...")
        RunCMD_QAction.triggered.connect(self.RunCMD_QAction_onButtonClick)

        # Find dupes button config
        self.FindDupes_QAction = QtWidgets.QAction(MainWindow)
        self.FindDupes_QAction.setObjectName("FindDupes_QAction")
        self.FindDupes_QAction.setText("Potential Duplicates")
        self.FindDupes_QAction.triggered.connect(self.FindDupes_QAction_onButtonClick)

        # Custom View button config
        CustomView_QAction = QtWidgets.QAction(MainWindow)
        CustomView_QAction.setObjectName("CustomView_QAction")
        CustomView_QAction.setText("Custom View...")
        CustomView_QAction.triggered.connect(self.CustomView_QAction_onButtonClick)

        # Locks button config
        Lock_QAction = QtWidgets.QAction(MainWindow)
        Lock_QAction.setObjectName("Lock_QAction")
        Lock_QAction.setText("Lock albums")
        Lock_QAction.triggered.connect(self.Lock_QAction_onButtonClick)

        # Add buttons to the Interactions menu
        Interactions_QMenu.addAction(Scrape_QAction)
        Interactions_QMenu.addAction(self.PlayVideo_QAction)
        Interactions_QMenu.addAction(OpenDashboard_QAction)
        Interactions_QMenu.addAction(RunCMD_QAction)

        # Add buttons to the View menu
        View_QMenu.addAction(self.FindDupes_QAction)
        View_QMenu.addAction(CustomView_QAction)

        # Add button to the Tool menu
        Tools_QMenu.addAction(Lock_QAction)

        # Database frame
        MusicDatabase_QGroupBox = QtWidgets.QGroupBox(self.CentralWidget)
        MusicDatabase_QGroupBox.setGeometry(QtCore.QRect(30, 10, 481, 131))
        MusicDatabase_QGroupBox.setObjectName("MusicDatabase_QGroupBox")
        MusicDatabase_QGroupBox.setTitle("Music Database")

        # Online label
        self.Online_QLabel = QtWidgets.QLabel(MusicDatabase_QGroupBox)
        self.Online_QLabel.setGeometry(QtCore.QRect(10, 20, 121, 21))
        self.Online_QLabel.setObjectName("Online_QLabel")
        self.Online_QLabel.setText("The database is offline.")

        # Artist label
        self.Artists_QLabel = QtWidgets.QLabel(MusicDatabase_QGroupBox)
        self.Artists_QLabel.setGeometry(QtCore.QRect(10, 40, 191, 21))
        self.Artists_QLabel.setObjectName("Artists_QLabel")

        # Album label
        self.Albums_QLablel = QtWidgets.QLabel(MusicDatabase_QGroupBox)
        self.Albums_QLablel.setGeometry(QtCore.QRect(10, 60, 191, 21))
        self.Albums_QLablel.setObjectName("Albums_QLablel")

        # Song label
        self.Songs_QLabel = QtWidgets.QLabel(MusicDatabase_QGroupBox)
        self.Songs_QLabel.setGeometry(QtCore.QRect(10, 80, 191, 21))
        self.Songs_QLabel.setObjectName("Songs_QLabel")

        # SongArtist label
        self.SongsArtists_QLabel = QtWidgets.QLabel(MusicDatabase_QGroupBox)
        self.SongsArtists_QLabel.setGeometry(QtCore.QRect(10, 100, 291, 21))
        self.SongsArtists_QLabel.setObjectName("SongsArtists_QLabel")

        # Progress bar
        self.QProgressBar = QtWidgets.QProgressBar(self.CentralWidget)
        self.QProgressBar.setObjectName("QProgressBar")
        self.QProgressBar.setGeometry(QtCore.QRect(30, 150, 481, 23))
        self.QProgressBar.setProperty("value", 0)
        self.QProgressBar.setMaximum(26)

        # Grid
        self.QTableView = QtWidgets.QTableView(self.CentralWidget)
        self.QTableView.setEnabled(True)
        self.QTableView.setGeometry(QtCore.QRect(20, 180, 501, 271))
        self.QTableView.setObjectName("QTableView")

        # Layout for all the CMBs
        Layout_QWidget = QtWidgets.QWidget(self.CentralWidget)
        Layout_QWidget.setGeometry(QtCore.QRect(30, 460, 481, 25))
        Layout_QWidget.setObjectName("Layout_QWidget")
        Layout_QHBoxLayout = QtWidgets.QHBoxLayout(Layout_QWidget)
        Layout_QHBoxLayout.setContentsMargins(0, 0, 0, 0)
        Layout_QHBoxLayout.setObjectName("Layout_QHBoxLayout")

        # Comboboxes and update button
        self.Genre_QComboBox = QtWidgets.QComboBox(self.CentralWidget)
        self.Genre_QComboBox.setObjectName("Genre_QComboBox")
        Layout_QHBoxLayout.addWidget(self.Genre_QComboBox)
        
        self.Type_QComboBox = QtWidgets.QComboBox(self.CentralWidget)
        self.Type_QComboBox.setObjectName("Type_QComboBox")
        Layout_QHBoxLayout.addWidget(self.Type_QComboBox)

        self.Sex_QComboBox = QtWidgets.QComboBox(self.CentralWidget)
        self.Sex_QComboBox.setObjectName("Sex_QComboBox")
        Layout_QHBoxLayout.addWidget(self.Sex_QComboBox)

        self.Update_QPushButton = QtWidgets.QPushButton(self.CentralWidget)
        self.Update_QPushButton.setObjectName("Update_QPushButton")
        self.Update_QPushButton.setText("Update")
        self.Update_QPushButton.clicked.connect(self.Update_QPushButton_onButtonClick)
        Layout_QHBoxLayout.addWidget(self.Update_QPushButton)

        # Status bar config and installation
        self.QStatusBar = QtWidgets.QStatusBar(MainWindow)
        self.QStatusBar.setObjectName("QStatusBar")
        MainWindow.setStatusBar(self.QStatusBar)

        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        # Open QLogin and hide this one
        self.open_qlogin()
    
    def Scrape_QAction_onButtonClick(self):
        QDialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(QDialog, self.FoobarDB)
        QDialog.show()
        QDialog.exec_()

    def PlayVideo_QAction_onButtonClick(self):
        if self.VideoPlaying_Boolean:
            self.Player_QThread.terminate()
            self.VideoPlaying_Boolean = False
            self.PlayVideo_QAction.setText("Enable Video Player")
        elif not self.VideoPlaying_Boolean:
            self.Player_QThread = VideoPlayer_QThread()
            self.Player_QThread.start()
            self.VideoPlaying_Boolean = True
            self.PlayVideo_QAction.setText("Disable Video Player")

    def OpenDashboard_QAction_onButtonClick(self):
        startfile(path.join(self.ThisFilePath_String, 'FoobalysisBI4.pbix'))

    def RunCMD_QAction_onButtonClick(self):
        sqlDialog = QtWidgets.QDialog()
        ui = Ui_sqlDialog()
        ui.setupUi(sqlDialog, self.FoobarDB)
        sqlDialog.show()
        sqlDialog.exec_()

    def FindDupes_QAction_onButtonClick(self):
        self.Duplicates_Thread = DuplicateFinder_QThread(self.FoobarDB)
        self.Duplicates_Thread.CountChanged_pyqtSignal.connect(self.FindDupes_QAction_onUpdate)
        self.Duplicates_Thread.Finished_pyqtSignal.connect(self.FindDupes_QAction_onFinish)
        self.Duplicates_Thread.start()
        self.FindDupes_QAction.setText("Show All")
        self.Genre_QComboBox.setEnabled(False)
        self.Type_QComboBox.setEnabled(False)
        self.Sex_QComboBox.setEnabled(False)
        self.Update_QPushButton.setEnabled(False)

    def FindDupes_QAction_onUpdate(self, Value):
        self.QProgressBar.setValue(Value)

    def FindDupes_QAction_onFinish(self):

        # Change the table view
        self.Model = Model(self.Duplicates_Thread.df)
        self.QTableView.setModel(self.Model)
        self.QTableView.resizeColumnsToContents()
        self.QTableView.resizeRowsToContents()

        self.FindDupes_QAction_onUpdate(0)
        self.Update_QPushButton.setText("Not Duplicate")
        self.Update_QPushButton.setEnabled(True)

    def CustomView_QAction_onButtonClick(self):
        
        def viewDialog_onUpdate():
            self.Model = Model(ui.df)
            self.QTableView.setModel(self.Model)
            self.QTableView.resizeColumnsToContents()
            self.QTableView.resizeRowsToContents()
            self.Genre_QComboBox.setEnabled(False)
            self.Type_QComboBox.setEnabled(False)
            self.Sex_QComboBox.setEnabled(False)
            self.Update_QPushButton.setEnabled(False)
        
        viewDialog = QtWidgets.QDialog()
        ui = Ui_viewsDialog()
        ui.setupUi(viewDialog, self.FoobarDB, self.ThisFilePath_String)
        ui.SQLstatement.connect(viewDialog_onUpdate)
        viewDialog.show()
        viewDialog.exec_()

    def Lock_QAction_onButtonClick(self):
        lockDialog = QtWidgets.QDialog()
        ui = Ui_LockDialog()
        ui.setupUi(lockDialog, self.FoobarDB)
        lockDialog.show()
        lockDialog.exec_()

    def Update_QPushButton_onButtonClick(self):

        def get_selected_IDs():
            Indexes_List = self.QTableView.selectedIndexes()
            Rows_List = [Index.row() for Index in Indexes_List]
            Rows_List = list( set( Rows_List ) )
            IDs_List = [self.QTableView.model().index(Row, 0).data() for Row in Rows_List]
            return (IDs_List, Rows_List)
        
        def show_popup(number_of_updates):
            MsgBox_QMessageBox = QtWidgets.QMessageBox()
            MsgBox_QMessageBox.setWindowTitle('Update')
            MsgBox_QMessageBox.setWindowIcon(QtGui.QIcon(path.join(self.ThisFilePath_String, 'foobalisis.ico')))
            MsgBox_QMessageBox.setText(f'{number_of_updates} record(s) have been updated correctly.')
            MsgBox_QMessageBox.setIcon(QtWidgets.QMessageBox.Information)
            MsgBox_QMessageBox.exec_()

        def update_model(lstRows, Genre, Type, Sex):
            for row in lstRows:
                self.Model.setData(self.QTableView.model().index(row, 2), Genre)
                self.Model.setData(self.QTableView.model().index(row, 3), Type)
                self.Model.setData(self.QTableView.model().index(row, 4), Sex)

        lstIDs, lstRows = get_selected_IDs()
        if len(lstRows) > 0:
            if self.Update_QPushButton.text() == "Update":
                    self.tblArtists.bulk_artist_update( lstIDs, self.Genre_QComboBox.currentText(), self.Type_QComboBox.currentText(), self.Sex_QComboBox.currentText() )
                    show_popup(len(lstIDs))
                    update_model(lstRows, self.Genre_QComboBox.currentText(), self.Type_QComboBox.currentText(), self.Sex_QComboBox.currentText())
            elif self.Update_QPushButton.text() == "Not Duplicate":
                lstArtists = [self.QTableView.model().index(row, 1).data() for row in lstRows]
                lstDuplicates = [self.QTableView.model().index(row, 2).data() for row in lstRows]
                strPathFile = path.join(self.ThisFilePath_String, 'NotDuplicates.csv')
                with open(strPathFile, 'a', encoding='utf-8') as f:
                    dupe_writer = csv.writer(f, delimiter=',', quotechar='"', lineterminator='\n')
                    for x in range(len(lstArtists)):
                        dupe_writer.writerow([lstArtists[x], lstDuplicates[x]])
                    show_popup(len(lstRows))
                    self.Model.drop_ids(lstIDs)
    
    def open_qlogin(self):

        def QLogin_OnUpdate():
            self.load_information(self.ui.Server_String, self.ui.Database_String)

        QDialog = QtWidgets.QDialog()
        self.ui = Ui_EntryWindow()
        self.ui.setupUi(QDialog)
        self.ui.LoadData_pyqtSignal.connect(QLogin_OnUpdate)
        QDialog.show()
        QDialog.exec_()

    def load_information(self, ServerName, DatabaseName):

        # Load Tables
        self.FoobarDB = AppDB(Server(ServerName).connect_to(DatabaseName))

        self.tblArtists = self.FoobarDB.load_table('tblArtists')
        self.tblAlbums = self.FoobarDB.load_table('tblAlbums')
        self.tblSongs = self.FoobarDB.load_table('tblSongs')
        self.tblArtistsSongs = self.FoobarDB.load_table('tblArtistsSongs')

        # Text indicators
        self.Online_QLabel.setText("The database is online.")
        self.Artists_QLabel.setText(f"There are {self.tblArtists.count_records()} artists in the database.")
        self.Albums_QLablel.setText(f"There are {self.tblAlbums.count_records()} albums in the database.")
        self.Songs_QLabel.setText(f"There are {self.tblSongs.count_records()} songs in the database.")
        self.SongsArtists_QLabel.setText(f"There are {self.tblArtistsSongs.count_records()} pairs of songs-artists data in the database.")

        # Table data
        CommonArtists_DataFrame = pd.read_sql('SELECT * FROM viewMostAppArtists ORDER BY Appearances DESC', self.FoobarDB.Connection)
        self.Model = Model(CommonArtists_DataFrame.iloc[:, :5])
        self.QTableView.setModel(self.Model)
        self.QTableView.resizeColumnsToContents()
        self.QTableView.setColumnWidth(1, 180)
        self.QTableView.resizeRowsToContents()

        # Comboboxes
        self.Genre_QComboBox.addItems(self.tblArtists.get_genre_list())
        self.Type_QComboBox.addItems(self.tblArtists.get_type_list())
        self.Sex_QComboBox.addItems(self.tblArtists.get_sex_list())

        # Status Bar
        self.QStatusBar.showMessage(f'Last Update: {self.FoobarDB.get_last_scrape()}')
Ejemplo n.º 13
0
    def setupUi(self, viewsDialog, MusicDB, ThisFilePath):

        self.MusicDB = MusicDB
        self.ThisFilePath_String = ThisFilePath

        # Dialog window
        viewsDialog.setObjectName("viewsDialog")
        viewsDialog.setFixedSize(615, 384)
        viewsDialog.setWindowTitle("Custom Views")
        viewsDialog.setWindowIcon(
            QtGui.QIcon(path.join(self.ThisFilePath_String, 'fobalisis.ico')))

        # Label views
        Views_QLabel = QtWidgets.QLabel(viewsDialog)
        Views_QLabel.setGeometry(QtCore.QRect(130, 10, 30, 13))
        Views_QLabel.setObjectName("Views_QLabel")
        Views_QLabel.setText("Views")

        # List of views
        self.QListView = QtWidgets.QListView(viewsDialog)
        self.QListView.setGeometry(QtCore.QRect(20, 30, 256, 311))
        self.QListView.setObjectName("QListView")
        with open(path.join(self.ThisFilePath_String, 'Views.txt'),
                  'r') as File:
            JSON_Dictionary = json.load(File)
        self.Views_Dataframe = pd.DataFrame.from_dict(JSON_Dictionary,
                                                      orient='index',
                                                      columns=['Definition'])
        self.Views_Dataframe.reset_index(inplace=True)
        self.View_Model = Model(self.Views_Dataframe)
        self.QListView.setModel(self.View_Model)

        # Lable title
        Title_QLabel = QtWidgets.QLabel(viewsDialog)
        Title_QLabel.setGeometry(QtCore.QRect(290, 10, 31, 16))
        Title_QLabel.setObjectName("Title_QLabel")
        Title_QLabel.setText("Title:")

        # Title dialog box
        self.Title_QLineEdit = QtWidgets.QLineEdit(viewsDialog)
        self.Title_QLineEdit.setGeometry(QtCore.QRect(290, 30, 311, 20))
        self.Title_QLineEdit.setObjectName("Title_QLineEdit")

        # Label definition
        Definition_QLabel = QtWidgets.QLabel(viewsDialog)
        Definition_QLabel.setGeometry(QtCore.QRect(290, 60, 61, 16))
        Definition_QLabel.setObjectName("Definition_QLabel")
        Definition_QLabel.setText("Definition:")

        # Text Definition
        self.Definition_QPlainTextEdit = QtWidgets.QPlainTextEdit(viewsDialog)
        self.Definition_QPlainTextEdit.setGeometry(
            QtCore.QRect(290, 80, 311, 261))
        self.Definition_QPlainTextEdit.setObjectName(
            "Definition_QPlainTextEdit")

        # Buttons
        self.Remove_QPushButton = QtWidgets.QPushButton(viewsDialog)
        self.Remove_QPushButton.setObjectName("Remove_QPushButton")
        self.Remove_QPushButton.setGeometry(QtCore.QRect(25, 350, 75, 23))
        self.Remove_QPushButton.setText("Remove")
        self.Remove_QPushButton.clicked.connect(
            self.Remove_QPushButton_onButtonClick)
        self.Load_QPushButton = QtWidgets.QPushButton(viewsDialog)
        self.Load_QPushButton.setGeometry(QtCore.QRect(195, 350, 75, 23))
        self.Load_QPushButton.setObjectName("Load_QPushButton")
        self.Load_QPushButton.setText("Load")
        self.Load_QPushButton.clicked.connect(
            self.Load_QPushButton_onButtonClick)
        self.Save_QPushButton = QtWidgets.QPushButton(viewsDialog)
        self.Save_QPushButton.setGeometry(QtCore.QRect(360, 350, 75, 23))
        self.Save_QPushButton.setObjectName("Save_QPushButton")
        self.Save_QPushButton.setText("Save")
        self.Save_QPushButton.clicked.connect(
            self.Save_QPushButton_onButtonClick)
        self.Apply_QPushButton = QtWidgets.QPushButton(viewsDialog)
        self.Apply_QPushButton.setGeometry(QtCore.QRect(440, 350, 75, 23))
        self.Apply_QPushButton.setObjectName("Apply_QPushButton")
        self.Apply_QPushButton.setText("Apply")
        self.Apply_QPushButton.clicked.connect(
            self.Apply_QPushButton_onButtonClick)
        self.Close_QPushButton = QtWidgets.QPushButton(viewsDialog)
        self.Close_QPushButton.setGeometry(QtCore.QRect(520, 350, 75, 23))
        self.Close_QPushButton.setObjectName("Close_QPushButton")
        self.Close_QPushButton.setText("Close")
        self.Close_QPushButton.clicked.connect(viewsDialog.close)

        QtCore.QMetaObject.connectSlotsByName(viewsDialog)