Ejemplo n.º 1
0
 def __init__(self):
     lib = cutil.find_library('v4lcapture')
     if lib is not None:
         self.v4l = cdll.LoadLibrary(lib)
         error.log('libv4lcapture.so shared library loaded')
     else:
         error.critical('cannot load libv4lcapture.so shared library')
Ejemplo n.º 2
0
 def __init__(self):
     lib = cutil.find_library("v4lcapture")
     if lib is not None:
         self.v4l = cdll.LoadLibrary(lib)
         error.log("libv4lcapture.so shared library loaded")
     else:
         error.critical("cannot load libv4lcapture.so shared library")
Ejemplo n.º 3
0
 def accept(self):
   '''
   Apply changes and hide window.
   '''
   self.route.execute(self.eth_cb.currentText())
   error.log('static route applied')
   self.hide()
Ejemplo n.º 4
0
 def apply(self):
   '''
   Apply changes.
   '''
   self.params.clear()
   self.params.set_attr('device', self.device_cb.currentText())
   self.root.capture()
   error.log('device change applied')
Ejemplo n.º 5
0
 def apply(self):
   '''
   Apply changes.
   '''
   self.captab.set()
   self.streamtab.set()
   self.root.capture()
   error.log('parameters changes applied')
Ejemplo n.º 6
0
 def _preferences(self):
     '''
 Create preference window.
 '''
     self.thread.ready.disconnect(self._preferences)
     self.pref = TabDialog(self.v4l, self.params, self.central)
     self.pref.setWindowTitle('Preferences')
     self.pref.setWindowIcon(QIcon.fromTheme('configure'))
     error.log('preferences window created')
Ejemplo n.º 7
0
 def _device(self):
   '''
   Create device choosing window.
   '''
   self.thread.ready.disconnect(self._device)
   self.dev = SimpleDialog(self.v4l, self.params, self.central)
   self.dev.setWindowTitle('Change capture board')
   self.dev.setWindowIcon(QIcon.fromTheme('preferences-desktop-multimedia'))
   error.log('device choosing window created')
Ejemplo n.º 8
0
 def _preferences(self):
   '''
   Create preference window.
   '''
   self.thread.ready.disconnect(self._preferences)
   self.pref = TabDialog(self.v4l, self.params, self.central)
   self.pref.setWindowTitle('Preferences')
   self.pref.setWindowIcon(QIcon.fromTheme('configure'))
   error.log('preferences window created')
Ejemplo n.º 9
0
 def set_attr(self, key, value):
     """
 Create or change an attribute into parameters dict.
 
 < key: string key to set
 < value: string/tuple paired with key
 """
     if key in self.VALID:
         self.params[key] = value
         error.log("{} changed to {}".format(key, value))
Ejemplo n.º 10
0
 def _toggleEncoding(self):
   self.enc_act.toggled.disconnect(self._toggleEncoding)
   self.params.toggle_encoding()
   if self.params.encoding():
     error.log('streaming started at {}'.format(self.v4l.getFilename()))
   else:
     error.log('streaming stopped')
   self._status()
   self.capture()
   self.enc_act.toggled.connect(self._toggleEncoding)
Ejemplo n.º 11
0
 def _device(self):
     '''
 Create device choosing window.
 '''
     self.thread.ready.disconnect(self._device)
     self.dev = SimpleDialog(self.v4l, self.params, self.central)
     self.dev.setWindowTitle('Change capture board')
     self.dev.setWindowIcon(
         QIcon.fromTheme('preferences-desktop-multimedia'))
     error.log('device choosing window created')
Ejemplo n.º 12
0
 def _toggleEncoding(self):
     self.enc_act.toggled.disconnect(self._toggleEncoding)
     self.params.toggle_encoding()
     if self.params.encoding():
         error.log('streaming started at {}'.format(self.v4l.getFilename()))
     else:
         error.log('streaming stopped')
     self._status()
     self.capture()
     self.enc_act.toggled.connect(self._toggleEncoding)
Ejemplo n.º 13
0
 def set_attr(self, key, value):
     '''
 Create or change an attribute into parameters dict.
 
 < key: string key to set
 < value: string/tuple paired with key
 '''
     if key in self.VALID:
         self.params[key] = value
         error.log('{} changed to {}'.format(key, value))
Ejemplo n.º 14
0
 def write(self):
   '''
   Writes the json config file.
   '''
   try:
     with open(self.PATH, 'w') as conf:
       json.dump(self.conf, conf, indent=4)
       error.log('changes written to {}'.format(self.PATH))
   except IOError:
     error.error('error writing to {}; changes not applied'.format(
         self.PATH))
Ejemplo n.º 15
0
 def execute(self, eth):
   '''
   Effectively execute the command with selected tool, using subprocess.
   
   < eth: the chosen eth interface
   '''
   cmd = self._build(eth)
   try:
     sp.check_call(cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
   except sp.CalledProcessError as e:
     if e.returncode == 2:
       error.log('static route for multicast streaming already set')
     else:
       error.error('cannot set static route for multicast streaming')
Ejemplo n.º 16
0
 def _read(self):
   '''
   Reads the json config file.
   If not found create a json object (dict).
   '''
   if path.isfile(self.PATH):
     try:
       with open(self.PATH, 'r') as conf:
         self.conf = json.load(conf)
         error.log('{} loaded'.format(self.PATH))
     except OSError:
       error.critical('cannot open {}'.format(self.PATH))
   else:
     self.conf = {}
Ejemplo n.º 17
0
 def capture(self):
     '''
 Instantiate new QThread to capture frames, waiting for previous to stop.
 '''
     if self.thread is not None:
         self.thread.quit()
         self.thread.wait()
     self.thread = thread.CaptureThread(self.app, self.v4l, self.params,
                                        self._updatePreview)
     self.thread.start()
     # update only if initialized
     try:
         self.thread.ready.connect(self.pref.update)
         self.thread.ready.connect(lambda: self._status(message=False))
     except AttributeError:
         pass
     error.log('capture thread created and started')
Ejemplo n.º 18
0
 def capture(self):
   '''
   Instantiate new QThread to capture frames, waiting for previous to stop.
   '''
   if self.thread is not None:
     self.thread.quit()
     self.thread.wait()
   self.thread = thread.CaptureThread(self.app, self.v4l, self.params,
       self._updatePreview)
   self.thread.start()
   # update only if initialized
   try:
     self.thread.ready.connect(self.pref.update)
     self.thread.ready.connect(lambda: self._status(message=False))
   except AttributeError:
     pass
   error.log('capture thread created and started')
Ejemplo n.º 19
0
 def closeEvent(self, event):
   '''
   Closes capture QThread when window is closed.
   Closes other windows open.
   Writes config.
   
   < event: closing event
   '''
   self.thread.quit()
   self.thread.wait()
   error.log('capture thread stopped')
   
   # close only if initialized
   try:
     self.dev.close()
     self.pref.close()
   except AttributeError:
     pass
   
   # close core log
   self.v4l.closeLog()
   error.log('core log closed')
Ejemplo n.º 20
0
    def closeEvent(self, event):
        '''
    Closes capture QThread when window is closed.
    Closes other windows open.
    Writes config.
    
    < event: closing event
    '''
        self.thread.quit()
        self.thread.wait()
        error.log('capture thread stopped')

        # close only if initialized
        try:
            self.dev.close()
            self.pref.close()
        except AttributeError:
            pass

        # close core log
        self.v4l.closeLog()
        error.log('core log closed')
Ejemplo n.º 21
0
 def __init__(self, conf, argv, v4l):
   '''
   Creates main window of the program.
   
   < conf: Config object
   < argv: command line options
   < v4l: v4l wrapper object
   '''
   # config and wrapper instance
   self.conf = conf
   self.v4l = v4l
   
   # thread: None for evaluating first execution
   self.params = thread.CaptureParams(self.conf)
   self.thread = None
   
   # application
   self.app = QApplication(argv)
   super(Window, self).__init__()
   
   ## title, icon and default size and position
   self.setWindowTitle('V4LCapture')
   iconpath = pkg.resource_filename('v4lcapture', 'v4lcapture.png')
   if path.isfile(iconpath):
     self.setWindowIcon(QIcon(iconpath))
   
   ## ui creation
   self._createUI()
   error.log('created main window')
   self._status(message=False)
   self._createPreview()
   self.capture()
   # route, device, preference (when thread is ready)
   self.thread.ready.connect(self._route)
   self.thread.ready.connect(self._device)
   self.thread.ready.connect(self._preferences)
   # visualize
   self.show()
Ejemplo n.º 22
0
    def __init__(self, conf, argv, v4l):
        '''
    Creates main window of the program.
    
    < conf: Config object
    < argv: command line options
    < v4l: v4l wrapper object
    '''
        # config and wrapper instance
        self.conf = conf
        self.v4l = v4l

        # thread: None for evaluating first execution
        self.params = thread.CaptureParams(self.conf)
        self.thread = None

        # application
        self.app = QApplication(argv)
        super(Window, self).__init__()

        ## title, icon and default size and position
        self.setWindowTitle('V4LCapture')
        iconpath = pkg.resource_filename('v4lcapture', 'v4lcapture.png')
        if path.isfile(iconpath):
            self.setWindowIcon(QIcon(iconpath))

        ## ui creation
        self._createUI()
        error.log('created main window')
        self._status(message=False)
        self._createPreview()
        self.capture()
        # route, device, preference (when thread is ready)
        self.thread.ready.connect(self._route)
        self.thread.ready.connect(self._device)
        self.thread.ready.connect(self._preferences)
        # visualize
        self.show()
Ejemplo n.º 23
0
 def toggle_encoding(self):
     '''
 Set encoding to true if false or the other way round.
 '''
     self.enc = not self.enc
     error.log('encoding set to {}'.format(self.enc))
Ejemplo n.º 24
0
 def _route(self):
     '''
 Create eth choosing window to add static route for streamings.
 '''
     self.route = RouteDialog(self.central)
     error.log('static route window created')
Ejemplo n.º 25
0
 def _route(self):
   '''
   Create eth choosing window to add static route for streamings.
   '''
   self.route = RouteDialog(self.central)
   error.log('static route window created')
Ejemplo n.º 26
0
 def toggle_encoding(self):
     """
 Set encoding to true if false or the other way round.
 """
     self.enc = not self.enc
     error.log("encoding set to {}".format(self.enc))