Skip to content

Instantly share code, notes, and snippets.

@jsbain
Created April 18, 2016 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbain/278667185d8f23ffd1ed2e48a8d46417 to your computer and use it in GitHub Desktop.
Save jsbain/278667185d8f23ffd1ed2e48a8d46417 to your computer and use it in GitHub Desktop.
column_guide.py
#!python2
import editor, ui
import _editor_pythonista
from objc_util import *
@on_main_thread
def create_column_guide(num_cols=80):
''' create vertical line at column index specified.
TODO: register for file change notifications, add to all tabs, etc. add ability to remove.
'''
ev = _editor_pythonista._get_editor_tab().editorView()
tv=ev.textView()
ts=tv.textStorage()
font=ts.paragraphs()[0].text().fontAttributesInRange_(NSRange(0,0))['NSFont']
font_char_width=font.advancementForGlyph_(99).width
# create a 1 pixel "line" view
v=ui.View(
frame=(font_char_width*num_cols+tv.gutterWidth(),
0,1,ev.frame().size.height),
flex='LH')
v.border_width=1
v.alpha=0.1
ev.addSubview_(ObjCInstance(v))
return v
create_column_guide(80)
@cclauss
Copy link

cclauss commented Apr 18, 2016

import _editor_pythonista  # this can be found where?

@jsbain
Copy link
Author

jsbain commented Apr 19, 2016

Out[32] = '/var/mobile/Containers/Bundle/Application/0745BFF1-B807-4C17-BDD5-27C4E8EAD739/Pythonista3.app/Frameworks/PythonistaKit.framework/pylib/site-packages/_editor_pythonista.py'

the default site packages for the py2 interpreter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment