def play(self, times=1, interval=0, callback=None):
        def play_cb(previous, current, err):
            #This is called first with EPlaying meaning that the playing started
            #and with EOpen meaning that the playing stopped.
            callback_error[0] = err
            if callback != None:
                if (current == EPlaying or current == EOpen):
                    lock.signal()
                callback(previous, current, err)
            elif (current == EPlaying
                  or current == EOpen) and callback == None:
                lock.signal()

        if self.state() != EOpen:
            raise RuntimeError, ("Sound not in correct state, state: %d" %
                                 (self.state()))
        lock = e32.Ao_lock()
        callback_error = [0]
        self._player.bind(play_cb)
        if not times == KMdaRepeatForever:
            times = times - 1
        self._player.play(times, interval)
        lock.wait()
        if callback_error[0]:
            raise SymbianError, (callback_error[0], "Error playing file: " +
                                 e32.strerror(callback_error[0]))
 def save(self,
          filename,
          callback=None,
          format=None,
          quality=75,
          bpp=24,
          compression='default'):
     if format is None:
         if filename.lower().endswith(
                 '.jpg') or filename.lower().endswith('.jpeg'):
             format = 'JPEG'
         elif filename.lower().endswith('.png'):
             format = 'PNG'
         else:
             raise ValueError(
                 'unrecognized suffix and format not specified')
     self._wait()
     lock = e32.Ao_lock()
     self._image.save(unicode(filename), self._callback, format,
                      quality, compression, bpp)
     # If the code above didn't raise an exception, this method
     # will succeed, so now it's safe to modify object state.
     self._usercallback = callback
     self._lock = lock
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err = self._errcode
             self._errcode = 0
             raise SymbianError, (err, "Error saving image:" +
                                  e32.strerror(err))
示例#3
0
 def open(filename):
     def finish_load(errcode):
         img._errcode=errcode
         lock.signal()
     lock=e32.Ao_lock()
     img=Image(_graphics.ImageOpen(unicode(filename),finish_load))
     lock.wait()        
     if img._errcode != 0:
         raise SymbianError,(img._errcode,
                             "Error loading image:"+e32.strerror(img._errcode))
     return img
示例#4
0
文件: graphics.py 项目: pymo/pymo
 def open(filename):
     def finish_load(errcode):
         img._errcode=errcode
         lock.signal()
     lock=e32.Ao_lock()
     img=Image(_graphics.ImageOpen(unicode(filename),finish_load))
     lock.wait()        
     if img._errcode != 0:
         raise SymbianError,(img._errcode,
                             "Error loading image:"+e32.strerror(img._errcode))
     return img
示例#5
0
 def load(self,filename,callback=None):
     self._wait()
     self._filename=unicode(filename)
     self._usercallback=callback
     self._lock=e32.Ao_lock()
     self._image.load(self._filename,self._callback)
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err=self._errcode
             self._errcode=0
             raise SymbianError,(err, "Error loading image:"+e32.strerror(err))
    def from_buffer(buffer, mime="image/jpeg", ignore_errors=True):
        def finish_load(errcode):
            img._errcode = errcode
            lock.signal()

        lock = e32.Ao_lock()
        img = Image(_graphics.ImageFromBuffer(buffer, mime, finish_load))
        lock.wait()
        if not ignore_errors and img._errcode != 0:
            raise SymbianError, (img._errcode, "Error loading image:" +
                                 e32.strerror(img._errcode))
        return img
示例#7
0
文件: graphics.py 项目: pymo/pymo
 def load(self,filename,callback=None):
     self._wait()
     self._filename=unicode(filename)
     self._usercallback=callback
     self._lock=e32.Ao_lock()
     self._image.load(self._filename,self._callback)
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err=self._errcode
             self._errcode=0
             raise SymbianError,(err, "Error loading image:"+e32.strerror(err))
示例#8
0
文件: audio.py 项目: pymo/pymo
 def _say(text):
     def say_cb(previous, current, err):
         callback_error[0]=err
         lock.signal()
     player=Sound()
     lock=e32.Ao_lock()
     callback_error=[0]
     player._player.bind(say_cb)
     player._player.say(text)
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error: "+e32.strerror(callback_error[0]))
示例#9
0
 def record(self):
     def rec_cb(previous, current, err):
         callback_error[0]=err
         lock.signal()
     if self.state()!=EOpen:
         raise RuntimeError,("Sound not in correct state, state: %d" % (self.state()))
     lock=e32.Ao_lock()
     callback_error=[0]
     self._player.bind(rec_cb)
     self._player.record()
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error while recording: "+e32.strerror(callback_error[0]))
示例#10
0
文件: audio.py 项目: pymo/pymo
 def record(self):
     def rec_cb(previous, current, err):
         callback_error[0]=err
         lock.signal()
     if self.state()!=EOpen:
         raise RuntimeError,("Sound not in correct state, state: %d" % (self.state()))
     lock=e32.Ao_lock()
     callback_error=[0]
     self._player.bind(rec_cb)
     self._player.record()
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error while recording: "+e32.strerror(callback_error[0]))
示例#11
0
文件: audio.py 项目: pymo/pymo
 def open(filename):
     def open_cb(previous, current, err):
         callback_error[0]=err
         lock.signal()
     player=Sound()
     lock=e32.Ao_lock()
     callback_error=[0]
     player._player.bind(open_cb)
     player._player.open_file(unicode(filename))
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error opening file: "+e32.strerror(callback_error[0]))
     return player
示例#12
0
 def open(filename):
     def open_cb(previous, current, err):
         callback_error[0]=err
         lock.signal()
     player=Sound()
     lock=e32.Ao_lock()
     callback_error=[0]
     player._player.bind(open_cb)
     player._player.open_file(unicode(filename))
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error opening file: "+e32.strerror(callback_error[0]))
     return player
    def _say(text):
        def say_cb(previous, current, err):
            callback_error[0] = err
            lock.signal()

        player = Sound()
        lock = e32.Ao_lock()
        callback_error = [0]
        player._player.bind(say_cb)
        player._player.say(text)
        lock.wait()
        if callback_error[0]:
            raise SymbianError, (callback_error[0],
                                 "Error: " + e32.strerror(callback_error[0]))
示例#14
0
 def resize(self,size,callback=None,keepaspect=0):
     self._wait()
     newimage=Image.new(size,self.mode) 
     lock=e32.Ao_lock()
     self._image.resize(newimage,keepaspect,self._callback)
     # If the code above didn't raise an exception, this method
     # will succeed, so now it's safe to modify object state.
     self._lock=lock
     self._usercallback=callback
     self._resized_image=newimage
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err=self._errcode
             self._errcode=0
             raise SymbianError,(err, "Error resizing image:"+e32.strerror(err))
         t=self._resized_image
         self._resized_image=None
         return t
示例#15
0
文件: graphics.py 项目: pymo/pymo
 def resize(self,size,callback=None,keepaspect=0):
     self._wait()
     newimage=Image.new(size,self.mode) 
     lock=e32.Ao_lock()
     self._image.resize(newimage,keepaspect,self._callback)
     # If the code above didn't raise an exception, this method
     # will succeed, so now it's safe to modify object state.
     self._lock=lock
     self._usercallback=callback
     self._resized_image=newimage
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err=self._errcode
             self._errcode=0
             raise SymbianError,(err, "Error resizing image:"+e32.strerror(err))
         t=self._resized_image
         self._resized_image=None
         return t
示例#16
0
文件: graphics.py 项目: pymo/pymo
 def save(self,filename,callback=None,format=None,quality=75,bpp=24,compression='default'):
     if format is None:
         if filename.lower().endswith('.jpg') or filename.lower().endswith('.jpeg'):
             format='JPEG'
         elif filename.lower().endswith('.png'):
             format='PNG'
         else:
             raise ValueError('unrecognized suffix and format not specified')
     self._wait()
     lock=e32.Ao_lock()
     self._image.save(unicode(filename),self._callback,format,quality,compression,bpp)
     # If the code above didn't raise an exception, this method
     # will succeed, so now it's safe to modify object state.
     self._usercallback=callback
     self._lock=lock
     if callback is None:
         self._wait()
         if self._errcode != 0:
             err=self._errcode
             self._errcode=0
             raise SymbianError,(err, "Error loading image:"+e32.strerror(err))
示例#17
0
文件: audio.py 项目: pymo/pymo
 def play(self, times=1, interval=0, callback=None):
     def play_cb(previous, current, err):
         #This is called first with EPlaying meaning that the playing started
         #and with EOpen meaning that the playing stopped.
         callback_error[0]=err
         if callback!=None:
             if (current==EPlaying or current==EOpen):
                 lock.signal()
             callback(previous, current, err)
         elif (current==EPlaying or current==EOpen) and callback==None:
             lock.signal()
     if self.state()!=EOpen:
         raise RuntimeError,("Sound not in correct state, state: %d" % (self.state()))
     lock=e32.Ao_lock()
     callback_error=[0]
     self._player.bind(play_cb)
     if not times==KMdaRepeatForever:
         times=times-1
     self._player.play(times, interval)
     lock.wait()
     if callback_error[0]:
         raise SymbianError,(callback_error[0],
                             "Error playing file: "+e32.strerror(callback_error[0]))