def search(self): if not self.modifiedSave(): return dom = self.domain dialog = SearchDialog(self.model, domain=self.domain, context=self.context, parent=self) if dialog.exec_() == QDialog.Rejected: return self.screen.clear() self.screen.load( dialog.result )
def addFiltersFromIDLE(self): """ Adds syntax colors, undo, replace, find, goto, indent, commment functionality from IDLE to the text widget """ textWidget = self.textWidget p = Percolator(textWidget) p.insertfilter(ColorDelegator()) # Python syntax coloring undo = UndoDelegator() p.insertfilter(undo) # Undo/Redo feature # This is used to undo stuff done with replace, indent, comment, etc. textWidget.undo_block_start = undo.undo_block_start textWidget.undo_block_stop = undo.undo_block_stop #----------------- Bind virtual events to the text widget ------------------ textWidget.bind( "<<replace>>", lambda e=None, self=self: ReplaceDialog.replace(self.textWidget)) textWidget.bind( "<<find>>", lambda e=None, self=self: SearchDialog.find(self.textWidget)) textWidget.bind("<<goto-line>>", lambda e=None, self=self: goto_line_event(self)) textWidget.bind("<<add-indent>>", lambda e=None, self=self: indent_region_event(self)) textWidget.bind("<<del-indent>>", lambda e=None, self=self: dedent_region_event(self)) textWidget.bind("<<add-comment>>", lambda e=None, self=self: comment_region_event(self)) textWidget.bind("<<del-comment>>", lambda e=None, self=self: uncomment_region_event(self)) textWidget.bind("<<select-all>>", lambda e=None, self=self: select_all(self)) textWidget.bind("<<deselect-all>>", lambda e=None, self=self: deselect_all(self)) textWidget.bind("<<paste>>", lambda e=None, self=self: paste(self)) textWidget.bind("<<copy>>", lambda e=None, self=self: copy(self)) textWidget.bind("<<cut>>", lambda e=None, self=self: cut(self)) textWidget.bind("<<popup-menu>>", lambda e=None, self=self: popupMenu(self, e)) textWidget.bind("<<open>>", lambda e=None, self=self: Open(self)) textWidget.bind("<<save>>", lambda e=None, self=self: SaveAs(self)) #---------------- Give virtual events a concrete keybinding ---------------- for key, value in KEY_DICT.iteritems(): textWidget.event_add(key, *value)
def OnSearch(self, widget, event=None): """ Called when the user clicks on the search button. Parameters: widget -- reserved for GTK callbacks. Don't use it explicitly. event -- reserved for GTK callbacks. Don't use it explicitly. """ if self.search: self.search.dlg.present() else: self.search = SearchDialog.SearchDialog( self.window, self.console.get_buffer().insert_at_cursor) return True
def find_selection_event(self, event): import SearchDialog SearchDialog.find_selection(self.editwin.text) return "break"
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 search(self): dlg = SearchDialog.SearchDialog() dlg.exec_()
def search(self): dlg = SearchDialog.SearchUniversity() dlg.exec_()
def _find_selection_event(self, event): SearchDialog.find_selection(self.text) return "break"
def _find_again_event(self, event): SearchDialog.find_again(self.text) return "break"
import tkSimpleDialog