Skip to content

Commit

Permalink
fix display button
Browse files Browse the repository at this point in the history
  • Loading branch information
danghoangnhan committed Nov 29, 2023
1 parent bd4f06f commit b2d875e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 35 deletions.
110 changes: 83 additions & 27 deletions component/screen/setting_screen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,78 @@
import os
from component.modal import ConfirmDialog
from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QTextEdit,QTabWidget,QDialog
from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QTextEdit,QTabWidget,QDialog,QSpinBox,QComboBox,QHBoxLayout
from PyQt6.QtGui import QFont
from storage.localStorage import dataHandaler

import logging
from config.dir import keyboard_dir

class GeneralSettingTab(QWidget):
def __init__(self, show_confirm_dialog_callback, keyboard_layout_list):
super().__init__()
main_layout = QVBoxLayout(self)

# Similarities section
similarities_layout = QHBoxLayout()
similarities_label = QLabel("Similarities:")
similarities_label.setFont(QFont("Arial", 16)) # Adjust font size
similarities_layout.addWidget(similarities_label)
self.similarities_spinbox = QSpinBox(self)
self.similarities_spinbox.setFont(QFont("Arial", 16)) # Adjust font size
self.similarities_spinbox.setMinimum(1)
self.similarities_spinbox.setMaximum(15)
self.similarities_spinbox.setValue(5)
similarities_layout.addWidget(self.similarities_spinbox)
main_layout.addLayout(similarities_layout)

# Keyboard section
keyboard_layout = QHBoxLayout()
filenames_label = QLabel("Keyboard Label:")
filenames_label.setFont(QFont("Arial", 16)) # Adjust font size
keyboard_layout.addWidget(filenames_label)
self.filenames_combobox = QComboBox(self)
self.filenames_combobox.setFont(QFont("Arial", 16)) # Adjust font size
self.filenames_combobox.addItems(keyboard_layout_list)
keyboard_layout.addWidget(self.filenames_combobox)
main_layout.addLayout(keyboard_layout)

# Reset button
reset_btn = QPushButton("Clear Csv Data", self)
reset_btn.setFont(QFont("Arial", 16)) # Adjust font size
reset_btn.clicked.connect(show_confirm_dialog_callback)
main_layout.addWidget(reset_btn)

self.setLayout(main_layout)


from PyQt6.QtWidgets import QWidget, QVBoxLayout, QTextEdit, QLabel

class AboutTab(QWidget):
def __init__(self, version, developer, designer):
super().__init__()

main_layout = QVBoxLayout(self)

about_text = QTextEdit("Information about the app...")
about_text.setReadOnly(True)
main_layout.addWidget(about_text)

version_label = QTextEdit(f"Version: {version}")
version_label.setReadOnly(True)
main_layout.addWidget(version_label)

designer_label = QTextEdit(f"Designer: {designer}")
designer_label.setReadOnly(True)
main_layout.addWidget(designer_label)

developer_label = QTextEdit(f"Developer: {developer}")
developer_label.setReadOnly(True)
main_layout.addWidget(developer_label)

self.setLayout(main_layout)



class SettingScreen(QWidget):
def __init__(self,navigator,screen_height,screen_width):
super().__init__()
Expand All @@ -23,56 +94,41 @@ def initUI(self):
layout.addWidget(tab_widget)

# Tab 1: General
general_tab = QWidget()
general_layout = QVBoxLayout(general_tab)

reset_btn = QPushButton("Reset", general_tab)
reset_btn.clicked.connect(self.show_confirm_dialog)
general_layout.addWidget(reset_btn)
general_tab = GeneralSettingTab(show_confirm_dialog_callback=self.show_confirm_dialog,keyboard_layout_list=self.load_filenames())

general_tab.setLayout(general_layout)
tab_widget.addTab(general_tab, "General")

# Tab 2: About the App
about_tab = QWidget()
about_layout = QVBoxLayout(about_tab)

about_text = QTextEdit("Information about the app...")
about_text.setReadOnly(True)
about_layout.addWidget(about_text)

about_tab.setLayout(about_layout)
about_tab = AboutTab("1.3","DanielDu","Mannichu")
tab_widget.addTab(about_tab, "About the App")



layout.addWidget(QLabel("Settings"))

reset_btn = QPushButton("Reset", self)
reset_btn.clicked.connect(self.show_confirm_dialog)
layout.addWidget(reset_btn)

back_btn = QPushButton("Back", self)
back_btn.clicked.connect(self.navigator.navigate_to_start_screen)
layout.addWidget(back_btn)

self.setLayout(layout)

def show_confirm_dialog(self):
dialog = ConfirmDialog(self)
dialog = ConfirmDialog("Confirm Reset",self)
result = dialog.exec()

if result == QDialog.DialogCode.Accepted:
print("Save confirmed")
self.confirm()
self.clear_csv_data()
else:
print("Save cancelled")
self.cancel()

def confirm(self):
def clear_csv_data(self):
dataHandaler.resetHistory()

print("Reset confirmed")

def cancel(self):
print("Reset cancelled")

def load_filenames(self):
filenames = os.listdir(keyboard_dir)
return filenames


14 changes: 6 additions & 8 deletions component/screen/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from model.answer import Answer
from storage.localStorage import dataHandaler
import random
from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QProgressBar,QSizePolicy,QHBoxLayout,QSpacerItem, QGridLayout
from PyQt6.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout,QSizePolicy,QHBoxLayout,QSpacerItem, QGridLayout
from PyQt6.QtGui import QIcon
from PyQt6.QtCore import Qt,QSize
from PyQt6.QtCore import QSize
from typing import List

import logging
Expand Down Expand Up @@ -166,15 +166,13 @@ def update_button_states(self):
self.update_button_style(button)
else:
self.reset_button_style(button)

for button in self.similarities_list:
if button.text() == current_question.get_similarity():
if button.text() == str(current_question.get_similarity()):
self.update_button_style(button)
else:
self.reset_button_style(button)

print(current_question.get_answer())
print(current_question.get_similarity())

def handling_submit_button(self):
self.submit_test()
self.navigator.navigate_to_end_screen()
Expand Down Expand Up @@ -216,13 +214,13 @@ def updateProcess(self):
def bofomo_consonant_action(self, button_index):
current_question = self.answerList[self.current_index]
current_question.set_answer(button_index)
# self.bofomo_consonants_list.updateState(button_index)
self.update_button_states()

# Action for similarities
def similarity_action(self, button_index):
current_question = self.answerList[self.current_index]
current_question.set_similarity(button_index)
# self.similarities_list.updateState(button_index)
self.update_button_states()


def update_button_style(self, button):
Expand Down
2 changes: 2 additions & 0 deletions config/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
history_dir = os.path.join(csv_dir, "history.xlsx")
exam_dir = os.path.join(csv_dir, "exam.xlsx")
volume_icon = os.path.join(image_dir, "volume.png")
keyboard_dir = os.path.join(csv_dir, "keyboard_layout")

1 change: 1 addition & 0 deletions storage/localStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ def readStructure_user(self):
def resetHistory(self):
self.user_data_handaler.truncate()
self.history_data_handaler.truncate()


dataHandaler= DataHandaler()

0 comments on commit b2d875e

Please sign in to comment.