示例#1
0
def rate(resource, rating):
  '''give a resource a nao:numericRating (float from 1-10)'''
  resource = RDF.Node(RDF.Uri(resource))

  rating = RDF.Node(literal=str(rating), datatype=ns['xs'].float.uri)

  # delete any existing ratings for this resource
  TripleStore.forget(resource, ns['nao'].numericRating, None)

  TripleStore.state(resource, ns['nao'].numericRating, rating)
示例#2
0
    def __init__(self, parent=None):
        
        #build parent user interface
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.text = QtCore.QString()
        self.connected = False
        self.deviceID = "nokiaN900"

        self.m_media = Phonon.MediaObject(self)
        audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
        Phonon.createPath(self.m_media, audioOutput)
        self.song = QtCore.QString("/home/user/scripts/groove.mp3")
        self.m_media.setCurrentSource(Phonon.MediaSource(self.song))
        
        self.ui.cueButton.hide()
        self.ui.textBrowser.hide()
        
        #connect signals
        QtCore.QObject.connect(self.ui.playButton, QtCore.SIGNAL('clicked()'), self.playSong)
        QtCore.QObject.connect(self.ui.stopButton, QtCore.SIGNAL('clicked()'), self.stopSong)
        QtCore.QObject.connect(self.ui.cueButton, QtCore.SIGNAL('clicked()'), self.forwardSong)
        #QtCore.QObject.connect(self.m_media, QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'), self.stateChanged)
        QtCore.QObject.connect(self.m_media, QtCore.SIGNAL('finished()'), self.finished)
        QtCore.QObject.connect(app, QtCore.SIGNAL('aboutToQuit()'), self.exit_handler)
        
        
        self.note("Joining smart space..")
        self.ts = TripleStore()
           
        self.connected = True
        self.addEvent("ConnectEvent")
        
        if self.connected:
        
            #Add subscriptions for play, stop and forward
            self.note("Subscribing to PlayEvents..")
            self.rs1 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf1 = self.rs1.subscribe_rdf([((None, None, ns+"PlayEvent"), 'uri')], RdfMsgHandler())
            self.note("Subscribing to StopEvents..")
            self.rs2 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf2 = self.rs2.subscribe_rdf([((None, None, ns+"StopEvent"), 'uri')], RdfMsgHandler())
            self.note("Subscribing to CueEvents..")
            self.rs3 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf3 = self.rs3.subscribe_rdf([((None, None, ns+"CueEvent"), 'uri')], RdfMsgHandler())
示例#3
0
def tag(resource, tags):
  '''tag a resource with a space-separated string'''
  resource = RDF.Node(RDF.Uri(resource))
  # space-separated, remove empty
  tags = [x for x in tags.strip().split(' ') if x != '']

  # remove all existing tags on this resource
  TripleStore.forget(resource, ns['nao'].hasTag, None)

  for _tag in tags:
    # XXX check if it's a nao:Tag too
    tag = TripleStore.model.get_source(ns['nao'].prefLabel, RDF.Node(_tag))

    if not tag:
      # create a new nao:Tag with the appropriate prefLabel
      tag = RDF.Node(blank=None)
      TripleStore.state(tag, ns['rdf'].type, ns['nao'].Tag)
      TripleStore.state(tag, ns['nao'].prefLabel, RDF.Node(_tag))

    TripleStore.state(resource, ns['nao'].hasTag, tag)
示例#4
0
class MediaPlayer(QtGui.QMainWindow):
    def __init__(self, parent=None):
        
        #build parent user interface
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.text = QtCore.QString()
        self.connected = False
        self.deviceID = "nokiaN900"

        self.m_media = Phonon.MediaObject(self)
        audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
        Phonon.createPath(self.m_media, audioOutput)
        self.song = QtCore.QString("/home/user/scripts/groove.mp3")
        self.m_media.setCurrentSource(Phonon.MediaSource(self.song))
        
        self.ui.cueButton.hide()
        self.ui.textBrowser.hide()
        
        #connect signals
        QtCore.QObject.connect(self.ui.playButton, QtCore.SIGNAL('clicked()'), self.playSong)
        QtCore.QObject.connect(self.ui.stopButton, QtCore.SIGNAL('clicked()'), self.stopSong)
        QtCore.QObject.connect(self.ui.cueButton, QtCore.SIGNAL('clicked()'), self.forwardSong)
        #QtCore.QObject.connect(self.m_media, QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'), self.stateChanged)
        QtCore.QObject.connect(self.m_media, QtCore.SIGNAL('finished()'), self.finished)
        QtCore.QObject.connect(app, QtCore.SIGNAL('aboutToQuit()'), self.exit_handler)
        
        
        self.note("Joining smart space..")
        self.ts = TripleStore()
           
        self.connected = True
        self.addEvent("ConnectEvent")
        
        if self.connected:
        
            #Add subscriptions for play, stop and forward
            self.note("Subscribing to PlayEvents..")
            self.rs1 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf1 = self.rs1.subscribe_rdf([((None, None, ns+"PlayEvent"), 'uri')], RdfMsgHandler())
            self.note("Subscribing to StopEvents..")
            self.rs2 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf2 = self.rs2.subscribe_rdf([((None, None, ns+"StopEvent"), 'uri')], RdfMsgHandler())
            self.note("Subscribing to CueEvents..")
            self.rs3 = node.CreateSubscribeTransaction(smartSpace)
            result_rdf3 = self.rs3.subscribe_rdf([((None, None, ns+"CueEvent"), 'uri')], RdfMsgHandler())
       
        
        
    #def stateChanged(self, newState, oldState):
    def finished(self):
        """When the song is finished, we need to send to handle it"""
        #if newState == Phonon.StoppedState and oldState != Phonon.StoppedState:
            #self.stopSong()
        print "Finished.. restarting"
        self.m_media.setCurrentSource(Phonon.MediaSource(self.song))
        self.m_media.play()
        
    def note(self, newText):
        self.text.append(QtCore.QString(newText + "\n"))
        self.ui.textBrowser.setPlainText(self.text)
        
    def playSong(self, event=None):
        """Starts song and sends notification"""
        self.m_media.play()
        self.note("Playing..")
        if self.connected:
            self.start_time = time.time()
            self.addEvent("PlayEvent")
            
    def stopSong(self, event=None):
        """Stops song and sends notification"""
        self.m_media.stop()
        playing = False
        self.note("Stopped..")
        if self.connected:
            self.start_time = time.time()
            self.addEvent("StopEvent")
            
    def forwardSong(self, event=None):
        """Forwards song 5s and sends notification"""
        global cueAt
               
        if self.connected and cueAt == 0: #If cueAt is 0, the button was pressed on this device
        	self.start_time = time.time()
        	eventID = self.addEvent("CueEvent")
        	t = RDFTransactionList()
        	t.add_literal(eventID, ns + "cueAt", '"5000"^^<http://www.w3.org/2001/XMLSchema#integer>')
        	self.ts.insert(t.get())

        self.m_media.seek(5000)
        self.note("Forwarding..")
        cueAt = 0
        	
    def exit_handler(self):
        """On exit, the app sends a notification and leaves smart space"""
        
        print "Unsubscribing RDF subscriptions"
        node.CloseSubscribeTransaction(self.rs1)
        node.CloseSubscribeTransaction(self.rs2)
        node.CloseSubscribeTransaction(self.rs3)
        
        if self.connected:
            self.addEvent("DisconnectEvent")
            node.leave(smartSpace)
        print "Exiting.."
        
    def addEvent(self, eventType):
    	"""Adds new event with metadata (generatedBy, datetime) to smart space"""
        t = RDFTransactionList()
        u1 = ns + "event" + str(uuid.uuid4())
        t.setType(u1, ns + eventType)
        t.add_uri(u1, ns + "generatedBy", ns + self.deviceID)
        dt = datetime.now()
        xsddt = '"'+dt.strftime('%Y-%m-%dT%H:%M:%S%z')  + '"^^<http://www.w3.org/2001/XMLSchema#dateTime>' # e.g. "2011-01-19T16:10:23"^^<http://www.w3.org/2001/XMLSchema#dateTime>
        t.add_literal(u1, ns + "inXSDDateTime", xsddt)
        self.ts.insert(t.get())
        return u1