def AddWordEntryToDatabase(self): defaultpointervalue = int(0) if path.isdir("DATA"): try: chdir("DATA") except: pass if not path.isfile("position"): with open("position","w") as ap: ap.write("%d"%defaultpointervalue) self.DbObj = DatabaseManagement(self.databasename) self.DbObj.CreateTable() with open("position","r") as gp: self.databaseposition = int(gp.read()) self.databasePosition = self.databaseposition + 1 #self.databasePosition = len(self.DbObj.FetchData()) + 1 self.newword = self.addword_inputneword.text() self.newword_syn = self.addword_inputsynonym.text() self.newword_mean = self.additem_meaning.text() if len(self.newword) == 0 or len(self.newword_mean) == 0: #!it should raise error as requisite information is not given. self.error_msgBox = QMessageBox() self.error_msgBox.setIcon(QMessageBox.Critical) self.error_msgBox.setText("Please Input Required information To Save New Word.") self.error_msgBox.setWindowTitle("Complete Details Not Provided") self.error_msgBox.setStandardButtons(QMessageBox.Ok) self.error_msgBox.show() pass else: with open("position","w") as lp: lp.write("%d"%self.databasePosition) self.DbObj.InsertNewDetails(self.databasePosition,self.newword,self.newword_syn,self.newword_mean) self.AddWord_.close()
def RefreshContents(self): self.DbObj = DatabaseManagement(self.database_name) self.DbObj.CreateTable() while True: if Ui_SpecificCatagory_Manager.DatabaseDeleted: self.DbObj.DeleteDatabase() Ui_SpecificCatagory_Manager.DatabaseDeleted = False else: sleep(0.5) self.DatabaseDetails = self.DbObj.FetchData() self.opened_cata_tableWidget.clearContents() if len(self.DatabaseDetails) != 0: for rowno, rowdata in enumerate(self.DatabaseDetails): for colno, coldata in enumerate(rowdata): self.opened_cata_tableWidget.setItem( rowno, colno, QtWidgets.QTableWidgetItem(str(coldata)))
def OpenCataManager(self, catagory_name): if path.isfile(catagory_name): self.Dialog.close() self.SpecificCatagory_Manager = QtWidgets.QMainWindow() self.SpecificCatagory_ManagerUI = Ui_SpecificCatagory_Manager( catagory_name) self.SpecificCatagory_ManagerUI.setupUi( self.SpecificCatagory_Manager) self.SpecificCatagory_Manager.show() else: #!Catagory Entry Found In Configuration File But No Database Found Of Such Catagory. DbObj = DatabaseManagement(catagory_name) DbObj.CreateTable() DbObj.CloseConnections() self.error_msgBox = QMessageBox() self.error_msgBox.setIcon(QMessageBox.Information) self.error_msgBox.setText( "No Database Entry Found Of Catagory, Blank Database Created.") self.error_msgBox.setWindowTitle("No Catagory Exists.") DbObj.CloseConnections() self.error_msgBox.setStandardButtons(QMessageBox.Ok) self.error_msgBox.show()
def DeleteFinal(self): self.targetdeleteID = self.deleteword_id.text() self.DbObj = DatabaseManagement(self.databasename) self.DbObj.DeleteWholeRow(self.targetdeleteID) self.DeleteWord.close()
class Ui_DeleteWord(object): def __init__(self, databasename): self.databasename = databasename def setupUi(self, DeleteWord): self.DeleteWord = DeleteWord self.DeleteWord.setObjectName("DeleteWord") self.DeleteWord.resize(622, 268) self.deleteword_label = QtWidgets.QLabel(self.DeleteWord) self.deleteword_label.setGeometry(QtCore.QRect(130, 20, 341, 61)) font = QtGui.QFont() font.setFamily("Nokia Standard Light") font.setPointSize(30) self.deleteword_label.setFont(font) self.deleteword_label.setObjectName("deleteword_label") self.deleteword_punchline = QtWidgets.QLabel(self.DeleteWord) self.deleteword_punchline.setGeometry(QtCore.QRect(160, 60, 651, 91)) self.deleteword_punchline.setObjectName("deleteword_punchline") self.line = QtWidgets.QFrame(self.DeleteWord) self.line.setGeometry(QtCore.QRect(30, 130, 561, 20)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.horizontalLayoutWidget = QtWidgets.QWidget(self.DeleteWord) self.horizontalLayoutWidget.setGeometry(QtCore.QRect( 100, 150, 211, 89)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout( self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.deleteword_id = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.deleteword_id.setObjectName("deleteword_id") self.horizontalLayout.addWidget(self.deleteword_id) self.verticalLayoutWidget = QtWidgets.QWidget(DeleteWord) self.verticalLayoutWidget.setGeometry(QtCore.QRect(350, 150, 160, 80)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.deleteword_ok = QtWidgets.QPushButton(self.verticalLayoutWidget) self.deleteword_ok.setObjectName("deleteword_ok") self.verticalLayout.addWidget(self.deleteword_ok) self.deleteword_cancel = QtWidgets.QPushButton( self.verticalLayoutWidget) self.deleteword_cancel.setObjectName("deleteword_cancel") self.verticalLayout.addWidget(self.deleteword_cancel) self.retranslateUi(self.DeleteWord) QtCore.QMetaObject.connectSlotsByName(self.DeleteWord) def CloseDeleteWizard(self): self.DeleteWord.close() def DeleteFinal(self): self.targetdeleteID = self.deleteword_id.text() self.DbObj = DatabaseManagement(self.databasename) self.DbObj.DeleteWholeRow(self.targetdeleteID) self.DeleteWord.close() def retranslateUi(self, DeleteWord): _translate = QtCore.QCoreApplication.translate DeleteWord.setWindowTitle( _translate("DeleteWord", "Delete Word Wizard (Vocabuilder)")) self.deleteword_label.setText(_translate("DeleteWord", "Vocabuilder")) self.deleteword_punchline.setText( _translate("DeleteWord", " - Use Unique ID Of Target Word To Remove It.")) self.label.setText(_translate("DeleteWord", "Word ID : ")) self.deleteword_ok.setText(_translate("DeleteWord", "Delete Word")) self.deleteword_cancel.setText(_translate("DeleteWord", "Cancel")) self.deleteword_cancel.clicked.connect(self.CloseDeleteWizard) self.deleteword_ok.clicked.connect(self.DeleteFinal)
class Ui_SpecificCatagory_Manager(threading.Thread): default_state = 0 DatabaseDeleted = False def __init__(self, database_name): self.database_name = database_name self.catagory_desc = "" self.catagory_name = self.database_name.split(".db")[0] try: print("in try ") with open("catadetails", "r") as fp: self.catadetail = fp.readlines() for eachline in self.catadetail: print("in for loop") eachline = eachline.replace('\n', '') print("checking %s in %s" % (self.catagory_name, eachline)) if self.catagory_name in eachline: self.catagory_desc = eachline.split(":")[1] else: pass except: pass threading.Thread.__init__(self) print("dbname : ", self.database_name) refreshthread = threading.Thread(target=self.RefreshContents, daemon=True) refreshthread.start() def RefreshContents(self): self.DbObj = DatabaseManagement(self.database_name) self.DbObj.CreateTable() while True: if Ui_SpecificCatagory_Manager.DatabaseDeleted: self.DbObj.DeleteDatabase() Ui_SpecificCatagory_Manager.DatabaseDeleted = False else: sleep(0.5) self.DatabaseDetails = self.DbObj.FetchData() self.opened_cata_tableWidget.clearContents() if len(self.DatabaseDetails) != 0: for rowno, rowdata in enumerate(self.DatabaseDetails): for colno, coldata in enumerate(rowdata): self.opened_cata_tableWidget.setItem( rowno, colno, QtWidgets.QTableWidgetItem(str(coldata))) def AddWordWizard(self): self.AddWord_ = QtWidgets.QDialog() self.AddWordUI = Ui_AddWord_(self.database_name) self.AddWordUI.setupUi(self.AddWord_) self.AddWord_.show() def setupUi(self, SpecificCatagory_Manager): self.SpecificCatagory_Manager = SpecificCatagory_Manager self.SpecificCatagory_Manager.setObjectName("SpecificCatagory_Manager") self.SpecificCatagory_Manager.resize(1119, 713) self.SpecificCatagory_Manager.setAcceptDrops(False) self.centralwidget = QtWidgets.QWidget(self.SpecificCatagory_Manager) self.centralwidget.setObjectName("centralwidget") self.opened_cata_banner = QtWidgets.QLabel(self.centralwidget) self.opened_cata_banner.setGeometry(QtCore.QRect(380, 10, 281, 51)) font = QtGui.QFont() font.setFamily("Nokia Standard Light") font.setPointSize(30) self.opened_cata_banner.setFont(font) self.opened_cata_banner.setObjectName("opened_cata_banner") self.line = QtWidgets.QFrame(self.centralwidget) self.line.setGeometry(QtCore.QRect(30, 110, 1061, 20)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.opened_cata_punchline = QtWidgets.QLabel(self.centralwidget) self.opened_cata_punchline.setGeometry(QtCore.QRect(220, 80, 601, 20)) self.opened_cata_punchline.setObjectName("opened_cata_punchline") self.line_2 = QtWidgets.QFrame(self.centralwidget) self.line_2.setGeometry(QtCore.QRect(873, 150, 20, 481)) self.line_2.setFrameShape(QtWidgets.QFrame.VLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.verticalLayoutWidget.setGeometry(QtCore.QRect(910, 170, 160, 461)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.opened_cata_details = QtWidgets.QPushButton( self.verticalLayoutWidget) self.opened_cata_details.setObjectName("opened_cata_details") self.verticalLayout.addWidget(self.opened_cata_details) self.opened_cata_addword = QtWidgets.QPushButton( self.verticalLayoutWidget) self.opened_cata_addword.setObjectName("opened_cata_addword") self.verticalLayout.addWidget(self.opened_cata_addword) self.opened_cata_removeword = QtWidgets.QPushButton( self.verticalLayoutWidget) self.opened_cata_removeword.setObjectName("opened_cata_removeword") self.verticalLayout.addWidget(self.opened_cata_removeword) self.opened_cata_deletecatagory = QtWidgets.QPushButton( self.verticalLayoutWidget) self.opened_cata_deletecatagory.setObjectName( "opened_cata_deletecatagory") self.verticalLayout.addWidget(self.opened_cata_deletecatagory) self.opened_cata_tableWidget = QtWidgets.QTableWidget( self.centralwidget) self.opened_cata_tableWidget.setSizeAdjustPolicy( QtWidgets.QAbstractScrollArea.AdjustToContents) self.opened_cata_tableWidget.setGeometry( QtCore.QRect(100, 170, 761, 471)) self.opened_cata_tableWidget.setRowCount(1000) self.opened_cata_tableWidget.setColumnCount(4) self.opened_cata_tableWidget.setObjectName("opened_cata_tableWidget") self.opened_cata_tableWidget.horizontalHeader().setDefaultSectionSize( 200) self.opened_cata_tableWidget.horizontalHeader().setMinimumSectionSize( 0) self.opened_cata_tableWidget.horizontalHeader().setSortIndicatorShown( False) self.opened_cata_tableWidget.horizontalHeader().setStretchLastSection( True) self.opened_cata_tableWidget.verticalHeader( ).setCascadingSectionResizes(False) self.opened_cata_tableWidget.verticalHeader().setDefaultSectionSize(40) self.opened_cata_tableWidget.verticalHeader().setMinimumSectionSize(40) self.SpecificCatagory_Manager.setCentralWidget(self.centralwidget) self.opened_cata_tableWidget.setHorizontalHeaderLabels( ["Id", "Word", "Synonym", "Meaning"]) self.statusbar = QtWidgets.QStatusBar(self.SpecificCatagory_Manager) self.statusbar.setObjectName("statusbar") self.SpecificCatagory_Manager.setStatusBar(self.statusbar) self.retranslateUi(self.SpecificCatagory_Manager) QtCore.QMetaObject.connectSlotsByName(self.SpecificCatagory_Manager) def RemoveParticularWord(self): self.DeleteWord = QtWidgets.QDialog() self.DeleteUI = Ui_DeleteWord(self.database_name) self.DeleteUI.setupUi(self.DeleteWord) self.DeleteWord.show() def RemoveCatagory(self): Ui_SpecificCatagory_Manager.DatabaseDeleted = True self.SpecificCatagory_Manager.close() self.del_dbSignal = self.database_name + ".del" with open(self.del_dbSignal, 'w') as qp: qp.write("DeleteCatagory:OK") def ShowDetails(self): self.Details = QtWidgets.QDialog() self.DetailsUI = Ui_Details(self.catagory_name, self.catagory_desc) self.DetailsUI.setupUi(self.Details) self.Details.show() def retranslateUi(self, SpecificCatagory_Manager): _translate = QtCore.QCoreApplication.translate SpecificCatagory_Manager.setWindowTitle( _translate("SpecificCatagory_Manager", "Vocabuilder")) self.opened_cata_banner.setText( _translate("SpecificCatagory_Manager", "Vocabuilder")) self.opened_cata_punchline.setText( _translate( "SpecificCatagory_Manager", " - Here you will be able to keep track of learned words and also to manage the catagory you\'ve selected." )) self.opened_cata_details.setText( _translate("SpecificCatagory_Manager", "Details")) self.opened_cata_addword.setText( _translate("SpecificCatagory_Manager", "Add Word")) self.opened_cata_removeword.setText( _translate("SpecificCatagory_Manager", "Remove Word")) self.opened_cata_deletecatagory.setText( _translate("SpecificCatagory_Manager", "Delete Catagory")) self.opened_cata_deletecatagory.clicked.connect(self.RemoveCatagory) self.opened_cata_addword.clicked.connect(self.AddWordWizard) self.opened_cata_removeword.clicked.connect(self.RemoveParticularWord) self.opened_cata_details.clicked.connect(self.ShowDetails)
class Ui_AddWord_(object): def __init__(self,databasename): self.databasename=databasename def setupUi(self, AddWord_): self.AddWord_ = AddWord_ self.AddWord_.setObjectName("AddWord_") self.AddWord_.resize(640, 483) self.addword_label = QtWidgets.QLabel(AddWord_) self.addword_label.setGeometry(QtCore.QRect(130, 20, 341, 61)) font = QtGui.QFont() font.setFamily("Nokia Standard Light") font.setPointSize(30) self.addword_label.setFont(font) self.addword_label.setObjectName("addword_label") self.addword_punchline = QtWidgets.QLabel(self.AddWord_) self.addword_punchline.setGeometry(QtCore.QRect(160, 60, 651, 91)) self.addword_punchline.setObjectName("addword_punchline") self.line = QtWidgets.QFrame(AddWord_) self.line.setGeometry(QtCore.QRect(30, 130, 561, 20)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.gridLayoutWidget = QtWidgets.QWidget(self.AddWord_) self.gridLayoutWidget.setGeometry(QtCore.QRect(60, 190, 521, 211)) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.gridLayoutWidget.setFont(font) self.gridLayoutWidget.setObjectName("gridLayoutWidget") self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setObjectName("gridLayout") self.additem_meaning = QtWidgets.QLineEdit(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.additem_meaning.setFont(font) self.additem_meaning.setObjectName("additem_meaning") self.gridLayout.addWidget(self.additem_meaning, 2, 1, 1, 1, QtCore.Qt.AlignHCenter) self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1, QtCore.Qt.AlignHCenter) self.addword_inputsynonym = QtWidgets.QLineEdit(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.addword_inputsynonym.setFont(font) self.addword_inputsynonym.setObjectName("addword_inputsynonym") self.gridLayout.addWidget(self.addword_inputsynonym, 1, 1, 1, 1, QtCore.Qt.AlignHCenter) self.addword_inputneword = QtWidgets.QLineEdit(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.addword_inputneword.setFont(font) self.addword_inputneword.setStyleSheet("color:green;") self.addword_inputneword.setObjectName("addword_inputneword") self.gridLayout.addWidget(self.addword_inputneword, 0, 1, 1, 1, QtCore.Qt.AlignHCenter) self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1, QtCore.Qt.AlignHCenter) self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget) font = QtGui.QFont() font.setFamily("Segoe UI Historic") self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.gridLayout.addWidget(self.label_5, 0, 0, 1, 1, QtCore.Qt.AlignHCenter) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.addword_ok = QtWidgets.QPushButton(self.gridLayoutWidget) self.addword_ok.setObjectName("addword_ok") self.horizontalLayout.addWidget(self.addword_ok) self.addword_cancel = QtWidgets.QPushButton(self.gridLayoutWidget) self.addword_cancel.setObjectName("addword_cancel") self.horizontalLayout.addWidget(self.addword_cancel) self.gridLayout.addLayout(self.horizontalLayout, 3, 1, 1, 1) self.retranslateUi(AddWord_) QtCore.QMetaObject.connectSlotsByName(self.AddWord_) def AddWordEntryToDatabase(self): defaultpointervalue = int(0) if path.isdir("DATA"): try: chdir("DATA") except: pass if not path.isfile("position"): with open("position","w") as ap: ap.write("%d"%defaultpointervalue) self.DbObj = DatabaseManagement(self.databasename) self.DbObj.CreateTable() with open("position","r") as gp: self.databaseposition = int(gp.read()) self.databasePosition = self.databaseposition + 1 #self.databasePosition = len(self.DbObj.FetchData()) + 1 self.newword = self.addword_inputneword.text() self.newword_syn = self.addword_inputsynonym.text() self.newword_mean = self.additem_meaning.text() if len(self.newword) == 0 or len(self.newword_mean) == 0: #!it should raise error as requisite information is not given. self.error_msgBox = QMessageBox() self.error_msgBox.setIcon(QMessageBox.Critical) self.error_msgBox.setText("Please Input Required information To Save New Word.") self.error_msgBox.setWindowTitle("Complete Details Not Provided") self.error_msgBox.setStandardButtons(QMessageBox.Ok) self.error_msgBox.show() pass else: with open("position","w") as lp: lp.write("%d"%self.databasePosition) self.DbObj.InsertNewDetails(self.databasePosition,self.newword,self.newword_syn,self.newword_mean) self.AddWord_.close() def CloseAddWord(self): self.AddWord_.close() def retranslateUi(self, AddWord_): _translate = QtCore.QCoreApplication.translate AddWord_.setWindowTitle(_translate("AddWord_", "Add Word Wizard (Vocabuilder)")) self.addword_label.setText(_translate("AddWord_", "Vocabuilder")) self.addword_punchline.setText(_translate("AddWord_", " - Add Your Vocabulary Findings Here To Remember Them Forever.")) self.label_3.setText(_translate("AddWord_", "Synonym (If Any ) : ")) self.label_4.setText(_translate("AddWord_", "Actual Meaning : ")) self.label_5.setText(_translate("AddWord_", "New Word : ")) self.addword_ok.setText(_translate("AddWord_", "Add")) self.addword_cancel.setText(_translate("AddWord_", "Cancel")) self.addword_cancel.clicked.connect(self.CloseAddWord) self.addword_ok.clicked.connect(self.AddWordEntryToDatabase)