コード例 #1
0
    def onStateChange(self, web_progress, request, state_flags, status):
        if state_flags & interfaces.nsIWebProgressListener.STATE_START:
            self._create_journal_object()            
            self._object_id = self.dl_jobject.object_id
            
            alert = TimeoutAlert(9)
            alert.props.title = _('Download started')
            alert.props.msg = _('%s' % self._get_file_name()) 
            self._activity.add_alert(alert)
            alert.connect('response', self.__start_response_cb)
            alert.show()
            global _active_downloads
            _active_downloads.append(self)
            
        elif state_flags & interfaces.nsIWebProgressListener.STATE_STOP:
            if NS_FAILED(status): # download cancelled
                return

            self._stop_alert = Alert()
            self._stop_alert.props.title = _('Download completed') 
            self._stop_alert.props.msg = _('%s' % self._get_file_name()) 
            open_icon = Icon(icon_name='zoom-activity') 
            self._stop_alert.add_button(gtk.RESPONSE_APPLY, 
                                        _('Show in Journal'), open_icon) 
            open_icon.show() 
            ok_icon = Icon(icon_name='dialog-ok') 
            self._stop_alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon) 
            ok_icon.show()            
            self._activity.add_alert(self._stop_alert) 
            self._stop_alert.connect('response', self.__stop_response_cb)
            self._stop_alert.show()

            self.dl_jobject.metadata['title'] = _('File %s from %s.') % \
                    (self._get_file_name(), self._source.spec)
            self.dl_jobject.metadata['progress'] = '100'
            self.dl_jobject.file_path = self._target_file.path

            if self._mime_type in ['application/octet-stream',
                                   'application/x-zip']:
                sniffed_mime_type = mime.get_for_file(self._target_file.path)
                self.dl_jobject.metadata['mime_type'] = sniffed_mime_type

            datastore.write(self.dl_jobject,
                            transfer_ownership=True,
                            reply_handler=self._internal_save_cb,
                            error_handler=self._internal_save_error_cb,
                            timeout=360 * DBUS_PYTHON_TIMEOUT_UNITS_PER_SECOND)
コード例 #2
0
    def _onMessageCb(self, bus, message):
        t = message.type
        if t == gst.MESSAGE_EOS:
            if self._eos_cb:
                cb = self._eos_cb
                self._eos_cb = None
                cb()
        elif t == gst.MESSAGE_ELEMENT:
            s = message.structure
            if s.has_name("barcode"):
                self.stop()
                self.window.hide()
                aplay.play(Constants.sound_click)
                self.last_detection = s['symbol']
                parsedurl = urlparse.urlparse(s['symbol'])
                if parsedurl.scheme in self.recognized_schemes:
                    alert = TimeoutAlert(60)
                    alert.remove_button(gtk.RESPONSE_CANCEL)
                    alert.props.title = 'Direccion detectada!'
                    alert.props.msg = 'La dirección fue copiada al ' +\
                                      'portatapeles. Acceda al ' +\
                                      'marco de Sugar y haga click sobre ' +\
                                      'ella para abrirla en el navegador.'
                    alert.connect('response', self._alert_uri_response_cb)
                    self.ca.add_alert(alert)
                    self._copyURIToClipboard()
                    self.ca.alert.show()
                else:
                    alert = ConfirmationAlert()
                    alert.props.title = 'Texto detectado. ' +\
                                        '¿Desea copiarlo al portapapeles?'
                    alert.props.msg = s['symbol']
                    alert.connect('response', self._alert_text_response_cb)
                    self.ca.add_alert(alert)
                    self.ca.alert.show()

        elif t == gst.MESSAGE_ERROR:
            #todo: if we come out of suspend/resume with errors, then get us
            #      back up and running...
            #todo: handle "No space left on the resource.gstfilesink.c"
            #err, debug = message.parse_error()
            pass
コード例 #3
0
ファイル: capture.py プロジェクト: mpaolino/cuadraditosxo
    def _onMessageCb(self, bus, message):
        t = message.type
        if t == gst.MESSAGE_EOS:
            if self._eos_cb:
                cb = self._eos_cb
                self._eos_cb = None
                cb()
        elif t == gst.MESSAGE_ELEMENT:
            s = message.structure
            if s.has_name("barcode"):
                self.stop()
                self.window.hide()
                aplay.play(Constants.sound_click)
                self.last_detection = s['symbol']
                parsedurl = urlparse.urlparse(s['symbol'])
                if parsedurl.scheme in self.recognized_schemes:
                    alert = TimeoutAlert(60)
                    alert.remove_button(gtk.RESPONSE_CANCEL)
                    alert.props.title = 'Direccion detectada!'
                    alert.props.msg = 'La dirección fue copiada al ' +\
                                      'portatapeles. Acceda al ' +\
                                      'marco de Sugar y haga click sobre ' +\
                                      'ella para abrirla en el navegador.'
                    alert.connect('response', self._alert_uri_response_cb)
                    self.ca.add_alert(alert)
                    self._copyURIToClipboard()
                    self.ca.alert.show()
                else:
                    alert = ConfirmationAlert()
                    alert.props.title = 'Texto detectado. ' +\
                                        '¿Desea copiarlo al portapapeles?'
                    alert.props.msg = s['symbol']
                    alert.connect('response', self._alert_text_response_cb)
                    self.ca.add_alert(alert)
                    self.ca.alert.show()

        elif t == gst.MESSAGE_ERROR:
            #todo: if we come out of suspend/resume with errors, then get us
            #      back up and running...
            #todo: handle "No space left on the resource.gstfilesink.c"
            #err, debug = message.parse_error()
            pass
コード例 #4
0
import gtk
from sugar.graphics.alert import TimeoutAlert

window = gtk.Window()

box = gtk.VBox()
window.add(box)

def _timeout_alert_response_cb(alert, response_id):
    if response_id is gtk.RESPONSE_OK:
        print 'Ok or Timeout'
    elif response_id is gtk.RESPONSE_CANCEL:
        print 'Cancel'
    box.remove(alert)
    gtk.main_quit()

alert = TimeoutAlert(10)
alert.props.title='Title of TimeoutAlert'
alert.props.msg = 'Text of timeout alert, either button will quit'
alert.connect('response', _timeout_alert_response_cb)
box.add(alert)

window.show_all()

gtk.main()