Python gi.repository.GLib.PRIORITY_LOW Examples

The following are 10 code examples of gi.repository.GLib.PRIORITY_LOW(). 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: logging_console.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def print_message(self, message, log_level):
        with self._lock:
            if log_level <= log.logging.VERBOSE and self._enables.get('VERBOSE', False):
                GLib.idle_add(self.print_to_text_view, message, self.filtered_buffer, "debug",
                              priority=GLib.PRIORITY_LOW)
            if log.logging.VERBOSE < log_level <= log.logging.DEBUG and self._enables.get('DEBUG', True):
                GLib.idle_add(self.print_to_text_view, message, self.filtered_buffer, "debug",
                              priority=self.logging_priority)
            elif log.logging.DEBUG < log_level <= log.logging.INFO and self._enables.get('INFO', True):
                GLib.idle_add(self.print_to_text_view, message, self.filtered_buffer, "info",
                              priority=self.logging_priority)
            elif log.logging.INFO < log_level <= log.logging.WARNING and self._enables.get('WARNING', True):
                GLib.idle_add(self.print_to_text_view, message, self.filtered_buffer, "warning",
                              priority=self.logging_priority)
            elif log.logging.WARNING < log_level and self._enables.get('ERROR', True):
                GLib.idle_add(self.print_to_text_view, message, self.filtered_buffer, "error",
                              priority=self.logging_priority) 
Example #2
Source File: PlayerListPanel.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def onPlayerRemoved(self, players, player):
        def do_onPlayerRemoved(players, player):
            log.debug("%s" % player,
                      extra={"task": (self.connection.username,
                                      "PTS.onPlayerRemoved")})
            if player not in self.players:
                return
            if self.store.iter_is_valid(self.players[player]["ti"]):
                self.store.remove(self.players[player]["ti"])
            for key in ("status", "game", "titles"):
                if player.handler_is_connected(self.players[player][key]):
                    player.disconnect(self.players[player][key])
            if player.game and "private" in self.players[player] and \
                    player.game.handler_is_connected(self.players[player]["private"]):
                player.game.disconnect(self.players[player]["private"])
            if player.handler_is_connected(self.players[player]["ratings"]):
                player.disconnect(self.players[player]["ratings"])
            del self.players[player]
            count = len(self.players)
            self.widgets["playersOnlineLabel"].set_text(_("Players: %d") % count)

        GLib.idle_add(do_onPlayerRemoved, players, player, priority=GLib.PRIORITY_LOW) 
Example #3
Source File: gtk.py    From kickoff-player with GNU General Public License v3.0 5 votes vote down vote up
def run_generator(function):
  gen = function()
  GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW) 
Example #4
Source File: logging_console.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self):
        View.__init__(self)

        self._lock = threading.Lock()

        self.text_view = Gtk.TextView()
        self.text_view.set_property('editable', False)

        self.filtered_buffer = self.create_text_buffer()

        self.text_view.set_buffer(self.filtered_buffer)

        self.text_view.set_border_window_size(Gtk.TextWindowType.LEFT, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.RIGHT, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.TOP, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.BOTTOM, 10)

        self._enables = {}
        self._auto_scroll_handler_id = None

        scrollable = Gtk.ScrolledWindow()
        scrollable.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrollable.set_name('console_scroller')
        scrollable.add(self.text_view)
        self.text_view.show()

        self['scrollable'] = scrollable
        self.top = 'scrollable'
        self.quit_flag = False

        self.logging_priority = global_gui_config.get_config_value("LOGGING_CONSOLE_GTK_PRIORITY", GLib.PRIORITY_LOW)

        self._stored_line_number = None
        self._stored_line_offset = None
        self._stored_text_of_line = None
        self._stored_relative_lines = None 
Example #5
Source File: GameListPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def onGameAdd(self, games, new_games):
        game_store = {}
        for game in new_games:
            game_store[game] = (game, self.clearpix,
                                game.wplayer.name + game.wplayer.display_titles(),
                                game.wplayer.getRatingForCurrentGame(),
                                game.bplayer.name + game.bplayer.display_titles(),
                                game.bplayer.getRatingForCurrentGame(),
                                game.display_text, game.display_rated)

        def do_onGameAdd(games, new_games, game_store):
            for game in new_games:
                # game removed before we finish processing "games /bslwBzSLx"
                if game not in game_store:
                    continue
                # log.debug("%s" % game,
                # extra={"task": (self.connection.username, "GTS.onGameAdd")})
                ti = self.store.append(game_store[game])
                self.games[game] = {"ti": ti}
                self.games[game]["private_cid"] = game.connect(
                    "notify::private", self.private_changed)
                self._update_gamesrunning_label()

        GLib.idle_add(do_onGameAdd,
                      games,
                      new_games,
                      game_store,
                      priority=GLib.PRIORITY_LOW) 
Example #6
Source File: GameListPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def onGameRemove(self, games, game):
        def do_onGameRemove(games, game):
            log.debug(
                "%s" % game,
                extra={"task": (self.connection.username, "GTS.onGameRemove")})
            if game not in self.games:
                return
            if self.store.iter_is_valid(self.games[game]["ti"]):
                self.store.remove(self.games[game]["ti"])
            if game.handler_is_connected(self.games[game]["private_cid"]):
                game.disconnect(self.games[game]["private_cid"])
            del self.games[game]
            self._update_gamesrunning_label()

        GLib.idle_add(do_onGameRemove, games, game, priority=GLib.PRIORITY_LOW) 
Example #7
Source File: FICSObjects.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def online_changed(self, player, prop):
        if player.online:
            GLib.idle_add(self.emit,
                          "FICSPlayerEntered",
                          [player, ],
                          priority=GLib.PRIORITY_LOW)

    # This method is a temporary hack until ChatWindow/ChatManager are
    # converted to use FICSPlayer references rather than player's names 
Example #8
Source File: stats_counter.py    From Apostrophe with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, callback):
        super().__init__()

        # Worker process to handle counting.
        self.counting = False
        self.count_pending_text = None
        self.parent_conn, child_conn = Pipe()
        Process(target=self.do_count, args=(child_conn,), daemon=True).start()
        GLib.io_add_watch(
            self.parent_conn.fileno(), GLib.PRIORITY_LOW, GLib.IO_IN, self.on_counted, callback) 
Example #9
Source File: gui_functions.py    From RAFCON with Eclipse Public License 1.0 4 votes vote down vote up
def call_gui_callback(callback, *args, **kwargs):
    """Wrapper method for GLib.idle_add

    This method is intended as replacement for idle_add. It wraps the method with a callback option. The advantage is
    that this way, the call is blocking. The method return, when the callback method has been called and executed.

    :param callback: The callback method, e.g. on_open_activate
    :param args: The parameters to be passed to the callback method
    """
    from future.utils import raise_
    from threading import Condition
    import sys
    from rafcon.utils import log
    global exception_info, result
    from gi.repository import GLib
    condition = Condition()
    exception_info = None

    @log.log_exceptions()
    def fun():
        """Call callback and notify condition variable
        """
        global exception_info, result
        result = None
        try:
            result = callback(*args, **kwargs)
        except:
            # Exception within this asynchronously called function won't reach pytest. This is why we have to store
            # the information about the exception to re-raise it at the end of the synchronous call.
            exception_info = sys.exc_info()
        finally:  # Finally is also executed in the case of exceptions
            condition.acquire()
            condition.notify()
            condition.release()

    if "priority" in kwargs:
        priority = kwargs.pop("priority")
    else:
        priority = GLib.PRIORITY_LOW

    with condition:
        GLib.idle_add(fun, priority=priority)
        # Wait for the condition to be notified
        # TODO: implement timeout that raises an exception
        condition.wait()
    if exception_info:
        e_class, e_instance, e_traceback = exception_info
        raise_(e_instance, None, e_traceback)
    return result 
Example #10
Source File: PlayerListPanel.py    From pychess with GNU General Public License v3.0 4 votes vote down vote up
def onPlayerAdded(self, players, new_players):
        # Let the hard work to be done in the helper connection thread
        np = {}
        for player in new_players:
            np[player] = (player, player.getIcon(),
                          player.name + player.display_titles(), player.blitz,
                          player.standard, player.lightning,
                          player.display_status,
                          get_player_tooltip_text(player))

        def do_onPlayerAdded(players, new_players, np):
            for player in new_players:
                # log.debug("%s" % player,
                # extra={"task": (self.connection.username,
                # "PTS.onPlayerAdded")})
                if player in self.players:
                    # log.warning("%s already in self" % player,
                    # extra={"task": (self.connection.username,
                    # "PTS.onPlayerAdded")})
                    continue

                # player can leave before we finish processing "who IbslwBzSLx"
                if player not in np:
                    continue

                self.players[player] = {}

                self.players[player]["ti"] = self.store.append(np[player])
                self.players[player]["status"] = player.connect(
                    "notify::status", self.status_changed)
                self.players[player]["game"] = player.connect(
                    "notify::game", self.status_changed)
                self.players[player]["titles"] = player.connect(
                    "notify::titles", self.titles_changed)
                if player.game:
                    self.players[player]["private"] = player.game.connect(
                        "notify::private", self.private_changed, player)
                self.players[player]["ratings"] = player.connect(
                    "ratings_changed", self.elo_changed, player)

            count = len(self.players)
            self.widgets["playersOnlineLabel"].set_text(_("Players: %d") %
                                                        count)

            return False

        GLib.idle_add(do_onPlayerAdded,
                      players,
                      new_players,
                      np,
                      priority=GLib.PRIORITY_LOW)