[svn] Add double click and remove sorting when refreshing data. immsview
authorfabien
Tue, 03 Feb 2004 13:50:03 -0500
branchimmsview
changeset 11 2913cf0e73e2
parent 10 bc1c7546502a
child 12 d275de5d2be2
[svn] Add double click and remove sorting when refreshing data.
immsview
--- a/immsview	Mon Feb 02 10:45:25 2004 -0500
+++ b/immsview	Tue Feb 03 13:50:03 2004 -0500
@@ -20,9 +20,12 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-_immsview_version = "$Id: immsview 1692 2004-02-02 15:45:25Z fabien $"
+_immsview_version = "$Id: immsview 1693 2004-02-03 18:50:03Z fabien $"
 
 # $Log$
+# Revision 1.12  2004/02/03 18:50:03  fabien
+# Add double click and remove sorting when refreshing data.
+#
 # Revision 1.11  2004/02/02 15:45:25  fabien
 # Add a comment about the autocommit value in db.connect()
 #
@@ -163,6 +166,7 @@
                    WHERE Library.path = '%s';''' % (path))
         return cu.fetchone()
     def get_ratings_and_info(self):
+    	print time.ctime(time.time()) + ": querying"
         cu = self.cx.cursor()
         cu.execute('''SELECT Rating.uid, Rating.rating,
                    Library.path, Last.last
@@ -172,10 +176,10 @@
                    ORDER BY Rating.rating DESC;''')
         # Better to fetch everything since locking can really mess
         # things in imms plugin.
-        res = cu.fetchall()
-        self.commit()
-        results = []
-        for tune in res:
+    	print time.ctime(time.time()) + ": mapping"
+	results = []
+	tune = cu.fetchone()
+        while tune:
             try:
                 tmp = {'rating' : int(tune[1]),
                        'path' : tune[2].decode('utf-8', 'replace'),
@@ -183,6 +187,7 @@
                 results.append(tmp)
             except UnicodeDecodeError:
                 print tune[2]
+	    tune = cu.fetchone()
         return results
 
 class IMMSStore(gtk.ListStore):
@@ -199,13 +204,20 @@
                                gobject.TYPE_INT,
                                gobject.TYPE_BOOLEAN)
         self.db = db
-        self.set_sort_column_id(IMMSStore.COL_RATING, gtk.SORT_DESCENDING)
+        # self.set_default_sort_func(self.default_sort)
+    def default_sort(self, a, b, dummy):
+        return 0
     def refresh(self):
         curtime = time.time()
         col, order = self.get_sort_column_id()
-        self.set_sort_column_id(IMMSStore.COL_RATING, gtk.SORT_DESCENDING)
+        # This create a GTK-Critical in GTKListStore which,
+        # however, have no consequences AFAIK.
+        # The doc permit it normally, even without default sort,
+        # elsewhere 
+        self.set_sort_column_id(-1, 0)
         tunes = self.db.get_ratings_and_info()
         self.clear()
+	print time.ctime(time.time()) + ": inserting"
         for tune in tunes:
             iter = self.append(None)
             self.set(iter,
@@ -214,6 +226,7 @@
                      IMMSStore.COL_LAST_STR, strtime(curtime-tune['last']),
                      IMMSStore.COL_LAST, tune['last'],
                      IMMSStore.COL_SELECT, gtk.FALSE)
+	print time.ctime(time.time()) + ": end insert"
         self.set_sort_column_id(col, order)
     def find_selection(self):
         giter = self.get_iter_first()
@@ -231,8 +244,9 @@
         return None
 
 class IMMSView(gtk.TreeView):
-	def __init__(self, model):
+	def __init__(self, model, xmms):
             gtk.TreeView.__init__(self, model)
+            self.xmms = xmms
             self.create_widgets()
 	def create_widgets(self):
             renderer = gtk.CellRendererText()
@@ -255,6 +269,7 @@
             self.append_column(column)
             self.set_search_column(IMMSStore.COL_PATH)
             self.set_headers_clickable(gtk.TRUE)
+            self.connect('row-activated', self.on_row_activated)
         def set_current_song(self, song):
             model = self.get_model()
             gpath = model.find_selection()
@@ -271,6 +286,12 @@
             if giter:
                 return model.get_value(giter, IMMSStore.COL_PATH)
             return None
+        def on_row_activated(self, tview, path, col):
+            model = self.get_model()
+            giter = model.get_iter(path)
+            fn = model.get_value(giter, IMMSStore.COL_PATH)
+            self.xmms.play_file(fn)
+
 
 class IMMSToolbar(gtk.Toolbar):
     # _IMMSPLOT_COMMAND = 'immsplot &'
@@ -315,7 +336,6 @@
         self.xmms.playlist_next()
         time.sleep(self._SLEEP_TIME)
         self.do_get_current(dummy)
-        
 
 root = gtk.Window()
 root.set_title(_("IMMSView"))
@@ -324,13 +344,14 @@
 root.add(vbox)
 vbox.show()
 model = IMMSStore(IMMSDb())
-iview = IMMSView(model)
+xmms_control = XMMSControl()
+iview = IMMSView(model,xmms_control)
 scroll = gtk.ScrolledWindow()
 scroll.add(iview)
 vbox.pack_end(scroll)
 iview.show()
 scroll.show()
-toolbar = IMMSToolbar(iview, XMMSControl())
+toolbar = IMMSToolbar(iview, xmms_control)
 vbox.pack_start(toolbar, expand = gtk.FALSE)
 toolbar.show()
 root.show()