A
A
Alexey Yarkov2016-10-24 15:53:27
Python
Alexey Yarkov, 2016-10-24 15:53:27

Why does Sublime Text 3 crash when calling sublime.message_dialog?

I master writing plug-ins for ST3. I took a ready-made example and try to display a MessageBox when selecting a symbol. Here is the code:

import os
import sublime
import sublime_plugin


class UnicodeCharacterInsertCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        content = self.get_popup_content()
        self.view.show_popup(content, flags=sublime.HTML, location=-1, max_width=400, on_navigate=self.on_choice_symbol)

    def get_characters_html(self):
        resources = sublime.find_resources('unicode-characters.html')
        content = sublime.load_resource(resources[0])
        return content

    def on_choice_symbol(self, symbol):
        self.view.run_command("insert", {"characters": symbol})
        self.view.hide_popup()
        sublime.message_dialog("message_dialog check: %s" % symbol) # вот тут саблайм падает

    def get_popup_content(self):
        tpl_path = os.path.dirname(os.path.realpath(__file__)) + '/unicode-characters.html'
        content = open(tpl_path, 'r').read()
        return content

The window is displayed, but when you click on the OK button or try to close it by clicking on the cross, the sublime silently falls. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-10-24
@yarkov

Found the answer by clicking. It was necessary to show the window in the asynchronous call of the set_timeout_async method :

sublime.set_timeout_async(lambda: sublime.message_dialog("message_dialog check: %s" % symbol), 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question