Sublime Forum

Updating the quick panel

#1

I’m trying to learn how to update the quick panel. Here’s a simple example:

class PanelTestCommand(sublimeplugin.WindowCommand):
	def run(self, window, args):
		args = "wait 5 seconds..."]
		window.showQuickPanel("", "", args)
		print "Wait"
		import time
		time.sleep(5)
		args.append("Done!")
		print "Done"
		window.showQuickPanel("update", "", args)

I’m not sure how the first parameter, called “key” in the docs, actually does. My understanding is that if it’s not blank, the panel gets updated, but I’m not sure.

Anyway, the problem is that it looks like both output to the output panel and updates to the quick panel are buffered. The net result is that, when I invoke the above code using

window.runCommand("panelTest")

nothing happens for 5 seconds, and then (1) the two lines of text are shown in the output panel, and (2) the quick panel pops up, again showing both lines of text.

I’m probably doing something really silly, but I’m running out of ideas. Anyone? Thanks! M

0 Likes

#2

If you’re specifying a key, you’ll need to specify the same key both when initially showing the quick panel and when updating it. The basic logic is that when calling the showQuickPanel function, if the key matches the key of the existing quick panel, then it’s updated rather than reset (i.e., the selected item and entered text is preserved).

To delay processing in an plugin, rather than calling sleep(), which blocks the editor, use sublime.setTimeout().

0 Likes

#3

OK, thanks for clarifying the use of the “key” parameter.

Regarding the “sleep” function, that was just an example. What I really want to do is show some text in the quick panel (“Compiling…”), launch a command-line tool via subprocess.Popen, and then show the result of compilation in the same quick panel. That, too, seems to be blocking: the quick panel comes up only when compilation ends, which is not what I want. Thanks! M

0 Likes

#4

Ah! Thanks a lot. I’ll try to figure it out. I did notice the generator tricks in AAA*, but did not ponder the issue long enough to understand how it works. Too bad the week-end is over here in Chicago :frowning:

0 Likes

#5

Hi, and thanks again,

any further info (even half-baked html!) would be very welcome :smile: If you don’t feel like posting it, you could email it to me at msiniscalchi shift-2 gmail dot com. Thanks!

Best—M

0 Likes

#6

It sounds like you should be creating a thread to launch the command line tool, and block on receiving the output there. When you’ve got the results, send them back to the main thread via setTimeout (setTimeout is the only API function safe to call from another thread).

0 Likes

#7

I updated the LaTeX plugin following jps’s advice—thanks! For the possible benefit of other plugin authors, I documented my learning experience on my blog:

tekonomist.wordpress.com/2010/06 … nd-profit/

I’m pretty sure I got a few things wrong; if so, please let me know. Thanks!

0 Likes