当前位置: 首页>>代码示例>>Python>>正文


Python editor.get_path方法代码示例

本文整理汇总了Python中editor.get_path方法的典型用法代码示例。如果您正苦于以下问题:Python editor.get_path方法的具体用法?Python editor.get_path怎么用?Python editor.get_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在editor的用法示例。


在下文中一共展示了editor.get_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main(mock):
    import libfuturize.main

    path = editor.get_path()
    if not path or not path.endswith('.py'):
        console.hud_alert('Not a Python file', 'error')
        return

    tab.save()
    args = ['-1', '-n', '-w', '--all-imports', '--add-suffix', _SUFFIX, path]

    result = libfuturize.main.main(args)
    if result == 0 and _replace_file_content(path):
        console.hud_alert('Futurized')
    else:
        console.hud_alert('Failed to futurize', 'error') 
开发者ID:zrzka,项目名称:blackmamba,代码行数:18,代码来源:futurize.py

示例2: apply_change_set

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def apply_change_set(change_set, path=None, initial_selection=None):
    #
    # Why not project.do(change_set)?
    #
    #  - iCloud, Files, ... - there're special functions to update files, not a simple file system
    #  - we have to be sure just one file (= opened) is updated only, because of Pythonista reloading, ...
    #
    for change in change_set.changes:
        if path and not change.resource.real_path == path:
            # Make sure we modify opened file only
            continue

        if path and not path == editor.get_path():
            # Make sure that user didn't switch tab, close tab, ...
            continue

        end = len(editor.get_text()) - 1
        editor.replace_text(0, end, change.new_contents)
        if initial_selection:
            editor.set_selection(*initial_selection, scroll=True) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:22,代码来源:refactoring.py

示例3: did_load

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def did_load(self):
        sv=self['scrollview1']
        self.sv=sv
        self.add_button = sv['add_button']
        self.add_button.action=self.add_file
        self.remove = sv['remove']
        self.edit = sv['edit']
        self.edit.action=edit_menu
        
        d=shelve.open(os.path.expanduser('~/Documents/.tabs'),writeback=True )
    
        current_path = editor.get_path()
    
        for tab in d.itervalues():
            self.add_new_button(tab['name'])
        self.d=d
        self.present('sidebar')
        self.check_tab()
        type(self)._lastinstance=self 
开发者ID:khilnani,项目名称:pythonista-scripts,代码行数:21,代码来源:Tabs.py

示例4: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main(args):
    try:
        # Source and destination are passed via runtime args
        src, dest = args
    except (TypeError, ValueError):
        # Get source and destination from user
        curfile = os.path.relpath(editor.get_path() or "", DOCUMENTS)
        
        shortsrc = console.input_alert(
            "Source Name", # title
            "Path is relative to Script Library root", # message
            curfile, # input
        )
        src = os.path.join(DOCUMENTS, shortsrc)
        
        if not os.path.exists(src):
            console.hud_alert("Source file does not exist", "error")
            sys.exit(1)
        
        dest = os.path.join(DOCUMENTS, console.input_alert(
            "Destination Name", # title
            "Path is relative to Script Library root", # message
            shortsrc, # input
        ))
    else:
        # Process source and destination from runtime args
        src, dest = os.path.join(DOCUMENTS, src), os.path.join(DOCUMENTS, dest)
        
        if not os.path.exists(src):
            console.hud_alert("Source file does not exist", "error")
            sys.exit(1)
    
    if os.path.exists(dest):
        console.hud_alert("Destination file already exists", "error")
        sys.exit(1)
    
    os.rename(src, dest)
    
    sys.exit(0) 
开发者ID:dgelessus,项目名称:pythonista-scripts,代码行数:41,代码来源:rename.py

示例5: current_path

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def current_path():
    # path to file currently open in editor
    return "/private" + editor.get_path() 
开发者ID:dgelessus,项目名称:pythonista-scripts,代码行数:5,代码来源:wannabetabs.py

示例6: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    if not get_config_value('general.jedi', False):
        log.warn('jump_to_definition disabled, you can enable it by setting general.jedi to True')
        return

    path = editor.get_path()
    if path is None:
        return

    if not path.endswith('.py'):
        return

    tab.save()

    text = editor.get_text()
    if not text:
        return

    line = source.get_line_number()
    column = source.get_column_index()

    if line is None or column is None:
        return

    script = jedi.api.Script(text, line, column, path)
    definitions = [
        d for d in script.goto_definitions()
        if d.module_path and d.line
    ]

    if not definitions:
        console.hud_alert('Definition not found', 'error')
        return

    if len(definitions) == 1:
        tab.open_file(definitions[0].module_path, line=definitions[0].line)
    else:
        _select_location(definitions) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:40,代码来源:jump_to_definition.py

示例7: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    path = editor.get_path()

    if not path:
        return

    if not path.endswith('.py'):
        return

    save(all=True)
    _run_unit_tests(path) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:13,代码来源:run_unit_tests.py

示例8: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    path = editor.get_path()

    if not path:
        return

    if not path.endswith('.py'):
        return

    editor.clear_annotations()

    flake8_options = get_config_value('analyzer.flake8', None)

    selection = editor.get_selection()
    text = _editor_text()

    if flake8_options:
        annotations = _flake8_annotations(
            os.path.abspath(path),
            flake8_options
        )
    else:
        annotations = _pep8_annotations(
            text,
            ignore=_ignore_codes(),
            max_line_length=_max_line_length()
        )

        annotations += _pyflakes_annotations(path, text)

    if not annotations:
        if selection:
            editor.set_selection(selection[0], scroll=True)
        console.hud_alert('No Issues Found', 'iob:checkmark_32', _hud_alert_delay())
        return None

    scroll = True
    by_line = sorted(annotations, key=lambda x: x.line)
    for l, a in groupby(by_line, lambda x: x.line):
        _annotate(l, a, scroll)
        scroll = False 
开发者ID:zrzka,项目名称:blackmamba,代码行数:43,代码来源:analyze.py

示例9: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    if not get_config_value('general.jedi', False):
        log.warn('show_documentation disabled, you can enable it by setting general.jedi to True')
        return

    path = editor.get_path()
    if path is None:
        return

    if not path.endswith('.py'):
        return

    tab.save()

    text = editor.get_text()
    if not text:
        return

    line = source.get_line_number()
    column = source.get_column_index()

    if line is None or column is None:
        return

    script = jedi.api.Script(text, line, column, path)
    definitions = [
        d for d in script.goto_definitions()
        if d.module_path and d.line and d.docstring()
    ]

    if not definitions:
        console.hud_alert('Documentation not found', 'error')
        return

    if len(definitions) == 1:
        _show_documentation(definitions[0])
    else:
        _select_location(definitions) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:40,代码来源:show_documentation.py

示例10: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    if not get_config_value('general.jedi', False):
        log.warn('find_usages disabled, you can enable it by setting general.jedi to True')
        return

    path = editor.get_path()
    if path is None:
        return

    if not path.endswith('.py'):
        return

    tab.save()

    text = editor.get_text()
    if not text:
        return

    line = source.get_line_number()
    column = source.get_column_index()

    if line is None or column is None:
        return

    script = jedi.api.Script(text, line, column, path)
    definitions = [
        d for d in script.usages()
        if d.module_path and d.line
    ]

    if not definitions:
        console.hud_alert('Definition not found', 'error')
        return

    _select_location(definitions) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:37,代码来源:find_usages.py

示例11: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
    filename = editor.get_path()
    if not filename:
        return

    if not filename.endswith('.py'):
        return

    text = editor.get_text()
    if not text:
        return

    def scroll_to_node(node, shift_enter):
        source.scroll_to_line(node.line)

    v = PickerView()
    v.name = 'Outline'
    v.datasource = OutlineDataSource(text, os.path.basename(filename))
    v.shift_enter_enabled = False
    v.help_label.text = (
        '⇅ - select • Enter - scroll to location'
        '\n'
        'Esc - close • Cmd . - close with Apple smart keyboard'
    )
    v.textfield.placeholder = 'Start typing to filter nodes...'
    v.did_select_item_action = scroll_to_node
    v.present('sheet')
    v.wait_modal() 
开发者ID:zrzka,项目名称:blackmamba,代码行数:30,代码来源:outline_quickly.py

示例12: run_script

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def run_script(sender):
		'''run a script without clearing glbals'''
		import editor
		editor.reload_files()
		execfile(editor.get_path(),globals())

	#create_toolbar_button(run_script,'iow:play_32',0,'execfile')
	
	#remove_toolbar_button(0) 
开发者ID:khilnani,项目名称:pythonista-scripts,代码行数:11,代码来源:apphack.py

示例13: check_tab

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def check_tab(self):
        open_path = editor.get_path()
        for tab in self.sv.subviews:
            try:
                if self.d[tab.name]['path'] != open_path:
                    tab.background_color = 'white'
                else:
                    tab.background_color = 'orange'
            except KeyError:
                pass 
开发者ID:khilnani,项目名称:pythonista-scripts,代码行数:12,代码来源:Tabs.py

示例14: add_file

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def add_file(self,sender):
        d=self.d
        current_path = str(editor.get_path())
        name = os.path.split(current_path)[1]
        for item in self.d.itervalues():
            if current_path==item['path']:
                console.hud_alert('There is already a tab for this file', duration = 1)
                return None
        if self.d.has_key(name): #has name, but diff path, still create the tab, but append !#
            suffix_list=[(k+'!').split('!')[1] or '0' for k in self.d.keys() if k.startswith(name) ]
            new_suffix='!'+max([int(m) for m in suffix_list])+1
            name=name+new_suffix
        d[name]={'name':name,'path':current_path,'selection':editor.get_selection()}
        self.add_new_button(name, new = True) 
开发者ID:khilnani,项目名称:pythonista-scripts,代码行数:16,代码来源:Tabs.py

示例15: main

# 需要导入模块: import editor [as 别名]
# 或者: from editor import get_path [as 别名]
def main():
	filename = editor.get_path()
	if not filename:
		dialogs.hud_alert('No file selected', 'error')
		return
	pyui_filename = os.path.splitext(filename)[0] + '.pyui'
	if not os.path.exists(pyui_filename):
		folder = os.path.split(filename)[0]
		files = os.listdir(folder)
		files = [f for f in files if f.endswith('.pyui')]
		if not files:
			dialogs.hud_alert('No pyui files found', 'error')
			return
		selected_pyui = dialogs.list_dialog('Select pyui file', files)
		if not selected_pyui:
			return
		pyui_filename = os.path.join(folder, selected_pyui)
	with open(pyui_filename, 'rb') as f:
		pyui = f.read()
	compressed = base64.b64encode(bz2.compress(pyui)).decode('utf-8')
	wrapped = '\n'.join(textwrap.wrap(compressed, 70))
	code = """\
data = '''\\\n%s
'''
import ui
import bz2
from base64 import b64decode
pyui = bz2.decompress(b64decode(data))
v = ui.load_view_str(pyui.decode('utf-8'))
""" % (wrapped,)
	clipboard.set(code)
	dialogs.hud_alert('Code copied', 'success') 
开发者ID:khilnani,项目名称:pythonista-scripts,代码行数:34,代码来源:EmbedPyui.py


注:本文中的editor.get_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。