From a5bfafa8a7940be17ee059d50ddc3c77445ea3d6 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 30 Jan 2024 21:59:19 -0500 Subject: [PATCH] Use sd binary in same directory as scripts instead of needing to pass path to sd binary --- README.md | 4 ++-- main.py | 4 +++- test.py | 2 ++ tkinter.py | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) mode change 100644 => 100755 main.py mode change 100644 => 100755 test.py mode change 100644 => 100755 tkinter.py diff --git a/README.md b/README.md index 6ee5021..286cec7 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ This is a C port of [SD](https://git.exozy.me/a/SD), a very efficient (and a tin Flash cards are stored in the `cards` table of a SQLite database. There are four columns: `idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING`. The `idx` is a unique index for each card, starting at 0. The weight is how often the card should come up. The key and value are the front and reverse sides of the card. -To create a card deck, use `sqlite3 cards "CREATE TABLE cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)`. You may be able to get twice as fast performance by enabling WAL with `PRAGMA journal_mode=WAL` because WAL only writes the content once instead of twice. +To create a card deck, use `sqlite3 cards "CREATE TABLE cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)`. You may be able to double the performance by enabling WAL with `PRAGMA journal_mode=WAL`, because WAL only writes the content once instead of twice. Now build this project with `gcc sd.c segmenttree.c -o sd -lsqlite3 -O2 -march=native` and run `./sd` to enjoy a fast flash cards experience! The program will display the `key` of a randomly selected card. Press any key to show the `val` of the card. Now press either `y` or `n` depending on whether you got the card correct, and the program adjusts that card's weight. -There is also a Python GUI which requires PyQt6. Run it with `python main.py PATH_TO_SDC_BINARY`. You can optionally pass additional flags to SDC. Alternatively, there is a Tkinter GUI, `python tkinter.py PATH_TO_SD_BINARY`, that only requires the Python standard library but does not support Wayland. The GUIs are not compatible with the original unmaintained SD which lacks noninteractive mode, but it would be easy to add that to SD. +There is also a Python GUI, `main.py`, which requires PyQt6. This script invokes the `sd` binary in the same directory as the script with the command-line flags that were passed to the script. Alternatively, there is a Tkinter GUI in `tkinter.py` that only requires the Python standard library but does not support Wayland. The GUIs are not compatible with the original unmaintained SD which lacks noninteractive mode, but it would be easy to add that feature to SD. It should also be fairly easy to write your own SD clone or GUI, so if you write one, I'd be glad to link to it here. diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 8bba5b5..9d821d1 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import subprocess import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel @@ -14,7 +16,7 @@ class SDGUI(QMainWindow): # Start SD self.proc = subprocess.Popen( - sys.argv[1:] + ['-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE + [sys.path[0] + '/sd', *sys.argv[1:], '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE ) # Display key diff --git a/test.py b/test.py old mode 100644 new mode 100755 index e600853..84c230b --- a/test.py +++ b/test.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import sqlite3 con = sqlite3.connect("test.db") diff --git a/tkinter.py b/tkinter.py old mode 100644 new mode 100755 index 99dcaa1..136f1a2 --- a/tkinter.py +++ b/tkinter.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import subprocess import sys import tkinter @@ -12,7 +14,7 @@ root.title('SD GUI') # Start SD proc = subprocess.Popen( - sys.argv[1:] + ['-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE + [sys.path[0] + '/sd', *sys.argv[1:], '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE ) # Display key