omz:forum

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

    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 40
    • Topics 82
    • Posts 3915
    • Best 751
    • Controversial 0
    • Groups 0

    JonB

    @JonB

    1026
    Reputation
    26963
    Profile views
    3915
    Posts
    40
    Followers
    0
    Following
    Joined Last Online
    Website github.com/jsbain

    JonB Unfollow Follow

    Best posts made by JonB

    • interactive local notifications

      Someone posted the wishlist the ability to add interactive local notifications.... so this was this evening's distraction.


      The basic idea is that you have to override the app delegate with a custom version. (it should have been possible to add a method to the existing delegate, but this always caused a crash for me). Of course, this only works until ios decides to unload the app from memory, or you actively kill or crash the app, since the delegate is not permanent. As such, it is probably less useful than regular notifications.... omz would need to provide a way to hook delegate calls to python functions (specific file in site-packages, say).

      One note, I had to override the type encoding, because the @? type for a Block caused a TypeError when called... so I replaced this with a regular pointer @ and used ObjCInstance to convert to a Block to .invoke() the completionhandler.

      posted in Pythonista
      JonB
      JonB
    • Visual Debugger for pythonista [share]

      I have been toying with various ideas for a pythonista debugging system for a long time, to replace pdb in the console. With ObjC, we can finally integrate this into the editor itself.
      Here is a working, albeit not yet complete, visual debugger. right now it supports stepping in/over/continue/quit, as well as a Locals/Globals display (read only right now).

      I have separately working an overlay system for setting breakpoints by tapping the line number, though this is not yet fully baked and is not integrated into the main class yet (see inwork folder) I think I want to also go back to my older line highlight method (currently using editor annotations, but the "warning" is not overridable and interferes with the interface a bit)...

      Anyhoo, here's the Readme/install/screenies:

      Visual Debugger(vdb)

      interactive debugger inside pythonista editor

      ##features

      • single stepping, or step over
      • continue, or quit
      • watch window (view only right now)
      • During debugging, current line is highlighted, and editor opens new file if needed

      ##TODO:

      • breakpoint set/clear by tapping line s
      • launch script via menu
      • stack up/down
      • help menu
      • optimizations for small devices

      usage (where debugging is needed)

      	import vdb
      	vdb.VDB().set_trace()
      	
      

      ##install
      Thanks to @ywangd for this method.

      import requests as r; exec r.get('https://raw.githubusercontent.com/jsbain/vdb/master/get_vdb.py').text
      

      screenshots

      watch window
      ui overview

      posted in Pythonista
      JonB
      JonB
    • RE: For those that would like to write code on your iPad, look into Pythonista. It's Amazing!

      Thanks, but does it have a user forum where people can ask and answer questions?

      ...

      posted in Pythonista
      JonB
      JonB
    • ObjC View and Object Browser

      https://github.com/jsbain/viewbrowser.git

      Inspired by the UIDebuggingInformationOverlay, which I couldn't get to run on my 32 bit device, this is an overlay that allows exploration of the UIView heirarchy. Add to wrench menu for easy access. Mainly for exploring pythonista internals, but can also be used for views presented from the ui module.

      Tapping a view highlights the view in red, making it easy to find where you are. Currently hidden views are greyed out. Expanding a view shows its subviews. For buttons, or other views with gesture recognizers, tapping the link button shows the action and target(prints to console for now) -- useful for determining the objc methods to simulate button taps, etc. (@zrzka, you have probably figured out everything you want to simulate for blackmamba, but if not, this might be helpful)
      browser

      The info button opens an objc object browser, which shows all of the properties of the instance. Tapping on a property that is an ObjCInstance opens that object in the object browser, and so on.
      object browser
      The object browser is still somewhat experimental, and sometimes crashes for properties that return a different objc object for each call -- since i currently do not store the actual instance, but instead use the address, so if the object is gc'd, tapping on its rowresults in a segfault. I may change that (though it also seems like it could be a bad idea hanging onto strong references to a bunch of objects)

      posted in Pythonista
      JonB
      JonB
    • git / github workflow in stash

      With the addition (in latest master and dev brsnches) of the new gh command for interfacing with github (create, fork, or issue pull requests), I figure it is time to start writing down some simple git in stash tutorials. This is probably also a good way to expose and work on the remaining bugs in the stash git implementation.

      https://github.com/jsbain/stash_git_tutorial/blob/master/stash_git_tutorial.md

      posted in Pythonista
      JonB
      JonB
    • RE: Writing watermarks to PDF files

      see http://wa5pb.freeshell.org/motd/?p=769 for an example of creating a watermark with reportlab, then applying it using PyPDF ( or PyPDF2 in our case)

      both reportlab and pypdf2 are included with pythonista

      posted in Pythonista
      JonB
      JonB
    • RE: Show Lines Number

      I don't have an iphone to test this on, but you could try this:

      # coding: utf-8
      from objc_util import *
      app=UIApplication.sharedApplication()
      rootVC = app.keyWindow().rootViewController()
      tabVC = rootVC.detailViewController()
      tvc=tabVC.selectedTabViewController()
      ed=tvc.editorView()
      tv=ed.textView()
      tv.showLineNumbers=not tv.showLineNumbers()
      #not sure how to force a redraw.  changing frame size works
      oldframe=tv.frame()
      newframe=oldframe
      newframe.size.width-=1
      tv.frame=newframe
      import time
      time.sleep(0.1)
      tv.frame=oldframe
      

      maybe use in an action script, and it should toggle line numbers in the current tab. Not sure if the view heirarchy is the same on iphone, so maybe this won't work.

      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista: Run Script with Command-Line Parameters?

      press and hold the play button, it will pop up a dialog asking for arguments.

      posted in Pythonista
      JonB
      JonB
    • RE: Access Pythonista Settings from Script
      from objc_util import *
      >>> defaults=ObjCClass('NSUserDefaults').standardUserDefaults()
      >>> defaultsDict=defaults.dictionaryRepresentation()
      >>> defaultsDict['UseSoftTabs']
      <b'__NSCFBoolean': 1>
      >>> defaultsDict['IndentationWidth']
      <b'__NSCFNumber': 3>
      

      type defaultsDict at the console to see all of the pythonista settings that you can check this way.

      posted in Pythonista
      JonB
      JonB
    • RE: How many days left until Python 2 end of life?

      @Ti-Leyon Actually, any devices still running python2.7 will instantly explode, into flames, possibly ending your life. The PSF does NOT mess around.

      posted in Pythonista
      JonB
      JonB

    Latest posts made by JonB

    • RE: Shortcut error: Could not run Run Pythonista Script

      @yaroslav_ya_ya have you tried running this from pythonista? How long does it take to return?

      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      @ihf there is a way to tell selfupdate which fork to install from.

      You could try

      selfupdate mkb79:patch-Pythonista3.4
      
      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      @JonB I will say, it's going to take a while to find and fix all of the problems with stash and 3.4

      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      @ihf there is another GitHub PR about fixing wget and others. I believe another fork has those fixes, it should be possible now to use selfupdate.

      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      @ihf I’m not sure if @bennr has committed the PR, which would allow you to delete stash then install it fresh.

      Maybe I will write a patch script next week.

      In short, you can do it manually, using this as your guide

      https://github.com/ywangd/stash/commit/cb9616605c30c230ec323a668b961d52c904b9cc

      First, you hav to change lines 20-21 in stash/system/shcommon.py, so that it uses plistlib.load instead of readPlist. See the patch in the PR.

      Next, in system/shui/pythonista _ui.py, you search and replace SUITextBox with SUITextbox_PY3. The PR used UITextBox, but the underscore PY3 should work better.

      Also, find isAlive and replace with is_alive in that same file.

      Finally, do the same isAlive replacement in shthreads.py.

      For me, I also had to make the following change in launch_stash.py, instead of _stash.launch():

      import ui
      
      @ui.in_background
      def launch_stash():
      	_stash.launch()
      
      launch_stash()
      
      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      Try this

      import shutil
      shutil.mv(‘/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas’, /private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandasfailed’)
      
      That should rename the pandas folder, then force quit and try again.
      posted in Pythonista
      JonB
      JonB
    • RE: Is it possible to change the Console font size?

      @OI you can store in Documents, just make sure you name it something unique. .you could also put in site-packages, which can be found in the main folder picker under Modules->site-packages

      posted in Pythonista
      JonB
      JonB
    • RE: Pythonista 3 3.4 (340006) beta: Import pandas throws error

      @ihf yes... You have to manually make some changes to stash to get it to run. There are details in a PR on the GitHub page. Or if you have working copy, maybe you can update that way.

      You could look at modules->site-packages>stash>bin>rm to look at the code being use to run rm -rf, then manually do that at the console. Actually it would be sufficient to rename the pandas folder to something else.

      posted in Pythonista
      JonB
      JonB
    • RE: What what what!! New version in TestFlight!!!

      @cvp I think this was always the rule, which we were allowed to violate for some reason in the past. IIRC, the compiler has certain strictness flags that you can enable to find bugs when doing things in an unsafe way. Presumably the TF version is just being more strict.

      posted in Pythonista
      JonB
      JonB
    • RE: What what what!! New version in TestFlight!!!

      @gurtler_marcel there is a PR request to fix the stash issues -- it is really a few line fix, so you may also be able to just do it manually. I was also getting a hard crash when launching stash, which I solved by wrapping the stash._launch(ns.command) into a function called on ui.in_background, since it seemed like a race condition between the stash ui getting displayed and the editor window moving over...

      posted in Pythonista
      JonB
      JonB