carlos1172 / ProgressBarTimeLeft

Hello, this is my first "add-on" (which isn't really by me since I just tweaked/merged Glutanimate's Progress Bar add-on with Carlos Duarte's More Decks Stats and Time Left add-on.). I basically got the progress bar to work on 2.1.49, as well as added statistics for cards left, percentage left, time (s) spent per card based on today's reviews, and time left based on how fast you've done today's reviews. Note: it says studied 637 cards in 1.36 hours today (7.67 s/card) but that's not reflected in the progress bar because I did those reviews on iPad. Also, the progress bar only tracts reviews in your current anki session. If you restart the app, it'll reset to 0 cards done (but the total cards left will be less already). I have not tested this on any other version besides 2.1.49, but I just wanted to share it since it took me a while to get this working and I'm very proud of it (and am hugely thankful to Glutanimate and Mr. Duarte). Installation: Unzip them and paste them in C:\%APPDATA%\Anki2\addons21
14 stars 8 forks source link

[Feature Request] ProgressBarCode #17

Open khonkhortisan opened 2 years ago

khonkhortisan commented 2 years ago

Every card you do is another line in the progress bar, in red/grey/green/blue depending on whether you answered again/hard/good/easy.

Proof of concept

imagen Control+Shift+;

class QProgressBarCode(QProgressBar):
    def __init__(self):
        QProgressBar.__init__(self)

    def setBarCodeColors(self, barcodecolors):
        self.barcodecolors = barcodecolors

    def paintEvent(self, e):
        if hasattr(self, 'barcodecolors'):
            dc = QPainter(self)
            for i, color in enumerate(reversed(self.barcodecolors)):
                dc.fillRect(0, 0, (self.value()-i) / self.maximum() * self.width(), 20, color)
            dc.drawText(0,0, self.width(), self.height(), Qt.AlignCenter, self.text());
            dc.end()
        else:
            QProgressBar.paintEvent(self, e)

self.progressBar = QProgressBarCode()
self.progressBar.setMinimumWidth(mw.size().width());
self.progressBar.setRange(0, 1000) #set to done+left

a = (mw.col.sched.day_cutoff - 86400) * 1000
reviews = mw.col.db.list("""select ease from revlog where id > ?""", a)
self.progressBar.setValue(len(reviews))
self.progressBar.setBarCodeColors([{1:QColor.fromRgbF(0.827,0.184,0.184,1), 2:QColor.fromRgbF(0.271,0.353,0.392,1), 3:QColor.fromRgbF(0.298,0.686,0.314,1), 4:QColor.fromRgbF(0.12,0.663,0.957,1)}[ease] for ease in reviews])

self.progressBar.setFormat("408 (9.47%) done     |     3900 (90.53%) left     |     12.00 (14.72) s/card     |     43.38% (33.86%) AR     |     58.16% (70.82%) TR     |     50.00% (81.82%) SMTR     |     01:21 spent     |     12:59 more     |     ETA 02:24 AM")
self.progressBar.show()

Control+enter

In the addon

imagen

diff --git a/reviewer_progress_bar-orig.py b/reviewer_progress_bar.py
index 8abd4b0..e86810b 100644
--- a/reviewer_progress_bar-orig.py
+++ b/reviewer_progress_bar.py
@@ -199,11 +199,27 @@ def add_info():

 gui_hooks.main_window_did_init.append(add_info)

+class QProgressBarCode(QProgressBar):
+    def __init__(self):
+        QProgressBar.__init__(self)
+
+    def setBarCodeColors(self, barcodecolors):
+        self.barcodecolors = barcodecolors
+
+    def paintEvent(self, e):
+        if hasattr(self, 'barcodecolors'):
+            dc = QPainter(self)
+            for i, color in enumerate(reversed(self.barcodecolors)):
+                dc.fillRect(0, 0, (self.value()-i) / self.maximum() * self.width(), self.height(), color)
+            dc.drawText(0,0, self.width(), self.height(), Qt.AlignCenter, self.text());
+            dc.end()
+        else:
+            QProgressBar.paintEvent(self, e)

 def initPB() -> None:
     """Initialize and set parameters for progress bar, adding it to the dock."""
     global progressBar
-    progressBar = QProgressBar()
+    progressBar = QProgressBarCode()
     progressBar.setTextVisible(show_percent or show_number)
     progressBar.setInvertedAppearance(invertTF)
     progressBar.setOrientation(orientationHV)
@@ -377,6 +393,10 @@ def updatePB():
     else:
         progressBar.setRange(0, progbarmax)
         progressBar.setValue(cards)
+        if config['show_barcode']:
+            a = (mw.col.sched.day_cutoff - 86400) * 1000
+            reviews = mw.col.db.list("""select ease from revlog where id > ?""", a)
+            progressBar.setBarCodeColors([{1:QColor.fromRgbF(0.827,0.184,0.184,1), 2:QColor.fromRgbF(0.271,0.353,0.392,1), 3:QColor.fromRgbF(0.298,0.686,0.314,1), 4:QColor.fromRgbF(0.12,0.663,0.957,1), 0:QColor.fromRgbF(0,0,0,1)}[ease] for ease in reviews])

     if show_number:
         if show_debug:

resources used https://stackoverflow.com/questions/4838890/python-pyqt-popup-window https://doc.qt.io/qt-6/qcolor.html#fromRgbF https://doc.qt.io/qt-6/qprogressbar.html https://stackoverflow.com/questions/48421589/qt-custom-progressbar-cant-refresh-paintevent

carlos1172 commented 2 years ago

I think there is an existing addon that does this already :oo

khonkhortisan commented 2 years ago

Remaining time (for Anki 2.1)? it doesn't outright state what the colors are https://github.com/trgkanki/remaining_time/issues/40

carlos1172 commented 2 years ago

Yes

Regards, Carlos Resurreccion On Sep 22, 2022 at 9:44 PM +0800, Kyle Mills @.***>, wrote:

Remaining time (for Anki 2.1)? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>