def _load_row(self, r): self.number = r['CollectNum'] self.id = r['CollectID'] self.parent = r['ParentCollectNum'] self.comment = r['CollectComment'] self.owner = r['CollectOwner'] if r.has_key('DefaultKeywordGroup'): self.keyword_group = r['DefaultKeywordGroup'] # If we're in Unicode mode, we need to encode the data from the database appropriately. # (unicode(var, TransanaGlobal.encoding) doesn't work, as the strings are already unicode, yet aren't decoded.) if 'unicode' in wx.PlatformInfo: self.id = DBInterface.ProcessDBDataForUTF8Encoding(self.id) self.comment = DBInterface.ProcessDBDataForUTF8Encoding( self.comment) self.owner = DBInterface.ProcessDBDataForUTF8Encoding(self.owner) self.keyword_group = DBInterface.ProcessDBDataForUTF8Encoding( self.keyword_group)
def load_additional_vids(self): """Load additional media file names from the database.""" # Get a database connection db = DBInterface.get_db() # Create a database cursor c = db.cursor() # Define the DB Query query = "SELECT MediaFile, VidLength, Offset, Audio FROM AdditionalVids2 WHERE EpisodeNum = %s ORDER BY AddVidNum" # Adjust the query for sqlite if needed query = DBInterface.FixQuery(query) # Execute the query c.execute(query, (self.number, )) # For each video in the query results ... for (vidFilename, vidLength, vidOffset, audio) in c.fetchall(): # Detection of the use of the Video Root Path is platform-dependent and must be done for EACH filename! if wx.Platform == "__WXMSW__": # On Windows, check for a colon in the position, which signals the presence or absence of a drive letter useVideoRoot = (vidFilename[1] != ':') and (vidFilename[:2] != '//') else: # On Mac OS-X and *nix, check for a slash in the first position for the root folder designation useVideoRoot = (vidFilename[0] != '/') # If we are using the Video Root Path, add it to the Filename if useVideoRoot: video = TransanaGlobal.configData.videoPath.replace( '\\', '/') + DBInterface.ProcessDBDataForUTF8Encoding( vidFilename) else: video = DBInterface.ProcessDBDataForUTF8Encoding(vidFilename) # Add the video to the additional media files list self.additional_media_files = { 'filename': video, 'length': vidLength, 'offset': vidOffset, 'audio': audio } # If the video offset is less than 0 and is smaller than the current smallest (most negative) offset ... if (vidOffset < 0) and (vidOffset < -self.offset): # ... then use this video offset as the global offset self.offset = abs(vidOffset) # Close the database cursor c.close()
def _load_row(self, r): self.keywordGroup = r['KeywordGroup'] self.keyword = r['Keyword'] self.definition = r['Definition'] if self.definition == None: self.definition = '' self.lineColorName = r['LineColorName'] self.lineColorDef = r['LineColorDef'] self.drawMode = r['DrawMode'] self.lineWidth = r['LineWidth'] self.lineStyle = r['LineStyle'] # If we're in Unicode mode, we need to encode the data from the database appropriately. # (unicode(var, TransanaGlobal.encoding) doesn't work, as the strings are already unicode, yet aren't decoded.) if 'unicode' in wx.PlatformInfo: self.keywordGroup = DBInterface.ProcessDBDataForUTF8Encoding( self.keywordGroup) self.keyword = DBInterface.ProcessDBDataForUTF8Encoding( self.keyword) self.definition = DBInterface.ProcessDBDataForUTF8Encoding( self.definition) self.lineColorName = DBInterface.ProcessDBDataForUTF8Encoding( self.lineColorName)
def _load_row(self, r): self.number = r['EpisodeNum'] self.id = r['EpisodeID'] self.comment = r['EpComment'] self.media_filename = r['MediaFile'] self.tape_length = r['EpLength'] self.tape_date = r['TapingDate'] # These come from the Library record self.series_id = r['SeriesID'] self.series_num = r['SeriesNum'] # If we're in Unicode mode, we need to encode the data from the database appropriately. # (unicode(var, TransanaGlobal.encoding) doesn't work, as the strings are already unicode, yet aren't decoded.) if 'unicode' in wx.PlatformInfo: self.id = DBInterface.ProcessDBDataForUTF8Encoding(self.id) self.comment = DBInterface.ProcessDBDataForUTF8Encoding( self.comment) self.media_filename = DBInterface.ProcessDBDataForUTF8Encoding( self.media_filename) self.series_id = DBInterface.ProcessDBDataForUTF8Encoding( self.series_id) # Remember whether the MediaFile uses the VideoRoot Folder or not. # Detection of the use of the Video Root Path is platform-dependent. if wx.Platform == "__WXMSW__": # On Windows, check for a colon in the position, which signals the presence or absence of a drive letter self.useVideoRoot = (self.media_filename[1] != ':') and (self.media_filename[:2] != '\\\\') else: # On Mac OS-X and *nix, check for a slash in the first position for the root folder designation self.useVideoRoot = (self.media_filename[0] != '/') # If we are using the Video Root Path, add it to the Filename if self.useVideoRoot: self.media_filename = TransanaGlobal.configData.videoPath.replace( '\\', '/') + self.media_filename
def __init__(self, dbTree, searchCount, kwg=None, kw=None, searchName=None, searchTerms=None): """ Initialize the ProcessSearch class. The dbTree parameter accepts a wxTreeCtrl as the Database Tree where Search Results should be displayed. The searchCount parameter accepts the number that should be included in the Default Search Title. Optional kwg (Keyword Group) and kw (Keyword) parameters implement Quick Search for the keyword specified. """ # Note the Database Tree that accepts Search Results self.dbTree = dbTree self.collectionList = [] # If kwg and kw are None, we are doing a regular (full) search. if ((kwg == None) or (kw == None)) and (searchTerms == None): # Create the Search Dialog Box dlg = SearchDialog.SearchDialog(_("Search") + " %s" % searchCount) # Display the Search Dialog Box and record the Result result = dlg.ShowModal() # If the user selects OK ... if result == wx.ID_OK: # ... get the search name from the dialog searchName = dlg.searchName.GetValue().strip() # Search Name is required. If it was eliminated, put it back! if searchName == '': searchName = _("Search") + " %s" % searchCount # Get the Collections Tree from the Search Form collTree = dlg.ctcCollections # Get the Collections Tree's Root Node collNode = collTree.GetRootItem() # Get a list of all the Checked Collections in the Collections Tree self.collectionList = dlg.GetCollectionList( collTree, collNode, True) # ... and get the search terms from the dialog searchTerms = dlg.searchQuery.GetValue().split('\n') # Get the includeDocuments info includeDocuments = dlg.includeDocuments.IsChecked() # Get the includeEpisodes info includeEpisodes = dlg.includeEpisodes.IsChecked() # Get the includeQuotes info includeQuotes = dlg.includeQuotes.IsChecked() # Get the includeClips info includeClips = dlg.includeClips.IsChecked() # Get the includeSnapshots info includeSnapshots = dlg.includeSnapshots.IsChecked() # Destroy the Search Dialog Box dlg.Destroy() elif (searchTerms != None): # There's no dialog. Just say the user said OK. result = wx.ID_OK # Include Clips. Do not include Documents or Episodes includeDocuments = False includeEpisodes = False includeClips = True # If Pro, Lab, or MU, include Quotes and Snapshots. if TransanaConstants.proVersion: includeQuotes = True includeSnapshots = True else: includeQuotes = False includeSnapshots = False # if kwg and kw are passed in, we're doing a Quick Search else: # There's no dialog. Just say the user said OK. result = wx.ID_OK # The Search Name is built from the kwg : kw combination searchName = "%s : %s" % (kwg, kw) # The Search Terms are just the keyword group and keyword passed in searchTerms = ["%s:%s" % (kwg, kw)] # Include Clips. Do not include Documents or Episodes includeDocuments = False includeEpisodes = False includeClips = True # If Pro, Lab, or MU, include Quotes and Snapshots. if TransanaConstants.proVersion: includeQuotes = True includeSnapshots = True else: includeQuotes = False includeSnapshots = False # If OK is pressed (or Quick Search), process the requested Search if result == wx.ID_OK: # Increment the Search Counter self.searchCount = searchCount + 1 # The "Search" node itself is always item 0 in the node list searchNode = self.dbTree.select_Node((_("Search"), ), 'SearchRootNode') # We need to collect a list of the named searches already done. namedSearches = [] # Get the first child node from the Search root node (childNode, cookieVal) = self.dbTree.GetFirstChild(searchNode) # As long as there are child nodes ... while childNode.IsOk(): # Add the node name to the named searches list ... namedSearches.append(self.dbTree.GetItemText(childNode)) # ... and get the next child node (childNode, cookieVal) = self.dbTree.GetNextChild(childNode, cookieVal) # We need to give each search result a unique name. So note the search count number nameIncrementValue = searchCount # As long as there's already a named search with the name we want to use ... while (searchName in namedSearches): # ... if this is our FIRST attempt ... if nameIncrementValue == searchCount: # ... append the appropriate number on the end of the search name searchName += unicode(_(' - Search %d'), 'utf8') % nameIncrementValue # ... if this is NOT our first attempt ... else: # ... remove the previous number and add the appropriate next number to try searchName = searchName[:searchName.rfind( ' ')] + ' %d' % nameIncrementValue # Increment our counter by one. We'll keep trying new numbers until we find one that works. nameIncrementValue += 1 # As long as there's a search name (and there's no longer a way to eliminate it! if searchName != '': # Add a Search Results Node to the Database Tree nodeListBase = [_("Search"), searchName] self.dbTree.add_Node('SearchResultsNode', nodeListBase, 0, 0, expandNode=True) # Build the appropriate Queries based on the Search Query specified in the Search Dialog. # (This method parses the Natural Language Search Terms into queries for Episode Search # Terms, for Clip Search Terms, and for Snapshot Search Terms, and includes the appropriate # Parameters to be used with the queries. Parameters are not integrated into the queries # in order to allow for automatic processing of apostrophes and other text that could # otherwise interfere with the SQL execution.) (documentQuery, episodeQuery, quoteQuery, clipQuery, wholeSnapshotQuery, snapshotCodingQuery, params) = \ self.BuildQueries(searchTerms) # Get a Database Cursor dbCursor = DBInterface.get_db().cursor() if includeEpisodes: # Adjust query for sqlite, if needed episodeQuery = DBInterface.FixQuery(episodeQuery) # Execute the Library/Episode query dbCursor.execute(episodeQuery, tuple(params)) # Process the results of the Library/Episode query for line in DBInterface.fetchall_named(dbCursor): # Add the new Transcript(s) to the Database Tree Tab. # To add a Transcript, we need to build the node list for the tree's add_Node method to climb. # We need to add the Library, Episode, and Transcripts to our Node List, so we'll start by loading # the current Library and Episode tempLibrary = Library.Library(line['SeriesNum']) tempEpisode = Episode.Episode(line['EpisodeNum']) # Add the Search Root Node, the Search Name, and the current Library and Episode Names. nodeList = (_('Search'), searchName, tempLibrary.id, tempEpisode.id) # Find out what Transcripts exist for each Episode transcriptList = DBInterface.list_transcripts( tempLibrary.id, tempEpisode.id) # If the Episode HAS defined transcripts ... if len(transcriptList) > 0: # Add each Transcript to the Database Tree for (transcriptNum, transcriptID, episodeNum) in transcriptList: # Add the Transcript Node to the Tree. self.dbTree.add_Node( 'SearchTranscriptNode', nodeList + (transcriptID, ), transcriptNum, episodeNum) # If the Episode has no transcripts, it still has the keywords and SHOULD be displayed! else: # Add the Transcript-less Episode Node to the Tree. self.dbTree.add_Node('SearchEpisodeNode', nodeList, tempEpisode.number, tempLibrary.number) if includeDocuments: # Adjust query for sqlite, if needed documentQuery = DBInterface.FixQuery(documentQuery) # Execute the Library/Document query dbCursor.execute(documentQuery, tuple(params)) # Process the results of the Library/Document query for line in DBInterface.fetchall_named(dbCursor): # Add the new Document(s) to the Database Tree Tab. # To add a Document, we need to build the node list for the tree's add_Node method to climb. # We need to add the Library and Documents to our Node List, so we'll start by loading # the current Library tempLibraryName = DBInterface.ProcessDBDataForUTF8Encoding( line['SeriesID']) tempDocument = Document.Document(line['DocumentNum']) # Add the Search Root Node, the Search Name, and the current Library Name. nodeList = (_('Search'), searchName, tempLibraryName) # Add the Document Node to the Tree. self.dbTree.add_Node('SearchDocumentNode', nodeList + (tempDocument.id, ), tempDocument.number, tempDocument.library_num) if includeQuotes: # Adjust query for sqlite, if needed quoteQuery = DBInterface.FixQuery(quoteQuery) # Execute the Collection/Quote query dbCursor.execute(quoteQuery, params) # Process all results of the Collection/Quote query for line in DBInterface.fetchall_named(dbCursor): # Add the new Quote to the Database Tree Tab. # To add a Quote, we need to build the node list for the tree's add_Node method to climb. # We need to add all of the Collection Parents to our Node List, so we'll start by loading # the current Collection tempCollection = Collection.Collection( line['CollectNum']) # Add the current Collection Node Data nodeList = tempCollection.GetNodeData() # Get the DB Values tempID = line['QuoteID'] # If we're in Unicode mode, format the strings appropriately if 'unicode' in wx.PlatformInfo: tempID = DBInterface.ProcessDBDataForUTF8Encoding( tempID) # Now add the Search Root Node and the Search Name to the front of the Node List and the # Quote Name to the back of the Node List nodeList = (_('Search'), searchName) + nodeList + (tempID, ) # Add the Node to the Tree self.dbTree.add_Node('SearchQuoteNode', nodeList, line['QuoteNum'], line['CollectNum'], sortOrder=line['SortOrder']) if includeClips: # Adjust query for sqlite, if needed clipQuery = DBInterface.FixQuery(clipQuery) # Execute the Collection/Clip query dbCursor.execute(clipQuery, params) # Process all results of the Collection/Clip query for line in DBInterface.fetchall_named(dbCursor): # Add the new Clip to the Database Tree Tab. # To add a Clip, we need to build the node list for the tree's add_Node method to climb. # We need to add all of the Collection Parents to our Node List, so we'll start by loading # the current Collection tempCollection = Collection.Collection( line['CollectNum']) # Add the current Collection Node Data nodeList = tempCollection.GetNodeData() # Get the DB Values tempID = line['ClipID'] # If we're in Unicode mode, format the strings appropriately if 'unicode' in wx.PlatformInfo: tempID = DBInterface.ProcessDBDataForUTF8Encoding( tempID) # Now add the Search Root Node and the Search Name to the front of the Node List and the # Clip Name to the back of the Node List nodeList = (_('Search'), searchName) + nodeList + (tempID, ) # Add the Node to the Tree self.dbTree.add_Node('SearchClipNode', nodeList, line['ClipNum'], line['CollectNum'], sortOrder=line['SortOrder']) if includeSnapshots: # Adjust query for sqlite, if needed wholeSnapshotQuery = DBInterface.FixQuery( wholeSnapshotQuery) # Execute the Whole Snapshot query dbCursor.execute(wholeSnapshotQuery, params) # Since we have two sources of Snapshots that get included, we need to track what we've already # added so we don't add the same Snapshot twice addedSnapshots = [] # Process all results of the Whole Snapshot query for line in DBInterface.fetchall_named(dbCursor): # Add the new Snapshot to the Database Tree Tab. # To add a Snapshot, we need to build the node list for the tree's add_Node method to climb. # We need to add all of the Collection Parents to our Node List, so we'll start by loading # the current Collection tempCollection = Collection.Collection( line['CollectNum']) # Add the current Collection Node Data nodeList = tempCollection.GetNodeData() # Get the DB Values tempID = line['SnapshotID'] # If we're in Unicode mode, format the strings appropriately if 'unicode' in wx.PlatformInfo: tempID = DBInterface.ProcessDBDataForUTF8Encoding( tempID) # Now add the Search Root Node and the Search Name to the front of the Node List and the # Clip Name to the back of the Node List nodeList = (_('Search'), searchName) + nodeList + (tempID, ) # Add the Node to the Tree self.dbTree.add_Node('SearchSnapshotNode', nodeList, line['SnapshotNum'], line['CollectNum'], sortOrder=line['SortOrder']) # Add the Snapshot to the list of Snapshots added to the Search Result addedSnapshots.append(line['SnapshotNum']) tmpNode = self.dbTree.select_Node( nodeList[:-1], 'SearchCollectionNode', ensureVisible=False) self.dbTree.SortChildren(tmpNode) # Adjust query for sqlite if needed snapshotCodingQuery = DBInterface.FixQuery( snapshotCodingQuery) # Execute the Snapshot Coding query dbCursor.execute(snapshotCodingQuery, params) # Process all results of the Snapshot Coding query for line in DBInterface.fetchall_named(dbCursor): # If the Snapshot is NOT already in the Search Results ... if not (line['SnapshotNum'] in addedSnapshots): # Add the new Snapshot to the Database Tree Tab. # To add a Snapshot, we need to build the node list for the tree's add_Node method to climb. # We need to add all of the Collection Parents to our Node List, so we'll start by loading # the current Collection tempCollection = Collection.Collection( line['CollectNum']) # Add the current Collection Node Data nodeList = tempCollection.GetNodeData() # Get the DB Values tempID = line['SnapshotID'] # If we're in Unicode mode, format the strings appropriately if 'unicode' in wx.PlatformInfo: tempID = DBInterface.ProcessDBDataForUTF8Encoding( tempID) # Now add the Search Root Node and the Search Name to the front of the Node List and the # Clip Name to the back of the Node List nodeList = (_('Search'), searchName) + nodeList + (tempID, ) # Add the Node to the Tree self.dbTree.add_Node('SearchSnapshotNode', nodeList, line['SnapshotNum'], line['CollectNum'], sortOrder=line['SortOrder']) # Add the Snapshot to the list of Snapshots added to the Search Result addedSnapshots.append(line['SnapshotNum']) tmpNode = self.dbTree.select_Node( nodeList[:-1], 'SearchCollectionNode', ensureVisible=False) self.dbTree.SortChildren(tmpNode) else: self.searchCount = searchCount # If the Search Dialog is cancelled, do NOT increment the Search Number else: self.searchCount = searchCount
def _load_row(self, row): """ Load the row of data returned from the database into the Core Data Object's properties """ self.number = row['CoreDataNum'] self.id = row['Identifier'] self.title = row['Title'] self.creator = row['Creator'] self.subject = row['Subject'] self.description = row['Description'] self.publisher = row['Publisher'] self.contributor = row['Contributor'] self.dc_date = row['DCDate'] self.dc_type = row['DCType'] self.format = row['Format'] self.source = row['Source'] self.language = row['Language'] self.relation = row['Relation'] self.coverage = row['Coverage'] self.rights = row['Rights'] # If we're in Unicode mode, we need to encode the data from the database appropriately. # (unicode(var, TransanaGlobal.encoding) doesn't work, as the strings are already unicode, yet aren't decoded.) if 'unicode' in wx.PlatformInfo: self.id = DBInterface.ProcessDBDataForUTF8Encoding(self.id) self.title = DBInterface.ProcessDBDataForUTF8Encoding(self.title) self.creator = DBInterface.ProcessDBDataForUTF8Encoding( self.creator) self.subject = DBInterface.ProcessDBDataForUTF8Encoding( self.subject) self.description = DBInterface.ProcessDBDataForUTF8Encoding( self.description) self.publisher = DBInterface.ProcessDBDataForUTF8Encoding( self.publisher) self.contributor = DBInterface.ProcessDBDataForUTF8Encoding( self.contributor) self.dc_type = DBInterface.ProcessDBDataForUTF8Encoding( self.dc_type) self.format = DBInterface.ProcessDBDataForUTF8Encoding(self.format) self.source = DBInterface.ProcessDBDataForUTF8Encoding(self.source) self.language = DBInterface.ProcessDBDataForUTF8Encoding( self.language) self.relation = DBInterface.ProcessDBDataForUTF8Encoding( self.relation) self.coverage = DBInterface.ProcessDBDataForUTF8Encoding( self.coverage) self.rights = DBInterface.ProcessDBDataForUTF8Encoding(self.rights)
def _load_row(self, row): self.number = row['QuoteNum'] self.id = row['QuoteID'] self.collection_num = row['CollectNum'] self.collection_id = row['CollectID'] self.source_document_num = row['SourceDocumentNum'] self.start_char = row['StartChar'] self.end_char = row['EndChar'] self.sort_order = row['SortOrder'] self.comment = row['Comment'] # If we're NOT skipping the XML Text ... if not self.skipText: # Can I get away with assuming Unicode? # Here's the plan: # test for rtf in here, if you find rtf, process normally # if you don't find it, pass data off to some weirdo method in TranscriptEditor.py # 1 - Determine encoding, adjust if needed # 2 - enact the plan above # determine encoding, fix if needed if type(row['XMLText']).__name__ == 'array': if DEBUG: print "Document._load_row(): 2", row['XMLText'].typecode if row['XMLText'].typecode == 'u': self.text = row['XMLText'].tounicode() else: self.text = row['XMLText'].tostring() else: self.text = row['XMLText'] if 'unicode' in wx.PlatformInfo: if type(self.text).__name__ == 'str': temp = self.text[2:5] # check to see if we're working with RTF try: if temp.encode('utf8') == u'rtf': # convert the data to unicode just to be safe. self.text = unicode(self.text, 'utf-8') except UnicodeDecodeError: # This would sometimes get called while I was using cPickle instead of Pickle. # You could probably remove the exception handling stuff and be okay, but it's # not hurting anything like it is. # self.dlg.editor.load_transcript(transcriptObj, 'pickle') # NOPE. There is no self.dlg.editor here! pass # self.text gets set to be our data # then load_transcript is called, from transcriptionui.LoadTranscript() self.plaintext = row['PlainText'] # If we ARE skipping the text ... else: # set the text to None self.text = None self.plaintext = None self.lastsavetime = row['LastSaveTime'] self.changed = False # If we're in Unicode mode, we need to encode the data from the database appropriately. # (unicode(var, TransanaGlobal.encoding) doesn't work, as the strings are already unicode, yet aren't decoded.) if 'unicode' in wx.PlatformInfo: self.id = DBInterface.ProcessDBDataForUTF8Encoding(self.id) self.collection_id = DBInterface.ProcessDBDataForUTF8Encoding( self.collection_id) self.comment = DBInterface.ProcessDBDataForUTF8Encoding( self.comment) if self.plaintext != None: self.plaintext = self.plaintext.decode(TransanaGlobal.encoding)