Beispiel #1
0
    def selectCases(self):
        """ When select case button is pressed a dialog of case names is presented to the user.
        The selected cases are then used when searching for codings.
        If cases are selected, then selected files are cleared.
        If neither are selected the default is all files are selected.
         """

        casenames = []
        self.fileIDs = ""
        self.caseIDs = ""  # default for all cases and allows the file selection search method to occur
        cur = self.settings['conn'].cursor()
        cur.execute("select id, name, status from cases")
        result = cur.fetchall()
        for row in result:
            casenames.append({'id': row[0], 'name': row[1], 'status': row[2]})

        Dialog_selectcase = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(casenames)
        ui.setupUi(Dialog_selectcase, "Select case(s) to view", "many")
        ok = Dialog_selectcase.exec_()
        if ok:
            tmp_IDs = ""
            selectedCases = ui.getSelected()  # list of dictionaries
            for row in selectedCases:
                tmp_IDs += "," + str(row['id'])
            if len(tmp_IDs) > 0:
                self.caseIDs = tmp_IDs[1:]
Beispiel #2
0
    def addFileToCase(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.tableWidget_cases.currentRow()
        if x == -1:
            QtGui.QMessageBox.warning(None, 'Warning',"No case was selected", QtGui.QMessageBox.Ok)
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile,"Select entire file for case: " + self.cases[x]['name'], "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            casefile = ui.getSelected()
            newlink = {'caseid':self.cases[x]['id'], 'fid':casefile['id'], 'selfirst':0, 'selend':len(casefile['file']), 'status':1, 'owner':self.settings['codername'],
                        'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'memo':""}

            cur = self.settings['conn'].cursor()
            # check for an existing duplicated linkage first
            cur.execute("select * from caselinkage where caseid = ? and fid=? and selfirst=? and selend=?",
                         (newlink['caseid'], newlink['fid'], newlink['selfirst'], newlink['selend']))
            result = cur.fetchall()
            if len(result) > 0:
                QtGui.QMessageBox.warning(None,"Already Linked", "This file has already been linked to this case", QtGui.QMessageBox.Ok)
                return

            cur.execute("insert into caselinkage (caseid, fid, selfirst, selend, status, owner, date, memo) values(?,?,?,?,?,?,?,?)"
                        ,(newlink['caseid'],newlink['fid'],newlink['selfirst'],newlink['selend'],newlink['status'],newlink['owner'],newlink['date'], newlink['memo']))
            self.settings['conn'].commit()
Beispiel #3
0
    def selectFiles(self):
        """ When select file button is pressed a dialog of filenames is presented to the user.
        The selected files are then used when searching for codings
        If files are selected, then selected cases are cleared.
        The default is all file IDs.
        To revert to default after files are selected,
        the user must press select files button then cancel the dialog.
         """

        filenames = []
        self.fileIDs = ""
        self.caseIDs = ""  # clears any case selections
        cur = self.settings['conn'].cursor()
        cur.execute("select id, name, status from source")
        result = cur.fetchall()
        for row in result:
            filenames.append({'id': row[0], 'name': row[1], 'status': row[2]})
            self.fileIDs += "," + str(row[0])
        if len(self.fileIDs) > 0:
            self.fileIDs = self.fileIDs[1:]

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(filenames)
        ui.setupUi(Dialog_selectfile, "Select file(s) to view", "many")
        ok = Dialog_selectfile.exec_()
        if ok:
            tmp_IDs = ""
            selectedFiles = ui.getSelected()  # list of dictionaries
            for row in selectedFiles:
                tmp_IDs += "," + str(row['id'])
            if len(tmp_IDs) > 0:
                self.fileIDs = tmp_IDs[1:]
Beispiel #4
0
    def selectFile(self):
        """ When select file button is pressed a dialog of filenames is presented to the user.
        The selected file is then used to view and do coding
         """

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.filenames)
        ui.setupUi(Dialog_selectfile, "Select file to view", "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            # filename is dictionary with id and name
            self.filename = ui.getSelected()
            cur = self.settings["conn"].cursor()
            cur.execute(
                "select name, id, file, memo, owner, date, dateM, status from source where id=?", [self.filename["id"]]
            )
            result = cur.fetchone()
            self.sourceText = result[2]
            self.label_fileName.setText("File " + str(result[1]) + " : " + result[0])

            # get codings for this file and coder
            self.coding = []
            codingsql = "select cid, fid, seltext, selfirst, selend, status, owner, date, memo from coding"
            if self.settings["codertable"] == "coding2":
                codingsql = codingsql + "2"
            codingsql = codingsql + " where fid = ?"
            cur.execute(codingsql, [int(result[1])])
            result = cur.fetchall()
            for row in result:
                self.coding.append(
                    {
                        "cid": row[0],
                        "fid": row[1],
                        "seltext": row[2],
                        "selfirst": row[3],
                        "selend": row[4],
                        "status": row[5],
                        "owner": row[6],
                        "date": row[7],
                        "memo": row[8],
                    }
                )

            self.textEd.setPlainText(self.sourceText)
            # update filter for tooltip
            self.eventFilter.setCodes(self.coding, self.freecode)

            # redo formatting
            self.unlight()
            self.highlight()
        else:
            self.textEd.clear()
Beispiel #5
0
    def mergeCats(self):
        """When merge categories button is pressed, merge two or more categories into one category.
        Note: there is no undo for this """

        removeCats = []
        for itemWidget in self.tableWidget_cats.selectedItems():
            removeTemp = {'name':self.tableWidget_cats.item(itemWidget.row(), self.CAT_NAME_COLUMN).text(),'catid':int(self.tableWidget_cats.item(itemWidget.row(), self.CAT_ID_COLUMN).text())}
            # remove duplicate selections, have duplicates because tableWidget_cats is not row selection only
            addCat = True
            for remCat in removeCats:
                if removeTemp == remCat:
                    addCat = False
            if addCat: removeCats.append(removeTemp)

        if len(removeCats) < 2:
            return

        Dialog_selectcat = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(removeCats)
        ui.setupUi(Dialog_selectcat, "Merging, Select category to keep", "single")
        ok = Dialog_selectcat.exec_()
        if not(ok):
            return
        keepCat = ui.getSelected()
        print("Keeping category: " + str(keepCat))
        for cat in removeCats:
            if cat['catid'] == keepCat['catid']:
                removeCats.remove(cat)  # exclude the kept category from the remove list
        print("Removing categories: " + str(removeCats))

        cur = self.settings['conn'].cursor()
        for cat in removeCats:
            cur.execute("update treecode set catid=? where catid=?", (keepCat['catid'] ,cat['catid']))
            cur.execute("delete from codecat where catid=?", (cat['catid'],))

        # Refresh categories, treecat and self.tableWidget_cats
        for row in self.cats:
            self.tableWidget_cats.removeRow(0)

        self.cats = []
        cur.execute("select name, cid, catid, owner, date, dateM, memo, status from codecat")
        result = cur.fetchall()
        for row in result:
            self.cats.append({'name':row[0],'cid':row[1], 'catid':row[2], 'owner':row[3], 'date':row[4], 'dateM':row[5], 'memo':row[6], 'status':row[7]})

        self.treecode = []
        cur.execute("select cid, catid, date, dateM, memo, status, owner from treecode")
        result = cur.fetchall()
        for row in result:
            self.treecode.append({'cid':row[0], 'catid':row[1], 'date':row[2], 'dateM':row[3], 'memo':row[4], 'status':row[5], 'owner':row[6]})
        self.settings['conn'].commit()
        self.fillCatsTable()
Beispiel #6
0
    def selectFile(self):
        """ When select file button is pressed a dialog of filenames is presented to the user.
        The selected file is then used to view and do coding
         """

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.filenames)
        ui.setupUi(Dialog_selectfile, "Select file to view", "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            #filename is dictionary with id and name
            self.filename = ui.getSelected()
            cur = self.settings['conn'].cursor()
            cur.execute(
                "select name, id, file, memo, owner, date, dateM, status from source where id=?",
                [self.filename['id']])
            result = cur.fetchone()
            self.sourceText = result[2]
            self.label_fileName.setText("File " + str(result[1]) + " : " +
                                        result[0])

            #get codings for this file and coder
            self.coding = []
            codingsql = "select cid, fid, seltext, selfirst, selend, status, owner, date, memo from coding"
            if self.settings['codertable'] == "coding2":
                codingsql = codingsql + "2"
            codingsql = codingsql + " where fid = ?"
            cur.execute(codingsql, [int(result[1])])
            result = cur.fetchall()
            for row in result:
                self.coding.append({
                    'cid': row[0],
                    'fid': row[1],
                    'seltext': row[2],
                    'selfirst': row[3],
                    'selend': row[4],
                    'status': row[5],
                    'owner': row[6],
                    'date': row[7],
                    'memo': row[8]
                })

            self.textEd.setPlainText(self.sourceText)
            # update filter for tooltip
            self.eventFilter.setCodes(self.coding, self.freecode)

            # redo formatting
            self.unlight()
            self.highlight()
        else:
            self.textEd.clear()
Beispiel #7
0
    def addFileToCase(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.tableWidget_cases.currentRow()
        if x == -1:
            QtGui.QMessageBox.warning(None, 'Warning', "No case was selected",
                                      QtGui.QMessageBox.Ok)
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile,
                   "Select entire file for case: " + self.cases[x]['name'],
                   "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            casefile = ui.getSelected()
            newlink = {
                'caseid': self.cases[x]['id'],
                'fid': casefile['id'],
                'selfirst': 0,
                'selend': len(casefile['file']),
                'status': 1,
                'owner': self.settings['codername'],
                'date':
                datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"),
                'memo': ""
            }

            cur = self.settings['conn'].cursor()
            # check for an existing duplicated linkage first
            cur.execute(
                "select * from caselinkage where caseid = ? and fid=? and selfirst=? and selend=?",
                (newlink['caseid'], newlink['fid'], newlink['selfirst'],
                 newlink['selend']))
            result = cur.fetchall()
            if len(result) > 0:
                QtGui.QMessageBox.warning(
                    None, "Already Linked",
                    "This file has already been linked to this case",
                    QtGui.QMessageBox.Ok)
                return

            cur.execute(
                "insert into caselinkage (caseid, fid, selfirst, selend, status, owner, date, memo) values(?,?,?,?,?,?,?,?)",
                (newlink['caseid'], newlink['fid'], newlink['selfirst'],
                 newlink['selend'], newlink['status'], newlink['owner'],
                 newlink['date'], newlink['memo']))
            self.settings['conn'].commit()
Beispiel #8
0
    def mergeCodes(self):
        """When merge codes button is pressed, merge two or more codes into one code.
        Note: there is no undo for this """

        removeCodes = []
        for itemWidget in self.tableWidget_codes.selectedItems():
            removeTemp = {'name':self.tableWidget_codes.item(itemWidget.row(), self.CODE_NAME_COLUMN).text(),'cid':int(self.tableWidget_codes.item(itemWidget.row(), self.CODE_ID_COLUMN).text())}
            # remove duplicate selections, have duplicates because tableWidget_codes is not row selection only
            addCode = True
            for remCode in removeCodes:
                if removeTemp == remCode:
                    addCode = False
            if addCode:
                removeCodes.append(removeTemp)
        if len(removeCodes) < 2:
            return

        Dialog_selectcode = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(removeCodes)
        ui.setupUi(Dialog_selectcode, "Merging, Select code to keep", "single")
        ok = Dialog_selectcode.exec_()
        if not(ok):
            return
        keepCode = ui.getSelected()
        #print(keepCode)
        #print(str(removeCodes))
        for code in removeCodes:
            if code['cid'] == keepCode['cid']:
                removeCodes.remove(code)  # exclude the kept code from the remove list
        #print(str(removeCodes))
        cur = self.settings['conn'].cursor()
        for code in removeCodes:
            cur.execute("update treecode set cid=? where cid=?", (keepCode['cid'] ,code['cid']))
            cur.execute("update coding set cid=? where cid=?", (keepCode['cid'] ,code['cid']))
            cur.execute("update coding2 set cid=? where cid=?", (keepCode['cid'] ,code['cid']))
            cur.execute("delete from freecode where id=?", (code['cid'],))

        #have to refresh self.tableWidget_codes and freecode list
        for row in self.freecode:
            self.tableWidget_codes.removeRow(0)

        cur.execute("select name, memo, owner, date, dateM, id, status, color from freecode")
        result = cur.fetchall()
        self.freecode = []
        for row in result:
            self.freecode.append({'name':row[0], 'memo':row[1], 'owner':row[2], 'date':row[3], 'dateM':row[4], 'id':row[5], 'status':row[6], 'color':row[7]})
        self.settings['conn'].commit()
        self.fillCodesTable()
Beispiel #9
0
    def selectFile(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
         """

        # clear table_widget selection - save confusion of loading file text and not having it highlighted for a currently selected case
        self.tableWidget_cases.clearSelection()
        self.caseLinks = []

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile, "Select file to view", "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            #selectedFile is dictionary with id and name
            self.selectedFile = ui.getSelected()
            self.label_fileName.setText("File: " + self.selectedFile['name'])
            self.textEd.setPlainText(self.selectedFile['file'])
            self.caseTextViewed = []
            self.pushButton_mark.setEnabled(True)
            self.pushButton_unmark.setEnabled(True)
Beispiel #10
0
    def selectFile(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
         """

        # clear table_widget selection - save confusion of loading file text and not having it highlighted for a currently selected case
        self.tableWidget_cases.clearSelection()
        self.caseLinks = []

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile,"Select file to view", "single")
        ok = Dialog_selectfile.exec_()
        if ok:
            #selectedFile is dictionary with id and name
            self.selectedFile = ui.getSelected()
            self.label_fileName.setText("File: " + self.selectedFile['name'])
            self.textEd.setPlainText(self.selectedFile['file'])
            self.caseTextViewed = []
            self.pushButton_mark.setEnabled(True)
            self.pushButton_unmark.setEnabled(True)
Beispiel #11
0
    def autocode(self):
        """ Autocode text in one file or all files with selected code """

        row = self.tableWidget_codes.currentRow()
        if row == -1:
            QtGui.QMessageBox.warning(None, 'Warning', "No code was selected",
                                      QtGui.QMessageBox.Ok)
            return

        #text, ok = QtGui.QInputDialog.getText(None, 'Autocode a word or phrase', 'Phrase:')
        # dialog too narrow, so code below
        dialog = QtGui.QInputDialog(None)
        dialog.setWindowTitle("Autocode")
        dialog.setInputMode(QtGui.QInputDialog.TextInput)
        dialog.setLabelText("Autocode a word or phrase with:\n" +
                            str(self.freecode[row]['name']))
        dialog.resize(200, 20)
        ok = dialog.exec_()
        if not ok:
            return

        findText = str(dialog.textValue())
        if findText == "" or findText is None:
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.filenames)
        ui.setupUi(Dialog_selectfile, "Select file to view",
                   "many")  # many has no meaning but is not 'single'
        ok = Dialog_selectfile.exec_()
        if not ok:
            return
        files = ui.getSelected()
        if len(files) == 0:
            return

        for file in files:
            cur = self.settings['conn'].cursor()
            cur.execute(
                "select name, id, file, memo, owner, date, dateM, status from source where id=?",
                [file['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':
                    int(self.freecode[row]['id']),
                    'fid':
                    int(file['id']),
                    'seltext':
                    str(findText),
                    'selfirst':
                    startPos,
                    'selend':
                    startPos + len(findText),
                    'owner':
                    self.settings['codername'],
                    'memo':
                    "",
                    'date':
                    datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"),
                    'status':
                    1
                }
                #print item
                cur = self.settings['conn'].cursor()
                cur.execute(
                    "insert into " + self.settings['codertable'] +
                    " (cid,fid,seltext,selfirst,selend,owner,memo,date,status) values(?,?,?,?,?,?,?,?,?)",
                    (item['cid'], item['fid'],
                     item['seltext'].encode('raw_unicode_escape'),
                     item['selfirst'], item['selend'], item['owner'],
                     item['memo'], item['date'], item['status']))
                self.settings['conn'].commit()

                # if this is the currently open file update the coding list and GUI
                if file['id'] == self.filename['id']:
                    self.coding.append(item)
            self.highlight()
Beispiel #12
0
    def automark(self):
        """ Automark text in one or more files with selected case """

        row = self.tableWidget_cases.currentRow()
        if row == -1:
            QtGui.QMessageBox.warning(None, 'Warning', "No case was selected",
                                      QtGui.QMessageBox.Ok)
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile, "Select file(s) to assign case",
                   "many")  # many has no real meaning but is not 'single'
        ok = Dialog_selectfile.exec_()
        if not ok:
            return
        files = ui.getSelected()
        if len(files) == 0:
            QtGui.QMessageBox.warning(None, 'Warning', "No file was selected",
                                      QtGui.QMessageBox.Ok)
            return

        dialog = QtGui.QDialog()
        ui = Ui_Dialog_autoassign(self.cases[row]['name'])
        ui.setupUi(dialog)
        ok = dialog.exec_()
        if not ok:
            return

        startMark = ui.getStartMark()
        endMark = ui.getEndMark()
        if startMark == "" or endMark == "":
            QtGui.QMessageBox.warning(None, 'Warning',
                                      "Cannot have blank text marks",
                                      QtGui.QMessageBox.Ok)
            return

        warnings = 0
        for file in files:
            cur = self.settings['conn'].cursor()
            cur.execute(
                "select name, id, file, memo, owner, date, dateM, status from source where id=?",
                [file['id']])
            currentfile = cur.fetchone()
            text = currentfile[2]
            textStarts = [
                match.start()
                for match in re.finditer(re.escape(startMark), text)
            ]
            textEnds = [
                match.start()
                for match in re.finditer(re.escape(endMark), text)
            ]
            #print(textStarts, textEnds)

            #add new code linkage items to database
            for startPos in textStarts:
                selend = -1  #temp
                textEndIterator = 0
                try:
                    while startPos >= textEnds[textEndIterator]:
                        textEndIterator += 1
                except IndexError:
                    # could not find end mark
                    textEndIterator = -1
                    warnings += 1

                if textEndIterator >= 0:
                    selend = textEnds[textEndIterator]

                    item = {
                        'caseid':
                        int(self.cases[row]['id']),
                        'fid':
                        int(file['id']),
                        'selfirst':
                        startPos,
                        'selend':
                        selend,
                        'status':
                        1,
                        'owner':
                        self.settings['codername'],
                        'date':
                        datetime.datetime.now().strftime(
                            "%a %b %d %H:%M:%S %Y"),
                        'memo':
                        ""
                    }

                    cur = self.settings['conn'].cursor()
                    cur.execute(
                        "insert into caselinkage (caseid,fid,selfirst,selend,status,owner,date,memo) values(?,?,?,?,?,?,?,?)",
                        (item['caseid'], item['fid'], item['selfirst'],
                         item['selend'], item['status'], item['owner'],
                         item['date'], item['memo']))
                    self.settings['conn'].commit()

        if warnings > 0:
            QtGui.QMessageBox.warning(
                None, 'Warning',
                str(warnings) + " end mark did not match up",
                QtGui.QMessageBox.Ok)

        self.tableWidget_cases.clearSelection()
Beispiel #13
0
    def mergeCats(self):
        """When merge categories button is pressed, merge two or more categories into one category.
        Note: there is no undo for this """

        removeCats = []
        for itemWidget in self.tableWidget_cats.selectedItems():
            removeTemp = {
                'name':
                self.tableWidget_cats.item(itemWidget.row(),
                                           self.CAT_NAME_COLUMN).text(),
                'catid':
                int(
                    self.tableWidget_cats.item(itemWidget.row(),
                                               self.CAT_ID_COLUMN).text())
            }
            # remove duplicate selections, have duplicates because tableWidget_cats is not row selection only
            addCat = True
            for remCat in removeCats:
                if removeTemp == remCat:
                    addCat = False
            if addCat: removeCats.append(removeTemp)

        if len(removeCats) < 2:
            return

        Dialog_selectcat = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(removeCats)
        ui.setupUi(Dialog_selectcat, "Merging, Select category to keep",
                   "single")
        ok = Dialog_selectcat.exec_()
        if not (ok):
            return
        keepCat = ui.getSelected()
        print("Keeping category: " + str(keepCat))
        for cat in removeCats:
            if cat['catid'] == keepCat['catid']:
                removeCats.remove(
                    cat)  # exclude the kept category from the remove list
        print("Removing categories: " + str(removeCats))

        cur = self.settings['conn'].cursor()
        for cat in removeCats:
            cur.execute("update treecode set catid=? where catid=?",
                        (keepCat['catid'], cat['catid']))
            cur.execute("delete from codecat where catid=?", (cat['catid'], ))

        # Refresh categories, treecat and self.tableWidget_cats
        for row in self.cats:
            self.tableWidget_cats.removeRow(0)

        self.cats = []
        cur.execute(
            "select name, cid, catid, owner, date, dateM, memo, status from codecat"
        )
        result = cur.fetchall()
        for row in result:
            self.cats.append({
                'name': row[0],
                'cid': row[1],
                'catid': row[2],
                'owner': row[3],
                'date': row[4],
                'dateM': row[5],
                'memo': row[6],
                'status': row[7]
            })

        self.treecode = []
        cur.execute(
            "select cid, catid, date, dateM, memo, status, owner from treecode"
        )
        result = cur.fetchall()
        for row in result:
            self.treecode.append({
                'cid': row[0],
                'catid': row[1],
                'date': row[2],
                'dateM': row[3],
                'memo': row[4],
                'status': row[5],
                'owner': row[6]
            })
        self.settings['conn'].commit()
        self.fillCatsTable()
Beispiel #14
0
    def mergeCodes(self):
        """When merge codes button is pressed, merge two or more codes into one code.
        Note: there is no undo for this """

        removeCodes = []
        for itemWidget in self.tableWidget_codes.selectedItems():
            removeTemp = {
                'name':
                self.tableWidget_codes.item(itemWidget.row(),
                                            self.CODE_NAME_COLUMN).text(),
                'cid':
                int(
                    self.tableWidget_codes.item(itemWidget.row(),
                                                self.CODE_ID_COLUMN).text())
            }
            # remove duplicate selections, have duplicates because tableWidget_codes is not row selection only
            addCode = True
            for remCode in removeCodes:
                if removeTemp == remCode:
                    addCode = False
            if addCode:
                removeCodes.append(removeTemp)
        if len(removeCodes) < 2:
            return

        Dialog_selectcode = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(removeCodes)
        ui.setupUi(Dialog_selectcode, "Merging, Select code to keep", "single")
        ok = Dialog_selectcode.exec_()
        if not (ok):
            return
        keepCode = ui.getSelected()
        #print(keepCode)
        #print(str(removeCodes))
        for code in removeCodes:
            if code['cid'] == keepCode['cid']:
                removeCodes.remove(
                    code)  # exclude the kept code from the remove list
        #print(str(removeCodes))
        cur = self.settings['conn'].cursor()
        for code in removeCodes:
            cur.execute("update treecode set cid=? where cid=?",
                        (keepCode['cid'], code['cid']))
            cur.execute("update coding set cid=? where cid=?",
                        (keepCode['cid'], code['cid']))
            cur.execute("update coding2 set cid=? where cid=?",
                        (keepCode['cid'], code['cid']))
            cur.execute("delete from freecode where id=?", (code['cid'], ))

        #have to refresh self.tableWidget_codes and freecode list
        for row in self.freecode:
            self.tableWidget_codes.removeRow(0)

        cur.execute(
            "select name, memo, owner, date, dateM, id, status, color from freecode"
        )
        result = cur.fetchall()
        self.freecode = []
        for row in result:
            self.freecode.append({
                'name': row[0],
                'memo': row[1],
                'owner': row[2],
                'date': row[3],
                'dateM': row[4],
                'id': row[5],
                'status': row[6],
                'color': row[7]
            })
        self.settings['conn'].commit()
        self.fillCodesTable()
Beispiel #15
0
    def autocode(self):
        """ Autocode text in one file or all files with selected code """

        row = self.tableWidget_codes.currentRow()
        if row == -1:
            QtGui.QMessageBox.warning(None, "Warning", "No code was selected", QtGui.QMessageBox.Ok)
            return

        # text, ok = QtGui.QInputDialog.getText(None, 'Autocode a word or phrase', 'Phrase:')
        # dialog too narrow, so code below
        dialog = QtGui.QInputDialog(None)
        dialog.setWindowTitle("Autocode")
        dialog.setInputMode(QtGui.QInputDialog.TextInput)
        dialog.setLabelText("Autocode a word or phrase with:\n" + str(self.freecode[row]["name"]))
        dialog.resize(200, 20)
        ok = dialog.exec_()
        if not ok:
            return

        findText = str(dialog.textValue())
        if findText == "" or findText is None:
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.filenames)
        ui.setupUi(Dialog_selectfile, "Select file to view", "many")  # many has no meaning but is not 'single'
        ok = Dialog_selectfile.exec_()
        if not ok:
            return
        files = ui.getSelected()
        if len(files) == 0:
            return

        for file in files:
            cur = self.settings["conn"].cursor()
            cur.execute("select name, id, file, memo, owner, date, dateM, status from source where id=?", [file["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": int(self.freecode[row]["id"]),
                    "fid": int(file["id"]),
                    "seltext": str(findText),
                    "selfirst": startPos,
                    "selend": startPos + len(findText),
                    "owner": self.settings["codername"],
                    "memo": "",
                    "date": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"),
                    "status": 1,
                }
                # print item
                cur = self.settings["conn"].cursor()
                cur.execute(
                    "insert into "
                    + self.settings["codertable"]
                    + " (cid,fid,seltext,selfirst,selend,owner,memo,date,status) values(?,?,?,?,?,?,?,?,?)",
                    (
                        item["cid"],
                        item["fid"],
                        item["seltext"].encode("raw_unicode_escape"),
                        item["selfirst"],
                        item["selend"],
                        item["owner"],
                        item["memo"],
                        item["date"],
                        item["status"],
                    ),
                )
                self.settings["conn"].commit()

                # if this is the currently open file update the coding list and GUI
                if file["id"] == self.filename["id"]:
                    self.coding.append(item)
            self.highlight()
Beispiel #16
0
    def automark(self):
        """ Automark text in one or more files with selected case """

        row = self.tableWidget_cases.currentRow()
        if row == -1:
            QtGui.QMessageBox.warning(None, 'Warning', "No case was selected", QtGui.QMessageBox.Ok)
            return

        Dialog_selectfile = QtGui.QDialog()
        ui = Ui_Dialog_selectfile(self.source)
        ui.setupUi(Dialog_selectfile,"Select file(s) to assign case", "many") # many has no real meaning but is not 'single'
        ok = Dialog_selectfile.exec_()
        if not ok:
            return
        files = ui.getSelected()
        if len(files) == 0:
            QtGui.QMessageBox.warning(None, 'Warning', "No file was selected", QtGui.QMessageBox.Ok)
            return

        dialog =  QtGui.QDialog()
        ui = Ui_Dialog_autoassign(self.cases[row]['name'])
        ui.setupUi(dialog)
        ok = dialog.exec_()
        if not ok:
            return

        startMark = ui.getStartMark()
        endMark = ui.getEndMark()
        if startMark == "" or endMark == "":
            QtGui.QMessageBox.warning(None, 'Warning', "Cannot have blank text marks", QtGui.QMessageBox.Ok)
            return

        warnings = 0
        for file in files:
            cur = self.settings['conn'].cursor()
            cur.execute("select name, id, file, memo, owner, date, dateM, status from source where id=?",[file['id']])
            currentfile = cur.fetchone()
            text = currentfile[2]
            textStarts = [match.start() for match in re.finditer(re.escape(startMark), text)]
            textEnds = [match.start() for match in re.finditer(re.escape(endMark), text)]
            #print(textStarts, textEnds)

            #add new code linkage items to database
            for startPos in textStarts:
                selend = -1  #temp
                textEndIterator = 0
                try:
                    while startPos >= textEnds[textEndIterator]:
                        textEndIterator += 1
                except IndexError:
                    # could not find end mark
                    textEndIterator = -1
                    warnings += 1

                if textEndIterator >= 0:
                    selend = textEnds[textEndIterator]

                    item = {'caseid':int(self.cases[row]['id']), 'fid':int(file['id']), 'selfirst':startPos, 'selend':selend, 'status':1,
                    'owner':self.settings['codername'], 'date':datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), 'memo':""}

                    cur = self.settings['conn'].cursor()
                    cur.execute("insert into caselinkage (caseid,fid,selfirst,selend,status,owner,date,memo) values(?,?,?,?,?,?,?,?)"
                        ,(item['caseid'], item['fid'], item['selfirst'], item['selend'], item['status'],
                          item['owner'], item['date'], item['memo']))
                    self.settings['conn'].commit()

        if warnings > 0:
            QtGui.QMessageBox.warning(None, 'Warning',str(warnings)+" end mark did not match up", QtGui.QMessageBox.Ok)

        self.tableWidget_cases.clearSelection()