Skip to content

Commit

Permalink
feat: all of inputs are dealt with exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Yejining committed Feb 11, 2020
1 parent a0dfd16 commit a1497d7
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 1 deletion.
54 changes: 53 additions & 1 deletion MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox

from gui.main import Ui_MainWindow
from src.GameWindow import GameWindow
from src.database import Database
from src.exception import Error
from src.form import Inputs


def warn(error):
Expand All @@ -33,11 +35,16 @@ def __init__(self):

def init_objects(self):
self.database = Database(self.table, self.lineEdit_dbid, self.checkBox_dbid)
self.form = Inputs(self.lineEdit_pupiltimer, self.lineEdit_seqsize,
self.lineEdit_boardsizen, self.lineEdit_boardsizem, self.sequence,
self.lineEdit_dwell)
self.error = Error()

def add_button_clicked(self):
self.pushButton_shortcuts.clicked.connect(self.on_click)
self.pushButton_dbsetting.clicked.connect(self.on_click)
self.pushButton_seqsize.clicked.connect(self.on_click)
self.pushButton_boardsize.clicked.connect(self.on_click)
self.pushButton_start.clicked.connect(self.on_click)
self.pushButton_ok.clicked.connect(self.on_shortcuts_click)
self.pushButton_cancel.clicked.connect(self.on_database_click)
Expand All @@ -48,6 +55,9 @@ def add_checkbox_changed(self):

def add_edit_entered(self):
self.lineEdit_dbid.returnPressed.connect(self.on_enter)
self.lineEdit_pupiltimer.returnPressed.connect(self.on_enter)
self.lineEdit_seqsize.returnPressed.connect(self.on_enter)
self.lineEdit_boardsizem.returnPressed.connect(self.on_enter)

def hide_boxes(self):
self.box_detailed.hide()
Expand All @@ -60,8 +70,12 @@ def on_click(self):
self.stack.setCurrentWidget(self.page_shortcuts)
if eq(sending_button.objectName(), "pushButton_dbsetting"):
self.stack.setCurrentWidget(self.page_database)
if eq(sending_button.objectName(), "pushButton_seqsize"):
self.show_sequence_matrix()
if eq(sending_button.objectName(), "pushButton_boardsize"):
self.show_board_matrix()
if eq(sending_button.objectName(), "pushButton_start"):
print("checking")
self.game()

@pyqtSlot()
def on_shortcuts_click(self):
Expand All @@ -87,6 +101,44 @@ def on_enter(self):
sending_edit = self.sender()
if eq(sending_edit.objectName(), "lineEdit_dbid"):
warn(self.database.on_id_apply())
if eq(sending_edit.objectName(), "lineEdit_pupiltimer"):
warn(self.form.is_pupil_timer_number())
if eq(sending_edit.objectName(), "lineEdit_seqsize"):
self.show_sequence_matrix()
if eq(sending_edit.objectName(), "lineEdit_boardsizem"):
self.show_board_matrix()

def show_sequence_matrix(self):
error = self.form.is_seqsize_number()
warn(error)
if error.is_true is False:
self.form.seqsize = int(self.lineEdit_seqsize.displayText())
self.box_detailed.show()
for element in self.form.sequence.elements:
element.hide()
for i in range(self.form.seqsize):
self.form.sequence.elements[i].show()

def show_board_matrix(self):
error = self.form.is_boardsize_number()
warn(error)
if error.is_true is False:
self.box_board.show()
for i in range(5):
for j in range(5):
self.form.sequence.matrix[i][j].hide()
for i in range(int(self.lineEdit_boardsizem.displayText())):
for j in range(int(self.lineEdit_boardsizen.displayText())):
self.form.sequence.matrix[i][j].show()

def game(self):
error = self.form.is_all_filled_properly()
warn(error)
if error.is_true is False:
print("game")
# self.game_window = GameWindow()
# self.game_window.showFullScreen()
# self.game_window.setFixedSize(self.game_window.size())


if __name__ == '__main__':
Expand Down
96 changes: 96 additions & 0 deletions src/form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from operator import eq

from src.exception import Error


def is_number(string):
try:
value = int(string)
except ValueError:
try:
value = float(string)
except ValueError:
return False
return True


def is_value_number(value, title):
error = Error()
if is_number(value):
if float(value) == 0:
error.set_message(title + "CANNOT be 0!")
return error
else:
error.set_message("Input of " + title + " is Not Number!")
return error


class Inputs:
def __init__(self,
lineEdit_pupiltimer,
lineEdit_seqsize,
lineEdit_boardsizen,
lineEdit_boardsizem,
sequence,
lineEdit_dwell):
self.lineEdit_pupiltimer = lineEdit_pupiltimer
self.lineEdit_seqsize = lineEdit_seqsize
self.lineEdit_boardsizen = lineEdit_boardsizen
self.lineEdit_boardsizem = lineEdit_boardsizem
self.sequence = sequence
self.lineEdit_dwell = lineEdit_dwell
self.seqsize = 0

def is_all_filled_properly(self):
pupil_timer = self.is_pupil_timer_number()
if pupil_timer.is_true: return pupil_timer
seqsize = self.is_seqsize_number()
if seqsize.is_true: return seqsize
is_seq_filled = self.is_seq_filled()
if is_seq_filled.is_true: return is_seq_filled
boardsize = self.is_board_filled()
if boardsize.is_true: return boardsize
is_board_filled = self.is_board_filled()
if is_board_filled.is_true: return is_board_filled
dwell_timer = self.is_dwell_timer_numer()
if dwell_timer.is_true: return dwell_timer

def is_pupil_timer_number(self):
error = is_value_number(self.lineEdit_pupiltimer.displayText(), "Pupil Timer")
return error

def is_seqsize_number(self):
error = is_value_number(self.lineEdit_seqsize.displayText(), "Sequence Size")
if int(self.lineEdit_seqsize.displayText()) > 8: error.set_message("8 is Maximum Number!")
return error

def is_boardsize_number(self):
error = is_value_number(self.lineEdit_boardsizem.displayText(), "Row")
if int(self.lineEdit_boardsizem.displayText()) > 5: error.set_message("5 is Maximum Number!")
error = is_value_number(self.lineEdit_boardsizen.displayText(), "Column")
if int(self.lineEdit_boardsizen.displayText()) > 5: error.set_message("5 is Maximum Number!")
return error

def is_seq_filled(self):
error = Error()
if self.seqsize == 0:
error.set_message("Enter Sequence Size!")
return error
for i in range(self.seqsize):
if eq(self.sequence.elements[i], ""):
error.set_message("%dth Sequence is Not Filled!" % (i + 1))
return error
return error

def is_board_filled(self):
error = Error()
for i in range(self.lineEdit_boardsizen):
for j in range(self.lineEdit_boardsizem):
if eq(self.sequence.matrix[i][j], ""):
error.set_message("(%d, %d) Board Value is Not Filled!" % (i + 1, j + 1))
return error
return error

def is_dwell_timer_numer(self):
error = is_value_number(self.lineEdit_dwell.displayText(), "Dwell Timer")
return error

0 comments on commit a1497d7

Please sign in to comment.