예제 #1
0
def on_focus_changed():
    """Show queued messages when a new window has been focused.

    Gets called when a new window has been focused.
    """
    while _QUEUED:
        msg = _QUEUED.pop()
        delta = datetime.datetime.now() - msg.time
        log.message.debug("Handling queued {} for window {}, delta {}".format(msg.method_name, msg.win_id, delta))
        try:
            bridge = _get_bridge(msg.win_id)
        except objreg.RegistryUnavailableError:
            # Non-mainwindow window focused.
            _QUEUED.append(msg)
            return
        if delta.total_seconds() < 1:
            text = msg.text
        else:
            text = "[{} ago] {}".format(utils.format_timedelta(delta), msg.text)
        getattr(bridge, msg.method_name)(text, *msg.args, **msg.kwargs)
예제 #2
0
def on_focus_changed():
    """Show queued messages when a new window has been focused.

    Gets called when a new window has been focused.
    """
    while _QUEUED:
        msg = _QUEUED.pop()
        delta = datetime.datetime.now() - msg.time
        log.message.debug("Handling queued {} for window {}, delta {}".format(
            msg.method_name, msg.win_id, delta))
        try:
            bridge = _get_bridge(msg.win_id)
        except objreg.RegistryUnavailableError:
            # Non-mainwindow window focused.
            _QUEUED.append(msg)
            return
        if delta.total_seconds() < 1:
            text = msg.text
        else:
            text = '[{} ago] {}'.format(utils.format_timedelta(delta),
                                        msg.text)
        getattr(bridge, msg.method_name)(text, *msg.args, **msg.kwargs)
예제 #3
0
 def test_format_seconds(self, td, out):
     """Test format_seconds with several tests."""
     assert utils.format_timedelta(td) == out
예제 #4
0
 def test_format_seconds(self):
     """Test format_seconds with several tests."""
     for td, out in self.TESTS:
         with self.subTest(td=td):
             self.assertEqual(utils.format_timedelta(td), out)
예제 #5
0
 def test_format_seconds(self, td, out):
     """Test format_seconds with several tests."""
     assert utils.format_timedelta(td) == out