def add_category(self): ''' When button pressed, add a new category. Note: the addItem dialog does the checking for duplicate category names Add the new category as a top level item ''' ui = DialogAddItemName(self.categories, "Category") ui.exec_() newCatText = ui.get_new_name() if newCatText is None: return # add to database item = { 'name': newCatText, 'cid': None, 'memo': "", 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") } cur = self.settings['conn'].cursor() cur.execute( "insert into code_cat (name, memo, owner, date, supercatid) values(?,?,?,?,?)", (item['name'], item['memo'], item['owner'], item['date'], None)) self.settings['conn'].commit() cur.execute("select last_insert_rowid()") catid = cur.fetchone()[0] item['catid'] = catid self.categories.append(item) # update widget top_item = QtWidgets.QTreeWidgetItem( [item['name'], 'catid:' + str(item['catid']), ""]) top_item.setIcon(0, QtGui.QIcon("GUI/icon_cat.png")) self.ui.treeWidget.addTopLevelItem(top_item)
def add_case(self): """ When add case button pressed, open addItem dialog to get the ase name. AddItem dialog checks for duplicate case name. New case is added to the model and database. Attribute placeholders are assigned to the database for this new case. """ ui = DialogAddItemName(self.cases, _("Case")) ui.exec_() newCaseText = ui.get_new_name() if newCaseText is None: return # update case list and database item = {'name': newCaseText, 'memo': "", 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} cur = self.settings['conn'].cursor() cur.execute("insert into cases (name,memo,owner,date) values(?,?,?,?)" ,(item['name'],item['memo'],item['owner'],item['date'])) self.settings['conn'].commit() cur.execute("select last_insert_rowid()") item['caseid'] = cur.fetchone()[0] # add placeholder attribute values cur.execute("select name, valuetype from attribute_type where caseOrFile='case'") atts = cur.fetchall() for att in atts: cur.execute("insert into attribute(name,attr_type,value,id,date,owner) \ values (?,?,?,?,?,?)", (att[0], "case", "", item['caseid'], item['date'], item['owner'])) self.settings['conn'].commit() self.cases.append(item) self.fill_tableWidget() self.parent_textEdit.append(_("Case added: ") + item['name'])
def add_code(self): ''' Use add_item dialog to get new code text. Add_code_name dialog checks for duplicate code name. New code is added to data and database ''' ui = DialogAddItemName(self.codes, "Add new code") ui.exec_() newCodeText = ui.get_new_name() if newCodeText is None: return item = { 'name': newCodeText, 'memo': "", 'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'catid': None, 'color': '#F8E0E0' } cur = self.settings['conn'].cursor() cur.execute( "insert into code_name (name,memo,owner,date,catid,color) values(?,?,?,?,?,?)", (item['name'], item['memo'], item['owner'], item['date'], item['catid'], item['color'])) self.settings['conn'].commit() cur.execute("select last_insert_rowid()") cid = cur.fetchone()[0] item['cid'] = cid self.codes.append(item) top_item = QtWidgets.QTreeWidgetItem( [item['name'], 'cid:' + str(item['cid']), ""]) top_item.setIcon(0, QtGui.QIcon("GUI/icon_code.png")) color = item['color'] top_item.setBackground(0, QBrush(QtGui.QColor(color), Qt.SolidPattern)) self.ui.treeWidget.addTopLevelItem(top_item) self.ui.treeWidget.setCurrentItem(top_item)
def add_category(self): """ Add a new category. Note: the addItem dialog does the checking for duplicate category names Add the new category as a top level item. """ ui = DialogAddItemName(self.app, self.categories, _("Category"), _("Category name")) ui.exec_() newCatText = ui.get_new_name() if newCatText is None: return # add to database item = { 'name': newCatText, 'cid': None, 'memo': "", 'owner': self.app.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") } cur = self.app.conn.cursor() cur.execute( "insert into code_cat (name, memo, owner, date, supercatid) values(?,?,?,?,?)", (item['name'], item['memo'], item['owner'], item['date'], None)) self.app.conn.commit() self.update_dialog_codes_and_categories() self.parent_textEdit.append(_("New category: ") + item['name']) self.app.delete_backup = False
def add_code(self): """ Use add_item dialog to get new code text. Add_code_name dialog checks for duplicate code name. New code is added to data and database. """ ui = DialogAddItemName(self.app, self.codes, _("Add new code"), _("Code name")) ui.exec_() new_code_name = ui.get_new_name() if new_code_name is None: return code_color = colors[randint(0, len(colors) - 1)] item = { 'name': new_code_name, 'memo': "", 'owner': self.app.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'catid': None, 'color': code_color } cur = self.app.conn.cursor() cur.execute( "insert into code_name (name,memo,owner,date,catid,color) values(?,?,?,?,?,?)", (item['name'], item['memo'], item['owner'], item['date'], item['catid'], item['color'])) self.app.conn.commit() self.update_dialog_codes_and_categories() self.parent_textEdit.append(_("New code: ") + item['name']) self.app.delete_backup = False
def create(self): """ Create a new journal by entering text into the dialog. """ self.current_jid = None self.ui.textEdit.setPlainText("") ui = DialogAddItemName(self.app, self.journals, _('New Journal'), _('Journal name')) ui.exec_() name = ui.get_new_name() if name is None: return # Check for unusual characters in filename that would affect exporting valid = re.match('^[\ \w-]+$', name) is not None if not valid: mb = QtWidgets.QMessageBox() mb.setIcon(QtWidgets.QMessageBox.Warning) mb.setStyleSheet("* {font-size:" + str(self.app.settings['fontsize']) + "pt} ") mb.setWindowTitle(_('Warning - invalid characters')) msg = _("In the journal name use only: a-z, A-z 0-9 - space") mb.setText(msg) mb.exec_() return # update database journal = {'name':name, 'jentry': '', 'owner':self.app.settings['codername'], 'date':datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'jid':None} cur = self.app.conn.cursor() cur.execute("insert into journal(name,jentry,owner,date) values(?,?,?,?)", (journal['name'], journal['jentry'], journal['owner'], journal['date'])) self.app.conn.commit() cur.execute("select last_insert_rowid()") jid = cur.fetchone() journal['jid'] = jid[0] self.parent_textEdit.append(_("Journal created: ") + journal['name']) # clear and refill table widget for r in self.journals: self.ui.tableWidget.removeRow(0) self.journals.append(journal) self.ui.label_jcount.setText(_("Journals: ") + str(len(self.journals))) for row, itm in enumerate(self.journals): self.ui.tableWidget.insertRow(row) item = QtWidgets.QTableWidgetItem(itm['name']) self.ui.tableWidget.setItem(row, self.NAME_COLUMN, item) item = QtWidgets.QTableWidgetItem(itm['date']) self.ui.tableWidget.setItem(row, self.DATE_COLUMN, item) item = QtWidgets.QTableWidgetItem(itm['owner']) self.ui.tableWidget.setItem(row, self.OWNER_COLUMN, item) self.ui.tableWidget.resizeColumnsToContents() self.ui.tableWidget.resizeRowsToContents() newest = len(self.journals) - 1 if newest < 0: return self.ui.tableWidget.setCurrentCell(newest, 0) self.ui.textEdit.setFocus()
def add_attribute(self): ''' When add button pressed, open addItem dialog to get new attribute text. AddItem dialog checks for duplicate attribute name. New attribute is added to the model and database ''' ui = DialogAddItemName(self.attribute_type, _("New attribute name")) ui.exec_() newText = ui.get_new_name() if newText is None or newText == "": return Dialog_type = QtWidgets.QDialog() ui = Ui_Dialog_attribute_type() ui.setupUi(Dialog_type) ok = Dialog_type.exec_() valuetype = "character" if ok and ui.radioButton_numeric.isChecked(): valuetype = "numeric" Dialog_assign = QtWidgets.QDialog() ui = Ui_Dialog_assignAttribute() ui.setupUi(Dialog_assign) ok = Dialog_assign.exec_() case_or_file = "case" if ok and ui.radioButton_files.isChecked(): case_or_file = "file" # update attribute_type list and database now_date = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) item = { 'name': newText, 'memo': "", 'owner': self.app.settings['codername'], 'date': now_date, 'valuetype': valuetype, 'caseOrFile': case_or_file } self.attribute_type.append(item) cur = self.app.conn.cursor() cur.execute( "insert into attribute_type (name,date,owner,memo,caseOrFile, valuetype) values(?,?,?,?,?,?)", (item['name'], item['date'], item['owner'], item['memo'], item['caseOrFile'], item['valuetype'])) self.app.conn.commit() sql = "select id from source" cur.execute(sql) ids = cur.fetchall() if case_or_file == "case": sql = "select caseid from cases" cur.execute(sql) ids = cur.fetchall() for id_ in ids: sql = "insert into attribute (name, value, id, attr_type, date, owner) values (?,?,?,?,?,?)" cur.execute(sql, (item['name'], "", id_[0], case_or_file, now_date, self.app.settings['codername'])) self.app.conn.commit() self.fill_tableWidget() self.parent_textEdit.append(_("Attribute added: ") + item['name'])
def add_attribute(self): ''' When add button pressed, opens the addItem dialog to get new attribute text. Then get the attribute type through a dialog. AddItem dialog checks for duplicate attribute name. New attribute is added to the model and database ''' cur = self.settings['conn'].cursor() cur.execute("select name from attribute_type where caseOrFile='case'") result = cur.fetchall() attribute_names = [] for a in result: attribute_names.append({'name': a[0]}) check_names = attribute_names + [{ 'name': 'name' }, { 'name': 'memo' }, { 'name': 'caseid' }, { 'name': 'date' }] ui = DialogAddItemName(check_names, _("New attribute name")) ui.exec_() name = ui.get_new_name() if name is None or name == "": return Dialog_type = QtWidgets.QDialog() ui = Ui_Dialog_attribute_type() ui.setupUi(Dialog_type) ok = Dialog_type.exec_() valuetype = "character" if ok and ui.radioButton_numeric.isChecked(): valuetype = "numeric" #self.attribute_names.append({'name': name}) # update attribute_type list and database now_date = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) cur = self.settings['conn'].cursor() cur.execute( "insert into attribute_type (name,date,owner,memo,caseOrFile, valuetype) values(?,?,?,?,?,?)", (name, now_date, self.settings['codername'], "", 'case', valuetype)) self.settings['conn'].commit() sql = "select caseid from cases" cur.execute(sql) case_ids = cur.fetchall() for id_ in case_ids: sql = "insert into attribute (name, value, id, attr_type, date, owner) values (?,?,?,?,?,?)" cur.execute(sql, (name, "", id_[0], 'case', now_date, self.settings['codername'])) self.settings['conn'].commit() self.load_cases_and_attributes() self.fill_tableWidget() self.parent_textEdit.append( _("Attribute added to cases: ") + name + ", " + _("type: ") + valuetype)
def add_attribute(self): """ When add button pressed, opens the addItem dialog to get new attribute text. Then get the attribute type through a dialog. AddItem dialog checks for duplicate attribute name. New attribute is added to the model and database. """ check_names = self.attribute_names + [{'name': 'name'}, {'name':'memo'}, {'name':'id'}, {'name':'date'}] ui = DialogAddItemName(check_names, "New attribute name") ui.exec_() name = ui.get_new_name() if name is None or name == "": return Dialog_type = QtWidgets.QDialog() ui = Ui_Dialog_attribute_type() ui.setupUi(Dialog_type) ok = Dialog_type.exec_() valuetype = "character" if ok and ui.radioButton_numeric.isChecked(): valuetype = "numeric" self.attribute_names.append({'name': name}) # update attribute_type list and database now_date = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) cur = self.settings['conn'].cursor() cur.execute("insert into attribute_type (name,date,owner,memo,caseOrFile, valuetype) values(?,?,?,?,?,?)" ,(name, now_date, self.settings['codername'], "", 'file', valuetype)) self.settings['conn'].commit() sql = "select id from source" cur.execute(sql) ids = cur.fetchall() for id_ in ids: sql = "insert into attribute (name, value, id, attr_type, date, owner) values (?,?,?,?,?,?)" cur.execute(sql, (name, "", id_[0], 'file', now_date, self.settings['codername'])) self.settings['conn'].commit() self.load_file_data() self.fill_table() self.parent_textEdit.append("Attribute added to files: " + name + ", type: " + valuetype)