Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create albums_statistics.py #384

Open
wants to merge 9 commits into
base: 2.0
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions plugins/albums_statistics/albums_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
PLUGIN_NAME = "Albums Statistics"
PLUGIN_AUTHOR = "Echelon"
PLUGIN_VERSION = '0.1'
PLUGIN_API_VERSIONS = ['2.2']
PLUGIN_LICENSE = "GPL-2.0-or-later"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html"
PLUGIN_DESCRIPTION = '''Counts the quality or status of albums.

A - An integer variable counting albums Incomplete & unchanged,
B - An integer variable counting albums Incomplete & modified,
C - An integer variable counting albums Complete & unchanged,
D - An integer variable counting albums Complete & modified,
E - An integer variable counting albums Errored,
T - An integer variable summing up the above variables'''

from PyQt5.QtWidgets import QLabel, QGridLayout, QWidget
from PyQt5.QtGui import QPixmap, QIcon

from picard.ui.itemviews import BaseAction, register_album_action

statwindow = QWidget()
grid = QGridLayout()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to put this into it's own class. Something like this:

class AlbumStatsDialog(QWidget):
    def __init__(self, albums):
        grid = QGridLayout()
        self.setLayout(grid)
        self.setGeometry(100, 100, 400, 200)
        self.setWindowTitle("Albums Statistics")
        # The full code to setup the UI goes here

Then this can be used in the callback function:

window = AlbumStatsDialog(objs)
window.show()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phw Philipp See my previous rewrite of this code that I made to try to help Peter - I put all the code inside the class, but I suspect that the above comment is still a useful enhancement to my version..


statwindow.setLayout(grid)
statwindow.setGeometry(100, 100, 400, 200)
statwindow.setWindowTitle("Albums Statistics")
statwindow.setWindowIcon(QIcon(":/images/16x16/org.musicbrainz.Picard.png"))
statwindow.setStyleSheet("font-size:12pt;")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually avoid hard coding font sizes so Qt uses system defaults.


class AlbumStats(BaseAction):
NAME = "Statistics"

def callback(self, objs):
A = B = C = D = E = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those variables should have proper names

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now we are testing the @Sophist-UK code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - this PR still has your code in it (regardless of what code you are personally working on) - and it the code you submitted (rather than what I posted in a comment) that @phw Philipp has just taken the time and effort to review.

As for my code, you are still welcome to use it even though I think you have made it abundantly clear in the forums that you do not appreciate my help. But if you do then:

  1. You need to push a commit to your PR with my code in it; and
  2. You needed to make it clear that you were doing so earlier so that @phw didn't waste his time reviewing your older and now obsolete code. IMO Philipp deserves an abject apology from you for wasting his time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new PR from scratch?

How to name the plugin and branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwrite new code here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new PR from scratch?
No

Overwrite new code here?
Yes

Which bit about "You need to push a commit to your PR with my code in it" was unclear? Did I mention creating a new PR?


while grid.count():
item = grid.takeAt(0)
widget = item.widget()
if widget is not None:
widget.clear()

icon1 = QLabel()
icon1.setPixmap(QPixmap(":/images/22x22/media-optical.png"))
icon2 = QLabel()
icon2.setPixmap(QPixmap(":/images/22x22/media-optical-modified.png"))
icon3 = QLabel()
icon3.setPixmap(QPixmap(":/images/22x22/media-optical-saved.png"))
icon4 = QLabel()
icon4.setPixmap(QPixmap(":/images/22x22/media-optical-saved-modified.png"))
icon5 = QLabel()
icon5.setPixmap(QPixmap(":/images/22x22/media-optical-error.png"))

grid.addWidget(icon1, 1, 0)
grid.addWidget(icon2, 2, 0)
grid.addWidget(icon3, 3, 0)
grid.addWidget(icon4, 4, 0)
grid.addWidget(icon5, 5, 0)

grid.addWidget(QLabel("The status of the selected Albums is as follows:"), 0, 0, 1, 3)
grid.addWidget(QLabel("Incomplete & unchanged"), 1, 2)
grid.addWidget(QLabel("Incomplete & modified"), 2, 2)
grid.addWidget(QLabel("Complete & unchanged"), 3, 2)
grid.addWidget(QLabel("Complete & modified"), 4, 2)
grid.addWidget(QLabel("Errored"), 5, 2)
grid.addWidget(QLabel("Total"), 6, 2)

for album in objs:
if album.errors:
E = E + 1
elif album.is_complete():
if album.is_modified():
D = D + 1
else:
C = C + 1
else:
if album.is_modified():
B = B + 1
else:
A = A + 1

T = A + B + C + D + E

grid.addWidget(QLabel(str(A)), 1, 1)
grid.addWidget(QLabel(str(B)), 2, 1)
grid.addWidget(QLabel(str(C)), 3, 1)
grid.addWidget(QLabel(str(D)), 4, 1)
grid.addWidget(QLabel(str(E)), 5, 1)
grid.addWidget(QLabel(str(T)), 6, 1)

statwindow.show()

register_album_action(AlbumStats())