Created
April 18, 2016 06:17
-
-
Save jsbain/278667185d8f23ffd1ed2e48a8d46417 to your computer and use it in GitHub Desktop.
column_guide.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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
commented
Apr 18, 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