Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@cclauss cclauss commented Apr 18, 2016

import _editor_pythonista  # this can be found where?
@jsbain

This comment has been minimized.

Copy link
Owner Author

@jsbain 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