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():
         self.old_selection.append(region)
   def __exit__(self, type, value, traceback):
      self.view.sel().clear()
      for region in self.old_selection:
         self.view.sel().add(region)

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):
         try:
            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()
            print(self.view)
            self.view.replace(edit, region, stdout)
            # self.view.end_edit(e)
            print(self.view)
         except (OSError, ValueError, subprocess.CalledProcessError, Exception) as e:
            err = '%s: Uncrustify was unable to executed (%s)' % (__name__, traceback.print_exc())
            sublime.error_message(err)
            self.result = False
      # edit.active_view().set_viewport_position((0.0, 1339.0))
      print(self.view)
      self.view.set_viewport_position((0.0, 0.1339))
      self.view.set_viewport_position((x, y))
      print(old_viewport_position)
      print(x)
      print(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.
CanisMajorWuff
 
Posts: 2
Joined: Sun Feb 24, 2013 6:21 pm

Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 34 guests