Ticket #3681: Port-Gtk3-backup.diff

File Port-Gtk3-backup.diff, 49.7 KB (added by humitos, 8 years ago)

This is my progress until now. I'm attaching this here to have as a reference if someone else is porting another activity and as a backup as well

  • GetIABooksActivity.py

    diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
    index 0a06069..7fc0827 100644
    a b  
    1919import os
    2020import logging
    2121import time
    22 import gtk
    23 
    24 OLD_TOOLBAR = False
    25 try:
    26     from sugar.graphics.toolbarbox import ToolbarBox
    27     from sugar.activity.widgets import StopButton
    28 except ImportError:
    29     OLD_TOOLBAR = True
    30 
    31 from sugar.graphics import style
    32 from sugar.graphics.toolbutton import ToolButton
    33 from sugar.graphics.toggletoolbutton import ToggleToolButton
    34 from sugar.graphics.toolcombobox import ToolComboBox
    35 from sugar.graphics.combobox import ComboBox
    36 from sugar.graphics import iconentry
    37 from sugar import profile
    38 from sugar.activity import activity
    39 from sugar.activity.widgets import ToolbarButton
    40 from sugar.bundle.activitybundle import ActivityBundle
    41 from sugar.datastore import datastore
    42 from sugar.graphics.alert import NotifyAlert
    43 from sugar.graphics.alert import Alert
    44 from sugar.graphics.icon import Icon
     22
     23from gi.repository import Gtk
     24from gi.repository import Gdk
     25from gi.repository import GdkPixbuf
     26from gi.repository import GObject
     27from gi.repository import Pango
     28
     29
     30from sugar3.graphics.toolbarbox import ToolbarBox
     31from sugar3.activity.widgets import StopButton
     32from sugar3.graphics import style
     33from sugar3.graphics.toolbutton import ToolButton
     34from sugar3.graphics.toggletoolbutton import ToggleToolButton
     35from sugar3.graphics.toolcombobox import ToolComboBox
     36from sugar3.graphics.combobox import ComboBox
     37from sugar3.graphics import iconentry
     38from sugar3 import profile
     39from sugar3.activity import activity
     40from sugar3.activity.widgets import ToolbarButton
     41from sugar3.bundle.activitybundle import ActivityBundle
     42from sugar3.datastore import datastore
     43from sugar3.graphics.alert import NotifyAlert
     44from sugar3.graphics.alert import Alert
     45from sugar3.graphics.icon import Icon
    4546from gettext import gettext as _
     47
    4648import dbus
    47 import gobject
    4849import ConfigParser
    4950import base64
    5051
    class GetIABooksActivity(activity.Activity): 
    8687        else:
    8788            self._read_configuration()
    8889
    89         if OLD_TOOLBAR:
    90             toolbox = activity.ActivityToolbox(self)
    91             activity_toolbar = toolbox.get_activity_toolbar()
    92 
    93             self.set_toolbox(toolbox)
    94             self._books_toolbar = gtk.Toolbar()
    95             self._add_search_controls(self._books_toolbar)
    96             self.toolbox.add_toolbar(_('Books'), self._books_toolbar)
    97             self._books_toolbar.show()
    98             toolbox.show()
    99             toolbox.set_current_toolbar(1)
    100         else:
    101             toolbar_box = ToolbarBox()
    102             activity_button = ToolButton()
    103             color = profile.get_color()
    104             bundle = ActivityBundle(activity.get_bundle_path())
    105             icon = Icon(file=bundle.get_icon(), xo_color=color)
    106             activity_button.set_icon_widget(icon)
    107             activity_button.show()
     90        toolbar_box = ToolbarBox()
     91        activity_button = ToolButton()
     92        color = profile.get_color()
     93        bundle = ActivityBundle(activity.get_bundle_path())
     94        icon = Icon(file=bundle.get_icon(), xo_color=color)
     95        activity_button.set_icon_widget(icon)
     96        activity_button.show()
    10897
    109             toolbar_box.toolbar.insert(activity_button, 0)
    110             self._add_search_controls(toolbar_box.toolbar)
     98        toolbar_box.toolbar.insert(activity_button, 0)
     99        self._add_search_controls(toolbar_box.toolbar)
    111100
    112             separator = gtk.SeparatorToolItem()
    113             separator.props.draw = False
    114             separator.set_expand(True)
    115             toolbar_box.toolbar.insert(separator, -1)
     101        separator = Gtk.SeparatorToolItem()
     102        separator.props.draw = False
     103        separator.set_expand(True)
     104        toolbar_box.toolbar.insert(separator, -1)
    116105
    117             toolbar_box.toolbar.insert(StopButton(self), -1)
     106        toolbar_box.toolbar.insert(StopButton(self), -1)
    118107
    119             self.set_toolbar_box(toolbar_box)
    120             toolbar_box.show_all()
    121             self._books_toolbar = toolbar_box.toolbar
     108        self.set_toolbar_box(toolbar_box)
     109        toolbar_box.show_all()
     110        self._books_toolbar = toolbar_box.toolbar
    122111
    123112        self._create_controls()
    124113
    class GetIABooksActivity(activity.Activity): 
    133122                logging.warning("Error setting OHM inhibit: %s", e)
    134123                self.ohm_keystore = None
    135124
     125
    136126    def powerd_running(self):
    137127        self.using_powerd = os.access(POWERD_INHIBIT_DIR, os.W_OK)
    138128        logging.error("using_powerd: %d", self.using_powerd)
    class GetIABooksActivity(activity.Activity): 
    236226        logging.error('catalogs %s', self.catalogs)
    237227
    238228    def _add_search_controls(self, toolbar):
    239         book_search_item = gtk.ToolItem()
     229        book_search_item = Gtk.ToolItem()
    240230        toolbar.search_entry = iconentry.IconEntry()
    241231        toolbar.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
    242232                                                'system-search')
    243233        toolbar.search_entry.add_clear_button()
    244234        toolbar.search_entry.connect('activate',
    245235                self.__search_entry_activate_cb)
    246         width = int(gtk.gdk.screen_width() / 4)
     236        width = int(Gdk.Screen.width() / 4)
    247237        toolbar.search_entry.set_size_request(width, -1)
    248238        book_search_item.add(toolbar.search_entry)
    249239        toolbar.search_entry.show()
    class GetIABooksActivity(activity.Activity): 
    268258        if len(self.languages) > 0:
    269259            toolbar.config_toolbarbutton = ToolbarButton()
    270260            toolbar.config_toolbarbutton.props.icon_name = 'preferences-system'
    271             toolbar.config_toolbarbox = gtk.Toolbar()
     261            toolbar.config_toolbarbox = Gtk.Toolbar()
    272262            toolbar.config_toolbarbutton.props.page = toolbar.config_toolbarbox
    273263            toolbar.language_combo = ComboBox()
    274264            toolbar.language_combo.props.sensitive = True
    class GetIABooksActivity(activity.Activity): 
    321311        self.queryresults = opds.RemoteQueryResult(catalog_config,
    322312                '', query_language)
    323313        self.show_message(_('Performing lookup, please wait...'))
    324         self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
     314        self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
    325315
    326316        self.queryresults.connect('updated', self.__query_updated_cb)
    327317
    class GetIABooksActivity(activity.Activity): 
    455445            self.tree_scroller.show_all()
    456446            self.separa.show()
    457447        else:
    458             self.tree_scroller.hide_all()
     448            # README: hide_all() doesn't exist anymore
     449            # http://developer.gnome.org/gtk3/3.5/GtkWidget.html#gtk-widget-hide
     450            self.tree_scroller.hide()
    459451            self.separa.hide()
    460452
    461453    def _create_controls(self):
    462454        self._download_content_length = 0
    463455        self._download_content_type = None
    464         self.progressbox = gtk.HBox(spacing=20)
    465         self.progressbar = gtk.ProgressBar()
    466         self.progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
     456        self.progressbox = Gtk.Box(spacing=20,
     457                                   orientation=Gtk.Orientation.HORIZONTAL)
     458        self.progressbar = Gtk.ProgressBar()
    467459        self.progressbar.set_fraction(0.0)
    468         self.progressbox.pack_start(self.progressbar, expand=True,
    469                 fill=True)
    470         self.cancel_btn = gtk.Button(stock=gtk.STOCK_CANCEL)
     460        self.progressbox.pack_start(self.progressbar, expand=True, fill=True,
     461                                    padding=0)
     462        self.cancel_btn = Gtk.Button(stock=Gtk.STOCK_CANCEL)
    471463        self.cancel_btn.connect('clicked', self.__cancel_btn_clicked_cb)
    472464        self.progressbox.pack_start(self.cancel_btn, expand=False,
    473                 fill=False)
     465                                    fill=False, padding=0)
    474466
    475         self.msg_label = gtk.Label()
     467        self.msg_label = Gtk.Label()
    476468
    477         self.list_box = gtk.HBox()
     469        self.list_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    478470
    479471        # Catalogs treeview
    480         self.catalog_listview = gtk.TreeView()
     472        self.catalog_listview = Gtk.TreeView()
    481473        self.catalog_listview.headers_clickble = True
    482474        self.catalog_listview.hover_expand = True
    483475        self.catalog_listview.rules_hint = True
    484476        self.catalog_listview.connect('cursor-changed', self.move_down_catalog)
    485477        self.catalog_listview.set_enable_search(False)
    486         self.treemodel = gtk.ListStore(gobject.TYPE_STRING)
    487         sorter = gtk.TreeModelSort(self.treemodel)
    488         sorter.set_sort_column_id(0, gtk.SORT_ASCENDING)
    489         sorter.set_sort_func(0, self._sort_logfile)
    490         self.catalog_listview.set_model(sorter)
    491         renderer = gtk.CellRendererText()
    492         renderer.set_property('wrap-mode', gtk.WRAP_WORD)
    493         self.treecol = gtk.TreeViewColumn(_('Catalogs'), renderer, text=0)
     478
     479        self.treemodel = Gtk.ListStore(GObject.TYPE_STRING)
     480        self.treemodel.set_sort_column_id(0, Gtk.SortType.ASCENDING)
     481        self.catalog_listview.set_model(self.treemodel)
     482
     483        renderer = Gtk.CellRendererText()
     484        renderer.set_property('wrap-mode', Pango.WrapMode.WORD)
     485        self.treecol = Gtk.TreeViewColumn(_('Catalogs'), renderer, text=0)
    494486        self.treecol.set_property('clickable', True)
    495487        self.treecol.connect('clicked', self.move_up_catalog)
    496488        self.catalog_listview.append_column(self.treecol)
    class GetIABooksActivity(activity.Activity): 
    508500            self.treemodel.clear()
    509501            for p in self.categories:
    510502                self.path_iter[p['text']] = self.treemodel.append([p['text']])
    511         self.tree_scroller = gtk.ScrolledWindow(hadjustment=None,
    512                 vadjustment=None)
    513         self.tree_scroller.set_policy(gtk.POLICY_NEVER,
    514                 gtk.POLICY_AUTOMATIC)
     503        self.tree_scroller = Gtk.ScrolledWindow(hadjustment=None,
     504                                                vadjustment=None)
     505        self.tree_scroller.set_policy(Gtk.PolicyType.NEVER,
     506                Gtk.PolicyType.AUTOMATIC)
    515507        self.tree_scroller.add(self.catalog_listview)
    516         self.list_box.pack_start(self.tree_scroller, expand=False, fill=False)
    517         self.separa = gtk.VSeparator()
    518         self.list_box.pack_start(self.separa, expand=False, fill=False)
     508        self.list_box.pack_start(self.tree_scroller, expand=False,
     509                                 fill=False, padding=0)
     510        self.separa = Gtk.VSeparator()
     511        self.list_box.pack_start(self.separa, expand=False,
     512                                 fill=False, padding=0)
    519513
    520514        # books listview
    521515        self.listview = ListView(self._lang_code_handler)
    522516        self.listview.connect('selection-changed', self.selection_cb)
    523517        self.listview.set_enable_search(False)
    524518
    525         self.list_scroller = gtk.ScrolledWindow(hadjustment=None,
     519        self.list_scroller = Gtk.ScrolledWindow(hadjustment=None,
    526520                vadjustment=None)
    527         self.list_scroller.set_policy(gtk.POLICY_AUTOMATIC,
    528                 gtk.POLICY_AUTOMATIC)
     521        self.list_scroller.set_policy(Gtk.PolicyType.AUTOMATIC,
     522                Gtk.PolicyType.AUTOMATIC)
    529523        vadjustment = self.list_scroller.get_vadjustment()
    530524        vadjustment.connect('value-changed',
    531525                self.__vadjustment_value_changed_cb)
    532526        self.list_scroller.add(self.listview)
    533         self.list_box.pack_start(self.list_scroller, expand=True, fill=True)
    534 
    535         self.scrolled = gtk.ScrolledWindow()
    536         self.scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
    537         self.scrolled.props.shadow_type = gtk.SHADOW_NONE
    538         self.textview = gtk.TextView()
     527        self.list_box.pack_start(self.list_scroller, expand=True,
     528                                 fill=True, padding=0)
     529
     530        self.scrolled = Gtk.ScrolledWindow()
     531        self.scrolled.set_policy(Gtk.PolicyType.NEVER,
     532                                 Gtk.PolicyType.AUTOMATIC)
     533        self.scrolled.props.shadow_type = Gtk.ShadowType.NONE
     534        self.textview = Gtk.TextView()
    539535        self.textview.set_editable(False)
    540536        self.textview.set_cursor_visible(False)
    541         self.textview.set_wrap_mode(gtk.WRAP_WORD)
    542         self.textview.set_justification(gtk.JUSTIFY_LEFT)
     537        self.textview.set_wrap_mode(Gtk.WrapMode.WORD)
     538        self.textview.set_justification(Gtk.Justification.LEFT)
    543539        self.textview.set_left_margin(20)
    544540        self.textview.set_right_margin(20)
    545541        self.scrolled.add(self.textview)
    class GetIABooksActivity(activity.Activity): 
    547543        self.separa.hide()
    548544        self.tree_scroller.hide()
    549545
    550         vbox_download = gtk.VBox()
     546        vbox_download = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
    551547
    552         hbox_format = gtk.HBox()
    553         format_label = gtk.Label(_('Format:'))
     548        hbox_format = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
     549        format_label = Gtk.Label(label=_('Format:'))
    554550        self.format_combo = ComboBox()
    555551        for key in _MIMETYPES.keys():
    556552            self.format_combo.append_item(_MIMETYPES[key], key)
    class GetIABooksActivity(activity.Activity): 
    563559        hbox_format.pack_start(self.format_combo, False, False, 10)
    564560        vbox_download.pack_start(hbox_format, False, False, 10)
    565561
    566         self._download = gtk.Button(_('Get Book'))
     562        self._download = Gtk.Button(_('Get Book'))
    567563        self._download.props.sensitive = False
    568564        self._download.connect('clicked', self.__get_book_cb)
    569565        vbox_download.pack_start(self._download, False, False, 10)
    570566
    571         bottom_hbox = gtk.HBox()
     567        bottom_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    572568
    573569        if self.show_images:
    574570            self.__image_downloader = None
    575             self.image = gtk.Image()
     571            self.image = Gtk.Image()
    576572            self.add_default_image()
    577573            bottom_hbox.pack_start(self.image, False, False, 10)
    578574        bottom_hbox.pack_start(self.scrolled, True, True, 10)
    579575        bottom_hbox.pack_start(vbox_download, False, False, 10)
    580576        bottom_hbox.show_all()
    581577
    582         vbox = gtk.VBox()
     578        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
    583579        vbox.pack_start(self.msg_label, False, False, 10)
    584580        vbox.pack_start(self.progressbox, False, False, 10)
    585581        vbox.pack_start(self.list_box, True, True, 0)
    class GetIABooksActivity(activity.Activity): 
    596592        if len(self.catalogs) > 0:
    597593            self.bt_catalogs.set_active(True)
    598594
    599 
    600595    def can_close(self):
    601596        self._lang_code_handler.close()
    602597        if self.queryresults is not None:
    class GetIABooksActivity(activity.Activity): 
    606601
    607602    def selection_cb(self, widget):
    608603        # Testing...
     604        logging.debug('FUNCTION: selection_cb')
    609605        selected_book = self.listview.get_selected_book()
     606        logging.debug('SELECTED_BOOK: %s', selected_book)
    610607        if self.source == 'local_books':
    611608            if selected_book:
    612609                self.download_url = ''
    class GetIABooksActivity(activity.Activity): 
    632629        self.msg_label.hide()
    633630
    634631    def show_book_data(self, load_image=True):
     632        logging.debug('FUNCTION: show_book_data')
    635633        self.selected_title = self.selected_book.get_title()
    636634        book_data = _('Title:\t\t') + self.selected_title + '\n'
    637635        self.selected_author = self.selected_book.get_author()
    class GetIABooksActivity(activity.Activity): 
    679677
    680678    def get_pixbuf_from_buffer(self, image_buffer):
    681679        """Buffer To Pixbuf"""
    682         pixbuf_loader = gtk.gdk.PixbufLoader()
     680        pixbuf_loader = GdkPixbuf.PixbufLoader()
    683681        pixbuf_loader.write(image_buffer)
    684682        pixbuf_loader.close()
    685683        pixbuf = pixbuf_loader.get_pixbuf()
    class GetIABooksActivity(activity.Activity): 
    718716        self.add_image(file_path)
    719717
    720718    def add_image(self, file_path):
    721         pixbuf = gtk.gdk.pixbuf_new_from_file(file_path)
     719        pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_path)
    722720        self.add_image_buffer(pixbuf)
    723721
    724722    def add_image_buffer(self, pixbuf):
    725         image_height = int(gtk.gdk.screen_height() / 4)
     723        image_height = int(Gdk.Screen.height() / 4)
    726724        image_width = image_height / 3 * 2
    727725        width, height = pixbuf.get_width(), pixbuf.get_height()
    728726        scale = 1
    class GetIABooksActivity(activity.Activity): 
    731729            scale_y = image_height / float(height)
    732730            scale = min(scale_x, scale_y)
    733731
    734         pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, \
    735                             pixbuf.get_has_alpha(), \
    736                             pixbuf.get_bits_per_sample(), \
    737                             image_width, image_height)
    738         pixbuf2.fill(style.COLOR_PANEL_GREY.get_int())
     732        pixbuf2 = GdkPixbuf.Pixbuf()
     733        # GdkPixbuf.Colorspace.RGB,
     734        # pixbuf.get_has_alpha(),
     735        # pixbuf.get_bits_per_sample(),
     736        # image_width, image_height
     737
     738        # import epdb; epdb.set_trace()
     739
     740        # FIXME: here is a "segmentation fault"
     741        # [humitos@michifus sugar-toolkit-gtk3]$ git grep \.fill\(
     742        # src/sugar3/graphics/colorbutton.py:        pixbuf.fill(red << 24 + green << 16 + blue << 8 + 0xff)
     743        # pixbuf2.fill(style.COLOR_PANEL_GREY.get_int())
    739744
    740745        margin_x = int((image_width - (width * scale)) / 2)
    741746        margin_y = int((image_height - (height * scale)) / 2)
    742747
    743         pixbuf.scale(pixbuf2, margin_x, margin_y, \
    744                             image_width - (margin_x * 2), \
    745                             image_height - (margin_y * 2), \
    746                             margin_x, margin_y, scale, scale, \
    747                             gtk.gdk.INTERP_BILINEAR)
     748        # pixbuf.scale(pixbuf2, margin_x, margin_y, \
     749        #                     image_width - (margin_x * 2), \
     750        #                     image_height - (margin_y * 2), \
     751        #                     margin_x, margin_y, scale, scale, \
     752        #                     GdkPixbuf.InterpType.BILINEAR)
    748753
    749754        self.image.set_from_pixbuf(pixbuf2)
    750755
    class GetIABooksActivity(activity.Activity): 
    793798                            self.source, search_text)
    794799
    795800            self.show_message(_('Performing lookup, please wait...'))
    796             self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
     801            self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
    797802            self.queryresults.connect('updated', self.__query_updated_cb)
    798803
    799804    def __query_updated_cb(self, query, midway):
    class GetIABooksActivity(activity.Activity): 
    818823                if only_english:
    819824                    self.show_message(
    820825                            _('Sorry, we only found english books.'))
    821         self.window.set_cursor(None)
     826        self.get_window().set_cursor(None)
    822827        self._allow_suspend()
    823828
    824829    def catalogs_updated(self, query, midway):
    class GetIABooksActivity(activity.Activity): 
    919924    def get_book(self):
    920925        self.enable_button(False)
    921926        self.progressbox.show_all()
    922         gobject.idle_add(self.download_book,  self.download_url)
     927        GObject.idle_add(self.download_book,  self.download_url)
    923928
    924929    def download_book(self,  url):
    925930        self._inhibit_suspend()
    class GetIABooksActivity(activity.Activity): 
    960965                          bytes_downloaded)
    961966        total = self._download_content_length
    962967        self.set_downloaded_bytes(bytes_downloaded,  total)
    963         while gtk.events_pending():
    964             gtk.main_iteration()
     968        while Gtk.events_pending():
     969            Gtk.main_iteration()
    965970
    966971    def _get_book_error_cb(self, getter, err):
    967972        self.listview.props.sensitive = True
    class GetIABooksActivity(activity.Activity): 
    10171022        textbuffer = self.textview.get_buffer()
    10181023        journal_entry.metadata['description'] = \
    10191024            textbuffer.get_text(textbuffer.get_start_iter(),
    1020                 textbuffer.get_end_iter())
     1025                                textbuffer.get_end_iter(), True)
    10211026        if self.exist_cover_image:
    10221027            image_buffer = self._get_preview_image_buffer()
    10231028            journal_entry.metadata['preview'] = dbus.ByteArray(image_buffer)
    class GetIABooksActivity(activity.Activity): 
    10461051        _stop_alert.props.title = title
    10471052        _stop_alert.props.msg = msg
    10481053        open_icon = Icon(icon_name='zoom-activity')
    1049         _stop_alert.add_button(gtk.RESPONSE_APPLY,
     1054        _stop_alert.add_button(Gtk.ResponseType.APPLY,
    10501055                                    _('Show in Journal'), open_icon)
    10511056        open_icon.show()
    10521057        ok_icon = Icon(icon_name='dialog-ok')
    1053         _stop_alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon)
     1058        _stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
    10541059        ok_icon.show()
    10551060        # Remove other alerts
    10561061        for alert in self._alerts:
    class GetIABooksActivity(activity.Activity): 
    10611066        _stop_alert.show()
    10621067
    10631068    def __stop_response_cb(self, alert, response_id):
    1064         if response_id is gtk.RESPONSE_APPLY:
     1069        if response_id is Gtk.ResponseType.APPLY:
    10651070            activity.show_object_in_journal(self._object_id)
    10661071        self.remove_alert(alert)
    10671072
    class GetIABooksActivity(activity.Activity): 
    10771082            scale_y = preview_height / float(height)
    10781083            scale = min(scale_x, scale_y)
    10791084
    1080         pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, \
     1085        pixbuf2 = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, \
    10811086                            pixbuf.get_has_alpha(), \
    10821087                            pixbuf.get_bits_per_sample(), \
    10831088                            preview_width, preview_height)
    class GetIABooksActivity(activity.Activity): 
    10901095                            preview_width - (margin_x * 2), \
    10911096                            preview_height - (margin_y * 2), \
    10921097                            margin_x, margin_y, scale, scale, \
    1093                             gtk.gdk.INTERP_BILINEAR)
     1098                            GdkPixbuf.InterpType.BILINEAR)
    10941099        preview_data = []
    10951100
    10961101        def save_func(buf, data):
    class GetIABooksActivity(activity.Activity): 
    11901195        pass
    11911196
    11921197
    1193 class ButtonWithImage(gtk.Button):
     1198class ButtonWithImage(Gtk.Button):
     1199
     1200    __gtype_name__ = 'Catalogs'
    11941201
    11951202    def __init__(self, label_text):
    1196         gtk.Button.__init__(self, _('Catalogs'))
     1203        GObject.GObject.__init__(self,)
    11971204        self.icon_move_up = Icon(icon_name='go-up')
    1198         self.remove(self.get_children()[0])
    1199         self.hbox = gtk.HBox()
     1205        # self.remove(self.get_children()[0])
     1206        self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    12001207        self.add(self.hbox)
    12011208        self.hbox.add(self.icon_move_up)
    1202         self.label = gtk.Label(label_text)
     1209        self.label = Gtk.Label(label=label_text)
    12031210        self.hbox.add(self.label)
    12041211        self.show_all()
    12051212
  • devicemanager.py

    diff --git a/devicemanager.py b/devicemanager.py
    index f673fce..7630126 100644
    a b  
    1818
    1919import os
    2020import logging
    21 import gobject
    2221import dbus
    2322
    24 UDISK_DEVICE_PATH = 'org.freedesktop.UDisks.Device'
     23from gi.repository import GObject
    2524
     25# UDISK_DEVICE_PATH = 'org.freedesktop.UDisks.Device'
    2626
    27 class DeviceManager(gobject.GObject):
     27
     28class DeviceManager(GObject.GObject):
    2829
    2930    __gsignals__ = {
    30         'device-changed': (gobject.SIGNAL_RUN_FIRST,
    31                           gobject.TYPE_NONE,
     31        'device-changed': (GObject.SignalFlags.RUN_FIRST,
     32                          None,
    3233                          ([])),
    3334    }
    3435
    3536    def __init__(self):
    36         gobject.GObject.__init__(self)
     37        GObject.GObject.__init__(self)
    3738
    3839        self._devices = {}
    3940        self._bus = dbus.SystemBus()
    class DeviceManager(gobject.GObject): 
    5960
    6061    def _get_props_from_device(self, device):
    6162        # http://hal.freedesktop.org/docs/udisks/Device.html
    62         device_obj = self._bus.get_object('org.freedesktop.UDisks', device)
    63         device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE)
    64         props = {}
    65         props['mounted'] = bool(device_props.Get(UDISK_DEVICE_PATH,
    66                 'DeviceIsMounted'))
    67         if props['mounted']:
    68             props['mount_path'] = str(device_props.Get(UDISK_DEVICE_PATH,
    69                     'DeviceMountPaths')[0])
    70             props['removable'] = bool(device_props.Get(UDISK_DEVICE_PATH,
    71                     'DriveCanDetach'))
    72             props['label'] = str(device_props.Get(UDISK_DEVICE_PATH,
    73                     'IdLabel'))
    74             props['size'] = int(device_props.Get(UDISK_DEVICE_PATH,
    75                     'DeviceSize'))
    76             return props
     63        # device_obj = self._bus.get_object('org.freedesktop.UDisks', device)
     64        # device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE)
     65        # props = {}
     66        # props['mounted'] = bool(device_props.Get(UDISK_DEVICE_PATH,
     67        #         'DeviceIsMounted'))
     68        # if props['mounted']:
     69        #     props['mount_path'] = str(device_props.Get(UDISK_DEVICE_PATH,
     70        #             'DeviceMountPaths')[0])
     71        #     props['removable'] = bool(device_props.Get(UDISK_DEVICE_PATH,
     72        #             'DriveCanDetach'))
     73        #     props['label'] = str(device_props.Get(UDISK_DEVICE_PATH,
     74        #             'IdLabel'))
     75        #     props['size'] = int(device_props.Get(UDISK_DEVICE_PATH,
     76        #             'DeviceSize'))
     77        #     return props
    7778        return None
    7879
    7980    def _have_catalog(self, props):
  • extListview.py

    diff --git a/extListview.py b/extListview.py
    index cf0b450..c1f83b8 100644
    a b  
    3434#
    3535# v1.3:
    3636#   * Greatly improved speed when sorting a lot of rows
    37 #   * Added support for gtk.CellRendererToggle
     37#   * Added support for Gtk.CellRendererToggle
    3838#   * Improved replaceContent() method
    3939#   * Added a call to set_cursor() when removing selected row(s)
    4040#   * Added getFirstSelectedRow(), appendRows(), addColumnAttribute(),
    4141#   unselectAll() and selectAll() methods
    42 #   * Set expand to False when calling pack_start()
     42#   * Set expand to False when calling pack_start(, True, True, 0)
    4343#
    4444# v1.2:
    4545#   * Fixed D'n'D reordering bugs
     
    5252#     the empty area
    5353#   * Sort indicators are now displayed whenever needed
    5454
    55 import gtk
    5655import random
     56import logging
    5757
    58 from gtk import gdk
    59 from gobject import signal_new, TYPE_INT, TYPE_STRING, TYPE_BOOLEAN, \
    60 TYPE_PYOBJECT, TYPE_NONE, SIGNAL_RUN_LAST
     58from gi.repository import Gtk
     59from gi.repository import GObject
     60from gi.repository import Gdk
    6161
    6262
    6363# Internal d'n'd (reordering)
    6464DND_REORDERING_ID = 1024
    6565DND_INTERNAL_TARGET = ('extListview-internal',
    66                         gtk.TARGET_SAME_WIDGET, DND_REORDERING_ID)
     66                        Gtk.TargetFlags.SAME_WIDGET, DND_REORDERING_ID)
    6767
    6868
    69 # Custom signals
    70 signal_new('extlistview-dnd', gtk.TreeView, SIGNAL_RUN_LAST, TYPE_NONE,
    71             (gdk.DragContext, TYPE_INT, TYPE_INT, gtk.SelectionData, TYPE_INT,
    72             TYPE_PYOBJECT))
    73 signal_new('extlistview-modified', gtk.TreeView, SIGNAL_RUN_LAST, TYPE_NONE,
    74             ())
    75 signal_new('extlistview-button-pressed', gtk.TreeView, SIGNAL_RUN_LAST,
    76             TYPE_NONE, (gdk.Event, TYPE_PYOBJECT))
    77 signal_new('extlistview-column-visibility-changed', gtk.TreeView,
    78             SIGNAL_RUN_LAST, TYPE_NONE, (TYPE_STRING, TYPE_BOOLEAN))
    79 signal_new('button-press-event', gtk.TreeViewColumn, SIGNAL_RUN_LAST,
    80             TYPE_NONE, (gdk.Event, ))
    81 
    82 
    83 class ExtListViewColumn(gtk.TreeViewColumn):
     69class ExtListViewColumn(Gtk.TreeViewColumn):
    8470    """
    8571        TreeViewColumn does not signal right-click events, and we need them
    8672        This subclass is equivalent to TreeViewColumn, but it signals these
    class ExtListViewColumn(gtk.TreeViewColumn): 
    9076        (http://www.sacredchao.net/quodlibet)
    9177    """
    9278
     79    __gsignals__ = {
     80        'button-press-event': (GObject.SignalFlags.RUN_FIRST, None,
     81                               (object,)),
     82        }
     83
    9384    def __init__(self, title=None, cell_renderer=None, **args):
    94         """ Constructor, see gtk.TreeViewColumn """
    95         gtk.TreeViewColumn.__init__(self, title, cell_renderer, **args)
    96         label = gtk.Label(title)
     85        """ Constructor, see Gtk.TreeViewColumn """
     86        GObject.GObject.__init__(self)
     87        label = Gtk.Label(label=title)
    9788        self.set_widget(label)
    9889        label.show()
    9990        label.__realize = label.connect('realize', self.onRealize)
    class ExtListViewColumn(gtk.TreeViewColumn): 
    10192    def onRealize(self, widget):
    10293        widget.disconnect(widget.__realize)
    10394        del widget.__realize
    104         button = widget.get_ancestor(gtk.Button)
     95        button = widget.get_ancestor(Gtk.Button)
    10596        if button is not None:
    10697            button.connect('button-press-event', self.onButtonPressed)
    10798
    class ExtListViewColumn(gtk.TreeViewColumn): 
    109100        self.emit('button-press-event', event)
    110101
    111102
    112 class ExtListView(gtk.TreeView):
     103class ExtListView(Gtk.TreeView):
     104
     105    __gsignals__ = {
     106        'extlistview-modified': (GObject.SignalFlags.RUN_FIRST, None,
     107                                 ()),
     108        'extlistview-button-pressed': (GObject.SignalFlags.RUN_FIRST, None,
     109                                       (object, bool)),
     110        }
    113111
    114112    def __init__(self, columns, sortable=True, dndTargets=[], useMarkup=False,
    115113            canShowHideColumns=True):
    class ExtListView(gtk.TreeView): 
    125123            If useMarkup is True, the 'markup' attributes is used instead of
    126124            'text' for CellRendererTexts
    127125        """
    128         gtk.TreeView.__init__(self)
     126        GObject.GObject.__init__(self)
    129127
    130128        self.selection = self.get_selection()
    131129
    class ExtListView(gtk.TreeView): 
    140138        self.set_rules_hint(True)
    141139        self.set_headers_visible(True)
    142140
    143         self.selection.set_mode(gtk.SELECTION_MULTIPLE)
     141        self.selection.set_mode(Gtk.SelectionMode.MULTIPLE)
    144142
    145143        # Create the columns
    146144        nbEntries = 0
    class ExtListView(gtk.TreeView): 
    152150            else:
    153151                column = ExtListViewColumn(title)
    154152                column.set_resizable(True)
    155                 #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
     153                #column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
    156154                column.set_expand(expandable)
    157155                column.set_visible(visible)
    158156                if canShowHideColumns:
    class ExtListView(gtk.TreeView): 
    169167                    nbEntries += 1
    170168                    dataTypes.append(type)
    171169                    column.pack_start(renderer, False)
    172                     if isinstance(renderer, gtk.CellRendererToggle):
     170                    if isinstance(renderer, Gtk.CellRendererToggle):
    173171                        column.add_attribute(renderer, 'active', nbEntries - 1)
    174                     elif isinstance(renderer, gtk.CellRendererPixbuf):
     172                    elif isinstance(renderer, Gtk.CellRendererPixbuf):
    175173                        column.add_attribute(renderer, 'pixbuf', nbEntries - 1)
    176                     elif isinstance(renderer, gtk.CellRendererText):
     174                    elif isinstance(renderer, Gtk.CellRendererText):
    177175                        if useMarkup:
    178176                            column.add_attribute(renderer, 'markup',
    179177                                nbEntries - 1)
    class ExtListView(gtk.TreeView): 
    184182        # Mark management
    185183        self.markedRow = None
    186184        self.markColumn = len(dataTypes)
    187         dataTypes.append(TYPE_BOOLEAN)  # When there's no other solution,
    188                                         # this additional entry helps in
    189                                         # finding the marked row
     185        dataTypes.append(bool)  # When there's no other solution,
     186                                # this additional entry helps in
     187                                # finding the marked row
    190188
    191189        # Create the ListStore associated with this tree
    192         self.store = gtk.ListStore(*dataTypes)
     190        self.store = Gtk.ListStore(*dataTypes)
    193191        self.set_model(self.store)
    194192
    195193        # Drag'n'drop management
    class ExtListView(gtk.TreeView): 
    200198        self.dndReordering = False
    201199
    202200        if len(dndTargets) != 0:
    203             self.enable_model_drag_dest(dndTargets, gdk.ACTION_DEFAULT)
     201            self.enable_model_drag_dest(dndTargets, Gdk.DragAction.DEFAULT)
    204202
    205203        self.connect('drag-begin', self.onDragBegin)
    206204        self.connect('drag-motion', self.onDragMotion)
    class ExtListView(gtk.TreeView): 
    314312        criteria = self.sortColCriteria[column]
    315313        rows.sort(lambda r1, r2: \
    316314                self.__cmpRows(r1, r2, criteria, self.sortAscending))
     315        # FIXME: AttributeError: 'ListStore' object has no attribute 'reorder'
    317316        self.store.reorder([r[-1] for r in rows])
    318317
    319318        # Move the mark if needed
    class ExtListView(gtk.TreeView): 
    322321
    323322        column.set_sort_indicator(True)
    324323        if self.sortAscending:
    325             column.set_sort_order(gtk.SORT_ASCENDING)
     324            column.set_sort_order(Gtk.SortType.ASCENDING)
    326325        else:
    327             column.set_sort_order(gtk.SORT_DESCENDING)
     326            column.set_sort_order(Gtk.SortType.DESCENDING)
    328327
    329328        self.emit('extlistview-modified')
    330329
    class ExtListView(gtk.TreeView): 
    461460        self.freeze_child_notify()
    462461        if position is None:
    463462            for row in rows:
     463                # FIXME: I had to remove an element from the row (False)
     464                logging.debug('ROW: %s', row)
    464465                self.store.append(row)
    465466        else:
    466467            for row in rows:
    class ExtListView(gtk.TreeView): 
    502503        """ Enable the use of Drag'n'Drop to reorder the list """
    503504        self.dndReordering = True
    504505        self.dndTargets.append(DND_INTERNAL_TARGET)
    505         self.enable_model_drag_dest(self.dndTargets, gdk.ACTION_DEFAULT)
     506        self.enable_model_drag_dest(self.dndTargets, Gdk.DragAction.DEFAULT)
    506507
    507508    def __isDropAfter(self, pos):
    508         """ Helper function, True if pos is gtk.TREE_VIEW_DROP_AFTER or
    509             gtk.TREE_VIEW_DROP_INTO_OR_AFTER """
    510         return pos == gtk.TREE_VIEW_DROP_AFTER or \
    511                 pos == gtk.TREE_VIEW_DROP_INTO_OR_AFTER
     509        """ Helper function, True if pos is Gtk.TreeViewDropPosition.AFTER or
     510            Gtk.TreeViewDropPosition.INTO_OR_AFTER """
     511        return pos == Gtk.TreeViewDropPosition.AFTER or \
     512                pos == Gtk.TreeViewDropPosition.INTO_OR_AFTER
    512513
    513514    def __moveSelectedRows(self, x, y):
    514515        """ Internal function used for drag'n'drop """
    class ExtListView(gtk.TreeView): 
    516517        dropInfo = self.get_dest_row_at_pos(int(x), int(y))
    517518
    518519        if dropInfo is None:
    519             pos, path = gtk.TREE_VIEW_DROP_INTO_OR_AFTER, len(self.store) - 1
     520            pos, path = Gtk.TreeViewDropPosition.INTO_OR_AFTER, len(self.store) - 1
    520521        else:
    521522            pos, path = dropInfo[1], dropInfo[0][0]
    522523            if self.__isDropAfter(pos) and path < len(self.store) - 1:
    523                 pos = gtk.TREE_VIEW_DROP_INTO_OR_BEFORE
     524                pos = Gtk.TreeViewDropPosition.INTO_OR_BEFORE
    524525                path += 1
    525526
    526527        self.freeze_child_notify()
    class ExtListView(gtk.TreeView): 
    573574                if self.dndReordering and self.motionEvtId is None \
    574575                    and event.button == 1:
    575576                    self.dndStartPos = (int(event.x), int(event.y))
    576                     self.motionEvtId = gtk.TreeView.connect(self, \
     577                    self.motionEvtId = Gtk.TreeView.connect(self, \
    577578                            'motion-notify-event', self.onMouseMotion)
    578579
    579                 stateClear = not (event.state & \
    580                             (gdk.SHIFT_MASK | gdk.CONTROL_MASK))
     580                stateClear = not (event.get_state() & \
     581                                      (Gdk.ModifierType.SHIFT_MASK |
     582                                       Gdk.ModifierType.CONTROL_MASK))
    581583
    582584                if stateClear and not self.selection.path_is_selected(path):
    583585                    self.selection.unselect_all()
    class ExtListView(gtk.TreeView): 
    586588                    retVal = (stateClear and self.getSelectedRowsCount() > 1 \
    587589                            and self.selection.path_is_selected(path))
    588590
     591        logging.debug('TYPE: %s', type(event))
     592        # FIXME: I'm getting this error:
     593        # TypeError: could not convert type EventButton to GdkEvent
     594        # required for parameter 0
    589595        self.emit('extlistview-button-pressed', event, path)
    590596
    591597        return retVal
    class ExtListView(gtk.TreeView): 
    599605
    600606            if len(self.dndTargets) != 0:
    601607                self.enable_model_drag_dest(self.dndTargets,
    602                     gdk.ACTION_DEFAULT)
     608                    Gdk.DragAction.DEFAULT)
    603609
    604         stateClear = not (event.state & (gdk.SHIFT_MASK | gdk.CONTROL_MASK))
     610        stateClear = not (event.get_state() & \
     611                              (Gdk.ModifierType.SHIFT_MASK |
     612                               Gdk.ModifierType.CONTROL_MASK))
    605613
    606         if stateClear and event.state & gdk.BUTTON1_MASK \
     614        if stateClear and event.get_state() & Gdk.ModifierType.BUTTON1_MASK \
    607615            and self.getSelectedRowsCount() > 1:
    608616            pathInfo = self.get_path_at_pos(int(event.x), int(event.y))
    609617            if pathInfo is not None:
    class ExtListView(gtk.TreeView): 
    616624            self.drag_check_threshold(self.dndStartPos[0], self.dndStartPos[1],
    617625            int(event.x), int(event.y)):
    618626            self.dndContext = self.drag_begin([DND_INTERNAL_TARGET],
    619                     gdk.ACTION_COPY, 1, event)
     627                    Gdk.DragAction.COPY, 1, event)
    620628
    621629    def onDragBegin(self, tree, context):
    622630        """ A drag'n'drop operation has begun """
    623631        if self.getSelectedRowsCount() == 1:
    624             context.set_icon_stock(gtk.STOCK_DND, 0, 0)
     632            context.set_icon_stock(Gtk.STOCK_DND, 0, 0)
    625633        else:
    626             context.set_icon_stock(gtk.STOCK_DND_MULTIPLE, 0, 0)
     634            context.set_icon_stock(Gtk.STOCK_DND_MULTIPLE, 0, 0)
    627635
    628636    def onDragDataReceived(self, tree, context, x, y, selection, dndId, time):
    629637        """ Some data has been dropped into the list """
    class ExtListView(gtk.TreeView): 
    639647        drop = self.get_dest_row_at_pos(int(x), int(y))
    640648
    641649        if drop is not None and \
    642             (drop[1] == gtk.TREE_VIEW_DROP_INTO_OR_AFTER or \
    643             drop[1] == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
     650            (drop[1] == Gtk.TreeViewDropPosition.INTO_OR_AFTER or \
     651            drop[1] == Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
    644652            self.enable_model_drag_dest([('invalid-position', 0, -1)],
    645                     gdk.ACTION_DEFAULT)
     653                    Gdk.DragAction.DEFAULT)
    646654        else:
    647             self.enable_model_drag_dest(self.dndTargets, gdk.ACTION_DEFAULT)
     655            self.enable_model_drag_dest(self.dndTargets,
     656                                        Gdk.DragAction.DEFAULT)
    648657
    649658    def onColumnHeaderClicked(self, column, event):
    650659        """ A column header has been clicked """
     660        logging.debug('CLICK: %s', event.button)
     661
    651662        if event.button == 3:
    652663            # Create a menu with a CheckMenuItem per column
    653             menu = gtk.Menu()
     664            menu = Gtk.Menu()
    654665            nbVisibleItems = 0
    655666            lastVisibleItem = None
    656667            for column in self.get_columns():
    657                 item = gtk.CheckMenuItem(column.get_title())
     668                item = Gtk.CheckMenuItem(column.get_title())
    658669                item.set_active(column.get_visible())
    659670                item.connect('toggled', self.onShowHideColumn, column)
    660671                item.show()
    class ExtListView(gtk.TreeView): 
    669680            if nbVisibleItems == 1:
    670681                lastVisibleItem.set_sensitive(False)
    671682
    672             menu.popup(None, None, None, event.button, event.get_time())
     683            logging.debug('CLICK')
     684
     685            # README: a new argument is needed
     686            # http://developer.gnome.org/gtk3/3.5/GtkMenu.html#gtk-menu-popup
     687            menu.popup(None, None, None, None, event.button, event.get_time())
     688
     689            # FIXME: for some reason this menu.popup call is not
     690            # showing the popup
    673691
    674692    def onShowHideColumn(self, menuItem, column):
    675693        """ Switch the visibility of the given column """
    676694        column.set_visible(not column.get_visible())
     695        logging.debug('CALL: onShowHideColumn')
    677696        self.emit('extlistview-column-visibility-changed', \
    678697                column.get_title(), column.get_visible())
  • get-books.cfg

    diff --git a/get-books.cfg b/get-books.cfg
    index dd07716..e340855 100644
    a b  
    11[GetBooks]
    2 show_images = yes
     2show_images = no
    33languages = en,es,fr,de
    44
    55[Feedbooks]
  • listview.py

    diff --git a/listview.py b/listview.py
    index 7a1769a..f170b55 100644
    a b  
    1616# along with this program; if not, write to the Free Software
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1818
    19 import gobject
    20 import gtk
    21 import pango
    2219import sys
    23 from gettext import gettext as _
    2420import logging
    2521
     22from gi.repository import GObject
     23from gi.repository import Gtk
     24from gi.repository import Pango
     25
     26from gettext import gettext as _
    2627from extListview import ExtListView
    2728
    2829_logger = logging.getLogger('get-ia-books-activity')
    2930
    3031
    3132class ListView(ExtListView):
    32     __txtRdr = gtk.CellRendererText()
    33     __txtRdr.props.wrap_mode = pango.WRAP_WORD
     33    __txtRdr = Gtk.CellRendererText()
     34    __txtRdr.props.wrap_mode = Pango.WrapMode.WORD
    3435    __txtRdr.props.wrap_width = 500
    3536    __txtRdr.props.width = 500
    3637    (ROW_TITLE, ROW_AUTHOR, ROW_PUBLISHER,
    3738    ROW_LANGUAGE, ROW_PUB_DATE, ROW_BOOK) = range(6)
    3839
    39     columns = ((_('Title'), [(__txtRdr, gobject.TYPE_STRING)],
     40    columns = ((_('Title'), [(__txtRdr, GObject.TYPE_STRING)],
    4041                    (ROW_TITLE,), False, True),
    41                (_('Author'), [(__txtRdr, gobject.TYPE_STRING)],
     42               (_('Author'), [(__txtRdr, GObject.TYPE_STRING)],
    4243                    (ROW_AUTHOR, ROW_TITLE), False,  True),
    43                (_('Publisher'), [(__txtRdr, gobject.TYPE_STRING)],
     44               (_('Publisher'), [(__txtRdr, GObject.TYPE_STRING)],
    4445                    (ROW_AUTHOR, ROW_TITLE), False,  False),
    45                (_('Language'), [(__txtRdr, gobject.TYPE_STRING)],
     46               (_('Language'), [(__txtRdr, GObject.TYPE_STRING)],
    4647                    (ROW_AUTHOR, ROW_TITLE), False,  False),
    47                (_('Publish Date'), [(__txtRdr, gobject.TYPE_STRING)],
     48               (_('Publish Date'), [(__txtRdr, GObject.TYPE_STRING)],
    4849                    (ROW_AUTHOR, ROW_TITLE), False,  False),
    49                (None, [(None, gobject.TYPE_PYOBJECT)], (None,), False, False))
     50               (None, [(None, GObject.TYPE_PYOBJECT)], (None,), False, False))
     51
    5052    __gsignals__ = {
    51         'selection-changed': (gobject.SIGNAL_RUN_FIRST,
    52                           gobject.TYPE_NONE,
    53                           ([])),
    54     }
     53        'selection-changed': (GObject.SignalFlags.RUN_FIRST,
     54                              None,
     55                              ([])),
     56        }
    5557
    5658    def __init__(self, lang_code_handler):
    5759        ExtListView.__init__(self, self.columns, sortable=True,
    58                 useMarkup=False, canShowHideColumns=True)
     60                             useMarkup=False, canShowHideColumns=True)
    5961        #self.enableDNDReordering() # Is this needed ?
    6062
    6163        self._lang_code_handler = lang_code_handler
    6264
    6365        selection = self.get_selection()
    64         selection.set_mode(gtk.SELECTION_SINGLE)
     66        selection.set_mode(Gtk.SelectionMode.SINGLE)
    6567        selection.connect("changed", self.__selection_changed_cb)
    6668
    6769    def __selection_changed_cb(self, selection):
    class ListView(ExtListView): 
    9496        try:
    9597            ret = self.getFirstSelectedRow()[self.ROW_BOOK]
    9698        except IndexError:
     99            logging.debug('self.getFirstSelectedRow: %s',
     100                          self.getFirstSelectedRow())
    97101            ret = None
    98102        return ret
  • opds.py

    diff --git a/opds.py b/opds.py
    index fc536f3..aad9919 100644
    a b  
    1616# along with this program; if not, write to the Free Software
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1818
    19 import logging
     19from gi.repository import GObject
     20from gi.repository import Gtk
     21
     22from sugar3 import network
    2023
     24import logging
    2125import threading
    2226import os
    2327import urllib
    24 import gobject
    25 import gtk
    2628import time
    2729import csv
    2830
    29 from sugar import network
    30 
    3131import sys
    3232sys.path.insert(0, './')
    3333import feedparser
    _REL_SUBSECTION = 'subsection' 
    3939_REL_OPDS_POPULAR = u'http://opds-spec.org/sort/popular'
    4040_REL_OPDS_NEW = u'http://opds-spec.org/sort/new'
    4141
    42 gobject.threads_init()
     42GObject.threads_init()
    4343
    4444
    4545class ReadURLDownloader(network.GlibURLDownloader):
    class DownloadThread(threading.Thread): 
    100100
    101101        self.obj._feedobj = feedobj
    102102        self.obj._ready = True
    103         gobject.idle_add(self.obj.notify_updated, self.midway)
     103        GObject.idle_add(self.obj.notify_updated, self.midway)
    104104        return False
    105105
    106106    def run(self):
    class Book(object): 
    222222        return False
    223223
    224224
    225 class QueryResult(gobject.GObject):
     225class QueryResult(GObject.GObject):
    226226
    227227    __gsignals__ = {
    228         'updated': (gobject.SIGNAL_RUN_FIRST,
    229                           gobject.TYPE_NONE,
    230                           ([gobject.TYPE_BOOLEAN])),
     228        'updated': (GObject.SignalFlags.RUN_FIRST,
     229                          None,
     230                          ([GObject.TYPE_BOOLEAN])),
    231231    }
    232232
    233233    def __init__(self, configuration, queryterm, language):
    234         gobject.GObject.__init__(self)
     234        GObject.GObject.__init__(self)
    235235        self._configuration = configuration
    236236        self._uri = self._configuration['query_uri']
    237237        self._queryterm = queryterm
    class DownloadIAThread(threading.Thread): 
    369369        self._download_content_type = None
    370370        self._booklist = []
    371371        queryterm = self.obj._queryterm
    372         search_tuple = queryterm.lower().split()
     372        # search_tuple = queryterm.lower().split()
    373373        FL = urllib.quote('fl[]')
    374374        SORT = urllib.quote('sort[]')
    375375        self.search_url = 'http://www.archive.org/advancedsearch.php?q=' +  \
    class DownloadIAThread(threading.Thread): 
    384384        self.stopthread = threading.Event()
    385385
    386386    def _download(self):
    387         gobject.idle_add(self.download_csv, self.search_url)
     387        GObject.idle_add(self.download_csv, self.search_url)
    388388
    389389    def download_csv(self, url):
    390390        logging.error('get csv from %s', url)
    class DownloadIAThread(threading.Thread): 
    461461            self.obj._booklist.append(IABook(None, entry, ''))
    462462
    463463        os.remove(tempfile)
    464         gobject.idle_add(self.obj.notify_updated, self.midway)
     464        GObject.idle_add(self.obj.notify_updated, self.midway)
    465465        self.obj._ready = True
    466466        return False
    467467
    class InternetArchiveQueryResult(QueryResult): 
    478478    # because the server implementation is not working very well
    479479
    480480    def __init__(self, queryterm, language, activity):
    481         gobject.GObject.__init__(self)
     481        GObject.GObject.__init__(self)
    482482        self._activity = activity
    483483        self._queryterm = queryterm
    484484        self._language = language
    class ImageDownloaderThread(threading.Thread): 
    519519            self._getter.start(path)
    520520        except:
    521521            _logger.debug("Connection timed out for")
    522             gobject.idle_add(self.obj.notify_updated, None)
     522            GObject.idle_add(self.obj.notify_updated, None)
    523523
    524524        self._download_content_length = \
    525525                self._getter.get_content_length()
    class ImageDownloaderThread(threading.Thread): 
    529529        _logger.debug("Got Cover Image %s (%s)", tempfile, suggested_name)
    530530        self._getter = None
    531531        if not self.stopthread.is_set():
    532             gobject.idle_add(self.obj.notify_updated, tempfile)
     532            GObject.idle_add(self.obj.notify_updated, tempfile)
    533533
    534534    def _get_image_progress_cb(self, getter, bytes_downloaded):
    535535        if self.stopthread.is_set():
    class ImageDownloaderThread(threading.Thread): 
    545545        else:
    546546            _logger.debug("Downloaded %u bytes...",
    547547                          bytes_downloaded)
    548         while gtk.events_pending():
    549             gtk.main_iteration()
     548        while Gtk.events_pending():
     549            Gtk.main_iteration()
    550550
    551551    def _get_image_error_cb(self, getter, err):
    552552        _logger.debug("Error getting image: %s", err)
    553553        self._download_content_length = 0
    554554        self._download_content_type = None
    555555        self._getter = None
    556         gobject.idle_add(self.obj.notify_updated, None)
     556        GObject.idle_add(self.obj.notify_updated, None)
    557557
    558558    def run(self):
    559559        self._download_image()
    class ImageDownloaderThread(threading.Thread): 
    562562        self.stopthread.set()
    563563
    564564
    565 class ImageDownloader(gobject.GObject):
     565class ImageDownloader(GObject.GObject):
    566566
    567567    __gsignals__ = {
    568         'updated': (gobject.SIGNAL_RUN_FIRST,
    569                           gobject.TYPE_NONE,
    570                           ([gobject.TYPE_STRING])),
     568        'updated': (GObject.SignalFlags.RUN_FIRST,
     569                          None,
     570                          ([GObject.TYPE_STRING])),
    571571    }
    572572
    573573    def __init__(self, activity, url):
    574         gobject.GObject.__init__(self)
     574        GObject.GObject.__init__(self)
    575575        self.threads = []
    576576        self._activity = activity
    577577        self._url = url
  • setup.py

    diff --git a/setup.py b/setup.py
    index d3ab3a3..2f2c143 100755
    a b  
    1616# along with this program; if not, write to the Free Software
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1818
    19 from sugar.activity import bundlebuilder
     19from sugar3.activity import bundlebuilder
    2020
    2121bundlebuilder.start()