Skip to content

Commit

Permalink
Bug fixes and improvements
Browse files Browse the repository at this point in the history
Program now capitilizes new definitions and sentences
Removed addWord_WordLabel and addWord_WordHLayout
Add placeholder text to WordLineEdit
Words in the search menu are now sorted alphabetically
Replace addWord_SentencesLineEdit with addWord_SentencesTextEdit
The definition and sentence labels in the surf words menu now has word wrap
Editing a word now sends you to the previous menu
  • Loading branch information
DolphyWind committed Sep 30, 2022
1 parent d6ef3af commit cae4b8a
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,10 @@ def createMainMenu(self):

def createAddWordMenu(self, preloadedWord:word.Word = None):
# region Word Typing
self.addWord_WordLabel = QtWidgets.QLabel("Word: ")
self.addWord_WordLabel.setFont(inapp_font)

self.addWord_WordLineEdit = QtWidgets.QLineEdit()
self.addWord_WordLineEdit.setFont(inapp_font)
self.addWord_WordLineEdit.setMinimumWidth(300)
# endregion

# region Word Layouts
self.addWord_WordHLayout = QtWidgets.QHBoxLayout()
self.addWord_WordHLayout.addWidget(self.addWord_WordLabel)
self.addWord_WordHLayout.addWidget(self.addWord_WordLineEdit)
self.addWord_WordLineEdit.setPlaceholderText("New Word")
# endregion

# region Add Choose Image Line
Expand Down Expand Up @@ -185,6 +177,7 @@ def chooseImage():
self.addWord_DefinitionsLineEdit = QtWidgets.QLineEdit()
self.addWord_DefinitionsLineEdit.setPlaceholderText("New Definition")
self.addWord_DefinitionsLineEdit.setFont(inapp_font)
self.addWord_DefinitionsLineEdit.setMaximumWidth(175)

self.addWord_AddDefButton = QtWidgets.QPushButton("Add")
self.addWord_AddDefButton.setFont(inapp_font)
Expand All @@ -197,7 +190,7 @@ def chooseImage():

def addNewDefinition():
word = self.addWord_DefinitionsLineEdit.text()

word = self.modifyWord(word)
if not word:
return
for i in range(self.addWord_DefinitionsListWidget.count()):
Expand Down Expand Up @@ -231,9 +224,12 @@ def removeNewDefinition():
# endregion

# region Add Example Sentences
self.addWord_SentencesLineEdit = QtWidgets.QLineEdit()
self.addWord_SentencesLineEdit.setPlaceholderText("New Sentence")
self.addWord_SentencesLineEdit.setFont(inapp_font)
self.addWord_SentencesTextEdit = QtWidgets.QTextEdit()
self.addWord_SentencesTextEdit.setPlaceholderText("New Sentence")
self.addWord_SentencesTextEdit.setFont(inapp_font)
self.addWord_SentencesTextEdit.setMaximumWidth(175)
self.addWord_SentencesTextEdit.setMaximumHeight(80)
self.addWord_SentencesTextEdit.setMinimumHeight(80)

self.addWord_AddSentencesButton = QtWidgets.QPushButton("Add")
self.addWord_AddSentencesButton.setFont(inapp_font)
Expand All @@ -245,16 +241,17 @@ def removeNewDefinition():
self.addWord_SentencesListWidget.setFont(inapp_font)

def addNewSentence():
word = self.addWord_SentencesLineEdit.text()

word = self.addWord_SentencesTextEdit.toPlainText()
word = self.modifyWord(word)
word = word.replace('\n', ' ')
if not word:
return
for i in range(self.addWord_SentencesListWidget.count()):
item = self.addWord_SentencesListWidget.item(i)
if item.text() == word:
return
self.addWord_SentencesListWidget.addItem(word)
self.addWord_SentencesLineEdit.clear()
self.addWord_SentencesTextEdit.clear()
def removeNewSentence():
item = self.addWord_SentencesListWidget.currentItem()
if not item:
Expand Down Expand Up @@ -284,7 +281,7 @@ def removeNewSentence():
# region Example Sentence Layouts
self.addWord_SentencesVLayout = QtWidgets.QVBoxLayout()
self.addWord_SentencesVLayout.addStretch()
self.addWord_SentencesVLayout.addWidget(self.addWord_SentencesLineEdit)
self.addWord_SentencesVLayout.addWidget(self.addWord_SentencesTextEdit)
self.addWord_SentencesVLayout.addWidget(self.addWord_AddSentencesButton)
self.addWord_SentencesVLayout.addWidget(self.addWord_RemoveSentencesButton)
self.addWord_SentencesVLayout.addStretch()
Expand Down Expand Up @@ -332,7 +329,7 @@ def addWord():
self.wordData[wordName] = w.getAsDictionary()

self.saveWordData()
self.switchMenu(Menu.ADD_WORD)
self.switchMenu(self.previousMenu, preloadedWord)

self.addWord_SaveButton.clicked.connect(addWord)
# endregion
Expand All @@ -349,7 +346,7 @@ def addWord():
self.addWord_VLayout = QtWidgets.QVBoxLayout()

self.addWord_VLayout.addStretch()
self.addWord_VLayout.addLayout(self.addWord_WordHLayout)
self.addWord_VLayout.addWidget(self.addWord_WordLineEdit)
self.addWord_VLayout.addLayout(self.addWord_ChooseImageHLayout)
self.addWord_VLayout.addStretch()
self.addWord_VLayout.addLayout(self.addWord_DefinitionsHLayout)
Expand All @@ -373,9 +370,14 @@ def updateListWidget(word: str):

searched = self.modifyWord(word)

matchedWords = []
for w in self.wordData.keys():
if w.startswith(searched):
self.searchWord_ListWidget.addItem(QtWidgets.QListWidgetItem(w))
matchedWords.append(w)

matchedWords = sorted(matchedWords)
for w in matchedWords:
self.searchWord_ListWidget.addItem(QtWidgets.QListWidgetItem(w))

self.searchWord_LineEdit = QtWidgets.QLineEdit()
self.searchWord_LineEdit.setPlaceholderText("Search Words...")
Expand Down Expand Up @@ -533,6 +535,7 @@ def createSurfWordsMenu(self, currentWord:word.Word = None):
for i, d in enumerate(currentWord.definitions):
lbl = QtWidgets.QLabel(f'{i + 1}. {d}')
lbl.setFont(text_font)
lbl.setWordWrap(True)
self.surfWords_DefinitionsScrollAreaVLayout.addWidget(lbl)

self.surfWords_DefinitionsCenteral.setLayout(self.surfWords_DefinitionsScrollAreaVLayout)
Expand All @@ -556,9 +559,11 @@ def createSurfWordsMenu(self, currentWord:word.Word = None):
self.surfWords_SentencesCenteral = QtWidgets.QWidget()
self.surfWords_SentencesScrollAreaVLayout = QtWidgets.QVBoxLayout()


for i, es in enumerate(currentWord.exampleSentences):
lbl = QtWidgets.QLabel(f'{i + 1}. {es}')
lbl.setFont(text_font)
lbl.setWordWrap(True)
self.surfWords_SentencesScrollAreaVLayout.addWidget(lbl)

self.surfWords_SentencesCenteral.setLayout(self.surfWords_SentencesScrollAreaVLayout)
Expand Down

0 comments on commit cae4b8a

Please sign in to comment.