Beispiel #1
0
 def view_image(self, img):
     if os.path.isfile(img):
         local = True
     else:
         local = False
         
     if local:
         viewer = Content_handler(self.refresh)
         try:
             viewer.open(img)
         except:
             note(LABELS.loc.pt_err_cant_open % img,"error") 
     else:
         local_file = "img_" + time.strftime("%Y%m%d_%H%M%S", time.localtime())
         local_file = os.path.join(DEFDIR, "cache", local_file)
         d = img.rfind(".")
         if d >= 0:
             local_file = local_file + img[d:]
             self.lock_ui(LABELS.loc.pt_info_downld_img % img)
             try:
                 urlprx = UrllibProxy(BLOG.get_proxy())
                 urlprx.urlretrieve(img, local_file)
             except:
                 note(LABELS.loc.pt_err_cant_downld % img,"error")
                 self.unlock_ui()
                 return
             self.unlock_ui()
             viewer = Content_handler(self.refresh)
             try:
                 viewer.open(local_file)
             except:
                 note(LABELS.loc.pt_err_cant_open % img,"error") 
         else:
             note(LABELS.loc.pt_err_unknown_ext % img,"error")
Beispiel #2
0
    def preview_html(self):

        html = self.text_to_html(self.body.get()).encode('utf-8')
        
        name = "html_" + time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".html"
        name = os.path.join(DEFDIR, "cache", name)

        soup = BeautifulSoup(html)
        imgs = soup.findAll('img')
        for img in imgs:
            if os.path.isfile(img["src"]):
                img["src"] = "file://localhost/" + img["src"]
                
        html = soup.prettify().replace("\n","")      

        try:
            fp = open(name,"wt")
            fp.write("<html>\n")
            fp.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n')
            fp.write("<body>\n")
            fp.write(html)
            fp.write("</body></html>")
            fp.close()
        except:
            note(LABELS.loc.pt_err_cant_gen_prvw,"error")
            return
        
        viewer = Content_handler(self.refresh)
        try:
            viewer.open(name)
        except:
            note(LABELS.loc.pt_err_cant_prvw,"error")
Beispiel #3
0
 def take_photo(self):
     try:
         img = camera.take_photo(size = camera.image_sizes()[self.setup['image_size']],
                                 flash = camera.flash_modes()[self.setup['flash_mode']],
                                 exposure = camera.exposure_modes()[self.setup['exp_mode']],
                                 white_balance = camera.white_balance_modes()[self.setup['white_mode']])
         self.filename = time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".jpg"
         self.filename = os.path.join(DEFDIR, "images", self.filename)
         img.save(self.filename)            
     except:
         note(LABELS.loc.pt_err_cant_take_pic,"error")
         self.cancel_app()
         return
     
     self.taken = True
Beispiel #4
0
    def upgrade(self):
        self.lock_ui(LABELS.loc.wm_info_check_updt)
        
        url = "http://code.google.com/p/wordmobi/wiki/LatestVersion"
        local_file = "web_" + time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".html"
        local_file = os.path.join(DEFDIR, "cache", local_file)

        try:
            urlprx = UrllibProxy(BLOG.get_proxy())
            urlprx.urlretrieve(url, local_file)
        except:
            note(LABELS.loc.wm_err_upd_page % url,"error")
            ok = False
        else:
            ok = True

        if ok:
            html = open(local_file).read()
            soup = BeautifulSoup( html )
            addrs = soup.findAll('a')
            version = ""
            file_url = ""
            file_url_py19 = ""
            for addr in addrs:
                if addr.contents[0] == "latest_wordmobi_version":
                    version = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url":
                    file_url = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url_py19":
                    file_url_py19 = addr["href"]

            if version and file_url and file_url_py19:
                version = version[version.rfind("/")+1:]
                num_rem_ver = self.ver2num(version)
                num_loc_ver = self.ver2num(VERSION)
                if (num_loc_ver >= num_rem_ver) and (VERSION.find('RC') == -1):
                    # RC versions gives to the user the upgrading decision
                    note(LABELS.loc.wm_info_ver_is_updt, "info")
                else:
                    yn = popup_menu( [LABELS.loc.gm_yes,LABELS.loc.gm_no],
                                     LABELS.loc.wm_pmenu_download % (version) )
                    if yn is not None:
                        if yn == 0:
                            if float(e32.pys60_version[:3]) >= 1.9:
                                furl = file_url_py19
                            else:
                                furl = file_url
                            sis_name = furl[furl.rfind("/")+1:]
                            local_file = os.path.join(DEFDIR, "updates", sis_name)

                            self.set_title( LABELS.loc.wm_info_downloading )
                            try:
                                urlprx = UrllibProxy(BLOG.get_proxy())
                                urlprx.urlretrieve(furl, local_file)
                            except:
                                note(LABELS.loc.wm_err_downld_fail % sis_name, "error")
                            else:
                                msg = LABELS.loc.wm_info_downld_ok % (sis_name,DEFDIR)
                                note( msg , "info")

            else:
                note(LABELS.loc.wm_err_upd_info,"error")
                
        self.set_title( u"Wordmobi" )
        self.unlock_ui()
        self.refresh()
Beispiel #5
0
def get_time_list(id_list):
	inb = inbox.Inbox()
	time_list = [inb.time(id) for id in id_list]
	sorted(time_list)
	time_list = [time.strftime("%d %H:%M", time.localtime(t)) for t in time_list]
	return time_list
Beispiel #6
0
def localtime_iso8601():
    return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())