Skip to content

Commit 0366aad

Browse files
committed
Improved for ST3 and fixed menu issues
1 parent 4facb79 commit 0366aad

File tree

8 files changed

+151
-71
lines changed

8 files changed

+151
-71
lines changed

Main.sublime-menu

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,12 @@
4949
"command": "sub_trans_about"
5050
},
5151
{
52-
"command": "open_file",
53-
"args": {
54-
"file": "${packages}/SublimeTextTrans/README.md",
55-
"platform": "Windows"
56-
},
52+
"command": "transparency_open_help_file",
5753
"caption": "Help"
5854
},
5955
{ "caption": "-"},
6056
{
61-
"command": "open_file",
62-
"args": {
63-
"file": "${packages}/SublimeTextTrans/SublimeTextTrans.sublime-settings",
64-
"platform": "Windows"
65-
},
57+
"command": "transparency_open_plugin_default_settings_file",
6658
"caption": "Settings - Default"
6759
},
6860
{

Readme.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@ This simple plugin for Sublime Text 2 and Sublime Text 3 provides contextual men
1111

1212
Install
1313
-------
14-
You may install `SublimeTextTrans` via git with the below commands:
14+
15+
**Using Package Installer:**
16+
17+
Ctrl+Shift+P - Install Package - Transparency
18+
19+
You may also install `SublimeTextTrans` via git with the below commands:
1520

1621
**Windows only**
1722

1823
**For Sublime Installed:**
1924

20-
git clone https://github.com/vhanla/SublimeTextTrans.git "%APPDATA%\Sublime Text 2\Packages\SublimeTextTrans"
25+
git clone https://github.com/vhanla/SublimeTextTrans.git "%APPDATA%\Sublime Text 2\Packages\Transparency"
2126

2227
**Notice** that this location might change on each SublimeText version, _you can find the correct path by going to menu **Preferences - Browse Packages**_
2328

2429
**For Sublime as Portable:**
2530

26-
git clone https://github.com/vhanla/SublimeTextTrans.git "C:\Sublime\Data\Packages\SublimeTextTrans""
31+
git clone https://github.com/vhanla/SublimeTextTrans.git "C:\Sublime\Data\Packages\Transparency"
2732

2833
*Where* ***C:\Sublime*** *is the portable's path. So change accordingly.*
2934

3035
You can also get it zipped from the [Releases](https://github.com/vhanla/SublimeTextTrans/releases) section.
3136

3237
Remember, this plugin must be inside its own directory within packages directory where you will unzip it.
3338

34-
**Alternative using Package Installer:**
35-
36-
Ctrl+Shift+P - Install Package - Transparency
3739

3840
Usage:
3941
-------
@@ -54,6 +56,13 @@ However, you don't need to install it or launch manually, the plugin does it for
5456

5557
Changelog:
5658
----------
59+
[16-05-2018] v1.4
60+
61+
- Fixed opening default settings and help menu
62+
- Improved window listing on ST3
63+
- Fixed issue #3 thanks to @rexdf
64+
- Only call external executable if ST2/3 window is not already WS_EX_LAYERED
65+
5766
[14-04-2018] v1.3
5867

5968
- Modified `SetSublimeLayered.asm` to make it smaller and to avoid false positives (tested on [VirusTotal](https://www.virustotal.com/#/file/66b72c28f54728c6df3995b0ae026aa1aeeca96911d5b484673a502ec6592f2a/detection))
@@ -103,7 +112,8 @@ You can see other options on `Settings - Default` file.
103112

104113
Author & Contributors
105114
----------------------
106-
[Victor Alberto Gil](http://profiles.google.com/vhanla) - Hope you like my work.
115+
- [@vhanla](https://github.com/vhanla) - Author.
116+
- [@rexdf](https://github.com/rexdf) - Contributor
107117

108118
License
109119
-------

SublimeTextTrans.sublime-settings

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
// It will set the default levels of opacity
1818

1919
// If you like to have a different transparency level
20-
// modify this array of options in your user preferences
20+
// modify this array of options in your user preferences
2121
// i.e. just add (copy/paste) this array and modify at wish
2222
// IMPORTANT: Level of opacity varies from 0 to 255
2323
// 0 = Totally transparent, 255 = Fully opaque
24+
// ORDER is important, it has its correspondent menu item/hotkey
2425
"levels": [
25-
255, // Full opaque i.e not transparency - a.k.a Disabled
26-
212, // Level 5
27-
220, // Level 4
28-
228, // Level 3
29-
236, // Level 2
30-
243 // Level 1
26+
255, // Full opaque i.e not transparent - a.k.a Disabled, recommended to leave it as 255 [Ctrl+Shift+1]
27+
212, // Level 5 - [Ctrl+Shift+6]
28+
220, // Level 4 - [Ctrl+Shift+5]
29+
228, // Level 3 - [Ctrl+Shift+4]
30+
236, // Level 2 - [Ctrl+Shift+3]
31+
243 // Level 1 - [Ctrl+Shift+2]
3132
]
3233
}

SublimeTrans.py

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from ctypes import wintypes
1313
from ctypes import windll
1414

15+
if sys.version_info < (3,):
16+
from transparency.commands import *
17+
else:
18+
import sublime_api
19+
from .transparency.commands import *
20+
1521
if sublime.platform()=='windows':
1622

1723
SetLayeredWindowAttributes = windll.user32.SetLayeredWindowAttributes
@@ -74,15 +80,18 @@
7480
WS_EX_LAYERED = 0x00080000
7581
SW_HIDE = 0
7682
SW_SHOW = 5
83+
PROCESS_QUERY_INFORMATION = 0x0400
84+
PROCESS_VM_READ = 0x0010
7785

78-
STT_VERSION = "1.3"
86+
STT_VERSION = "1.4"
7987
#default global variables , needed to use plugin_loaded function in order to work on ST3
8088
stt_settings_filename = "SublimeTextTrans.sublime-settings"
8189
stt_settings = None
8290
stt_about_message = ("SublimeTextTrans plugin v%s\n"
8391
"for Sublime Text 2 & Sublime Text 3\n"
8492
"Windows only version\n\n"
85-
"Description: It will make Sublime transparent.\n\n"
93+
"Package Name: Transparency\n"
94+
"Description: It will make Sublime Text transparent.\n\n"
8695
"Written by Victor Alberto Gil <vhanla>\n"
8796
"https://github.com/vhanla/SublimeTextTrans") % (STT_VERSION)
8897
stt_opacity = 0
@@ -99,34 +108,57 @@
99108
def sublime_opacity(opacity):
100109
if stt_settings is None:
101110
return
102-
#LHDesktop = GetDesktopWindow(None)
103-
LHDesktop = GetDesktopWindow()
104-
LHWindow = GetWindow(LHDesktop,GW_CHILD)
105-
Clase = 'PX_WINDOW_CLASS'
106-
while(LHWindow != None):
107-
LHParent = GetWindowLong(LHWindow, GWL_HWNDPARENT)
108-
clas = create_string_buffer(255)
109-
GetClassName(LHWindow,clas,255)
110-
classs = clas.value
111-
if IsWindowVisible(LHWindow):
112-
if (LHParent==0) or (LHParent==LHDesktop):
113-
if(classs==b'PX_WINDOW_CLASS'):
114-
#print('Applying opacity level ',opacity)
115-
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
116-
try:
117-
parametro = str(LHWindow)+' '+ str(wl)
118-
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)
119-
if opacity is not None:
120-
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
121-
cur_opacity = stt_settings.get("opacity", None)
122-
if cur_opacity != opacity:
123-
stt_settings.set("opacity", opacity)
124-
persist_settings()
125-
break
126-
except ValueError:
127-
print("Error! ")
128-
129-
LHWindow = GetWindow(LHWindow, GW_HWNDNEXT)
111+
112+
if sublime_3:
113+
wndLst = [sublime.Window(hwnd) for hwnd in sublime_api.windows()]
114+
for wnd in wndLst:
115+
LHDesktop = GetDesktopWindow()
116+
LHWindow = wnd.hwnd()
117+
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
118+
try:
119+
if((wl & WS_EX_LAYERED) != WS_EX_LAYERED):
120+
parametro = str(LHWindow)+' '+ str(wl)
121+
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)
122+
123+
if opacity is not None:
124+
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
125+
cur_opacity = stt_settings.get("opacity", None)
126+
if cur_opacity != opacity:
127+
stt_settings.set("opacity", opacity)
128+
persist_settings()
129+
except ValueError:
130+
print("Error! ")
131+
else:
132+
#LHDesktop = GetDesktopWindow(None)
133+
LHDesktop = GetDesktopWindow()
134+
LHWindow = GetWindow(LHDesktop,GW_CHILD)
135+
Clase = 'PX_WINDOW_CLASS'
136+
while(LHWindow != None):
137+
LHParent = GetWindowLong(LHWindow, GWL_HWNDPARENT)
138+
clas = create_string_buffer(255)
139+
GetClassName(LHWindow,clas,255)
140+
classs = clas.value
141+
if IsWindowVisible(LHWindow):
142+
if (LHParent==0) or (LHParent==LHDesktop):
143+
if(classs==b'PX_WINDOW_CLASS'):
144+
#print('Applying opacity level ',opacity)
145+
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
146+
try:
147+
if((wl & WS_EX_LAYERED) != WS_EX_LAYERED):
148+
parametro = str(LHWindow)+' '+ str(wl)
149+
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)
150+
151+
if opacity is not None:
152+
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
153+
cur_opacity = stt_settings.get("opacity", None)
154+
if cur_opacity != opacity:
155+
stt_settings.set("opacity", opacity)
156+
persist_settings()
157+
break
158+
except ValueError:
159+
print("Error! ")
160+
161+
LHWindow = GetWindow(LHWindow, GW_HWNDNEXT)
130162

131163
def sublime_opaque(level):
132164
global stt_opacity
@@ -217,11 +249,11 @@ def reload_settings():
217249
global stt_settings_filename, stt_settings, sublime_3
218250
global stt_opacity
219251
global stt_autoapply
220-
print ("Notice: Load/Reload settings incase user modified")
252+
# print ("Notice: Load/Reload settings incase user modified")
221253
stt_settings = sublime.load_settings(stt_settings_filename)
222254
stt_opacity = int(stt_settings.get('opacity',255))
223255
stt_autoapply = bool(stt_settings.get('autoapply',False))
224-
stt_levels = stt_settings.get('levels');
256+
stt_levels = stt_settings.get('levels')
225257
stt_level0 = int(stt_levels[0])
226258
stt_level1 = int(stt_levels[1])
227259
stt_level2 = int(stt_levels[2])
@@ -249,6 +281,11 @@ def plugin_loaded():
249281

250282
#print('Done!')
251283

284+
def plugin_unloaded():
285+
#restore opacity on plugin unloaded/uninstalled
286+
sublime_opacity(255)
287+
288+
252289
# This delayed procedure will change focused view and call sublime_opacity
253290
# in order to apply on sublime's startup
254291
def focus_active_view():

messages/install.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,37 @@ There are three methods to set transparency:
1616
2. You can use the hotkeys `Ctrl+Shift+[1,2,3,4,5,6]`
1717
3. Or you can right click and use the contextual menu
1818

19-
![](https://github.com/vhanla/SublimeTextTrans/raw/master/snapshot.png?raw=true)
20-
2119

2220
Configuration:
2321
--------------
2422
To set custom transparency levels visit `Preferences > Package Settings > SublimeTextTrans > Settings - User`, it will open the user's custom preferences file for this plugin.
2523

2624
There you can modify the transparency levels, by adding the following and adjusting the levels as you wish:
2725

28-
```json
2926
{
3027

3128
// If you like to have a different transparency level
32-
// modify this array of options in your user preferences
29+
// modify this array of options in your user preferences
3330
// i.e. just add (copy/paste) this array and modify at wish
3431
// IMPORTANT: Level of opacity varies from 0 to 255
3532
// 0 = Totally transparent, 255 = Fully opaque
33+
// ORDER is important, it has its correspondent menu item/hotkey
3634
"levels": [
37-
255, // Full opaque i.e not transparency - a.k.a Disabled
38-
212, // Level 5
39-
220, // Level 4
40-
228, // Level 3
41-
236, // Level 2
42-
243 // Level 1
35+
255, // Full opaque i.e not transparent - a.k.a Disabled, recommended to leave it as 255 [Ctrl+Shift+1]
36+
212, // Level 5 - [Ctrl+Shift+6]
37+
220, // Level 4 - [Ctrl+Shift+5]
38+
228, // Level 3 - [Ctrl+Shift+4]
39+
236, // Level 2 - [Ctrl+Shift+3]
40+
243 // Level 1 - [Ctrl+Shift+2]
4341
]
4442
}
45-
```
4643

47-
You can also find other options on `Settings - Default` file.
44+
You can enable or disable autoapply transparency on ST load automatically by adding to the user settings:
45+
{
46+
"autoapply": true // false to disable
47+
}
48+
49+
Or just open default settings, copy it and paste it in your user settings, modifiy as you wish and save your new settings.
4850

49-
Author & Contributors
50-
----------------------
51-
[Victor Alberto Gil](http://profiles.google.com/vhanla) - Hope you like my work.
5251

52+
Report issues at: https://github.com/vhanla/SublimeTextTrans/issues

transparency/__init__.py

Whitespace-only changes.

transparency/commands/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .settings import (
2+
TransparencyOpenPluginDefaultSettingsFile,
3+
TransparencyOpenHelpFile
4+
)
5+
6+
__all__ = [
7+
"TransparencyOpenPluginDefaultSettingsFile",
8+
"TransparencyOpenHelpFile"
9+
]

transparency/commands/settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sublime_plugin
2+
import sublime
3+
4+
import os
5+
from os.path import dirname
6+
7+
ST2 = int(sublime.version()) < 3000
8+
9+
if not ST2:
10+
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
11+
else:
12+
_st_pkgs_dir = sublime.packages_path()
13+
_cur_file_abspath = os.path.abspath(__file__)
14+
if _st_pkgs_dir not in _cur_file_abspath:
15+
for p in os.listdir(_st_pkgs_dir):
16+
link_path = _st_pkgs_dir + os.sep + p
17+
if os.path.realpath(link_path) in _cur_file_abspath:
18+
PLUGIN_DIR = link_path
19+
break
20+
else:
21+
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
22+
23+
class TransparencyOpenPluginDefaultSettingsFile(sublime_plugin.WindowCommand):
24+
def run(self):
25+
default_plugin_settings_path = os.path.join(PLUGIN_DIR, "SublimeTextTrans.sublime-settings")
26+
sublime.active_window().open_file(default_plugin_settings_path)
27+
28+
class TransparencyOpenHelpFile(sublime_plugin.WindowCommand):
29+
def run(self):
30+
help_file_path = os.path.join(PLUGIN_DIR, "messages/install.txt")
31+
sublime.active_window().open_file(help_file_path)

0 commit comments

Comments
 (0)