Ejemplo n.º 1
0
    def cell_selected(self):
        '''
        Highlight case text if a file is selected.
        Indicate memo is present, update memo text, or delete memo by clearing text.
        '''

        x = self.ui.tableWidget.currentRow()
        y = self.ui.tableWidget.currentColumn()

        if x == -1:
            self.selected_case = None
            self.ui.textBrowser.clear()
            self.case_text = []
            return
        self.selected_case = self.cases[x]
        # clear case text viewed if the caseid has changed
        if self.caseTextViewed != [] and self.caseTextViewed[0][
                'caseid'] != self.selected_case['caseid']:
            self.caseTextViewed = []
            self.case_text = []
            self.ui.textBrowser.clear()
        self.unlight()
        #logger.debug("Selected case: " + str(self.selected_case['id']) +" "+self.selected_case['name'])
        # get case_text for this file
        if self.selected_file is not None:
            #logger.debug("File Selected: " + str(self.selected_file['id'])+"  "+self.selected_file['file'])
            self.case_text = []
            cur = self.settings['conn'].cursor()
            cur.execute(
                "select caseid, fid, pos0, pos1, owner, date, memo from case_text where fid = ? and caseid = ?",
                [self.selected_file['id'], self.selected_case['caseid']])
            result = cur.fetchall()
            for row in result:
                self.case_text.append({
                    'caseid': row[0],
                    'fid': row[1],
                    'pos0': row[2],
                    'pos1': row[3],
                    'owner': row[4],
                    'date': row[5],
                    'memo': row[6]
                })
        self.highlight()

        if y == self.MEMO_COLUMN:
            ui = DialogMemo(self.settings,
                            "Memo for case " + self.cases[x]['name'],
                            self.cases[x]['memo'])
            ui.exec_()
            self.cases[x]['memo'] = ui.memo
            cur = self.settings['conn'].cursor()
            cur.execute('update cases set memo=? where caseid=?',
                        (self.cases[x]['memo'], self.cases[x]['caseid']))
            self.settings['conn'].commit()
            if self.cases[x]['memo'] == "":
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN,
                                            QtWidgets.QTableWidgetItem())
            else:
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN,
                                            QtWidgets.QTableWidgetItem("Yes"))
Ejemplo n.º 2
0
    def cell_selected(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.ui.tableWidget.currentRow()
        y = self.ui.tableWidget.currentColumn()
        if y == self.MEMO_COLUMN:
            ui = DialogMemo(
                self.app,
                _("Memo for Attribute ") + self.attribute_type[x]['name'],
                self.attribute_type[x]['memo'])
            ui.exec_()
            memo = ui.memo
            if memo != self.attribute_type[x]['memo']:
                self.attribute_type[x]['memo'] = memo
                cur = self.app.conn.cursor()
                cur.execute("update attribute_type set memo=? where name=?",
                            (memo, self.attribute_type[x]['name']))
                self.app.conn.commit()
            if memo == "":
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN,
                                            QtWidgets.QTableWidgetItem())
            else:
                self.ui.tableWidget.setItem(
                    x, self.MEMO_COLUMN, QtWidgets.QTableWidgetItem(_("Yes")))
            self.attribute_type[x]['memo'] = str(memo)
Ejemplo n.º 3
0
    def cell_selected(self):
        """ Highlight case text if a file is selected.
        Indicate memo is present, update memo text, or delete memo by clearing text.
        """

        self.ui.textBrowser.clear()
        x = self.ui.tableWidget.currentRow()
        y = self.ui.tableWidget.currentColumn()
        if x == -1:
            self.selected_case = None
            self.case_text = []
            return
        self.selected_case = self.cases[x]
        if self.count_selected_items() > 1:
            return

        #logger.debug("Selected case: " + str(self.selected_case['id']) +" "+self.selected_case['name'])'''
        # get case_text for this file
        if self.selected_file is not None:
            #logger.debug("File Selected: " + str(self.selected_file['id'])+"  "+self.selected_file['file'])
            self.case_text = []
            cur = self.app.conn.cursor()
            cur.execute(
                "select caseid, fid, pos0, pos1, owner, date, memo from case_text where fid = ? and caseid = ?",
                [self.selected_file['id'], self.selected_case['caseid']])
            result = cur.fetchall()
            for row in result:
                self.case_text.append({
                    'caseid': row[0],
                    'fid': row[1],
                    'pos0': row[2],
                    'pos1': row[3],
                    'owner': row[4],
                    'date': row[5],
                    'memo': row[6]
                })

        # if y == self.NAME_COLUMN:
        self.view()

        if y == self.MEMO_COLUMN:
            ui = DialogMemo(self.app,
                            _("Memo for case ") + self.cases[x]['name'],
                            self.cases[x]['memo'])
            ui.exec_()
            self.cases[x]['memo'] = ui.memo
            cur = self.app.conn.cursor()
            cur.execute('update cases set memo=? where caseid=?',
                        (self.cases[x]['memo'], self.cases[x]['caseid']))
            self.app.conn.commit()
            if self.cases[x]['memo'] == "" or self.cases[x]['memo'] is None:
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN,
                                            QtWidgets.QTableWidgetItem())
            else:
                self.ui.tableWidget.setItem(
                    x, self.MEMO_COLUMN, QtWidgets.QTableWidgetItem(_("Memo")))
            self.app.delete_backup = False

        if y == self.FILES_COLUMN:
            self.open_case_file_manager()
Ejemplo n.º 4
0
    def create(self):
        ''' Create a new text file by entering text into the dialog.
        Implements the QtDesigner memo dialog '''

        name, ok = QtWidgets.QInputDialog.getText(self, 'New File', 'Enter the file name:')
        if not ok:
            return
        if name is None or name == "":
            QtWidgets.QMessageBox.warning(None, 'Warning',"No filename was selected", QtWidgets.QMessageBox.Ok)
            return
        # check for non-unique filename
        if any(d['name'] == name for d in self.source):
            QtWidgets.QMessageBox.warning(None, 'Warning',"Filename in use", QtWidgets.QMessageBox.Ok)
            return

        ui = DialogMemo(self.settings, "Creating a new file: " + name)
        ui.exec_()
        filetext = ui.memo
        # update database
        entry = {'name': name, 'id': -1, 'fulltext': filetext, 'memo': "",
        'owner': self.settings['codername'], 'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        'mediapath': None}
        cur = self.settings['conn'].cursor()
        cur.execute("insert into source(name,fulltext,mediapath,memo,owner,date) values(?,?,?,?,?,?)",
            (entry['name'], entry['fulltext'], entry['mediapath'], entry['memo'], entry['owner'], entry['date']))
        self.settings['conn'].commit()
        self.parent_textEdit.append("File created: " + entry['name'])
        self.source.append(entry)
        self.fill_table()
Ejemplo n.º 5
0
    def annotate(self, location):
        """ Add view, or remove an annotation for selected text.
        Annotation positions are displayed as bold text.
        """

        if self.filename == {}:
            QtWidgets.QMessageBox.warning(None, _('Warning'), _("No file was selected"))
            return
        pos0 = self.ui.textEdit.textCursor().selectionStart()
        pos1 = self.ui.textEdit.textCursor().selectionEnd()
        text_length = len(self.ui.textEdit.toPlainText())
        if pos0 >= text_length or pos1 >= text_length:
            return
        item = None
        details = ""
        annotation = ""
        # find existing annotation at this position for this file
        for note in self.annotations:
            if location >= note['pos0'] and location <= note['pos1'] and note['fid'] == self.filename['id']:
                item = note  # use existing annotation
                details = item['owner'] + " " + item['date']
        # exit method if no text selected and there is not annotation at this position
        if pos0 == pos1 and item is None:
            return
        # add new item to annotations, add to database and update GUI
        if item is None:
            item = {'fid': int(self.filename['id']), 'pos0': pos0, 'pos1': pos1,
            'memo': str(annotation), 'owner': self.settings['codername'],
            'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'anid': -1}
        ui = DialogMemo(self.settings, _("Annotation: ") + details, item['memo'])
        ui.exec_()
        item['memo'] = ui.memo
        if item['memo'] != "":
            cur = self.settings['conn'].cursor()
            cur.execute("insert into annotation (fid,pos0, pos1,memo,owner,date) \
                values(?,?,?,?,?,?)" ,(item['fid'], item['pos0'], item['pos1'],
                item['memo'], item['owner'], item['date']))
            self.settings['conn'].commit()
            cur.execute("select last_insert_rowid()")
            anid = cur.fetchone()[0]
            item['anid'] = anid
            self.annotations.append(item)
            self.highlight()
            self.parent_textEdit.append(_("Annotation added at position: ") \
                + str(item['pos0']) + "-" + str(item['pos1']) + _(" for: ") + self.filename['name'])
        # if blank delete the annotation
        if item['memo'] == "":
            cur = self.settings['conn'].cursor()
            cur.execute("delete from annotation where pos0 = ?", (item['pos0'], ))
            self.settings['conn'].commit()
            for note in self.annotations:
                if note['pos0'] == item['pos0'] and note['fid'] == item['fid']:
                    self.annotations.remove(note)
            self.parent_textEdit.append(_("Annotation removed from position ") \
                + str(item['pos0']) + _(" for: ") + self.filename['name'])
        self.unlight()
        self.highlight()
Ejemplo n.º 6
0
    def image_memo(self):
        """ Create a memo for the image file. """

        ui = DialogMemo(self.app, _("Memo for image ") + self.file_['name'],
            self.file_['memo'])
        ui.exec_()
        cur = self.app.conn.cursor()
        cur.execute('update source set memo=? where id=?', (ui.memo, self.file_['id']))
        self.app.conn.commit()
        self.file_['memo'] = ui.memo
Ejemplo n.º 7
0
    def image_memo(self):
        ''' Create a memo for the image file '''

        ui = DialogMemo(self.settings, "Memo for image " + self.file_['name'],
                        self.file_['memo'])  # "id=" + str(self.file_['id']))
        ui.exec_()
        cur = self.settings['conn'].cursor()
        cur.execute('update source set memo=? where id=?',
                    (ui.memo, self.file_['id']))
        self.settings['conn'].commit()
        self.file_['memo'] = ui.memo
Ejemplo n.º 8
0
    def coded_area_memo(self, item):
        ''' Add memo to this coded area '''

        ui = DialogMemo(self.settings,
                        "Memo for coded area of " + self.file_['name'],
                        item['memo'])
        ui.exec_()
        memo = ui.memo
        if memo != item['memo']:
            item['memo'] = memo
            cur = self.settings['conn'].cursor()
            cur.execute('update code_image set memo=? where id=?',
                        (ui.memo, item['id']))
            self.settings['conn'].commit()
Ejemplo n.º 9
0
    def project_memo(self):
        ''' Give the entire project a memo '''

        cur = self.settings['conn'].cursor()
        cur.execute("select memo from project")
        memo = cur.fetchone()[0]
        ui = DialogMemo(self.settings,
                        "Memo for project " + self.settings['projectName'],
                        memo)
        ui.exec_()
        if memo != ui.memo:
            cur.execute('update project set memo=?', (ui.memo, ))
            self.settings['conn'].commit()
            self.ui.textEdit.append("Project memo entered.")
Ejemplo n.º 10
0
    def project_memo(self):
        """ Give the entire project a memo. Modal dialog. """

        cur = self.app.conn.cursor()
        cur.execute("select memo from project")
        memo = cur.fetchone()[0]
        ui = DialogMemo(self.app, _("Memo for project ") + self.app.project_name,
            memo)
        self.dialogList.append(ui)
        ui.exec_()
        if memo != ui.memo:
            cur.execute('update project set memo=?', (ui.memo,))
            self.app.conn.commit()
            self.ui.textEdit.append(_("Project memo entered."))
Ejemplo n.º 11
0
    def coded_area_memo(self, item):
        """ Add memo to this coded area. """

        ui = DialogMemo(self.app, _("Memo for coded area of ") + self.file_['name'],
            item['memo'])
        ui.exec_()
        memo = ui.memo
        if memo != item['memo']:
            item['memo'] = memo
            cur = self.app.conn.cursor()
            cur.execute('update code_image set memo=? where imid=?', (ui.memo, item['imid']))
            self.app.conn.commit()
        # re-draw to update memos in tooltips
        self.draw_coded_areas()
Ejemplo n.º 12
0
    def cell_selected(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.ui.tableWidget.currentRow()
        y = self.ui.tableWidget.currentColumn()

        if y == self.MEMO_COLUMN:
            name =self.source[x]['name'].lower()
            if name[-5:] == ".jpeg" or name[-4:] in ('.jpg', '.png', '.gif'):
                ui = DialogMemo(self.settings, "Memo for file " + self.source[x]['name'],
                self.source[x]['memo'])
                ui.exec_()
                self.source[x]['memo'] = ui.memo
                cur = self.settings['conn'].cursor()
                cur.execute('update source set memo=? where id=?', (ui.memo, self.source[x]['id']))
                self.settings['conn'].commit()
            else:
                ui = DialogMemo(self.settings, "Memo for file " + self.source[x]['name'],
                self.source[x]['memo'])
                ui.exec_()
                self.source[x]['memo'] = ui.memo
                cur = self.settings['conn'].cursor()
                cur.execute('update source set memo=? where id=?', (ui.memo, self.source[x]['id']))
                self.settings['conn'].commit()
            if self.source[x]['memo'] == "":
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN, QtWidgets.QTableWidgetItem())
            else:
                self.ui.tableWidget.setItem(x, self.MEMO_COLUMN, QtWidgets.QTableWidgetItem("Yes"))
Ejemplo n.º 13
0
    def project_memo(self):
        """ Give the entire project a memo. """

        for d in self.dialogList:
            if type(d).__name__ == "DialogMemo":
                return
        cur = self.settings['conn'].cursor()
        cur.execute("select memo from project")
        memo = cur.fetchone()[0]
        ui = DialogMemo(self.settings, "Memo for project " + self.settings['projectName'],
            memo)
        self.dialogList.append(ui)
        ui.show()
        if memo != ui.memo:
            cur.execute('update project set memo=?', (ui.memo,))
            self.settings['conn'].commit()
            self.ui.textEdit.append("Project memo entered.")
Ejemplo n.º 14
0
    def add_edit_code_memo(self, selected):
        """ View and edit a memo. """

        if selected.text(1)[0:3] == 'cid':
            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
            ui = DialogMemo(self.app,
                            _("Memo for Code ") + self.codes[found]['name'],
                            self.codes[found]['memo'])
            ui.exec_()
            memo = ui.memo
            if memo == "":
                selected.setData(2, QtCore.Qt.DisplayRole, "")
            else:
                selected.setData(2, QtCore.Qt.DisplayRole, _("Memo"))
            # update codes list and database
            if memo != self.codes[found]['memo']:
                self.codes[found]['memo'] = memo
                cur = self.app.conn.cursor()
                cur.execute("update code_name set memo=? where cid=?",
                            (memo, self.codes[found]['cid']))
                self.app.conn.commit()
                self.app.delete_backup = False

        if selected.text(1)[0:3] == 'cat':
            # find the category in the list
            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
            ui = DialogMemo(
                self.app,
                _("Memo for Category: ") + self.categories[found]['name'],
                self.categories[found]['memo'])
            ui.exec_()
            memo = ui.memo
            if memo == "":
                selected.setData(2, QtCore.Qt.DisplayRole, "")
            else:
                selected.setData(2, QtCore.Qt.DisplayRole, _("Memo"))
            # update codes list and database
            if memo != self.categories[found]['memo']:
                self.categories[found]['memo'] = memo
                cur = self.app.conn.cursor()
                cur.execute("update code_cat set memo=? where catid=?",
                            (memo, self.categories[found]['catid']))
                self.app.conn.commit()
                self.app.delete_backup = False
        self.update_dialog_codes_and_categories()
Ejemplo n.º 15
0
    def add_edit_memo(self, selected):
        """ View and edit a memo for a category or code. """

        if selected.text(1)[0:3] == 'cid':
            # find the code in the list
            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
            ui = DialogMemo(self.settings,
                            _("Memo for Code: ") + self.codes[found]['name'],
                            self.codes[found]['memo'])
            ui.exec_()
            memo = ui.memo
            if memo != self.codes[found]['memo']:
                self.codes[found]['memo'] = memo
                cur = self.settings['conn'].cursor()
                cur.execute("update code_name set memo=? where cid=?",
                            (memo, self.codes[found]['cid']))
                self.settings['conn'].commit()
            if memo == "":
                selected.setData(2, QtCore.Qt.DisplayRole, "")
            else:
                selected.setData(2, QtCore.Qt.DisplayRole, _("Memo"))
                self.parent_textEdit.append(
                    _("Memo for code: ") + self.codes[found]['name'])

        if selected.text(1)[0:3] == 'cat':
            # find the category in the list
            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
            ui = DialogMemo(
                self.settings,
                _("Memo for Category: ") + self.categories[found]['name'],
                self.categories[found]['memo'])
            ui.exec_()
            memo = ui.memo
            if memo != self.categories[found]['memo']:
                self.categories[found]['memo'] = memo
                cur = self.settings['conn'].cursor()
                cur.execute("update code_cat set memo=? where catid=?",
                            (memo, self.categories[found]['catid']))
                self.settings['conn'].commit()
            if memo == "":
                selected.setData(2, QtCore.Qt.DisplayRole, "")
            else:
                selected.setData(2, QtCore.Qt.DisplayRole, _("Memo"))
                self.parent_textEdit.append(
                    _("Memo for category: ") + self.categories[found]['name'])
Ejemplo n.º 16
0
    def add_edit_memo(self, data):
        """ Add or edit memos for codes and categories. """

        if data['cid'] is not None:
            ui = DialogMemo(self.settings, "Memo for Code " + data['name'], data['memo'])
            ui.exec_()
            self.data['memo'] = ui.memo
            cur = self.settings['conn'].cursor()
            cur.execute("update code_name set memo=? where cid=?", (self.data['memo'], self.data['cid']))
            self.settings['conn'].commit()
        if data['catid'] is not None and data['cid'] is None:
            ui = DialogMemo(self.settings, "Memo for Category " + data['name'], data['memo'])
            ui.exec_()
            self.data['memo'] = ui.memo
            cur = self.settings['conn'].cursor()
            cur.execute("update code_cat set memo=? where catid=?", (self.data['memo'], self.data['catid']))
            self.settings['conn'].commit()
Ejemplo n.º 17
0
    def add_edit_memo(self, data):
        ''' delete this method later '''

        if data['cid'] is not None:
            ui = DialogMemo(self.settings, "Memo for Code " + data['name'],
                            data['memo'])
            ui.exec_()
            self.data['memo'] = ui.memo
            cur = self.settings['conn'].cursor()
            cur.execute("update code_name set memo=? where cid=?",
                        (self.data['memo'], self.data['cid']))
            self.settings['conn'].commit()
        if data['catid'] is not None and data['cid'] is None:
            ui = DialogMemo(self.settings, "Memo for Category " + data['name'],
                            data['memo'])
            ui.exec_()
            self.data['memo'] = ui.memo
            cur = self.settings['conn'].cursor()
            cur.execute("update code_cat set memo=? where catid=?",
                        (self.data['memo'], self.data['catid']))
            self.settings['conn'].commit()