Skip to content

Commit

Permalink
Improved for ST3 and fixed menu issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vhanla committed May 17, 2018
1 parent 4facb79 commit 0366aad
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 71 deletions.
12 changes: 2 additions & 10 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,12 @@
"command": "sub_trans_about"
},
{
"command": "open_file",
"args": {
"file": "${packages}/SublimeTextTrans/README.md",
"platform": "Windows"
},
"command": "transparency_open_help_file",
"caption": "Help"
},
{ "caption": "-"},
{
"command": "open_file",
"args": {
"file": "${packages}/SublimeTextTrans/SublimeTextTrans.sublime-settings",
"platform": "Windows"
},
"command": "transparency_open_plugin_default_settings_file",
"caption": "Settings - Default"
},
{
Expand Down
24 changes: 17 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ This simple plugin for Sublime Text 2 and Sublime Text 3 provides contextual men

Install
-------
You may install `SublimeTextTrans` via git with the below commands:

**Using Package Installer:**

Ctrl+Shift+P - Install Package - Transparency

You may also install `SublimeTextTrans` via git with the below commands:

**Windows only**

**For Sublime Installed:**

git clone https://github.com/vhanla/SublimeTextTrans.git "%APPDATA%\Sublime Text 2\Packages\SublimeTextTrans"
git clone https://github.com/vhanla/SublimeTextTrans.git "%APPDATA%\Sublime Text 2\Packages\Transparency"

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

**For Sublime as Portable:**

git clone https://github.com/vhanla/SublimeTextTrans.git "C:\Sublime\Data\Packages\SublimeTextTrans""
git clone https://github.com/vhanla/SublimeTextTrans.git "C:\Sublime\Data\Packages\Transparency"

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

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

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

**Alternative using Package Installer:**

Ctrl+Shift+P - Install Package - Transparency

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

Changelog:
----------
[16-05-2018] v1.4

- Fixed opening default settings and help menu
- Improved window listing on ST3
- Fixed issue #3 thanks to @rexdf
- Only call external executable if ST2/3 window is not already WS_EX_LAYERED

[14-04-2018] v1.3

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

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

License
-------
Expand Down
15 changes: 8 additions & 7 deletions SublimeTextTrans.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
// It will set the default levels of opacity

// If you like to have a different transparency level
// modify this array of options in your user preferences
// modify this array of options in your user preferences
// i.e. just add (copy/paste) this array and modify at wish
// IMPORTANT: Level of opacity varies from 0 to 255
// 0 = Totally transparent, 255 = Fully opaque
// ORDER is important, it has its correspondent menu item/hotkey
"levels": [
255, // Full opaque i.e not transparency - a.k.a Disabled
212, // Level 5
220, // Level 4
228, // Level 3
236, // Level 2
243 // Level 1
255, // Full opaque i.e not transparent - a.k.a Disabled, recommended to leave it as 255 [Ctrl+Shift+1]
212, // Level 5 - [Ctrl+Shift+6]
220, // Level 4 - [Ctrl+Shift+5]
228, // Level 3 - [Ctrl+Shift+4]
236, // Level 2 - [Ctrl+Shift+3]
243 // Level 1 - [Ctrl+Shift+2]
]
}
101 changes: 69 additions & 32 deletions SublimeTrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from ctypes import wintypes
from ctypes import windll

if sys.version_info < (3,):
from transparency.commands import *
else:
import sublime_api
from .transparency.commands import *

if sublime.platform()=='windows':

SetLayeredWindowAttributes = windll.user32.SetLayeredWindowAttributes
Expand Down Expand Up @@ -74,15 +80,18 @@
WS_EX_LAYERED = 0x00080000
SW_HIDE = 0
SW_SHOW = 5
PROCESS_QUERY_INFORMATION = 0x0400
PROCESS_VM_READ = 0x0010

STT_VERSION = "1.3"
STT_VERSION = "1.4"
#default global variables , needed to use plugin_loaded function in order to work on ST3
stt_settings_filename = "SublimeTextTrans.sublime-settings"
stt_settings = None
stt_about_message = ("SublimeTextTrans plugin v%s\n"
"for Sublime Text 2 & Sublime Text 3\n"
"Windows only version\n\n"
"Description: It will make Sublime transparent.\n\n"
"Package Name: Transparency\n"
"Description: It will make Sublime Text transparent.\n\n"
"Written by Victor Alberto Gil <vhanla>\n"
"https://github.com/vhanla/SublimeTextTrans") % (STT_VERSION)
stt_opacity = 0
Expand All @@ -99,34 +108,57 @@
def sublime_opacity(opacity):
if stt_settings is None:
return
#LHDesktop = GetDesktopWindow(None)
LHDesktop = GetDesktopWindow()
LHWindow = GetWindow(LHDesktop,GW_CHILD)
Clase = 'PX_WINDOW_CLASS'
while(LHWindow != None):
LHParent = GetWindowLong(LHWindow, GWL_HWNDPARENT)
clas = create_string_buffer(255)
GetClassName(LHWindow,clas,255)
classs = clas.value
if IsWindowVisible(LHWindow):
if (LHParent==0) or (LHParent==LHDesktop):
if(classs==b'PX_WINDOW_CLASS'):
#print('Applying opacity level ',opacity)
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
try:
parametro = str(LHWindow)+' '+ str(wl)
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)
if opacity is not None:
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
cur_opacity = stt_settings.get("opacity", None)
if cur_opacity != opacity:
stt_settings.set("opacity", opacity)
persist_settings()
break
except ValueError:
print("Error! ")

LHWindow = GetWindow(LHWindow, GW_HWNDNEXT)

if sublime_3:
wndLst = [sublime.Window(hwnd) for hwnd in sublime_api.windows()]
for wnd in wndLst:
LHDesktop = GetDesktopWindow()
LHWindow = wnd.hwnd()
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
try:
if((wl & WS_EX_LAYERED) != WS_EX_LAYERED):
parametro = str(LHWindow)+' '+ str(wl)
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)

if opacity is not None:
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
cur_opacity = stt_settings.get("opacity", None)
if cur_opacity != opacity:
stt_settings.set("opacity", opacity)
persist_settings()
except ValueError:
print("Error! ")
else:
#LHDesktop = GetDesktopWindow(None)
LHDesktop = GetDesktopWindow()
LHWindow = GetWindow(LHDesktop,GW_CHILD)
Clase = 'PX_WINDOW_CLASS'
while(LHWindow != None):
LHParent = GetWindowLong(LHWindow, GWL_HWNDPARENT)
clas = create_string_buffer(255)
GetClassName(LHWindow,clas,255)
classs = clas.value
if IsWindowVisible(LHWindow):
if (LHParent==0) or (LHParent==LHDesktop):
if(classs==b'PX_WINDOW_CLASS'):
#print('Applying opacity level ',opacity)
wl = GetWindowLong(LHWindow,GWL_EXSTYLE)
try:
if((wl & WS_EX_LAYERED) != WS_EX_LAYERED):
parametro = str(LHWindow)+' '+ str(wl)
ShellExecute(LHDesktop,"open", exe_file,parametro,None,SW_HIDE)

if opacity is not None:
SetLayeredWindowAttributes(LHWindow,0,opacity, LWA_ALPHA)
cur_opacity = stt_settings.get("opacity", None)
if cur_opacity != opacity:
stt_settings.set("opacity", opacity)
persist_settings()
break
except ValueError:
print("Error! ")

LHWindow = GetWindow(LHWindow, GW_HWNDNEXT)

def sublime_opaque(level):
global stt_opacity
Expand Down Expand Up @@ -217,11 +249,11 @@ def reload_settings():
global stt_settings_filename, stt_settings, sublime_3
global stt_opacity
global stt_autoapply
print ("Notice: Load/Reload settings incase user modified")
# print ("Notice: Load/Reload settings incase user modified")
stt_settings = sublime.load_settings(stt_settings_filename)
stt_opacity = int(stt_settings.get('opacity',255))
stt_autoapply = bool(stt_settings.get('autoapply',False))
stt_levels = stt_settings.get('levels');
stt_levels = stt_settings.get('levels')
stt_level0 = int(stt_levels[0])
stt_level1 = int(stt_levels[1])
stt_level2 = int(stt_levels[2])
Expand Down Expand Up @@ -249,6 +281,11 @@ def plugin_loaded():

#print('Done!')

def plugin_unloaded():
#restore opacity on plugin unloaded/uninstalled
sublime_opacity(255)


# This delayed procedure will change focused view and call sublime_opacity
# in order to apply on sublime's startup
def focus_active_view():
Expand Down
30 changes: 15 additions & 15 deletions messages/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ There are three methods to set transparency:
2. You can use the hotkeys `Ctrl+Shift+[1,2,3,4,5,6]`
3. Or you can right click and use the contextual menu

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


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

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

```json
{

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

You can also find other options on `Settings - Default` file.
You can enable or disable autoapply transparency on ST load automatically by adding to the user settings:
{
"autoapply": true // false to disable
}

Or just open default settings, copy it and paste it in your user settings, modifiy as you wish and save your new settings.

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

Report issues at: https://github.com/vhanla/SublimeTextTrans/issues
Empty file added transparency/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions transparency/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .settings import (
TransparencyOpenPluginDefaultSettingsFile,
TransparencyOpenHelpFile
)

__all__ = [
"TransparencyOpenPluginDefaultSettingsFile",
"TransparencyOpenHelpFile"
]
31 changes: 31 additions & 0 deletions transparency/commands/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sublime_plugin
import sublime

import os
from os.path import dirname

ST2 = int(sublime.version()) < 3000

if not ST2:
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
else:
_st_pkgs_dir = sublime.packages_path()
_cur_file_abspath = os.path.abspath(__file__)
if _st_pkgs_dir not in _cur_file_abspath:
for p in os.listdir(_st_pkgs_dir):
link_path = _st_pkgs_dir + os.sep + p
if os.path.realpath(link_path) in _cur_file_abspath:
PLUGIN_DIR = link_path
break
else:
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))

class TransparencyOpenPluginDefaultSettingsFile(sublime_plugin.WindowCommand):
def run(self):
default_plugin_settings_path = os.path.join(PLUGIN_DIR, "SublimeTextTrans.sublime-settings")
sublime.active_window().open_file(default_plugin_settings_path)

class TransparencyOpenHelpFile(sublime_plugin.WindowCommand):
def run(self):
help_file_path = os.path.join(PLUGIN_DIR, "messages/install.txt")
sublime.active_window().open_file(help_file_path)

0 comments on commit 0366aad

Please sign in to comment.