def codeMemo(self): """ Add a memo to the selected code """ if self.filename == {}: QtGui.QMessageBox.warning(None, 'Warning', "No file was selected", QtGui.QMessageBox.Ok) return location = self.textEd.textCursor().selectionStart() codehere = None for item in self.coding: if location >= item['selfirst'] and location <= item['selend']: codehere = item if codehere is None: return Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(codehere['memo']) ui.setupUi( Dialog_memo, "Memo the code here <" + str(codehere['selfirst']) + " - " + str(codehere['selend']) + "> ") Dialog_memo.exec_() memo = ui.getMemo() cur = self.settings['conn'].cursor() cur.execute( "update " + self.settings['codertable'] + " set memo=? where cid=? and selfirst =? and selend =?", (memo, codehere['cid'], codehere['selfirst'], codehere['selend'])) self.settings['conn'].commit() # why are these here ? self.unlight() self.highlight()
def codeMemo(self): """ Add a memo to the selected code """ if self.filename == {}: QtGui.QMessageBox.warning(None, "Warning", "No file was selected", QtGui.QMessageBox.Ok) return location = self.textEd.textCursor().selectionStart() codehere = None for item in self.coding: if location >= item["selfirst"] and location <= item["selend"]: codehere = item if codehere is None: return Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(codehere["memo"]) ui.setupUi( Dialog_memo, "Memo the code here <" + str(codehere["selfirst"]) + " - " + str(codehere["selend"]) + "> " ) Dialog_memo.exec_() memo = ui.getMemo() cur = self.settings["conn"].cursor() cur.execute( "update " + self.settings["codertable"] + " set memo=? where cid=? and selfirst =? and selend =?", (memo, codehere["cid"], codehere["selfirst"], codehere["selend"]), ) self.settings["conn"].commit() # why are these here ? self.unlight() self.highlight()
def cellSelected(self): """ When the table widget memo cell is selected display the memo. Update memo text, or delete memo by clearing text. If a new memo also show in table widget by displaying YES in the memo column""" x = self.tableWidget.currentRow() y = self.tableWidget.currentColumn() if y == self.MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.attributes[x]['memo']) ui.setupUi(Dialog_memo, "Attribute memo " + self.attributes[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem()) else: self.tableWidget.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) # update attributes list and database self.attributes[x]['memo'] = str(memo).encode('raw_unicode_escape') cur = self.settings['conn'].cursor() cur.execute("update attributes set memo=? where name=?", (self.attributes[x]['memo'], self.attributes[x]['name'])) self.settings['conn'].commit()
def catsCellSelected(self): """ Open a memo dialog if a category memo cell is selected """ x = self.tableWidget_cats.currentRow() y = self.tableWidget_cats.currentColumn() # category memo column if y == self.CAT_MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.cats[x]['memo']) ui.setupUi(Dialog_memo, "Category memo " + self.cats[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_cats.setItem(x, self.CAT_MEMO_COLUMN, QtGui.QTableWidgetItem()) else: self.tableWidget_cats.setItem(x, self.CAT_MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) #update cats list and database self.cats[x]['memo'] = str(memo) cur = self.settings['conn'].cursor() cur.execute("update codecat set memo=? where catid=?", (self.cats[x]['memo'], self.cats[x]['catid'])) self.settings['conn'].commit() # view codes for this category if y == self.CAT_VIEW_COLUMN: # important need to unselect all codes in tableWidget if self.selectedCategoryId == -1: # all categories currently displayed, so change this to selected category self.pushButton_link.setEnabled(False) self.pushButton_unlink.setEnabled(True) self.selectedCategoryId = int(self.tableWidget_cats.item(x, self.CAT_ID_COLUMN).text()) for (row, item) in enumerate(self.cats): if self.selectedCategoryId != int(self.tableWidget_cats.item(row, self.CAT_ID_COLUMN).text()): self.tableWidget_cats.hideRow(row) # hide other categories # now show codes associated with this category for(row, item) in enumerate(self.freecode): hide = True for treeCodeItem in self.treecode: #print(str(treeCodeItem['catid'])+" "+str(self.selectedCategoryId)+" co:"+str(treeCodeItem['cid'])+" "+str(item['id'])) if int(treeCodeItem['catid']) == self.selectedCategoryId and treeCodeItem['cid'] == item['id']: hide = False if hide: self.tableWidget_codes.hideRow(row) else: self.selectedCategoryId = -1 self.pushButton_link.setEnabled(True) self.pushButton_unlink.setEnabled(False) for (row, item) in enumerate(self.cats): self.tableWidget_cats.showRow(row) for(row, item) in enumerate(self.freecode): self.tableWidget_codes.showRow(row) # need to clear selection in category table when showing all rows # as there are no selected items but the previous view cell appears selected self.tableWidget_cats.clearSelection()
def cellSelected(self): """ When the table widget memo cell is selected display the memo. Update memo text, or delete memo by clearing text. If a new memo also show in table widget by displaying YES in the memo column """ x = self.tableWidget_cases.currentRow() y = self.tableWidget_cases.currentColumn() if x == -1: self.selectedCase = None self.textEd.clear() self.caseLinks = [] else: self.selectedCase = self.cases[x] # clear case text viewed if the caseid has changed if self.caseTextViewed != [] and self.caseTextViewed[0]['caseid'] != self.selectedCase['id']: self.caseTextViewed = [] self.caseLinks = [] self.textEd.clear() self.unlight() #print("Selected case: " + str(self.selectedCase['id']) +" "+self.selectedCase['name']) # get caselinks for this file if self.selectedFile is not None: #print("File Selected: " + str(self.selectedFile['id'])+" "+self.selectedFile['file']) self.caseLinks = [] cur = self.settings['conn'].cursor() cur.execute("select caseid, fid, selfirst, selend, status, owner, date, memo from caselinkage where fid = ? and caseid = ?", [self.selectedFile['id'], self.selectedCase['id']]) result = cur.fetchall() for row in result: self.caseLinks.append({'caseid':row[0], 'fid':row[1], 'selfirst':row[2], 'selend':row[3], 'status':row[4], 'owner':row[5], 'date':row[6], 'memo':row[7]}) self.highlight() if y == self.MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.cases[x]['memo']) ui.setupUi(Dialog_memo, "File memo " + self.cases[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_cases.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem()) else: self.tableWidget_cases.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) # update cases list and database self.cases[x]['memo'] = str(memo).encode('raw_unicode_escape') cur = self.settings['conn'].cursor() cur.execute("update cases set memo=? where id=?", (self.cases[x]['memo'], self.cases[x]['id'])) self.settings['conn'].commit()
def createJournal(self): """ Create a new journal by entering text into the dialog """ Dialog_text = QtGui.QDialog() ui = Ui_Dialog_memo("") ui.setupUi(Dialog_text, "New journal") Dialog_text.exec_() newText = ui.getMemo() journalName = ui.getFilename() if journalName is None or journalName == "": QtGui.QMessageBox.warning(None, "Warning", "No journal name selected") return #check for non-unique filename if any(d['name'] == journalName for d in self.journals): QtGui.QMessageBox.warning(None, "Warning", str(journalName) + " is already in use") return # update database newJrnl = { 'name': journalName, 'journal': newText, 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM': "", 'status': 1 } cur = self.settings['conn'].cursor() cur.execute( "insert into journal(name,journal,owner,date,dateM,status) values(?,?,?,?,?,?)", (newJrnl['name'], newJrnl['journal'], newJrnl['owner'], newJrnl['date'], newJrnl['dateM'], newJrnl['status'])) self.settings['conn'].commit() self.log += "Journal " + newJrnl['name'] + " created\n" # clear and refill table widget for r in self.journals: self.tableWidget_journals.removeRow(0) self.journals.append(newJrnl) for row, itm in enumerate(self.journals): self.tableWidget_journals.insertRow(row) item = QtGui.QTableWidgetItem(itm['name']) self.tableWidget_journals.setItem(row, self.NAME_COLUMN, item) item = QtGui.QTableWidgetItem(itm['date']) self.tableWidget_journals.setItem(row, self.DATE_COLUMN, item) self.tableWidget_journals.resizeColumnsToContents() self.tableWidget_journals.resizeRowsToContents()
def projectMemo(self): """ Give the entire project a memo """ if self.settings["projectName"] == "": QtGui.QMessageBox.warning(None, "No Project","You need to load or create a project first.") return Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.project['memo']) ui.setupUi(Dialog_memo, "Project memo " + self.settings['projectName']) Dialog_memo.exec_() self.project['memo'] = ui.getMemo() cur = self.settings['conn'].cursor() cur.execute("update project set memo=?", [str(self.project['memo'])]) self.settings['conn'].commit() self.logWidget.textEdit.append("Project memo entered")
def createFile(self): """ Create a new text file by entering text into the dialog """ Dialog_text = QtGui.QDialog() ui = Ui_Dialog_memo("") ui.setupUi(Dialog_text, "New file") Dialog_text.exec_() fileText = ui.getMemo() fileName = ui.getFilename() if fileName == None or fileName == "": QtGui.QMessageBox.warning(None, 'Warning',"No filename was selected", QtGui.QMessageBox.Ok) return #check for non-unique filename if any(d['name'] == fileName for d in self.sourcetext): QtGui.QMessageBox.warning(None, 'Warning',"Filename in use", QtGui.QMessageBox.Ok) return # increment fileId until a spare id is available fileId = 1 while any(d['id'] == fileId for d in self.sourcetext): fileId = fileId + 1 # update database newFile = {'name':fileName, 'id':fileId, 'file': fileText, 'memo':"", 'owner':self.settings['codername'], 'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM':"", 'status':1} cur = self.settings['conn'].cursor() cur.execute("insert into source(name,id,file,memo,owner,date,dateM,status) values(?,?,?,?,?,?,?,?)", (newFile['name'],newFile['id'],newFile['file'],newFile['memo'],newFile['owner'],newFile['date'],newFile['dateM'],newFile['status'])) self.settings['conn'].commit() self.log +=newFile['name'] + " added.\n" # clear and refill table widget for r in self.sourcetext: self.tableWidget_files.removeRow(0) self.sourcetext.append(newFile) for row, itm in enumerate(self.sourcetext): self.tableWidget_files.insertRow(row) item = QtGui.QTableWidgetItem(itm['name']) self.tableWidget_files.setItem(row,self.NAME_COLUMN, item) item = QtGui.QTableWidgetItem(itm['date']) self.tableWidget_files.setItem(row,self.DATE_COLUMN, item) if itm['memo'] != None and itm['memo'] != "": self.tableWidget_files.setItem(row, self.MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) item = QtGui.QTableWidgetItem(str(itm['id'])) self.tableWidget_files.setItem(row, self.ID_COLUMN, item) self.tableWidget_files.resizeColumnsToContents() self.tableWidget_files.resizeRowsToContents()
def projectMemo(self): """ Give the entire project a memo """ if self.settings["projectName"] == "": QtGui.QMessageBox.warning( None, "No Project", "You need to load or create a project first.") return Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.project['memo']) ui.setupUi(Dialog_memo, "Project memo " + self.settings['projectName']) Dialog_memo.exec_() self.project['memo'] = ui.getMemo() cur = self.settings['conn'].cursor() cur.execute("update project set memo=?", [str(self.project['memo'])]) self.settings['conn'].commit() self.logWidget.textEdit.append("Project memo entered")
def viewFile(self): """ View and edit the file contents """ x = self.tableWidget_files.currentRow() Dialog_memo = QtGui.QDialog() text = self.sourcetext[x]['file'] ui = Ui_Dialog_memo(text) ui.setupUi(Dialog_memo, "View file: " + self.sourcetext[x]['name'] +" (ID:"+ str(self.sourcetext[x]['id'])+") " +self.sourcetext[x]['owner'] + ", " + self.sourcetext[x]['date']) Dialog_memo.exec_() # update model and database fileText = ui.getMemo() ## unicode if fileText != self.sourcetext[x]['file']: # NEED TO CHECK THAT THERE ARE NO CODES OR ANNOATIONS OR CASES LINKED TO THIS FILE BEFORE COMMITING CHANGE # CHECK NOT YET IMPLEMENTED self.sourcetext[x]['file'] = fileText cur = self.settings['conn'].cursor() cur.execute("update source set file=? where id=?", (fileText, self.sourcetext[x]['id'])) self.settings['conn'].commit()
def viewJournal(self): """ View and edit journal contents """ x = self.tableWidget_journals.currentRow() Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.journals[x]['journal']) ui.setupUi(Dialog_memo, self.journals[x]['name'] +" "+ self.journals[x]['owner'] +", "+self.journals[x]['date']) Dialog_memo.exec_() # update model and database newText = ui.getMemo() newText = newText.decode('unicode-escape') try: pass newText = newText.decode("utf-8", "replace") except UnicodeDecodeError: print("unicode error") if newText != self.journals[x]['journal']: self.journals[x]['journal'] = newText cur = self.settings['conn'].cursor() cur.execute("update journal set journal=? where name=?", (newText, self.journals[x]['name'])) self.settings['conn'].commit()
def viewFile(self): """ View and edit the file contents """ x = self.tableWidget_files.currentRow() Dialog_memo = QtGui.QDialog() text = self.sourcetext[x]['file'] ui = Ui_Dialog_memo(text) ui.setupUi( Dialog_memo, "View file: " + self.sourcetext[x]['name'] + " (ID:" + str(self.sourcetext[x]['id']) + ") " + self.sourcetext[x]['owner'] + ", " + self.sourcetext[x]['date']) Dialog_memo.exec_() # update model and database fileText = ui.getMemo() ## unicode if fileText != self.sourcetext[x]['file']: # NEED TO CHECK THAT THERE ARE NO CODES OR ANNOATIONS OR CASES LINKED TO THIS FILE BEFORE COMMITING CHANGE # CHECK NOT YET IMPLEMENTED self.sourcetext[x]['file'] = fileText cur = self.settings['conn'].cursor() cur.execute("update source set file=? where id=?", (fileText, self.sourcetext[x]['id'])) self.settings['conn'].commit()
def fileCellSelected(self): """ When memo cells are selected in the table widget, open a memo dialog """ x = self.tableWidget_files.currentRow() y = self.tableWidget_files.currentColumn() if y == self.FILE_MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.source[x]['memo']) ui.setupUi(Dialog_memo, "File memo "+ self.source[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_files.setItem(x, 1, QtGui.QTableWidgetItem()) else: self.tableWidget_files.setItem(x, 1, QtGui.QTableWidgetItem("Yes")) #update source list and database self.source[x]['memo'] = str(memo) cur = self.settings['conn'].cursor() cur.execute("update source set memo=? where id=?", (self.source[x]['memo'], self.source[x]['id'])) self.settings['conn'].commit()
def createJournal(self): """ Create a new journal by entering text into the dialog """ Dialog_text = QtGui.QDialog() ui = Ui_Dialog_memo("") ui.setupUi(Dialog_text, "New journal") Dialog_text.exec_() newText = ui.getMemo() journalName = ui.getFilename() if journalName is None or journalName == "": QtGui.QMessageBox.warning(None, "Warning", "No journal name selected") return #check for non-unique filename if any(d['name'] == journalName for d in self.journals): QtGui.QMessageBox.warning(None, "Warning", str(journalName) + " is already in use") return # update database newJrnl = {'name':journalName, 'journal': newText, 'owner':self.settings['codername'], 'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM':"", 'status':1} cur = self.settings['conn'].cursor() cur.execute("insert into journal(name,journal,owner,date,dateM,status) values(?,?,?,?,?,?)", (newJrnl['name'],newJrnl['journal'],newJrnl['owner'],newJrnl['date'],newJrnl['dateM'],newJrnl['status'])) self.settings['conn'].commit() self.log += "Journal " + newJrnl['name'] + " created\n" # clear and refill table widget for r in self.journals: self.tableWidget_journals.removeRow(0) self.journals.append(newJrnl) for row, itm in enumerate(self.journals): self.tableWidget_journals.insertRow(row) item = QtGui.QTableWidgetItem(itm['name']) self.tableWidget_journals.setItem(row, self.NAME_COLUMN, item) item = QtGui.QTableWidgetItem(itm['date']) self.tableWidget_journals.setItem(row, self.DATE_COLUMN, item) self.tableWidget_journals.resizeColumnsToContents() self.tableWidget_journals.resizeRowsToContents()
def viewJournal(self): """ View and edit journal contents """ x = self.tableWidget_journals.currentRow() Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.journals[x]['journal']) ui.setupUi( Dialog_memo, self.journals[x]['name'] + " " + self.journals[x]['owner'] + ", " + self.journals[x]['date']) Dialog_memo.exec_() # update model and database newText = ui.getMemo() newText = newText.decode('unicode-escape') try: pass newText = newText.decode("utf-8", "replace") except UnicodeDecodeError: print("unicode error") if newText != self.journals[x]['journal']: self.journals[x]['journal'] = newText cur = self.settings['conn'].cursor() cur.execute("update journal set journal=? where name=?", (newText, self.journals[x]['name'])) self.settings['conn'].commit()
def fileCellSelected(self): """ When memo cells are selected in the table widget, open a memo dialog """ x = self.tableWidget_files.currentRow() y = self.tableWidget_files.currentColumn() if y == self.FILE_MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.source[x]['memo']) ui.setupUi(Dialog_memo, "File memo " + self.source[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_files.setItem(x, 1, QtGui.QTableWidgetItem()) else: self.tableWidget_files.setItem(x, 1, QtGui.QTableWidgetItem("Yes")) #update source list and database self.source[x]['memo'] = str(memo) cur = self.settings['conn'].cursor() cur.execute("update source set memo=? where id=?", (self.source[x]['memo'], self.source[x]['id'])) self.settings['conn'].commit()
def annotate(self): """ Add an annotation: or memo text to the current cursor position. The position is at a point infornt of the cursor. Annotations are displayed as a bolded character when text is highlighted """ annotation = "" details = "" item = None if self.filename == {}: QtGui.QMessageBox.warning(None, "Warning", "No file was selected", QtGui.QMessageBox.Ok) return selstart = self.textEd.textCursor().selectionStart() textLength = len(self.textEd.toPlainText()) if selstart >= textLength: return for note in self.annotations: if note["position"] == selstart and note["fid"] == self.filename["id"]: item = note # use existing annotation details = item["owner"] + " " + item["date"] # add new item to annotations, add to database and update GUI if item is None: # item = {'fid': int(self.filename['id']), 'position': selstart, 'annotation': str(annotation), 'owner':self.settings['codername'], 'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM':None, 'status':1} item = { "fid": int(self.filename["id"]), "position": selstart, "annotation": annotation, "owner": self.settings["codername"], "date": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), "dateM": None, "status": 1, } Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(item["annotation"]) ui.setupUi(Dialog_memo, "Annotation: " + details) Dialog_memo.exec_() item["annotation"] = ui.getMemo() # if blank then delete the annotation if item["annotation"] == "": cur = self.settings["conn"].cursor() cur.execute("delete from annotation where position = ?", (item["position"],)) # note comma, this is a tuple self.settings["conn"].commit() for note in self.annotations: if note["position"] == item["position"] and note["fid"] == item["fid"]: self.annotations.remove(note) self.unlight() self.highlight() if item["annotation"] != "": self.annotations.append(item) self.highlight() cur = self.settings["conn"].cursor() ##cur.execute("insert into annotation"+" (fid,position,annotation,owner,date,dateM,status) values(?,?,?,?,?,?,?)" ## ,(item['fid'],item['position'],item['annotation'].encode('raw_unicode_escape'),item['owner'],item['date'],item['dateM'],item['status'])) cur.execute( "insert into annotation" + " (fid,position,annotation,owner,date,dateM,status) values(?,?,?,?,?,?,?)", ( item["fid"], item["position"], item["annotation"], item["owner"], item["date"], item["dateM"], item["status"], ), ) self.settings["conn"].commit()
def annotate(self): """ Add an annotation: or memo text to the current cursor position. The position is at a point infornt of the cursor. Annotations are displayed as a bolded character when text is highlighted """ annotation = "" details = "" item = None if self.filename == {}: QtGui.QMessageBox.warning(None, 'Warning', "No file was selected", QtGui.QMessageBox.Ok) return selstart = self.textEd.textCursor().selectionStart() textLength = len(self.textEd.toPlainText()) if selstart >= textLength: return for note in self.annotations: if note['position'] == selstart and note['fid'] == self.filename[ 'id']: item = note # use existing annotation details = item['owner'] + " " + item['date'] # add new item to annotations, add to database and update GUI if item is None: #item = {'fid': int(self.filename['id']), 'position': selstart, 'annotation': str(annotation), 'owner':self.settings['codername'], 'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM':None, 'status':1} item = { 'fid': int(self.filename['id']), 'position': selstart, 'annotation': annotation, 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM': None, 'status': 1 } Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(item['annotation']) ui.setupUi(Dialog_memo, "Annotation: " + details) Dialog_memo.exec_() item['annotation'] = ui.getMemo() # if blank then delete the annotation if item['annotation'] == "": cur = self.settings['conn'].cursor() cur.execute("delete from annotation where position = ?", (item['position'], )) # note comma, this is a tuple self.settings['conn'].commit() for note in self.annotations: if note['position'] == item['position'] and note[ 'fid'] == item['fid']: self.annotations.remove(note) self.unlight() self.highlight() if item['annotation'] != "": self.annotations.append(item) self.highlight() cur = self.settings['conn'].cursor() ##cur.execute("insert into annotation"+" (fid,position,annotation,owner,date,dateM,status) values(?,?,?,?,?,?,?)" ## ,(item['fid'],item['position'],item['annotation'].encode('raw_unicode_escape'),item['owner'],item['date'],item['dateM'],item['status'])) cur.execute( "insert into annotation" + " (fid,position,annotation,owner,date,dateM,status) values(?,?,?,?,?,?,?)", (item['fid'], item['position'], item['annotation'], item['owner'], item['date'], item['dateM'], item['status'])) self.settings['conn'].commit()
def catsCellSelected(self): """ Open a memo dialog if a category memo cell is selected """ x = self.tableWidget_cats.currentRow() y = self.tableWidget_cats.currentColumn() # category memo column if y == self.CAT_MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.cats[x]['memo']) ui.setupUi(Dialog_memo, "Category memo " + self.cats[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_cats.setItem(x, self.CAT_MEMO_COLUMN, QtGui.QTableWidgetItem()) else: self.tableWidget_cats.setItem(x, self.CAT_MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) #update cats list and database self.cats[x]['memo'] = str(memo) cur = self.settings['conn'].cursor() cur.execute("update codecat set memo=? where catid=?", (self.cats[x]['memo'], self.cats[x]['catid'])) self.settings['conn'].commit() # view codes for this category if y == self.CAT_VIEW_COLUMN: # important need to unselect all codes in tableWidget if self.selectedCategoryId == -1: # all categories currently displayed, so change this to selected category self.pushButton_link.setEnabled(False) self.pushButton_unlink.setEnabled(True) self.selectedCategoryId = int( self.tableWidget_cats.item(x, self.CAT_ID_COLUMN).text()) for (row, item) in enumerate(self.cats): if self.selectedCategoryId != int( self.tableWidget_cats.item( row, self.CAT_ID_COLUMN).text()): self.tableWidget_cats.hideRow( row) # hide other categories # now show codes associated with this category for (row, item) in enumerate(self.freecode): hide = True for treeCodeItem in self.treecode: #print(str(treeCodeItem['catid'])+" "+str(self.selectedCategoryId)+" co:"+str(treeCodeItem['cid'])+" "+str(item['id'])) if int(treeCodeItem['catid'] ) == self.selectedCategoryId and treeCodeItem[ 'cid'] == item['id']: hide = False if hide: self.tableWidget_codes.hideRow(row) else: self.selectedCategoryId = -1 self.pushButton_link.setEnabled(True) self.pushButton_unlink.setEnabled(False) for (row, item) in enumerate(self.cats): self.tableWidget_cats.showRow(row) for (row, item) in enumerate(self.freecode): self.tableWidget_codes.showRow(row) # need to clear selection in category table when showing all rows # as there are no selected items but the previous view cell appears selected self.tableWidget_cats.clearSelection()
def createFile(self): """ Create a new text file by entering text into the dialog """ Dialog_text = QtGui.QDialog() ui = Ui_Dialog_memo("") ui.setupUi(Dialog_text, "New file") Dialog_text.exec_() fileText = ui.getMemo() fileName = ui.getFilename() if fileName == None or fileName == "": QtGui.QMessageBox.warning(None, 'Warning', "No filename was selected", QtGui.QMessageBox.Ok) return #check for non-unique filename if any(d['name'] == fileName for d in self.sourcetext): QtGui.QMessageBox.warning(None, 'Warning', "Filename in use", QtGui.QMessageBox.Ok) return # increment fileId until a spare id is available fileId = 1 while any(d['id'] == fileId for d in self.sourcetext): fileId = fileId + 1 # update database newFile = { 'name': fileName, 'id': fileId, 'file': fileText, 'memo': "", 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'dateM': "", 'status': 1 } cur = self.settings['conn'].cursor() cur.execute( "insert into source(name,id,file,memo,owner,date,dateM,status) values(?,?,?,?,?,?,?,?)", (newFile['name'], newFile['id'], newFile['file'], newFile['memo'], newFile['owner'], newFile['date'], newFile['dateM'], newFile['status'])) self.settings['conn'].commit() self.log += newFile['name'] + " added.\n" # clear and refill table widget for r in self.sourcetext: self.tableWidget_files.removeRow(0) self.sourcetext.append(newFile) for row, itm in enumerate(self.sourcetext): self.tableWidget_files.insertRow(row) item = QtGui.QTableWidgetItem(itm['name']) self.tableWidget_files.setItem(row, self.NAME_COLUMN, item) item = QtGui.QTableWidgetItem(itm['date']) self.tableWidget_files.setItem(row, self.DATE_COLUMN, item) if itm['memo'] != None and itm['memo'] != "": self.tableWidget_files.setItem(row, self.MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) item = QtGui.QTableWidgetItem(str(itm['id'])) self.tableWidget_files.setItem(row, self.ID_COLUMN, item) self.tableWidget_files.resizeColumnsToContents() self.tableWidget_files.resizeRowsToContents()
def cellSelected(self): """ When the table widget memo cell is selected display the memo. Update memo text, or delete memo by clearing text. If a new memo also show in table widget by displaying YES in the memo column """ x = self.tableWidget_cases.currentRow() y = self.tableWidget_cases.currentColumn() if x == -1: self.selectedCase = None self.textEd.clear() self.caseLinks = [] else: self.selectedCase = self.cases[x] # clear case text viewed if the caseid has changed if self.caseTextViewed != [] and self.caseTextViewed[0][ 'caseid'] != self.selectedCase['id']: self.caseTextViewed = [] self.caseLinks = [] self.textEd.clear() self.unlight() #print("Selected case: " + str(self.selectedCase['id']) +" "+self.selectedCase['name']) # get caselinks for this file if self.selectedFile is not None: #print("File Selected: " + str(self.selectedFile['id'])+" "+self.selectedFile['file']) self.caseLinks = [] cur = self.settings['conn'].cursor() cur.execute( "select caseid, fid, selfirst, selend, status, owner, date, memo from caselinkage where fid = ? and caseid = ?", [self.selectedFile['id'], self.selectedCase['id']]) result = cur.fetchall() for row in result: self.caseLinks.append({ 'caseid': row[0], 'fid': row[1], 'selfirst': row[2], 'selend': row[3], 'status': row[4], 'owner': row[5], 'date': row[6], 'memo': row[7] }) self.highlight() if y == self.MEMO_COLUMN: Dialog_memo = QtGui.QDialog() ui = Ui_Dialog_memo(self.cases[x]['memo']) ui.setupUi(Dialog_memo, "File memo " + self.cases[x]['name']) Dialog_memo.exec_() memo = ui.getMemo() if memo == "": self.tableWidget_cases.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem()) else: self.tableWidget_cases.setItem(x, self.MEMO_COLUMN, QtGui.QTableWidgetItem("Yes")) # update cases list and database self.cases[x]['memo'] = str(memo).encode('raw_unicode_escape') cur = self.settings['conn'].cursor() cur.execute("update cases set memo=? where id=?", (self.cases[x]['memo'], self.cases[x]['id'])) self.settings['conn'].commit()