Python gi.repository.GLib.PRIORITY_HIGH Examples

The following are 5 code examples of gi.repository.GLib.PRIORITY_HIGH(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.GLib , or try the search function .
Example #1
Source File: winetricks_cache_backup.py    From games_nebula with GNU General Public License v3.0 6 votes vote down vote up
def copy_files(self, file_name, action):

        if action == 'make_backup':
            command = ['cp', '-R', self.winetricks_cache + '/' + file_name, self.winetricks_cache_backup]
        elif action == 'restore_backup':
            command = ['cp', '-R', self.winetricks_cache_backup + '/' + file_name, self.winetricks_cache]

        self.pid, stdin, stdout, stderr = GLib.spawn_async(command,
                                    flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD,
                                    standard_output=True,
                                    standard_error=True)

        io = GLib.IOChannel(stdout)

        self.source_id_out = io.add_watch(GLib.IO_IN|GLib.IO_HUP,
                             self.watch_process,
                             'copy_files',
                             priority=GLib.PRIORITY_HIGH) 
Example #2
Source File: start.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def register_signal_handlers(callback):
    # When using plain signal.signal to install a signal handler, the GUI will not shutdown until it receives the
    # focus again. The following logic (inspired from https://stackoverflow.com/a/26457317) fixes this
    def install_glib_handler(sig):
        unix_signal_add = None

        if hasattr(GLib, "unix_signal_add"):
            unix_signal_add = GLib.unix_signal_add
        elif hasattr(GLib, "unix_signal_add_full"):
            unix_signal_add = GLib.unix_signal_add_full

        if unix_signal_add:
            unix_signal_add(GLib.PRIORITY_HIGH, sig, callback, sig)

    def idle_handler(*args):
        GLib.idle_add(callback, *args, priority=GLib.PRIORITY_HIGH)

    for signal_code in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]:
        signal.signal(signal_code, idle_handler)
        GLib.idle_add(install_glib_handler, signal_code, priority=GLib.PRIORITY_HIGH) 
Example #3
Source File: test_history.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def _test_multiple_undo_redo_bug_with_gui(gui):
    from gi.repository import GLib
    import rafcon.gui.singleton

    num_add = 10
    num_undo = 20
    num_redo = 20

    sm = StateMachine(HierarchyState())
    gui(rafcon.core.singleton.state_machine_manager.add_state_machine, sm)
    sm_m = list(rafcon.gui.singleton.state_machine_manager_model.state_machines.values())[-1]
    gui(sm_m.selection.set, [sm_m.root_state])

    main_window_controller = rafcon.gui.singleton.main_window_controller
    sm_id = sm_m.state_machine.state_machine_id
    state_machines_editor_ctrl = main_window_controller.state_machines_editor_ctrl
    gui(state_machines_editor_ctrl.get_controller(sm_id).view.get_top_widget().grab_focus)
    gui(state_machines_editor_ctrl.get_controller(sm_id).view.editor.grab_focus)
    def trigger_action_repeated(action_name, number):
        for _ in range(number):
            main_window_controller.shortcut_manager.trigger_action(action_name, None, None)
    gui(trigger_action_repeated, "add", num_add, priority=GLib.PRIORITY_HIGH)
    assert len(sm_m.history.modifications) == num_add + 1
    gui(trigger_action_repeated, "undo", num_undo, priority=GLib.PRIORITY_HIGH)
    gui.expected_warnings += max(num_undo - num_add, 0)
    gui(trigger_action_repeated, "redo", num_redo, priority=GLib.PRIORITY_HIGH)
    gui.expected_warnings += max(num_redo - min(num_add, num_undo), 0) 
Example #4
Source File: preset_list.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, preset_select_callback):
        super().__init__()
        self.set_size_request(width=UI_SETTINGS.preset_list_minimal_width, height=-1)

        self.preset_select_callback = preset_select_callback

        self.treestore = Gtk.TreeStore(str, str, str, bool)
        self.treeview = Gtk.TreeView(
            model=self.treestore, headers_visible=False
        )
        self.treeview.connect(
            "key-press-event", self._on_keypress
        )
        self.treeview.connect(
            "row-collapsed", self._on_row_collapsed
        )
        self.treeview.connect(
            "row-expanded", self._on_row_expanded
        )
        column = Gtk.TreeViewColumn(
            cell_renderer=Gtk.CellRendererText(), markup=self.DISPLAY_NAME
        )
        self.treeview.append_column(column)
        self.load_presets()

        self.add(self.treeview)

        GLib.idle_add(
            self.focus_first_available,
            priority=GLib.PRIORITY_HIGH
        )

    ###########################################################################
    # Public interface:
    ########################################################################### 
Example #5
Source File: daemon.py    From openrazer with GNU General Public License v2.0 4 votes vote down vote up
def _init_signals(self):
        """
        Heinous hack to properly handle signals on the mainloop. Necessary
        if we want to use the mainloop run() functionality.
        """
        def signal_action(signum):
            """
            Action to take when a signal is trapped
            """
            self.quit(signum)

        def idle_handler():
            """
            GLib idle handler to propagate signals
            """
            GLib.idle_add(signal_action, priority=GLib.PRIORITY_HIGH)

        def handler(*args):
            """
            Unix signal handler
            """
            signal_action(args[0])

        def install_glib_handler(sig):
            """
            Choose a compatible method and install the handler
            """
            unix_signal_add = None

            if hasattr(GLib, "unix_signal_add"):
                unix_signal_add = GLib.unix_signal_add
            elif hasattr(GLib, "unix_signal_add_full"):
                unix_signal_add = GLib.unix_signal_add_full

            if unix_signal_add:
                unix_signal_add(GLib.PRIORITY_HIGH, sig, handler, sig)
            else:
                print("Can't install GLib signal handler!")

        for sig in signal.SIGINT, signal.SIGTERM, signal.SIGHUP:
            signal.signal(sig, idle_handler)
            GLib.idle_add(install_glib_handler, sig, priority=GLib.PRIORITY_HIGH)