- Code: Select all
webbrowser.open("file://" + output.name)
to open an html file.
However, after opening the file in a web browser, the focus is shifted to the web browser.
Any idea on how to switch the focus back to Sublime Text?
webbrowser.open("file://" + output.name)import ctypes
ctypes.windll.user32.SetForegroundWindow(self.window.hwnd())erinata wrote:I've tried exactly the same thing but it didn't work.
I also try to import win32com ........and it says that there is no module named win32com
I don't mind if it only works on windows.....if there is a way to do it.
MS Documentation for SetForegroundWindow reads as follows:
"Windows NT 5.0 and later: An application cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow) and call the FlashWindowEx function to notify the user."
import sublime, sublime_plugin
import ctypes, time
class ExampleCommand(sublime_plugin.WindowCommand):
def run(self):
time.sleep(5)
# ctypes.windll.user32.BringWindowToTop(self.window.hwnd())
ctypes.windll.user32.SwitchToThisWindow(self.window.hwnd(), 0)
# ctypes.windll.user32.SetForegroundWindow(self.window.hwnd())
# ctypes.windll.user32.SetActiveWindow(self.window.hwnd())
# ctypes.windll.user32.SetFocus(self.window.hwnd())
# ctypes.windll.user32.ShowWindow(self.window.hwnd(), 5)"Windows NT 5.0 and later: An application cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow) and call the FlashWindowEx function to notify the user."
import sublime, webbrowser
from functools import partial
from ctypes import windll
def do():
"""
>>> from tester import do
>>> do()
"""
webbrowser.open("http://www.google.com.au")
sublime.set_timeout (partial( windll.user32.SetForegroundWindow,
sublime.active_window().hwnd()), 500 )
sublime.set_timeout(partial(ctypes.windll.user32.SwitchToThisWindow,
sublime.active_window().hwnd(), 0), 500)It don't work for me with SetForegroundWindow.
[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]
Users browsing this forum: inkytonik and 1 guest