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')
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")
def accept(self): ''' Apply changes and hide window. ''' self.route.execute(self.eth_cb.currentText()) error.log('static route applied') self.hide()
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')
def apply(self): ''' Apply changes. ''' self.captab.set() self.streamtab.set() self.root.capture() error.log('parameters changes applied')
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')
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')
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))
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)
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')
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))
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))
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')
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 = {}
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')
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')
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()
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))
def _route(self): ''' Create eth choosing window to add static route for streamings. ''' self.route = RouteDialog(self.central) error.log('static route window created')
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))