← Back to team overview

clicompanion-devs team mailing list archive

[Merge] lp:~dcaro/clicompanion/fix-910370 into lp:clicompanion

 

David Caro has proposed merging lp:~dcaro/clicompanion/fix-910370 into lp:clicompanion.

Requested reviews:
  CLI Companion Development Team (clicompanion-devs)
Related bugs:
  Bug #910370 in CLI Companion: "Drag and drop when searching breaks the drag and drop"
  https://bugs.launchpad.net/clicompanion/+bug/910370

For more details, see:
https://code.launchpad.net/~dcaro/clicompanion/fix-910370/+merge/87196

Now the liststore is saved before a search and restored after, so the drag and drop is only available when not searching. Also the drag_and_drop signal is now intercepted to avoid the warning.
-- 
https://code.launchpad.net/~dcaro/clicompanion/fix-910370/+merge/87196
Your team CLI Companion Development Team is requested to review the proposed merge of lp:~dcaro/clicompanion/fix-910370 into lp:clicompanion.
=== modified file 'clicompanionlib/controller.py'
--- clicompanionlib/controller.py	2011-12-31 14:49:46 +0000
+++ clicompanionlib/controller.py	2011-12-31 16:20:29 +0000
@@ -194,16 +194,16 @@
             return
         row_int_x = int(view.ROW[0][0])
         row_int = 0
-		## TODO: Not implemented with filted yet
+        ## TODO: Not implemented with filted yet
         if view.FILTER == 1:
             with open(CHEATSHEET, "r") as cheatfile:
                 cheatlines = cheatfile.readlines()
                 for i in range(len(cheatlines)):
-			    	if view.CMNDS[row_int_x][0] in cheatlines[i] and view.CMNDS[row_int_x][1] in cheatlines[i] :
-				    	row_int = i 
+                    if view.CMNDS[row_int_x][0] in cheatlines[i] and view.CMNDS[row_int_x][1] in cheatlines[i] :
+                        row_int = i 
                 cheatfile.close()
         else:
-			row_int = row_int_x
+            row_int = row_int_x
 
          
         row_obj1 = view.MainWindow.liststore[row_int][0]
@@ -293,21 +293,21 @@
 
     ## Remove command from command file and GUI
     def remove_command(self, widget, liststore):
-		
+        
         if not view.ROW:
             return
         row_int_x = int(view.ROW[0][0])
         row_int = 0
-		## TODO: Not implemented with filted yet
+        ## TODO: Not implemented with filted yet
         if view.FILTER == 1:
             with open(CHEATSHEET, "r") as cheatfile:
                 cheatlines = cheatfile.readlines()
                 for i in range(len(cheatlines)):
-			    	if view.CMNDS[row_int_x][0] in cheatlines[i] and view.CMNDS[row_int_x][1] in cheatlines[i]:
-				    	row_int = i 
+                    if view.CMNDS[row_int_x][0] in cheatlines[i] and view.CMNDS[row_int_x][1] in cheatlines[i]:
+                        row_int = i 
                 cheatfile.close()
         else:
-			row_int = row_int_x
+            row_int = row_int_x
 
         del view.CMNDS[row_int_x]
         del liststore[row_int]
@@ -330,9 +330,17 @@
         Pretty straight-forward.
         """
         search_term = widget.get_text().lower()
+        ## if the searchbox is empty, set the original model
         if search_term == "":
-		    view.FILTER = 0
+            view.FILTER = 0
+            treeview.set_model(liststore)
+            #clear CMNDS list then populate it with the filteredlist of commands
+            view.CMNDS = []
+            for line in liststore:
+                filteredcommandplus = tuple(liststore.get(line.iter, 0, 1, 2))
+                view.CMNDS.append(filteredcommandplus)
         else:
+<<<<<<< TREE
 		    view.FILTER = 1
         
         ## Create a TreeModelFilter object which provides auxiliary functions for
@@ -367,6 +375,41 @@
         for line in modelfilter:
             filteredcommandplus = tuple(modelfilter.get(line.iter, 0, 1, 2))
             view.CMNDS.append(filteredcommandplus)
+=======
+            view.FILTER = 1
+            ## save the current liststore
+            self.liststore = liststore
+            ## Create a TreeModelFilter object which provides auxiliary functions for
+            ## filtering data.
+            ## http://www.pygtk.org/pygtk2tutorial/sec-TreeModelSortAndTreeModelFilter.html
+            modelfilter = liststore.filter_new()
+            def search(modelfilter, iter, search_term):
+                try:
+                    ## Iterate through every column and row and check if the search
+                    ## term is there:
+                    if search_term in modelfilter.get_value(iter, 0).lower() or \
+                       search_term in modelfilter.get_value(iter, 1).lower() or \
+                       search_term in modelfilter.get_value(iter, 2).lower() :
+                            return True
+                                             
+                except TypeError:
+                    ## Python raises a TypeError if row data doesn't exist. Catch
+                    ## that and fail silently.
+                    pass
+                except AttributeError:
+                    ## Python raises a AttributeError if row data was modified . Catch
+                    ## that and fail silently.
+                    pass
+    
+            modelfilter.set_visible_func(search, search_term)
+            treeview.set_model(modelfilter)
+
+            #clear CMNDS list then populate it with the filteredlist of commands
+            view.CMNDS = []
+            for line in modelfilter:
+                filteredcommandplus = tuple(modelfilter.get(line.iter, 0, 1, 2))
+                view.CMNDS.append(filteredcommandplus)
+>>>>>>> MERGE-SOURCE
 
 
 

=== modified file 'clicompanionlib/view.py'
--- clicompanionlib/view.py	2011-12-30 12:22:17 +0000
+++ clicompanionlib/view.py	2011-12-31 16:20:29 +0000
@@ -433,14 +433,23 @@
         self.treeview.enable_model_drag_dest(TARGETS,
                                                 gtk.gdk.ACTION_DEFAULT)
 
-        self.treeview.connect ("drag_data_get", self.drag_data_get_event)
-        self.treeview.connect ("drag_data_received", self.drag_data_received_event)
+        self.treeview.connect("drag_data_get", self.drag_data_get_event)
+        self.treeview.connect("drag_data_received", self.drag_data_received_event)
+        self.treeview.connect("drag_drop", self.on_drag_drop )
 
 
         #self.vte.grab_focus()
         self.window.show_all()
         return
 
+    def on_drag_drop(self, treeview, *x):
+        '''
+        Stop the signal when in search mode
+        '''
+        if FILTER:
+            treeview.stop_emission('drag_drop')
+            return
+
     def drag_data_get_event(self, treeview, context, selection, target_id, 
                             etime):
         """