Skip to content

Commit

Permalink
Fix PEP8 Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MaZderMind committed Jan 30, 2015
1 parent 1c3c18c commit 48c50e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 35 deletions.
1 change: 1 addition & 0 deletions python-api/gstswitch/connection.py
Expand Up @@ -152,6 +152,7 @@ def connect_dbus(self):
raise ConnectionError(new_message)

def signal_subscribe(self, signal_handler):
"""Subscribe to Signals on the bus"""
if not hasattr(signal_handler, '__call__'):
raise ValueError('Provided argument signal_handler is not callable')

Expand Down
95 changes: 60 additions & 35 deletions python-api/gstswitch/controller.py
Expand Up @@ -47,12 +47,12 @@ def __init__(
self.object_path = object_path
self.default_interface = default_interface

self.cbs_preview_port_added = []
self.cbs_preview_port_removed = []
self.cbs_new_mode_online = []
self.cbs_show_face_marker = []
self.cbs_show_track_marker = []
self.cbs_select_face = []
self.callbacks_preview_port_added = []
self.callbacks_preview_port_removed = []
self.callbacks_new_mode_online = []
self.callbacks_show_face_marker = []
self.callbacks_show_track_marker = []
self.callbacks_select_face = []

@property
def address(self):
Expand Down Expand Up @@ -163,15 +163,22 @@ def establish_connection(self):
self.connection.connect_dbus()
self.connection.signal_subscribe(self._signal_handler)

def _signal_handler(self, connection, sender_name, object_path, interface_name, signal_name, parameters, user_data):
def _signal_handler(self, connection, sender_name, object_path,
interface_name, signal_name, parameters, user_data):
"""Private Callback passed into Gio's signal_subscribe and called
for every signal arriving on the bus.
For params see Gio-Docs: <https://lazka.github.io/pgi-docs/#Gio-2.0/
classes/DBusConnection.html#Gio.DBusConnection.signal_subscribe>
"""
try:
cblist = getattr(self, 'cbs_'+signal_name)
if not isinstance(cblist, list):
callbacks = getattr(self, 'callbacks_'+signal_name)
if not isinstance(callbacks, list):
raise AttributeError()

unpack = parameters.unpack()
for cb in cblist:
cb(*unpack)
for callback in callbacks:
callback(*unpack)

except AttributeError:
pass
Expand Down Expand Up @@ -416,38 +423,56 @@ def parse_preview_ports(cls, res):
preview_ports.append(int(tupl[0]))
return preview_ports

def on_preview_port_added(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
def on_preview_port_added(self, callback):
"""Register a Callback for the preview_port_added Signal
"""

if not callable(callback):
raise ValueError('Provided argument callback is not callable')

self.callbacks_preview_port_added.append(callback)

def on_preview_port_removed(self, callback):
"""Register a Callback for the preview_port_removed Signal
"""

if not callable(callback):
raise ValueError('Provided argument callback is not callable')

self.cbs_preview_port_added.append(cb)
self.callbacks_preview_port_removed.append(callback)

def on_preview_port_removed(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
def on_new_mode_online(self, callback):
"""Register a Callback for the new_mode_online Signal
"""

self.cbs_preview_port_removed.append(cb)
if not callable(callback):
raise ValueError('Provided argument callback is not callable')

def on_new_mode_online(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
self.callbacks_new_mode_online.append(callback)

self.cbs_new_mode_online.append(cb)
def on_show_face_marker(self, callback):
"""Register a Callback for the show_face_marker Signal
"""

def on_show_face_marker(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
if not callable(callback):
raise ValueError('Provided argument callback is not callable')

self.cbs_show_face_marker.append(cb)
self.callbacks_show_face_marker.append(callback)

def on_show_track_marker(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
def on_show_track_marker(self, callback):
"""Register a Callback for the show_track_marker Signal
"""

self.cbs_show_track_marker.append(cb)
if not callable(callback):
raise ValueError('Provided argument callback is not callable')

self.callbacks_show_track_marker.append(callback)

def on_select_face(self, callback):
"""Register a Callback for the select_face Signal
"""

def on_select_face(self, cb):
if not callable(cb):
raise ValueError('Provided argument cb is not callable')
if not callable(callback):
raise ValueError('Provided argument callback is not callable')

self.cbs_select_face.append(cb)
self.callbacks_select_face.append(callback)
5 changes: 5 additions & 0 deletions python-api/gstswitch/helpers.py
Expand Up @@ -11,6 +11,11 @@
__all__ = ["TestSources", "PreviewSinks", "assert_no_segfault"]

def assert_no_segfault(serv):

"""Test is a closed Server-Processed died because of a SEGMENTATION
FAULT and print its Log if it did
"""

if serv.proc:
poll = serv.proc.poll()
if poll == -11:
Expand Down

0 comments on commit 48c50e0

Please sign in to comment.