Exemplo n.º 1
0
 def f():
     try:
         self.card.prepare_for_sending()
         data = serialize_card(self.card)
         save_unsent_card(data)
         self.cb("ok", u"Card stored")
     except:
         ut.print_exception()
         self.cb("fail", u"Storing failed")
Exemplo n.º 2
0
 def f():
     try:
         self.card.prepare_for_sending()
         self.uploader.send(serialize_card(self.card), self._send_done)
         self.active = True
     except:
         self.config.set_apid(None)
         ut.print_exception()
         #appuifw.note(u"Sending failed", "error")
         self.cb("fail", u"Sending failed")
 def _try(self, action):
     try:
         action()
     except:
         self.tn_fail = True
         self.image = self.tn_image = None
         ut.print_exception()
         self.cb("fail")
         return True
     return False
Exemplo n.º 4
0
 def take_photo(self):
     newfile = None
     uid = self.config.db.get("camera_uid", 0x101ffa86)
     try:
         newfile = pynewfile.take_photo(uid)
     except:
         if ut.get_debug_on():
             ut.print_exception()
         appuifw.note(u"Failed to take a photo", "error")
     if newfile is not None:
         self.card.set_picfile(newfile)
Exemplo n.º 5
0
    def change_apid(self):
        apid = None
        try:
            # Will return None if the user selects nothing, and that
            # is fine. Or it would be, if this call did not produce a
            # KERN-EXEC 3 almost every time.
            #apid = socket.select_access_point()

            apid = my_select_access_point()
        except:
            appuifw.note(u"Failed to select", "error")
            ut.print_exception()

        self.set_apid(apid)
Exemplo n.º 6
0
 def _examine(self, id):
     ut.report("examining message %d" % id)
     try:
         ut.report("message size is %d" % self.inbox.size(id))
         desc = self.inbox.description(id)
         if self.is_filedata_message(id, desc):
             data = inbox_read_data(self.inbox, id)
             ut.report("message fetched")
             self.inbox.delete(id)
             ut.report("message deleted")
             self.cb(desc, data)
         else:
             ut.report("ignoring non-Filedata message")
     except:
         ut.report("failed to handle message")
         ut.print_exception()
 def create_tn_image(self, tn_size, cb):
     #print "create tn"
     
     try:
         info = graphics.Image.inspect(self.pn)
         #print repr(info)
         img_size = info["size"]
         img = graphics.Image.new(img_size)
         self.tn_size = tn_size
         self.cb = cb
         img.load(self.pn, callback = self._loaded)
         self.image = img
     except:
         ut.print_exception()
         self.tn_fail = True
         raise # re-raise
Exemplo n.º 8
0
 def _scan_btprox(self):
     ut.report("_scan_btprox")
     try:
         if not self.config.get_btprox_scan():
             self._btprox_done(None)
             return
         if not self.btprox_scanner:
             self.init_btprox_scanner()
         if not self.btprox_scanner:
             if not self.btprox_scan_error_shown:
                 self.btprox_scan_error_shown = True
                 appuifw.note(u"Could not scan proximity: Is Bluetooth enabled?", "error")
             self._btprox_done(None)
             return
         self.btprox_scanner.scan(self._btprox_done)
         self.active = True
     except:
         ut.print_exception()
         self._btprox_done(None)
Exemplo n.º 9
0
 def _init_gps_scanner(self):
     """
     It is valid for "self.gps_scanner" to be None, since the
     capabilities required to access GPS may not be available. If
     this method fails, then "self.gps_scanner" will be set to
     None, and will stay that way. To change the used positioning
     module, invoke the appropriate methods on the scanner.
     """
     self.gps_scanner = None
     if gps_avail:
         try:
             omid = self.config.db.get("gps_module_id", None)
             self.gps_scanner = GpsScanner(self._gps_scanned, omid)
         except:
             if ut.get_debug_on():
                 ut.print_exception()
                 ut.report("GPS scanner init failure")
             self.gps_scanner = None
     else:
         ut.report("GPS not available")
Exemplo n.º 10
0
    def send(self, card_data, cb):
        if self.sock:
            raise "still sending"

        self.cb = cb
        self.data = card_data
        apid = self.config.get_apid()

        if not self.serv:
            self.serv = AoSocketServ()
            self.serv.connect()

        if (apid is None) or (apid != self.apid):
            if self.conn:
                self.conn.close()
                self.conn = None
        self.apid = apid
        if (self.apid is not None) and (not self.conn):
            try:
                self.conn = AoConnection()
                self.conn.open(self.serv, self.apid)
            except:
                self.conn = None
                ut.print_exception()

        self.sock = AoSocket()
        try:
            self.sock.set_socket_serv(self.serv)
            if self.conn:
                self.sock.set_connection(self.conn)
            self.sock.open_tcp()
            #print "making connect request"
            self.sock.connect_tcp(unicode(self.host), self.port, self._connected, None)
            #print "now connecting"
        except:
            self.sock.close()
            self.sock = None