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: 1740
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: 1740
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: 76
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: 1740
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: 734
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

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

Postby facelessuser on Fri Jul 10, 2015 7:15 pm

Thinking about dropping support for this. I only have one plugin that uses it, and I am in the process of moving to using ctypes instead. There looks to be maybe around 400 installs on Package Control, not sure how many actively even use this.

As I can do most things with ctypes directly, which saves me this extra dependency, I have no personal use for it anymore; therefore, I have no desire to continue supporting it. My support for packages is usually tied to my personal usage. If anyone wants to take over, let me know. I think once I finish getting my plugin weened off this, I will give it a month to see if anyone wants to take it over, if not, I may transfer it over to SublimeText organization or just kill it off completely.

To be honest, if someone where taking this over, it would make more sense to implement it as a package control dependency than its current usage model; maybe I will kill it off and let someone re-implement it as a dependency if there is a strong enough desire for it.
facelessuser
 
Posts: 1740
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby FichteFoll on Sat Jul 11, 2015 12:23 pm

I can easily translate the package into a dependency since I spent quite a bit of time with Pc's internals in that regard and know how it works. I don't think I would be able to provide support however (never used itit so far) , so moving it to the sublime text org is probably better.
FichteFoll
 
Posts: 734
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

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

Postby facelessuser on Sat Jul 11, 2015 2:51 pm

FichteFoll wrote:I can easily translate the package into a dependency since I spent quite a bit of time with Pc's internals in that regard and know how it works. I don't think I would be able to provide support however (never used itit so far) , so moving it to the sublime text org is probably better.


That would be great. I figure the people who can't figure out how to get things working with ctypes and want to use PyWin32 can just contribute to the Sublime Text org if they run into troubles with it. That way the people who are actually using it can make things better. As I have spent more time with ctypes, it's really not that hard to use instead of PyWin32, though you are working with less of an abstraction layer making you do a little more reading. So yeah, PyWin32 can be more accessible at times, but not having the extra dependency is nice as well.

On a side note, I have been looking into dependencies, for Package Control. How do you setup Package Control to test out dependencies locally? I wouldn't mind setting up PyWin32 myself, but I'm just not sure yet how you validate it locally.
facelessuser
 
Posts: 1740
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby FichteFoll on Sat Jul 11, 2015 3:20 pm

facelessuser wrote:On a side note, I have been looking into dependencies, for Package Control. How do you setup Package Control to test out dependencies locally? I wouldn't mind setting up PyWin32 myself, but I'm just not sure yet how you validate it locally.


I don't think it's m.tiond anywhere, but you can add channel or repository JSON files to PC's config that are on your hard drive. I used that to test much of the dependency installation stuff and quicks that existed in 3.0.0 and have been fixed in 3.0.1. Unfortunately, I couldn't seem to get PC to install packages from the hard drive, so I had to upload the test package to a web server.

Following is an excerpt of my local .json file that I added to PC's "repositories" setting:
Code: Select all
{
    "schema_version": "3.0.0",

    "packages": [
        {
            "name": "RequestsTest",
            "author": "me",
            "releases": [
                {
                    "sublime_text": "*",
                    "url": "<url to the .sublime-package file I uploaded on some server>",
                    "version": "1.0.0",
                    "date": "2015-01-10 22:38:02"
                }
            ]
        }
    ],

    "dependencies": [
        {
            "name": "requests",
            "load_order": "50",
            "description": "Python requests module",
            "author": "FichteFoll",
            "issues": "https://github.com/packagecontrol/requests/issues",
            "releases": [
                {
                    "base": "https://github.com/packagecontrol/requests",
                    "tags": true,
                    "sublime_text": "*"
                }
            ]
        }
    ]
}


Note: "m.tioned" was required to trick the utterly stupid and annoying "kit*n spam filter". I get so mad whenever I see it.

And yes, I did delete remote tags a couple times.
FichteFoll
 
Posts: 734
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 11 guests