Home Download Buy Blog Forum Support

(ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

(ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby facelessuser on Sat Jan 04, 2014 6:37 pm

I know this gets asks occasionally: "How do I import win32api?". Well you can't...at least not out of the box. This is where Pywin32 comes in. I recently started throwing together a plugin that needed pywin32 so I could show Windows notification bubbles from sublime:

Image

So I threw this together.

example to show path of all open explorer windows:
import sublime_plugin
import Pywin32.setup
from win32com.client.gencache import EnsureDispatch


def run():
for w in EnsureDispatch("Shell.Application").Windows():
print(w.LocationName + "=" + w.LocationURL)

run()


Output:
Code: Select all
User=file:///C:/Users/facelessuser/AppData/Roaming/Sublime%20Text%203/Packages/User
A Test Plugin=file:///C:/Users/facelessuser/AppData/Roaming/Sublime%20Text%203/Packages/A%20Test%20Plugin
Downloads=file:///C:/Users/facelessuser/Downloads


Notice, you just need to call import Pywin32.setup once before your plugin accesses any win32api, win32com, etc. calls. Technically it only needs to be called once when Sublime starts, but there is no guarantee your plugin will start after Pywin32 gets loaded. That is why your plugin just needs to make sure by manually including it.

  • This is only for ST3
  • Not everything may work. I have only tested what I needed to use.

Good luck! And I am not responsible if something breaks :D.

repo: https://github.com/facelessuser/Pywin32
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: (ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby KonTrax on Sun Jan 05, 2014 11:41 am

Interesting. Another step closer to finally being able to utilize Sublime Text as a cross-platform shell replacement / portable environment platform. At least reducing the alt+tab frequency while working. :)
KonTrax
 
Posts: 46
Joined: Sun Mar 17, 2013 10:24 am

Re: (ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby facelessuser on Sun Jan 05, 2014 4:15 pm

I am interesting to see what people may do with this. This does open up a number of possibilities on Windows.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: (ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby Binocular222 on Wed Jan 08, 2014 5:17 pm

I need to get plain text from clipboard (sublime.get_clipboard() not work with copied file object viewtopic.php?f=6&t=15068),
but sth like this doesn't work:
OpenClipboard()
d=GetClipboardData(win32con.CF_TEXT) # get clipboard data
SetClipboardData(win32con.CF_TEXT, "Hello") # set clipboard data
CloseClipboard()
Binocular222
 
Posts: 55
Joined: Sat May 18, 2013 4:10 pm

Re: (ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby facelessuser on Wed Jan 08, 2014 5:37 pm

Why try to extract the file path from a file object in clipboard? Why not just hold shift in explorer, right click the file, and select "Copy as path"?

If this is unacceptable, I would try and read through the pywin32 documentation. I frankly don't have the time to be a consultant for pywin32, I simply provide the package to help people out. I'm sorry I cannot be of more help right now.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: (ST3) Pywin32 Plugin Beta: pywin32 support in Sublime

Postby FichteFoll on Thu Feb 13, 2014 2:16 am

subscribing~
FichteFoll
 
Posts: 407
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 9 guests

cron