Exemplo n.º 1
0
    def set_metaworld_tree( self, tree ):
        #assert tree is not None
        #assert tree.meta == self._meta_tree, (tree.meta, self._meta_tree)
        # setup event listener for the tree
# Notes: somehow the tree remain empty if we do not allow setting twice. To investigate...
#        if tree == self._metaworld_tree:
#            return
        if self._metaworld_tree is not None:
            self._metaworld_tree.disconnect_from_element_events( 
                self._onElementAdded, self._onElementUpdated,
                self._onElementAboutToBeRemoved )
            louie.disconnect( self._on_element_issues_updated, 
                              metaworldui.ElementIssuesUpdated,
                              self._metaworld_tree.world )
        self._metaworld_tree = tree
        self._issue_tracker = tree is not None and tree.world or None
        if tree is not None:
            self._metaworld_tree.connect_to_element_events( 
                self._onElementAdded, self._onElementUpdated,
                self._onElementAboutToBeRemoved )
            louie.connect( self._on_element_issues_updated, 
                           metaworldui.ElementIssuesUpdated,
                           self._metaworld_tree.world )
            self._refreshTreeRoot()
        else:
            self.clear()
Exemplo n.º 2
0
    def configure(self, match):
        """ Configures the playing field using the supplied GameConfig """
        self.match = match
        self.game = match.next_game()
        self.player = Player('You', 'blue', self.game_config)
        self.rules = self.game.rules
        self.foundation_piles = FoundationPiles(self.player,
                                                self.rules,
                                                self.game_config.num_players)
        self.status_bar = StatusBar(self.player, match)
        self.players = [self.player]
        self.humans = [self.player]

        for i in range(self.game_config.num_players-len(self.humans)):
            self.players.append(self.make_computer(i))

        assert(len(self.players) >= 2 and len(self.players) <= 4)

        louie.connect(self.on_game_over, Player.finished)

        self.drawables = [self.foundation_piles, self.status_bar]
        self.drawables.extend(self.players)
        self.handlers = [self.player, self.foundation_piles]
        self.updateables = [self.foundation_piles]
        self.updateables.extend(self.players)
Exemplo n.º 3
0
 def __init__(self):
   self.binds = []    
   self.event = louie.Signal()
   self.app = HotKeyApp.alloc().init()
   
   louie.connect(self.on_key, HotKeyApp.event)
   louie.connect(self.on_launched, HotKeyApp.launched)
Exemplo n.º 4
0
 def test_qt_plugin():
     louie.reset()
     # Create receivers.
     class Receiver(qt.QWidget):
         def __init__(self):
             qt.QObject.__init__(self)
             self.args = []
         def receive(self, arg):
             self.args.append(arg)
     receiver1 = Receiver()
     receiver2 = Receiver()
     # Connect signals.
     louie.connect(receiver1.receive, 'sig')
     louie.connect(receiver2.receive, 'sig')
     # Destroy receiver2 so only a shell is left.
     receiver2.close(True)
     # Check reception without plugins.
     louie.send('sig', arg='foo')
     assert receiver1.args == ['foo']
     assert receiver2.args == ['foo']
     # Install plugin.
     plugin = louie.QtWidgetPlugin()
     louie.install_plugin(plugin)
     # Check reception with plugins.
     louie.send('sig', arg='bar')
     assert receiver1.args == ['foo', 'bar']
     assert receiver2.args == ['foo']
Exemplo n.º 5
0
    def setupControls(self, controls, name, curve, slider):
        box = gtk.VBox()
        controls.add(box)
        
        txt = "curve '%s'" % name
        if len(name) > 7:
            txt = name
        curve_name_label = gtk.Label(txt)
        box.pack_start(curve_name_label)

        bools = gtk.HBox()
        box.pack_start(bools)
        self.collapsed = gtk.CheckButton("C")
        bools.pack_start(self.collapsed)
        self.collapsed.connect("toggled", self.update_ui_to_collapsed_state)
        self.hideWhenCollapsed = [bools]
        self.muted = gtk.CheckButton("M")
        
        bools.pack_start(self.muted)
        self.muted.connect("toggled", self.sync_mute_to_curve)
        dispatcher.connect(self.mute_changed, 'mute changed', sender=curve)

        self.sliderLabel = None
        if slider is not None:
            # slider should have a checkbutton, defaults to off for
            # music tracks
            self.sliderLabel = gtk.Label("Slider %s" % slider)
            box.pack_start(self.sliderLabel)
Exemplo n.º 6
0
    def test_qt_plugin():
        louie.reset()

        # Create receivers.
        class Receiver(qt.QWidget):
            def __init__(self):
                qt.QObject.__init__(self)
                self.args = []

            def receive(self, arg):
                self.args.append(arg)

        receiver1 = Receiver()
        receiver2 = Receiver()
        # Connect signals.
        louie.connect(receiver1.receive, 'sig')
        louie.connect(receiver2.receive, 'sig')
        # Destroy receiver2 so only a shell is left.
        receiver2.close(True)
        # Check reception without plugins.
        louie.send('sig', arg='foo')
        assert receiver1.args == ['foo']
        assert receiver2.args == ['foo']
        # Install plugin.
        plugin = louie.QtWidgetPlugin()
        louie.install_plugin(plugin)
        # Check reception with plugins.
        louie.send('sig', arg='bar')
        assert receiver1.args == ['foo', 'bar']
        assert receiver2.args == ['foo']
Exemplo n.º 7
0
    def connect(self):
        self.handlers = []

        for button in self.buttons:
            on_click = self.make_on_click(button)
            self.handlers.append(on_click)
            louie.connect(on_click, Button.clicked, button)
Exemplo n.º 8
0
 def _on_active_world_change(self, active_world):
     """Refresh a tree view with the new root element."""
     if active_world!=self._active_world:
         self._active_world = active_world
         model = self.model()
         # disconnect for previous world selection events
         if model is not None and model.metaworld_tree is not None:
             old_world = model.metaworld_tree.world
             louie.disconnect( self._on_selection_change, metaworldui.WorldSelectionChanged,
                               old_world )
         # connect to new world selection events & refresh tree view
         if model is None or active_world is None:
             model.set_metaworld_tree( None )
             #self.clear()
         else:
             model_tree = active_world.find_tree( model.meta_tree )
             if model_tree is not None:
                 louie.connect( self._on_selection_change, metaworldui.WorldSelectionChanged,
                                active_world )
                 model.set_metaworld_tree( model_tree )
                 self._expand_roots()
                 self.resizeColumnToContents(0)
                 self.show()
             else: # the new world has no tree of the type of the view
                 self.hide()
Exemplo n.º 9
0
 def __init__(self, locator):
     self.locator = locator
     self.messages = []
     louie.connect(self.onEvent, 'hub:status')
     louie.connect(self.onEvent, 'hub:global_to')
     louie.connect(self.onEvent, 'hub:to')
     louie.connect(self.onEvent, 'hub:sent_to')
     louie.connect(self.onEvent, 'hub:chat')
Exemplo n.º 10
0
 def __init__(self, term, hubIds=None, maxsize=None, minsize=None, filetype=1):
     self.term = term 
     self.hubIds = hubIds
     self.maxsize = maxsize
     self.minsize = minsize
     self.filetype = filetype
     self.deferreds = []
     louie.connect(self.filter, 'search:result:raw')
Exemplo n.º 11
0
 def __init__( self, *args ):
     QtGui.QStandardItemModel.__init__( self, *args )
     self._element = None
     self._element_tree = None
     self._active_world = None
     # Selection change event are on a per world basis, so listen for the current world
     louie.connect( self._on_active_world_change, metaworldui.ActiveWorldChanged )
     self._resetPropertyListModel()
Exemplo n.º 12
0
 def subscribe_for_variable(self, var_name, instance=0, callback=None, signal=False):
     variable = self.get_state_variable(var_name)
     if variable:
         if callback != None:
             if signal == True:
                 callback(variable)
                 louie.connect(callback, signal='Coherence.UPnP.StateVariable.%s.changed' % var_name, sender=self)
             else:
                 variable.subscribe(callback)
Exemplo n.º 13
0
    def cmd_search(self, term, kwargs):
        # the keys will be unicode() objects
        kwargs = dict([(str(key), item) for key, item in kwargs.items()])
        kwargs['priority'] = 100

        times, searchFilter = self.searchHerder.search(term, **kwargs)
        self.searchFilters.append(searchFilter)
        louie.connect(self.onSearchResult, 'search:result', searchFilter)
        return [id(searchFilter), times]
Exemplo n.º 14
0
    def test_handleTo(self):
        self.proto.hubId = "127.0.0.1:4242"
        message = u"<Kryten> The commands available to you are:\r\n\r\n(just type "

        def _(peer, sent_at, msg):
            louie.disconnect(_, "hub:to")
            self.assertEqual(message, msg)

        louie.connect(_, "hub:to")
        self._hubSends("$To: iamferret From: Kryten $%s|" % (message,))
Exemplo n.º 15
0
 def __init__( self, world, queue_depth = 0 ):
     """world: world that is tracked for change.
        is_dirty: is the world initially considered has dirty (new world for example).
     """
     self.__world = world
     self.__queue_depth = queue_depth
     self.__undo_queue = []
     self.__redo_queue = []
     self.__active = True
     louie.connect( self.__on_tree_added, metaworld.TreeAdded, world )
Exemplo n.º 16
0
 def __init__( self, world, is_dirty = False ):
     """world: world that is tracked for change.
        is_dirty: is the world initially considered has dirty (new world for example).
     """
     self.__world = world
     if is_dirty:
         self.__dirty_tree_metas = set( self.__world.meta.trees )
     else:
         self.__dirty_tree_metas = set()
     louie.connect( self.__on_tree_added, metaworld.TreeAdded, world )
Exemplo n.º 17
0
 def __init__(self, world):
     """world: world that is tracked for change.
     """
     self.__world = world
     louie.connect(self.__on_tree_added, metaworld.TreeAdded, world)
     louie.connect(self.__on_refresh_element_status, RefreshElementIssues)
     self._issues_by_element = {}  #dict element:(child,attribute,node)
     self._pending_full_check = set()
     self._pending_updated = set()
     self._modified_issues = set()
Exemplo n.º 18
0
 def __init__(self, world, queue_depth=0):
     """world: world that is tracked for change.
        is_dirty: is the world initially considered has dirty (new world for example).
     """
     self.__world = world
     self.__queue_depth = queue_depth
     self.__undo_queue = []
     self.__redo_queue = []
     self.__active = True
     louie.connect(self.__on_tree_added, metaworld.TreeAdded, world)
Exemplo n.º 19
0
 def __init__(self, world, is_dirty=False):
     """world: world that is tracked for change.
        is_dirty: is the world initially considered has dirty (new world for example).
     """
     self.__world = world
     if is_dirty:
         self.__dirty_tree_metas = set(self.__world.meta.trees)
     else:
         self.__dirty_tree_metas = set()
     louie.connect(self.__on_tree_added, metaworld.TreeAdded, world)
Exemplo n.º 20
0
 def __init__( self, world ):
     """world: world that is tracked for change.
     """
     self.__world = world
     louie.connect( self.__on_tree_added, metaworld.TreeAdded, world )
     louie.connect( self.__on_refresh_element_status, RefreshElementIssues )
     self._issues_by_element = {} #dict element:(child,attribute,node)
     self._pending_full_check = set()
     self._pending_updated = set()
     self._modified_issues = set()
 def test_robust(self):
     """Test the sendRobust function."""
     def fails():
         raise ValueError('this')
     a = object()
     signal = 'this'
     louie.connect(fails, louie.All, a)
     result = louie.send_robust('this', a, a=a)
     err = result[0][1]
     assert isinstance(err, ValueError)
     assert err.args == ('this', )
Exemplo n.º 22
0
 def test_Exact(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, signal, a)
     expected = [(x, a)]
     result = louie.send('this', a, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:{0}\n\tgot:{1}"
             .format(expected, result))
     louie.disconnect(x, signal, a)
     assert len(list(louie.get_all_receivers(a, signal))) == 0
     self._isclean()
 def test_AllRegistration(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, louie.All, a)
     expected = [(x, a)]
     result = louie.send('this', a, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s"
         % (expected, result))
     louie.disconnect(x, louie.All, a)
     assert len(list(louie.get_all_receivers(a, louie.All))) == 0
     self._isclean()
 def test_AnonymousSend(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, signal)
     expected = [(x, a)]
     result = louie.send(signal, None, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s"
         % (expected, result))
     louie.disconnect(x, signal)
     assert len(list(louie.get_all_receivers(None, signal))) == 0
     self._isclean()
Exemplo n.º 25
0
 def test_AnonymousSend(self):
     a = Dummy()
     signal = "this"
     louie.connect(x, signal)
     expected = [(x, a)]
     result = louie.send(signal, None, a=a)
     assert (
         result == expected
     ), f"Send didn't return expected result:\n\texpected:{expected}\n\tgot:{result}"
     louie.disconnect(x, signal)
     assert len(list(louie.get_all_receivers(None, signal))) == 0
     self._isclean()
Exemplo n.º 26
0
 def test_Exact(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, signal, a)
     expected = [(x, a)]
     result = louie.send('this', a, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:{0}\n\tgot:{1}".
         format(expected, result))
     louie.disconnect(x, signal, a)
     assert len(list(louie.get_all_receivers(a, signal))) == 0
     self._isclean()
Exemplo n.º 27
0
 def test_AllRegistration(self):
     a = Dummy()
     signal = "this"
     louie.connect(x, louie.All, a)
     expected = [(x, a)]
     result = louie.send(signal, a, a=a)
     assert (
         result == expected
     ), f"Send didn't return expected result:\n\texpected:{expected}\n\tgot:{result}"
     louie.disconnect(x, louie.All, a)
     assert len(list(louie.get_all_receivers(a, louie.All))) == 0
     self._isclean()
Exemplo n.º 28
0
    def __init__(self, playing_field):
        self.playing_field = playing_field
        self.screen = GameOverScreen()
        self.screen.create_ui(self.playing_field.game_score_summary(),
                              self.playing_field.set_score_summary())

        louie.connect(self.new_game, GameOverScreen.new_game)
        louie.connect(self.escape_pressed, GameOverScreen.escape_pressed)

        self.drawables = [self.playing_field, self.screen]
        self.handlers = [self.screen]
        self.updateables = [self.screen]
Exemplo n.º 29
0
    def __init__(self, application):
        self.application = application

        self.hubClientFactory = protocol.ClientCreator(reactor, self.protocol, application=self.application)
        
        # key: hubId, v: hubprotocol instance
        self.hubs = {}

        # key: hubId, v: current status
        self.activeHubs = {}
        louie.connect(self.onHubStatus, 'hub:status')
        louie.connect(self.onHubQuit, 'hub:quit')
Exemplo n.º 30
0
 def test_AllRegistration(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, louie.All, a)
     expected = [(x, a)]
     result = louie.send('this', a, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" %
         (expected, result))
     louie.disconnect(x, louie.All, a)
     assert len(list(louie.get_all_receivers(a, louie.All))) == 0
     self._isclean()
Exemplo n.º 31
0
 def test_AnonymousSend(self):
     a = Dummy()
     signal = 'this'
     louie.connect(x, signal)
     expected = [(x, a)]
     result = louie.send(signal, None, a=a)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" %
         (expected, result))
     louie.disconnect(x, signal)
     assert len(list(louie.get_all_receivers(None, signal))) == 0
     self._isclean()
Exemplo n.º 32
0
    def test_robust(self):
        """Test the sendRobust function."""
        def fails():
            raise ValueError("this")

        a = object()
        signal = "this"
        louie.connect(fails, louie.All, a)
        result = louie.send_robust(signal, a, a=a)
        err = result[0][1]
        assert isinstance(err, ValueError)
        assert err.args == ("this", )
Exemplo n.º 33
0
 def __init__(self, multivisor):
     self.multivisor = multivisor
     self.commands = Commands(multivisor)
     status = self.multivisor.status
     words = list(status['processes'].keys())
     words.extend(self.commands.get_commands())
     completer = WordCompleter(words)
     self.session = Prompt(completer=completer,
                           bottom_toolbar=self.toolbar,
                           key_bindings=self.keys)
     self.session.app.commands = self.commands
     self.__update_toolbar()
     louie.connect(self.__update_toolbar, sender=self.multivisor)
Exemplo n.º 34
0
    def watchCurveAreaHeight(self):
        def sizeEvent(w, size):
            # this is firing really often
            if self.visibleHeight == size.height:
                return
            log.debug("size.height is new: %s", size.height)
            self.visibleHeight = size.height
            self.setRowHeights()

        visibleArea = self.curvesVBox.get_parent().get_parent()
        visibleArea.connect('size-allocate', sizeEvent)

        dispatcher.connect(self.setRowHeights, "curve row focus change")
Exemplo n.º 35
0
 def __init__( self, common_actions, group_icons, *args ):
     QtGui.QTreeView.__init__( self, *args )
     self._common_actions = common_actions
     # Hook context menu popup signal
     self._active_world = None
     self.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows )
     self.setContextMenuPolicy( Qt.CustomContextMenu )
     self.setRootIsDecorated( True )
     self.setSortingEnabled(True)
     self.setIconSize( QtCore.QSize(16,16) )
     self.group_icons = group_icons
     self.connect( self, QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
                   self._onContextMenu )
     louie.connect( self._on_active_world_change, metaworldui.ActiveWorldChanged )
Exemplo n.º 36
0
    def __init__(self, graph, curvesVBox, zoomControlBox, curveset):
        self.graph = graph
        self.live = True
        self.curvesVBox = curvesVBox
        self.curveset = curveset
        self.allCurveRows = set()
        self.visibleHeight = 1000

        self.zoomControl = self.initZoomControl(zoomControlBox)
        self.zoomControl.redrawzoom()

        for uri, label, curve in curveset.currentCurves():
            self.add_curve(uri, label, curve) 

        dispatcher.connect(self.clear_curves, "clear_curves")
        dispatcher.connect(self.add_curve, "add_curve", sender=self.curveset)
        dispatcher.connect(self.set_featured_curves, "set_featured_curves")
        dispatcher.connect(self.song_has_changed, "song_has_changed")
        
        self.newcurvename = Gtk.EntryBuffer.new("", 0)

        eventBox = self.curvesVBox.get_parent()
        eventBox.connect("key-press-event", self.onKeyPress)
        eventBox.connect("button-press-event", self.takeFocus)

        self.watchCurveAreaHeight()
 def test_GarbageCollected(self):
     a = Callable()
     b = Dummy()
     signal = 'this'
     louie.connect(a.a, signal, b)
     expected = []
     del a
     result = louie.send('this', b, a=b)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s"
         % (expected, result))
     assert len(list(louie.get_all_receivers(b, signal))) == 0, (
         "Remaining handlers: %s" % (louie.get_all_receivers(b, signal),))
     self._isclean()
Exemplo n.º 38
0
    def create_ui(self):
        label = Label(self.title_font, Color.white, Color.medium_blue)
        label.set_text('Paused')
        label.set_y(200)

        a, b = self.make_spacer(), self.make_spacer()
        
        resume_button = self.make_button('Return to Game')
        exit_button = self.make_button('Quit')

        louie.connect(self.finish, Button.clicked, resume_button)
        louie.connect(self.exit, Button.clicked, exit_button)

        self.widget.create_ui([label, a, resume_button, exit_button, b])
Exemplo n.º 39
0
 def test_GarbageCollected(self):
     a = Callable()
     b = Dummy()
     signal = "this"
     louie.connect(a.a, signal, b)
     expected = []
     del a
     gc.collect()
     result = louie.send(signal, b, a=b)
     assert (
         result == expected
     ), f"Send didn't return expected result:\n\texpected:{expected}\n\tgot:{result}"
     assert (len(list(louie.get_all_receivers(b, signal))) == 0
             ), f"Remaining handlers: {louie.get_all_receivers(b, signal)}"
     self._isclean()
Exemplo n.º 40
0
 def __init__(self):
   self.clipboard = anyos.Clipboard()
   self.hotkey = anyos.Hotkey()
   louie.connect(self.on_hotkey, self.hotkey.event)
   self.network = Network('192.168.0.255', 45644)
   louie.connect(self.on_command, self.network.command)
   
   self.hotkey.add_bind('CLIPBOARD', '<control><alt>C')
   self.hotkey.add_bind('URL', '<control><alt>B')    
   
   chrome = os.path.join(os.environ.get('LOCALAPPDATA') or '', 'Google\\Chrome\\Application\\chrome.exe')
   extra_browsers = [chrome, 'chrome.exe']
   for browser in extra_browsers:
     if webbrowser._iscommand(browser):
       webbrowser.register(browser, None, webbrowser.BackgroundBrowser(browser), -1)
Exemplo n.º 41
0
 def _resetPropertyListModel( self, element = None ):
     """Change the element displayed in the property list.
        Subscribe to update event for the element and unsubscribe from the old one.
     """
     self.clear()
     self.setHorizontalHeaderLabels( [self.tr('Name'), self.tr('Value')] )
     if self._element_tree is not None:
         louie.disconnect( self.__on_element_updated, metaworld.AttributeUpdated, 
                           self._element_tree )
         self._element_tree = None
     self._element = element
     if element is not None:
         self._element_tree = element.tree
         louie.connect( self.__on_element_updated, metaworld.AttributeUpdated, 
                        self._element_tree )
Exemplo n.º 42
0
    def zerorpc_stream__(self):
        stream = gevent.queue.Queue()
        self._streams.add(stream)

        def dispatcher(value, signal):
            stream.put((signal, value))

        louie.connect(dispatcher, sender=self._object)
        debug = self._log.debug
        for message in stream:
            if message is None:
                break
            signal, value = message
            debug('streaming signal=%r value=%s', signal, StripIt(value))
            yield message
Exemplo n.º 43
0
 def test_GarbageCollected(self):
     a = Callable()
     b = Dummy()
     signal = 'this'
     louie.connect(a.a, signal, b)
     expected = []
     del a
     result = louie.send('this', b, a=b)
     assert result == expected, (
         "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" %
         (expected, result))
     assert len(list(louie.get_all_receivers(
         b, signal))) == 0, ("Remaining handlers: %s" %
                             (louie.get_all_receivers(b, signal), ))
     self._isclean()
Exemplo n.º 44
0
 def test_notification(self):
     louie.reset()
     User = db.User
     subscriber = self.Subscriber()
     louie.connect(subscriber, TransactionExecuted)
     # Execute a transaction before telling the database to
     # dispatch messages.
     tx = User.t.create(name='foo')
     db.execute(tx)
     assert tx not in subscriber.received
     # Turn on dispatching and execute another.
     db.dispatch = True
     tx = User.t.create(name='bar')
     db.execute(tx)
     assert tx in subscriber.received
Exemplo n.º 45
0
 def _on_active_world_change(self, active_world):
   if self._active_world!=active_world:
     if self._active_world is not None:
         louie.disconnect( self._on_selection_change, metaworldui.WorldSelectionChanged, 
                           self._active_world )
         louie.disconnect( self._on_element_issues_updated, 
                           metaworldui.ElementIssuesUpdated,
                           self._active_world )
     self._active_world = active_world
     if active_world is not None:
         louie.connect( self._on_selection_change, metaworldui.WorldSelectionChanged, 
                        active_world )
         louie.connect( self._on_element_issues_updated, 
                        metaworldui.ElementIssuesUpdated,
                        self._active_world )
         louie.send( metaworldui.WorldSelectionChanged, active_world,
                     active_world.selected_elements,
                     active_world.selected_elements, None )
     else:
         self.clear()
Exemplo n.º 46
0
    def test_GarbageCollectedObj(self):
        class x:
            def __call__(self, a):
                return a

        a = Callable()
        b = Dummy()
        signal = 'this'
        louie.connect(a, signal, b)
        expected = []
        del a
        gc.collect()
        result = louie.send('this', b, a=b)
        assert result == expected, (
            "Send didn't return expected result:\n\texpected:{0}\n\tgot:{1}".
            format(expected, result))
        assert len(list(louie.get_all_receivers(
            b, signal))) == 0, ("Remaining handlers: {0}".format(
                louie.get_all_receivers(b, signal)))
        self._isclean()
 def test_ConnectNotify(self):
     louie.connect(two, 'one', priority=200)
     louie.connect(one, 'one', priority=100)
     louie.connect(three, 'one', priority=300)
     result = [i[1] for i in louie.send('one')]
     if not result == [1, 2, 3]:
         print result
         assert (False)
Exemplo n.º 48
0
def test_is_live():
    louie.reset()
    # Create receivers.
    receiver1a = Receiver1()
    receiver1b = Receiver1()
    receiver2a = Receiver2()
    receiver2b = Receiver2()
    # Connect signals.
    louie.connect(receiver1a, "sig")
    louie.connect(receiver1b, "sig")
    louie.connect(receiver2a, "sig")
    louie.connect(receiver2b, "sig")
    # Check reception without plugins.
    louie.send("sig", arg="foo")
    assert receiver1a.args == ["foo"]
    assert receiver1b.args == ["foo"]
    assert receiver2a.args == ["foo"]
    assert receiver2b.args == ["foo"]
    # Install plugin 1.
    plugin1 = Plugin1()
    louie.install_plugin(plugin1)
    # Make some receivers not live.
    receiver1a.live = False
    receiver2b.live = False
    # Check reception.
    louie.send("sig", arg="bar")
    assert receiver1a.args == ["foo"]
    assert receiver1b.args == ["foo", "bar"]
    assert receiver2a.args == ["foo", "bar"]
    assert receiver2b.args == ["foo"]
    # Remove plugin 1, install plugin 2.
    plugin2 = Plugin2()
    louie.remove_plugin(plugin1)
    louie.install_plugin(plugin2)
    # Check reception.
    louie.send("sig", arg="baz")
    assert receiver1a.args == ["foo", "baz"]
    assert receiver1b.args == ["foo", "bar", "baz"]
    assert receiver2a.args == ["foo", "bar"]
    assert receiver2b.args == ["foo"]
    # Install plugin 1 alongside plugin 2.
    louie.install_plugin(plugin1)
    # Check reception.
    louie.send("sig", arg="fob")
    assert receiver1a.args == ["foo", "baz"]
    assert receiver1b.args == ["foo", "bar", "baz", "fob"]
    assert receiver2a.args == ["foo", "bar"]
    assert receiver2b.args == ["foo"]
Exemplo n.º 49
0
def test_is_live():
    louie.reset()
    # Create receivers.
    receiver1a = Receiver1()
    receiver1b = Receiver1()
    receiver2a = Receiver2()
    receiver2b = Receiver2()
    # Connect signals.
    louie.connect(receiver1a, 'sig')
    louie.connect(receiver1b, 'sig')
    louie.connect(receiver2a, 'sig')
    louie.connect(receiver2b, 'sig')
    # Check reception without plugins.
    louie.send('sig', arg='foo')
    assert receiver1a.args == ['foo']
    assert receiver1b.args == ['foo']
    assert receiver2a.args == ['foo']
    assert receiver2b.args == ['foo']
    # Install plugin 1.
    plugin1 = Plugin1()
    louie.install_plugin(plugin1)
    # Make some receivers not live.
    receiver1a.live = False
    receiver2b.live = False
    # Check reception.
    louie.send('sig', arg='bar')
    assert receiver1a.args == ['foo']
    assert receiver1b.args == ['foo', 'bar']
    assert receiver2a.args == ['foo', 'bar']
    assert receiver2b.args == ['foo']
    # Remove plugin 1, install plugin 2.
    plugin2 = Plugin2()
    louie.remove_plugin(plugin1)
    louie.install_plugin(plugin2)
    # Check reception.
    louie.send('sig', arg='baz')
    assert receiver1a.args == ['foo', 'baz']
    assert receiver1b.args == ['foo', 'bar', 'baz']
    assert receiver2a.args == ['foo', 'bar']
    assert receiver2b.args == ['foo']
    # Install plugin 1 alongside plugin 2.
    louie.install_plugin(plugin1)
    # Check reception.
    louie.send('sig', arg='fob')
    assert receiver1a.args == ['foo', 'baz']
    assert receiver1b.args == ['foo', 'bar', 'baz', 'fob']
    assert receiver2a.args == ['foo', 'bar']
    assert receiver2b.args == ['foo']
Exemplo n.º 50
0
    def test_receiver_disconnects_itself(self):
        disconnect_receiver1 = []
        signal = "this"

        def receiver1():
            if disconnect_receiver1:
                louie.disconnect(receiver1, signal)
            return 1

        def receiver2():
            return 2

        louie.connect(receiver1, signal)
        louie.connect(receiver2, signal)
        # Try without disconnecting; we'll get two responses.
        result = louie.send(signal)
        assert result == [(receiver1, 1), (receiver2, 2)]
        # We should also get two responses when first receiver disconnects.
        disconnect_receiver1.append(True)
        result = louie.send(signal)
        assert result == [(receiver1, 1), (receiver2, 2)]
        # Then the next time around should have no receiver1.
        result = louie.send(signal)
        assert result == [(receiver2, 2)]
Exemplo n.º 51
0
 def __init__(self):
     self.clients = []
     louie.connect(self.on_multivisor_event, sender='multivisor')
Exemplo n.º 52
0
 def add_handler(self, channel="global", handler=None, signal=None):
     """sets up listing to a channel"""
     louie.connect(handler or self,
                   signal=signal or All,
                   sender=channel,
                   weak=True)
Exemplo n.º 53
0
 def _connectSignals(self):
     louie.connect(self.onDataChanged, 'discovery-done')
     louie.connect(self.onDataChanged, 'identity-deleted')
     louie.connect(self.onDataChanged, 'identity-changed')
Exemplo n.º 54
0
 def test_MultipleRegistration(self):
     a = Callable()
     b = Dummy()
     signal = 'this'
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     result = louie.send('this', b, a=b)
     assert len(result) == 1, result
     assert len(list(louie.get_all_receivers(
         b, signal))) == 1, ("Remaining handlers: %s" %
                             (louie.get_all_receivers(b, signal), ))
     del a
     del b
     del result
     self._isclean()
Exemplo n.º 55
0
 def test_MultipleRegistration(self):
     a = Callable()
     b = Dummy()
     signal = "this"
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     louie.connect(a, signal, b)
     result = louie.send(signal, b, a=b)
     assert len(result) == 1, result
     assert (len(list(louie.get_all_receivers(b, signal))) == 1
             ), f"Remaining handlers: {louie.get_all_receivers(b, signal)}"
     del a
     del b
     del result
     gc.collect()
     self._isclean()