Home Download Buy Blog Forum Support

Rid of viewport blinking

Rid of viewport blinking

Postby CanisMajorWuff on Sun Feb 24, 2013 6:28 pm

I am writing a plugin for C++ formatting by Uncrustify, that is what I written:
Code: Select all
import sublime, sublime_plugin, subprocess, traceback

class FirmSelection():
   def __init__(self, view):
      self.view = view
   def __enter__(self):
      self.old_selection = []
      for region in self.view.sel():
   def __exit__(self, type, value, traceback):
      for region in self.old_selection:

class UncrustifyCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      old_viewport_position = self.view.viewport_position()
      x = old_viewport_position[0]
      y = old_viewport_position[1]
      with FirmSelection(self.view):
            region = sublime.Region(0, self.view.size())
            content = self.view.substr(region)
            command = ["uncrustify", "-q", "-l", "CPP", "-c", "D:/uncrustify/default.cfg"]
            popopenObject = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            stdout = popopenObject.communicate(input=content)[0]
            returnCode = popopenObject.poll()
            if (returnCode != 0):
               stderr = popopenObject.communicate()[1]
               raise Exception(("Non-zero return code (%d): " + stderr) % returnCode)
            # e = self.view.begin_edit()
            self.view.replace(edit, region, stdout)
            # self.view.end_edit(e)
         except (OSError, ValueError, subprocess.CalledProcessError, Exception) as e:
            err = '%s: Uncrustify was unable to executed (%s)' % (__name__, traceback.print_exc())
            self.result = False
      # edit.active_view().set_viewport_position((0.0, 1339.0))
      self.view.set_viewport_position((0.0, 0.1339))
      self.view.set_viewport_position((x, y))

How u can see I need a weird thing with set_viewport_position, only in this way it brings me the position of viewport in a right place, more details about this problem u can see here (http://stackoverflow.com/questions/1505 ... 5_15053679).
Ok, now it works somehow. But it is obvious that there are unpleasant blinkings of viewport because of moving. Can somebody explain me how to fix all this mess with viewport.
Posts: 2
Joined: Sun Feb 24, 2013 6:21 pm

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 17 guests