Ejemplo n.º 1
0
    def remove_files_from_case(self):
        """ Remove selected files from case. """

        index_list = self.ui.tableWidget.selectionModel().selectedIndexes()
        rows = []
        for i in index_list:
            rows.append(i.row())
        rows = list(set(rows))  # duplicate rows due to multiple columns
        if len(rows) == 0:
            return
        selected_files = []
        remove_msg = ""
        for r in rows:
            #print(self.allfiles[r])
            selected_files.append(self.allfiles[r])
            remove_msg += "\n" + self.allfiles[r][1]
        ui = DialogConfirmDelete(self.app, remove_msg)
        ok = ui.exec_()
        if not ok:
            return
        cur = self.app.conn.cursor()
        sql = "delete from case_text where caseid=? and fid=?"
        for f in selected_files:
            try:
                cur.execute(sql, [self.case['caseid'], f[0]])
                self.app.conn.commit()
                self.parent_textEdit.append(f[1] + " removed from case " +
                                            self.case['name'])
            except Exception as e:
                print(e)
                logger.debug(str(e))
        # update assigned files and table widget
        self.get_files()
        self.fill_table()
        self.app.delete_backup = False
Ejemplo n.º 2
0
    def delete_case(self):
        ''' When delete button pressed, case is deleted from model and database '''

        tableRowsToDelete = []  # for table widget ids
        caseNamesToDelete = ""  # for confirmDelete Dialog
        idsToDelete = []  # for ids for cases and db

        for itemWidget in self.ui.tableWidget.selectedItems():
            tableRowsToDelete.append(int(itemWidget.row()))
            idsToDelete.append(int(self.ui.tableWidget.item(itemWidget.row(),
            self.ID_COLUMN).text()))
            caseNamesToDelete = caseNamesToDelete + "\n" + str(self.ui.tableWidget.item(itemWidget.row(),
            self.NAME_COLUMN).text())
            #logger.debug("X:"+ str(itemWidget.row()) + "  y:"+str(itemWidget.column()) +"  "+itemWidget.text() +"  id:"+str(self.tableWidget_codes.item(itemWidget.row(),3).text()))
        tableRowsToDelete.sort(reverse=True)
        if len(caseNamesToDelete) == 0:
            return
        ui = DialogConfirmDelete(caseNamesToDelete)
        ok = ui.exec_()
        if not ok:
            return
        for id in idsToDelete:
            for c in self.cases:
                if c['caseid'] == id:
                    self.parent_textEdit.append("Case deleted: " + c['name'])
                    self.cases.remove(c)
                    cur = self.settings['conn'].cursor()
                    #logger.debug(str(id) + "  "+ str(type(id)))
                    cur.execute("delete from cases where caseid = ?", [id])
                    cur.execute("delete from case_text where caseid = ?", [id])
                    sql = "delete from attribute where id=? and attr_type='case'"
                    cur.execute(sql, [id])
                    self.settings['conn'].commit()
        self.fill_tableWidget()
Ejemplo n.º 3
0
    def delete_code(self, selected):
        ''' Find code, remove from database, refresh and code_name data and fill treeWidget '''

        # find the code_in the list, check to delete
        found = -1
        for i in range(0, len(self.codes)):
            if self.codes[i]['cid'] == int(selected.text(1)[4:]):
                found = i
        if found == -1:
            return
        code_ = self.codes[found]
        ui = DialogConfirmDelete("Code: " + selected.text(0))
        ok = ui.exec_()
        if not ok:
            return
        cur = self.settings['conn'].cursor()
        cur.execute("delete from code_name where cid=?", [
            code_['cid'],
        ])
        cur.execute("delete from code_text where cid=?", [
            code_['cid'],
        ])
        self.settings['conn'].commit()
        selected = None
        self.get_codes_categories()
        self.fill_tree()
Ejemplo n.º 4
0
    def delete_category(self, selected):
        ''' Find category, remove from database, refresh categories and code data
        and fill treeWidget '''

        found = -1
        for i in range(0, len(self.categories)):
            if self.categories[i]['catid'] == int(selected.text(1)[6:]):
                found = i
        if found == -1:
            return
        category = self.categories[found]
        ui = DialogConfirmDelete("Category: " + selected.text(0))
        ok = ui.exec_()
        if not ok:
            return
        cur = self.settings['conn'].cursor()
        cur.execute("update code_name set catid=null where catid=?", [
            category['catid'],
        ])
        cur.execute("update code_cat set supercatid=null where catid = ?", [
            category['catid'],
        ])
        cur.execute("delete from code_cat where catid = ?", [
            category['catid'],
        ])
        self.settings['conn'].commit()
        selected = None
        self.get_codes_categories()
        self.fill_tree()
Ejemplo n.º 5
0
    def delete_category(self, selected):
        """ Find category, remove from database, refresh categories and code data
        and fill treeWidget. Sub-level items are retained. """

        found = -1
        for i in range(0, len(self.categories)):
            if self.categories[i]['catid'] == int(selected.text(1)[6:]):
                found = i
        if found == -1:
            return
        category = self.categories[found]
        ui = DialogConfirmDelete(self.app, _("Category: ") + selected.text(0))
        ok = ui.exec_()
        if not ok:
            return
        self.parent_textEdit.append(_("Category deleted: ") + category['name'])
        cur = self.app.conn.cursor()
        cur.execute("update code_name set catid=null where catid=?", [
            category['catid'],
        ])
        cur.execute("update code_cat set supercatid=null where catid = ?", [
            category['catid'],
        ])
        cur.execute("delete from code_cat where catid = ?", [
            category['catid'],
        ])
        self.app.conn.commit()
        selected = None
        self.update_dialog_codes_and_categories()
        self.app.delete_backup = False
Ejemplo n.º 6
0
    def delete_code(self, selected):
        """ Find code, remove from database, refresh and code_name data and fill
        treeWidget. """

        # find the code_in the list, check to delete
        found = -1
        for i in range(0, len(self.codes)):
            if self.codes[i]['cid'] == int(selected.text(1)[4:]):
                found = i
        if found == -1:
            return
        code_ = self.codes[found]
        ui = DialogConfirmDelete(self.app, _("Code: ") + selected.text(0))
        ok = ui.exec_()
        if not ok:
            return
        self.parent_textEdit.append(_("Code deleted: ") + code_['name'])
        cur = self.app.conn.cursor()
        cur.execute("delete from code_name where cid=?", [
            code_['cid'],
        ])
        cur.execute("delete from code_image where cid=?", [
            code_['cid'],
        ])
        cur.execute("delete from code_av where cid=?", [
            code_['cid'],
        ])
        cur.execute("delete from code_text where cid=?", [
            code_['cid'],
        ])
        self.app.conn.commit()
        selected = None
        self.update_dialog_codes_and_categories()
        self.app.delete_backup = False
Ejemplo n.º 7
0
    def delete_attribute(self):
        ''' When delete button pressed, attribute is deleted from database '''

        tableRowsToDelete = []  # for table widget ids
        namesToDelete = []
        for itemWidget in self.ui.tableWidget.selectedItems():
            tableRowsToDelete.append(int(itemWidget.row()))
            namesToDelete.append(self.ui.tableWidget.item(itemWidget.row(), 0).text())
        tableRowsToDelete.sort(reverse=True)
        if len(namesToDelete) == 0:
            return
        ui = DialogConfirmDelete("\n".join(namesToDelete))
        ok = ui.exec_()
        if not ok:
            return
        for name in namesToDelete:
            for attr in self.attribute_type:
                if attr['name'] == name:
                    self.parent_textEdit.append(_("Attribute deleted: ") + attr['name'])
                    cur = self.settings['conn'].cursor()
                    cur.execute("delete from attribute where name = ?", (name,))
                    cur.execute("delete from attribute_type where name = ?", (name,))
        self.settings['conn'].commit()
        self.attribute_type = []
        cur.execute("select name, date, owner, memo, caseOrFile, valuetype from attribute_type")
        result = cur.fetchall()
        for row in result:
            self.attribute_type.append({'name': row[0], 'date': row[1], 'owner': row[2],
            'memo': row[3], 'caseOrFile': row[4],'valuetype': row[5]})
        self.fill_tableWidget()
Ejemplo n.º 8
0
    def delete_code(self, selected):
        """ Find code, remove from database, refresh and code data and fill treeWidget.
        """

        # find the code in the list, check to delete
        found = -1
        for i in range(0, len(self.codes)):
            if self.codes[i]['cid'] == int(selected.text(1)[4:]):
                found = i
        if found == -1:
            return
        code_ = self.codes[found]
        ui = DialogConfirmDelete(_("Code: ") + selected.text(0))
        ok = ui.exec_()
        if not ok:
            return
        cur = self.settings['conn'].cursor()
        cur.execute("delete from code_name where cid=?", [code_['cid'], ])
        cur.execute("delete from code_text where cid=?", [code_['cid'], ])
        cur.execute("delete from code_image where cid=?", [code_['cid'], ])
        cur.execute("delete from code_av where cid=?", [code_['cid'], ])
        self.settings['conn'].commit()
        selected = None
        self.get_codes_categories()
        self.fill_tree()
        self.parent_textEdit.append(_("Code deleted: ") + code_['name'] + "\n")
        # update filter for tooltip
        self.eventFilterTT.setCodes(self.code_text, self.codes)
Ejemplo n.º 9
0
    def change_text_code_start_positions(self):
        """ Extend or shrink text coding start positions in all codings and all files for owner. """

        delta = self.ui.spinBox_text_starts.value()
        if delta == 0:
            return
        cur = self.app.conn.cursor()
        sql = "select cid,fid,pos0,pos1,code_text.owner, length(source.fulltext) from code_text join source on source.id=code_text.fid where code_text.owner=?"
        text_sql = "select substr(source.fulltext, ?, ?) from source where source.id=?"
        update_sql = "update code_text set pos0=?, seltext=? where pos0=? and pos1=? and cid=? and fid=? and owner=?"
        cur.execute(sql, [self.app.settings['codername']])
        res = cur.fetchall()
        if res == []:
            return
        msg = _("Change ALL text code start positions in ALL text files by ")
        msg += str(delta) + _(" characters.\n")
        msg += _("Made by coder: ") + self.app.settings['codername'] + "\n"
        msg += str(len(res)) + _(" to change.") + "\n"
        msg += _("Backup project before performing this function.\n")
        msg += _("Press OK to continue.")
        ui = DialogConfirmDelete(self.app, msg, _("Change code start positions"))
        ok = ui.exec_()
        if not ok:
            return

        for r in res:
            new_pos0 = r[2] - delta
            # cannot have start pos less than start of text
            if new_pos0 < 0:
                new_pos0 = 0
            # cannot have start pos larger than end pos
            if new_pos0 > r[3]:
                new_pos0 = r[3] - 1
            cur.execute(text_sql, [new_pos0 + 1, r[3] - new_pos0, r[1]])
            seltext = cur.fetchone()[0]
            try:
                cur.execute(update_sql, [new_pos0, seltext, r[2], r[3], r[0], r[1], r[4]])
            except:
                pass
        self.app.conn.commit()
        self.parent_textEdit.append(_("All text codings by ") + self.app.settings['codername'] + _(" resized by ") + str(delta) + _(" characters."))
        self.update_tab_coding_dialog()
Ejemplo n.º 10
0
    def delete(self):
        ''' Delete journal from database and update model and widget. '''

        x = self.ui.tableWidget.currentRow()
        if x == -1:
            return
        journalname = self.journals[x]['name']
        #logger.debug(("Delete row: " + str(x)))
        ui = DialogConfirmDelete(self.journals[x]['name'])
        ok = ui.exec_()

        if ok:
            cur = self.settings['conn'].cursor()
            cur.execute("delete from journal where name = ?", [journalname])
            self.settings['conn'].commit()
            for item in self.journals:
                if item['name'] == journalname:
                    self.journals.remove(item)
            self.ui.tableWidget.removeRow(x)
            self.parent_textEdit.append(_("Journal deleted: ") + journalname)
Ejemplo n.º 11
0
    def delete(self):
        """ Delete file from database and update model and widget.
        Also, delete files from sub-directories. """

        x = self.ui.tableWidget.currentRow()
        fileId = self.source[x]['id']
        ui = DialogConfirmDelete(self.source[x]['name'])
        ok = ui.exec_()

        if not ok:
            return
        cur = self.app.conn.cursor()
        # delete text source
        if self.source[x]['mediapath'] is None:
            cur.execute("delete from source where id = ?", [fileId])
            cur.execute("delete from code_text where fid = ?", [fileId])
            cur.execute("delete from annotation where fid = ?", [fileId])
            cur.execute("delete from case_text where fid = ?", [fileId])
            sql = "delete from attribute where attr_type in (select attribute_type.name from "
            sql += "attribute_type where id=? and attribute_type.caseOrFile='file')"
            cur.execute(sql, [fileId])
            self.app.conn.commit()
        # delete image source
        if self.source[x]['mediapath'] is not None:
            filepath = self.app.project_path + self.source[x]['mediapath']
            try:
                os.remove(filepath)
            except Exception as e:
                logger.warning(_("Deleting image error: ") + str(e))
            cur.execute("delete from source where id = ?", [fileId])
            cur.execute("delete from code_image where id = ?", [fileId])
            sql = "delete from attribute where attr_type in (select attribute_type.name from "
            sql += "attribute_type where id=? and attribute_type.caseOrFile='file')"
            cur.execute(sql, [fileId])
            self.app.conn.commit()

        self.parent_textEdit.append(_("Deleted: ") + self.source[x]['name'])
        for item in self.source:
            if item['id'] == fileId:
                self.source.remove(item)
        self.fill_table()