reuse of flashcard elements and other fixes

This commit is contained in:
jorenchik
2024-09-10 12:50:15 +03:00
parent f154f1a255
commit cd1ef1bb44
6 changed files with 606 additions and 175 deletions

View File

@@ -0,0 +1,245 @@
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- [cap_est] What is the capital of Estonia? >
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin
- Tallin

View File

@@ -0,0 +1,110 @@
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga
- [cap_riga] What is the capital of Latvia? >
- Riga

23
src/mdemory-app-qt/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
},
{
"name": "Debug Go Program",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "${workspaceFolder}/mdemory_debug",
"args": []
}
]
}

View File

@@ -1,5 +1,8 @@
package main
// TODO: open flashcard with many answers and switch mdem file,
// it remains opens with the same options -> Rehide the answers.
import (
"fmt"
"os"
@@ -12,14 +15,37 @@ import (
"github.com/therecipe/qt/widgets"
)
var mdems []*widgets.QWidget
var hMdemScroll *widgets.QVBoxLayout
var mdemSpacer *widgets.QSpacerItem
var spacerInitialized bool = false
var workingPath string = "/home/jorenchik/Code/mdemory/memorybase"
func CreateMdem(frontText string, backTexts []string) *widgets.QWidget {
// frontText := "What is the capital of Latvia?"
type Mdem struct {
wMdem *widgets.QWidget;
wFrontText *widgets.QLabel;
wBack *widgets.QWidget;
backLabels []*widgets.QLabel;
showButton *widgets.QToolButton;
labelCount int;
}
var mdems []*Mdem
func (mdem *Mdem) showBacklabels() {
for i := range(len(mdem.backLabels)) {
if i < mdem.labelCount {
if !mdem.backLabels[i].IsVisible() {
mdem.backLabels[i].Show()
}
} else {
if mdem.backLabels[i].IsVisible() {
mdem.backLabels[i].Hide()
}
}
}
}
func CreateMdem() *Mdem {
// DefineMdem
wMdem := widgets.NewQWidget(nil, 0)
@@ -33,9 +59,8 @@ func CreateMdem(frontText string, backTexts []string) *widgets.QWidget {
wFront := widgets.NewQWidget(nil, 0)
hFront := widgets.NewQHBoxLayout()
wFront.SetMinimumHeight(60)
// wFront.SetMaximumHeight(60)
wFront.SetLayout(hFront)
wFront.SetProperty("first", core.NewQVariant1(true));
wFront.SetProperty("first", core.NewQVariant1(true))
wMdem.SetStyleSheet(fmt.Sprintf(`
QWidget#%s > QWidget {
border-right: 1px solid gray;
@@ -48,33 +73,25 @@ func CreateMdem(frontText string, backTexts []string) *widgets.QWidget {
`, id, id))
// AddFrontContent
elFrontText := widgets.NewQLabel2(frontText, nil, 0)
elFrontText := widgets.NewQLabel(nil, 0)
hFront.AddWidget(elFrontText, 0, 0)
hFront.AddStretch(1)
hideButton := widgets.NewQToolButton(nil)
showAnswer := widgets.NewQToolButton(nil)
hideButton.SetText("Hide")
showAnswer.SetText("Show")
hFront.AddWidget(hideButton, 0, 0)
hFront.AddWidget(showAnswer, 0, 0)
wBack := widgets.NewQWidget(nil, 0)
hBack := widgets.NewQVBoxLayout()
// wBack.SetMinimumHeight(60)
wBack.SetLayout(hBack)
vMdem.AddWidget(wBack, 0, 0)
// AddBackContent
for i := range(backTexts) {
backText := strings.Trim(backTexts[i], " \t\n")
elBackText := widgets.NewQLabel2(
fmt.Sprintf("- %s", backText),
nil,
0,
)
var backLabels []*widgets.QLabel
for range(20) {
elBackText := widgets.NewQLabel(nil, 0)
hBack.AddWidget(elBackText, 0, 0)
backLabels = append(backLabels, elBackText)
}
hBack.AddStretch(1)
vMdem.AddWidget(wFront, 0, 0)
vMdem.AddWidget(wBack, 0, 0)
@@ -83,63 +100,91 @@ func CreateMdem(frontText string, backTexts []string) *widgets.QWidget {
wBack.Hide()
hideButton.ConnectClicked(func(checked bool) {
if wBack.IsVisible() {
wBack.Hide()
}
})
showAnswer.ConnectClicked(func(checked bool) {
if !wBack.IsVisible() {
wBack.Show()
}
})
return wMdem
wMdem.Hide()
mdem := Mdem{
wMdem,
elFrontText,
wBack,
backLabels,
showAnswer,
0,
}
mdem.showButton.ConnectClicked(func(checked bool) {
if mdem.wBack.IsVisible() {
mdem.wBack.Hide()
mdem.showButton.SetText("Show")
} else {
mdem.wBack.Show()
mdem.showButton.SetText("Hide")
}
mdem.showBacklabels()
})
return &mdem
}
func CreateMdems(questions *[]parser.Question) {
if spacerInitialized {
hMdemScroll.RemoveItem(mdemSpacer)
}
for i := range(mdems) {
hMdemScroll.RemoveWidget(mdems[i])
mdems[i].Hide()
mdems[i].DeleteLater()
} else {
mdemSpacer = widgets.NewQSpacerItem(
0, 0, widgets.QSizePolicy__Maximum, widgets.QSizePolicy__Minimum,
)
}
// destroy widgets
mdems = nil
for i := range(*questions) {
for i := range mdems {
if mdems[i].wMdem.IsVisible() {
mdems[i].wMdem.Hide()
}
}
if len(*questions) > len(mdems) {
for range(len(*questions) - len(mdems)) {
mdem := CreateMdem()
mdems = append(mdems, mdem)
hMdemScroll.AddWidget(mdem.wMdem, 0, 0)
}
}
for i := range *questions {
question := (*questions)[i]
switch question.(type) {
case parser.SingleAnswerQuestion:
mdems = append(
mdems,
CreateMdem(
mdems[i].wFrontText.SetText(
question.(parser.SingleAnswerQuestion).Question,
[]string{
question.(parser.SingleAnswerQuestion).Answer,
},
),
)
answer := strings.Trim(
question.(parser.SingleAnswerQuestion).Answer, " \t\n",
)
mdems[i].backLabels[0].SetText(answer)
if mdems[i].wBack.IsVisible() {
mdems[i].wBack.Hide()
}
mdems[i].labelCount = 1
case parser.MultipleChoiceQuestion:
var answers []string
choices := question.(parser.MultipleChoiceQuestion).Choices
for i := range(choices) {
answers = append(answers, choices[i].Answer)
}
mdems = append(
mdems,
CreateMdem(
mdems[i].wFrontText.SetText(
question.(parser.MultipleChoiceQuestion).Question,
answers,
),
)
for k := range choices {
answer := strings.Trim(choices[k].Answer, " \t\n")
if k < len(mdems[i].backLabels) {
mdems[i].backLabels[k].SetText(answer)
} else {
label := widgets.NewQLabel2(answer, nil, 0)
mdems[i].backLabels = append(
mdems[i].backLabels,
label,
)
mdems[i].wBack.Layout().AddWidget(label)
}
}
for i := 0; i < len(mdems); i++ {
hMdemScroll.AddWidget(mdems[i], 0, 0)
mdems[i].labelCount = len(choices)
}
if !mdems[i].wMdem.IsVisible() {
mdems[i].wMdem.Show()
}
}
if !spacerInitialized {
@@ -154,7 +199,6 @@ func CreateMdems(questions *[]parser.Question) {
hMdemScroll.AddItem(mdemSpacer)
}
func main() {
// InitApp
app := widgets.NewQApplication(len(os.Args), os.Args)
@@ -186,7 +230,7 @@ func main() {
}
filePath := model.FilePath(index)
fileContents, err := os.ReadFile(filePath)
if (err != nil) {
if err != nil {
widgets.QMessageBox_Critical(
nil,
"Compilation error",
@@ -198,7 +242,7 @@ func main() {
}
start := time.Now().UnixMicro()
questions, err := api.Compile(string(fileContents))
if (err != nil) {
if err != nil {
widgets.QMessageBox_Critical(
nil,
"Compilation error",
@@ -210,6 +254,9 @@ func main() {
}
duration := float32(time.Now().UnixMicro()-start) / 1000
fmt.Printf("Compilation took %.3fms", duration)
// Take a slice (mock pagination for now)
questions = questions[0:10]
CreateMdems(&questions)
})
@@ -248,10 +295,16 @@ func main() {
mdemScroll.SetWidgetResizable(true)
mdemContainer.SetLayout(hMdemScroll)
// CreateMdems
rightLayout.AddWidget(mdemScroll, 1, 0)
// CreateMdems(nil, hMdemScroll)
for i := 0; i < 40; i++ {
mdem := CreateMdem()
mdems = append(
mdems,
mdem,
)
hMdemScroll.AddWidget(mdem.wMdem, 0, 0)
}
rightLayout.AddWidget(mdemScroll, 1, 0)
// Pagination
pagination := widgets.NewQWidget(nil, 0)
hPagination := widgets.NewQHBoxLayout()

Binary file not shown.

BIN
src/mdemory-app-qt/mdemory_debug Executable file

Binary file not shown.