aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2024-01-30 21:59:19 -0500
committerAnthony Wang2024-01-30 21:59:19 -0500
commita5bfafa8a7940be17ee059d50ddc3c77445ea3d6 (patch)
tree875e2a706f2881c9bf7f1d0759d6060b272c198f
parent33b76d4106a2024e8f095c7bbb232482b7883eee (diff)
Use sd binary in same directory as scripts instead of needing to pass path to sd binary
-rw-r--r--README.md4
-rwxr-xr-x[-rw-r--r--]main.py4
-rwxr-xr-x[-rw-r--r--]test.py2
-rwxr-xr-x[-rw-r--r--]tkinter.py4
4 files changed, 10 insertions, 4 deletions
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
index 8bba5b5..9d821d1 100644..100755
--- 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
index e600853..84c230b 100644..100755
--- 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
index 99dcaa1..136f1a2 100644..100755
--- 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