Example #1
0
    def __init__(self, parent, id, title, note_object):
        # Make the Keyword Edit List resizable by passing wx.RESIZE_BORDER style
        Dialogs.GenForm.__init__(self, parent, id, title, size=(400, 260), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                                 useSizers = True, HelpContext='Notes')  # 'Notes' is the Help Context for Notes.  There is no entry for Note Properties at this time

        self.obj = note_object
        seriesID = ''
        episodeID = ''
        transcriptID = ''
        collectionID = ''
        clipID = ''
        snapshotID = ''
        documentID = ''
        quoteID = ''
        if (self.obj.series_num != 0) and (self.obj.series_num != None):
            tempLibrary = Library.Library(self.obj.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.episode_num != 0) and (self.obj.episode_num != None):
            tempEpisode = Episode.Episode(self.obj.episode_num)
            episodeID = tempEpisode.id
            tempLibrary = Library.Library(tempEpisode.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.transcript_num != 0) and (self.obj.transcript_num != None):
            # To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
            tempTranscript = Transcript.Transcript(self.obj.transcript_num, skipText=True)
            transcriptID = tempTranscript.id
            tempEpisode = Episode.Episode(tempTranscript.episode_num)
            episodeID = tempEpisode.id
            tempLibrary = Library.Library(tempEpisode.series_num)
            seriesID = tempLibrary.id
        elif (self.obj.collection_num != 0) and (self.obj.collection_num != None):
            tempCollection = Collection.Collection(self.obj.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.clip_num != 0) and (self.obj.clip_num != None):
            # We can skip loading the Clip Transcript to save load time
            tempClip = Clip.Clip(self.obj.clip_num, skipText=True)
            clipID = tempClip.id
            tempCollection = Collection.Collection(tempClip.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.snapshot_num != 0) and (self.obj.snapshot_num != None):
            tempSnapshot = Snapshot.Snapshot(self.obj.snapshot_num)
            snapshotID = tempSnapshot.id
            tempCollection = Collection.Collection(tempSnapshot.collection_num)
            collectionID = tempCollection.GetNodeString()
        elif (self.obj.document_num != 0) and (self.obj.document_num != None):
            tempDocument = Document.Document(self.obj.document_num)
            documentID = tempDocument.id
            tempLibrary = Library.Library(tempDocument.library_num)
            seriesID = tempLibrary.id
        elif (self.obj.quote_num != 0) and (self.obj.quote_num != None):
            tempQuote = Quote.Quote(num=self.obj.quote_num, skipText=True)
            quoteID = tempQuote.id
            tempCollection = Collection.Collection(tempQuote.collection_num)
            collectionID = tempCollection.GetNodeString()
            
        # Create the form's main VERTICAL sizer
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        # Create a HORIZONTAL sizer for the first row
        r1Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v1 = wx.BoxSizer(wx.VERTICAL)
        # Note ID
        id_edit = self.new_edit_box(_("Note ID"), v1, self.obj.id, maxLen=100)
        # Add the element to the sizer
        r1Sizer.Add(v1, 1, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r1Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r2Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v2 = wx.BoxSizer(wx.VERTICAL)
        # Library ID
        seriesID_edit = self.new_edit_box(_("Library ID"), v2, seriesID)
        # Add the element to the row sizer
        r2Sizer.Add(v2, 1, wx.EXPAND)
        seriesID_edit.Enable(False)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r2Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r3Sizer = wx.BoxSizer(wx.HORIZONTAL)

        if TransanaConstants.proVersion:
            # Create a VERTICAL sizer for the next element
            v9 = wx.BoxSizer(wx.VERTICAL)
            # Document ID
            documentID_edit = self.new_edit_box(_("Document ID"), v9, documentID)
            # Add the element to the row sizer
            r3Sizer.Add(v9, 1, wx.EXPAND)
            documentID_edit.Enable(False)

            # Add a horizontal spacer to the row sizer        
            r3Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v3 = wx.BoxSizer(wx.VERTICAL)
        # Episode ID
        episodeID_edit = self.new_edit_box(_("Episode ID"), v3, episodeID)
        # Add the element to the row sizer
        r3Sizer.Add(v3, 1, wx.EXPAND)
        episodeID_edit.Enable(False)

        # Add a horizontal spacer to the row sizer        
        r3Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v4 = wx.BoxSizer(wx.VERTICAL)
        # Transcript ID
        transcriptID_edit = self.new_edit_box(_("Transcript ID"), v4, transcriptID)
        # Add the element to the row sizer
        r3Sizer.Add(v4, 1, wx.EXPAND)
        transcriptID_edit.Enable(False)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r3Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r5Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v5 = wx.BoxSizer(wx.VERTICAL)
        # Collection ID
        collectionID_edit = self.new_edit_box(_("Collection ID"), v5, collectionID)
        # Add the element to the row sizer
        r5Sizer.Add(v5, 2, wx.EXPAND)
        collectionID_edit.Enable(False)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r5Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r6Sizer = wx.BoxSizer(wx.HORIZONTAL)

        if TransanaConstants.proVersion:
            # Create a VERTICAL sizer for the next element
            v7 = wx.BoxSizer(wx.VERTICAL)
            # Quote ID
            quoteID_edit = self.new_edit_box(_("Quote ID"), v7, quoteID)
            # Add the element to the row sizer
            r6Sizer.Add(v7, 1, wx.EXPAND)
            quoteID_edit.Enable(False)

            # Add a horizontal spacer to the row sizer        
            r6Sizer.Add((10, 0))

        # Create a VERTICAL sizer for the next element
        v6 = wx.BoxSizer(wx.VERTICAL)
        # Clip ID
        clipID_edit = self.new_edit_box(_("Clip ID"), v6, clipID)
        # Add the element to the row sizer
        r6Sizer.Add(v6, 1, wx.EXPAND)
        clipID_edit.Enable(False)

        if TransanaConstants.proVersion:
            # Add a horizontal spacer to the row sizer        
            r6Sizer.Add((10, 0))

            # Create a VERTICAL sizer for the next element
            v8 = wx.BoxSizer(wx.VERTICAL)
            # Snapshot ID
            snapshotID_edit = self.new_edit_box(_("Snapshot ID"), v8, snapshotID)
            # Add the element to the row sizer
            r6Sizer.Add(v8, 1, wx.EXPAND)
            snapshotID_edit.Enable(False)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r6Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a HORIZONTAL sizer for the next row
        r8Sizer = wx.BoxSizer(wx.HORIZONTAL)

        # Create a VERTICAL sizer for the next element
        v8 = wx.BoxSizer(wx.VERTICAL)
        # Comment layout
        noteTaker_edit = self.new_edit_box(_("Note Taker"), v8, self.obj.author, maxLen=100)
        # Add the element to the row sizer
        r8Sizer.Add(v8, 2, wx.EXPAND)

        # Add the row sizer to the main vertical sizer
        mainSizer.Add(r8Sizer, 0, wx.EXPAND)

        # Add a vertical spacer to the main sizer        
        mainSizer.Add((0, 10))

        # Create a sizer for the buttons
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        # Add the buttons
        self.create_buttons(sizer=btnSizer)
        # Add the button sizer to the main sizer
        mainSizer.Add(btnSizer, 0, wx.EXPAND)
        # If Mac ...
        if 'wxMac' in wx.PlatformInfo:
            # ... add a spacer to avoid control clipping
            mainSizer.Add((0, 2))

        # Set the PANEL's main sizer
        self.panel.SetSizer(mainSizer)
        # Tell the PANEL to auto-layout
        self.panel.SetAutoLayout(True)
        # Lay out the Panel
        self.panel.Layout()
        # Lay out the panel on the form
        self.Layout()
        # Resize the form to fit the contents
        self.Fit()

        # Get the new size of the form
        (width, height) = self.GetSizeTuple()
        # Reset the form's size to be at least the specified minimum width
        self.SetSize(wx.Size(max(400, width), height))
        # Define the minimum size for this dialog as the current size, and define height as unchangeable
        self.SetSizeHints(max(400, width), height, -1, height)
        # Center the form on screen
        TransanaGlobal.CenterOnPrimary(self)
        
        # Set focus to the Note ID
        id_edit.SetFocus()
Example #2
0
    def OnSnapshot(self, event):
        """ Handle the Snapshot button press """

        # Just because the media file is showing doesn't mean it's the CURRENT item in the Transana interface.
        # Let's bring the Transcript forward, making the media file part of the CURRENT interface
        self.parent.ControlObject.BringTranscriptToFront()
        
        # Create the Media Conversion dialog, including Clip Information so we export only the clip segment
        convertDlg = MediaConvert.MediaConvert(self, self.parent.ControlObject.currentObj.media_filename,
                                               self.parent.ControlObject.GetVideoPosition(), snapshot=True)
        # Show the Media Conversion Dialog
        convertDlg.ShowModal()
        # If the user took a snapshop and the image was successfully created ...
        if convertDlg.snapshotSuccess and os.path.exists(convertDlg.txtDestFileName.GetValue() % 1):
            imgFile = convertDlg.txtDestFileName.GetValue() % 1
            # Set the field value to the file name selected
            self.fname_edit.SetValue(imgFile)
            # If the form's ID field is empty ...
            if self.id_edit.GetValue() == '':
                # ... get the base filename
                tempFilename = os.path.basename(imgFile)
                # ... separate the filename root and extension
                (self.obj.id, tempExt) = os.path.splitext(tempFilename)
                # ... and set the ID to match the base file name
                self.id_edit.SetValue(self.obj.id)
            # If the Snapshot comes from an Episode ...
            if isinstance(self.parent.ControlObject.currentObj, Episode.Episode):
                self.obj.series_num = self.parent.ControlObject.currentObj.series_num
                self.obj.series_id = self.parent.ControlObject.currentObj.series_id
                self.obj.episode_num = self.parent.ControlObject.currentObj.number
                self.obj.episode_id = self.parent.ControlObject.currentObj.id
                self.obj.transcript_num = self.parent.ControlObject.TranscriptWindow.dlg.editor.TranscriptObj.number
                self.series_cb.SetStringSelection(self.obj.series_id)
                self.PopulateEpisodeChoiceBasedOnSeries(self.obj.series_id)
                self.episode_cb.SetStringSelection(self.obj.episode_id)
                self.PopulateTranscriptChoiceBasedOnEpisode(self.obj.series_id, self.obj.episode_id)
                tmpTranscript = Transcript.Transcript(self.obj.transcript_num)
                self.transcript_cb.SetStringSelection(tmpTranscript.id)
                self.obj.episode_start = self.parent.ControlObject.GetVideoPosition()
                self.episode_start_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_start))
                self.episode_start_edit.Enable(True)
                self.obj.episode_duration = 10000
                self.episode_duration_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_duration))
                self.episode_duration_edit.Enable(True)
            # If the Snapshot comes from a Clip ...
            elif isinstance(self.parent.ControlObject.currentObj, Clip.Clip):
                self.obj.episode_num = self.parent.ControlObject.currentObj.episode_num
                tmpEpisode = Episode.Episode(self.obj.episode_num)
                self.obj.series_num = tmpEpisode.series_num
                self.obj.series_id = tmpEpisode.series_id
                self.obj.episode_id = tmpEpisode.id
                # We need the Clip's SOURCE TRANSCRIPT for the Active Transcript
                self.obj.transcript_num = self.parent.ControlObject.currentObj.transcripts[self.parent.ControlObject.activeTranscript].source_transcript
                self.series_cb.SetStringSelection(self.obj.series_id)
                self.PopulateEpisodeChoiceBasedOnSeries(self.obj.series_id)
                self.episode_cb.SetStringSelection(self.obj.episode_id)
                self.PopulateTranscriptChoiceBasedOnEpisode(self.obj.series_id, self.obj.episode_id)
                tmpTranscript = Transcript.Transcript(self.obj.transcript_num)
                self.transcript_cb.SetStringSelection(tmpTranscript.id)
                self.obj.episode_start = self.parent.ControlObject.currentObj.clip_start
                self.episode_start_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_start))
                self.episode_start_edit.Enable(True)
                self.obj.episode_duration = self.parent.ControlObject.currentObj.clip_stop - self.parent.ControlObject.currentObj.clip_start - 0.1
                self.episode_duration_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_duration))
                self.episode_duration_edit.Enable(True)

        # We need to explicitly Close the conversion dialog here to force cleanup of temp files in some circumstances
        convertDlg.Close()
        # Destroy the Media Conversion Dialog
        convertDlg.Destroy()
Example #3
0
        def __init__(self, parent, ID, title):
            # Specify the Internationalization Base
            gettext.install("ReportPrintoutClass")
            # Create the basic Frame structure with a white background
            self.frame = wx.Frame.__init__(self,
                                           parent,
                                           ID,
                                           'Transana - %s' % title,
                                           pos=(10, 10),
                                           size=(300, 150),
                                           style=wx.DEFAULT_FRAME_STYLE
                                           | wx.TAB_TRAVERSAL
                                           | wx.NO_FULL_REPAINT_ON_RESIZE)
            self.title = title
            self.SetBackgroundColour(wx.WHITE)

            # Add a Menu Bar
            menuBar = wx.MenuBar()  # Create the Menu Bar
            self.menuFile = wx.Menu()  # Create the File Menu
            self.menuFile.Append(
                M_FILE_PRINTSETUP, "Printer Setup",
                "Set up Printer")  # Add "Printer Setup" to the File Menu
            self.menuFile.Append(M_FILE_PRINTPREVIEW, "Print Preview",
                                 "Preview your printed output"
                                 )  # Add "Print Preview" to the File Menu
            self.menuFile.Append(M_FILE_PRINT, "&Print",
                                 "Send your output to the Printer"
                                 )  # Add "Print" to the File Menu
            self.menuFile.Append(M_FILE_EXIT, "E&xit", "Exit the %s program" %
                                 self.title)  # Add "Exit" to the File Menu
            menuBar.Append(self.menuFile,
                           '&File')  # Add the File Menu to the Menu Bar
            wx.EVT_MENU(
                self, M_FILE_PRINTSETUP,
                self.OnPrintSetup)  # Attach File > Print Setup to a method
            wx.EVT_MENU(
                self, M_FILE_PRINTPREVIEW,
                self.OnPrintPreview)  # Attach File > Print Preview to a method
            wx.EVT_MENU(self, M_FILE_PRINT,
                        self.OnPrint)  # Attach File > Print to a method
            wx.EVT_MENU(self, M_FILE_EXIT,
                        self.CloseWindow)  # Attach CloseWindow to File > Exit
            self.SetMenuBar(menuBar)  # Connect the Menu Bar to the Frame

            # Add a Status Bar
            self.CreateStatusBar()

            # Prepare the wxPrintData object for use in Printing
            self.printData = wx.PrintData()
            self.printData.SetPaperId(wx.PAPER_LETTER)

            # Show the Frame
            self.Show(True)

            # Get a filename of an RTF file to use as the transcript
            dlg = wx.FileDialog(None, wildcard="*.rtf", style=wx.OPEN)
            if dlg.ShowModal() == wx.ID_OK:
                fname = dlg.GetPath()
                dlg.Destroy()
            else:
                dlg.Destroy()
                self.Close()

            # Create a dummy Transcript object
            self.transcriptObj = Transcript.Transcript()
            f = open(fname, "r")
            self.transcriptObj.text = f.read()
            f.close()

            # Initialize the pageData structure to an empty list
            self.pageData = []
Example #4
0
    def OnDisplay(self, reportText):
        """ This method, required by TextReport, populates the TextReport.  The reportText parameter is
            the wxSTC control from the TextReport object.  It needs to be in the report parent because
            the TextReport doesn't know anything about the actual data.  """
        # Determine if we need to populate the Filter Lists.  If it hasn't already been done, we should do it.
        # If it has already been done, no need to do it again.
        if self.filterList == []:
            populateFilterList = True
        else:
            populateFilterList = False
        # Make the control writable
        reportText.SetReadOnly(False)
        # Set the font for the Report Title
        reportText.SetTxtStyle(fontFace='Courier New',
                               fontSize=16,
                               fontBold=True,
                               fontUnderline=True,
                               parAlign=wx.TEXT_ALIGNMENT_CENTER,
                               parSpacingAfter=12)
        # Add the Report Title
        reportText.WriteText(self.title)
        # Turn off underlining and bold
        reportText.SetTxtStyle(fontBold=False, fontUnderline=False)
        reportText.Newline()

        if self.searchText != None:
            # ...  add a subtitle
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(_("Search Text: %s"), 'utf8')
            else:
                prompt = _("Search Text: %s")
            self.subtitle = prompt % self.searchText
            # ... set the font for the subtitle ...
            reportText.SetTxtStyle(fontSize=10)
            # ... and insert the spacer and the subtitle.
            reportText.WriteText(self.subtitle)
            reportText.Newline()

        if self.configName != '':
            # ...  add a subtitle
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(_("Filter Configuration: %s"), 'utf8')
            else:
                prompt = _("Filter Configuration: %s")
            self.configLine = prompt % self.configName
            # ... set the font for the subtitle ...
            reportText.SetTxtStyle(fontSize=10)
            # ... and insert the subtitle.
            reportText.WriteText(self.configLine)
            reportText.Newline()

        # If a Root Node flag is passed in ...
        if self.reportType == 'RootNode':
            # ... we want to group notes by category.  (They will be alphabetical within each category.)
            majorList = DBInterface.list_of_all_notes(
                reportType='LibraryNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='DocumentNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='EpisodeNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='TranscriptNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='CollectionNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='QuoteNode', searchText=self.searchText)
            majorList += DBInterface.list_of_all_notes(
                reportType='ClipNode', searchText=self.searchText)
            if TransanaConstants.proVersion:
                majorList += DBInterface.list_of_all_notes(
                    reportType='SnapshotNode', searchText=self.searchText)
        # if a specific Node flag is passed in ...
        else:
            # ... and use the Notes from the requested Report Type for the majorList.
            majorList = DBInterface.list_of_all_notes(
                reportType=self.reportType, searchText=self.searchText)

        # Initialize the initial data structure that will be turned into the report
        self.data = []
        # We need a list of all checked NoteNums to apply the Filter.  Initialize it here.
        checkedRecords = []
        # Now populate it based on the Filter List.  (The filterList will be empty if not populate yet, but that's OK.)
        # Iterate through the filter list ...
        for noteRecord in self.filterList:
            # ... pull out the filter list record elements.
            (noteNum, noteID, noteParent, checked) = noteRecord
            # If an item is checked ...
            if checked:
                # ... add it to the list of checked items!
                checkedRecords.append(noteNum)

        # Iterate through the major list
        for noteRecord in majorList:
            # If the current item from the Major List is in the list of checked records from the filter dialog
            # OR if we're going through the list for the first time (populateFilterList == True) ....
            if (noteRecord['NoteNum'] in checkedRecords) or populateFilterList:
                # ... load each note ...
                tempNote = Note.Note(noteRecord['NoteNum'])
                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True,
                                       fontSize=12,
                                       parAlign=wx.TEXT_ALIGNMENT_LEFT,
                                       parLeftIndent=0,
                                       parSpacingBefore=36,
                                       parSpacingAfter=12)
                # Add the note ID to the report
                reportText.WriteText('%s' % tempNote.id)
                reportText.Newline()

                # Initialize all temporary objects to None so we can detect their presence or absence
                tempLibrary = None
                tempDocument = None
                tempEpisode = None
                tempTranscript = None
                tempCollection = None
                tempQuote = None
                tempClip = None
                tempSnapshot = None
                # If we have a Library Note ...
                if tempNote.series_num > 0:
                    # ... load the Library data
                    tempLibrary = Library.Library(tempNote.series_num)
                    noteParent = unicode(_('Libraries'),
                                         'utf8') + ' ' + tempLibrary.id
                # If we have a Document Note ...
                elif tempNote.document_num > 0:
                    # ... load the Document and Library data
                    tempDocument = Document.Document(tempNote.document_num)
                    tempLibrary = Library.Library(tempDocument.library_num)
                    noteParent = unicode(
                        _('Document'), 'utf8'
                    ) + ' ' + tempLibrary.id + ' > ' + tempDocument.id
                # If we have an Episode Note ...
                elif tempNote.episode_num > 0:
                    # ... load the Episode and Library data
                    tempEpisode = Episode.Episode(tempNote.episode_num)
                    tempLibrary = Library.Library(tempEpisode.series_num)
                    noteParent = unicode(
                        _('Episode'),
                        'utf8') + ' ' + tempLibrary.id + ' > ' + tempEpisode.id
                # If we have a Transcript Note ...
                elif tempNote.transcript_num > 0:
                    # ... load the Transcript, Episode, and Library data
                    # To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
                    tempTranscript = Transcript.Transcript(
                        tempNote.transcript_num, skipText=True)
                    tempEpisode = Episode.Episode(tempTranscript.episode_num)
                    tempLibrary = Library.Library(tempEpisode.series_num)
                    noteParent = unicode(
                        _('Transcript'), 'utf8'
                    ) + ' ' + tempLibrary.id + ' > ' + tempEpisode.id + ' > ' + tempTranscript.id
                # If we have a Collection Note ...
                elif tempNote.collection_num > 0:
                    # ... load the Collection data
                    tempCollection = Collection.Collection(
                        tempNote.collection_num)
                    noteParent = unicode(
                        _('Collection'),
                        'utf8') + ' ' + tempCollection.GetNodeString()
                # If we have a Quote Note ...
                elif tempNote.quote_num > 0:
                    # ... load the Quote and Collection data.  We can skip loading the Quote text to save load time
                    tempQuote = Quote.Quote(tempNote.quote_num, skipText=True)
                    tempCollection = Collection.Collection(
                        tempQuote.collection_num)
                    noteParent = unicode(
                        _('Quote'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempQuote.id
                # If we have a Clip Note ...
                elif tempNote.clip_num > 0:
                    # ... load the Clip and Collection data.  We can skip loading the Clip Transcript to save load time
                    tempClip = Clip.Clip(tempNote.clip_num, skipText=True)
                    tempCollection = Collection.Collection(
                        tempClip.collection_num)
                    noteParent = unicode(
                        _('Clip'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempClip.id
                # If we have a Snapshot Note ...
                elif tempNote.snapshot_num > 0:
                    # ... load the Snapshot and Collection data.
                    tempSnapshot = Snapshot.Snapshot(tempNote.snapshot_num)
                    tempCollection = Collection.Collection(
                        tempSnapshot.collection_num)
                    noteParent = unicode(
                        _('Snapshot'),
                        'utf8') + ' ' + tempCollection.GetNodeString(
                        ) + ' > ' + tempSnapshot.id

                # If we have Library data ...
                if tempLibrary != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontSize=10,
                                           fontBold=True,
                                           parLeftIndent=63,
                                           parSpacingBefore=0,
                                           parSpacingAfter=0)
                    # Add the note ID to the report
                    reportText.WriteText(_('Library: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Library ID
                    reportText.WriteText('%s' % tempLibrary.id)
                    reportText.Newline()
                # If we have Document data ...
                if tempDocument != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Document: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Document ID
                    reportText.WriteText('%s' % tempDocument.id)
                    reportText.Newline()
                # If we have Episode data ...
                if tempEpisode != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Episode: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Episode ID
                    reportText.WriteText('%s' % tempEpisode.id)
                    reportText.Newline()
                # If we have Transcript data ...
                if tempTranscript != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Transcript: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Transcript ID
                    reportText.WriteText('%s' % tempTranscript.id)
                    reportText.Newline()
                # If we have Collection data ...
                if tempCollection != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontSize=10,
                                           fontBold=True,
                                           parLeftIndent=63,
                                           parSpacingBefore=0,
                                           parSpacingAfter=0)
                    # Add the note ID to the report
                    reportText.WriteText(_('Collection: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Collection ID
                    reportText.WriteText('%s' % tempCollection.GetNodeString())
                    reportText.Newline()
                # If we have Quote data ...
                if tempQuote != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Quote: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Quote ID
                    reportText.WriteText('%s' % tempQuote.id)
                    reportText.Newline()
                # If we have Clip data ...
                if tempClip != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Clip: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Clip ID
                    reportText.WriteText('%s' % tempClip.id)
                    reportText.Newline()
                # If we have Snapshot data ...
                if tempSnapshot != None:
                    # Turn bold on.
                    reportText.SetTxtStyle(fontBold=True)
                    # Add the note ID to the report
                    reportText.WriteText(_('Snapshot: '))
                    # Turn bold off.
                    reportText.SetTxtStyle(fontBold=False)
                    # Add the Snapshot ID
                    reportText.WriteText('%s' % tempSnapshot.id)
                    reportText.Newline()

                # If we're going through the list for the first time and need to populate the filter list ...
                if populateFilterList:
                    # ... add the note number, note ID, note parent info, and checked=True to the filter list.
                    self.filterList.append(
                        (tempNote.number, tempNote.id, noteParent, True))

                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True)
                # Add the note ID to the report
                reportText.WriteText(_('Note Taker: '))
                # Turn bold off.
                reportText.SetTxtStyle(fontBold=False)
                # Add the Note's author
                reportText.WriteText('%s' % tempNote.author)
                reportText.Newline()
                # Turn bold on.
                reportText.SetTxtStyle(fontBold=True)
                # Add the note ID to the report
                reportText.WriteText(_('Note Text:'))
                reportText.Newline()
                # Turn bold off.
                reportText.SetTxtStyle(fontBold=False, parLeftIndent=127)
                # Add the note text to the report (rstrip() prevents formatting problems when notes end with blank lines)
                reportText.WriteText('%s' % tempNote.text.rstrip())
                reportText.Newline()

        # Make the control read only, now that it's done
        reportText.SetReadOnly(True)
Example #5
0
    def db_delete(self, use_transactions=1):
        """Delete this object record from the database."""
        result = 1
        try:
            # Initialize delete operation, begin transaction if necessary
            (db, c) = self._db_start_delete(use_transactions)

            # Delete all Episode-based Filter Configurations
            #   Delete Episode Keyword Map records
            DBInterface.delete_filter_records(1, self.number)
            #   Delete Episode Keyword Visualization records
            DBInterface.delete_filter_records(2, self.number)
            #   Delete Episode Clip Data Export records
            DBInterface.delete_filter_records(3, self.number)
            #   Delete Episode Clip Data Coder Reliability Export records (Kathleen Liston's code)
            DBInterface.delete_filter_records(8, self.number)
            #   Delete Episode Report records
            DBInterface.delete_filter_records(11, self.number)

            # Detect, Load, and Delete all Clip Notes.
            notes = self.get_note_nums()
            for note_num in notes:
                note = Note.Note(note_num)
                result = result and note.db_delete(0)
                del note
            del notes

            for (transcriptNo, transcriptID,
                 transcriptEpisodeNo) in DBInterface.list_transcripts(
                     self.series_id, self.id):
                # To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
                trans = Transcript.Transcript(transcriptNo, skipText=True)
                # if transcript delete fails, rollback clip delete
                result = result and trans.db_delete(0)
                del trans

            # Delete all related references in the ClipKeywords table
            if result:
                DBInterface.delete_all_keywords_for_a_group(
                    self.number, 0, 0, 0, 0)

            if result:
                # Craft a query to remove all existing Additonal Videos
                query = "DELETE FROM AdditionalVids2 WHERE EpisodeNum = %s"
                # Adjust the query for sqlite if needed
                query = DBInterface.FixQuery(query)
                # Execute the query
                c.execute(query, (self.number, ))

            # We need a user confirmation when Snapshot will be orphaned.

            # Snapshots with this Episode number need to be cleared.
            # This must be done LAST, after everything else.
            if result:
                DBInterface.ClearSourceEpisodeRecords(self.number)

            # Delete the actual record.
            self._db_do_delete(use_transactions, c, result)

            # Cleanup
            c.close()
            self.clear()
        except RecordLockedError, e:
            # if a sub-record is locked, we may need to unlock the Episode record (after rolling back the Transaction)
            if self.isLocked:
                # c (the database cursor) only exists if the record lock was obtained!
                # We must roll back the transaction before we unlock the record.
                c.execute("ROLLBACK")
                c.close()
                self.unlock_record()
            raise e
Example #6
0
    def createTranscripts(self):

        for key, splinelist in self.gff3_ID_Dict.items():

            for spline in splinelist:
                if spline[2] != "gene":
                    continue

                gene_seqid = spline[0]
                gene_gff3_ID = key[1]  # because of (seqid,gff3_id)
                gene_info_string = spline[8]

                if gene_seqid not in self.dict_Chr_dict_Transcript:
                    self.dict_Chr_dict_Transcript[gene_seqid] = {}

                for spline_child in self.dict_gff_for_parents[gene_seqid,
                                                              gene_gff3_ID]:
                    chr = spline_child[0]
                    gfftype = spline_child[2]
                    if 'mRNA' not in gfftype:
                        continue

                    start = int(spline_child[3])
                    end = int(spline_child[4])
                    if spline_child[6] == '+':
                        strand = Transcript.TranscriptEnum.FORWARD
                    elif spline_child[6] == '-':
                        strand = Transcript.TranscriptEnum.REVERSE
                    else:
                        strand = Transcript.TranscriptEnum.UNKNOWN_STRAND_DIRECTION
                    phase = spline_child[7]

                    atts = spline_child[8].split(';')
                    TID = ""
                    for att in atts:
                        if 'ID=' in att:
                            TID = att[3:]
                            break
                    if TID == "":
                        print("No ID:\n" + spline_child)
                        sys.exit()

                    # IndexKey: int, TID: str, StartOfRNA: int, EndOfRNA: int, ForwardDirection: TranscriptEnum.REVERSE):
                    transcript = Transcript.Transcript(
                        self.GetNextTranscriptIndex(), TID, start, end, strand,
                        chr)
                    cdslist = []
                    for rna_child_spline in self.dict_gff_for_parents[
                            gene_seqid, TID]:
                        if "CDS" in rna_child_spline[2]:
                            cdslist.append((int(rna_child_spline[3]),
                                            int(rna_child_spline[4]),
                                            rna_child_spline[7]))
                        elif "exon" in rna_child_spline[2]:
                            transcript.AddEXON_Descriptin(
                                "\t".join(rna_child_spline))
                        elif "utr" in rna_child_spline[2]:
                            transcript.AddUTR_Description(
                                "\t".join(rna_child_spline))

                    cdslist = sorted(cdslist)
                    for cds in cdslist:
                        transcript.addCDS(cds[0], cds[1], cds[2])
                    transcript.SetGene_Info_String(gene_info_string)
                    self.dict_Chr_dict_Transcript[gene_seqid][
                        transcript.IndexKey] = transcript
                    self.List_Of_Transcripts[gene_seqid].append(transcript)
Example #7
0
    def OnConvert(self):
        """ Perform the Plain Text Extraction operation """
        # Get the database connection (required for Transactions)
        db = DBInterface.get_db()
        # Get a Database Cursor
        dbCursor = db.cursor()

        # Initialize a Record Counter
        counter = 0

        # Get a list of the Documents that need Plain Text extraction
        documents = DBInterface.list_of_documents(withoutPlainText=True)
        # Update User Info
        self.txtCtrl.AppendText("%5d Document Records\n" % len(documents))
        # Iterate through the list
        for document in documents:
            # Update User Info
            self.txtCtrl.AppendText("%5d  Document:  %s\n" %
                                    (self.numRecords - counter, document[1]))
            # Load the Document Object
            tmpDocument = Document.Document(num=document[0])

            # I'm not sure why I have to use a Transaction here.  But records are remaining locked
            # without this.  This at least makes things work!
            dbCursor.execute("BEGIN")
            # Lock the record
            tmpDocument.lock_record()
            # Load the record into the hidden RichTextCtrl.  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.load_transcript(tmpDocument, showPopup=False)
            # Save the record.  This causes the PlainText to be added!  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.save_transcript(use_transactions=False,
                                              showPopup=False)
            # Unlock the record
            tmpDocument.unlock_record()
            # Commit the Transaction
            dbCursor.execute("COMMIT")

            # Update the Record Counter
            counter += 1
            # Update the Progress Bar
            self.gauge.SetValue(counter)
            # This form can freeze up and appear non-responsive.  Every 20 items, we should avoid that
            if counter % 20 == 0:
                wx.YieldIfNeeded()

        # Get a list of the Episode Transcripts that need Plain Text extraction
        episodeTranscripts = DBInterface.list_of_episode_transcripts(
            withoutPlainText=True)
        # Update User Info
        self.txtCtrl.AppendText("%5d Episode Transcript Records\n" %
                                len(episodeTranscripts))
        # Iterate through the list
        for episodeTranscript in episodeTranscripts:
            # Update User Info
            self.txtCtrl.AppendText(
                "%5d  Episode Transcript:  %s\n" %
                (self.numRecords - counter, episodeTranscript[1]))
            # Load the Transcript Object
            tmpEpisodeTranscript = Transcript.Transcript(
                id_or_num=episodeTranscript[0])

            # I'm not sure why I have to use a Transaction here.  But the transaction from the Transcript
            # object doesn't seem to be cutting it.  This at least makes things work!
            dbCursor.execute("BEGIN")
            # Lock the record
            tmpEpisodeTranscript.lock_record()
            # Load the record into the hidden RichTextCtrl.  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.load_transcript(tmpEpisodeTranscript,
                                              showPopup=False)
            # Save the record.  This causes the PlainText to be added!  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.save_transcript(use_transactions=False,
                                              showPopup=False)
            # Unlock the record
            tmpEpisodeTranscript.unlock_record()
            # Commit the Transaction
            dbCursor.execute("COMMIT")

            # Update the Record Counter
            counter += 1
            # Update the Progress Bar
            self.gauge.SetValue(counter)
            # This form can freeze up and appear non-responsive.  We should avoid that with every Episode Transcript (they are big).
            wx.YieldIfNeeded()

        # Get a list of the Quotes that need Plain Text extraction
        quotes = DBInterface.list_of_quotes(withoutPlainText=True)
        # Update User Info
        self.txtCtrl.AppendText("%5d Quote Records\n" % len(quotes))
        # Iterate through the list
        for quote in quotes:
            # Update User Info
            self.txtCtrl.AppendText("%5d  Quote:  %s\n" %
                                    (self.numRecords - counter, quote[1]))
            # Load the Quote Object
            tmpQuote = Quote.Quote(num=quote[0])

            # I'm not sure why I have to use a Transaction here.  But the transaction from the Transcript
            # object doesn't seem to be cutting it.  This at least makes things work!
            dbCursor.execute("BEGIN")
            # Lock the record
            tmpQuote.lock_record()
            # Load the record into the hidden RichTextCtrl.  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.load_transcript(tmpQuote, showPopup=False)
            # Save the record.  This causes the PlainText to be added!  Don't show the popup, as too many of these crashes the program!
            self.richTextCtrl.save_transcript(use_transactions=False,
                                              showPopup=False)
            # Unlock the record
            tmpQuote.unlock_record()
            # Commit the Transaction
            dbCursor.execute("COMMIT")

            # Update the Record Counter
            counter += 1
            # Update the Progress Bar
            self.gauge.SetValue(counter)
            # This form can freeze up and appear non-responsive.  Every 20 items, we should avoid that
            if counter % 20 == 0:
                wx.YieldIfNeeded()

        # Get a list of the Clips that need Plain Text extraction
        clips = DBInterface.list_of_clips(withoutPlainText=True)
        # Update User Info
        self.txtCtrl.AppendText("%5d Clip Records\n" % len(clips))
        # Iterate through the list
        for clip in clips:
            # Update User Info
            self.txtCtrl.AppendText(
                "%5d  Clip:  %d  %s\n" %
                (self.numRecords - counter, clip[0], clip[1]))
            # Load the Clip Object
            tmpClip = Clip.Clip(id_or_num=clip[0])
            # For each Transcript in the Clip ...
            for tmpClipTranscript in tmpClip.transcripts:

                # I'm not sure why I have to use a Transaction here.  But the transaction from the Transcript
                # object doesn't seem to be cutting it.  This at least makes things work!
                dbCursor.execute("BEGIN")
                # Lock the record
                tmpClipTranscript.lock_record()
                # Load the record into the hidden RichTextCtrl.  Don't show the popup, as too many of these crashes the program!
                self.richTextCtrl.load_transcript(tmpClipTranscript,
                                                  showPopup=False)
                # Save the record.  This causes the PlainText to be added!  Don't show the popup, as too many of these crashes the program!
                self.richTextCtrl.save_transcript(use_transactions=False,
                                                  showPopup=False)

                ## This alternate method also works, and is slightly faster, but is less object friendly.
                ## The speed difference is about 10 - 15 seconds in a 3 minute processing of 1400 clips.

                ## import re

                ##                    plaintext = self.richTextCtrl.GetValue()
                ##                    # Strip Time Codes
                ##                    regex = "%s<[\d]*>" % TransanaConstants.TIMECODE_CHAR
                ##                    reg = re.compile(regex)
                ##                    pos = 0
                ##                    for x in reg.findall(plaintext):
                ##                        pos = plaintext.find(x, pos, len(plaintext))
                ##                        plaintext = plaintext[ : pos] + plaintext[pos + len(x) : ]
                ##                    query = "UPDATE Transcripts2 SET PlainText = %s WHERE TranscriptNum = %s"
                ##                    values = (plaintext.encode('utf8'), tmpClipTranscript.number)
                ##                    query = DBInterface.FixQuery(query)
                ##                    result = dbCursor.execute(query, values)

                # Unlock the record
                tmpClipTranscript.unlock_record()
                # Commit the Transaction
                dbCursor.execute("COMMIT")

            # Update the Record Counter
            counter += 1
            # Update the Progress Bar
            self.gauge.SetValue(counter)
            # This form can freeze up and appear non-responsive.  Every 20 items, we should avoid that
            if counter % 20 == 0:
                wx.YieldIfNeeded()

        dbCursor.close()