コード例 #1
0
ファイル: infodialog.py プロジェクト: Braingate/picard
    def _display_artwork_tab(self):
        tab = self.ui.artwork_tab
        images = self.obj.metadata.images
        if not images:
            self.tab_hide(tab)
            return

        for image in images:
            try:
                data = image.data
            except (OSError, IOError) as e:
                log.error(traceback.format_exc())
                continue
            size = len(data)
            item = QtGui.QListWidgetItem()
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(data)
            icon = QtGui.QIcon(pixmap)
            item.setIcon(icon)
            s = "%s (%s)\n%d x %d" % (bytes2human.decimal(size),
                                      bytes2human.binary(size),
                                      pixmap.width(),
                                      pixmap.height())
            item.setText(s)
            self.ui.artwork_list.addItem(item)
コード例 #2
0
ファイル: infodialog.py プロジェクト: mishranant/picard
def format_file_info(file_):
    info = []
    info.append((_('Filename:'), file_.filename))
    if '~format' in file_.orig_metadata:
        info.append((_('Format:'), file_.orig_metadata['~format']))
    try:
        size = os.path.getsize(encode_filename(file_.filename))
        sizestr = "%s (%s)" % (bytes2human.decimal(size),
                               bytes2human.binary(size))
        info.append((_('Size:'), sizestr))
    except BaseException:
        pass
    if file_.orig_metadata.length:
        info.append((_('Length:'), format_time(file_.orig_metadata.length)))
    if '~bitrate' in file_.orig_metadata:
        info.append(
            (_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate']))
    if '~sample_rate' in file_.orig_metadata:
        info.append(
            (_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate']))
    if '~bits_per_sample' in file_.orig_metadata:
        info.append((_('Bits per sample:'),
                     str(file_.orig_metadata['~bits_per_sample'])))
    if '~channels' in file_.orig_metadata:
        ch = file_.orig_metadata['~channels']
        if ch == '1':
            ch = _('Mono')
        elif ch == '2':
            ch = _('Stereo')
        info.append((_('Channels:'), ch))
    return '<br/>'.join(
        map(lambda i: '<b>%s</b> %s' % (htmlescape(i[0]), htmlescape(i[1])),
            info))
コード例 #3
0
ファイル: infodialog.py プロジェクト: sequethin/picard
 def _display_info_tab(self):
     file = self.obj
     info = []
     info.append((_('Filename:'), file.filename))
     if '~format' in file.orig_metadata:
         info.append((_('Format:'), file.orig_metadata['~format']))
     try:
         size = os.path.getsize(encode_filename(file.filename))
         sizestr = "%s (%s)" % (bytes2human.decimal(size), bytes2human.binary(size))
         info.append((_('Size:'), sizestr))
     except:
         pass
     if file.orig_metadata.length:
         info.append((_('Length:'), format_time(file.orig_metadata.length)))
     if '~bitrate' in file.orig_metadata:
         info.append((_('Bitrate:'), '%s kbps' % file.orig_metadata['~bitrate']))
     if '~sample_rate' in file.orig_metadata:
         info.append((_('Sample rate:'), '%s Hz' % file.orig_metadata['~sample_rate']))
     if '~bits_per_sample' in file.orig_metadata:
         info.append((_('Bits per sample:'), str(file.orig_metadata['~bits_per_sample'])))
     if '~channels' in file.orig_metadata:
         ch = file.orig_metadata['~channels']
         if ch == 1:
             ch = _('Mono')
         elif ch == 2:
             ch = _('Stereo')
         else:
             ch = str(ch)
         info.append((_('Channels:'), ch))
     text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' %
                             (cgi.escape(i[0]),
                              cgi.escape(i[1])), info))
     self.ui.info.setText(text)
コード例 #4
0
ファイル: infodialog.py プロジェクト: mineo/picard
def format_file_info(file_):
    info = []
    info.append((_('Filename:'), file_.filename))
    if '~format' in file_.orig_metadata:
        info.append((_('Format:'), file_.orig_metadata['~format']))
    try:
        size = os.path.getsize(encode_filename(file_.filename))
        sizestr = "%s (%s)" % (bytes1human.decimal(size), bytes2human.binary(size))
        info.append((_('Size:'), sizestr))
    except BaseException:
        pass
    if file_.orig_metadata.length:
        info.append((_('Length:'), format_time(file_.orig_metadata.length)))
    if '~bitrate' in file_.orig_metadata:
        info.append((_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate']))
    if '~sample_rate' in file_.orig_metadata:
        info.append((_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate']))
    if '~bits_per_sample' in file_.orig_metadata:
        info.append((_('Bits per sample:'), str(file_.orig_metadata['~bits_per_sample'])))
    if '~channels' in file_.orig_metadata:
        ch = file_.orig_metadata['~channels']
        if ch == '1':
            ch = _('Mono')
        elif ch == '2':
            ch = _('Stereo')
        info.append((_('Channels:'), ch))
    return '<br/>'.join(map(lambda i: '<b>%s</b> %s' %
                            (htmlescape(i[0]),
                             htmlescape(i[1])), info))
コード例 #5
0
    def test_00(self):
        # testing with default C locale, english
        lang = 'C'
        setup_gettext(self.localedir, lang)
        self.run_test(lang)

        self.assertEqual(bytes2human.binary(45682), '44.6 KiB')
        self.assertEqual(bytes2human.binary(-45682), '-44.6 KiB')
        self.assertEqual(bytes2human.decimal(45682), '45.7 kB')
        self.assertEqual(bytes2human.decimal(9223372036854775807), '9223.4 PB')
        self.assertEqual(bytes2human.decimal(123.6), '123 B')
        self.assertRaises(ValueError, bytes2human.decimal, 'xxx')
        self.assertRaises(ValueError, bytes2human.decimal, '123.6')
        self.assertRaises(ValueError, bytes2human.binary, 'yyy')
        self.assertRaises(ValueError, bytes2human.binary, '456yyy')
        try:
            bytes2human.decimal(u'123')
        except Exception as e:
            self.fail('Unexpected exception: %s' % e)
コード例 #6
0
ファイル: test_bytes2human.py プロジェクト: kewpdawg/picard
    def test_00(self):
        # testing with default C locale, english
        lang = 'C'
        setup_gettext(self.localedir, lang)
        self.run_test(lang)

        self.assertEqual(bytes2human.binary(45682), '44.6 KiB')
        self.assertEqual(bytes2human.binary(-45682), '-44.6 KiB')
        self.assertEqual(bytes2human.decimal(45682), '45.7 kB')
        self.assertEqual(bytes2human.decimal(9223372036854775807), '9223.4 PB')
        self.assertEqual(bytes2human.decimal(123.6), '123 B')
        self.assertRaises(ValueError, bytes2human.decimal, 'xxx')
        self.assertRaises(ValueError, bytes2human.decimal, '123.6')
        self.assertRaises(ValueError, bytes2human.binary, 'yyy')
        self.assertRaises(ValueError, bytes2human.binary, '456yyy')
        try:
            bytes2human.decimal(u'123')
        except Exception as e:
            self.fail('Unexpected exception: %s' % e)
コード例 #7
0
    def _display_artwork(self, images, col):
        """Draw artwork in corresponding cell if image type matches type in Type column.

        Arguments:
        images -- The images to be drawn.
        col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col.
        """
        row = 0
        row_count = self.artwork_table.rowCount()
        for image in images:
            while row != row_count:
                image_type = self.artwork_table.item(
                    row, self.artwork_table._type_col)
                if image_type and image_type.data(
                        QtCore.Qt.UserRole) == image.types_as_string():
                    break
                row += 1
            if row == row_count:
                continue
            data = None
            try:
                if image.thumbnail:
                    try:
                        data = image.thumbnail.data
                    except CoverArtImageIOError as e:
                        log.warning(unicode(e))
                        pass
                else:
                    data = image.data
            except CoverArtImageIOError:
                log.error(traceback.format_exc())
                continue
            item = QtWidgets.QTableWidgetItem()
            item.setData(QtCore.Qt.UserRole, image)
            pixmap = QtGui.QPixmap()
            if data is not None:
                pixmap.loadFromData(data)
                item.setToolTip(
                    _("Double-click to open in external viewer\n"
                      "Temporary file: %s\n"
                      "Source: %s") % (image.tempfile_filename, image.source))
            infos = []
            if image.comment:
                infos.append(image.comment)
            infos.append(u"%s (%s)" % (bytes2human.decimal(
                image.datalength), bytes2human.binary(image.datalength)))
            if image.width and image.height:
                infos.append(u"%d x %d" % (image.width, image.height))
            infos.append(image.mimetype)

            img_wgt = self.artwork_table.get_coverart_widget(
                pixmap, "\n".join(infos))
            self.artwork_table.setCellWidget(row, col, img_wgt)
            self.artwork_table.setItem(row, col, item)
            row += 1
コード例 #8
0
ファイル: infodialog.py プロジェクト: JDLH/picard
    def _display_artwork(self, images, col):
        """Draw artwork in corresponding cell if image type matches type in Type column.

        Arguments:
        images -- The images to be drawn.
        col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col.
        """
        row = 0
        row_count = self.artwork_table.rowCount()
        for image in images:
            while row != row_count:
                image_type = self.artwork_table.item(row, self.artwork_table._type_col)
                if image_type and image_type.data(QtCore.Qt.UserRole) == image.types_as_string():
                    break
                row += 1
            if row == row_count:
                continue
            data = None
            try:
                if image.thumbnail:
                    try:
                        data = image.thumbnail.data
                    except CoverArtImageIOError as e:
                        log.warning(e)
                        pass
                else:
                    data = image.data
            except CoverArtImageIOError:
                log.error(traceback.format_exc())
                continue
            item = QtWidgets.QTableWidgetItem()
            item.setData(QtCore.Qt.UserRole, image)
            pixmap = QtGui.QPixmap()
            if data is not None:
                pixmap.loadFromData(data)
                item.setToolTip(
                    _("Double-click to open in external viewer\n"
                      "Temporary file: %s\n"
                      "Source: %s") % (image.tempfile_filename, image.source))
            infos = []
            if image.comment:
                infos.append(image.comment)
            infos.append("%s (%s)" %
                         (bytes2human.decimal(image.datalength),
                          bytes2human.binary(image.datalength)))
            if image.width and image.height:
                infos.append("%d x %d" % (image.width, image.height))
            infos.append(image.mimetype)

            img_wgt = self.artwork_table.get_coverart_widget(pixmap, "\n".join(infos))
            self.artwork_table.setCellWidget(row, col, img_wgt)
            self.artwork_table.setItem(row, col, item)
            row += 1
コード例 #9
0
 def _create_testlist(self):
     values = [0, 1]
     for n in [1000, 1024]:
         p = 1
         for e in range(0, 6):
             p *= n
             for x in [0.1, 0.5, 0.99, 0.9999, 1, 1.5]:
                 values.append(int(p * x))
     l = []
     for x in sorted(values):
         l.append(";".join([str(x), bytes2human.decimal(x),
                            bytes2human.binary(x),
                            bytes2human.short_string(x, 1024, 2)]))
     return l
コード例 #10
0
ファイル: infodialog.py プロジェクト: sequethin/picard
    def _display_artwork_tab(self):
        tab = self.ui.artwork_tab
        images = self.obj.metadata.images
        if not images:
            self.tab_hide(tab)
            return

        self.ui.artwork_list.itemDoubleClicked.connect(self.show_item)
        for image in images:
            data = None
            try:
                if image.thumbnail:
                    try:
                        data = image.thumbnail.data
                    except CoverArtImageIOError as e:
                        log.warning(unicode(e))
                        pass
                else:
                    data = image.data
            except CoverArtImageIOError:
                log.error(traceback.format_exc())
                continue
            item = QtGui.QListWidgetItem()
            item.setData(QtCore.Qt.UserRole, image)
            if data is not None:
                pixmap = QtGui.QPixmap()
                pixmap.loadFromData(data)
                icon = QtGui.QIcon(pixmap)
                item.setIcon(icon)
                item.setToolTip(
                    _("Double-click to open in external viewer\n"
                      "Temporary file: %s\n"
                      "Source: %s") % (image.tempfile_filename, image.source))
            infos = []
            infos.append(image.types_as_string())
            if image.comment:
                infos.append(image.comment)
            infos.append(u"%s (%s)" %
                         (bytes2human.decimal(image.datalength),
                          bytes2human.binary(image.datalength)))
            if image.width and image.height:
                infos.append(u"%d x %d" % (image.width, image.height))
            infos.append(image.mimetype)
            item.setText(u"\n".join(infos))
            self.ui.artwork_list.addItem(item)
コード例 #11
0
ファイル: infodialog.py プロジェクト: kewpdawg/picard
    def _display_artwork_tab(self):
        tab = self.ui.artwork_tab
        images = self.obj.metadata.images
        if not images:
            self.tab_hide(tab)
            return

        for image in images:
            data = image["data"]
            size = len(data)
            item = QtGui.QListWidgetItem()
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(data)
            icon = QtGui.QIcon(pixmap)
            item.setIcon(icon)
            s = "%s (%s)\n%d x %d" % (bytes2human.decimal(size),
                                      bytes2human.binary(size), pixmap.width(),
                                      pixmap.height())
            item.setText(s)
            self.ui.artwork_list.addItem(item)
コード例 #12
0
ファイル: infodialog.py プロジェクト: JonnyJD/picard
    def _display_artwork_tab(self):
        tab = self.ui.artwork_tab
        images = self.obj.metadata.images
        if not images:
            self.tab_hide(tab)
            return

        for image in images:
            data = image["data"]
            size = len(data)
            item = QtGui.QListWidgetItem()
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(data)
            icon = QtGui.QIcon(pixmap)
            item.setIcon(icon)
            s = "%s (%s)\n%d x %d" % (bytes2human.decimal(size),
                                      bytes2human.binary(size),
                                      pixmap.width(),
                                      pixmap.height())
            item.setText(s)
            self.ui.artwork_list.addItem(item)