我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用sublime_plugin.EventListener()。
def on_selection_modified ( self, view ): # ? ? ?? • • Verify Extension ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??¦••i1?# documentExtension = Commands.get_FileType () if documentExtension != V.documentExtension \ or V.settingsLoaded == False: V.load_DynamicVars () # ? ? ?? • • open_MediaLink ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??¦••i1?# if EventListener.mediaLink_Enabled == True \ and V.mediaLink_OnClick_Enabled == True: Commands.open_MediaLink ( view ) #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #???????? Variables ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????c3# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?#
def view_has_file_only_linter(self, vid): """Return True if any linters for the given view are file-only.""" for lint in persist.view_linters.get(vid, []): if lint.tempfile_suffix == '-': return True return False # sublime_plugin.EventListener event handlers
def updatePos(view): #print 'updatepos' view.settings().set('origPos',view.viewport_position()) def initialize(view): #print 'initialize' if not view.settings().has('syncScroll'): view.settings().set('syncScroll',False) #the add on change should be here, it's elsewhere for debug reasons updatePos(view) view.settings().clear_on_change('syncScroll') #for debug reasons view.settings().add_on_change('syncScroll', updateStatus) #when syncScroll is toggled, update status bar settings = sublime.load_settings('Sync View Scroll.sublime-settings') status_off = settings.get('status_off') if status_off: view.set_status('syncScroll', status_off)def plugin_loaded(): if not 'running_synch_scroll_loop' in globals(): global running_synch_scroll_loop running_synch_scroll_loop = True _thread.start_new_thread(synch_scroll_loop, ()) #on startup initialize every view print ("syncScroll starting") for window in sublime.windows(): for view in window.views(): initialize(view)def synch_scroll_loop(): while True: global synch_scroll_running if not synch_scroll_running: synch_scroll_running = True sublime.set_timeout(lambda: synch_scroll(), 0) time.sleep(0.08)def synch_scroll(): global synch_scroll_running global synch_scroll_current_view_object # print ("one timeout") current_view = synch_scroll_current_view_object if current_view is None or current_view.is_loading() or not current_view.settings().get('syncScroll'): synch_scroll_running = False return callingViewPosX, callingViewPosY = current_view.viewport_position() origCallingViewPosX, origCallingViewPosY = current_view.settings().get('origPos') # print ('modified. origCallingViewPos=', origCallingViewPosX, origCallingViewPosY, 'callingViewPos= ', callingViewPosX, callingViewPosY) if callingViewPosX != origCallingViewPosY or callingViewPosY != origCallingViewPosY: #and it moved vertically or horizontally # print ("it moved") for view in current_view.window().views(): if view.settings().get('syncScroll') and view.id() != current_view.id(): #if view has syncScroll enabled AND we're not talking about the same view as view #we move view viewPosX, viewPosY = view.viewport_position() newViewPosX = viewPosX+callingViewPosX-origCallingViewPosX newViewPosY = viewPosY+callingViewPosY-origCallingViewPosY # print ("moving. viewPos= ",viewPosX,viewPosY," newViewPos= ",newViewPosX,newViewPosY) view.set_viewport_position((newViewPosX,newViewPosY), True) #move the other view updatePos(view) updatePos(current_view) #update original positions synch_scroll_running = False def updateStatus(): # print "updateStatus" settings = sublime.load_settings('Sync View Scroll.sublime-settings') for window in sublime.windows(): for view in window.views(): if view.settings().get('syncScroll'): status_on = settings.get('status_on') if status_on: view.set_status('syncScroll', status_on) else: status_off = settings.get('status_off') if status_off: view.set_status('syncScroll', status_off) else: view.erase_status('syncScroll') class syncScrollListener(sublime_plugin.EventListener): def on_activated(self, view): global synch_scroll_current_view_object synch_scroll_current_view_object = view view.settings().set('origPos', view.viewport_position()) def on_load(self,view): #on load add settings to a view # print ("on_load") initialize(view) def on_text_command(self, current_view, command_name, args): if current_view.settings().get('syncScroll') and command_name == 'move_to' and args['to'] in ['bof', 'eof']: for view in current_view.window().views(): if view.settings().get('syncScroll') and view.id() != current_view.id(): view.run_command(command_name, args) class ToggleSyncScrollCommand(sublime_plugin.TextCommand): def run(self, edit): current_state = self.view.settings().get('syncScroll') self.view.settings().set('syncScroll',not current_state) def is_checked(self): if not self.view.settings().has('syncScroll'): initialize(self.view)
def toggle_MediaLink (): if EventListener.mediaLink_Enabled == True: EventListener.mediaLink_Enabled = False sublime.status_message ( "SlideNav MediaLink: DISABLED" ) elif EventListener.mediaLink_Enabled == False: EventListener.mediaLink_Enabled = True sublime.status_message ( "SlideNav MediaLink: ENABLED" ) #??»»??????????????????????????????????????????««??_____________________________________________________________________________________________________________________________________________¦••?# #??»»???? • • get_MediaLink_Region ????««?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????m2# #??»»??????????????????????????????????????????««???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦••?#
def verify_InvertedRegion ( region ): if region.a > region.b: region = sublime.Region ( region.b, region.a ) return ( region ) #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #???????? EventListener ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????c3# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?#
def on_message(ws, message): print(message) # class FocusWatcher(sublime_plugin.EventListener): # pending_toggle = False # prev_is_on_top = False # already_in_progress = False # def on_deactivated_async(self, view): # if self.already_in_progress: # return # self.already_in_progress = True # focused = False # if isWindows and self.pending_toggle == False: # global windowsWindow # if windowsWindow: # fg = win32gui.GetForegroundWindow() # if windowsWindow == fg: # focused = True # else: # for win in sublime.windows(): # if win.hwnd() == fg: # focused = True # if focused == False: # global isOnTop # self.prev_is_on_top = isOnTop # set_always_on_top(False) # self.pending_toggle = True # print("on deactived, focused:") # print(focused) # self.already_in_progress = False # def on_activated_async(self, view): # if self.already_in_progress: # return # self.already_in_progress = True # print(1) # if isWindows and self.pending_toggle: # print(2) # global windowsWindow # if windowsWindow: # self.pending_toggle = False # print(3) # print(self.prev_is_on_top) # try: # if self.prev_is_on_top: # # win32gui.SetForegroundWindow(windowsWindow) # # time.sleep(0.05) # win32gui.SetFocus(windowsWindow) # set_always_on_top(True) # # time.sleep(0.05) # # win32gui.SetForegroundWindow(view.window().hwnd()) # except Exception as e: # pass # print(4) # self.already_in_progress = False