[jokosher-devel] add instrument search



hello

i have noticed that lots of instruments have recently been added to jokosher, and the add instrument dialog is at risk of getting quite crowded.

this patch adds a quick filter-as-you-type search box.

it adds the interface to the glade file
a few lines in AddInstrumentDialog.__init__() in AddInstrumentDialog.py
a new signal handling function to the AddInstrumentDialog.py
and a change to AddInstrumentDialog.OnOK to select the instrument from the displayed list, rather than the full list.

the patch was made with 'svn diff' against revision 467

Sam Tygier

Index: AddInstrumentDialog.py
===================================================================
--- AddInstrumentDialog.py	(revision 467)
+++ AddInstrumentDialog.py	(working copy)
@@ -26,12 +26,14 @@
 		self.signals = {
 			"on_OK_clicked" : self.OnOK,
 			"on_Cancel_clicked" : self.OnCancel,
+			"on_instrument_search_changed" : self.OnSearchChange,
 		}
 		
 		self.res.signal_autoconnect(self.signals)
 		
 		self.dlg = self.res.get_widget("AddInstrumentDialog")
 		self.tree = self.res.get_widget("Instruments")
+		self.search_entry = self.res.get_widget("instrument_search")
 		
 		self.okbutton = self.res.get_widget("okButton")
 		self.okbutton.set_sensitive(False)
@@ -68,7 +70,7 @@
 	def OnOK(self, button=None):
 		sel = self.tree.get_selected_items()
 		for i in sel:
-			currentItem = getCachedInstruments()[i[0]]
+			currentItem = self.model[i[0]]
 			
 			filenameList = []
 			for i in currentItem[3].split(","):
@@ -106,6 +108,18 @@
 			self.okbutton.set_sensitive(True)
 			
 	#_____________________________________________________________________
+	
+	def OnSearchChange(self, widget):
+		search_text = self.search_entry.get_text()
+		self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, str, str, str)
+		
+		for i in getCachedInstruments():
+			if search_text.lower() in i[0].lower():
+				self.model.append(i)
+		
+		self.tree.set_model(self.model)
+		
+	#_____________________________________________________________________
 
 #=========================================================================
 #static list of all the instrument files (to prevent having to reimport files)
Index: Jokosher.glade
===================================================================
--- Jokosher.glade	(revision 467)
+++ Jokosher.glade	(working copy)
@@ -1160,6 +1160,64 @@
       </child>
 
       <child>
+	<widget class="GtkHBox" id="hbox10">
+	  <property name="visible">True</property>
+	  <property name="homogeneous">False</property>
+	  <property name="spacing">0</property>
+
+	  <child>
+	    <widget class="GtkLabel" id="label57">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Search</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkEntry" id="instrument_search">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="editable">True</property>
+	      <property name="visibility">True</property>
+	      <property name="max_length">0</property>
+	      <property name="text" translatable="yes"></property>
+	      <property name="has_frame">True</property>
+	      <property name="invisible_char">â??</property>
+	      <property name="activates_default">False</property>
+	      <signal name="changed" handler="on_instrument_search_changed" last_modification_time="Wed, 05 Jul 2006 21:42:49 GMT"/>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+
+      <child>
 	<widget class="GtkScrolledWindow" id="scrolledwindow2">
 	  <property name="visible">True</property>
 	  <property name="can_focus">True</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]