示例#1
0
 def set_filename(self, filename):
     """Set the filename to be displayed to <filename>. Call this before
     set_main_info().
     """
     label = labels.BoldLabel(encoding.to_unicode(filename))
     label.set_alignment(0, 0.5)
     self._mainbox.pack_start(label, False, False)
     self._mainbox.pack_start(gtk.VBox())  # Just to add space (better way?)
示例#2
0
文件: library.py 项目: foxes485/comix
    def __init__(self, library, paths, collection):
        """Adds the books at <paths> to the library, and also to the
        <collection>, unless it is None.
        """
        gtk.Dialog.__init__(self, _('Adding books'), library, gtk.DIALOG_MODAL,
                            (gtk.STOCK_STOP, gtk.RESPONSE_CLOSE))
        self._destroy = False
        self.set_size_request(400, -1)
        self.set_has_separator(False)
        self.set_resizable(False)
        self.set_border_width(4)
        self.connect('response', self._response)
        self.set_default_response(gtk.RESPONSE_CLOSE)

        main_box = gtk.VBox(False, 5)
        main_box.set_border_width(6)
        self.vbox.pack_start(main_box, False, False)
        hbox = gtk.HBox(False, 10)
        main_box.pack_start(hbox, False, False, 5)
        left_box = gtk.VBox(True, 5)
        right_box = gtk.VBox(True, 5)
        hbox.pack_start(left_box, False, False)
        hbox.pack_start(right_box, False, False)

        label = labels.BoldLabel('%s:' % _('Added books'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        number_label = gtk.Label('0')
        number_label.set_alignment(0, 1.0)
        right_box.pack_start(number_label, True, True)

        bar = gtk.ProgressBar()
        main_box.pack_start(bar, False, False)

        added_label = labels.ItalicLabel()
        added_label.set_alignment(0, 0.5)
        added_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        main_box.pack_start(added_label, False, False)
        self.show_all()

        total_paths = float(len(paths))
        total_added = 0
        for i, path in enumerate(paths):
            if library.backend.add_book(path, collection):
                total_added += 1
                number_label.set_text('%d' % total_added)
            added_label.set_text(
                _("Adding '%s'...") % encoding.to_unicode(path))
            bar.set_fraction((i + 1) / total_paths)
            while gtk.events_pending():
                gtk.main_iteration(False)
            if self._destroy:
                return
        self._response()
示例#3
0
 def __init__(self, header, right_column_width=150):
     """Contruct a new section with the header set to the text in
     <header>, and the width request of the (possible) right columns
     set to that of <right_column_width>.
     """
     gtk.VBox.__init__(self, False, 0)
     self._right_column_width = right_column_width
     self.contentbox = gtk.VBox(False, 6)
     label = labels.BoldLabel(header)
     label.set_alignment(0, 0.5)
     hbox = gtk.HBox(False, 0)
     hbox.pack_start(gtk.HBox(), False, False, 6)
     hbox.pack_start(self.contentbox)
     self.pack_start(label, False, False)
     self.pack_start(hbox, False, False, 6)
示例#4
0
 def set_secondary_info(self, info):
     """Set the information below the main info box to the values in the
     sequence <info>. Each entry in info should be a tuple (desc, value).
     """
     hbox = gtk.HBox(False, 10)
     self.pack_start(hbox, False, False)
     left_box = gtk.VBox(True, 8)
     right_box = gtk.VBox(True, 8)
     hbox.pack_start(left_box, False, False)
     hbox.pack_start(right_box, False, False)
     for desc, value in info:
         desc_label = labels.BoldLabel('%s:' % desc)
         desc_label.set_alignment(1.0, 1.0)
         left_box.pack_start(desc_label, True, True)
         value_label = gtk.Label(value)
         value_label.set_alignment(0, 1.0)
         right_box.pack_start(value_label, True, True)
示例#5
0
文件: library.py 项目: foxes485/comix
    def __init__(self, library):
        self._library = library
        gtk.HBox.__init__(self, False, 12)

        self.set_border_width(10)
        borderbox = gtk.EventBox()
        borderbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#333'))
        borderbox.set_size_request(350, -1)
        insidebox = gtk.EventBox()
        insidebox.set_border_width(1)
        insidebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ddb'))
        infobox = gtk.VBox(False, 5)
        infobox.set_border_width(10)
        self.pack_start(borderbox, False, False)
        borderbox.add(insidebox)
        insidebox.add(infobox)
        self._namelabel = labels.BoldLabel()
        self._namelabel.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        self._namelabel.set_alignment(0, 0.5)
        infobox.pack_start(self._namelabel, False, False)
        self._pageslabel = gtk.Label()
        self._pageslabel.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        self._pageslabel.set_alignment(0, 0.5)
        infobox.pack_start(self._pageslabel, False, False)
        self._filelabel = gtk.Label()
        self._filelabel.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        self._filelabel.set_alignment(0, 0.5)
        infobox.pack_start(self._filelabel, False, False)
        self._dirlabel = gtk.Label()
        self._dirlabel.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        self._dirlabel.set_alignment(0, 0.5)
        infobox.pack_start(self._dirlabel, False, False)

        vbox = gtk.VBox(False, 10)
        self.pack_start(vbox, True, True)
        hbox = gtk.HBox(False)
        vbox.pack_start(hbox, False, False)
        label = gtk.Label('%s:' % _('Search'))
        hbox.pack_start(label, False, False)
        search_entry = gtk.Entry()
        search_entry.connect('activate', self._filter_books)
        search_entry.set_tooltip_text(
            _('Display only those books that have the specified text string in their full path. The search is not case sensitive.'
              ))
        hbox.pack_start(search_entry, True, True, 6)
        label = gtk.Label('%s:' % _('Cover size'))
        hbox.pack_start(label, False, False, 6)
        adjustment = gtk.Adjustment(prefs['library cover size'], 50, 128, 1,
                                    10, 0)
        cover_size_scale = gtk.HScale(adjustment)
        cover_size_scale.set_size_request(150, -1)
        cover_size_scale.set_draw_value(False)
        cover_size_scale.connect('value_changed', self._change_cover_size)
        hbox.pack_start(cover_size_scale, False, False)
        vbox.pack_start(gtk.HBox(), True, True)

        hbox = gtk.HBox(False, 10)
        vbox.pack_start(hbox, False, False)
        add_book_button = gtk.Button(_('Add books'))
        add_book_button.set_image(
            gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON))
        add_book_button.connect('clicked', self._add_books)
        add_book_button.set_tooltip_text(_('Add more books to the library.'))
        hbox.pack_start(add_book_button, False, False)
        add_collection_button = gtk.Button(_('Add collection'))
        add_collection_button.connect('clicked', self._add_collection)
        add_collection_button.set_image(
            gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON))
        add_collection_button.set_tooltip_text(
            _('Add a new empty collection.'))
        hbox.pack_start(add_collection_button, False, False)
        hbox.pack_start(gtk.HBox(), True, True)
        self._open_button = gtk.Button(None, gtk.STOCK_OPEN)
        self._open_button.connect('clicked',
                                  self._library.book_area.open_selected_book)
        self._open_button.set_tooltip_text(_('Open the selected book.'))
        self._open_button.set_sensitive(False)
        hbox.pack_start(self._open_button, False, False)
示例#6
0
    def __init__(self, window):
        gtk.Dialog.__init__(self, _('About'), window, 0,
                            (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
        self.set_has_separator(False)
        self.set_resizable(False)
        self.connect('response', _close_dialog)
        self.set_default_response(gtk.RESPONSE_CLOSE)

        notebook = gtk.Notebook()
        self.vbox.pack_start(notebook, False, False, 0)
        self.set_border_width(4)
        notebook.set_border_width(6)

        # ----------------------------------------------------------------
        # About tab.
        # ----------------------------------------------------------------
        box = gtk.VBox(False, 0)
        box.set_border_width(5)
        base = os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
        icon_path = os.path.join(base, 'images/comix.svg')
        if not os.path.isfile(icon_path):
            for prefix in [base, '/usr', '/usr/local', '/usr/X11R6']:
                icon_path = os.path.join(prefix,
                                         'share/comix/images/comix.svg')
                if os.path.isfile(icon_path):
                    break
        try:
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_path, 200, 200)
            icon = gtk.Image()
            icon.set_from_pixbuf(pixbuf)
            box.pack_start(icon, False, False, 10)
        except Exception:
            print '! Could not find the icon file "comix.svg"\n'
        label = gtk.Label()
        label.set_markup(
            '<big><big><big><big><b><span foreground="#333333">Com</span>' +
            '<span foreground="#79941b">ix</span> <span foreground="#333333">'
            + constants.VERSION + '</span></b></big></big></big></big>\n\n' +
            _('Comix is an image viewer specifically designed to handle comic books.'
              ) + '\n' +
            _('It reads ZIP, RAR and tar archives, as well as plain image files.'
              ) + '\n\n' +
            _('Comix is licensed under the GNU General Public License.') +
            '\n\n' + '<small>Copyright © 2005-2009 Pontus Ekberg\n\n' +
            '[email protected]\n' +
            'http://comix.sourceforge.net</small>\n')
        box.pack_start(label, True, True, 0)
        label.set_justify(gtk.JUSTIFY_CENTER)
        label.set_selectable(True)
        notebook.insert_page(box, gtk.Label(_('About')))

        # ----------------------------------------------------------------
        # Credits tab.
        # ----------------------------------------------------------------
        scrolled = gtk.ScrolledWindow()
        scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        hbox = gtk.HBox(False, 5)
        hbox.set_border_width(5)
        scrolled.add_with_viewport(hbox)
        left_box = gtk.VBox(True, 8)
        right_box = gtk.VBox(True, 8)
        hbox.pack_start(left_box, False, False)
        hbox.pack_start(right_box, False, False)
        for nice_person, description in (
            ('Pontus Ekberg',
             _('Developer')), ('Emfox Zhou',
                               _('Simplified Chinese translation')),
            ('Xie Yanbo',
             _('Simplified Chinese translation')), ('Manuel Quiñones',
                                                    _('Spanish translation')),
            ('Marcelo Góes', _('Brazilian Portuguese translation')),
            ('Christoph Wolk',
             _('German translation and Nautilus thumbnailer')),
            ('Chris Leick',
             _('German translation')), ('Raimondo Giammanco',
                                        _('Italian translation')),
            ('GhePeU', _('Italian translation')), ('Arthur Nieuwland',
                                                   _('Dutch translation')),
            ('Achraf Cherti', _('French translation')),
            ('Benoît H.', _('French translation')), ('Kamil Leduchowski',
                                                     _('Polish translation')),
            ('Darek Jakoniuk',
             _('Polish translation')), ('Paul Chatzidimitriou',
                                        _('Greek translation')),
            ('Carles Escrig Royo',
             _('Catalan translation')), ('Hsin-Lin Cheng',
                                         _('Traditional Chinese translation')),
            ('Wayne Su', _('Traditional Chinese translation')),
            ('Mamoru Tasaka',
             _('Japanese translation')), ('Ernő Drabik',
                                          _('Hungarian translation')),
            ('Artyom Smirnov',
             _('Russian translation')), ('Adrian C.',
                                         _('Croatian translation')),
            ('김민기', _('Korean translation')), ('Maryam Sanaat',
                                               _('Persian translation')),
            ('Andhika Padmawan',
             _('Indonesian translation')), ('Jan Nekvasil',
                                            _('Czech translation')),
            ('Олександр Заяц',
             _('Ukrainian translation')), ('Roxerio Roxo Carrillo',
                                           _('Galician translation')),
            ('Victor Castillejo', _('Icon design'))):
            name_label = labels.BoldLabel('%s:' % nice_person)
            name_label.set_alignment(1.0, 1.0)
            left_box.pack_start(name_label, True, True)
            desc_label = gtk.Label(description)
            desc_label.set_alignment(0, 1.0)
            right_box.pack_start(desc_label, True, True)
        notebook.insert_page(scrolled, gtk.Label(_('Credits')))
        self.show_all()
示例#7
0
    def __init__(self, window):
        self._num_thumbs = 0
        gtk.Dialog.__init__(self, _('Thumbnail maintenance'), window, 0,
                            (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
        button = self.add_button(_('Cleanup'), gtk.RESPONSE_OK)
        button.set_image(
            gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
        self.set_has_separator(False)
        self.set_resizable(False)
        self.set_border_width(4)
        self.connect('response', self._response)
        self.set_default_response(gtk.RESPONSE_OK)
        main_box = gtk.VBox(False, 5)
        main_box.set_border_width(6)
        self.vbox.pack_start(main_box, False, False)

        label = labels.BoldLabel(_('Cleanup thumbnails'))
        label.set_alignment(0, 0.5)
        attrlist = label.get_attributes()
        attrlist.insert(
            pango.AttrScale(pango.SCALE_LARGE, 0, len(label.get_text())))
        label.set_attributes(attrlist)
        main_box.pack_start(label, False, False, 2)
        main_box.pack_start(gtk.HSeparator(), False, False, 5)

        label = labels.ItalicLabel(
            _('Thumbnails for files (such as image files and comic book archives) are stored in your home directory. Many different applications use and create these thumbnails, but sometimes thumbnails remain even though the original files have been removed - wasting space. This dialog can cleanup your stored thumbnails by removing orphaned and outdated thumbnails.'
              ))
        label.set_alignment(0, 0.5)
        label.set_line_wrap(True)
        main_box.pack_start(label, False, False, 10)

        hbox = gtk.HBox(False, 10)
        main_box.pack_start(hbox, False, False)
        left_box = gtk.VBox(True, 5)
        right_box = gtk.VBox(True, 5)
        hbox.pack_start(left_box, False, False)
        hbox.pack_start(right_box, False, False)

        label = labels.BoldLabel('%s:' % _('Thumbnail directory'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        label = gtk.Label('%s' % encoding.to_unicode(_thumb_base))
        label.set_alignment(0, 1.0)
        right_box.pack_start(label, True, True)

        label = labels.BoldLabel('%s:' % _('Total number of thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        self._num_thumbs_label = gtk.Label(_('Calculating...'))
        self._num_thumbs_label.set_alignment(0, 1.0)
        right_box.pack_start(self._num_thumbs_label, True, True)

        label = labels.BoldLabel('%s:' % _('Total size of thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        self._size_thumbs_label = gtk.Label(_('Calculating...'))
        self._size_thumbs_label.set_alignment(0, 1.0)
        right_box.pack_start(self._size_thumbs_label, True, True)

        label = labels.ItalicLabel(
            _('Do you want to cleanup orphaned and outdated thumbnails now?'))
        label.set_alignment(0, 0.5)
        main_box.pack_start(label, False, False, 10)

        self.show_all()
        while gtk.events_pending():
            gtk.main_iteration(False)
        self._update_num_and_size()
示例#8
0
    def __init__(self, parent, total_thumbs):
        self._total_thumbs = total_thumbs
        self._destroy = False
        gtk.Dialog.__init__(self, _('Removing thumbnails'), parent, 0,
                            (gtk.STOCK_STOP, gtk.RESPONSE_CLOSE))
        self.set_size_request(400, -1)
        self.set_has_separator(False)
        self.set_resizable(False)
        self.set_border_width(4)
        self.connect('response', self._response)
        self.set_default_response(gtk.RESPONSE_CLOSE)
        main_box = gtk.VBox(False, 5)
        main_box.set_border_width(6)
        self.vbox.pack_start(main_box, False, False)

        hbox = gtk.HBox(False, 10)
        main_box.pack_start(hbox, False, False, 5)
        left_box = gtk.VBox(True, 5)
        right_box = gtk.VBox(True, 5)
        hbox.pack_start(left_box, False, False)
        hbox.pack_start(right_box, False, False)

        label = labels.BoldLabel('%s:' % _('Number of removed thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        number_label = gtk.Label('0')
        number_label.set_alignment(0, 1.0)
        right_box.pack_start(number_label, True, True)

        label = labels.BoldLabel('%s:' % _('Total size of removed thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        size_label = gtk.Label('0.0 MiB')
        size_label.set_alignment(0, 1.0)
        right_box.pack_start(size_label, True, True)

        bar = gtk.ProgressBar()
        main_box.pack_start(bar, False, False)

        removing_label = labels.ItalicLabel()
        removing_label.set_alignment(0, 0.5)
        removing_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        main_box.pack_start(removing_label, False, False)

        self.show_all()

        iteration = 0.0
        removed_thumbs = 0
        thumbs_size = 0
        for subdir in ('normal', 'large'):
            dir_path = os.path.join(_thumb_base, subdir)
            if not os.path.isdir(dir_path) or not os.access(dir_path, os.X_OK):
                continue
            for entry in os.listdir(dir_path):
                if self._destroy:
                    return
                iteration += 1
                entry_path = os.path.join(dir_path, entry)
                if not os.path.isfile(entry_path) or not os.access(
                        entry_path, os.W_OK | os.R_OK):
                    continue
                try:
                    im_info = Image.open(entry_path).info
                    thumb_mtime = int(im_info['Thumb::MTime'])
                    src_path = _uri_to_path(im_info['Thumb::URI'])
                    broken = False
                except Exception:
                    src_path = '?'
                    broken = True
                else:
                    try:
                        src_mtime = os.stat(src_path).st_mtime
                    except Exception:
                        src_mtime = None
                # Thumb is orphaned, outdated or invalid.
                if (broken or not os.path.isfile(src_path)
                        or src_mtime != thumb_mtime):
                    size = os.stat(entry_path).st_size
                    try:
                        os.remove(entry_path)
                    except Exception:
                        continue
                    removed_thumbs += 1
                    thumbs_size += size
                    number_label.set_text('%d' % removed_thumbs)
                    size_label.set_text('%.1f MiB' % (thumbs_size / 1048576.0))
                    if broken:
                        src_path = '?'
                    else:
                        src_path = encoding.to_unicode(src_path)
                    removing_label.set_text(
                        _("Removed thumbnail for '%s'") % src_path)
                if iteration % 50 == 0:
                    bar.set_fraction(min(1, iteration / self._total_thumbs))
                while gtk.events_pending():
                    gtk.main_iteration(False)

        self._response()