python – 在sublime 3 api中将文本插入视图
发布时间:2020-12-20 13:50:03 所属栏目:Python 来源:网络整理
导读:我现在在我的崇高中有4个视图.我想在一个视图中插入一些文本.我这样想.但没有运气. getAllViews = self.window.views()jobView = getAllViews[1]jobEdit = jobView.begin_edit()jobView.insert(jobEdit,'Hello')jobView.end_edit(jobEdit) 有没有更好的想法
我现在在我的崇高中有4个视图.我想在一个视图中插入一些文本.我这样想.但没有运气.
getAllViews = self.window.views() jobView = getAllViews[1] jobEdit = jobView.begin_edit() jobView.insert(jobEdit,'Hello') jobView.end_edit(jobEdit) 有没有更好的想法呢? 更新我的问题 我正在编辑我当前的视图布局到4窗格布局,我想将一些差异数据放到我新创建的布局中.我现在有这个代码. import sublime import sublime_plugin import os,subprocess class SpliterCommand(sublime_plugin.TextCommand): def on_done(self,Regex): self.window.set_layout({ "cols": [0,0.5,1],"rows": [0.0,0.33,0.66,1.0],"cells": [ [0,1,3],[1,2,2],3]] }) def run(self,edit): self.editview = edit self.window = sublime.active_window() self.window.show_input_panel('User Input',"Hello",self.on_done,None,None) getAllViews = self.window.layouts() 这将以4种布局分割ui.但无法将数据设置为新布局. 解决方法
问题是,当您创建一个新组时,该组为空(不包含视图),因此如果没有视图,则无法插入文本.您需要在每个空组中创建一个新视图以在其中插入字符.我已经更新了你的on_done方法,以便在每个空组中创建一个视图,并在新视图中插入一些文本.这在代码注释中解释.
def on_done(self,Regex): self.window.set_layout({ "cols": [0,3]] }) # For each of the new groups call putHello (self.window.num_groups() = 4) for numGroup in range(self.window.num_groups()): # If the group is empty (has no views) then we create a new file (view) and insert the text hello if len(self.window.views_in_group(numGroup)) == 0: self.window.focus_group(numGroup) # Focus in group createdView = self.window.new_file() # New view in group createdView.run_command("insert",{"characters": "Hello"}) # Insert in created view 之前: 后: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |