flashcards

Stupid LaTeX flashcard viewer
git clone git://lumidify.org/flashcards.git
Log | Files | Refs | README

commit 91450f11ff4e31aa056e42f86be5c29610629b7b
parent 1148dd020e6d7449567ed96b7e417c9bb8b3e36a
Author: lumidify <nobody@lumidify.org>
Date:   Wed,  8 Apr 2020 17:59:11 +0200

Implement chained cards

Diffstat:
MREADME | 21+++++++++++++++++++++
Acache/01_back.png | 0
Acache/01_front1.png | 0
Acache/01_front2.png | 0
Acache/02_back.png | 0
Acache/02_front1.png | 0
Acache/02_front2.png | 0
Acache/03_back.png | 0
Acache/03_front1.png | 0
Acache/03_front2.png | 0
Acache/04_back.png | 0
Acache/04_front1.png | 0
Acache/04_front2.png | 0
Acache/05_back.png | 0
Acache/05_front1.png | 0
Acache/05_front2.png | 0
Acache/06_back.png | 0
Acache/06_front1.png | 0
Acache/06_front2.png | 0
Dcache/bob_back.png | 0
Dcache/bob_front1.png | 0
Dcache/bob_front2.png | 0
Mconfig.json | 2+-
Aflashcards_orig/01 | 3+++
Aflashcards_orig/02 | 3+++
Aflashcards_orig/03 | 3+++
Aflashcards_orig/04 | 3+++
Aflashcards_orig/05 | 3+++
Aflashcards_orig/06 | 3+++
Dflashcards_orig/bob | 3---
Alatex/01 | 3+++
Alatex/02 | 3+++
Alatex/03 | 3+++
Alatex/04 | 3+++
Alatex/05 | 3+++
Alatex/06 | 3+++
Dlatex/bob | 3---
Mviewer2.pl | 58+++++++++++++++++++++++++++++++++++++++++-----------------
38 files changed, 99 insertions(+), 24 deletions(-)

diff --git a/README b/README @@ -2,6 +2,18 @@ This is a stupid little flashcard reader for LaTeX files. You probably don't want to use it. The images aren't even resized properly. It just works for me, that's why I use it. +The maximum image size is currently hardcoded for my monitor size. +If you actually want to use this for some weird reason and don't have +a 1280x800 monitor with the exact bars in my setup of the dwm window +manager, maybe change it. +Just change the following two lines in the `gui` function: + + my $w_final = $w < 1280 ? $w : 1280; + my $h_final = $h < 600 ? $h : 600; + +1280 is the maximum width and 600 the maximum height of the backside +of the flashcard. + `viewer.pl` is the old version using Tk, `viewer2.pl` is the new version using Gtk2. @@ -14,6 +26,15 @@ to PNG, pasting `fm.tex` at the beginning of the flashcard before rendering it. The top line of each flashcard file has the theorem number or something similar, the second line has the front side of the card, and the rest of the lines are the actual content of the card. +If the top line has a "|" character, the name of the flashcard to the +right of it has to be displayed before this one. This is useful to make +chained flashcards in which several flashcards depend on context given +in the initial one. The chain will always be shown in order. +The view count is only increased when "Reveal card" is pressed, so +it can be messed up if you skip past one flashcard in a chain and only +view the later one. In this case, the chain will still always be shown +in order, but the view counts for the flashcards in the chain won't +be the same. The actual program only has two buttons, "Next card" and "Reveal card", which should be obvious. The number of times the card was viewed is diff --git a/cache/01_back.png b/cache/01_back.png Binary files differ. diff --git a/cache/01_front1.png b/cache/01_front1.png Binary files differ. diff --git a/cache/01_front2.png b/cache/01_front2.png Binary files differ. diff --git a/cache/02_back.png b/cache/02_back.png Binary files differ. diff --git a/cache/02_front1.png b/cache/02_front1.png Binary files differ. diff --git a/cache/02_front2.png b/cache/02_front2.png Binary files differ. diff --git a/cache/03_back.png b/cache/03_back.png Binary files differ. diff --git a/cache/03_front1.png b/cache/03_front1.png Binary files differ. diff --git a/cache/03_front2.png b/cache/03_front2.png Binary files differ. diff --git a/cache/04_back.png b/cache/04_back.png Binary files differ. diff --git a/cache/04_front1.png b/cache/04_front1.png Binary files differ. diff --git a/cache/04_front2.png b/cache/04_front2.png Binary files differ. diff --git a/cache/05_back.png b/cache/05_back.png Binary files differ. diff --git a/cache/05_front1.png b/cache/05_front1.png Binary files differ. diff --git a/cache/05_front2.png b/cache/05_front2.png Binary files differ. diff --git a/cache/06_back.png b/cache/06_back.png Binary files differ. diff --git a/cache/06_front1.png b/cache/06_front1.png Binary files differ. diff --git a/cache/06_front2.png b/cache/06_front2.png Binary files differ. diff --git a/cache/bob_back.png b/cache/bob_back.png Binary files differ. diff --git a/cache/bob_front1.png b/cache/bob_front1.png Binary files differ. diff --git a/cache/bob_front2.png b/cache/bob_front2.png Binary files differ. diff --git a/config.json b/config.json @@ -1 +1 @@ -{"cards":{"bob":3}} +{"cards":{"06":3,"02":3,"03":4,"01":3,"04":3,"05":3}} diff --git a/flashcards_orig/01 b/flashcards_orig/01 @@ -0,0 +1,3 @@ +1 +1 +1 diff --git a/flashcards_orig/02 b/flashcards_orig/02 @@ -0,0 +1,3 @@ +2|01 +2 +2 diff --git a/flashcards_orig/03 b/flashcards_orig/03 @@ -0,0 +1,3 @@ +3|02 +3 +3 diff --git a/flashcards_orig/04 b/flashcards_orig/04 @@ -0,0 +1,3 @@ +4 +4 +4 diff --git a/flashcards_orig/05 b/flashcards_orig/05 @@ -0,0 +1,3 @@ +5|04 +5 +5 diff --git a/flashcards_orig/06 b/flashcards_orig/06 @@ -0,0 +1,3 @@ +6 +6 +6 diff --git a/flashcards_orig/bob b/flashcards_orig/bob @@ -1,3 +0,0 @@ -Satz 1|bla -Tolle Karte -$\frac{x}{y}$ diff --git a/latex/01 b/latex/01 @@ -0,0 +1,3 @@ +1 +1 +1 diff --git a/latex/02 b/latex/02 @@ -0,0 +1,3 @@ +2|01 +2 +2 diff --git a/latex/03 b/latex/03 @@ -0,0 +1,3 @@ +3|02 +3 +3 diff --git a/latex/04 b/latex/04 @@ -0,0 +1,3 @@ +4 +4 +4 diff --git a/latex/05 b/latex/05 @@ -0,0 +1,3 @@ +5|04 +5 +5 diff --git a/latex/06 b/latex/06 @@ -0,0 +1,3 @@ +6 +6 +6 diff --git a/latex/bob b/latex/bob @@ -1,3 +0,0 @@ -Satz 1|bla -Tolle Karte -$\frac{x}{y}$ diff --git a/viewer2.pl b/viewer2.pl @@ -7,19 +7,27 @@ use open qw< :encoding(UTF-8) >; binmode(STDOUT, ":utf8"); use Gtk2 '-init'; use Glib qw/TRUE FALSE/; -use Data::Dumper; use JSON qw(decode_json encode_json); use List::Util qw(min); sub load_cards { my %cards; + my %cards_backreference; opendir my $dir, "latex" or die "Unable to open flashcards directory.\n"; while (my $filename = readdir($dir)) { next if ($filename =~ /\A\.\.?\z/); - $cards{$filename} = 1; + open my $fh, "<", "latex/$filename" || die "Unable to open file \"latex/$filename\"\n"; + my $line = <$fh>; + $line =~ /\|(.*)$/; + $cards{$filename} = $1; + $cards_backreference{$1} = $filename if $1; + if ($1 && !-f "latex/$1") { + die "Flashcard \"$1\" mentioned in \"$filename\" does not exist.\n"; + } + close $fh; } closedir $dir; - return \%cards; + return \%cards, \%cards_backreference; } sub load_config { @@ -68,10 +76,27 @@ sub get_rand_card { return ($min_view_count, $card); } +sub find_card_view_count { + my ($cards, $card_id) = @_; + foreach my $view_count (keys %$cards) { + return $view_count if exists $cards->{$view_count}->{$card_id}; + } +} + sub next_card { - my ($config, $cards, $img_vbox, $window) = @_; + my ($config, $cards, $cards_backreference, $img_vbox, $window, $cur_card_id) = @_; $img_vbox->foreach(sub {$_[0]->destroy}); - my ($view_count, $card_id) = get_rand_card $cards; + my ($view_count, $card_id); + if ($cur_card_id && ($card_id = $cards_backreference->{$cur_card_id})) { + $view_count = find_card_view_count $cards, $card_id; + } else { + ($view_count, $card_id) = get_rand_card $cards; + while (my $req_card = $cards->{$view_count}->{$card_id}) { + $card_id = $req_card; + # efficiency is for sissies + $view_count = find_card_view_count $cards, $card_id; + } + } $window->set_title($card_id); my $pixbuf1 = Gtk2::Gdk::Pixbuf->new_from_file("cache/${card_id}_front1.png"); my $pixbuf2 = Gtk2::Gdk::Pixbuf->new_from_file("cache/${card_id}_front2.png"); @@ -85,7 +110,7 @@ sub next_card { sub gui { my $config = load_config("config.json"); - my $cards = load_cards; + my ($cards, $cards_backreference) = load_cards; $config = remove_cruft $config, $cards; $cards = sort_cards $config, $cards; @@ -97,8 +122,7 @@ sub gui { my $view_count; my $card_id; - # so you can press space bar multiple times without increasing the view count - # again (useful for reloading edited cards) + # so you can press "Reveal card" multiple times without increasing the view count again my $view_count_increased = 0; my $vbox = Gtk2::VBox->new(FALSE, 5); my $hbox = Gtk2::HBox->new(FALSE, 5); @@ -107,20 +131,20 @@ sub gui { my $img_vbox = Gtk2::VBox->new(); $button->signal_connect(clicked => sub { $view_count_increased = 0; - ($view_count, $card_id) = next_card $config, $cards, $img_vbox, $window; + ($view_count, $card_id) = next_card $config, $cards, $cards_backreference, $img_vbox, $window, $card_id; }, $window); $hbox->pack_start($button, FALSE, FALSE, 0); my $label = Gtk2::Label->new(""); - $button = Gtk2::Button->new_with_mnemonic("_Reveal back"); + $button = Gtk2::Button->new_with_mnemonic("Reveal _back"); $button->signal_connect(clicked => sub { - my ($fmt, $w, $h) = Gtk2::Gdk::Pixbuf->get_file_info("cache/${card_id}_back.png"); - my $w_final = $w < 1280 ? $w : 1280; - my $h_final = $h < 600 ? $h : 1280; - my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size("cache/${card_id}_back.png", $w_final, $h_final); - my $image = Gtk2::Image->new_from_pixbuf($pixbuf); - $img_vbox->pack_start($image, FALSE, FALSE, 0); - $image->show; if (!$view_count_increased) { + my ($fmt, $w, $h) = Gtk2::Gdk::Pixbuf->get_file_info("cache/${card_id}_back.png"); + my $w_final = $w < 1280 ? $w : 1280; + my $h_final = $h < 600 ? $h : 600; + my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size("cache/${card_id}_back.png", $w_final, $h_final); + my $image = Gtk2::Image->new_from_pixbuf($pixbuf); + $img_vbox->pack_start($image, FALSE, FALSE, 0); + $image->show; $view_count_increased = 1; $config->{cards}->{$card_id}++; $cards->{$view_count+1}->{$card_id} = $cards->{$view_count}->{$card_id};