def on_btnOk_clicked(self, *args): gobject.source_remove(self.idleTimer) for (update, blogName, blogID) in self.model: if update: self._updateBlogData(blogName, blogID) louie.send('discovery-done') self.window.destroy()
def changelevel(self,newlev): """the user is adjusting the level on this widget. the main program needs to hear about it. then the main program will call setlevel()""" dispatcher.send("levelchanged",channel=self.channelnum,newlevel=newlev)
def update_time_bar(self, t): if not self.alive(): return if not getattr(self, 'timelineLine', None): self.timelineGroup = GooCanvas.CanvasGroup( parent=self.canvas.get_root_item()) self.timelineLine = polyline_new_line( parent=self.timelineGroup, points=Points([(0,0), (0,0)]), line_width=2, stroke_color='red') try: pts = [self.screen_from_world((t, 0)), self.screen_from_world((t, 1))] except ZeroDivisionError: pts = [(-1, -1), (-1, -1)] self.timelineLine.set_property('points', Points(pts)) self._time = t if self.knobEnabled: self.delete('knob') prevKey = self.curve.point_before(t) if prevKey is not None: pos = self.screen_from_world(prevKey) self.create_oval(pos[0] - 8, pos[1] - 8, pos[0] + 8, pos[1] + 8, outline='#800000', tags=('knob',)) dispatcher.send("knob out", value=prevKey[1], curve=self.curve)
def __on_refresh_element_status(self): # import time # start_time = time.clock() checked_elements = set() # Scan added or parent of removed elements and all their children for element in self._pending_full_check: self._check_element(element, checked_elements, recurse=True) self._pending_full_check.clear() # Scan updated elements, but not their children for element in self._pending_updated: self._check_element(element, checked_elements, recurse=False) self._pending_updated.clear() # Scan parents elements of any modified issue (need to escalate warning) all_issue_elements = set() while self._modified_issues: self._modified_issues, modified_issues = set( ), self._modified_issues all_issue_elements |= modified_issues parents_to_check = set([ element.parent for element in modified_issues if element.parent is not None ]) for element in parents_to_check: if element not in checked_elements: self._check_element(element, checked_elements, recurse=False) if all_issue_elements: # print 'Refreshed element status: %.3fs' % (time.clock()-start_time) # start_time = time.clock() # print 'Broadcasting issues:', all_issue_elements louie.send(ElementIssuesUpdated, self.__world, all_issue_elements)
def __init__(self, device, **kwargs): self.warning("__init__ RhythmboxPlayer %r", kwargs) self.shell = kwargs['shell'] self.server = device self.rb_mediaserver = kwargs['rb_mediaserver'] self.player = None self.entry = None self.metadata = None try: self.name = kwargs['name'] except KeyError: self.name = "Rhythmbox on %s" % self.server.coherence.hostname self.player = self.shell.get_player() louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self) self.entry_type = rhythmdb.EntryType(name='CoherencePlayer') self.shell.props.db.register_entry_type(self.entry_type) self.playing = False self.state = None self.duration = None self.volume = 1.0 self.muted_volume = None self.view = [] self.tags = {}
def input_time(self, val, forceUpdate=False): if self._time == val: return t=val if not getattr(self, 'timelineLine', None): self.timelineGroup = goocanvas.Group(parent=self.root) self.timelineLine = goocanvas.Polyline( parent=self.timelineGroup, points=goocanvas.Points([(0,0), (0,0)]), line_width=2, stroke_color='red') self.timelineLine.set_property('points', goocanvas.Points([ self.screen_from_world((val,0)), self.screen_from_world((val,1))])) self._time = t if self.knobEnabled: self.delete('knob') prevKey = self.curve.point_before(t) if prevKey is not None: pos = self.screen_from_world(prevKey) self.create_oval(pos[0] - 8, pos[1] - 8, pos[0] + 8, pos[1] + 8, outline='#800000', tags=('knob',)) dispatcher.send("knob out", value=prevKey[1], curve=self.curve)
def load(self,filename): self.points[:]=[] for line in file(filename): x, y = line.split() self.points.append((float(x), ast.literal_eval(y))) self.points.sort() dispatcher.send("points changed",sender=self)
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']
def dispatch(proxy): while True: for signal, value in client.zerorpc_stream__(timeout=None): client._log.debug( 'dispatching stream event signal=%r value=%r', signal, StripIt(value)) louie.send(signal, proxy, value)
def loadCurvesForSong(self): """ current curves will track song's curves. This fires 'add_curve' dispatcher events to announce the new curves. """ log.info('loadCurvesForSong') dispatcher.send("clear_curves") self.curveResources.clear() self.markers = Markers(uri=None, pointsStorage='file') self.currentSong = self.graph.value(self.session, L9['currentSong']) if self.currentSong is None: return for uri in sorted(self.graph.objects(self.currentSong, L9['curve'])): try: cr = self.curveResources[uri] = CurveResource(self.graph, uri) cr.loadCurve() curvename = self.graph.label(uri) if not curvename: raise ValueError("curve %r has no label" % uri) dispatcher.send("add_curve", sender=self, uri=uri, label=curvename, curve=cr.curve) except Exception as e: log.error("loading %s failed: %s", uri, e) basename = os.path.join( showconfig.curvesDir(), showconfig.songFilenameFromURI(self.currentSong)) try: self.markers.load("%s.markers" % basename) except IOError: print "no marker file found"
def sendEvent_(self, theEvent): if theEvent.type() == AppKit.NSSystemDefined and theEvent.subtype() == kEventHotKeyReleasedSubtype: #self.activateIgnoringOtherApps_(True) louie.send(HotKeyApp.event, theEvent=theEvent) #command = HKCommand() #carbon.GetEventParameter( # theEvent, # _name('----'), # _name('hkid'), # ctypes.c_void_p(), # ctypes.sizeof(command), # ctypes.c_void_p(), # # command #) #print theEvent #print ctypes.byref(theEvent) # #i = ctypes.c_int32() #carbon.GetEventParameter( # theEvent, # _name('kcod'), # _name('magn'), # ctypes.c_void_p(), # ctypes.sizeof(i), # ctypes.c_void_p(), # ctypes.byref(i) #) else: super(HotKeyApp, self).sendEvent_(theEvent)
def _redrawzoom(self): """redraw pieces based on start/end""" self.size = self.widget.get_allocation() dispatcher.send("zoom changed") if not hasattr(self,'created'): return y1, y2 = 3, self.size.height - 3 lip = 6 try: scan = self.can_for_t(self.start) ecan = self.can_for_t(self.end) except ZeroDivisionError: # todo: set the zoom to some clear null state return self.leftbrack.set_property("points", Points([ (scan + lip, y1), (scan, y1), (scan, y2), (scan + lip, y2)])) self.rightbrack.set_property("points", Points([ (ecan - lip, y1), (ecan, y1), (ecan, y2), (ecan - lip, y2)])) self.shade.set_properties( x=scan + 5, y=y1 + lip, width=max(0, ecan - 5 - (scan + 5)), height=max(0, y2 - lip - (y1 + lip))) self.redrawTics()
def redrawzoom(self,*args): """redraw pieces based on start/end""" self.size = self.widget.get_allocation() dispatcher.send("zoom changed") if not hasattr(self,'created'): return y1, y2 = 3, self.size.height - 3 lip = 6 scan = self.can_for_t(self.start) ecan = self.can_for_t(self.end) self.leftbrack.set_property("points", goocanvas.Points([ (scan + lip, y1), (scan, y1), (scan, y2), (scan + lip, y2)])) self.rightbrack.set_property("points", goocanvas.Points([ (ecan - lip, y1), (ecan, y1), (ecan, y2), (ecan - lip, y2)])) self.shade.set_properties( x=scan + 5, y=y1 + lip, width=max(0, ecan - 5 - (scan + 5)), height=max(0, y2 - lip - (y1 + lip))) self.redrawTics()
def on_btnOk_clicked(self, *args): publications = [] for (delete, pubDate, blogName, publication) in self.model: if delete: publications.append(publication) louie.send('entry-delete', publications) self.window.destroy()
def timeoutPeerConnection(self, peer): louie.send('peer:timeout', self, peer) self.log("timeoutPeerConnection %r" % (peer,)) del self._waitingForConnection[peer.nick] if peer in self._peerCheckout: self.log("reconnecting to %r in 30 seconds" % (peer,)) self.connectionToPeer(peer, delay=30)
def loop(self): owner = 1 keyboard = pointer = Xlib.X.GrabModeAsync self.root.change_attributes(event_mask=Xlib.X.KeyPressMask) for bind in self.binds: for mask in self.apply_masks: self.root.grab_key(bind['key'], bind['modifiers'] | mask, owner, pointer, keyboard) while not self.shutdown: while self.display.pending_events(): event = self.display.next_event() if event.type == Xlib.X.KeyPress: #print("key pressed: %d" % event.detail) for bind in self.binds: if bind['key'] == event.detail: louie.send(self.event, sender=self.__class__, name=bind['name']) break time.sleep(0.1) self.display.ungrab_keyboard(Xlib.X.CurrentTime) self.display.flush() self.display.screen().root.ungrab_key(Xlib.X.AnyKey, Xlib.X.AnyModifier)
def hw_knob_button(self, num): try: curve = self.curves[self.sliderCurve[num]] except KeyError: return dispatcher.send("set key", curve=curve)
def __on_refresh_element_status( self ): # import time # start_time = time.clock() checked_elements = set() # Scan added or parent of removed elements and all their children for element in self._pending_full_check: self._check_element( element, checked_elements, recurse = True ) self._pending_full_check.clear() # Scan updated elements, but not their children for element in self._pending_updated: self._check_element( element, checked_elements, recurse = False ) self._pending_updated.clear() # Scan parents elements of any modified issue (need to escalate warning) all_issue_elements = set() while self._modified_issues: self._modified_issues, modified_issues = set(), self._modified_issues all_issue_elements |= modified_issues parents_to_check = set( [ element.parent for element in modified_issues if element.parent is not None ] ) for element in parents_to_check: if element not in checked_elements: self._check_element( element, checked_elements, recurse = False ) if all_issue_elements: # print 'Refreshed element status: %.3fs' % (time.clock()-start_time) # start_time = time.clock() # print 'Broadcasting issues:', all_issue_elements louie.send( ElementIssuesUpdated, self.__world, all_issue_elements )
def insert_pt(self, new_pt): """returns index of new point""" i = bisect(self.points, (new_pt[0],None)) self.points.insert(i,new_pt) # missing a check that this isn't the same X as the neighbor point dispatcher.send("points changed", sender=self) return i
def start_update(self, confirm=True): """ Shows the dialog and starts the update process. If *confirm* is True, a confirmation dialog is shown before starting the update. The :class:`~pyflu.update.signals.not_updated` signal is sent if no update was performed (either because there was no update available or the user refused to apply it). """ # Check for updates self.patches_paths = [] self.start_long_operation( self.trUtf8("Searching for updates..."), 1) self.download_queue = self._updates_urls() self.update_long_operation(1) if self.download_queue: # Updates available, apply them or exit if confirm: ret = QMessageBox.question(self, self.trUtf8("Updates available"), self.trUtf8("Updates were found, do you want to " "install them now ?"), QMessageBox.Ok | QMessageBox.Abort) do_update = ret == QMessageBox.Ok else: do_update = True if do_update: self._download_next() return louie.send(signals.not_updated, self)
def live_input_point(self, new_pt, clear_ahead_secs=.01): x, y = new_pt exist = self.points_between(x, x + clear_ahead_secs) for pt in exist: self.remove_point(pt) self.insert_pt(new_pt) dispatcher.send("points changed", sender=self)
def connectionLost(self, reason): self.log('lost connection: %r' % (reason,)) if self.searchTimer: self.searchTimer.cancel() if self.periodiclySendMyINFOId: self.periodiclySendMyINFOId.cancel() louie.send('hub:quit', self, self.id, reason)
def _fetch_one(generator, path, keywords, storage, store_match): status, data = generator.get_paste(path) #if 5xx or 4xx if status['status'][0] in ('4', '5'): #TODO better handling of timeouts print >> sys.stderr, "%s: %s. skipping" % (path, status['status']) return full_url = generator.full_url(path) match = None text = None name = None for kw in keywords: if hasattr(kw, '__call__'): text = kw(data) name = getattr(kw, '__name__') else: match = re.search(kw, data) name = kw text = match.group() if match else None if match: L.send('match', generator, storage, match=match.group(), url=full_url, data=data) if store_match: storage.save_url(full_url, [(name, text), ]) # stop after the first match break if not match and store_match: storage.save_url(full_url, None)
def set_from_string(self, pts): self.points[:] = [] vals = pts.split() pairs = zip(vals[0::2], vals[1::2]) for x, y in pairs: self.points.append((float(x), ast.literal_eval(y))) self.points.sort() dispatcher.send("points changed",sender=self)
def handleQuit(self, nick): try: peer = self.peerForNick(nick.decode(DC_ENCODING)) del self.peers[peer] self.log('peer quit: %r' % (peer,)) louie.send('hub:user:quit', self, self.id, peer) except errors.PeerNotFound: pass
def _afterQueued(res): if not dl.id: self.log('download NOT queued %r' % (outfile,)) return if res: self.log("download queued: %r %r" % (outfile, type,)) louie.send('download:queued', self, dl) return res
def set_points(self, updates): for i, pt in updates: self.points[i] = pt # this should be on, but live_input_point made it fail a # lot. need a new solution. #self.checkOverlap() dispatcher.send("points changed", sender=self)
def __init__(self, server, **kwargs): BackendStore.__init__(self,server,**kwargs) self.warning("__init__ MediaStore %r", kwargs) self.db = kwargs['db'] self.plugin = kwargs['plugin'] self.wmc_mapping.update({'4': lambda : self.get_by_id(AUDIO_ALL_CONTAINER_ID), # all tracks '7': lambda : self.get_by_id(AUDIO_ALBUM_CONTAINER_ID), # all albums '6': lambda : self.get_by_id(AUDIO_ARTIST_CONTAINER_ID), # all artists }) self.next_id = CONTAINER_COUNT self.albums = None self.artists = None self.tracks = None self.urlbase = kwargs.get('urlbase','') if( len(self.urlbase) > 0 and self.urlbase[len(self.urlbase)-1] != '/'): self.urlbase += '/' try: self.name = kwargs['name'] except KeyError: self.name = "Rhythmbox on %s" % self.server.coherence.hostname query = self.db.query_new() self.info(query) self.db.query_append(query, [rhythmdb.QUERY_PROP_EQUALS, rhythmdb.PROP_TYPE, self.db.entry_type_get_by_name('song')]) qm = self.db.query_model_new(query) self.db.do_full_query_async_parsed(qm, query) self.album_query = self.db.property_model_new(rhythmdb.PROP_ALBUM) self.album_query.props.query_model = qm self.artist_query = self.db.property_model_new(rhythmdb.PROP_ARTIST) self.artist_query.props.query_model = qm self.containers = {} self.containers[ROOT_CONTAINER_ID] = \ Container( ROOT_CONTAINER_ID,-1, "Rhythmbox on %s" % self.server.coherence.hostname) self.containers[AUDIO_ALL_CONTAINER_ID] = \ Container( AUDIO_ALL_CONTAINER_ID,ROOT_CONTAINER_ID, 'All tracks', children_callback=self.children_tracks, store=self,play_container=True) self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ALL_CONTAINER_ID]) self.containers[AUDIO_ALBUM_CONTAINER_ID] = \ Container( AUDIO_ALBUM_CONTAINER_ID,ROOT_CONTAINER_ID, 'Albums', children_callback=self.children_albums) self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ALBUM_CONTAINER_ID]) self.containers[AUDIO_ARTIST_CONTAINER_ID] = \ Container( AUDIO_ARTIST_CONTAINER_ID,ROOT_CONTAINER_ID, 'Artists', children_callback=self.children_artists) self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ARTIST_CONTAINER_ID]) louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
def handle(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.new_game() elif event.key == pygame.K_ESCAPE: louie.send(GameOverScreen.escape_pressed) for handler in self.handlers: handler.handle(event)
def testEnqueuingDownloadStartsDownloader(self): self.downloader = flexmock() self.downloader.should_receive('start').once() self.downloader.should_receive('cancel').once() flexmock(StubDownloaderFactory).new_instances(self.downloader).once() self.downloaderManager.downloaderFactory = StubDownloaderFactory louie.send('download:queued', self, self.download)
def start(self): if self.running: raise Exception('already running') self.running = True louie.send('share_store:indexer:started') self.log('starting') yield self.run() self.shutdown()
def handleHubName(self, hubname): hubname = hubname.decode(DC_ENCODING) self.ready = True louie.send('hub:name', self, self.id, hubname) self.hubname = hubname if self.extendedProtocol and not self.hubConnected: louie.send('hub:connected', self, self.id, self.hubname) self.hubConnected = True
def run(self): for event in self.events(): status = self.status name, payload = event['event'], event['payload'] if name == 'process_changed': status['processes'][payload['uid']].update(payload) self._update_status_stats(status) elif name == 'notification': self.notifications.append(payload) louie.send(signal=name, sender=self, payload=payload)
def on_btnOk_clicked(self, *args): weblogs = [] for (publish, blogName, identityName, blog) in self.model: if publish: weblogs.append(blog) if self.entry: event = 'entry-republish' else: event = 'entry-publish' louie.send(event, louie.Anonymous, weblogs) self.window.destroy()
def _send_selection_update(self, old_selection): """Broadcast the selection change to the world if required.""" if None in self.__selection: self.__selection.remove(None) selected_elements = self.__selection - old_selection deselected_elements = old_selection - self.__selection if selected_elements or deselected_elements: #print 'Selection changed:',self #print ' Selection:', self.__selection #print ' Selected:', selected_elements #print ' Unselected:', deselected_elements louie.send(WorldSelectionChanged, self.__world, self.__selection.copy(), selected_elements, deselected_elements)
def run(self): ret = self.window.run() if ret == gtk.RESPONSE_OK: if DEBUG: print 'pressed ok, sending signal' self.curFilter['month'] = self.cbxMonth.get_active() + 1 self.curFilter['year'] = int(self.spnYear.get_value()) if self.ckbShowAllCategories.get_active(): self.curFilter['categories'] = [] else: for (selected, name) in self.lvCategories.get_model(): if selected: self.curFilter['categories'].append( name.decode('utf-8')) louie.send('filter-changed') self.window.destroy()
def test_AnyRegistration(self): a = Dummy() signal = 'this' louie.connect(x, signal, louie.Any) expected = [(x, a)] result = louie.send('this', object(), a=a) assert result == expected, ( "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" % (expected, result)) louie.disconnect(x, signal, louie.Any) expected = [] result = louie.send('this', object(), a=a) assert result == expected, ( "Send didn't return expected result:\n\texpected:%s\n\tgot:%s" % (expected, result)) assert len(list(louie.get_all_receivers(louie.Any, signal))) == 0 self._isclean()
def test_AnyRegistration(self): a = Dummy() signal = "this" louie.connect(x, signal, louie.Any) expected = [(x, a)] result = louie.send(signal, object(), a=a) assert ( result == expected ), f"Send didn't return expected result:\n\texpected:{expected}\n\tgot:{result}" louie.disconnect(x, signal, louie.Any) expected = [] result = louie.send(signal, object(), a=a) assert ( result == expected ), f"Send didn't return expected result:\n\texpected:{expected}\n\tgot:{result}" assert len(list(louie.get_all_receivers(louie.Any, signal))) == 0 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)
def run(self): ret = self.window.run() if ret == gtk.RESPONSE_OK: name = self.edName.get_text().decode('utf-8') bf = self.tvDescription.get_buffer() description = bf.get_text(bf.get_start_iter(), bf.get_end_iter()).decode('utf-8') active = self.ckbIsActive.get_active() if self.category: self.category.name = name self.category.description = description self.category.isActive = active else: datamodel.Category(name=name, description=description, isActive=active) louie.send('category-changed') self.window.destroy()
def deleteEntry(self, entry, parent): if entry.publications: text = _('This entry has been published to weblogs.\n' 'Do you want to delete this entry with all publications?') else: text = _('Do you really want to delete this entry?') if apputils.question(text, parent.window): i = len(entry.publications) - 1 if DEBUG: print entry.publications while i > -1: publication = entry.publications[i] blog = publication.weblog publication.deleteRemoteEntry(blog, parent) publication.destroySelf() i = i - 1 entry.destroySelf() louie.send('entry-deleted')
def run(self): ret = self.window.run() if ret == gtk.RESPONSE_OK: name = self.edWeblogName.get_text().decode('utf-8') model = self.cbxIdentity.get_model() identity = model.get_value(self.cbxIdentity.get_active_iter(), 1) blogID = self.edWeblogID.get_text().decode('utf-8') isActive = self.ckbActive.get_active() if self.weblog: self.weblog.name = name self.weblog.identity = identity self.weblog.weblogID = blogID self.weblog.isActive = isActive else: datamodel.Weblog(name=name, identity=identity, weblogID=blogID, isActive=isActive) louie.send('weblog-changed') self.window.destroy()
def on_btnOk_clicked(self, *args): if self.autosaveTimer: gobject.source_remove(self.autosaveTimer) self._saveEntry() self.cfg.setOption('editing', 'last_locale', self.entry.lang) model = self.cbxLang.get_model() listOpt = [] for item in model: listOpt.append(item[0]) if not self.entry.lang in listOpt: listOpt.append(self.entry.lang) listOpt.sort() self.cfg.setList('editing', 'locales', listOpt) if self.isNew: event = 'entry-added' else: event = 'entry-changed' louie.send(event) self.window.destroy()
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()
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()
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:{0}\n\tgot:{1}". format(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()
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"]
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']
def _fetch_one(generator, path, keywords, storage, store_match): status, data = generator.get_paste(path) #if 5xx or 4xx if status['status'][0] in ('4', '5'): #TODO better handling of timeouts print >> sys.stderr, "%s: %s. skipping" % (path, status['status']) return full_url = generator.full_url(path) match = None text = None name = None for kw in keywords: if hasattr(kw, '__call__'): text = kw(data) name = getattr(kw, '__name__') else: match = re.search(kw, data) name = kw text = match.group() if match else None if match: L.send('match', generator, storage, match=match.group(), url=full_url, data=data) if store_match: storage.save_url(full_url, [ (name, text), ]) # stop after the first match break if not match and store_match: storage.save_url(full_url, None)
def run(self): ret = self.window.run() if ret == gtk.RESPONSE_OK: name = self.edName.get_text().decode('utf-8') model = self.cbxType.get_model() it = self.cbxType.get_active_iter() transportType = model.get_value(it, 0) model = self.cbxProtocol.get_model() it = self.cbxProtocol.get_active_iter() proto = model.get_value(it, 0) uri = self.edUri.get_text().decode('utf-8') useDefPort = self.ckbUseDefPort.get_active() if useDefPort: port = 0 else: port = int(self.edPort.get_text()) login = self.edLogin.get_text().decode('utf-8') password = self.edPassword.get_text().decode('utf-8') if self.identity: identity = self.identity identity.name = name identity.transportType = transportType identity.login = login identity.password = password identity.serviceProtocol = proto identity.serviceURI = uri identity.servicePort = port else: identity = datamodel.Identity(name=name, transportType=transportType, login=login, password=password, serviceURI=uri, serviceProtocol=proto, servicePort=port) louie.send('identity-changed') self.window.destroy()
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)]
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()
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()
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()