Source code for pisak.handlers

"""
ClutterScript signal handler library. See also :module:`pisak.signals`.
"""
from gi.repository import Clutter, Gtk

import pisak
from pisak import signals


@signals.registered_handler("general/run_input_middleware")
[docs]def run_input_middleware(source): """ Run the current middleware. :param source: signal source. """ pisak.app.window.input_group.run_middleware()
@signals.registered_handler("general/stop_input_middleware")
[docs]def stop_input_middleware(source): """ Stop the middleware. Useful if the middleware is planned to be restarted. :param source: signal source. """ pisak.app.window.input_group.stop_middleware()
[docs]def connect_button(script, button_name, handler, *args): """ Function connecting the given button to a callback using the defalt signal. :param script: ClutterScript to get the button from. :param button_name: name of the given button. :param handler: callable handler. :param args: optional arguments to be passed to handler. """ button = script.get_object(button_name) if button is not None: # the only arguments that will optionally be passed to the handler are # 'args', default signal parameter emitted by the button # will be ignored by lambda button.connect("clicked", lambda source, *args_for_handler: handler(*args_for_handler), *args)
[docs]def button_to_view(window, script, button_name, view_to_load=None, data=None): """ Function connecting the given button to a callback loading the given view. :param stage: ClutterStage instance being the ancestor of the given button. :param script: ClutterScript to get the button from. :param button_name: name of the given button. :param view_to_load: name of the view to be loaded. :param data: optional data. """ button = script.get_object(button_name) if button is not None: if view_to_load is None: if window.type == "gtk": button.connect("clicked", lambda *_: Gtk.main_quit()) else: button.connect("clicked", lambda *_: window.stage.destroy()) else: button.connect("clicked", lambda *_: window.load_view(view_to_load, data))
@signals.registered_handler("data_source/next_data_set")
[docs]def next_data_set(data_source): """ Make the given data source to move to the next data set. :param data_source: data source. """ data_source.next_data_set()
@signals.registered_handler("data_source/previous_data_set")
[docs]def previous_data_set(data_source): """ Make the given data source to move to the previous data set. :param data_source: data source. """ data_source.previous_data_set()
@signals.registered_handler("playlist/next")
[docs]def move_next(playlist): """ Move to the next position on the given playlist. :param playlist: PisakPlaylist instance. """ playlist.move_next()
@signals.registered_handler("playlist/previous")
[docs]def move_previous(playlist): """ Move to the previous position on the given playlist. :param playlist: PisakPlaylist instance. """ playlist.move_previous()
@signals.registered_handler("playlist/play")
[docs]def play(playlist): """ Start playing the current media item on the given playlist. :param playlist: PisakPlaylist instance. """ playlist.move_focus(and_play=True)
@signals.registered_handler("playlist/stop")
[docs]def stop(playlist): """ Stop playing of the given playlist. :param playlist: PisakPlaylist instance. """ playlist.stop()
@signals.registered_handler("playlist/pause")
[docs]def pause(playlist): """ Pause playing the current media item on the given playlist. :param playlist: PisakPlaylist instance. """ playlist.pause()
@signals.registered_handler("playlist/toggle_looped")
[docs]def toggle_looped(playlist): """ Turn on or turn off the looped mode of the given playlist. :param playlist: PisakPlaylist instance. """ playlist.looped = not playlist.looped
@signals.registered_handler("playlist/toggle_random_order")
[docs]def toggle_random_order(playlist): """ Turn on or turn off the random order of playing the items on the given playlist. :param playlist: PisakPlaylist instance. """ playlist.random_order = not playlist.random_order
@signals.registered_handler("playlist/toggle_play")
[docs]def toggle_play(playlist): """ Start or pause playing the current media item on the given playlist, basing on the current item state. :param playlist: PisakPlaylist instance. """ if playlist.is_playing(): playlist.pause() else: playlist.move_focus(and_play=True)
@signals.registered_handler("media/toggle_play")
[docs]def toggle_play_media(player): """ Start or pause playing the current media stream, basing on the current state. :param player: PisakMediaPlayback instance. """ if player.is_playing(): player.pause() else: player.play()
@signals.registered_handler("media/play")
[docs]def play_media(player): """ Start playing the media playback. :param player: media player instance. """ player.play()
@signals.registered_handler("media/stop")
[docs]def stop_media(player): """ Stop playing the media playback. :param player: media player instance. """ player.stop()
@signals.registered_handler("media/pause")
[docs]def pause_media(player): """ Pause playing the media playback. :param player: media player instance. """ player.pause()
@signals.registered_handler("media/increase_volume")
[docs]def increase_volume(player): """ Increase volume of the media playback. :param player: media player instance. """ player.increase_volume()
@signals.registered_handler("media/decrease_volume")
[docs]def decrease_volume(player): """ Decrease volume of the media playback. :param player: media player instance. """ player.decrease_volume()
@signals.registered_handler("media/skip_forward")
[docs]def skip_forward(player): """ Skip the media playback forward. :param player: media player instance. """ player.skip_forward()
@signals.registered_handler("media/skip_backward")
[docs]def skip_backward(player): """ Skip the media playback backward. :param player: media player instance. """ player.skip_backward()
@signals.registered_handler("media/toggle_rewind_forward")
[docs]def toggle_rewind_forward(player): """ Start or stop rewinding of the media playback forward. :param player: media player instance. """ player.toggle_rewind_forward()
@signals.registered_handler("media/toggle_rewind_backward")
[docs]def toggle_rewind_backward(player): """ Start or stop rewinding of the media playback backward. :param player: media player instance. """ player.toggle_rewind_backward()
@signals.registered_handler("general/exit")
[docs]def exit_app(source): """ Destroy stage of the given element. :param source: element whose stage should be destroyed. """ source.get_stage().destroy()
@signals.registered_handler("general/start_group")
[docs]def start_group(source): """ Start scanning group. :param source: signal source. """ if source.get_property("mapped"): source.start_cycle()
@signals.registered_handler("general/kill_group")
[docs]def kill_group(source): """ Stop scanning group, fatally. :param source: signal source. """ source.killed = True
@signals.registered_handler("scanning/toggle_pause_group")
[docs]def toggle_pause_group(source): """ Pause or restart to scan group. :param source: signal source. """ source.paused = not source.paused
@signals.registered_handler("scanning/unpause_group")
[docs]def unpause_group(source): """ Unpause the scanning of a group. :param source: signal source. """ source.paused = False
@signals.registered_handler("pager/scan_page")
[docs]def scan_page(pager): """ Start scanning the current page of the given pager. :param pager: pisak pager instance. """ pager.scan_page()
@signals.registered_handler("pager/next_page")
[docs]def next_page(pager): """ Move to the next page of the given pager. :param pager: pisak pager instance. """ pager.next_page()
@signals.registered_handler("pager/previous_page")
[docs]def previous_page(pager): """ Move to the previous page of the given pager. :param pager: pisak pager instance. """ pager.previous_page()
@signals.registered_handler("pager/toggle_automatic")
[docs]def toggle_automatic(pager): """ Turn on or turn off the automatic mode of pages flipping. :param pager: pisak pager instance. """ if not pager.is_running: pager.run_automatic() else: pager.stop_automatic()
@signals.registered_handler("scanning/set_pending_group")
[docs]def set_pending_group(group): """ Set the given group strategy's unwind to as the group's parent group. Set the given group as a pending group of its window. :param group: pisak scanning group instance. """ group.parent_group = group.strategy.unwind_to pisak.app.window.pending_group = group
@signals.registered_handler("general/switch_label")
[docs]def switch_label(button): """ Switch label on the given button. :param button: pisak button instance. """ button.switch_label()
@signals.registered_handler("general/switch_icon")
[docs]def switch_icon(button): """ Switch icon on the given button. :param button: pisak button instance. """ button.switch_icon()
@signals.registered_handler("general/toggle_toggle")
[docs]def toggle_toggle(button): """ Turn on or off the toggled state of the given button. :param button: pisak button instance. """ if button.is_toggled(): button.untoggle() else: button.toggle()
@signals.registered_handler("general/untoggle")
[docs]def untoggle(button): """ Turn off the toggled state of the given button. :param button: pisak button instance. """ button.untoggle()
@signals.registered_handler("general/toggle")
[docs]def toggle(button): """ Turn on the toggled state of the given button. :param button: pisak button instance. """ button.toggle()
@signals.registered_handler("general/set_working")
[docs]def set_working(button): """ Turn on the working state of the given button. :param button: pisak button instance. """ button.set_working()
@signals.registered_handler("general/set_unworking")
[docs]def set_unworking(button): """ Turn off the working state of the given button. :param button: pisak button instance. """ button.set_unworking()
@signals.registered_handler("general/toggle_working")
[docs]def toggle_working(button): """ Turn on or turn off the working state of the given button. :param button: pisak button instance. """ if button.is_working(): button.set_unworking() else: button.set_working()