omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. lukaskollmer

    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.


    • Profile
    • Following 4
    • Followers 3
    • Topics 23
    • Posts 119
    • Best 30
    • Controversial 0
    • Groups 0

    Lukas Kollmer

    @lukaskollmer

    Programmer

    52
    Reputation
    3244
    Profile views
    119
    Posts
    3
    Followers
    4
    Following
    Joined Last Online
    Website lukaskollmer.me Location Munich, Germany Age 24

    lukaskollmer Unfollow Follow

    Best posts made by lukaskollmer

    • RE: Pythonista Slack or Mattermost

      I think we should use slack-invite-automation. It's a small web application that runs on heroku (at no cost).

      There are two big advantages:

      • Users interested in joining the Slack don't have to post their email address in a public forum
      • The invitations are sent out automatically
      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • [Share Code] Implemented x-callback-url

      This morning I asked if it is possible to use x-callback-urls with Pythonista and access data other apps provide.

      I did some experimentation and came up with a script that is working perfectly.

      What it does:

      • Add support for x-callback.urls to Pythonista
      • Replace the default UIApplication -openURL:sourceApplication:annotation: method with a custom one (Using @JonB's swizzle.py)
      • The custom -openURL: method checks if the url that is opened is the callback from the other app
      • If the url is from the other app, a handler function that you provide will be called, with some information about the url as a parameter
      • Passed information includes:
        • The full url called
        • The app that opened the callback-url
        • A dictionary containing all parameters and their values from the url (This is where you get data you requested from another app)
      • If the url is NOT in response to the x-callback-url, Pythonistas default -openURL: will be called, with all parameters passed to the swizzled one. This ensures that other scripts using the pythonista:// url scheme to open/launch files still work.

      How to use it:
      (Using Drafts as an example, works with any app that supports x-callback-urls)

      import x_callback_url
      
      url = 'drafts4://x-callback-url/get?uuid=YOUR_UUID&x-success=pythonista://'
      def handler(url_info):
          print(info)
          # Do something with the data passed back to Pythonista (available through url_info.parameters)
      
      x_callback_url.open_url(url, handler)
      

      Notes:

      • You'll also need swizzle.py
      • If you don't want to do anything with data passed back to Pythonista, you can omit the handler parameter and just pass the url to x_callback_url.open_url() function
      • This currently supports only the x-success parameter, I'll add support for x-source and x-error at a later point (x-success is by far the most important one)
      • If you have any questions about this, just ask!

      Where you can get this awesome piece of code:

      • Just download it from GitHub

      I have to say that this is the Pythonista script I'm by far the most proud of. Thanks @omz for making this great app!

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • [Share code] Get available memory

      Recently, the question came up how to get memory statistics.
      I found an Objective-C example on StackOverflow and rewrote it using ctypes.

      My gist: https://gist.github.com/lukaskollmer/a09c0278d2d224b9f4839a895ebb9988

      Notes:

      • There are 2 different total memory counts: "total" and "total (according to Cocoa)"
      • Because the graphics card and the CPU share the same memory, the GPU us actually using a part of the RAM for it's graphics memory
      • That's why the first total count is smaller. It's only the amount of memory available to the CPU, while the second total count contains both

      Example:

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • [Share Code] Update iOS contact images with Twitter profile pictures

      Hi,

      I made a small script that scans the iOS contacts list and looks for contacts that have a Twitter handle set in the Social section.
      For every Twitter username found, the app will offer you both the current image and the Twitter profile picture. Then, you can select which image you'd like to set to the contact.

      You can get the script from GitHub.

      Currently, the script will suggest the Twitter picture, even when it is identical with the one from the address book. However, I'll add support for detecting if the images are equal soon.

      This is what it looks like:

      (I know that the code probably could be written in a better, more elegant way, but it is my first Python script and I think it's definetly good enough to share it. If you have any suggestions how it could be improved, please let me know)

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Simple file download.

      @TutorialDoctor Isn't that basically what I already proposed?

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Delete Module

      Why would you want to delete a module? If you don't want to use it, just don't import it in the first place

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: [Tip] adding screenshots to your code

      @JosephBywater you can also replace www with dl and remove the parameters altogether

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • [Share Code] `ui.View`: without x-Button

      I struggled with that recently and just wanted to share my solution:

      If you don't want the default x-Button at the left side of the title bar, just create a ui.NavigationView and present that instead

      import ui
      
      view = ui.View()
      navigationView = ui.NavigationView(view)
      
      # Add a close button
      view.left_button_items = [ui.ButtonItem(title="Close", action=lambda x: navigationView.close())] 
      
      # Won't show the x-button
      navigationView.present("sheet", hide_title_bar=True)
      
      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • [Share Code] Custom editor font

      Recently, I asked if it is possible to use custom fonts in the editor.

      After some experimentation with this, I ended up with a script to automatically load a custom font and set it as Pythonistas default font.

      You can download the example font from http://cdn.kollmer.me/embed/SFMono-Regular.otf

      Add the script to your site-packages Folder and add the following lines to your pythonista-startup.py file:

      import custom_editor_font
      import editor
      import console
      
      # point this to your font file
      font_path = "file://" + os.path.expanduser("~/Documents/Fonts/SFMono/SFMono-Regular.otf")
      
      custom_editor_font.load_custom_font(font_path)
      
      font_name = "SFMono-Regular"
      font_size = 15
      
      custom_editor_font.set_editor_font(font_name, font_size)
      console.set_font(font_name, font_size)
      editor._get_editor_tab().reloadFile()
      

      Now, just change the font name and size based on your preferences.

      NOTE: This is not a perfect solution and may crash or stop working at any time

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Documentation Examples

      @omz
      I think it would be a great idea to publish the documentation on GitHub, thus allowing the community to change descriptions or update outdated examples.
      (I'd love to write some examples and documentation for the evernote module.)

      Also, I don't know how documentation is structured internally (i think it's html files), but it'd make sense to have - unless it's absolutely impossible - documentation for both Python versions in the same file.
      For most modules, the Python 2.7 and 3.5 version consists of roughly the same set of functions/attributes. You could just hide the parts that don't apply to the currently selected Python version. This'd also fix the problem that changing the Python version for coeumentation will return you to the homepage.

      posted in Pythonista
      lukaskollmer
      lukaskollmer

    Latest posts made by lukaskollmer

    • RE: [Share Code] Implemented x-callback-url

      (fyi, you should wrap the code block with ```, to get proper syntax highlighting. reading the code w/out that is really difficult)

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: [Share Code] Implemented x-callback-url

      @eddo888 what do you mean?
      did you swizzle openPythonistaURL: instead of swizzling -[UIApplicationDelegate application:openURL:options:]?

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Phone Call

      Kinda. While there is no API to make a phone call, you can use the webbrowser module to open a tel:PHONE_NUMBER url. This will show a dialog, asking for confirmation to initiate the call. This should work for you since, when the call ends, you automatically return to Pythonista.

      For example, this code makes a call to Amazon Germany:

      import webbrowser
      webbrowser.open('tel:+49-800-2629663')
      
      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Include more custom fonts

      Yes it is indeed possible to load a font from a .otf file at runtime (in fact, I implemented such a feature months ago using the ctypes module), but that's never as good as a proper first-party implementation.

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: objc_util wishlist

      @scj643 it says that the type error is caused by the 3rd argument (which makes sense since 1 is self and 2 is cmd).
      And it can't say which type it wants because it doesn't know what to expect, it just knows that what it got was wrong

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: objc_util wishlist

      @scj643 because it doesn't know. The objc runtime can only get the expected type encoding of an argument or a method's return value. The type encoding specifies which primitive type an argument should be (float/int/char/etc) or whether it is an object. But since ObjC classes are basically just glorified structs, the runtime can't differentiate between different classes. (That's why objc has the id type to represent "any objc-object")

      NSHipster on Type Encodings

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • Include more custom fonts

      It'd be nice if Pythonista offered Apple's SF-Mono font in addition to the existing fonts.

      Another font that'd be very well suited for Pythonista is FiraCode, which is a monospaced font with programming ligatures.
      Since UITextView already supports ligatures, FiraCode would work fine in Pythonista.

      Example of FiraCode:

      cc @omz

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: objc_util wishlist

      @scj643 said:

      Currently objc_utils throws very cryptic errors when a type issue happens with an objc function

      What exactly do you mean? I never found the objc_util errors to be cryptic at all.

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: Adding an image to my own album in Photos – how?

      Pythonista already includes a "draw image and save to camera roll" script in the examples folder. You might be able to learn from that how to save the contents of your view to an image.

      You can find the example script at Documents -> Examples -> User Interface

      posted in Pythonista
      lukaskollmer
      lukaskollmer
    • RE: TableView Swipe Row for More Buttons

      The built in ui.TableView supports only one action per row, but you can use the objc_util module to create a custom UITableView and implement the -[UITableViewDelegate tableView:editActionsForRowAtIndexPath: method which returns an array of table view row actions.

      An other option for multiple actions per row would be to simply add an info accessory button to each row and show an alert w/ more options when the accessory button is pressed

      posted in Pythonista
      lukaskollmer
      lukaskollmer