omz:forum

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

    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 0
    • Followers 90
    • Topics 41
    • Posts 2264
    • Best 449
    • Controversial 0
    • Groups 1

    omz

    @omz

    admin

    I make Pythonista and Editorial – @olemoritz on Twitter.

    789
    Reputation
    32733
    Profile views
    2264
    Posts
    90
    Followers
    0
    Following
    Joined Last Online
    Website omz-software.com Location Berlin

    omz Unfollow Follow
    admin

    Best posts made by omz

    • Python 3.x Progress Update

      Python 3.x support has been a topic of discussion here for years, and I finally have some news on that front. :)

      As I've teased a bit earlier on Twitter, I'm working on a version of Pythonista that is based on Python 3.5.1 instead of the current 2.7.5. I've made pretty good progress recently, and the app is already in a completely usable state with most custom and third-party modules working. The app's UI is essentially identical to Pythonista 2.0.

      Things that are working so far:

      • Python 3.5.1 with all new syntax features and most standard library modules (exceptions are basically the same as in 2.x, i.e. mostly Tkinter)
      • Numpy, matplotlib, Pillow, PyCrypto, and most other third-party modules that are currently included in Pythonista 2.0 (in some cases more recent versions than in 2.0)
      • Most custom modules (ui, scene, contacts, reminders, ...)

      Not working yet:

      • A few custom modules (currently only notification, editor, and canvas)
      • The app extension (invoking Pythonista from the share sheet)
      • The URL scheme
      • The documentation browser
      • The example scripts aren't completely ported yet
      • A couple of third-party modules that are included in Pythonista 2.0, but aren't (yet?) compatible with Python 3 (screenplain, midiutil, mechanize, xhtml2pdf)

      There are probably still a few bugs in the ported versions of my custom modules. Getting the string/unicode handling to work right has been tricky in some cases, and I haven't tested all modules very thoroughly yet.

      I expect that I'll have the first beta ready within the next week or so, hopefully without some of the limitations I've listed above. I'll post a new beta signup form here when I'm ready.

      Lastly, this will be a separate app, or "paid upgrade" if you will. This is, by the way, one of the reasons I did not charge for the 2.0 update. It'll co-exist with Pythonista 2.x for a while because there are still valid reasons to prefer Python 2.7, and I don't want to force people to upgrade to a version that is not backwards-compatible.

      As I've mentioned before, creating an app that supports both Python 2 and 3 would be very difficult, if not impossible. The only way this could theoretically work would require relaunching the app in order to switch versions, and I honestly think that having Python 3 in a separate app will result in a better user experience and less confusion. It will be possible to access files in Pythonista 2.x from 3.x though (and vice-versa).

      posted in Pythonista
      omz
      omz
    • Pythonista Slack Chat

      I'll put this here as a sticky post, so that it's easier to find, without digging through old threads...

      We now have a Slack chat for discussing all things Pythonista, and everyone who's interested can sign up here:

      → Join Pythonista Slack

      This is not intended to be a replacement for the forum. In a lot of cases, it is much more useful to post questions and feedback here because the forum content is indexed by search enginees, available publicly (without signing up for anything), and generally more long-lived. A lot of questions come up more than once, and it's useful to be able to link to forum topics later.

      Note: This topic is locked, but if you have any trouble with the Slack signup, please feel free to create a new thread.

      posted in Pythonista
      omz
      omz
    • Pythonista 2 Release

      Good news: Pythonista 2 has been approved by Apple, and will be out on Monday (tomorrow).

      I would recommend that all beta users do a backup before updating because I'm not completely sure if a clean update will be possible from the beta. Actually, you might also want to do this if you are not using the beta, just to be sure. There's always a possibility that something goes wrong with a major update like this.

      2.0 will be a free update for existing users, but I intend to increase the price for new purchases to $9.99 (version 1.5 is currently $6.99).

      posted in Pythonista
      omz
      omz
    • RE: Python 3.x Progress Update

      @ccc @OI

      The final version of Python 3.6 is still quite a long way off, so I'm not too concerned about that...

      The current beta is taking a bit longer because I'm in the process of making some pretty substantial changes. In short, I've found out that my assumptions about using Python 2 + 3 in the same app were incorrect, and that it is in fact possible to do this, even without having to restart the app when switching interpreters.

      As I really only want to have one version of Pythonista, to avoid confusion and backwards-compatibility woes, my current plan is to make Pythonista 3 support both Python 2.7 and 3.5. It's actually working quite well already, but there are just a lot of little details to consider, things to move around, refactor, etc.

      This doesn't change my plan to make this a paid upgrade btw.

      posted in Pythonista
      omz
      omz
    • Helper script for embedding pyui files in single-file scripts

      I've just built a little script to make it easier to share UI scripts. Sometimes, it's just more convenient to have everything in a single file for simple copy/paste – this basically generates code to load the UI from an embedded (compressed) string instead of from an external .pyui file.

      Here's the code:

      EmbedPyui.py (Gist)

      (some more details about how to use it in the docstring)

      And this is an example of what the generated code looks like (this is from the bundled ColorMixer example):

      data = '''\
      QlpoOTFBWSZTWXGZJlkAA4FfgBAAWGd/8D/HGYq/79/6UAOe4DODcAKGkSeRpNPSNlHoTQ
      AMgAAADSBoaKnsEk0AABoAAABElCmxEyah6T9SGgNqeKGjTQGTR6hzAATAAEwAAAAACpJC
      NTAp6NNINqADQAaeo00zUeLNIRevYhXCrDnMydv5ddssuKvtW15+Xbtq5Jb7tdp+9zbxAt
      0YFOEK1PYeGP1TvLaJaWQwRKSmwu10yMYD+I3AZhIpeImxVjxApqNRWMEpqlaWFSEBpDL/
      aufdj7d+bciZInpuffUawrbLDoAvAbnRnsGwjlCwY3AQoiMikcVFxjaN+bHfmJbntv5eF2
      +uFa81a57LMdue7TprLZNiPISIBIJIpCEjJJyQUTLnrPqyRNwBBIRSQ6G5UCEdREAQhnkc
      6VdTklBZifrGeSmnRkpxuY0EVsxA1pVB5Qsz4MiA4S8EXkSFKFsCzBrVMbE5AonjPMqxNC
      wkHGbGhkyVvKNgvhUrMzbhyRIMUtxbanSoYg+DVEpEagCDTofplQ3HJlBms7EigcLOq3RN
      EFnsFtYRbfKW4/Xg+4el7Z5BiEa4QvDTfExOSYnYNrB8bvRTDiUXComARAkIEKYi2uQM0N
      wquuSlujXUQINEaOD0so0QHiOEwuir0S0zm12Bd4dWkF5BtsG9FSbCDFaughLw0+P7WKlQ
      DzAdvV2jJ1bfW8DetJUYFS5Uu4fTq9o4DhGuO1X7cZkkZhiMA2oxWh2ilVcKF0RctN1Xou
      kwaxiLoYw7hbBokOM/0utJ81GN1q71DY/mocm3dN37tJFhz/3wTOL29qnhmhI3MriMuzv2
      ugX87PJph2cWzffrVjBZ02cdE6BvZLDeyOedIocsxTdhkSLRyblpDmvSXjP5aUqNoy4N14
      syUvKLVLTKNLr1xGhgilLNaVL6cqRkhh0DTObOaIqIqSZhaGcahUjYMBllDUyaHJr8EpNg
      7t+MqoZhg357F85kWcrJrJ0yLGcapzSM2mYR5gNDHyATsKOUTCXuuAaYcWnwTbJzAd/ApR
      Ucg6hwdb9dn84ZR9Rl4V+Zav+LuSKcKEg4zJMsgA==
      '''
      import ui
      import bz2
      from base64 import b64decode
      pyui = bz2.decompress(b64decode(data))
      v = ui.load_view_str(pyui.decode('utf-8'))
      

      Should work in Pythonista 2 and 3 (beta).

      posted in Pythonista
      omz
      omz
    • RE: [Feature Request] Pythonista built-in file picker

      I've started working on a file picker dialog that I might add to the dialogs module. You can find the code here:

      → File Picker.py (works in Pythonista 2 and 3)

      The API isn't exactly like you suggested, but similar, and quite extensible. As a demo, I've implemented an alternative "data source" that shows files and folders from an FTP server instead of the local file system. It would easily be possible to build a Zip file browser with this as well...

      The idea is basically that you can subclass TreeNode to represent whatever kind of tree structure you need. The TreeDialogController gets one TreeNode as its root and a couple of options (multiple selection etc.). The TreeNode is then responsible for loading its children (each of the children is also a TreeNode), and each node has a title/icon that is shown in the table view. For cases when a node might take a relatively long time to load its children, TreeDialogController has an async_mode option that causes it to automatically dispatch the loading to a background thread, and to show a spinner overlay while loading.

      Overall, the UI is very close to Pythonista's own directory picker, i.e. I'm using the same icons, table view animations, etc.

      Screenshot

      posted in Pythonista
      omz
      omz
    • Barcode / QR Code Camera Scanner Demo (objc_util)

      Someone asked me on Twitter if Pythonista had support for scanning barcodes, using the camera. While there's nothing like that built-in, I looked around a bit, and it turns out that there are APIs for this in Apple's AVFoundation framework, so I thought it might be interesting to build a wrapper around that.

      This demo shows a live camera preview, and it plays a sound when a barcode or QR code is found in the viewfinder. The scanned code (a number for EAN codes, URLs or text for QR codes...) is shown in an overlay label. When the view is closed, a list of all (unique) codes that were scanned is printed to the console.

      Here's the code: Barcode Scanner.py (Gist)

      And a screenshot:

      posted in Pythonista
      omz
      omz
    • Pythonista 3.4 is out!

      Title says it all, I've finally managed to get the new version through app review, so the new features (Python 3.10, Shortcuts, pandas...) are now available to everyone.

      Here are the release notes for 3.4.

      posted in Pythonista
      omz
      omz
    • RE: When will OMZ release an Xcode Template for Python3?

      Here's a first attempt at a Python 3-based Xcode template: https://www.dropbox.com/s/5l94m0xjbot5je0/Pythonista3AppTemplate.zip?dl=1

      This is roughly equivalent to the current App Store version (not the 3.3 beta), and not final, just something to play around with for people interested in the Xcode template. Let me know if anything's unclear.

      posted in Pythonista
      omz
      omz
    • RE: Python 3.6

      I'm making progress... There's still a lot left to do, but it's looking good so far.

      posted in Pythonista
      omz
      omz

    Latest posts made by omz

    • RE: Pythonista 3.4 is out!

      @LankyDonkey I have a suspicion that the crashes might have to do with UIKit APIs not being called on the main (UI) thread somewhere in your code (or possibly in Pythonista's own code, I'm not sure). Using UIKit on a secondary thread has always been discouraged by Apple, but it's enforced more strictly when building with the iOS 16 SDK, so this could be why the new version's behavior is different.

      This is just a guess, but you could try decorating your functions/methods that use ObjC APIs with @objc_util.on_main_thread, like this:

      @objc_util.on_main_thread
      def button_tapped(sender):
        # ...
      
      posted in Pythonista
      omz
      omz
    • RE: Help with dialog field

      @ProfessorFlaw Here's a possible solution. The kb_input_alert function below allows you to get a short text input, using the on-screen (PyKeys) keyboard. It doesn't support cursor placement or text selection, so it's only really suitable for short input, but I hope it's still helpful.

      import keyboard
      import ui
      import dialogs
      
      
      class KeyboardTypingView(ui.View):
        def __init__(self, *args, **kwargs):
          self.label = ui.Label(frame=self.bounds, flex='wh')
          self.label.font = ('<System>', 20)
          self.placeholder = ui.Label(frame=self.bounds.inset(0, 8, 0, 8), flex='wh')
          self.placeholder.font = ('<System>', 20)
          self.add_subview(self.label)
          self.add_subview(self.placeholder)
          self.label.text = ''
          self.placeholder.alpha = 0.3
          self.cursor = ui.View(bg_color='#63aaff')
          self.add_subview(self.cursor)
          self.update_cursor()
          self.entered_text = ''
          super().__init__(*args, **kwargs)
      
        def kb_should_insert(self, text):
          if text == '\n':
            # Return pressed
            self.entered_text = self.label.text
            keyboard.set_view(None)
          self.label.text += text
          self.update_cursor()
          return ''
      
        def update_cursor(self):
          self.placeholder.hidden = len(self.label.text) > 0
          self.label.size_to_fit()
          self.cursor.frame = (self.label.frame.max_x, 0, 3, self.bounds.h)
      
        def kb_should_delete(self):
          self.label.text = self.label.text[0:-1]
          self.update_cursor()
          return False
      
      
      def kb_input_alert(title='Enter text'):
        if not keyboard.is_keyboard():
          return dialogs.input_alert(title)
        v = KeyboardTypingView()
        v.placeholder.text = title
        keyboard.set_view(v)
        v.wait_modal()
        return v.entered_text
      
      def main():
        name = kb_input_alert('Enter your name')
        dialogs.hud_alert(f'Hello, {name}!')
      
      
      if __name__ == '__main__':
        main()```
      posted in Pythonista
      omz
      omz
    • RE: Help with dialog field

      @ProfessorFlaw input_alert and similar functions are not available in the custom keyboard because they would require showing the system keyboard, which isn't possible in custom keyboards. I realize that this is unfortunate, but right now, this simply isn't supported.

      posted in Pythonista
      omz
      omz
    • RE: 'No route to host' error in beta 340009 when using multicast

      @ttobias It looks like multicast networking requires an additional entitlement from Apple that I have to apply for, and explain why my app needs this... I think the previous version might still have worked because it was built with an older iOS SDK. I'll look into this, but it might take a little while.

      posted in Pythonista
      omz
      omz
    • RE: Black on Pythonista?

      @upwart Release notes are available in in the documentation, and there's a link from empty tabs.

      posted in Pythonista
      omz
      omz
    • RE: Bug: scene.load_pil_image raises SystemError

      @upwart Thank you, I'll look into it.

      posted in Pythonista
      omz
      omz
    • RE: 3.4: URL schemes not working in built-in browser

      I made a last-minute change to use WKWebView instead of UIWebView for the in-App browser, and it looks like I forgot about some details.

      Here's sort of a workaround, similar to the one @cvp suggested, but opening in a tab, like the built-in one.

      import ui
      import webbrowser
      from urllib.parse import urlparse
      
      class WebDelegate (object):
        def webview_should_start_load(self, webview, url, nav_type):
          if urlparse(url).scheme in  ['http', 'https', 'file']:
            return True
          else:
            webbrowser.open(url)
      
      def open_browser(url):
        v = ui.WebView()
        v.name = 'Web Browser'
        v.delegate = WebDelegate()
        v.load_url(url)
        v.present('panel')
      
      import os
      url = 'file://' + os.path.abspath('test.html')
      open_browser(url)
      
      
      posted in Pythonista
      omz
      omz
    • RE: Pythonista 3.4 is out!

      @ForceBru Thanks for the crash log. Unfortunately, it has become pretty difficult to test on iOS 12, and apparently no one in the beta was still using it, so it slipped through. Sorry about this! I'll look into it.

      posted in Pythonista
      omz
      omz
    • Pythonista 3.4 is out!

      Title says it all, I've finally managed to get the new version through app review, so the new features (Python 3.10, Shortcuts, pandas...) are now available to everyone.

      Here are the release notes for 3.4.

      posted in Pythonista
      omz
      omz
    • RE: I have a dumb editor question.

      @Zoot You can skip the closing bracket by typing it.

      posted in Pythonista
      omz
      omz