Sublime Forum

When my plugin is running can i show some message or loader in the console panel

#1

i am working on file upload plugin…for now when the file is uploaded i am showing a dialogue box thatshows file is uploaded…but user needs to press ok every time…is there a method which shows custom text on the bottom panel(beside the monitor symbol where line number is shown)…i observe that package control can show a loader while installing a package… then i can also show it… but how?

0 Likes

#2

The bottom panel is called status bar. So, you can use sublime.status_message('my message'), or view.set_status('my_plugin', 'my_message')

And what package control does is simply log plenty of status message. Because they erase the previous, you can do some cool stuff. Wait a sec, I’ll give you an example…

0 Likes

#3

yes its working thank u…but how to make it look like a loader?and also continue with my upload simultaneously?do i need to use threads?

0 Likes

#4

Sorry… Yep, you have to use threads (if you didn’t you’d freeze sublime text, so you loader wouldn’t be able to move…)

Here’s what I’ve done for fun:

# -*- encoding: utf-8 -*-

import sublime
import threading

class _Loader(threading.Thread):

    def __init__(self, loading_message, final_message):
        super().__init__()
        self.pos = 0
        self.length = 7
        self.loading_message = loading_message
        self.final_message = final_message
        self.going = 1

    def _go(self):
        if self.going == 0:
            return sublime.status_message(self.final_message)

        msg = '[{}={}] {}'.format(' ' * self.pos, ' ' * (self.length - self.pos), self.loading_message)

        self.pos += self.going
        if self.pos >= self.length:
            self.going = -1
        if self.pos <= 0:
            self.going = 1
        sublime.status_message(msg)
        sublime.set_timeout(self._go, 100)

    def run(self):
        sublime.set_timeout(self._go, 0)

class Loader:

    def go(self, loading_message, final_message):
        self.loader = _Loader(loading_message, final_message)
        self.loader.start()

    def stop(self):
        self.loader.going = 0
        self.loader.join()

loader = Loader()
loader.go('Looking good...', 'Done!')
sublime.set_timeout_async(lambda: loader.stop(), 5000)

But, the package control’s solution seems much better.

1 Like

#5

What about logging to console, or to a panel, rather than to the status-bar? Can’t find references for that :confused:

0 Likes

#6

I answer myself: print() :sweat_smile:

0 Likes