def __init__(self, library): gtk.ScrolledWindow.__init__(self) self._library = library self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self._treestore = gtk.TreeStore(str, int) # (Name, ID) of collections. self._treeview = gtk.TreeView(self._treestore) self._treeview.connect('cursor_changed', self._collection_selected) self._treeview.connect('drag_data_received', self._drag_data_received) self._treeview.connect('drag_motion', self._drag_motion) self._treeview.connect_after('drag_begin', self._drag_begin) self._treeview.connect('button_press_event', self._button_press) self._treeview.connect('key_press_event', self._key_press) self._treeview.connect('popup_menu', self._popup_menu) self._treeview.connect('row_activated', self._expand_or_collapse_row) self._treeview.set_headers_visible(False) self._treeview.set_rules_hint(True) self._set_acceptable_drop(True) self._treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, [('collection', gtk.TARGET_SAME_WIDGET, constants.LIBRARY_DRAG_COLLECTION_ID)], gtk.gdk.ACTION_MOVE) cellrenderer = gtk.CellRendererText() column = gtk.TreeViewColumn(None, cellrenderer, markup=0) self._treeview.append_column(column) self.add(self._treeview) self._ui_manager = gtk.UIManager() self._tooltipstatus = status.TooltipStatusHelper(self._ui_manager, self._library.get_status_bar()) ui_description = """ <ui> <popup name="library collections"> <menuitem action="_title" /> <separator /> <menuitem action="add" /> <separator /> <menuitem action="new" /> <menuitem action="rename" /> <menuitem action="duplicate" /> <separator /> <menuitem action="cleanup" /> <menuitem action="remove" /> </popup> </ui> """ self._ui_manager.add_ui_from_string(ui_description) actiongroup = gtk.ActionGroup('mcomix-library-collection-area') actiongroup.add_actions([ ('_title', None, _("Library collections"), None, None, lambda *args: False), ('add', gtk.STOCK_ADD, _('_Add...'), None, _('Add more books to the library.'), lambda *args: file_chooser_library_dialog.open_library_filechooser_dialog(self._library)), ('new', gtk.STOCK_NEW, _('New'), None, _('Add a new empty collection.'), self.add_collection), ('rename', gtk.STOCK_EDIT, _('Re_name'), None, _('Renames the selected collection.'), self._rename_collection), ('duplicate', gtk.STOCK_COPY, _('_Duplicate'), None, _('Creates a duplicate of the selected collection.'), self._duplicate_collection), ('cleanup', gtk.STOCK_CLEAR, _('_Clean up'), None, _('Removes no longer existant books from the collection.'), self._clean_collection), ('remove', gtk.STOCK_REMOVE, _('_Remove'), None, _('Deletes the selected collection.'), self._remove_collection)]) self._ui_manager.insert_action_group(actiongroup, 0) self.display_collections()
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._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) self._iconview.set_pixbuf_column(0) self._iconview.pixbuf_column = 0 self._iconview.status_column = 5 self._iconview.generate_thumbnail = self._get_pixbuf self._iconview.get_file_path_from_model = lambda model, iter: \ model.get_value(iter, 2).decode('utf-8') 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 /> <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())