mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
reuse of flashcard elements and other fixes
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
23
src/mdemory-app-qt/.vscode/launch.json
vendored
Normal 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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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,31 +15,53 @@ import (
|
||||
"github.com/therecipe/qt/widgets"
|
||||
)
|
||||
|
||||
var mdems []*widgets.QWidget
|
||||
var hMdemScroll *widgets.QVBoxLayout
|
||||
var mdemSpacer *widgets.QSpacerItem
|
||||
var hMdemScroll *widgets.QVBoxLayout
|
||||
var mdemSpacer *widgets.QSpacerItem
|
||||
var spacerInitialized bool = false
|
||||
var workingPath string = "/home/jorenchik/Code/mdemory/memorybase"
|
||||
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;
|
||||
}
|
||||
|
||||
// DefineMdem
|
||||
wMdem := widgets.NewQWidget(nil, 0)
|
||||
vMdem := widgets.NewQVBoxLayout()
|
||||
var mdems []*Mdem
|
||||
|
||||
wMdem.SetLayout(vMdem)
|
||||
id := fmt.Sprintf("mdem_%d", 1)
|
||||
wMdem.SetObjectName(id)
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InitFront
|
||||
wFront := widgets.NewQWidget(nil, 0)
|
||||
hFront := widgets.NewQHBoxLayout()
|
||||
wFront.SetMinimumHeight(60)
|
||||
// wFront.SetMaximumHeight(60)
|
||||
wFront.SetLayout(hFront)
|
||||
wFront.SetProperty("first", core.NewQVariant1(true));
|
||||
wMdem.SetStyleSheet(fmt.Sprintf(`
|
||||
func CreateMdem() *Mdem {
|
||||
|
||||
// DefineMdem
|
||||
wMdem := widgets.NewQWidget(nil, 0)
|
||||
vMdem := widgets.NewQVBoxLayout()
|
||||
|
||||
wMdem.SetLayout(vMdem)
|
||||
id := fmt.Sprintf("mdem_%d", 1)
|
||||
wMdem.SetObjectName(id)
|
||||
|
||||
// InitFront
|
||||
wFront := widgets.NewQWidget(nil, 0)
|
||||
hFront := widgets.NewQHBoxLayout()
|
||||
wFront.SetMinimumHeight(60)
|
||||
wFront.SetLayout(hFront)
|
||||
wFront.SetProperty("first", core.NewQVariant1(true))
|
||||
wMdem.SetStyleSheet(fmt.Sprintf(`
|
||||
QWidget#%s > QWidget {
|
||||
border-right: 1px solid gray;
|
||||
border-bottom: 1px solid gray;
|
||||
@@ -47,174 +72,196 @@ func CreateMdem(frontText string, backTexts []string) *widgets.QWidget {
|
||||
}
|
||||
`, id, id))
|
||||
|
||||
// AddFrontContent
|
||||
elFrontText := widgets.NewQLabel2(frontText, 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)
|
||||
// AddFrontContent
|
||||
elFrontText := widgets.NewQLabel(nil, 0)
|
||||
hFront.AddWidget(elFrontText, 0, 0)
|
||||
hFront.AddStretch(1)
|
||||
showAnswer := widgets.NewQToolButton(nil)
|
||||
showAnswer.SetText("Show")
|
||||
hFront.AddWidget(showAnswer, 0, 0)
|
||||
|
||||
wBack := widgets.NewQWidget(nil, 0)
|
||||
hBack := widgets.NewQVBoxLayout()
|
||||
// wBack.SetMinimumHeight(60)
|
||||
wBack.SetLayout(hBack)
|
||||
wBack := widgets.NewQWidget(nil, 0)
|
||||
hBack := widgets.NewQVBoxLayout()
|
||||
wBack.SetLayout(hBack)
|
||||
vMdem.AddWidget(wBack, 0, 0)
|
||||
|
||||
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,
|
||||
)
|
||||
// AddBackContent
|
||||
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)
|
||||
vMdem.SetContentsMargins(0,0,0,0)
|
||||
vMdem.SetSpacing(0)
|
||||
vMdem.AddWidget(wFront, 0, 0)
|
||||
vMdem.AddWidget(wBack, 0, 0)
|
||||
vMdem.SetContentsMargins(0, 0, 0, 0)
|
||||
vMdem.SetSpacing(0)
|
||||
|
||||
|
||||
wBack.Hide()
|
||||
hideButton.ConnectClicked(func(checked bool) {
|
||||
if wBack.IsVisible() {
|
||||
wBack.Hide()
|
||||
}
|
||||
})
|
||||
showAnswer.ConnectClicked(func(checked bool) {
|
||||
if !wBack.IsVisible() {
|
||||
wBack.Show()
|
||||
wBack.Hide()
|
||||
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 wMdem
|
||||
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()
|
||||
}
|
||||
if spacerInitialized {
|
||||
hMdemScroll.RemoveItem(mdemSpacer)
|
||||
} else {
|
||||
mdemSpacer = widgets.NewQSpacerItem(
|
||||
0, 0, widgets.QSizePolicy__Maximum, widgets.QSizePolicy__Minimum,
|
||||
)
|
||||
}
|
||||
|
||||
// destroy widgets
|
||||
mdems = nil
|
||||
for i := range(*questions) {
|
||||
question := (*questions)[i]
|
||||
switch question.(type) {
|
||||
case parser.SingleAnswerQuestion:
|
||||
mdems = append(
|
||||
mdems,
|
||||
CreateMdem(
|
||||
question.(parser.SingleAnswerQuestion).Question,
|
||||
[]string{
|
||||
question.(parser.SingleAnswerQuestion).Answer,
|
||||
},
|
||||
),
|
||||
)
|
||||
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(
|
||||
question.(parser.MultipleChoiceQuestion).Question,
|
||||
answers,
|
||||
),
|
||||
)
|
||||
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 := 0; i < len(mdems); i++ {
|
||||
hMdemScroll.AddWidget(mdems[i], 0, 0)
|
||||
}
|
||||
|
||||
if !spacerInitialized {
|
||||
mdemSpacer = widgets.NewQSpacerItem(
|
||||
40,
|
||||
40,
|
||||
widgets.QSizePolicy__Minimum,
|
||||
widgets.QSizePolicy__Expanding,
|
||||
)
|
||||
spacerInitialized = true
|
||||
}
|
||||
hMdemScroll.AddItem(mdemSpacer)
|
||||
for i := range *questions {
|
||||
question := (*questions)[i]
|
||||
switch question.(type) {
|
||||
case parser.SingleAnswerQuestion:
|
||||
mdems[i].wFrontText.SetText(
|
||||
question.(parser.SingleAnswerQuestion).Question,
|
||||
)
|
||||
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:
|
||||
choices := question.(parser.MultipleChoiceQuestion).Choices
|
||||
mdems[i].wFrontText.SetText(
|
||||
question.(parser.MultipleChoiceQuestion).Question,
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
mdems[i].labelCount = len(choices)
|
||||
}
|
||||
if !mdems[i].wMdem.IsVisible() {
|
||||
mdems[i].wMdem.Show()
|
||||
}
|
||||
}
|
||||
|
||||
if !spacerInitialized {
|
||||
mdemSpacer = widgets.NewQSpacerItem(
|
||||
40,
|
||||
40,
|
||||
widgets.QSizePolicy__Minimum,
|
||||
widgets.QSizePolicy__Expanding,
|
||||
)
|
||||
spacerInitialized = true
|
||||
}
|
||||
hMdemScroll.AddItem(mdemSpacer)
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
// InitApp
|
||||
app := widgets.NewQApplication(len(os.Args), os.Args)
|
||||
window := widgets.NewQMainWindow(nil, 0)
|
||||
// InitApp
|
||||
app := widgets.NewQApplication(len(os.Args), os.Args)
|
||||
window := widgets.NewQMainWindow(nil, 0)
|
||||
hSplitter := widgets.NewQSplitter(nil)
|
||||
window.SetWindowTitle("MDemory")
|
||||
window.SetMinimumSize2(400, 300)
|
||||
|
||||
leftWidget := widgets.NewQWidget(nil, 0)
|
||||
leftLayout := widgets.NewQVBoxLayout()
|
||||
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
|
||||
model := widgets.NewQFileSystemModel(nil)
|
||||
mdemList := widgets.NewQTreeView(nil)
|
||||
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
|
||||
model := widgets.NewQFileSystemModel(nil)
|
||||
mdemList := widgets.NewQTreeView(nil)
|
||||
leftWidget.SetLayout(leftLayout)
|
||||
leftLayout.AddWidget(mdemLabel, 0, 0)
|
||||
model.SetRootPath(workingPath)
|
||||
model.SetRootPath(workingPath)
|
||||
mdemList.SetModel(model)
|
||||
|
||||
rootIndex := model.Index2("/home/jorenchik/Code/mdemory/memorybase", 0)
|
||||
fmt.Printf("Root index: %s\n", model.FileName(rootIndex))
|
||||
mdemList.SetRootIndex(rootIndex)
|
||||
rootIndex := model.Index2("/home/jorenchik/Code/mdemory/memorybase", 0)
|
||||
fmt.Printf("Root index: %s\n", model.FileName(rootIndex))
|
||||
mdemList.SetRootIndex(rootIndex)
|
||||
|
||||
mdemList.HideColumn(1)
|
||||
mdemList.HideColumn(2)
|
||||
mdemList.HideColumn(3)
|
||||
mdemList.HideColumn(1)
|
||||
mdemList.HideColumn(2)
|
||||
mdemList.HideColumn(3)
|
||||
mdemList.ConnectDoubleClicked(func(index *core.QModelIndex) {
|
||||
if model.IsDir(index) {
|
||||
return
|
||||
}
|
||||
filePath := model.FilePath(index)
|
||||
fileContents, err := os.ReadFile(filePath)
|
||||
if (err != nil) {
|
||||
widgets.QMessageBox_Critical(
|
||||
nil,
|
||||
"Compilation error",
|
||||
err.Error(),
|
||||
widgets.QMessageBox__Ok,
|
||||
widgets.QMessageBox__Ok,
|
||||
)
|
||||
return
|
||||
}
|
||||
start := time.Now().UnixMicro()
|
||||
questions, err := api.Compile(string(fileContents))
|
||||
if (err != nil) {
|
||||
widgets.QMessageBox_Critical(
|
||||
nil,
|
||||
"Compilation error",
|
||||
err.Error(),
|
||||
widgets.QMessageBox__Ok,
|
||||
widgets.QMessageBox__Ok,
|
||||
)
|
||||
return
|
||||
}
|
||||
duration := float32(time.Now().UnixMicro() - start) / 1000
|
||||
fmt.Printf("Compilation took %.3fms", duration)
|
||||
CreateMdems(&questions)
|
||||
if model.IsDir(index) {
|
||||
return
|
||||
}
|
||||
filePath := model.FilePath(index)
|
||||
fileContents, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
widgets.QMessageBox_Critical(
|
||||
nil,
|
||||
"Compilation error",
|
||||
err.Error(),
|
||||
widgets.QMessageBox__Ok,
|
||||
widgets.QMessageBox__Ok,
|
||||
)
|
||||
return
|
||||
}
|
||||
start := time.Now().UnixMicro()
|
||||
questions, err := api.Compile(string(fileContents))
|
||||
if err != nil {
|
||||
widgets.QMessageBox_Critical(
|
||||
nil,
|
||||
"Compilation error",
|
||||
err.Error(),
|
||||
widgets.QMessageBox__Ok,
|
||||
widgets.QMessageBox__Ok,
|
||||
)
|
||||
return
|
||||
}
|
||||
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)
|
||||
})
|
||||
|
||||
deckLabel := widgets.NewQLabel2("Decks", nil, 0)
|
||||
deckList := widgets.NewQListView(nil)
|
||||
deckList := widgets.NewQListView(nil)
|
||||
leftLayout.AddWidget(mdemList, 1, 0)
|
||||
leftLayout.AddWidget(deckLabel, 0, 0)
|
||||
leftLayout.AddWidget(deckList, 1, 0)
|
||||
@@ -223,17 +270,17 @@ func main() {
|
||||
rightLayout := widgets.NewQVBoxLayout()
|
||||
rightWidget.SetLayout(rightLayout)
|
||||
|
||||
top := widgets.NewQWidget(nil, 0)
|
||||
hTop := widgets.NewQHBoxLayout()
|
||||
top := widgets.NewQWidget(nil, 0)
|
||||
hTop := widgets.NewQHBoxLayout()
|
||||
deckListLabel := widgets.NewQLabel2("Mdem: file.mdem", nil, 0)
|
||||
top.SetLayout(hTop)
|
||||
rightLayout.AddWidget(top, 0, 0)
|
||||
|
||||
hTop.AddWidget(deckListLabel, 0, 0)
|
||||
hTop.AddStretch(1)
|
||||
refresh := widgets.NewQToolButton(nil)
|
||||
refresh := widgets.NewQToolButton(nil)
|
||||
practice := widgets.NewQToolButton(nil)
|
||||
shuffle := widgets.NewQToolButton(nil)
|
||||
shuffle := widgets.NewQToolButton(nil)
|
||||
hTop.AddWidget(refresh, 0, 0)
|
||||
hTop.AddWidget(shuffle, 0, 0)
|
||||
hTop.AddWidget(practice, 0, 0)
|
||||
@@ -241,42 +288,48 @@ func main() {
|
||||
shuffle.SetText("Shuffle")
|
||||
practice.SetText("Practice")
|
||||
|
||||
mdemScroll := widgets.NewQScrollArea(nil)
|
||||
mdemContainer := widgets.NewQWidget(nil, 0)
|
||||
mdemScroll := widgets.NewQScrollArea(nil)
|
||||
mdemContainer := widgets.NewQWidget(nil, 0)
|
||||
hMdemScroll = widgets.NewQVBoxLayout()
|
||||
mdemScroll.SetWidget(mdemContainer)
|
||||
mdemScroll.SetWidgetResizable(true)
|
||||
mdemScroll.SetWidget(mdemContainer)
|
||||
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)
|
||||
}
|
||||
|
||||
// Pagination
|
||||
pagination := widgets.NewQWidget(nil, 0)
|
||||
rightLayout.AddWidget(mdemScroll, 1, 0)
|
||||
// Pagination
|
||||
pagination := widgets.NewQWidget(nil, 0)
|
||||
hPagination := widgets.NewQHBoxLayout()
|
||||
pagination.SetLayout(hPagination)
|
||||
|
||||
// TEMP: mock pagination
|
||||
prevButton := widgets.NewQToolButton(nil)
|
||||
prevButton.SetText("<")
|
||||
hPagination.AddWidget(prevButton, 0, 0)
|
||||
// TEMP: mock pagination
|
||||
prevButton := widgets.NewQToolButton(nil)
|
||||
prevButton.SetText("<")
|
||||
hPagination.AddWidget(prevButton, 0, 0)
|
||||
for i := 0; i < 5; i++ {
|
||||
button := widgets.NewQToolButton(nil)
|
||||
button.SetText(fmt.Sprintf("%d", i+1))
|
||||
hPagination.AddWidget(button, 0, 0)
|
||||
}
|
||||
nextButton := widgets.NewQToolButton(nil)
|
||||
nextButton.SetText(">")
|
||||
hPagination.AddWidget(nextButton, 0, 0)
|
||||
nextButton := widgets.NewQToolButton(nil)
|
||||
nextButton.SetText(">")
|
||||
hPagination.AddWidget(nextButton, 0, 0)
|
||||
|
||||
hPagination.AddStretch(1)
|
||||
rightLayout.AddWidget(pagination, 0, 0)
|
||||
|
||||
hSplitter.AddWidget(leftWidget)
|
||||
hSplitter.AddWidget(rightWidget)
|
||||
hSplitter.SetStretchFactor(0, 1)
|
||||
hSplitter.SetStretchFactor(1, 3)
|
||||
hSplitter.SetStretchFactor(0, 1)
|
||||
hSplitter.SetStretchFactor(1, 3)
|
||||
window.SetCentralWidget(hSplitter)
|
||||
|
||||
window.Show()
|
||||
|
||||
Binary file not shown.
BIN
src/mdemory-app-qt/mdemory_debug
Executable file
BIN
src/mdemory-app-qt/mdemory_debug
Executable file
Binary file not shown.
Reference in New Issue
Block a user