def __init__(self, library): super(_BookArea, self).__init__() self._library = library self._cache = get_pixbuf_cache() self._library.backend.book_added_to_collection += self._new_book_added self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) # Store Cover, book ID, book path, book size, date added to library, # is thumbnail loaded? # The SORT_ constants must correspond to the correct column here, # i.e. SORT_SIZE must be 3, since 3 is the size column in the ListStore. self._liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_INT, GObject.TYPE_STRING, GObject.TYPE_INT64, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN) self._liststore.set_sort_func(constants.SORT_NAME, self._sort_by_name, None) self._liststore.set_sort_func(constants.SORT_PATH, self._sort_by_path, None) self.set_sort_order() self._iconview = thumbnail_view.ThumbnailIconView( self._liststore, 1, # UID 0, # pixbuf 5, # status ) self._iconview.generate_thumbnail = self._get_pixbuf self._iconview.connect('item_activated', self._book_activated) self._iconview.connect('selection_changed', self._selection_changed) self._iconview.connect_after('drag_begin', self._drag_begin) self._iconview.connect('drag_data_get', self._drag_data_get) self._iconview.connect('drag_data_received', self._drag_data_received) self._iconview.connect('button_press_event', self._button_press) self._iconview.connect('key_press_event', self._key_press) self._iconview.connect('popup_menu', self._popup_menu) self._iconview.enable_model_drag_source( Gdk.ModifierType.BUTTON1_MASK, [ Gtk.TargetEntry.new('book', Gtk.TargetFlags.SAME_APP, constants.LIBRARY_DRAG_EXTERNAL_ID) ], Gdk.DragAction.MOVE) self._iconview.drag_dest_set(Gtk.DestDefaults.ALL, [ Gtk.TargetEntry.new('text/uri-list', 0, constants.LIBRARY_DRAG_EXTERNAL_ID) ], Gdk.DragAction.COPY | Gdk.DragAction.MOVE) self._iconview.set_selection_mode(Gtk.SelectionMode.MULTIPLE) self.add(self._iconview) self._iconview.set_margin(0) self._iconview.set_row_spacing(0) self._iconview.set_column_spacing(0) self._ui_manager = Gtk.UIManager() self._tooltipstatus = status.TooltipStatusHelper( self._ui_manager, self._library.get_status_bar()) ui_description = ''' <ui> <popup name="library books"> <menuitem action="_title" /> <separator /> <menuitem action="open" /> <menuitem action="open keep library" /> <separator /> <menuitem action="add" /> <separator /> <menuitem action="remove from collection" /> <menuitem action="remove from library" /> <separator /> <menuitem action="copy path to clipboard" /> <menuitem action="copy cover to clipboard" /> <separator /> <menu action="sort"> <menuitem action="by name" /> <menuitem action="by path" /> <menuitem action="by size" /> <menuitem action="by date added" /> <separator /> <menuitem action="ascending" /> <menuitem action="descending" /> </menu> <menu action="cover size"> <menuitem action="huge" /> <menuitem action="large" /> <menuitem action="normal" /> <menuitem action="small" /> <menuitem action="tiny" /> <separator /> <menuitem action="custom" /> </menu> </popup> </ui> ''' self._ui_manager.add_ui_from_string(ui_description) actiongroup = Gtk.ActionGroup(name='mcomix-library-book-area') # General book actions actiongroup.add_actions([ ('_title', None, _('Library books'), None, None, None), ('open', Gtk.STOCK_OPEN, _('_Open'), None, _('Opens the selected books for viewing.'), self.open_selected_book), ('open keep library', Gtk.STOCK_OPEN, _('Open _without closing library'), None, _('Opens the selected books, but keeps the library window open.'), self.open_selected_book_noclose), ('add', Gtk.STOCK_ADD, _('_Add...'), '<Ctrl><Shift>a', _('Add more books to the library.'), lambda *args: file_chooser_library_dialog. open_library_filechooser_dialog(self._library)), ('remove from collection', Gtk.STOCK_REMOVE, _('Remove from this _collection'), None, _('Removes the selected books from the current collection.'), self._remove_books_from_collection), ('remove from library', Gtk.STOCK_REMOVE, _('Remove from the _library'), None, _('Removes the selected books from the library.'), self._remove_books_from_library), ('copy path to clipboard', Gtk.STOCK_COPY, _('_Copy'), None, _('Copies the selected book\'s path to clipboard.'), self._copy_selected_path), ('copy cover to clipboard', '', _('_Copy Cover'), None, _('Copies the selected book\'s cover to clipboard.'), self._copy_selected_cover), ('sort', None, _('_Sort'), None, _('Changes the sort order of the library.'), None), ('cover size', None, _('Cover si_ze'), None, _('Changes the book cover size.'), None) ]) # Sorting the view actiongroup.add_radio_actions([ ('by name', None, _('Book name'), None, None, constants.SORT_NAME), ('by path', None, _('Full path'), None, None, constants.SORT_PATH), ('by size', None, _('File size'), None, None, constants.SORT_SIZE), ('by date added', None, _('Date added'), None, None, constants.SORT_LAST_MODIFIED) ], prefs['lib sort key'], self._sort_changed) actiongroup.add_radio_actions( [('ascending', Gtk.STOCK_SORT_ASCENDING, _('Ascending'), None, None, constants.SORT_ASCENDING), ('descending', Gtk.STOCK_SORT_DESCENDING, _('Descending'), None, None, constants.SORT_DESCENDING)], prefs['lib sort order'], self._sort_changed) # Library cover size actiongroup.add_radio_actions( [('huge', None, _('Huge') + ' (%dpx)' % constants.SIZE_HUGE, None, None, constants.SIZE_HUGE), ('large', None, _('Large') + ' (%dpx)' % constants.SIZE_LARGE, None, None, constants.SIZE_LARGE), ('normal', None, _('Normal') + ' (%dpx)' % constants.SIZE_NORMAL, None, None, constants.SIZE_NORMAL), ('small', None, _('Small') + ' (%dpx)' % constants.SIZE_SMALL, None, None, constants.SIZE_SMALL), ('tiny', None, _('Tiny') + ' (%dpx)' % constants.SIZE_TINY, None, None, constants.SIZE_TINY), ('custom', None, _('Custom...'), None, None, 0)], prefs['library cover size'] if prefs['library cover size'] in (constants.SIZE_HUGE, constants.SIZE_LARGE, constants.SIZE_NORMAL, constants.SIZE_SMALL, constants.SIZE_TINY) else 0, self._book_size_changed) self._ui_manager.insert_action_group(actiongroup, 0) library.add_accel_group(self._ui_manager.get_accel_group())
def __init__(self, library): super(_BookArea, self).__init__() self._library = library self._cache = get_pixbuf_cache() self._library.backend.book_added_to_collection += self._new_book_added self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) # Store Cover, book ID, book path, book size, date added to library, # is thumbnail loaded? # The SORT_ constants must correspond to the correct column here, # i.e. SORT_SIZE must be 3, since 3 is the size column in the ListStore. self._liststore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT64, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN) self._liststore.set_sort_func(constants.SORT_NAME, self._sort_by_name, None) self._liststore.set_sort_func(constants.SORT_PATH, self._sort_by_path, None) self.set_sort_order() self._liststore.connect('row-inserted', self._icon_added) self._iconview = thumbnail_view.ThumbnailIconView( self._liststore, 1, # UID 0, # pixbuf 5, # status ) self._iconview.generate_thumbnail = self._get_pixbuf self._iconview.connect('item_activated', self._book_activated) self._iconview.connect('selection_changed', self._selection_changed) self._iconview.connect_after('drag_begin', self._drag_begin) self._iconview.connect('drag_data_get', self._drag_data_get) self._iconview.connect('drag_data_received', self._drag_data_received) self._iconview.connect('button_press_event', self._button_press) self._iconview.connect('key_press_event', self._key_press) self._iconview.connect('popup_menu', self._popup_menu) self._iconview.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color()) # Black. self._iconview.enable_model_drag_source(0, [('book', gtk.TARGET_SAME_APP, constants.LIBRARY_DRAG_EXTERNAL_ID)], gtk.gdk.ACTION_MOVE) self._iconview.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, constants.LIBRARY_DRAG_EXTERNAL_ID)], gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) self._iconview.set_selection_mode(gtk.SELECTION_MULTIPLE) self.add(self._iconview) self._iconview.set_margin(0) self._iconview.set_row_spacing(0) self._iconview.set_column_spacing(0) self._ui_manager = gtk.UIManager() self._tooltipstatus = status.TooltipStatusHelper(self._ui_manager, self._library.get_status_bar()) ui_description = """ <ui> <popup name="library books"> <menuitem action="_title" /> <separator /> <menuitem action="open" /> <menuitem action="open keep library" /> <separator /> <menuitem action="add" /> <separator /> <menuitem action="remove from collection" /> <menuitem action="remove from library" /> <menuitem action="completely remove" /> <separator /> <menuitem action="copy to clipboard" /> <separator /> <menu action="sort"> <menuitem action="by name" /> <menuitem action="by path" /> <menuitem action="by size" /> <menuitem action="by date added" /> <separator /> <menuitem action="ascending" /> <menuitem action="descending" /> </menu> <menu action="cover size"> <menuitem action="huge" /> <menuitem action="large" /> <menuitem action="normal" /> <menuitem action="small" /> <menuitem action="tiny" /> <separator /> <menuitem action="custom" /> </menu> </popup> </ui> """ self._ui_manager.add_ui_from_string(ui_description) actiongroup = gtk.ActionGroup('mcomix-library-book-area') # General book actions actiongroup.add_actions([ ('_title', None, _('Library books'), None, None, None), ('open', gtk.STOCK_OPEN, _('_Open'), None, _('Opens the selected books for viewing.'), self.open_selected_book), ('open keep library', gtk.STOCK_OPEN, _('Open _without closing library'), None, _('Opens the selected books, but keeps the library window open.'), self.open_selected_book_noclose), ('add', gtk.STOCK_ADD, _('_Add...'), '<Ctrl><Shift>a', _('Add more books to the library.'), lambda *args: file_chooser_library_dialog.open_library_filechooser_dialog(self._library)), ('remove from collection', gtk.STOCK_REMOVE, _('Remove from this _collection'), None, _('Removes the selected books from the current collection.'), self._remove_books_from_collection), ('remove from library', gtk.STOCK_REMOVE, _('Remove from the _library'), None, _('Completely removes the selected books from the library.'), self._remove_books_from_library), ('completely remove', gtk.STOCK_DELETE, _('_Remove and delete from disk'), None, _('Deletes the selected books from disk.'), self._completely_remove_book), ('copy to clipboard', gtk.STOCK_COPY, _('_Copy'), None, _('Copies the selected book\'s path to clipboard.'), self._copy_selected), ('sort', None, _('_Sort'), None, _('Changes the sort order of the library.'), None), ('cover size', None, _('Cover si_ze'), None, _('Changes the book cover size.'), None) ]) # Sorting the view actiongroup.add_radio_actions([ ('by name', None, _('Book name'), None, None, constants.SORT_NAME), ('by path', None, _('Full path'), None, None, constants.SORT_PATH), ('by size', None, _('File size'), None, None, constants.SORT_SIZE), ('by date added', None, _('Date added'), None, None, constants.SORT_LAST_MODIFIED)], prefs['lib sort key'], self._sort_changed) actiongroup.add_radio_actions([ ('ascending', gtk.STOCK_SORT_ASCENDING, _('Ascending'), None, None, constants.SORT_ASCENDING), ('descending', gtk.STOCK_SORT_DESCENDING, _('Descending'), None, None, constants.SORT_DESCENDING)], prefs['lib sort order'], self._sort_changed) # Library cover size actiongroup.add_radio_actions([ ('huge', None, _('Huge') + ' (%dpx)' % constants.SIZE_HUGE, None, None, constants.SIZE_HUGE), ('large', None, _('Large') + ' (%dpx)' % constants.SIZE_LARGE, None, None, constants.SIZE_LARGE), ('normal', None, _('Normal') + ' (%dpx)' % constants.SIZE_NORMAL, None, None, constants.SIZE_NORMAL), ('small', None, _('Small') + ' (%dpx)' % constants.SIZE_SMALL, None, None, constants.SIZE_SMALL), ('tiny', None, _('Tiny') + ' (%dpx)' % constants.SIZE_TINY, None, None, constants.SIZE_TINY), ('custom', None, _('Custom...'), None, None, 0)], prefs['library cover size'] if prefs['library cover size'] in (constants.SIZE_HUGE, constants.SIZE_LARGE, constants.SIZE_NORMAL, constants.SIZE_SMALL, constants.SIZE_TINY) else 0, self._book_size_changed) self._ui_manager.insert_action_group(actiongroup, 0) library.add_accel_group(self._ui_manager.get_accel_group())
def __init__(self, library): gtk.ScrolledWindow.__init__(self) self._library = library self._cache = get_pixbuf_cache() self._stop_update = False self._thumbnail_threads = None self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) # Store Cover, book ID, book path, book size # The SORT_ constants must correspond to the correct column here, # i.e. SORT_SIZE must be 3, since 3 is the size column in the ListStore. self._liststore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT64) self._liststore.set_sort_func(constants.SORT_NAME, self._sort_by_name, None) self._iconview = gtk.IconView(self._liststore) self._iconview.set_pixbuf_column(0) self._iconview.connect('item_activated', self._book_activated) self._iconview.connect('selection_changed', self._selection_changed) self._iconview.connect_after('drag_begin', self._drag_begin) self._iconview.connect('drag_data_get', self._drag_data_get) self._iconview.connect('drag_data_received', self._drag_data_received) self._iconview.connect('button_press_event', self._button_press) self._iconview.connect('key_press_event', self._key_press) self._iconview.connect('popup_menu', self._popup_menu) self._iconview.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color()) # Black. self._iconview.enable_model_drag_source(0, [ ('book', gtk.TARGET_SAME_APP, constants.LIBRARY_DRAG_EXTERNAL_ID) ], gtk.gdk.ACTION_MOVE) self._iconview.drag_dest_set( gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, constants.LIBRARY_DRAG_EXTERNAL_ID)], gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) self._iconview.set_selection_mode(gtk.SELECTION_MULTIPLE) self.add(self._iconview) self._ui_manager = gtk.UIManager() self._tooltipstatus = status.TooltipStatusHelper( self._ui_manager, self._library.get_status_bar()) ui_description = """ <ui> <popup name="library books"> <menuitem action="_title" /> <separator /> <menuitem action="open" /> <menuitem action="open keep library" /> <separator /> <menuitem action="add" /> <separator /> <menuitem action="remove from collection" /> <menuitem action="remove from library" /> <menuitem action="completely remove" /> <separator /> <menu action="sort"> <menuitem action="by name" /> <menuitem action="by path" /> <menuitem action="by size" /> <separator /> <menuitem action="ascending" /> <menuitem action="descending" /> </menu> <menu action="cover size"> <menuitem action="huge" /> <menuitem action="large" /> <menuitem action="normal" /> <menuitem action="small" /> <menuitem action="tiny" /> <separator /> <menuitem action="custom" /> </menu> </popup> </ui> """ self._ui_manager.add_ui_from_string(ui_description) actiongroup = gtk.ActionGroup('mcomix-library-book-area') # General book actions actiongroup.add_actions([ ('_title', None, _('Library books'), None, None, None), ('open', gtk.STOCK_OPEN, _('_Open'), None, _('Opens the selected books for viewing.'), self.open_selected_book), ('open keep library', gtk.STOCK_OPEN, _('Open _without closing library'), None, _('Opens the selected books, but keeps the library window open.'), self.open_selected_book_noclose), ('add', gtk.STOCK_ADD, _('_Add...'), '<Ctrl><Shift>a', _('Add more books to the library.'), lambda *args: file_chooser_library_dialog. open_library_filechooser_dialog(self._library)), ('remove from collection', gtk.STOCK_REMOVE, _('Remove from this _collection'), None, _('Removes the selected books from the current collection.'), self._remove_books_from_collection), ('remove from library', gtk.STOCK_REMOVE, _('Remove from the _library'), None, _('Completely removes the selected books from the library.'), self._remove_books_from_library), ('completely remove', gtk.STOCK_DELETE, _('_Remove and delete from disk'), None, _('Deletes the selected books from disk.'), self._completely_remove_book), ('sort', None, _('_Sort'), None, _('Changes the sort order of the library.'), None), ('cover size', None, _('Cover si_ze'), None, _('Changes the book cover size.'), None) ]) # Sorting the view actiongroup.add_radio_actions([ ('by name', None, _('Book name'), None, None, constants.SORT_NAME), ('by path', None, _('Full path'), None, None, constants.SORT_PATH), ('by size', None, _('File size'), None, None, constants.SORT_SIZE) ], prefs['lib sort key'], self._sort_changed) actiongroup.add_radio_actions( [('ascending', gtk.STOCK_SORT_ASCENDING, _('Ascending'), None, None, constants.SORT_ASCENDING), ('descending', gtk.STOCK_SORT_DESCENDING, _('Descending'), None, None, constants.SORT_DESCENDING)], prefs['lib sort order'], self._sort_changed) # Library cover size actiongroup.add_radio_actions( [('huge', None, _('Huge') + ' (%dpx)' % constants.SIZE_HUGE, None, None, constants.SIZE_HUGE), ('large', None, _('Large') + ' (%dpx)' % constants.SIZE_LARGE, None, None, constants.SIZE_LARGE), ('normal', None, _('Normal') + ' (%dpx)' % constants.SIZE_NORMAL, None, None, constants.SIZE_NORMAL), ('small', None, _('Small') + ' (%dpx)' % constants.SIZE_SMALL, None, None, constants.SIZE_SMALL), ('tiny', None, _('Tiny') + ' (%dpx)' % constants.SIZE_TINY, None, None, constants.SIZE_TINY), ('custom', None, _('Custom...'), None, None, 0)], prefs['library cover size'] if prefs['library cover size'] in (constants.SIZE_HUGE, constants.SIZE_LARGE, constants.SIZE_NORMAL, constants.SIZE_SMALL, constants.SIZE_TINY) else 0, self._book_size_changed) self._ui_manager.insert_action_group(actiongroup, 0) library.add_accel_group(self._ui_manager.get_accel_group())