Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Sounds & Fonts
-
It would be pretty easy to do this in 1.6, using
objc_util
, but I think you're still on 1.5, right?Edit: It would look something like this:
from objc_util import * UIFont = ObjCClass('UIFont') all_fonts = [] families = UIFont.familyNames() for family in families: names = UIFont.fontNamesForFamilyName_(family) all_fonts += names
-
Also- that website project is here:
https://github.com/mcritz/iosfonts?files=1Read the license. Looks like you could use it with reference.
Json file in the data folder. -
Yes omz , still 1.5. I can see I have to be a little bit careful about my comments as it seems a lot will be possible with 1.6 that's not possible in 1.5. I will roll my own solution for now. Good learning exp. for me. If I knew 1.5 back the front, I would be begging to get 1.6, but I have a long way to go :) but ok thanks, it answers my question.
-
I don't really think you can copyright a list of fonts that is most likely generated automatically, but giving credit is always nice of course.
The benefit of generating the list dynamically on the device are
a) It would include custom fonts that are bundled with Pythonista.
b) It would update automatically when new fonts are added in the OS.
c) You don't need an internet connection.
...but anyway, right now it's only possible in the 1.6 beta, so if you're on 1.5, scraping iosfonts.com is probably a good option.
-
@omz, I agree with all your points. I think I am getting a little used to its not possible on iOS. But, I don't get stressed about it, I have time. I was very inflexible when I was younger, but now I am fairly laid back. Well really laid back :)
Actually, the repo that @cook points to, has a JSON file from the author of the iosfonts.com website. So that was nice of him. I have no commercial interest in any data, trying to write a few apps for some good friends.
@cook, thanks for the repo link. I have got the JSON file. Now will try to understand it programmatically :)
-
I'm pretty sure with the beta (which you can through via TestFlight by Apple https://appsto.re/us/W4wM1.i)
You are able to record audio. I remember a while back I asked a similar question, if you search "Audio" and look for a question by Reefboy1, there should be some help there. Good luck! -
One way to get a list of fonts might be to pull a long list of font names off somewhere and see which ones don't produce errors if you try to use them.
Something like:
# coding: utf-8 from PIL import ImageFont fonts = ["Helvetica", "Courier", "FontNameThatDoesNotExist", "Arial", "PoopingPenguins", "Inconsolata"] installed_fonts = [] for font in fonts: try: ImageFont.truetype(font, 10) installed_fonts.append(font) except: print "Font '"+font+"' not found." print "\nThe installed fonts are:\n" + "\n".join(installed_fonts)
-
That won't work (
console.set_font
never throws an exception, it just ignores invalid fonts). -
Ah, thanks. What about
PIL.ImageFont
? -
I think that would work, yes.
-
Edited, but still haven't tested. Can someone test that code for me?
-
Yes. The code works as expected if you remove the quotes around "font" in the append() line.
Of course it is also best practice to change
except:
toexcept TypeError:
. ;-) -
Right, @ccc, but I didn't know what kind of exception it would throw since I'm not somewhere I can test it.
-
I love that you can play sounds directly from their urls. Is there a way to simplify the script for this?
-
@jerovargas something like this?
import ui webview = ui.WebView() webview.frame = (0,0,600,100) url = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3' webview.load_url(url) webview.present('sheet')
-
What about using these apis... http://omz-software.com/pythonista/docs/ios/sound.html
-
@ccc He asked to play directly from url...
-
@jerovargas, here’s a more light-weight alternative, which does play the sound ”directly from the url”, but only after it has been fully downloaded. I tried to combine streaming with
play_effect
, but was unsuccessful.import tempfile import sound import requests def play(url): with tempfile.NamedTemporaryFile(suffix='.caf') as fp: r = requests.get(url) r.raise_for_status() fp.write(r.content) sound.play_effect(fp.name) play('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3')
-
@jerovargas, ok, a version that streams a longer file instead of downloading it first.
import objc_util objc_util.load_framework('AVFoundation') AVPlayer = objc_util.ObjCClass('AVPlayer') def play(url): audio_player = AVPlayer.playerWithURL_(objc_util.nsurl(url)) audio_player.play() return audio_player player = play('https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_2MG.mp3') input('Press enter to stop') player.pause()