Beispiel #1
0
 def tableview_did_select(self, tableview, section, row):
     u"""Called when the user selects a row.
     """
     if not tableview.editing:
         fi = self.lists[section][row]
         if section == 0:
             console.show_activity("Loading file list...")
             self.app.push_view(self.app.make_file_list(fi))
             console.hide_activity()
         elif section == 1:
             group = fi.constants.group
             if fi.constants.ext in (u"htm", u"html"):
                 webbrowser.open(u"file://" + fi.path)
                 self.app.close()
             elif group in ("code", "code_tags", "text"):
                 open_path(fi.path)
                 self.app.close()
             elif group == "audio":
                 spath = rel_to_app(fi.path.rsplit(u".", 1)[0])
                 sound.load_effect(spath)
                 sound.play_effect(spath)
             elif group == "image":
                 console.show_image(fi.path)
             else:
                 self.app.close()
                 time.sleep(ANIM_DELAY)
                 console.quicklook(fi.path)
Beispiel #2
0
 def tableview_did_select(self, tableview, section, row):
     # Called when the user selects a row
     if not tableview.editing:
         fi = self.lists[section][row]
         if section == 0:
             console.show_activity()
             nav.push_view(make_file_list(fi))
             console.hide_activity()
         elif section == 1:
             filetype = fi.fileinfo.filetype
             if fi.fileinfo.file_ext in ("htm", "html"):
                 webbrowser.open("file://" + fi.path)
                 nav.close()
             elif filetype in ("code", "code_tags", "text"):
                 open_path(fi.path)
                 nav.close()
             elif filetype == "audio":
                 spath = rel_to_app(fi.path.rsplit(".", 1)[0])
                 sound.load_effect(spath)
                 sound.play_effect(spath)
             elif filetype == "image":
                 console.show_image(fi.path)
             else:
                 console.quicklook(fi.path)
                 nav.close()
Beispiel #3
0
 def take_a_selfie(self, filename='.temp.jpg'):
     self.name = raw_input()
     self.selfie = raw_input()
     if 'selfie' in self.selfie:
         img = photos.capture_image()
         if img:
             img.save(filename)
             console.show_image(filename)
             speech.say(self.name + ', you look stunning!')
             print self.name + ', you look stunning!'
             speech.say(
                 'Would you like to save your master piece in a custom album?'
             )
             print 'Would you like to save your master piece in a custom album?'
             self.to_save_or_not_to_save = raw_input()
             if 'ye' in self.to_save_or_not_to_save:
                 photos.create_album(self.name + 's Album')
                 speech.say(
                     'Okay. I have created your own custom album to save your legendary pic.'
                 )
                 print 'Okay. I have created your own custom album to save your legendary pic.'
                 speech.say(
                     'Hold the image to save your elegant pic in your custom album'
                 )
                 print 'Hold the image to save your elegant pic in your custom album'
                 self.idle()
             else:
                 speech.say(
                     'Affirmative... Your photo will be deleted after this session.'
                 )
                 print 'Affirmative... Your photo will be deleted after this session.'
                 self.idle()
     console.clear()
Beispiel #4
0
 def tableview_did_select(self, tableview, section, row):
     # Called when the user selects a row
     if not tableview.editing:
         fi = self.lists[section][row]
         if section == 0:
             console.show_activity()
             nav.push_view(make_file_list(fi))
             console.hide_activity()
         elif section == 1:
             filetype = fi.fileinfo.filetype
             if fi.fileinfo.file_ext in ("htm", "html"):
                 webbrowser.open("file://" + fi.path)
                 nav.close()
             elif filetype in ("code", "code_tags", "text"):
                 open_path(fi.path)
                 nav.close()
             elif filetype == "audio":
                 spath = rel_to_app(fi.path.rsplit(".", 1)[0])
                 sound.load_effect(spath)
                 sound.play_effect(spath)
             elif filetype == "image":
                 console.show_image(fi.path)
             else:
                 console.quicklook(fi.path)
                 nav.close()
Beispiel #5
0
 def tableview_did_select(self, tableview, section, row):
     u"""Called when the user selects a row.
     """
     if not tableview.editing:
         fi = self.lists[section][row]
         if section == 0:
             console.show_activity()
             self.app.push_view(self.app.make_file_list(fi))
             console.hide_activity()
         elif section == 1:
             group = fi.constants.group
             if fi.constants.ext in (u"htm", u"html"):
                 webbrowser.open(u"file://" + fi.path)
                 self.app.close()
             elif group in ("code", "code_tags", "text"):
                 open_path(fi.path)
                 self.app.close()
             elif group == "audio":
                 spath = rel_to_app(fi.path.rsplit(u".", 1)[0])
                 sound.load_effect(spath)
                 sound.play_effect(spath)
             elif group == "image":
                 console.show_image(fi.path)
             else:
                 self.app.close()
                 time.sleep(ANIM_DELAY)
                 console.quicklook(fi.path)
Beispiel #6
0
def main():
    console.clear()
    i = console.alert('Info', 'This script detects faces in a photo.',
                      'Take Photo', 'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    ci_img = load_ci_image(filename)
    out_file = write_output(ci_img)
    console.show_image(out_file)
    faces = find_faces(ci_img)
    if faces.count() == 0:
        print(
            'Error: Could not find a face in the photo. Please try again with a different image.'
        )
        return
    j = 0
    for face in faces:
        b = face.bounds()
        w = b.size.width
        h = b.size.height
        rt = CGPoint(b.origin.x + w, b.origin.y + h)
        rb = CGPoint(b.origin.x + w, b.origin.y)
        lt = CGPoint(b.origin.x, b.origin.y + h)
        lb = CGPoint(b.origin.x, b.origin.y)
        corners = (rt, rb, lt, lb)
        out_img = apply_perspective(corners, ci_img)
        j = j + 1
        out_file = write_output(out_img, filename='.output' + str(j) + '.jpg')
        console.show_image(out_file)
    print('Tap and hold the image to save it to your camera roll.')
Beispiel #7
0
def main(args):
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("image", action="store", help="image to show")
    ns = p.parse_args(args)
    
    console.show_image(ns.image)
    
    sys.exit(0)
Beispiel #8
0
def show(image, title=None, **options):
	if image.mode != 'RGBA':
		image = image.convert('RGBA')
	tmpfile = tempfile.mktemp()
	w, h = image.size
	console.save_raw_image_data(copy(image.tostring()), image.mode, w, h, tmpfile)
	console.show_image(tmpfile)
	return True
Beispiel #9
0
def show(image, title=None, **options):
    if image.mode != 'RGBA':
        image = image.convert('RGBA')
    tmpfile = tempfile.mktemp()
    w, h = image.size
    console._save_raw_image_data(copy(image.tostring()), image.mode, w, h, tmpfile)
    console.show_image(tmpfile)
    return True
Beispiel #10
0
 def tableview_did_select(self, tableview, section, row):
     u"""Called when the user selects a row.
     """
     key = self.lists[section][1][row][0]
     if key == "ios.quick_look":
         # Preview - Quick Look
         self.app.close()
         time.sleep(ANIM_DELAY)
         console.quicklook(self.fi.path)
     elif key == "editor.edit":
         # Open in Editor - editor
         open_path(self.fi.path)
         self.app.close()
     elif key == "editor.copy_edit":
         # Copy & Open - editor
         destdir = full_path(
             os.path.join(full_path(u"~"), u"Documents/temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(
             os.path.join(destdir,
                          self.fi.basename().lstrip(u".")))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         self.app.close()
     elif key == "editor.copy_edit_txt":
         # Copy & Open as Text - editor
         destdir = full_path(
             os.path.join(full_path(u"~"), u"Documents/temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(
             os.path.join(destdir,
                          self.fi.basename().lstrip(u".") + u".txt"))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         self.app.close()
     elif key == "console.print_image":
         # Show in Console - console
         console.show_image(self.fi.path)
     elif key == "sound.play_sound":
         # Play Sound - sound
         spath = rel_to_app(self.fi.path.rsplit(u".", 1)[0])
         sound.load_effect(spath)
         sound.play_effect(spath)
     elif key == "webbrowser.open":
         # Open Website - webbrowser
         webbrowser.open(u"file://" + self.fi.path)
         self.app.close()
     elif key == "ios.open_in":
         # Open In - External Apps
         if console.open_in(self.fi.path):
             self.app.close()
         else:
             console.hud_alert(u"Failed to Open", "error")
def run_ui(err_m=""):
    stre = str(err_m)
    if stre.count('Rate limit exceeded') > 0:
        console.hud_alert('【制限エラー】15分後にお試しください')
        console.show_image('./src/limit_error.png')
        sys.exit()
    v.present('sheet')
    if stre.count('.tw.txt') > 0:
        v['PRINT'].text = "まだ設定されていません。"

    v['send_code'].text = str(send_code)
def _show():
    from matplotlib._pylab_helpers import Gcf
    active_manager = Gcf.get_active()
    if active_manager:
        import console
        import tempfile
        screen_width, screen_height = console._get_screen_size()
        compact = screen_width < 768
        dpi = 160 if not compact else 66.2
        tmp = tempfile.mktemp(suffix='.png')
        active_manager.canvas.figure.savefig(tmp, dpi=dpi)
        console.show_image(tmp)
Beispiel #13
0
def _show():
    from matplotlib._pylab_helpers import Gcf
    active_manager = Gcf.get_active()
    if active_manager:
        import console
        import tempfile
        screen_width, screen_height = console._get_screen_size()
        compact = screen_width < 768
        dpi = 160 if not compact else 66.2
        tmp = tempfile.mktemp(suffix='.png')
        active_manager.canvas.figure.savefig(tmp, dpi=dpi)
        console.show_image(tmp)
Beispiel #14
0
 def tableview_did_select(self, tableview, section, row):
     u"""Called when the user selects a row.
     """
     key = self.lists[section][1][row][0]
     if key == "ios.quick_look":
         # Preview - Quick Look
         self.app.close()
         time.sleep(ANIM_DELAY)
         console.quicklook(self.fi.path)
     elif key == "editor.edit":
         # Open in Editor - editor
         open_path(self.fi.path)
         self.app.close()
     elif key == "editor.copy_edit":
         # Copy & Open - editor
         destdir = full_path(os.path.join(full_path(u"~"), u"Documents/temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(u".")))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         self.app.close()
     elif key == "editor.copy_edit_txt":
         # Copy & Open as Text - editor
         destdir = full_path(os.path.join(full_path(u"~"), u"Documents/temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(u".") + u".txt"))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         self.app.close()
     elif key == "console.print_image":
         # Show in Console - console
         console.show_image(self.fi.path)
     elif key == "sound.play_sound":
         # Play Sound - sound
         spath = rel_to_app(self.fi.path.rsplit(u".", 1)[0])
         sound.load_effect(spath)
         sound.play_effect(spath)
     elif key == "webbrowser.open":
         # Open Website - webbrowser
         webbrowser.open(u"file://" + self.fi.path)
         self.app.close()
     elif key == "ios.open_in":
         # Open In - External Apps
         if console.open_in(self.fi.path):
             self.app.close()
         else:
             console.hud_alert(u"Failed to Open", "error")
def tweet_get(twpy_api, userid, first=False):
    global switch
    try:
        gtweets = twpy_api.user_timeline(count=1, screen_name=userid)
        return tweets2element(gtweets)
    except Exception as e:
        if switch == 0:
            en = re.sub('[^0-9]','', str(e.args))
            if en == '88':
                console.hud_alert('【取得制限エラー】','error')
                if first:
                    console.show_image('./src/limit_error.png')
        	
        switch = 2
        sys.exit(3)
        return False
Beispiel #16
0
def main():
    console.clear()
    i = console.alert('Info', '画像の入力方法を選択して下さい。', 'Take Photo',
                      'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    console.show_image(filename)
    img = img_to_base64(filename)
    res_json = goog_cloud_vison(img)
    #print res_json
    imagebuffer = Image.open(filename)
    highlight_faces(imagebuffer, res_json['responses'][0]['faceAnnotations'])
def main():
    console.clear()
    i = console.alert('Info', '画像の入力方法を選択して下さい。', 'Take Photo',
                      'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    console.show_image(filename)
    img = img_to_base64(filename)
    res_json = goog_cloud_vison(img)
    #print res_json
    #print json.dumps(res_json, indent=2, sort_keys=True)
    print_description(res_json)
Beispiel #18
0
def findFrame(parent, fp, callback=None, userdata=None):
    
    while parent.isPlaying():
        line = fp.readline()
        if line[:len('--ipcamera')] == '--ipcamera':
            fp.readline()
            content_length = int(fp.readline().split(':')[1].strip())
            fp.readline()
            jpeg = fp.read(content_length)
            with open('test.jpg','w') as f:
                f.write(jpeg)
                console.show_image('test.jpg')
                time.sleep(0.1)
                console.clear()
                
            if callback:
                callback(jpeg, userdata)
Beispiel #19
0
def main():
	console.clear()
	i = console.alert('Info', 'This script detects a printed page (e.g. a receipt) in a photo, and applies perspective correction and contrast enhancement filters automatically.\n\nThe result is a "scanned" black&white image that you can save to your camera roll.\n\nFor best results, make sure that the page is evenly lit.', 'Take Photo', 'Pick from Library')
	if i == 1:
		filename = take_photo()
	else:
		filename = pick_photo()
	if not filename:
		return
	ci_img = load_ci_image(filename)
	corners = find_corners(ci_img)
	if not corners:
		print('Error: Could not find a rectangle in the photo. Please try again with a different image.')
		return
	out_img = apply_perspective(corners, ci_img)
	out_img = enhance_contrast(out_img)
	out_file = write_output(out_img)
	console.show_image(out_file)
	print('Tap and hold the image to save it to your camera roll.')
Beispiel #20
0
    def openSelected(self):
        if self.scroller.sublayer.selected:
            filename = self.scroller.sublayer.selected.text
            absolute_path = os.path.join(self.fs.cwd, filename)
            relative_path = os.path.relpath(absolute_path)
            ext = os.path.splitext(filename)[1]

            if self.fs.isdir(absolute_path):
                self.opendir(filename)
            # cant open anything below the documents folder
            elif ext in ['.png', '.jpg']:
                console.show_image(absolute_path)
                sys.exit()
            elif relative_path[:2] != '..':
                if ext == '.py':
                    editor.open_file(relative_path)
                    sys.exit()
                else:
                    show_tempfile(absolute_path)
            else:
                show_tempfile(absolute_path)
Beispiel #21
0
	def openSelected(self):
		if self.scroller.sublayer.selected:
			filename = self.scroller.sublayer.selected.text
			absolute_path = os.path.join(self.fs.cwd,filename)
			relative_path = os.path.relpath(absolute_path)
			ext = os.path.splitext(filename)[1]

			if self.fs.isdir(absolute_path):
				self.opendir(filename)
			# cant open anything below the documents folder
			elif ext in ['.png','.jpg']:
				console.show_image(absolute_path)
				sys.exit()
			elif relative_path[:2] != '..':
				if ext == '.py':
					editor.open_file(relative_path)
					sys.exit()
				else:
					show_tempfile(absolute_path)
			else:
				show_tempfile(absolute_path)
Beispiel #22
0
def test():
  default_mode = spelling_mode.spelling_mode()
  rulesets.set_default_mode(default_mode.combination)
  text = rulesets.to_upper(unicode(sample_text.get_sample_text()))
  histogram = statistics.map_labels(statistics.get_letter_histogram(text), DEFAULT_REPLACEMENTS)
  histogram2 = statistics.keep_n_largest(histogram, 20)
  print histogram2
  print histogram2[:][1]
  plot_letter_histogram(TMP_PLOT_FILE, histogram2, 200, 200)
  console.show_image(TMP_PLOT_FILE)

  new_text = text[100:] + 'XXÖÖÜßßßßxxxxp'
  histogram = statistics.get_letter_histogram(text)
  histogram2 = statistics.get_letter_histogram(new_text)

  changes = statistics.compute_changes(histogram, histogram2)
  summary_small_changes = statistics.summarize_small_changes(changes, 0.05)
  actual_changes = statistics.keep_actual_changes(changes,0.05)  
  
  plot_frequency_change_bars(TMP_PLOT_FILE, actual_changes, 600, 200, summary_small_changes)
  console.show_image(TMP_PLOT_FILE)  
Beispiel #23
0
def main():
    console.clear()
    i = console.alert(
        'Info',
        'This script detects a printed page (e.g. a receipt) in a photo, and applies perspective correction and contrast enhancement filters automatically.\n\nThe result is a "scanned" black&white image that you can save to your camera roll.\n\nFor best results, make sure that the page is evenly lit.',
        'Take Photo', 'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    ci_img = load_ci_image(filename)
    corners = find_corners(ci_img)
    if not corners:
        print 'Error: Could not find a rectangle in the photo. Please try again with a different image.'
        return
    out_img = apply_perspective(corners, ci_img)
    out_img = enhance_contrast(out_img)
    out_file = write_output(out_img)
    console.show_image(out_file)
    print 'Tap and hold the image to save it to your camera roll.'
Beispiel #24
0
def main():
    if appex.is_running_extension():
        images = appex.get_attachments('public.jpeg')
    else:
        print('Pick a photo to mask.')
        images = [pick_photo()]

    print(images)

    if not images:
        print('No input image found')
        return
    ci_img = load_ci_image(images[0])
    faces = find_faces(ci_img)
    if not faces:
        print('Error: No faces found in the photo.')
        return
    out_img = mask_faces(ci_img, faces)
    out_file = write_output(out_img)
    console.clear()
    console.show_image(out_file)
    console.alert('Tweet this image?')
Beispiel #25
0
 def tableview_did_select(self, tableview, section, row):
     # Called when the user selects a row
     key = self.lists[section][1][row][0]
     if key == "shellista-cd":
         # Go Here - Shellista
         nav.close()
         print("Launching Shellista...")
         try:
             from Shellista import Shell
         except ImportError as err:
             print("Failed to import Shellista: " + err.message)
             print("See note on Shellista integration at the top of filenav.py.")
             print("> logout")
             return
         shell = Shell()
         shell.prompt = "> "
         shell.onecmd("cd " + self.fi.path)
         print("> cd " + self.fi.path)
         shell.cmdloop()
     elif key == "ios-qlook":
         # Preview - Quick Look
         nav.close()
         time.sleep(1)  # ui thread will hang otherwise
         console.quicklook(self.fi.path)
     elif key == "pysta-edit":
         # Open in Editor - Pythonista
         open_path(self.fi.path)
         nav.close()
     elif key == "pysta-cpedit":
         # Copy & Open - Pythonista
         destdir = full_path(os.path.join(SCRIPT_ROOT, "temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".")))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         nav.close()
     elif key == "pysta-cptxt":
         # Copy & Open as Text - Pythonista
         destdir = full_path(os.path.join(SCRIPT_ROOT, "temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".") + ".txt"))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         nav.close()
     elif key == "console-printimg":
         # Show in Console - console
         console.show_image(self.fi.path)
     elif key == "sound-playsound":
         # Play Sound - sound
         spath = rel_to_app(self.fi.path.rsplit(".", 1)[0])
         sound.load_effect(spath)
         sound.play_effect(spath)
     elif key == "webbrowser-open":
         # Open Website - webbrowser
         webbrowser.open("file://" + self.fi.path)
         nav.close()
     elif key == "ios-openin":
         # Open In - External Apps
         if console.open_in(self.fi.path):
             nav.close()
         else:
             console.hud_alert("Failed to Open", "error")
Beispiel #26
0
def main():
    console.clear()
    i = console.alert('Info', 'This script detects faces in a photo.',
                      'Take Photo', 'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    ci_img = load_ci_image(filename)
    out_file = write_output(ci_img)
    console.show_image(out_file)
    # faces = find_faces(ci_img)
    ### ここから ###
    mainfolder = "./"
    outputfolder = ""
    trainfolder = "training-images"
    testfolder = "test-images"
    if os.path.exists(trainfolder + '/1'):
        shutil.rmtree(trainfolder + '/1')
    ###if os.path.exists(testfolder+'/1'):
    ###	shutil.rmtree(testfolder+'/1')
    os.mkdir(trainfolder + '/1')
    ###os.mkdir(testfolder+'/1')
    # convert from JPG to MNIST data format
    path_jpg = ".output.jpg"
    path_png = "output.png"
    img = Image.open(path_jpg)
    # アルファ値を考慮したグレイスケールに変換
    img = img.convert("L")
    # 白黒反転
    img = ImageOps.invert(img)
    img = img.point(lambda x: 0 if x < 130 else x)
    img = img.point(lambda x: (x * 1000))
    # 画像内で値が0でない最小領域を返す
    crop = img.split()[-1].getbbox()
    img.crop(crop)
    # 28x28のサイズに縮小
    img = img.resize((28, 28), Image.LANCZOS)
    img.save(path_png)
    # 下段に画像を表示
    ci_img = load_ci_image(path_png)
    out_file = write_output(ci_img,
                            filename='./training-images/1/output' + '.png')
    console.show_image(out_file)
    #
    tmp_img = Image.open(path_png)
    tmp_img = ImageOps.mirror(tmp_img)
    tmp_img = tmp_img.rotate(90)
    tmp_img.save(path_png)
    ci_img = load_ci_image(path_png)
    out_file = write_output(ci_img,
                            filename='./training-images/1/output' + '.png')

    # MNISTデータへの変換
    itm = image_mnist(main_folder=mainfolder,
                      output_folder=outputfolder,
                      train_folder=trainfolder,
                      test_folder=testfolder)
    itm.image_to_mnist(toSquare=False, minSquareSize=28, convertToGZip=True)
    # MNISTデータのロード
    ###(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)
    (x_train, t_train) = load_thimage(flatten=False, normalize=False)
    ###print(x_train.shape)
    ###print(x_train)
    print(x_train[0].shape)
    plt.imshow(x_train[0][0, :, :])
    plt.show()
    # DeepConvNetによる推測
    hoge = deep_convnet.DeepConvNet()
    hoge.load_params(file_name='deep_convnet_params.pkl')
    x = hoge.predict(x_train, train_flg=False)
    print(x.shape)
    print(x)
    # 最も確率の高い要素のインデックスを取得
    p = np.argmax(x)
    print('=== PREDICT ===')
    print(p)
    print('===============')
Beispiel #27
0
def show_image(image):

    if console:
        console.show_image(image)
    else:
        webbrowser.open(image)
Beispiel #28
0
def view_ci_image(ci_img):
    filename = write_output(ci_img)
    console.show_image(filename)
Beispiel #29
0
 def tableview_did_select(self, tableview, section, row):
     # Called when the user selects a row
     key = self.lists[section][1][row][0]
     if key == "shellista-cd":
         # Go Here - Shellista
         nav.close()
         print("Launching Shellista...")
         try:
             from Shellista import Shell
         except ImportError as err:
             print("Failed to import Shellista: " + err.message)
             print("See note on Shellista integration at the top of filenav.py.")
             print("> logout")
             return
         shell = Shell()
         shell.prompt = '> '
         shell.onecmd("cd " + self.fi.path)
         print("> cd " + self.fi.path)
         shell.cmdloop()
     elif key == "ios-qlook":
         # Preview - Quick Look
         nav.close()
         time.sleep(1) # ui thread will hang otherwise
         console.quicklook(self.fi.path)
     elif key == "pysta-edit":
         # Open in Editor - Pythonista
         open_path(self.fi.path)
         nav.close()
     elif key == "pysta-cpedit":
         # Copy & Open - Pythonista
         destdir = full_path(os.path.join(SCRIPT_ROOT, "temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".")))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         nav.close()
     elif key == "pysta-cptxt":
         # Copy & Open as Text - Pythonista
         destdir = full_path(os.path.join(SCRIPT_ROOT, "temp"))
         if not os.path.exists(destdir):
             os.mkdir(destdir)
         destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".") + ".txt"))
         shutil.copy(self.fi.path, destfile)
         editor.reload_files()
         open_path(destfile)
         nav.close()
     elif key == "console-printimg":
         # Show in Console - console
         console.show_image(self.fi.path)
     elif key == "sound-playsound":
         # Play Sound - sound
         spath = rel_to_app(self.fi.path.rsplit(".", 1)[0])
         sound.load_effect(spath)
         sound.play_effect(spath)
     elif key == "webbrowser-open":
         # Open Website - webbrowser
         webbrowser.open("file://" + self.fi.path)
         nav.close()
     elif key == "ios-openin":
         # Open In - External Apps
         if console.open_in(self.fi.path):
             nav.close()
         else:
             console.hud_alert("Failed to Open", "error")
Beispiel #30
0
    console.clear()
    i = console.alert(
        'Info',
        'This script detects a printed page (e.g. a receipt) in a photo, and applies perspective correction and contrast enhancement filters automatically.\n\nThe result is a "scanned" black&white image that you can save to your camera roll.\n\nFor best results, make sure that the page is evenly lit.',
        'Take Photo', 'Pick from Library')
    if i == 1:
        filename = take_photo()
    else:
        filename = pick_photo()
    if not filename:
        return
    ci_img = load_ci_image(filename)
    corners = find_corners(ci_img)
    if not corners:
        print(
            'Error: Could not find a rectangle in the photo. Please try again with a different image.'
        )
        return
    out_img = apply_perspective(corners, ci_img)
    out_img = enhance_contrast(out_img)
    out_file = write_output(out_img)
    return out_file
    #console.show_image(out_file)
    #print('Tap and hold the image to save it to your camera roll.')


if __name__ == '__main__':
    result = main()
    console.show_image(result)
    print('Tap and hold the image to save it to your camera roll.')