# Path: vocto/port.py
# class Port(object):
# 
#     NONE = 0
# 
#     IN = 1
#     OUT = 2
# 
#     OFFSET_PREVIEW = 100
#     # core listening port
#     CORE_LISTENING = 9999
#     # input ports
#     SOURCES_IN = 10000
#     SOURCES_BACKGROUND = 16000
#     SOURCE_OVERLAY= 14000
#     SOURCES_BLANK = 17000
#     AUDIO_SOURCE_BLANK = 18000
#     # output ports
#     MIX_OUT = 11000
#     MIX_PREVIEW = MIX_OUT+OFFSET_PREVIEW
#     SOURCES_OUT = 13000
#     SOURCES_PREVIEW = SOURCES_OUT+OFFSET_PREVIEW
#     LIVE_OUT = 15000
#     LIVE_PREVIEW = LIVE_OUT+OFFSET_PREVIEW
# 
#     def __init__(self, name, source=None, audio=None, video=None):
#         self.name = name
#         self.source = source
#         self.audio = audio
#         self.video = video
#         self.update()
# 
#     def todict(self):
#         return {
#             'name': self.name,
#             'port': self.port,
#             'audio': self.audio,
#             'video': self.video,
#             'io': self.io,
#             'connections': self.connections
#         }
# 
#     def update(self):
#         if self.source:
#             self.port = self.source.port()
#             self.audio = self.source.audio_channels()
#             self.video = self.source.video_channels()
#             self.io = self.IN if self.source.is_input() else self.OUT
#             self.connections = self.source.num_connections()
# 
#     def from_str(_str):
#         p = Port(_str['name'])
#         p.port = _str['port']
#         p.audio = _str['audio']
#         p.video = _str['video']
#         p.io = _str['io']
#         p.connections = _str['connections']
#         return p
# 
#     def is_input(self):
#         return self.io == Port.IN
# 
#     def is_output(self):
#         return self.io == Port.OUT


import logging
import os
import json
import lib.connection as Connection
from gi.repository import Gtk, Gst, GLib
from lib.config import Config
from lib.uibuilder import UiBuilder
from vocto.port import Port
    def __init__(self, uibuilder):
        self.log = logging.getLogger('QueuesWindowController')

        # get related widgets
        self.win = uibuilder.get_check_widget('ports_win')
        self.store = uibuilder.get_check_widget('ports_store')
        self.scroll = uibuilder.get_check_widget('ports_scroll')
        self.title = uibuilder.get_check_widget('ports_title')
        self.title.set_title("VOC2CORE {}".format(Config.getHost()))
        # remember row iterators
        self.iterators = None

        # listen for queue_report from voctocore
        Connection.on('port_report', self.on_port_report)

    def on_port_report(self, *report):

        def color(port):
            if port.connections > 0:
                return COLOR_OK
            else:
                return COLOR_ERROR if port.is_input() else COLOR_WARN

        # read string report into dictonary
        report = json.loads("".join(report))
        # check if this is the initial report
        if not self.iterators:
            # append report as rows to treeview store and remember row iterators
            self.iterators = dict()
            for p in report:

# Path: vocto/port.py
# class Port(object):
# 
#     NONE = 0
# 
#     IN = 1
#     OUT = 2
# 
#     OFFSET_PREVIEW = 100
#     # core listening port
#     CORE_LISTENING = 9999
#     # input ports
#     SOURCES_IN = 10000
#     SOURCES_BACKGROUND = 16000
#     SOURCE_OVERLAY= 14000
#     SOURCES_BLANK = 17000
#     AUDIO_SOURCE_BLANK = 18000
#     # output ports
#     MIX_OUT = 11000
#     MIX_PREVIEW = MIX_OUT+OFFSET_PREVIEW
#     SOURCES_OUT = 13000
#     SOURCES_PREVIEW = SOURCES_OUT+OFFSET_PREVIEW
#     LIVE_OUT = 15000
#     LIVE_PREVIEW = LIVE_OUT+OFFSET_PREVIEW
# 
#     def __init__(self, name, source=None, audio=None, video=None):
#         self.name = name
#         self.source = source
#         self.audio = audio
#         self.video = video
#         self.update()
# 
#     def todict(self):
#         return {
#             'name': self.name,
#             'port': self.port,
#             'audio': self.audio,
#             'video': self.video,
#             'io': self.io,
#             'connections': self.connections
#         }
# 
#     def update(self):
#         if self.source:
#             self.port = self.source.port()
#             self.audio = self.source.audio_channels()
#             self.video = self.source.video_channels()
#             self.io = self.IN if self.source.is_input() else self.OUT
#             self.connections = self.source.num_connections()
# 
#     def from_str(_str):
#         p = Port(_str['name'])
#         p.port = _str['port']
#         p.audio = _str['audio']
#         p.video = _str['video']
#         p.io = _str['io']
#         p.connections = _str['connections']
#         return p
# 
#     def is_input(self):
#         return self.io == Port.IN
# 
#     def is_output(self):
#         return self.io == Port.OUT


# Path: voctogui/lib/ports.py
import logging
import os
import json
import lib.connection as Connection
from gi.repository import Gtk, Gst, GLib
from lib.config import Config
from lib.uibuilder import UiBuilder
from vocto.port import Port

    def __init__(self, uibuilder):
        self.log = logging.getLogger('QueuesWindowController')

        # get related widgets
        self.win = uibuilder.get_check_widget('ports_win')
        self.store = uibuilder.get_check_widget('ports_store')
        self.scroll = uibuilder.get_check_widget('ports_scroll')
        self.title = uibuilder.get_check_widget('ports_title')
        self.title.set_title("VOC2CORE {}".format(Config.getHost()))
        # remember row iterators
        self.iterators = None

        # listen for queue_report from voctocore
        Connection.on('port_report', self.on_port_report)

    def on_port_report(self, *report):

        def color(port):
            if port.connections > 0:
                return COLOR_OK
            else:
                return COLOR_ERROR if port.is_input() else COLOR_WARN

        # read string report into dictonary
        report = json.loads("".join(report))
        # check if this is the initial report
        if not self.iterators:
            # append report as rows to treeview store and remember row iterators
            self.iterators = dict()
            for p in report:

                port = Port.from_str(p)