Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2009-10-12 17:09:15 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2009-10-12 17:09:15 (GMT)
commit831c52acea4ecd848b84e7ef62e8e98a02ca5483 (patch)
treef83d99b0df6ba3d935c33ad8d0967d61483c8613
parent613e264a7a75eeb48e15749dea0931beb33e050f (diff)
Use the _right_ listview.py this time. Eeeghgit status
-rw-r--r--listview.py156
1 files changed, 73 insertions, 83 deletions
diff --git a/listview.py b/listview.py
index bb42218..ca3914e 100644
--- a/listview.py
+++ b/listview.py
@@ -1,84 +1,74 @@
-#!/usr/bin/env python
+#! /usr/bin/env python
+
+# Copyright (C) 2009 Sayamindu Dasgupta <sayamindu@laptop.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gobject, gtk, gtk.gdk, pango, sys
+from gettext import gettext as _
+import logging
+
+from extListview import ExtListView
+
+_logger = logging.getLogger('get-ia-books-activity')
+
+class ListView(ExtListView):
+ __txtRdr = gtk.CellRendererText()
+ __txtRdr.props.wrap_mode = pango.WRAP_WORD
+ __txtRdr.props.wrap_width = 500
+ __txtRdr.props.width = 500
+ (
+ ROW_TITLE,
+ ROW_AUTHOR,
+ ROW_PUBLISHER,
+ ROW_LANGUAGE,
+ ROW_PUB_DATE,
+ ROW_BOOK
+ ) = range(6)
+ columns = ((_('Title'), [(__txtRdr, gobject.TYPE_STRING)], (ROW_TITLE,), False, True),
+ (_('Author'), [(__txtRdr, gobject.TYPE_STRING)], (ROW_AUTHOR, ROW_TITLE), False, True),
+ (_('Publisher'), [(__txtRdr, gobject.TYPE_STRING)], (ROW_AUTHOR, ROW_TITLE), False, False),
+ (_('Language'), [(__txtRdr, gobject.TYPE_STRING)], (ROW_AUTHOR, ROW_TITLE), False, False),
+ (_('Publish Date'), [(__txtRdr, gobject.TYPE_STRING)], (ROW_AUTHOR, ROW_TITLE), False, False),
+ (None, [(None, gobject.TYPE_PYOBJECT)], (None,), False, False))
+ __gsignals__ = {
+ 'selection-changed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([])),
+ }
+ def __init__(self):
+ ExtListView.__init__(self, self.columns, sortable=True, useMarkup=False, canShowHideColumns=True)
+ #self.enableDNDReordering() # Is this needed ?
+ selection = self.get_selection()
+ selection.set_mode(gtk.SELECTION_SINGLE)
+ selection.connect("changed", self.__selection_changed_cb)
+
+ def __selection_changed_cb(self, selection):
+ self.emit('selection-changed')
+
+ def populate(self, results):
+ rows = []
+
+ for book in results.get_book_list():
+ try:
+ rows.append([book.get_title(), book.get_author(), book.get_publisher(), book.get_language(), book.get_published_year(), book])
+ except:
+ _logger.debug(sys.exc_info())
+
+ self.insertRows(rows)
+
+ def get_selected_book(self):
+ return self.getFirstSelectedRow()[self.ROW_BOOK]
-import extListview, gobject, gtk, gtk.gdk, pango, sys
-import opds
-
-def onListModified():
- print 'Modified!'
-
-def onColumnVisibilityChanged(list, colTitle, visible):
- print 'Visibility of', colTitle, 'is now', visible
-
-# Setup the main window
-window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-window.connect('delete_event', gtk.main_quit)
-#window.set_default_size(450, 300)
-
-# Setup the scrolled window
-scrolledwin = gtk.ScrolledWindow()
-scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
-box = gtk.VBox()
-window.add(box)
-box.pack_start(scrolledwin)
-box.set_homogeneous(False)
-
-# Create the two renderers used in the listview
-txtRdr = gtk.CellRendererText()
-txtRdr.props.wrap_mode = pango.WRAP_WORD
-txtRdr.props.wrap_width = 500
-pixbufRdr = gtk.CellRendererPixbuf()
-
-# The fields in a row of the listview
-(
- ROW_TIT,
- ROW_AUT,
- ROW_PUB,
- ROW_LANG,
- ROW_DATE
-) = range(5)
-
-# Setup the columns
-# Part 1 is the title of the column. If None, the column is not visible at all.
-# Part 2 is a list of tuple (CellRenderer, ValueType) to be put in that column.
-# Part 3 is the tuple with all the fields used when sorting on that column: first sort on the first field, then on the second...
-# Part 4 is a boolean that specifies whether the column is expanded.
-# Part 5 is a boolean giving the initial visibility of the column. This can be changed by the user by right-clicking on the column headers.
-columns = (('Title', [(txtRdr, gobject.TYPE_STRING)], (ROW_TIT,), True, True),
- ('Author', [(txtRdr, gobject.TYPE_STRING)], (ROW_AUT, ROW_TIT), True, True),
- ('Publisher', [(txtRdr, gobject.TYPE_STRING)], (ROW_AUT, ROW_TIT), True, True),
- ('Language', [(txtRdr, gobject.TYPE_STRING)], (ROW_AUT, ROW_TIT), True, False),
- (None, [(None, gobject.TYPE_STRING)], (None,), False, False))
-
-listview = extListview.ExtListView(columns, sortable=True, useMarkup=False, canShowHideColumns=True)
-listview.enableDNDReordering()
-listview.connect('extlistview-modified', lambda *args: onListModified())
-listview.connect('extlistview-column-visibility-changed', onColumnVisibilityChanged)
-scrolledwin.add(listview)
-
-# Buttons
-#buttons = gtk.HButtonBox()
-#box.pack_start(buttons, False)
-
-#shuffleBtn = gtk.Button('Shuffle')
-#shuffleBtn.connect('clicked', lambda btn: listview.shuffle())
-#buttons.add(shuffleBtn)
-
-# Some arbitrary data to put in the listview
-#icon = listview.render_icon(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_MENU)
-
-rows = []
-
-searchresults = opds.FeedBooksQueryResult('Jules Verne')
-
-for book in searchresults.get_book_list():
- try:
- rows.append([book.get_title(), book.get_author(), book.get_publisher(), 'English', book.get_published_year()])
- #rows.append([entry['title'], entry['author'], entry['publisher'], entry['language'], entry['published']])
- except:
- print sys.exc_info()
-
-listview.insertRows(rows)
-
-# Let's go
-window.show_all()
-gtk.main()