def run():
    # Protobuf
    #c = ControllerProtobuf()

    # Directly connected to the vision server
    c = VisionManager()
    
    if not c.is_connected():
        print("Vision server is not accessible.")
        return

    server = Server()
    server.start("127.0.0.1", 5030)

    # add observer output for "server"
    c.add_filter_output_observer(server.send)

    from gi.repository import Gtk, GObject
    import CapraVision.client.gtk.main
    GObject.threads_init()

    w = CapraVision.client.gtk.main.WinFilterChain(c)

    w.window.show_all()
    Gtk.main()

    # Close connection
    server.stop()
    c.close_server()
class WinMain(QtGui.QMainWindow):
    def __init__(self):
        super(WinMain,self).__init__()
        
        self.source_list = imageproviders.load_sources()
        
        c = VisionManager()
    
        if not c.is_connected():
            print("Vision server is not accessible.")
            return
        
        #create and start server
        self.server = Server()
        self.server.start("127.0.0.1", 5030)        
        
        #create dockWidgets
        self.winFilterChain = WinFilterChain(c)
        self.winFilter = WinFilter()
        self.winFilterSel = WinFilterSel()
          
        self.setCentralWidget(self.winFilterChain.ui)      
         
        #connect action between dock widgets       
        self.winFilterSel.onAddFilter.connect(self.winFilterChain.add_filter)       
        self.winFilterChain.selectedFilterChanged.connect(self.winFilter.setFilter)
        
        self._addToolBar() 
        self._addDockWidget()
        self._connectMainButtonsToWinFilterChain()         
    
    def _connectMainButtonsToWinFilterChain(self):
        self.ui.saveButton.clicked.connect(self.winFilterChain.save_chain)
        self.ui.saveAsButton.clicked.connect(self.winFilterChain.save_chain_as)
        self.ui.createNewButton.clicked.connect(self.winFilterChain.new_chain)
        self.ui.previewButton.clicked.connect(self.addPreview)
        self.ui.upButton.clicked.connect(self.winFilterChain.moveUpSelectedFilter)
        self.ui.downButton.clicked.connect(self.winFilterChain.moveDownSelectedFilter)
        self.ui.openButton.clicked.connect(self.winFilterChain.open_chain)
        self.ui.removeButton.clicked.connect(self.winFilterChain.remove_filter)
        
    def _addDockWidget(self):
        self.addDockWidget(QtCore.Qt.DockWidgetArea.LeftDockWidgetArea,self.winFilter)        
        self.addDockWidget(QtCore.Qt.DockWidgetArea.LeftDockWidgetArea,self.winFilterSel.ui)
        
        
    def _addToolBar(self):
        self.ui = get_ui(self)
        self.toolbar = QtGui.QToolBar()
        self.addToolBar(self.toolbar)
        for widget in self.ui.children():
            if isinstance(widget, QtGui.QToolButton):
                self.toolbar.addWidget(widget)
            
    def addPreview(self):
        if self.winFilterChain.filterchain == None:
            return
        self.winViewer = WinViewer(self.winFilterChain.filterchain)
        self.addDockWidget(QtCore.Qt.DockWidgetArea.RightDockWidgetArea,self.winViewer.ui)
 def __init__(self):
     super(WinMain,self).__init__()
     
     self.source_list = imageproviders.load_sources()
     
     c = VisionManager()
 
     if not c.is_connected():
         print("Vision server is not accessible.")
         return
     
     #create and start server
     self.server = Server()
     self.server.start("127.0.0.1", 5030)        
     
     #create dockWidgets
     self.winFilterChain = WinFilterChain(c)
     self.winFilter = WinFilter()
     self.winFilterSel = WinFilterSel()
       
     self.setCentralWidget(self.winFilterChain.ui)      
      
     #connect action between dock widgets       
     self.winFilterSel.onAddFilter.connect(self.winFilterChain.add_filter)       
     self.winFilterChain.selectedFilterChanged.connect(self.winFilter.setFilter)
     
     self._addToolBar() 
     self._addDockWidget()
     self._connectMainButtonsToWinFilterChain()