Пример #1
0
    def __init__(self, window):
        gtk.UIManager.__init__(self)

        self._window = window
        self._tooltipstatus = status.TooltipStatusHelper(
            self, window.statusbar)

        # ----------------------------------------------------------------
        # Create actions for the menus.
        # ----------------------------------------------------------------
        self._actiongroup = gtk.ActionGroup('mcomix-main')
        self._actiongroup.add_actions([
            ('copy_page', gtk.STOCK_COPY, _('_Copy'), None,
             _('Copies the current page to clipboard.'),
             window.clipboard.copy_page),
            ('delete', gtk.STOCK_DELETE, _('_Delete'), None,
             _('Deletes the current file or archive from disk.'),
             window.delete),
            ('next_page', gtk.STOCK_GO_FORWARD, _('_Next page'), None,
             _('Next page'), window.next_page),
            ('previous_page', gtk.STOCK_GO_BACK, _('_Previous page'), None,
             _('Previous page'), window.previous_page),
            ('first_page', gtk.STOCK_GOTO_FIRST, _('_First page'), None,
             _('First page'), window.first_page),
            ('last_page', gtk.STOCK_GOTO_LAST, _('_Last page'), None,
             _('Last page'), window.last_page),
            ('go_to', gtk.STOCK_JUMP_TO, _('_Go to page...'), None,
             _('Go to page...'), window.page_select),
            ('refresh_archive', gtk.STOCK_REFRESH, _('Re_fresh'), None,
             _('Reloads the currently opened files or archive.'),
             window.filehandler.refresh_file),
            ('next_archive', gtk.STOCK_MEDIA_NEXT, _('Next _archive'), None,
             _('Next archive'), window.filehandler._open_next_archive),
            ('previous_archive', gtk.STOCK_MEDIA_PREVIOUS,
             _('Previous a_rchive'), None, _('Previous archive'),
             window.filehandler._open_previous_archive),
            ('next_directory', gtk.STOCK_REDO, _('Next directory'), None,
             _('Next directory'), window.filehandler.open_next_directory),
            ('previous_directory', gtk.STOCK_UNDO, _('Previous directory'),
             None, _('Previous directory'),
             window.filehandler.open_previous_directory),
            ('zoom_in', gtk.STOCK_ZOOM_IN, _('Zoom _In'), None, None,
             window.manual_zoom_in),
            ('zoom_out', gtk.STOCK_ZOOM_OUT, _('Zoom _Out'), None, None,
             window.manual_zoom_out),
            ('zoom_original', gtk.STOCK_ZOOM_100, _('_Normal Size'), None,
             None, window.manual_zoom_original),
            ('minimize', gtk.STOCK_LEAVE_FULLSCREEN, _('Mi_nimize'), None,
             None, window.minimize),
            ('close', gtk.STOCK_CLOSE, _('_Close'), None,
             _('Closes all opened files.'), window.filehandler.close_file),
            ('quit', gtk.STOCK_QUIT, _('_Quit'), None, None,
             window.close_program),
            ('save_and_quit', gtk.STOCK_QUIT, _('_Save and quit'), None,
             _('Quits and restores the currently opened file next time the program starts.'
               ), window.save_and_terminate_program),
            ('rotate_90', 'mcomix-rotate-90', _('_Rotate 90 degrees CW'), None,
             None, window.rotate_90),
            ('rotate_180', 'mcomix-rotate-180', _('Rotate 180 de_grees'), None,
             None, window.rotate_180),
            ('rotate_270', 'mcomix-rotate-270', _('Rotat_e 90 degrees CCW'),
             None, None, window.rotate_270),
            ('flip_horiz', 'mcomix-flip-horizontal', _('Fli_p horizontally'),
             None, None, window.flip_horizontally),
            ('flip_vert', 'mcomix-flip-vertical', _('Flip _vertically'), None,
             None, window.flip_vertically),
            ('extract_page', gtk.STOCK_SAVE_AS, _('Save _As'), None, None,
             window.extract_page), ('menu_zoom', 'mcomix-zoom', _('_Zoom')),
            ('menu_recent', gtk.STOCK_DND_MULTIPLE, _('_Recent')),
            ('menu_bookmarks_popup', 'comix-add-bookmark', _('_Bookmarks')),
            ('menu_bookmarks', None, _('_Bookmarks')),
            ('menu_toolbars', None, _('T_oolbars')),
            ('menu_edit', None, _('_Edit')),
            ('menu_open_with', gtk.STOCK_OPEN, _('Open _with'), ''),
            ('menu_open_with_popup', gtk.STOCK_OPEN, _('Open _with'), ''),
            ('menu_file', None, _('_File')), ('menu_view', None, _('_View')),
            ('menu_view_popup', 'comix-image', _('_View')),
            ('menu_go', None, _('_Go')),
            ('menu_go_popup', gtk.STOCK_GO_FORWARD, _('_Go')),
            ('menu_tools', None, _('_Tools')), ('menu_help', None, _('_Help')),
            ('menu_transform', 'mcomix-transform', _('_Transform image')),
            ('menu_autorotate', None, _('_Auto-rotate image')),
            ('menu_autorotate_width', None, _('...when width exceeds height')),
            ('menu_autorotate_height', None,
             _('...when height exceeds width')),
            ('expander', None, None, None, None, None)
        ])

        self._actiongroup.add_toggle_actions([
            ('fullscreen', gtk.STOCK_FULLSCREEN, _('_Fullscreen'), None,
             _('Fullscreen mode'), window.change_fullscreen),
            ('double_page', 'mcomix-double-page', _('_Double page mode'), None,
             _('Double page mode'), window.change_double_page),
            ('toolbar', None, _('_Toolbar'), None, None,
             window.change_toolbar_visibility),
            ('menubar', None, _('_Menubar'), None, None,
             window.change_menubar_visibility),
            ('statusbar', None, _('St_atusbar'), None, None,
             window.change_statusbar_visibility),
            ('scrollbar', None, _('S_crollbars'), None, None,
             window.change_scrollbar_visibility),
            ('thumbnails', None, _('Th_umbnails'), None, None,
             window.change_thumbnails_visibility),
            ('hide_all', None, _('H_ide all'), None, None,
             window.change_hide_all),
            ('manga_mode', 'mcomix-manga', _('_Manga mode'), None,
             _('Manga mode'), window.change_manga_mode),
            ('invert_scroll', gtk.STOCK_UNDO, _('Invert smart scroll'), None,
             _('Invert smart scrolling direction.'),
             window.change_invert_scroll),
            ('keep_transformation', None, _('_Keep transformation'), None,
             _('Keeps the currently selected transformation for the next pages.'
               ), window.change_keep_transformation),
            ('slideshow', gtk.STOCK_MEDIA_PLAY, _('Start _slideshow'), None,
             _('Start slideshow'), window.slideshow.toggle),
            ('lens', 'mcomix-lens', _('Magnifying _lens'), None,
             _('Magnifying lens'), window.lens.toggle),
            ('stretch', None, _('Stretch small images'), None,
             _('Stretch images to fit to the screen, depending on zoom mode.'),
             window.change_stretch)
        ])

        # Note: Don't change the default value for the radio buttons unless
        # also fixing the code for setting the correct one on start-up in main.py.
        self._actiongroup.add_radio_actions(
            [('best_fit_mode', 'mcomix-fitbest', _('_Best fit mode'), None,
              _('Best fit mode'), constants.ZOOM_MODE_BEST),
             ('fit_width_mode', 'mcomix-fitwidth', _('Fit _width mode'), None,
              _('Fit width mode'), constants.ZOOM_MODE_WIDTH),
             ('fit_height_mode', 'mcomix-fitheight', _('Fit _height mode'),
              None, _('Fit height mode'), constants.ZOOM_MODE_HEIGHT),
             ('fit_size_mode', 'mcomix-fitsize', _('Fit _size mode'), None,
              _('Fit to size mode'), constants.ZOOM_MODE_SIZE),
             ('fit_manual_mode', 'mcomix-fitmanual', _('M_anual zoom mode'),
              None, _('Manual zoom mode'), constants.ZOOM_MODE_MANUAL)], 3,
            window.change_zoom_mode)

        # Automatically rotate image if width>height or height>width
        self._actiongroup.add_radio_actions([
            ('no_autorotation', None, _('Never'), None, None,
             constants.AUTOROTATE_NEVER),
            ('rotate_90_width', 'mcomix-rotate-90', _('_Rotate 90 degrees CW'),
             None, None, constants.AUTOROTATE_WIDTH_90),
            ('rotate_270_width', 'mcomix-rotate-270',
             _('Rotat_e 90 degrees CCW'), None, None,
             constants.AUTOROTATE_WIDTH_270),
            ('rotate_90_height', 'mcomix-rotate-90',
             _('_Rotate 90 degrees CW'), None, None,
             constants.AUTOROTATE_HEIGHT_90),
            ('rotate_270_height', 'mcomix-rotate-270',
             _('Rotat_e 90 degrees CCW'), None, None,
             constants.AUTOROTATE_HEIGHT_270)
        ], prefs['auto rotate depending on size'], window.change_autorotation)

        self._actiongroup.add_actions(
            [('about', gtk.STOCK_ABOUT, _('_About'), None, None,
              dialog_handler.open_dialog)], (window, 'about-dialog'))

        self._actiongroup.add_actions(
            [('comments', 'mcomix-comments', _('Co_mments...'), None, None,
              dialog_handler.open_dialog)], (window, 'comments-dialog'))

        self._actiongroup.add_actions(
            [('properties', gtk.STOCK_PROPERTIES, _('Proper_ties'), None, None,
              dialog_handler.open_dialog)], (window, 'properties-dialog'))

        self._actiongroup.add_actions(
            [('preferences', gtk.STOCK_PREFERENCES, _('Pr_eferences'), None,
              None, preferences_dialog.open_dialog)], (window))

        # Some actions added separately since they need extra arguments.
        self._actiongroup.add_actions(
            [('edit_archive', gtk.STOCK_EDIT, _('_Edit archive...'), None,
              _('Opens the archive editor.'), edit_dialog.open_dialog),
             ('open', gtk.STOCK_OPEN, _('_Open...'), None, None,
              file_chooser_main_dialog.open_main_filechooser_dialog),
             ('enhance_image', 'mcomix-enhance-image', _('En_hance image...'),
              None, None, enhance_dialog.open_dialog)], window)

        self._actiongroup.add_actions(
            [('library', 'mcomix-library', _('_Library...'), None, None,
              library_main_dialog.open_dialog)], window)

        # fix some gtk magic: removing unreqired accelerators
        gtk.accel_map_change_entry('<Actions>/mcomix-main/%s' % 'close', 0, 0,
                                   True)

        ui_description = """
        <ui>
            <toolbar name="Tool">
                <toolitem action="previous_archive" />
                <toolitem action="first_page" />
                <toolitem action="previous_page" />
                <toolitem action="go_to" />
                <toolitem action="next_page" />
                <toolitem action="last_page" />
                <toolitem action="next_archive" />
                <separator />
                <toolitem action="slideshow" />
                <toolitem action="expander" />
                <toolitem action="best_fit_mode" />
                <toolitem action="fit_width_mode" />
                <toolitem action="fit_height_mode" />
                <toolitem action="fit_size_mode" />
                <toolitem action="fit_manual_mode" />
                <separator />
                <toolitem action="double_page" />
                <toolitem action="manga_mode" />
                <separator />
                <toolitem action="lens" />
            </toolbar>

            <menubar name="Menu">
                <menu action="menu_file">
                    <menuitem action="open" />
                    <menu action="menu_recent" />
                    <menuitem action="library" />
                    <separator />
                    <menuitem action="extract_page" />
                    <menuitem action="refresh_archive" />
                    <menuitem action="properties" />
                    <separator />
                    <menu action="menu_open_with"></menu>
                    <separator />
                    <menuitem action="delete" />
                    <separator />
                    <menuitem action="minimize" />
                    <menuitem action="close" />
                    <menuitem action="save_and_quit" />
                    <menuitem action="quit" />
                </menu>
                <menu action="menu_edit">
                    <menuitem action="copy_page" />
                    <separator />
                    <menuitem action="edit_archive" />
                    <menuitem action="comments" />
                    <separator />
                    <menuitem action="preferences" />
                </menu>
                <menu action="menu_view">
                    <menuitem action="fullscreen" />
                    <menuitem action="double_page" />
                    <menuitem action="manga_mode" />
                    <separator />
                    <menuitem action="best_fit_mode" />
                    <menuitem action="fit_width_mode" />
                    <menuitem action="fit_height_mode" />
                    <menuitem action="fit_size_mode" />
                    <menuitem action="fit_manual_mode" />
                    <separator />
                    <menuitem action="slideshow" />
                    <separator />
                    <menuitem action="stretch" />
                    <menuitem action="invert_scroll" />
                    <menuitem action="lens" />
                    <menu action="menu_zoom">
                        <menuitem action="zoom_in" />
                        <menuitem action="zoom_out" />
                        <menuitem action="zoom_original" />
                    </menu>
                    <separator />
                    <menu action="menu_toolbars">
                        <menuitem action="menubar" />
                        <menuitem action="toolbar" />
                        <menuitem action="statusbar" />
                        <menuitem action="scrollbar" />
                        <menuitem action="thumbnails" />
                        <separator />
                        <menuitem action="hide_all" />
                    </menu>
                </menu>
                <menu action="menu_go">
                    <menuitem action="next_page" />
                    <menuitem action="previous_page" />
                    <menuitem action="go_to" />
                    <menuitem action="first_page" />
                    <menuitem action="last_page" />
                    <separator />
                    <menuitem action="next_archive" />
                    <menuitem action="previous_archive" />
                    <separator />
                    <menuitem action="next_directory" />
                    <menuitem action="previous_directory" />
                </menu>
                <menu action="menu_bookmarks">
                </menu>
                <menu action="menu_tools">
                    <menuitem action="enhance_image" />
                    <menu action="menu_transform">
                        <menuitem action="rotate_90" />
                        <menuitem action="rotate_270" />
                        <menuitem action="rotate_180" />
                        <separator />
                        <menu action="menu_autorotate">
                            <menuitem action="no_autorotation" />
                            <separator />
                            <menuitem action="menu_autorotate_height" />
                            <separator />
                            <menuitem action="rotate_90_height" />
                            <menuitem action="rotate_270_height" />
                            <separator />
                            <menuitem action="menu_autorotate_width" />
                            <separator />
                            <menuitem action="rotate_90_width" />
                            <menuitem action="rotate_270_width" />
                        </menu>
                        <separator />
                        <menuitem action="flip_horiz" />
                        <menuitem action="flip_vert" />
                        <separator />
                        <menuitem action="keep_transformation" />
                    </menu>
                </menu>
                <menu action="menu_help">
                    <menuitem action="about" />
                </menu>
            </menubar>

            <popup name="Popup">
                <menu action="menu_go_popup">
                    <menuitem action="next_page" />
                    <menuitem action="previous_page" />
                    <menuitem action="go_to" />
                    <menuitem action="first_page" />
                    <menuitem action="last_page" />
                    <separator />
                    <menuitem action="next_archive" />
                    <menuitem action="previous_archive" />
                    <separator />
                    <menuitem action="next_directory" />
                    <menuitem action="previous_directory" />
                </menu>
                <menu action="menu_view_popup">
                    <menuitem action="fullscreen" />
                    <menuitem action="double_page" />
                    <menuitem action="manga_mode" />
                    <separator />
                    <menuitem action="best_fit_mode" />
                    <menuitem action="fit_width_mode" />
                    <menuitem action="fit_height_mode" />
                    <menuitem action="fit_size_mode" />
                    <menuitem action="fit_manual_mode" />
                    <separator />
                    <menuitem action="slideshow" />
                    <separator />
                    <menuitem action="enhance_image" />
                    <separator />
                    <menuitem action="stretch" />
                    <menuitem action="invert_scroll" />
                    <menuitem action="lens" />
                    <menu action="menu_zoom">
                        <menuitem action="zoom_in" />
                        <menuitem action="zoom_out" />
                        <menuitem action="zoom_original" />
                    </menu>
                    <separator />
                    <menu action="menu_toolbars">
                        <menuitem action="menubar" />
                        <menuitem action="toolbar" />
                        <menuitem action="statusbar" />
                        <menuitem action="scrollbar" />
                        <menuitem action="thumbnails" />
                        <separator />
                        <menuitem action="hide_all" />
                    </menu>
                </menu>
                <menu action="menu_bookmarks_popup">
                </menu>
                <separator />
                <menuitem action="open" />
                <menu action="menu_recent" />
                <menuitem action="library" />
                <separator />
                <menu action="menu_open_with_popup"></menu>
                <separator />
                <menuitem action="preferences" />
                <separator />
                <menuitem action="close" />
                <menuitem action="quit" />
            </popup>
        </ui>
        """

        self.add_ui_from_string(ui_description)
        self.insert_action_group(self._actiongroup, 0)

        self.bookmarks = bookmark_menu.BookmarksMenu(self, window)
        self.get_widget('/Menu/menu_bookmarks').set_submenu(self.bookmarks)
        self.get_widget('/Menu/menu_bookmarks').show()

        self.bookmarks_popup = bookmark_menu.BookmarksMenu(self, window)
        self.get_widget('/Popup/menu_bookmarks_popup').set_submenu(
            self.bookmarks_popup)
        self.get_widget('/Popup/menu_bookmarks_popup').show()

        self.recent = recent.RecentFilesMenu(self, window)
        self.get_widget('/Menu/menu_file/menu_recent').set_submenu(self.recent)
        self.get_widget('/Menu/menu_file/menu_recent').show()

        self.recentPopup = recent.RecentFilesMenu(self, window)
        self.get_widget('/Popup/menu_recent').set_submenu(self.recentPopup)
        self.get_widget('/Popup/menu_recent').show()

        openwith = openwith_menu.OpenWithMenu(self, window)
        self.get_widget('/Menu/menu_file/menu_open_with').set_submenu(openwith)
        self.get_widget('/Menu/menu_file/menu_open_with').show()
        openwith = openwith_menu.OpenWithMenu(self, window)
        self.get_widget('/Popup/menu_open_with_popup').set_submenu(openwith)
        self.get_widget('/Popup/menu_open_with_popup').show()

        window.add_accel_group(self.get_accel_group())

        # Is there no built-in way to do this?
        self.get_widget('/Tool/expander').set_expand(True)
        self.get_widget('/Tool/expander').set_sensitive(False)
Пример #2
0
    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())
Пример #3
0
    def __init__(self, library):
        super(_CollectionArea, self).__init__()
        self._library = library
        self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)

        self._treestore = Gtk.TreeStore(str, int)  # (Name, ID) of collections.
        self._treeview = Gtk.TreeView(model=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._set_acceptable_drop(True)
        self._treeview.enable_model_drag_source(
            Gdk.ModifierType.BUTTON1_MASK,
            [('collection', Gtk.TargetFlags.SAME_WIDGET,
              constants.LIBRARY_DRAG_COLLECTION_ID)], Gdk.DragAction.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(name='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()
Пример #4
0
    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())