<commit_before># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.

import gettext
import os
import time
import gtk
import pango

from kiwi.ui.objectlist import Column
from kiwi.python import Settable
from twisted.internet import task

from flumotion.common.formatting import formatStorage, formatTime
from flumotion.component.base.admin_gtk import BaseAdminGtk
from flumotion.component.base.baseadminnode import BaseAdminGtkNode

__version__ = "$Rev$"
_ = gettext.gettext


class MediaAdminGtkNode(BaseAdminGtkNode):
    gladeFile = os.path.join('flumotion', 'component',
                             'producers', 'fms', 'fms.glade')

    def haveWidgetTree(self):
        self.widget = self.wtree.get_widget('media_vbox')

        # Video
        self._label_video_device = self.wtree.get_widget('video_device')
        self._label_video_codec = self.wtree.get_widget('video_codec')
        self._label_video_framerate = self.wtree.get_widget('video_framerate')
        self._label_video_keyframe = \
                self.wtree.get_widget('video_keyframe_dist')
        self._label_video_br = self.wtree.get_widget('video_bitrate')
        self._label_video_size = self.wtree.get_widget('video_size')

        # Audio
        self._label_audio_device = self.wtree.get_widget('audio_device')
        self._label_audio_codec = self.wtree.get_widget('audio_codec')
        self._label_audio_rate = self.wtree.get_widget('audio_samplerate')
        self._label_audio_br = self.wtree.get_widget('audio_bitrate')
        self._label_audio_channels = self.wtree.get_widget('audio_channels')
        self._label_audio_depth = self.wtree.get_widget('audio_depth')

        self.widget.show_all()
        return self.widget

    def setUIState(self, state):
        BaseAdminGtkNode.setUIState(self, state)
        if not self.widget:
            return

        self.haveMetadata(state.get('metadata', {}))
        self.haveCodecInfo(state.get('codec-info', {}))

    def stateSet(self, state, key, value):
        if key == "codec-info":
            self.haveCodecInfo(value)
        elif key == "metadata":
            self.haveMetadata(value)

    def stateSetitem(self, state, key, subkey, value):
        if key != 'codec-info':
            return

        if subkey == 'audiocodec':
            self._label_audio_codec.set_text(value)
        elif subkey == 'videocodec':
            self._label_video_codec.set_text(value)
        elif subkey == 'audiorate':
            self._label_audio_rate.set_text(value)
        elif subkey == 'audiochannels':
            self._label_audio_channels.set_text(value)
        elif subkey == 'audiodepth':
            self._label_audio_depth.set_text(value)

    def haveMetadata(self, metadata):
        self._clean_metadata_labels()

        # Video
        device = metadata.get('videodevice', '')
        if device:
            self._label_video_device.set_text(device)

        framerate = metadata.get('framerate', 0)
        if framerate:
            self._label_video_framerate.set_text("%d fps" % framerate)

        bitrate = metadata.get('videodatarate', 0)
        if bitrate:
            self._label_video_br.set_text(
                formatStorage(bitrate*1000) + _("bit/s"))

        keyframe_dist = metadata.get('videokeyframe_frequency', 0)
        if keyframe_dist:
            self._label_video_keyframe.set_text("%d s" % keyframe_dist)

        width = metadata.get('width', 0)
        height = metadata.get('height', 0)
        if width:
            if height:
                self._label_video_size.set_text("%d x %d" % (width, height))
            else:
                self._label_video_size.set_text("%d x Unknown" % width)
        elif height:
            self._label_video_size.set_text("Unknown x %d" % height)

        # Audio
        device = metadata.get('audiodevice', 'Unknown')
        self._label_audio_device.set_text(device)

        bitrate = metadata.get('audiodatarate', 0)
        if bitrate:
            self._label_audio_br.set_text(formatStorage(bitrate*1000) +
                                          _("bit/s"))

    def haveCodecInfo(self, codec_info):<commit_msg>Convert width and height to integer values<commit_after># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.

import gettext
import os
import time
import gtk
import pango

from kiwi.ui.objectlist import Column
from kiwi.python import Settable
from twisted.internet import task

from flumotion.common.formatting import formatStorage, formatTime
from flumotion.component.base.admin_gtk import BaseAdminGtk
from flumotion.component.base.baseadminnode import BaseAdminGtkNode

__version__ = "$Rev$"
_ = gettext.gettext


class MediaAdminGtkNode(BaseAdminGtkNode):
    gladeFile = os.path.join('flumotion', 'component',
                             'producers', 'fms', 'fms.glade')

    def haveWidgetTree(self):
        self.widget = self.wtree.get_widget('media_vbox')

        # Video
        self._label_video_device = self.wtree.get_widget('video_device')
        self._label_video_codec = self.wtree.get_widget('video_codec')
        self._label_video_framerate = self.wtree.get_widget('video_framerate')
        self._label_video_keyframe = \
                self.wtree.get_widget('video_keyframe_dist')
        self._label_video_br = self.wtree.get_widget('video_bitrate')
        self._label_video_size = self.wtree.get_widget('video_size')

        # Audio
        self._label_audio_device = self.wtree.get_widget('audio_device')
        self._label_audio_codec = self.wtree.get_widget('audio_codec')
        self._label_audio_rate = self.wtree.get_widget('audio_samplerate')
        self._label_audio_br = self.wtree.get_widget('audio_bitrate')
        self._label_audio_channels = self.wtree.get_widget('audio_channels')
        self._label_audio_depth = self.wtree.get_widget('audio_depth')

        self.widget.show_all()
        return self.widget

    def setUIState(self, state):
        BaseAdminGtkNode.setUIState(self, state)
        if not self.widget:
            return

        self.haveMetadata(state.get('metadata', {}))
        self.haveCodecInfo(state.get('codec-info', {}))

    def stateSet(self, state, key, value):
        if key == "codec-info":
            self.haveCodecInfo(value)
        elif key == "metadata":
            self.haveMetadata(value)

    def stateSetitem(self, state, key, subkey, value):
        if key != 'codec-info':
            return

        if subkey == 'audiocodec':
            self._label_audio_codec.set_text(value)
        elif subkey == 'videocodec':
            self._label_video_codec.set_text(value)
        elif subkey == 'audiorate':
            self._label_audio_rate.set_text(value)
        elif subkey == 'audiochannels':
            self._label_audio_channels.set_text(value)
        elif subkey == 'audiodepth':
            self._label_audio_depth.set_text(value)

    def haveMetadata(self, metadata):
        self._clean_metadata_labels()

        # Video
        device = metadata.get('videodevice', '')
        if device:
            self._label_video_device.set_text(device)

        framerate = metadata.get('framerate', 0)
        if framerate:
            self._label_video_framerate.set_text("%d fps" % framerate)

        bitrate = metadata.get('videodatarate', 0)
        if bitrate:
            self._label_video_br.set_text(
                formatStorage(bitrate*1000) + _("bit/s"))

        keyframe_dist = metadata.get('videokeyframe_frequency', 0)
        if keyframe_dist:
            self._label_video_keyframe.set_text("%d s" % keyframe_dist)

        try:
            width = int(metadata.get('width', 0))
        except ValueError:
            width = 0
        try:
            height = int(metadata.get('height', 0))
        except ValueError:
            height = 0

        if width:
            if height:
                self._label_video_size.set_text("%d x %d" % (width, height))
            else:
                self._label_video_size.set_text("%d x Unknown" % width)
        elif height:
            self._label_video_size.set_text("Unknown x %d" % height)

        # Audio
        device = metadata.get('audiodevice', 'Unknown')
        self._label_audio_device.set_text(device)

        bitrate = metadata.get('audiodatarate', 0)
        if bitrate:
            self._label_audio_br.set_text(formatStorage(bitrate*1000) +
                                          _("bit/s"))

    def haveCodecInfo(self, codec_info):
{'fraction_non_alphanumeric': 0.10305225038799794, 'fraction_numerical': 0.010760475944128298, 'mean_word_length': 2.7148347425057646, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1361420', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2882, 'n_words': 601}