Exemple #1
0
    def select_file(self):
        ''' When open file button is pressed a dialog of filenames is presented to the user.
        The selected file is then used to view and for assigning text portions to cases

        Start with clear selection to save confusion of loading file text and not having it
        highlighted for a currently selected case '''

        self.ui.tableWidget.clearSelection()
        self.case_text = []
        ui = DialogSelectFile(self.source, _("Select file to view"), "single")
        ok = ui.exec_()
        if not ok:
            return
        # selected_file is dictionary with id and name
        self.selected_file = ui.get_selected()
        if self.selected_file['fulltext'] is not None:
            chars = str(len(self.selected_file['fulltext']))
            self.ui.label_filename.setText("File: " + self.selected_file['name'] + " [chars: " + chars + "]")
            self.ui.textBrowser.setText(self.selected_file['fulltext'])
            self.caseTextViewed = []
            self.unlight()
            self.highlight()
        else:
            self.ui.textBrowser.setText("")
            ui = DialogViewImage(self.settings, self.selected_file)
            ui.exec_()
            memo = ui.ui.textEdit.toPlainText()
            if self.selected_file['memo'] != memo:
                self.selected_file['memo'] = memo
                cur = self.settings['conn'].cursor()
                cur.execute('update source set memo=? where id=?',
                    (self.selected_file['memo'], self.selected_file['id']))
                self.settings['conn'].commit()
Exemple #2
0
    def select_image(self):
        '''  dialog of filenames is presented to the user.
        The selected image file is then displayed for coding '''

        ui = DialogSelectFile(self.files, "Select file to view", "single")
        ok = ui.exec_()
        if ok:
            self.file_ = ui.get_selected()
            self.load_image()
Exemple #3
0
    def add_file_to_case(self):
        """ When select file button is pressed a dialog of filenames is presented to the user.
        The entire text of the selected file is then added to the selected case.
        """

        x = self.ui.tableWidget.currentRow()
        if x == -1:
            QtWidgets.QMessageBox.warning(None, _('Warning'),
                                          _("No case was selected"))
            return
        ui = DialogSelectFile(
            self.source,
            _("Select entire file for case: ") + self.cases[x]['name'],
            "single")
        ok = ui.exec_()
        if not ok:
            return
        casefile = ui.get_selected()
        #logger.debug(casefile)
        text_len = 0
        if casefile['fulltext'] is not None:
            text_len = len(casefile['fulltext'])
        newlink = {
            'caseid': self.cases[x]['caseid'],
            'fid': casefile['id'],
            'pos0': 0,
            'pos1': text_len,
            'owner': self.app.settings['codername'],
            'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            'memo': ""
        }

        cur = self.app.conn.cursor()
        # check for an existing duplicated liked file first
        cur.execute(
            "select * from case_text where caseid = ? and fid=? and pos0=? and pos1=?",
            (newlink['caseid'], newlink['fid'], newlink['pos0'],
             newlink['pos1']))
        result = cur.fetchall()
        if len(result) > 0:
            QtWidgets.QMessageBox.warning(
                None, _("Already Linked"),
                _("This file has already been linked to this case"))
            return
        cur.execute(
            "insert into case_text (caseid, fid, pos0, pos1, owner, date, memo) values(?,?,?,?,?,?,?)",
            (newlink['caseid'], newlink['fid'], newlink['pos0'],
             newlink['pos1'], newlink['owner'], newlink['date'],
             newlink['memo']))
        self.app.conn.commit()
        msg = casefile['name'] + _(" added to case.")
        QtWidgets.QMessageBox.information(None, _("File added to case"), msg)
        self.parent_textEdit.append(msg)
Exemple #4
0
    def view_file(self):
        """ When view file button is pressed a dialog of filenames is presented to the user.
        The selected file is then displayed for coding. """

        ui = DialogSelectFile(self.filenames, "Select file to view", "single")
        ok = ui.exec_()
        sql_values = []
        if ok:
            # filename is dictionary with id and name
            self.filename = ui.get_selected()
            cur = self.settings['conn'].cursor()
            cur.execute(
                "select name, id, fulltext, memo, owner, date from source where id=?",
                [self.filename['id']])
            file_result = cur.fetchone()
            sql_values.append(int(file_result[1]))
            self.sourceText = file_result[2]
            self.ui.label_file.setText("File " + str(file_result[1]) + " : " +
                                       file_result[0])

            # get code text for this file and for this coder, or all coders
            self.code_text = []
            codingsql = "select cid, fid, seltext, pos0, pos1, owner, date, memo from code_text"
            codingsql += " where fid=? "
            if not self.ui.checkBox_show_coders.isChecked():
                codingsql += " and owner=? "
                sql_values.append(self.settings['codername'])
            cur.execute(codingsql, sql_values)
            code_results = cur.fetchall()
            for row in code_results:
                self.code_text.append({
                    'cid': row[0],
                    'fid': row[1],
                    'seltext': row[2],
                    'pos0': row[3],
                    'pos1': row[4],
                    'owner': row[5],
                    'date': row[6],
                    'memo': row[7]
                })
            self.ui.textEdit.setPlainText(self.sourceText)
            # update filter for tooltip
            self.eventFilterTT.setCodes(self.code_text, self.codes)
            # clear search indices and lineEdit
            self.ui.lineEdit_search.setText("")
            self.search_indices = []
            self.search_index = 0
            # redo formatting
            self.unlight()
            self.highlight()
        else:
            self.ui.textEdit.clear()
Exemple #5
0
    def automark(self):
        ''' Automark text in one or more files with selected case.
        '''

        row = self.ui.tableWidget.currentRow()
        if row == -1:
            QtWidgets.QMessageBox.warning(None, _('Warning'), _("No case was selected"))
            return
        ui = DialogSelectFile(self.source, _("Select files to assign case"), "many")
        ok = ui.exec_()
        if not ok:
            return
        files = ui.get_selected()
        if len(files) == 0:
            QtWidgets.QMessageBox.warning(None, _('Warning'), _("No file was selected"))
            return
        #logger.debug(str(files))
        #logger.debug(str(type(files)))
        filenames = ""
        for f in files:
            filenames += f['name'] + " "
        ui = DialogGetStartAndEndMarks(self.cases[row]['name'], filenames)
        ok = ui.exec_()
        if not ok:
            return
        start_mark = ui.get_start_mark()
        end_mark = ui.get_end_mark()
        if start_mark == "" or end_mark == "":
            QtWidgets.QMessageBox.warning(None, _('Warning'), _('Cannot have blank text marks'))
            return
        warnings = 0
        for f in files:
            cur = self.settings['conn'].cursor()
            cur.execute("select name, id, fulltext, memo, owner, date from source where id=?",
                [f['id']])
            currentfile = cur.fetchone()
            text = currentfile[2]
            text_starts = [match.start() for match in re.finditer(re.escape(start_mark), text)]
            text_ends = [match.start() for match in re.finditer(re.escape(end_mark), text)]
            #logger.debug(textStarts, textEnds)
            #add new code linkage items to database
            for startPos in text_starts:
                pos1 = -1  # default if not found
                textEndIterator = 0
                try:
                    while startPos >= text_ends[textEndIterator]:
                        textEndIterator += 1
                except IndexError:
                    textEndIterator = -1
                    warnings += 1
                    logger.warning("Could not find end mark: " + f['name'] + "  " + end_mark)

                if textEndIterator >= 0:
                    pos1 = text_ends[textEndIterator]
                    item = {'caseid': int(self.cases[row]['caseid']), 'fid': int(f['id']),
                    'pos0': startPos, 'pos1': pos1,
                    'owner': self.settings['codername'],
                    'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'memo': ""}

                    cur = self.settings['conn'].cursor()
                    cur.execute("insert into case_text (caseid,fid,pos0,pos1,owner,date,memo) values(?,?,?,?,?,?,?)"
                        ,(item['caseid'], item['fid'], item['pos0'], item['pos1'],
                          item['owner'], item['date'], item['memo']))
                    self.settings['conn'].commit()
        if warnings > 0:
            QtWidgets.QMessageBox.warning(None, _('Warning'),
                  _("End mark did not match up: ") + str(warnings))
        self.ui.tableWidget.clearSelection()
Exemple #6
0
    def auto_code(self):
        """ Autocode text in one file or all files with currently selected code.
        """

        item = self.ui.treeWidget.currentItem()
        if item is None:
            QtWidgets.QMessageBox.warning(None, _('Warning'), _("No code was selected"),
                QtWidgets.QMessageBox.Ok)
            return
        if item.text(1)[0:3] == 'cat':
            return
        cid = int(item.text(1).split(':')[1])
        # Input dialog too narrow, so code below
        dialog = QtWidgets.QInputDialog(None)
        dialog.setWindowTitle(_("Automatic coding"))
        dialog.setInputMode(QtWidgets.QInputDialog.TextInput)
        dialog.setLabelText(_("Autocode files with the current code for this text:") +"\n" + item.text(0))
        dialog.resize(200, 20)
        ok = dialog.exec_()
        if not ok:
            return
        findText = str(dialog.textValue())
        if findText == "" or findText is None:
            return
        ui = DialogSelectFile(self.filenames, _("Select file to view"), "many")
        ok = ui.exec_()
        if not ok:
            return
        files = ui.get_selected()
        if len(files) == 0:
            return
        filenames = ""
        for f in files:
            filenames += f['name'] + " "
            cur = self.settings['conn'].cursor()
            cur.execute("select name, id, fulltext, memo, owner, date from source where id=? and mediapath is Null",
                [f['id']])
            currentfile = cur.fetchone()
            text = currentfile[2]
            textStarts = [match.start() for match in re.finditer(re.escape(findText), text)]
            # add new items to database
            for startPos in textStarts:
                item = {'cid': cid, 'fid': int(f['id']), 'seltext': str(findText),
                'pos0': startPos, 'pos1': startPos + len(findText),
                'owner': self.settings['codername'], 'memo': "",
                'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
                cur = self.settings['conn'].cursor()
                cur.execute("insert into code_text (cid,fid,seltext,pos0,pos1,\
                    owner,memo,date) values(?,?,?,?,?,?,?,?)"
                    , (item['cid'], item['fid'], item['seltext'], item['pos0'],
                    item['pos1'], item['owner'], item['memo'], item['date']))
                self.settings['conn'].commit()

                # if this is the currently open file update the code text list and GUI
                if f['id'] == self.filename['id']:
                    self.code_text.append(item)
            self.highlight()
            self.parent_textEdit.append(_("Automatic coding in files: ") + filenames \
                + _(". with text: ") + findText)
        # update filter for tooltip
        self.eventFilterTT.setCodes(self.code_text, self.codes)